Commit c512b99e authored by brettw@chromium.org's avatar brettw@chromium.org

Hook up the new font API to WebKit. This moves the existing GetFontTable API to

the private font interface.

TEST=none
BUG=none
Review URL: http://codereview.chromium.org/3044029

git-svn-id: svn://svn.chromium.org/chrome/trunk/src@54173 0039d316-1c4b-4281-b951-d872f2087c98
parent 5c49bf95
...@@ -158,7 +158,7 @@ deps = { ...@@ -158,7 +158,7 @@ deps = {
Var("libvpx_revision"), Var("libvpx_revision"),
"src/third_party/ppapi": "src/third_party/ppapi":
"http://ppapi.googlecode.com/svn/trunk@174", "http://ppapi.googlecode.com/svn/trunk@176",
"src/third_party/libjingle/source": "src/third_party/libjingle/source":
"http://libjingle.googlecode.com/svn/branches/nextsnap@" + "http://libjingle.googlecode.com/svn/branches/nextsnap@" +
......
This diff is collapsed.
...@@ -5,9 +5,15 @@ ...@@ -5,9 +5,15 @@
#ifndef WEBKIT_GLUE_PLUGINS_PEPPER_FONT_H_ #ifndef WEBKIT_GLUE_PLUGINS_PEPPER_FONT_H_
#define WEBKIT_GLUE_PLUGINS_PEPPER_FONT_H_ #define WEBKIT_GLUE_PLUGINS_PEPPER_FONT_H_
#include <string>
#include "base/scoped_ptr.h"
#include "third_party/ppapi/c/ppb_font.h"
#include "webkit/glue/plugins/pepper_resource.h" #include "webkit/glue/plugins/pepper_resource.h"
typedef struct _ppb_Font PPB_Font; namespace WebKit {
class WebFont;
}
namespace pepper { namespace pepper {
...@@ -15,7 +21,7 @@ class PluginInstance; ...@@ -15,7 +21,7 @@ class PluginInstance;
class Font : public Resource { class Font : public Resource {
public: public:
Font(PluginModule* module, int fd); Font(PluginModule* module, const PP_FontDescription& desc);
virtual ~Font(); virtual ~Font();
// Returns a pointer to the interface implementing PPB_Font that is exposed to // Returns a pointer to the interface implementing PPB_Font that is exposed to
...@@ -26,12 +32,22 @@ class Font : public Resource { ...@@ -26,12 +32,22 @@ class Font : public Resource {
Font* AsFont() { return this; } Font* AsFont() { return this; }
// PPB_Font implementation. // PPB_Font implementation.
bool GetFontTable(uint32_t table, bool Describe(PP_FontDescription* description,
void* output, PP_FontMetrics* metrics);
uint32_t* output_length); bool DrawTextAt(PP_Resource image_data,
const PP_TextRun* text,
const PP_Point* position,
uint32_t color,
const PP_Rect* clip,
bool image_data_is_opaque);
int32_t MeasureText(const PP_TextRun* text);
uint32_t CharacterOffsetForPixel(const PP_TextRun* text,
int32_t pixel_position);
int32_t PixelOffsetForCharacter(const PP_TextRun* text,
uint32_t char_offset);
private: private:
int fd_; scoped_ptr<WebKit::WebFont> font_;
}; };
} // namespace pepper } // namespace pepper
......
...@@ -9,11 +9,30 @@ ...@@ -9,11 +9,30 @@
#include "base/utf_string_conversions.h" #include "base/utf_string_conversions.h"
#include "grit/webkit_strings.h" #include "grit/webkit_strings.h"
#include "webkit/glue/webkit_glue.h" #include "webkit/glue/webkit_glue.h"
#include "webkit/glue/plugins/pepper_plugin_module.h"
#include "webkit/glue/plugins/pepper_var.h" #include "webkit/glue/plugins/pepper_var.h"
#include "webkit/glue/plugins/ppb_private.h" #include "webkit/glue/plugins/ppb_private.h"
namespace pepper { namespace pepper {
#if defined(OS_LINUX)
class PrivateFontFile : public Resource {
public:
PrivateFontFile(PluginModule* module, int fd) : Resource(module), fd_(fd) {}
virtual ~PrivateFontFile() {}
// Resource overrides.
PrivateFontFile* AsPrivateFontFile() { return this; }
bool GetFontTable(uint32_t table,
void* output,
uint32_t* output_length);
private:
int fd_;
};
#endif
namespace { namespace {
PP_Var GetLocalizedString(PP_ResourceString string_id) { PP_Var GetLocalizedString(PP_ResourceString string_id) {
...@@ -24,8 +43,50 @@ PP_Var GetLocalizedString(PP_ResourceString string_id) { ...@@ -24,8 +43,50 @@ PP_Var GetLocalizedString(PP_ResourceString string_id) {
return StringToPPVar(rv); return StringToPPVar(rv);
} }
PP_Resource GetFontFileWithFallback(
PP_Module module_id,
const PP_PrivateFontFileDescription* description) {
#if defined(OS_LINUX)
PluginModule* module = PluginModule::FromPPModule(module_id);
if (!module)
return NULL;
int fd = webkit_glue::MatchFontWithFallback(description->face,
description->weight >= 700,
description->italic,
description->charset);
if (fd == -1)
return NULL;
scoped_refptr<PrivateFontFile> font(new PrivateFontFile(module, fd));
return font->GetReference();
#else
// For trusted pepper plugins, this is only needed in Linux since font loading
// on Windows and Mac works through the renderer sandbox.
return false;
#endif
}
bool GetFontTableForPrivateFontFile(PP_Resource font_file,
uint32_t table,
void* output,
uint32_t* output_length) {
#if defined(OS_LINUX)
scoped_refptr<PrivateFontFile> font(
Resource::GetAs<PrivateFontFile>(font_file));
if (!font.get())
return false;
return font->GetFontTable(table, output, output_length);
#else
return false;
#endif
}
const PPB_Private ppb_private = { const PPB_Private ppb_private = {
&GetLocalizedString, &GetLocalizedString,
&GetFontFileWithFallback,
&GetFontTableForPrivateFontFile,
}; };
} // namespace } // namespace
...@@ -35,4 +96,16 @@ const PPB_Private* Private::GetInterface() { ...@@ -35,4 +96,16 @@ const PPB_Private* Private::GetInterface() {
return &ppb_private; return &ppb_private;
} }
#if defined(OS_LINUX)
bool PrivateFontFile::GetFontTable(uint32_t table,
void* output,
uint32_t* output_length) {
size_t temp_size = static_cast<size_t>(*output_length);
bool rv = webkit_glue::GetFontTable(
fd_, table, static_cast<uint8_t*>(output), &temp_size);
*output_length = static_cast<uint32_t>(temp_size);
return rv;
}
#endif
} // namespace pepper } // namespace pepper
...@@ -22,6 +22,7 @@ class FileRef; ...@@ -22,6 +22,7 @@ class FileRef;
class Font; class Font;
class ImageData; class ImageData;
class PluginModule; class PluginModule;
class PrivateFontFile;
class Scrollbar; class Scrollbar;
class URLLoader; class URLLoader;
class URLRequestInfo; class URLRequestInfo;
...@@ -80,6 +81,7 @@ class Resource : public base::RefCountedThreadSafe<Resource> { ...@@ -80,6 +81,7 @@ class Resource : public base::RefCountedThreadSafe<Resource> {
virtual FileRef* AsFileRef() { return NULL; } virtual FileRef* AsFileRef() { return NULL; }
virtual Font* AsFont() { return NULL; } virtual Font* AsFont() { return NULL; }
virtual ImageData* AsImageData() { return NULL; } virtual ImageData* AsImageData() { return NULL; }
virtual PrivateFontFile* AsPrivateFontFile() { return NULL; }
virtual Scrollbar* AsScrollbar() { return NULL; } virtual Scrollbar* AsScrollbar() { return NULL; }
virtual URLLoader* AsURLLoader() { return NULL; } virtual URLLoader* AsURLLoader() { return NULL; }
virtual URLRequestInfo* AsURLRequestInfo() { return NULL; } virtual URLRequestInfo* AsURLRequestInfo() { return NULL; }
......
...@@ -33,7 +33,8 @@ PP_Var NPObjectToPPVar(NPObject* object); ...@@ -33,7 +33,8 @@ PP_Var NPObjectToPPVar(NPObject* object);
NPObject* GetNPObject(PP_Var var); NPObject* GetNPObject(PP_Var var);
// Returns a PP_Var of type string that contains a copy of the given string. // Returns a PP_Var of type string that contains a copy of the given string.
// The input data must be valid UTF-8 encoded text. // The input data must be valid UTF-8 encoded text. The return value will
// have a reference count of 1.
PP_Var StringToPPVar(const std::string& str); PP_Var StringToPPVar(const std::string& str);
// Returns the String corresponding to the PP_Var. This pointer has not been // Returns the String corresponding to the PP_Var. This pointer has not been
......
...@@ -5,6 +5,7 @@ ...@@ -5,6 +5,7 @@
#ifndef WEBKIT_GLUE_PLUGINS_PPB_PRIVATE_H_ #ifndef WEBKIT_GLUE_PLUGINS_PPB_PRIVATE_H_
#define WEBKIT_GLUE_PLUGINS_PPB_PRIVATE_H_ #define WEBKIT_GLUE_PLUGINS_PPB_PRIVATE_H_
#include "third_party/ppapi/c/pp_module.h"
#include "third_party/ppapi/c/pp_var.h" #include "third_party/ppapi/c/pp_var.h"
#define PPB_PRIVATE_INTERFACE "PPB_Private;1" #define PPB_PRIVATE_INTERFACE "PPB_Private;1"
...@@ -13,9 +14,64 @@ typedef enum _pp_ResourceString { ...@@ -13,9 +14,64 @@ typedef enum _pp_ResourceString {
PP_RESOURCESTRING_PDFGETPASSWORD = 0, PP_RESOURCESTRING_PDFGETPASSWORD = 0,
} PP_ResourceString; } PP_ResourceString;
typedef enum _pp_PrivateFontPitch {
PP_PRIVATEFONTPITCH_DEFAULT = 0,
PP_PRIVATEFONTPITCH_FIXED = 1
} PP_PrivateFontPitch;
typedef enum _pp_PrivateFontFamily {
PP_PRIVATEFONTFAMILY_DEFAULT = 0,
PP_PRIVATEFONTFAMILY_ROMAN = 1,
PP_PRIVATEFONTFAMILY_SCRIPT = 2
} PP_PrivateFontFamily;
typedef enum _pp_PrivateFontCharset {
PP_PRIVATEFONTCHARSET_ANSI = 0,
PP_PRIVATEFONTCHARSET_DEFAULT = 1,
PP_PRIVATEFONTCHARSET_SYMBOL = 2,
PP_PRIVATEFONTCHARSET_MAC = 77,
PP_PRIVATEFONTCHARSET_SHIFTJIS = 128,
PP_PRIVATEFONTCHARSET_HANGUL = 129,
PP_PRIVATEFONTCHARSET_JOHAB = 130,
PP_PRIVATEFONTCHARSET_GB2312 =134,
PP_PRIVATEFONTCHARSET_CHINESEBIG5 = 136,
PP_PRIVATEFONTCHARSET_GREEK = 161,
PP_PRIVATEFONTCHARSET_TURKISH = 162,
PP_PRIVATEFONTCHARSET_VIETNAMESE = 163,
PP_PRIVATEFONTCHARSET_HEBREW = 177,
PP_PRIVATEFONTCHARSET_ARABIC = 178,
PP_PRIVATEFONTCHARSET_BALTIC = 186,
PP_PRIVATEFONTCHARSET_RUSSIAN = 204,
PP_PRIVATEFONTCHARSET_THAI = 222,
PP_PRIVATEFONTCHARSET_EASTEUROPE = 238,
PP_PRIVATEFONTCHARSET_OEM = 255
} PP_PrivateFontCharset;
typedef struct _pp_PrivateFontFileDescription {
const char* face;
uint32_t weight;
bool italic;
PP_PrivateFontPitch pitch;
PP_PrivateFontFamily family;
PP_PrivateFontCharset charset;
} PP_PrivateFontFileDescription;
typedef struct _ppb_Private { typedef struct _ppb_Private {
// Returns a localized string. // Returns a localized string.
PP_Var (*GetLocalizedString)(PP_ResourceString string_id); PP_Var (*GetLocalizedString)(PP_ResourceString string_id);
// Returns a resource identifying a font file corresponding to the given font
// request after applying the browser-specific fallback. Linux only.
PP_Resource (*GetFontFileWithFallback)(
PP_Module module,
const PP_PrivateFontFileDescription* description);
// Given a resource previously returned by GetFontFileWithFallback, returns
// a pointer to the requested font table. Linux only.
bool (*GetFontTableForPrivateFontFile)(PP_Resource font_file,
uint32_t table,
void* output,
uint32_t* output_length);
} PPB_Private; } PPB_Private;
#endif // WEBKIT_GLUE_PLUGINS_PPB_PRIVATE_H_ #endif // WEBKIT_GLUE_PLUGINS_PPB_PRIVATE_H_
Markdown is supported
0%
or
You are about to add 0 people to the discussion. Proceed with caution.
Finish editing this message first!
Please register or to comment