summaryrefslogtreecommitdiffstats
diff options
context:
space:
mode:
-rw-r--r--content/browser/renderer_host/pepper/pepper_truetype_font_list.h15
-rw-r--r--content/browser/renderer_host/pepper/pepper_truetype_font_list_android.cc6
-rw-r--r--content/browser/renderer_host/pepper/pepper_truetype_font_list_host.cc24
-rw-r--r--content/browser/renderer_host/pepper/pepper_truetype_font_list_host.h4
-rw-r--r--content/browser/renderer_host/pepper/pepper_truetype_font_list_linux.cc41
-rw-r--r--content/browser/renderer_host/pepper/pepper_truetype_font_list_mac.mm59
-rw-r--r--content/browser/renderer_host/pepper/pepper_truetype_font_list_win.cc55
-rw-r--r--content/renderer/pepper/pepper_truetype_font_mac.mm31
-rw-r--r--content/renderer/pepper/pepper_truetype_font_win.cc2
-rw-r--r--ppapi/api/dev/ppb_truetype_font_dev.idl47
-rw-r--r--ppapi/c/dev/ppb_truetype_font_dev.h42
-rw-r--r--ppapi/cpp/dev/truetype_font_dev.cc30
-rw-r--r--ppapi/cpp/dev/truetype_font_dev.h81
-rw-r--r--ppapi/native_client/src/untrusted/pnacl_irt_shim/pnacl_shim.c7
-rw-r--r--ppapi/proxy/ppapi_messages.h5
-rw-r--r--ppapi/proxy/truetype_font_resource.cc2
-rw-r--r--ppapi/proxy/truetype_font_singleton_resource.cc53
-rw-r--r--ppapi/proxy/truetype_font_singleton_resource.h12
-rw-r--r--ppapi/tests/test_truetype_font.cc63
-rw-r--r--ppapi/tests/test_truetype_font.h1
-rw-r--r--ppapi/thunk/ppb_truetype_font_dev_thunk.cc18
-rw-r--r--ppapi/thunk/ppb_truetype_font_singleton_api.h6
22 files changed, 536 insertions, 68 deletions
diff --git a/content/browser/renderer_host/pepper/pepper_truetype_font_list.h b/content/browser/renderer_host/pepper/pepper_truetype_font_list.h
index c0ce782..da944c5 100644
--- a/content/browser/renderer_host/pepper/pepper_truetype_font_list.h
+++ b/content/browser/renderer_host/pepper/pepper_truetype_font_list.h
@@ -8,6 +8,12 @@
#include <string>
#include <vector>
+namespace ppapi {
+namespace proxy {
+struct SerializedTrueTypeFontDesc;
+}
+}
+
namespace content {
// Adds font family names on the host platform to the vector of strings.
@@ -16,6 +22,15 @@ namespace content {
// sure not to call this on a time-critical thread like the UI or I/O threads.
void GetFontFamilies_SlowBlocking(std::vector<std::string>* font_families);
+// Adds font descriptors for fonts on the host platform in the given family to
+// the vector of descriptors.
+//
+// This function is potentially slow (the system may do a bunch of I/O) so be
+// sure not to call this on a time-critical thread like the UI or I/O threads.
+void GetFontsInFamily_SlowBlocking(
+ const std::string& family,
+ std::vector<ppapi::proxy::SerializedTrueTypeFontDesc>* fonts_in_family);
+
} // namespace content
#endif // CONTENT_BROWSER_RENDERER_HOST_PEPPER_PEPPER_TRUETYPE_FONT_LIST_H_
diff --git a/content/browser/renderer_host/pepper/pepper_truetype_font_list_android.cc b/content/browser/renderer_host/pepper/pepper_truetype_font_list_android.cc
index 7a8880a..28db24f 100644
--- a/content/browser/renderer_host/pepper/pepper_truetype_font_list_android.cc
+++ b/content/browser/renderer_host/pepper/pepper_truetype_font_list_android.cc
@@ -11,4 +11,10 @@ void GetFontFamilies_SlowBlocking(std::vector<std::string>* font_families) {
NOTIMPLEMENTED(); // Font API isn't implemented on Android.
}
+void GetFontsInFamily_SlowBlocking(
+ const std::string& family,
+ std::vector<ppapi::proxy::SerializedTrueTypeFontDesc>* fonts_in_family) {
+ NOTIMPLEMENTED(); // Font API isn't implemented on Android.
+}
+
} // namespace content
diff --git a/content/browser/renderer_host/pepper/pepper_truetype_font_list_host.cc b/content/browser/renderer_host/pepper/pepper_truetype_font_list_host.cc
index e3a74d9..1b2aa66 100644
--- a/content/browser/renderer_host/pepper/pepper_truetype_font_list_host.cc
+++ b/content/browser/renderer_host/pepper/pepper_truetype_font_list_host.cc
@@ -36,8 +36,10 @@ class FontMessageFilter : public ppapi::host::ResourceMessageFilter {
private:
virtual ~FontMessageFilter();
- // Message handler.
+ // Message handlers.
int32_t OnHostMsgGetFontFamilies(ppapi::host::HostMessageContext* context);
+ int32_t OnHostMsgGetFontsInFamily(ppapi::host::HostMessageContext* context,
+ const std::string& family);
DISALLOW_COPY_AND_ASSIGN(FontMessageFilter);
};
@@ -65,6 +67,9 @@ int32_t FontMessageFilter::OnResourceMessageReceived(
PPAPI_DISPATCH_HOST_RESOURCE_CALL_0(
PpapiHostMsg_TrueTypeFontSingleton_GetFontFamilies,
OnHostMsgGetFontFamilies)
+ PPAPI_DISPATCH_HOST_RESOURCE_CALL(
+ PpapiHostMsg_TrueTypeFontSingleton_GetFontsInFamily,
+ OnHostMsgGetFontsInFamily)
IPC_END_MESSAGE_MAP()
return PP_ERROR_FAILED;
}
@@ -86,6 +91,23 @@ int32_t FontMessageFilter::OnHostMsgGetFontFamilies(
return result;
}
+int32_t FontMessageFilter::OnHostMsgGetFontsInFamily(
+ ppapi::host::HostMessageContext* context,
+ const std::string& family) {
+ // OK to use "slow blocking" version since we're on the blocking pool.
+ std::vector<ppapi::proxy::SerializedTrueTypeFontDesc> fonts_in_family;
+ GetFontsInFamily_SlowBlocking(family, &fonts_in_family);
+
+ int32_t result = base::checked_numeric_cast<int32_t>(fonts_in_family.size());
+ ppapi::host::ReplyMessageContext reply_context =
+ context->MakeReplyMessageContext();
+ reply_context.params.set_result(result);
+ context->reply_msg =
+ PpapiPluginMsg_TrueTypeFontSingleton_GetFontsInFamilyReply(
+ fonts_in_family);
+ return result;
+}
+
} // namespace
PepperTrueTypeFontListHost::PepperTrueTypeFontListHost(
diff --git a/content/browser/renderer_host/pepper/pepper_truetype_font_list_host.h b/content/browser/renderer_host/pepper/pepper_truetype_font_list_host.h
index c67553b..69a471b 100644
--- a/content/browser/renderer_host/pepper/pepper_truetype_font_list_host.h
+++ b/content/browser/renderer_host/pepper/pepper_truetype_font_list_host.h
@@ -15,8 +15,8 @@ class BrowserPpapiHost;
class PepperTrueTypeFontListHost : public ppapi::host::ResourceHost {
public:
PepperTrueTypeFontListHost(BrowserPpapiHost* host,
- PP_Instance instance,
- PP_Resource resource);
+ PP_Instance instance,
+ PP_Resource resource);
virtual ~PepperTrueTypeFontListHost();
private:
diff --git a/content/browser/renderer_host/pepper/pepper_truetype_font_list_linux.cc b/content/browser/renderer_host/pepper/pepper_truetype_font_list_linux.cc
index 661266d..24c3f5d 100644
--- a/content/browser/renderer_host/pepper/pepper_truetype_font_list_linux.cc
+++ b/content/browser/renderer_host/pepper/pepper_truetype_font_list_linux.cc
@@ -9,6 +9,8 @@
#include <string>
+#include "ppapi/proxy/serialized_structs.h"
+
namespace content {
void GetFontFamilies_SlowBlocking(std::vector<std::string>* font_families) {
@@ -17,9 +19,46 @@ void GetFontFamilies_SlowBlocking(std::vector<std::string>* font_families) {
int num_families = 0;
::pango_font_map_list_families(font_map, &families, &num_families);
- for (int i = 0; i < num_families; i++)
+ for (int i = 0; i < num_families; ++i)
font_families->push_back(::pango_font_family_get_name(families[i]));
g_free(families);
}
+void GetFontsInFamily_SlowBlocking(
+ const std::string& family,
+ std::vector<ppapi::proxy::SerializedTrueTypeFontDesc>* fonts_in_family) {
+ PangoFontMap* font_map = ::pango_cairo_font_map_get_default();
+ PangoFontFamily** font_families = NULL;
+ int num_families = 0;
+ ::pango_font_map_list_families(font_map, &font_families, &num_families);
+
+ for (int i = 0; i < num_families; ++i) {
+ PangoFontFamily* font_family = font_families[i];
+ if (family.compare(::pango_font_family_get_name(font_family)) == 0) {
+ PangoFontFace** font_faces = NULL;
+ int num_faces = 0;
+ ::pango_font_family_list_faces(font_family, &font_faces, &num_faces);
+
+ for (int j = 0; j < num_faces; ++j) {
+ PangoFontFace* font_face = font_faces[j];
+ PangoFontDescription* font_desc = ::pango_font_face_describe(font_face);
+ ppapi::proxy::SerializedTrueTypeFontDesc desc;
+ desc.family = family;
+ if (::pango_font_description_get_style(font_desc) == PANGO_STYLE_ITALIC)
+ desc.style = PP_TRUETYPEFONTSTYLE_ITALIC;
+ desc.weight = static_cast<PP_TrueTypeFontWeight_Dev>(
+ ::pango_font_description_get_weight(font_desc));
+ desc.width = static_cast<PP_TrueTypeFontWidth_Dev>(
+ ::pango_font_description_get_stretch(font_desc));
+ // Character set is not part of Pango font description.
+ desc.charset = PP_TRUETYPEFONTCHARSET_DEFAULT;
+
+ fonts_in_family->push_back(desc);
+ }
+ g_free(font_faces);
+ }
+ }
+ g_free(font_families);
+}
+
} // namespace content
diff --git a/content/browser/renderer_host/pepper/pepper_truetype_font_list_mac.mm b/content/browser/renderer_host/pepper/pepper_truetype_font_list_mac.mm
index 4507325..4c7ec94 100644
--- a/content/browser/renderer_host/pepper/pepper_truetype_font_list_mac.mm
+++ b/content/browser/renderer_host/pepper/pepper_truetype_font_list_mac.mm
@@ -8,9 +8,32 @@
#include "base/mac/scoped_nsautorelease_pool.h"
#include "base/strings/sys_string_conversions.h"
+#include "ppapi/c/dev/ppb_truetype_font_dev.h"
+#include "ppapi/proxy/serialized_structs.h"
namespace content {
+namespace {
+
+// Table to map AppKit weights to Pepper ones.
+const PP_TrueTypeFontWeight_Dev kPepperFontWeights[] = {
+ PP_TRUETYPEFONTWEIGHT_THIN, // 0 is the minimum AppKit weight.
+ PP_TRUETYPEFONTWEIGHT_ULTRALIGHT,
+ PP_TRUETYPEFONTWEIGHT_ULTRALIGHT,
+ PP_TRUETYPEFONTWEIGHT_LIGHT,
+ PP_TRUETYPEFONTWEIGHT_LIGHT,
+ PP_TRUETYPEFONTWEIGHT_NORMAL, // 5 is a 'normal' AppKit weight.
+ PP_TRUETYPEFONTWEIGHT_MEDIUM,
+ PP_TRUETYPEFONTWEIGHT_MEDIUM,
+ PP_TRUETYPEFONTWEIGHT_SEMIBOLD,
+ PP_TRUETYPEFONTWEIGHT_BOLD, // 9 is a 'bold' AppKit weight.
+ PP_TRUETYPEFONTWEIGHT_ULTRABOLD,
+ PP_TRUETYPEFONTWEIGHT_HEAVY,
+};
+const NSInteger kPepperFontWeightsLength = arraysize(kPepperFontWeights);
+
+} // namespace
+
void GetFontFamilies_SlowBlocking(std::vector<std::string>* font_families) {
base::mac::ScopedNSAutoreleasePool autorelease_pool;
NSFontManager* fontManager = [[[NSFontManager alloc] init] autorelease];
@@ -20,4 +43,40 @@ void GetFontFamilies_SlowBlocking(std::vector<std::string>* font_families) {
font_families->push_back(base::SysNSStringToUTF8(family_name));
}
+void GetFontsInFamily_SlowBlocking(
+ const std::string& family,
+ std::vector<ppapi::proxy::SerializedTrueTypeFontDesc>* fonts_in_family) {
+ base::mac::ScopedNSAutoreleasePool autorelease_pool;
+ NSFontManager* fontManager = [[[NSFontManager alloc] init] autorelease];
+ NSString* ns_family = base::SysUTF8ToNSString(family);
+ NSArray* ns_fonts_in_family =
+ [fontManager availableMembersOfFontFamily:ns_family];
+
+ for (NSArray* font_info in ns_fonts_in_family) {
+ ppapi::proxy::SerializedTrueTypeFontDesc desc;
+ desc.family = family;
+ NSInteger font_weight = [[font_info objectAtIndex:2] intValue];
+ font_weight = std::max(0, font_weight);
+ font_weight = std::min(kPepperFontWeightsLength - 1, font_weight);
+ desc.weight = kPepperFontWeights[font_weight];
+
+ NSFontTraitMask font_traits =
+ [[font_info objectAtIndex:3] unsignedIntValue];
+ desc.style = PP_TRUETYPEFONTSTYLE_NORMAL;
+ if (font_traits & NSItalicFontMask)
+ desc.style = PP_TRUETYPEFONTSTYLE_ITALIC;
+
+ desc.width = PP_TRUETYPEFONTWIDTH_NORMAL;
+ if (font_traits & NSCondensedFontMask)
+ desc.width = PP_TRUETYPEFONTWIDTH_CONDENSED;
+ else if (font_traits & NSExpandedFontMask)
+ desc.width = PP_TRUETYPEFONTWIDTH_EXPANDED;
+
+ // Mac doesn't support requesting non-default character sets.
+ desc.charset = PP_TRUETYPEFONTCHARSET_DEFAULT;
+
+ fonts_in_family->push_back(desc);
+ }
+}
+
} // namespace content
diff --git a/content/browser/renderer_host/pepper/pepper_truetype_font_list_win.cc b/content/browser/renderer_host/pepper/pepper_truetype_font_list_win.cc
index 6a3ee0f..649d2b7 100644
--- a/content/browser/renderer_host/pepper/pepper_truetype_font_list_win.cc
+++ b/content/browser/renderer_host/pepper/pepper_truetype_font_list_win.cc
@@ -8,17 +8,21 @@
#include "base/utf_string_conversions.h"
#include "base/win/scoped_hdc.h"
+#include "ppapi/c/dev/ppb_truetype_font_dev.h"
+#include "ppapi/proxy/serialized_structs.h"
namespace content {
namespace {
-static int CALLBACK EnumFontFamExProc(ENUMLOGFONTEXW* logical_font,
- NEWTEXTMETRICEXW* physical_font,
- DWORD font_type,
- LPARAM lparam) {
- std::vector<std::string>* font_families =
- reinterpret_cast<std::vector<std::string>*>(lparam);
+typedef std::vector<std::string> FontFamilyList;
+typedef std::vector<ppapi::proxy::SerializedTrueTypeFontDesc> FontDescList;
+
+static int CALLBACK EnumFontFamiliesProc(ENUMLOGFONTEXW* logical_font,
+ NEWTEXTMETRICEXW* physical_font,
+ DWORD font_type,
+ LPARAM lparam) {
+ FontFamilyList* font_families = reinterpret_cast<FontFamilyList*>(lparam);
if (font_families) {
const LOGFONTW& lf = logical_font->elfLogFont;
if (lf.lfFaceName[0] && lf.lfFaceName[0] != '@' &&
@@ -30,15 +34,50 @@ static int CALLBACK EnumFontFamExProc(ENUMLOGFONTEXW* logical_font,
return 1;
}
+static int CALLBACK EnumFontsInFamilyProc(ENUMLOGFONTEXW* logical_font,
+ NEWTEXTMETRICEXW* physical_font,
+ DWORD font_type,
+ LPARAM lparam) {
+ FontDescList* fonts_in_family = reinterpret_cast<FontDescList*>(lparam);
+ if (fonts_in_family) {
+ const LOGFONTW& lf = logical_font->elfLogFont;
+ if (lf.lfFaceName[0] && lf.lfFaceName[0] != '@' &&
+ lf.lfOutPrecision == OUT_STROKE_PRECIS) { // Outline fonts only.
+ ppapi::proxy::SerializedTrueTypeFontDesc desc;
+ desc.family = UTF16ToUTF8(lf.lfFaceName);
+ if (lf.lfItalic)
+ desc.style = PP_TRUETYPEFONTSTYLE_ITALIC;
+ desc.weight = static_cast<PP_TrueTypeFontWeight_Dev>(lf.lfWeight);
+ desc.width = PP_TRUETYPEFONTWIDTH_NORMAL; // TODO(bbudge) support widths.
+ desc.charset =
+ static_cast<PP_TrueTypeFontCharset_Dev>(lf.lfCharSet);
+ fonts_in_family->push_back(desc);
+ }
+ }
+ return 1;
+}
+
} // namespace
-void GetFontFamilies_SlowBlocking(std::vector<std::string>* font_families) {
+void GetFontFamilies_SlowBlocking(FontFamilyList* font_families) {
LOGFONTW logfont;
memset(&logfont, 0, sizeof(logfont));
logfont.lfCharSet = DEFAULT_CHARSET;
base::win::ScopedCreateDC hdc(::GetDC(NULL));
- ::EnumFontFamiliesExW(hdc, &logfont, (FONTENUMPROCW)&EnumFontFamExProc,
+ ::EnumFontFamiliesExW(hdc, &logfont, (FONTENUMPROCW)&EnumFontFamiliesProc,
(LPARAM)font_families, 0);
}
+void GetFontsInFamily_SlowBlocking(const std::string& family,
+ FontDescList* fonts_in_family) {
+ LOGFONTW logfont;
+ memset(&logfont, 0, sizeof(logfont));
+ logfont.lfCharSet = DEFAULT_CHARSET;
+ string16 family16 = UTF8ToUTF16(family);
+ memcpy(&logfont.lfFaceName, &family16[0], sizeof(logfont.lfFaceName));
+ base::win::ScopedCreateDC hdc(::GetDC(NULL));
+ ::EnumFontFamiliesExW(hdc, &logfont, (FONTENUMPROCW)&EnumFontsInFamilyProc,
+ (LPARAM)fonts_in_family, 0);
+}
+
} // namespace content
diff --git a/content/renderer/pepper/pepper_truetype_font_mac.mm b/content/renderer/pepper/pepper_truetype_font_mac.mm
index 0c396a3..7f10b3e 100644
--- a/content/renderer/pepper/pepper_truetype_font_mac.mm
+++ b/content/renderer/pepper/pepper_truetype_font_mac.mm
@@ -21,6 +21,15 @@ namespace content {
namespace {
+static bool FindFloat(CFDictionaryRef dict, CFStringRef name, float* value) {
+ CFNumberRef num;
+ return
+ CFDictionaryGetValueIfPresent(dict, name,
+ reinterpret_cast<const void**>(&num)) &&
+ CFNumberIsFloatType(num) &&
+ CFNumberGetValue(num, kCFNumberFloatType, value);
+}
+
float GetMacWeight(PP_TrueTypeFontWeight_Dev weight) {
// Map values from NORMAL (400) to HEAVY (900) to the range [0 .. 1], and
// values below NORMAL to the range [-0.6 .. 0]. NORMAL should map to 0.
@@ -234,28 +243,18 @@ int32_t PepperTrueTypeFontMac::Describe(
if (symbolic_traits & kCTFontBoldTrait) {
desc->weight = PP_TRUETYPEFONTWEIGHT_BOLD;
} else {
- base::mac::ScopedCFTypeRef<CFNumberRef> weight_trait_ref(
- static_cast<CFNumberRef>(
- CFDictionaryGetValue(traits_ref, kCTFontWeightTrait)));
- if (weight_trait_ref) {
- float weight;
- if (CFNumberGetValue(weight_trait_ref, kCFNumberFloat32Type, &weight))
- desc->weight = GetPepperWeight(weight);
- }
+ float weight;
+ if (FindFloat(traits_ref, kCTFontWeightTrait, &weight))
+ desc->weight = GetPepperWeight(weight);
}
if (symbolic_traits & kCTFontCondensedTrait) {
desc->width = PP_TRUETYPEFONTWIDTH_CONDENSED;
} else if (symbolic_traits & kCTFontExpandedTrait) {
desc->width = PP_TRUETYPEFONTWIDTH_EXPANDED;
} else {
- base::mac::ScopedCFTypeRef<CFNumberRef> width_trait_ref(
- static_cast<CFNumberRef>(
- CFDictionaryGetValue(traits_ref, kCTFontWidthTrait)));
- if (width_trait_ref) {
- float width;
- if (CFNumberGetValue(width_trait_ref, kCFNumberFloat32Type, &width))
- desc->width = GetPepperWidth(width);
- }
+ float width;
+ if (FindFloat(traits_ref, kCTFontWidthTrait, &width))
+ desc->width = GetPepperWidth(width);
}
// Character set isn't supported on Mac.
diff --git a/content/renderer/pepper/pepper_truetype_font_win.cc b/content/renderer/pepper/pepper_truetype_font_win.cc
index 2e24d7c..ea6a1e9 100644
--- a/content/renderer/pepper/pepper_truetype_font_win.cc
+++ b/content/renderer/pepper/pepper_truetype_font_win.cc
@@ -113,7 +113,7 @@ int32_t PepperTrueTypeFontWin::Describe(
desc->style = font_desc.lfItalic ? PP_TRUETYPEFONTSTYLE_ITALIC :
PP_TRUETYPEFONTSTYLE_NORMAL;
desc->weight = static_cast<PP_TrueTypeFontWeight_Dev>(font_desc.lfWeight);
- desc->width = PP_TRUETYPEFONTWIDTH_NORMAL;
+ desc->width = PP_TRUETYPEFONTWIDTH_NORMAL; // TODO(bbudge) support widths.
desc->charset =
static_cast<PP_TrueTypeFontCharset_Dev>(font_desc.lfCharSet);
diff --git a/ppapi/api/dev/ppb_truetype_font_dev.idl b/ppapi/api/dev/ppb_truetype_font_dev.idl
index 6460c17..b327eec 100644
--- a/ppapi/api/dev/ppb_truetype_font_dev.idl
+++ b/ppapi/api/dev/ppb_truetype_font_dev.idl
@@ -34,7 +34,7 @@ enum PP_TrueTypeFontFamily_Dev {
};
/**
- * The PP_TrueTypeFontStyle_Dev defines font styles.
+ * The PP_TrueTypeFontStyle_Dev enum defines font styles.
*/
[assert_size(4)]
enum PP_TrueTypeFontStyle_Dev {
@@ -43,7 +43,7 @@ enum PP_TrueTypeFontStyle_Dev {
};
/**
- * The PP_TrueTypeFontWeight_Dev defines font weights.
+ * The PP_TrueTypeFontWeight_Dev enum defines font weights.
*/
[assert_size(4)]
enum PP_TrueTypeFontWeight_Dev {
@@ -59,7 +59,7 @@ enum PP_TrueTypeFontWeight_Dev {
};
/**
- * The PP_TrueTypeFontWidth_Dev defines font widths.
+ * The PP_TrueTypeFontWidth_Dev enum defines font widths.
*/
[assert_size(4)]
enum PP_TrueTypeFontWidth_Dev {
@@ -75,7 +75,7 @@ enum PP_TrueTypeFontWidth_Dev {
};
/**
- * The PP_TrueTypeFontCharset defines font character sets.
+ * The PP_TrueTypeFontCharset enum defines font character sets.
*/
[assert_size(4)]
enum PP_TrueTypeFontCharset_Dev {
@@ -101,8 +101,8 @@ enum PP_TrueTypeFontCharset_Dev {
};
/**
- * The <code>PP_TrueTypeFontDesc</code> structure describes a TrueType font. It
- * is passed to Create, and returned by Describe.
+ * The <code>PP_TrueTypeFontDesc</code> struct describes a TrueType font. It is
+ * passed to Create(), and returned by Describe().
*/
[assert_size(40)]
struct PP_TrueTypeFontDesc_Dev {
@@ -117,14 +117,19 @@ struct PP_TrueTypeFontDesc_Dev {
/** This value specifies a generic font family. If a family name string is
* provided when creating a font, this is ignored. */
PP_TrueTypeFontFamily_Dev generic_family;
+
/** This value specifies the font style. */
PP_TrueTypeFontStyle_Dev style;
+
/** This value specifies the font weight. */
PP_TrueTypeFontWeight_Dev weight;
+
/** This value specifies the font width, for condensed or expanded fonts */
PP_TrueTypeFontWidth_Dev width;
+
/** This value specifies a character set. */
PP_TrueTypeFontCharset_Dev charset;
+
/**
* Ensure that this struct is 40-bytes wide by padding the end. In some
* compilers, PP_Var is 8-byte aligned, so those compilers align this struct
@@ -155,6 +160,30 @@ interface PPB_TrueTypeFont_Dev {
[in] PP_CompletionCallback callback);
/**
+ * Gets an array of TrueType font descriptors for a given font family. These
+ * descriptors can be used to create a font in that family and matching the
+ * descriptor attributes.
+ *
+ * @param[in] instance A <code>PP_Instance</code> requesting the font
+ * descriptors.
+ * @param[in] family A <code>PP_Var</code> holding a string specifying the
+ * font family.
+ * @param[in] output A <code>PP_ArrayOutput</code> to hold the descriptors.
+ * The output is an array of <code>PP_TrueTypeFontDesc</code> structs. Each
+ * desc contains a PP_Var for the family name which must be released.
+ * @param[in] callback A <code>PP_CompletionCallback</code> to be called upon
+ * completion of GetFontsInFamily.
+ *
+ * @return If >= 0, the number of font descriptors returned, otherwise an
+ * error code from <code>pp_errors.h</code>.
+ */
+ [singleton,api=PPB_TrueTypeFont_Singleton_API]
+ int32_t GetFontsInFamily([in] PP_Instance instance,
+ [in] PP_Var family,
+ [in] PP_ArrayOutput output,
+ [in] PP_CompletionCallback callback);
+
+ /**
* Creates a font resource matching the given font characteristics. The
* resource id will be non-zero on success, or zero on failure.
*
@@ -168,7 +197,7 @@ interface PPB_TrueTypeFont_Dev {
/**
* Determines if the given resource is a TrueType font.
*
- * @param[in] resource A <code>PP_Resource</code> corresponding to a font.
+ * @param[in] resource A <code>PP_Resource</code> corresponding to a resource.
*
* @return <code>PP_TRUE</code> if the resource is a
* <code>PPB_TrueTypeFont_Dev</code>, <code>PP_FALSE</code> otherwise.
@@ -197,8 +226,8 @@ interface PPB_TrueTypeFont_Dev {
[in] PP_CompletionCallback callback);
/**
- * Gets an array of identifying tags for each table in the font.
- * These tags can be used to request specific tables using GetTable.
+ * Gets an array of identifying tags for each table in the font. These tags
+ * can be used to request specific tables using GetTable.
*
* @param[in] font A <code>PP_Resource</code> corresponding to a font.
* @param[in] output A <code>PP_ArrayOutput</code> to hold the tags.
diff --git a/ppapi/c/dev/ppb_truetype_font_dev.h b/ppapi/c/dev/ppb_truetype_font_dev.h
index c8f3673..5172cae 100644
--- a/ppapi/c/dev/ppb_truetype_font_dev.h
+++ b/ppapi/c/dev/ppb_truetype_font_dev.h
@@ -3,7 +3,7 @@
* found in the LICENSE file.
*/
-/* From dev/ppb_truetype_font_dev.idl modified Wed Apr 10 11:41:36 2013. */
+/* From dev/ppb_truetype_font_dev.idl modified Wed Apr 17 15:38:46 2013. */
#ifndef PPAPI_C_DEV_PPB_TRUETYPE_FONT_DEV_H_
#define PPAPI_C_DEV_PPB_TRUETYPE_FONT_DEV_H_
@@ -51,7 +51,7 @@ typedef enum {
PP_COMPILE_ASSERT_SIZE_IN_BYTES(PP_TrueTypeFontFamily_Dev, 4);
/**
- * The PP_TrueTypeFontStyle_Dev defines font styles.
+ * The PP_TrueTypeFontStyle_Dev enum defines font styles.
*/
typedef enum {
PP_TRUETYPEFONTSTYLE_NORMAL = 0,
@@ -60,7 +60,7 @@ typedef enum {
PP_COMPILE_ASSERT_SIZE_IN_BYTES(PP_TrueTypeFontStyle_Dev, 4);
/**
- * The PP_TrueTypeFontWeight_Dev defines font weights.
+ * The PP_TrueTypeFontWeight_Dev enum defines font weights.
*/
typedef enum {
PP_TRUETYPEFONTWEIGHT_THIN = 100,
@@ -76,7 +76,7 @@ typedef enum {
PP_COMPILE_ASSERT_SIZE_IN_BYTES(PP_TrueTypeFontWeight_Dev, 4);
/**
- * The PP_TrueTypeFontWidth_Dev defines font widths.
+ * The PP_TrueTypeFontWidth_Dev enum defines font widths.
*/
typedef enum {
PP_TRUETYPEFONTWIDTH_ULTRACONDENSED = 0,
@@ -92,7 +92,7 @@ typedef enum {
PP_COMPILE_ASSERT_SIZE_IN_BYTES(PP_TrueTypeFontWidth_Dev, 4);
/**
- * The PP_TrueTypeFontCharset defines font character sets.
+ * The PP_TrueTypeFontCharset enum defines font character sets.
*/
typedef enum {
PP_TRUETYPEFONTCHARSET_ANSI = 0,
@@ -125,8 +125,8 @@ PP_COMPILE_ASSERT_SIZE_IN_BYTES(PP_TrueTypeFontCharset_Dev, 4);
* @{
*/
/**
- * The <code>PP_TrueTypeFontDesc</code> structure describes a TrueType font. It
- * is passed to Create, and returned by Describe.
+ * The <code>PP_TrueTypeFontDesc</code> struct describes a TrueType font. It is
+ * passed to Create(), and returned by Describe().
*/
struct PP_TrueTypeFontDesc_Dev {
/**
@@ -183,6 +183,28 @@ struct PPB_TrueTypeFont_Dev_0_1 {
struct PP_ArrayOutput output,
struct PP_CompletionCallback callback);
/**
+ * Gets an array of TrueType font descriptors for a given font family. These
+ * descriptors can be used to create a font in that family and matching the
+ * descriptor attributes.
+ *
+ * @param[in] instance A <code>PP_Instance</code> requesting the font
+ * descriptors.
+ * @param[in] family A <code>PP_Var</code> holding a string specifying the
+ * font family.
+ * @param[in] output A <code>PP_ArrayOutput</code> to hold the descriptors.
+ * The output is an array of <code>PP_TrueTypeFontDesc</code> structs. Each
+ * desc contains a PP_Var for the family name which must be released.
+ * @param[in] callback A <code>PP_CompletionCallback</code> to be called upon
+ * completion of GetFontsInFamily.
+ *
+ * @return If >= 0, the number of font descriptors returned, otherwise an
+ * error code from <code>pp_errors.h</code>.
+ */
+ int32_t (*GetFontsInFamily)(PP_Instance instance,
+ struct PP_Var family,
+ struct PP_ArrayOutput output,
+ struct PP_CompletionCallback callback);
+ /**
* Creates a font resource matching the given font characteristics. The
* resource id will be non-zero on success, or zero on failure.
*
@@ -195,7 +217,7 @@ struct PPB_TrueTypeFont_Dev_0_1 {
/**
* Determines if the given resource is a TrueType font.
*
- * @param[in] resource A <code>PP_Resource</code> corresponding to a font.
+ * @param[in] resource A <code>PP_Resource</code> corresponding to a resource.
*
* @return <code>PP_TRUE</code> if the resource is a
* <code>PPB_TrueTypeFont_Dev</code>, <code>PP_FALSE</code> otherwise.
@@ -222,8 +244,8 @@ struct PPB_TrueTypeFont_Dev_0_1 {
struct PP_TrueTypeFontDesc_Dev* desc,
struct PP_CompletionCallback callback);
/**
- * Gets an array of identifying tags for each table in the font.
- * These tags can be used to request specific tables using GetTable.
+ * Gets an array of identifying tags for each table in the font. These tags
+ * can be used to request specific tables using GetTable.
*
* @param[in] font A <code>PP_Resource</code> corresponding to a font.
* @param[in] output A <code>PP_ArrayOutput</code> to hold the tags.
diff --git a/ppapi/cpp/dev/truetype_font_dev.cc b/ppapi/cpp/dev/truetype_font_dev.cc
index 3de81fd..b10348a 100644
--- a/ppapi/cpp/dev/truetype_font_dev.cc
+++ b/ppapi/cpp/dev/truetype_font_dev.cc
@@ -4,7 +4,6 @@
#include "ppapi/cpp/dev/truetype_font_dev.h"
-#include <stdio.h>
#include <string.h> // memcpy
#include "ppapi/c/dev/ppb_truetype_font_dev.h"
@@ -41,7 +40,7 @@ TrueTypeFontDesc_Dev::TrueTypeFontDesc_Dev(
PassRef,
const PP_TrueTypeFontDesc_Dev& pp_desc) {
desc_ = pp_desc;
- family_ = Var(PASS_REF, pp_desc.family);
+ set_family(Var(PASS_REF, pp_desc.family));
}
TrueTypeFontDesc_Dev::TrueTypeFontDesc_Dev(const TrueTypeFontDesc_Dev& other) {
@@ -61,12 +60,12 @@ TrueTypeFontDesc_Dev& TrueTypeFontDesc_Dev::operator=(
if (this == &other)
return *this;
- desc_ = other.desc_;
- // Be careful about the refcount of the string, the assignment above doesn't
- // copy a ref. The assignments below take a ref to the new name and copy the
- // PP_Var into the wrapped descriptor.
- family_ = other.family();
- desc_.family = family_.pp_var();
+ set_family(other.family());
+ set_generic_family(other.generic_family());
+ set_style(other.style());
+ set_weight(other.weight());
+ set_width(other.width());
+ set_charset(other.charset());
return *this;
}
@@ -104,6 +103,21 @@ int32_t TrueTypeFont_Dev::GetFontFamilies(
return cc.MayForce(PP_ERROR_NOINTERFACE);
}
+// static
+int32_t TrueTypeFont_Dev::GetFontsInFamily(
+ const InstanceHandle& instance,
+ const Var& family,
+ const CompletionCallbackWithOutput<std::vector<TrueTypeFontDesc_Dev> >& cc)
+ {
+ if (has_interface<PPB_TrueTypeFont_Dev_0_1>()) {
+ return get_interface<PPB_TrueTypeFont_Dev_0_1>()->GetFontsInFamily(
+ instance.pp_instance(),
+ family.pp_var(),
+ cc.output(), cc.pp_completion_callback());
+ }
+ return cc.MayForce(PP_ERROR_NOINTERFACE);
+}
+
int32_t TrueTypeFont_Dev::Describe(
const CompletionCallbackWithOutput<TrueTypeFontDesc_Dev>& cc) {
if (has_interface<PPB_TrueTypeFont_Dev_0_1>()) {
diff --git a/ppapi/cpp/dev/truetype_font_dev.h b/ppapi/cpp/dev/truetype_font_dev.h
index a2c4369..cdaeade 100644
--- a/ppapi/cpp/dev/truetype_font_dev.h
+++ b/ppapi/cpp/dev/truetype_font_dev.h
@@ -27,14 +27,17 @@ class TrueTypeFontDesc_Dev {
/// Default constructor for creating a <code>TrueTypeFontDesc_Dev</code>
/// object.
TrueTypeFontDesc_Dev();
+
/// Constructor that takes an existing <code>PP_TrueTypeFontDesc_Dev</code>
/// structure. The 'family' PP_Var field in the structure will be managed by
/// this instance.
TrueTypeFontDesc_Dev(PassRef, const PP_TrueTypeFontDesc_Dev& pp_desc);
+
/// The copy constructor for <code>TrueTypeFontDesc_Dev</code>.
///
/// @param[in] other A reference to a <code>TrueTypeFontDesc_Dev</code>.
TrueTypeFontDesc_Dev(const TrueTypeFontDesc_Dev& other);
+
~TrueTypeFontDesc_Dev();
TrueTypeFontDesc_Dev& operator=(const TrueTypeFontDesc_Dev& other);
@@ -81,8 +84,6 @@ class TrueTypeFontDesc_Dev {
}
private:
- friend class TrueTypeFont_Dev;
-
pp::Var family_; // This manages the PP_Var embedded in desc_.
PP_TrueTypeFontDesc_Dev desc_;
};
@@ -125,7 +126,26 @@ class TrueTypeFont_Dev : public Resource {
/// code from <code>pp_errors.h</code>.
static int32_t GetFontFamilies(
const InstanceHandle& instance,
- const CompletionCallbackWithOutput<std::vector<Var> >& cc);
+ const CompletionCallbackWithOutput<std::vector<Var> >& callback);
+
+ /// Gets an array of TrueType font descriptors for a given font family. These
+ /// descriptors can be used to create a font in that family and matching the
+ /// descriptor attributes.
+ ///
+ /// @param[in] instance A <code>PP_Instance</code> requesting the font
+ /// descriptors.
+ /// @param[in] family A <code>Var</code> holding a string specifying the font
+ /// family.
+ /// @param[in] callback A <code>CompletionCallbackWithOutput</code> to be
+ /// called upon completion of GetFontsInFamily.
+ ///
+ /// @return If >= 0, the number of font descriptors returned, otherwise an
+ /// error code from <code>pp_errors.h</code>.
+ static int32_t GetFontsInFamily(
+ const InstanceHandle& instance,
+ const Var& family,
+ const CompletionCallbackWithOutput<std::vector<TrueTypeFontDesc_Dev> >&
+ callback);
/// Returns a description of the given font resource. This description may
/// differ from the description passed to Create, reflecting the host's font
@@ -137,7 +157,7 @@ class TrueTypeFont_Dev : public Resource {
/// @return A return code from <code>pp_errors.h</code>. If an error code is
/// returned, the descriptor will be left unchanged.
int32_t Describe(
- const CompletionCallbackWithOutput<TrueTypeFontDesc_Dev>& cc);
+ const CompletionCallbackWithOutput<TrueTypeFontDesc_Dev>& callback);
/// Gets an array of identifying tags for each table in the font.
/// These tags can be used to request specific tables using GetTable.
@@ -148,7 +168,7 @@ class TrueTypeFont_Dev : public Resource {
/// @return If >= 0, the number of table tags returned, otherwise an error
/// code from <code>pp_errors.h</code>.
int32_t GetTableTags(
- const CompletionCallbackWithOutput<std::vector<uint32_t> >& cc);
+ const CompletionCallbackWithOutput<std::vector<uint32_t> >& callback);
/// Copies the given font table into client memory.
///
@@ -158,8 +178,6 @@ class TrueTypeFont_Dev : public Resource {
/// @param[in] offset The offset into the font table.
/// @param[in] max_data_length The maximum number of bytes to transfer from
/// <code>offset</code>.
- /// @param[in] output A <code>PP_ArrayOutput</code> to hold the font data.
- /// The data is an array of bytes.
/// @param[in] callback A <code>CompletionCallbackWithOutput</code> to be
/// called upon completion of GetTable.
///
@@ -169,7 +187,7 @@ class TrueTypeFont_Dev : public Resource {
uint32_t table,
int32_t offset,
int32_t max_data_length,
- const CompletionCallbackWithOutput<std::vector<char> >& cc);
+ const CompletionCallbackWithOutput<std::vector<char> >& callback);
};
namespace internal {
@@ -192,6 +210,53 @@ struct CallbackOutputTraits<TrueTypeFontDesc_Dev> {
}
};
+class TrueTypeFontDescArrayOutputAdapterWithStorage
+ : public ArrayOutputAdapter<PP_TrueTypeFontDesc_Dev> {
+ public:
+ TrueTypeFontDescArrayOutputAdapterWithStorage() {
+ set_output(&temp_storage_);
+ };
+
+ virtual ~TrueTypeFontDescArrayOutputAdapterWithStorage() {
+ if (!temp_storage_.empty()) {
+ // An easy way to release the resource references held by |temp_storage_|.
+ output();
+ }
+ };
+
+ std::vector<TrueTypeFontDesc_Dev>& output() {
+ PP_DCHECK(output_storage_.empty());
+ typedef std::vector<PP_TrueTypeFontDesc_Dev> Entries;
+ for (Entries::iterator it = temp_storage_.begin();
+ it != temp_storage_.end(); ++it)
+ output_storage_.push_back(TrueTypeFontDesc_Dev(PASS_REF, *it));
+ temp_storage_.clear();
+ return output_storage_;
+ }
+
+ private:
+ std::vector<PP_TrueTypeFontDesc_Dev> temp_storage_;
+ std::vector<TrueTypeFontDesc_Dev> output_storage_;
+};
+
+// A specialization of CallbackOutputTraits to provide the callback system the
+// information on how to handle vectors of TrueTypeFontDesc_Dev. This converts
+// PP_TrueTypeFontDesc_Dev to TrueTypeFontDesc_Dev when passing to the plugin.
+template<>
+struct CallbackOutputTraits< std::vector<TrueTypeFontDesc_Dev> > {
+ typedef PP_ArrayOutput APIArgType;
+ typedef TrueTypeFontDescArrayOutputAdapterWithStorage StorageType;
+
+ static inline APIArgType StorageToAPIArg(StorageType& t) {
+ return t.pp_array_output();
+ }
+
+ static inline std::vector<TrueTypeFontDesc_Dev>& StorageToPluginArg(
+ StorageType& t) {
+ return t.output();
+ }
+};
+
} // namespace internal
} // namespace pp
diff --git a/ppapi/native_client/src/untrusted/pnacl_irt_shim/pnacl_shim.c b/ppapi/native_client/src/untrusted/pnacl_irt_shim/pnacl_shim.c
index 04b4d3e..c07d029 100644
--- a/ppapi/native_client/src/untrusted/pnacl_irt_shim/pnacl_shim.c
+++ b/ppapi/native_client/src/untrusted/pnacl_irt_shim/pnacl_shim.c
@@ -2215,6 +2215,12 @@ int32_t Pnacl_M26_PPB_TrueTypeFont_Dev_GetFontFamilies(PP_Instance instance, str
}
static __attribute__((pnaclcall))
+int32_t Pnacl_M26_PPB_TrueTypeFont_Dev_GetFontsInFamily(PP_Instance instance, struct PP_Var family, struct PP_ArrayOutput output, struct PP_CompletionCallback callback) {
+ const struct PPB_TrueTypeFont_Dev_0_1 *iface = Pnacl_WrapperInfo_PPB_TrueTypeFont_Dev_0_1.real_iface;
+ return iface->GetFontsInFamily(instance, family, output, callback);
+}
+
+static __attribute__((pnaclcall))
PP_Resource Pnacl_M26_PPB_TrueTypeFont_Dev_Create(PP_Instance instance, const struct PP_TrueTypeFontDesc_Dev* desc) {
const struct PPB_TrueTypeFont_Dev_0_1 *iface = Pnacl_WrapperInfo_PPB_TrueTypeFont_Dev_0_1.real_iface;
return iface->Create(instance, desc);
@@ -4597,6 +4603,7 @@ struct PPB_Testing_Dev_0_91 Pnacl_Wrappers_PPB_Testing_Dev_0_91 = {
struct PPB_TrueTypeFont_Dev_0_1 Pnacl_Wrappers_PPB_TrueTypeFont_Dev_0_1 = {
.GetFontFamilies = (int32_t (*)(PP_Instance instance, struct PP_ArrayOutput output, struct PP_CompletionCallback callback))&Pnacl_M26_PPB_TrueTypeFont_Dev_GetFontFamilies,
+ .GetFontsInFamily = (int32_t (*)(PP_Instance instance, struct PP_Var family, struct PP_ArrayOutput output, struct PP_CompletionCallback callback))&Pnacl_M26_PPB_TrueTypeFont_Dev_GetFontsInFamily,
.Create = (PP_Resource (*)(PP_Instance instance, const struct PP_TrueTypeFontDesc_Dev* desc))&Pnacl_M26_PPB_TrueTypeFont_Dev_Create,
.IsTrueTypeFont = (PP_Bool (*)(PP_Resource resource))&Pnacl_M26_PPB_TrueTypeFont_Dev_IsTrueTypeFont,
.Describe = (int32_t (*)(PP_Resource font, struct PP_TrueTypeFontDesc_Dev* desc, struct PP_CompletionCallback callback))&Pnacl_M26_PPB_TrueTypeFont_Dev_Describe,
diff --git a/ppapi/proxy/ppapi_messages.h b/ppapi/proxy/ppapi_messages.h
index 78f9eda..42ef363 100644
--- a/ppapi/proxy/ppapi_messages.h
+++ b/ppapi/proxy/ppapi_messages.h
@@ -1445,6 +1445,11 @@ IPC_MESSAGE_CONTROL0(PpapiHostMsg_TrueTypeFontSingleton_Create)
IPC_MESSAGE_CONTROL0(PpapiHostMsg_TrueTypeFontSingleton_GetFontFamilies)
IPC_MESSAGE_CONTROL1(PpapiPluginMsg_TrueTypeFontSingleton_GetFontFamiliesReply,
std::vector<std::string> /* font_families */)
+IPC_MESSAGE_CONTROL1(PpapiHostMsg_TrueTypeFontSingleton_GetFontsInFamily,
+ std::string /* family */)
+IPC_MESSAGE_CONTROL1(PpapiPluginMsg_TrueTypeFontSingleton_GetFontsInFamilyReply,
+ std::vector<ppapi::proxy::SerializedTrueTypeFontDesc>
+ /* fonts */)
IPC_MESSAGE_CONTROL1(PpapiHostMsg_TrueTypeFont_Create,
ppapi::proxy::SerializedTrueTypeFontDesc /* desc */)
IPC_MESSAGE_CONTROL0(PpapiHostMsg_TrueTypeFont_Describe)
diff --git a/ppapi/proxy/truetype_font_resource.cc b/ppapi/proxy/truetype_font_resource.cc
index 0b07195..1de32abb 100644
--- a/ppapi/proxy/truetype_font_resource.cc
+++ b/ppapi/proxy/truetype_font_resource.cc
@@ -44,7 +44,6 @@ PPB_TrueTypeFont_API* TrueTypeFontResource::AsPPB_TrueTypeFont_API() {
int32_t TrueTypeFontResource::Describe(
PP_TrueTypeFontDesc_Dev* desc,
scoped_refptr<TrackedCallback> callback) {
-
Call<PpapiPluginMsg_TrueTypeFont_DescribeReply>(RENDERER,
PpapiHostMsg_TrueTypeFont_Describe(),
base::Bind(&TrueTypeFontResource::OnPluginMsgDescribeComplete, this,
@@ -83,6 +82,7 @@ void TrueTypeFontResource::OnPluginMsgDescribeComplete(
int32_t result = params.result();
if (result == PP_OK)
desc.CopyToPPTrueTypeFontDesc(pp_desc);
+
callback->Run(result);
}
diff --git a/ppapi/proxy/truetype_font_singleton_resource.cc b/ppapi/proxy/truetype_font_singleton_resource.cc
index b812bf1..1fee97b 100644
--- a/ppapi/proxy/truetype_font_singleton_resource.cc
+++ b/ppapi/proxy/truetype_font_singleton_resource.cc
@@ -5,9 +5,12 @@
#include "ppapi/proxy/truetype_font_singleton_resource.h"
#include "ppapi/proxy/ppapi_messages.h"
+#include "ppapi/proxy/serialized_structs.h"
#include "ppapi/shared_impl/array_writer.h"
+#include "ppapi/shared_impl/ppapi_globals.h"
#include "ppapi/shared_impl/tracked_callback.h"
#include "ppapi/shared_impl/var.h"
+#include "ppapi/shared_impl/var_tracker.h"
namespace ppapi {
namespace proxy {
@@ -39,11 +42,30 @@ int32_t TrueTypeFontSingletonResource::GetFontFamilies(
return PP_OK_COMPLETIONPENDING;
}
+int32_t TrueTypeFontSingletonResource::GetFontsInFamily(
+ PP_Instance instance,
+ PP_Var family,
+ const PP_ArrayOutput& output,
+ const scoped_refptr<TrackedCallback>& callback) {
+ scoped_refptr<StringVar> family_var = StringVar::FromPPVar(family);
+ const uint32_t kMaxFamilySizeInBytes = 1024;
+ if (!family_var || family_var->value().size() > kMaxFamilySizeInBytes)
+ return PP_ERROR_BADARGUMENT;
+ Call<PpapiPluginMsg_TrueTypeFontSingleton_GetFontsInFamilyReply>(BROWSER,
+ PpapiHostMsg_TrueTypeFontSingleton_GetFontsInFamily(family_var->value()),
+ base::Bind(
+ &TrueTypeFontSingletonResource::OnPluginMsgGetFontsInFamilyComplete,
+ this, callback, output));
+ return PP_OK_COMPLETIONPENDING;
+}
+
void TrueTypeFontSingletonResource::OnPluginMsgGetFontFamiliesComplete(
scoped_refptr<TrackedCallback> callback,
PP_ArrayOutput array_output,
const ResourceMessageReplyParams& params,
const std::vector<std::string>& font_families) {
+ if (!TrackedCallback::IsPending(callback))
+ return;
// The result code should contain the data size if it's positive.
int32_t result = params.result();
DCHECK((result < 0 && font_families.size() == 0) ||
@@ -64,5 +86,36 @@ void TrueTypeFontSingletonResource::OnPluginMsgGetFontFamiliesComplete(
callback->Run(result);
}
+void TrueTypeFontSingletonResource::OnPluginMsgGetFontsInFamilyComplete(
+ scoped_refptr<TrackedCallback> callback,
+ PP_ArrayOutput array_output,
+ const ResourceMessageReplyParams& params,
+ const std::vector<SerializedTrueTypeFontDesc>& fonts) {
+ if (!TrackedCallback::IsPending(callback))
+ return;
+ // The result code should contain the data size if it's positive.
+ int32_t result = params.result();
+ DCHECK((result < 0 && fonts.size() == 0) ||
+ result == static_cast<int32_t>(fonts.size()));
+ ArrayWriter output;
+ output.set_pp_array_output(array_output);
+ if (output.is_valid()) {
+ // Convert the message data to an array of PP_TrueTypeFontDesc_Dev structs.
+ // Each desc has an embedded PP_Var containing the family name.
+ std::vector<PP_TrueTypeFontDesc_Dev> pp_fonts(fonts.size());
+ for (size_t i = 0; i < fonts.size(); i++)
+ fonts[i].CopyToPPTrueTypeFontDesc(&pp_fonts[i]);
+
+ if (!output.StoreVector(pp_fonts)) {
+ for (size_t i = 0; i < pp_fonts.size(); i++)
+ PpapiGlobals::Get()->GetVarTracker()->ReleaseVar(pp_fonts[i].family);
+ }
+ } else {
+ result = PP_ERROR_FAILED;
+ }
+
+ callback->Run(result);
+}
+
} // namespace proxy
} // namespace ppapi
diff --git a/ppapi/proxy/truetype_font_singleton_resource.h b/ppapi/proxy/truetype_font_singleton_resource.h
index 03c9c7d..dee5863 100644
--- a/ppapi/proxy/truetype_font_singleton_resource.h
+++ b/ppapi/proxy/truetype_font_singleton_resource.h
@@ -18,7 +18,7 @@ class TrackedCallback;
namespace proxy {
-struct SerializedTrueTypeFontDescription;
+struct SerializedTrueTypeFontDesc;
// This handles the singleton calls (that don't take a PP_Resource parameter)
// on the TrueType font interface.
@@ -38,6 +38,11 @@ class TrueTypeFontSingletonResource
PP_Instance instance,
const PP_ArrayOutput& output,
const scoped_refptr<TrackedCallback>& callback) OVERRIDE;
+ virtual int32_t GetFontsInFamily(
+ PP_Instance instance,
+ PP_Var family,
+ const PP_ArrayOutput& output,
+ const scoped_refptr<TrackedCallback>& callback) OVERRIDE;
private:
void OnPluginMsgGetFontFamiliesComplete(
@@ -45,6 +50,11 @@ class TrueTypeFontSingletonResource
PP_ArrayOutput array_output,
const ResourceMessageReplyParams& params,
const std::vector<std::string>& data);
+ void OnPluginMsgGetFontsInFamilyComplete(
+ scoped_refptr<TrackedCallback> callback,
+ PP_ArrayOutput array_output,
+ const ResourceMessageReplyParams& params,
+ const std::vector<SerializedTrueTypeFontDesc>& fonts);
DISALLOW_COPY_AND_ASSIGN(TrueTypeFontSingletonResource);
};
diff --git a/ppapi/tests/test_truetype_font.cc b/ppapi/tests/test_truetype_font.cc
index 7644b95..67587a0 100644
--- a/ppapi/tests/test_truetype_font.cc
+++ b/ppapi/tests/test_truetype_font.cc
@@ -6,7 +6,6 @@
#include "ppapi/tests/test_truetype_font.h"
-#include <stdio.h>
#include <string.h>
#include <algorithm>
#include <limits>
@@ -86,6 +85,7 @@ TestTrueTypeFont::~TestTrueTypeFont() {
void TestTrueTypeFont::RunTests(const std::string& filter) {
RUN_TEST(GetFontFamilies, filter);
+ RUN_TEST(GetFontsInFamily, filter);
RUN_TEST(Create, filter);
RUN_TEST(Describe, filter);
RUN_TEST(GetTableTags, filter);
@@ -123,6 +123,67 @@ std::string TestTrueTypeFont::TestGetFontFamilies() {
PASS();
}
+std::string TestTrueTypeFont::TestGetFontsInFamily() {
+ {
+ // Get the list of all font families.
+ TestCompletionCallbackWithOutput< std::vector<pp::Var> > cc(
+ instance_->pp_instance(), false);
+ cc.WaitForResult(pp::TrueTypeFont_Dev::GetFontFamilies(instance_,
+ cc.GetCallback()));
+ // Try to use a common family that is likely to have multiple variations.
+ const std::vector<pp::Var> families = cc.output();
+ pp::Var family("Arial");
+ if (std::find(families.begin(), families.end(), family) == families.end()) {
+ family = pp::Var("Times");
+ if (std::find(families.begin(), families.end(), family) == families.end())
+ family = families[0]; // Just use the first family.
+ }
+
+ // GetFontsInFamily: A valid instance should be able to enumerate fonts
+ // in a given family.
+ TestCompletionCallbackWithOutput< std::vector<pp::TrueTypeFontDesc_Dev> >
+ cc2(instance_->pp_instance(), false);
+ cc2.WaitForResult(pp::TrueTypeFont_Dev::GetFontsInFamily(
+ instance_,
+ family,
+ cc2.GetCallback()));
+ std::vector<pp::TrueTypeFontDesc_Dev> fonts_in_family = cc2.output();
+ ASSERT_NE(0, fonts_in_family.size());
+ ASSERT_EQ(static_cast<int32_t>(fonts_in_family.size()), cc2.result());
+
+ // We should be able to create any of the returned fonts without fallback.
+ for (size_t i = 0; i < fonts_in_family.size(); ++i) {
+ pp::TrueTypeFontDesc_Dev& font_in_family = fonts_in_family[i];
+ pp::TrueTypeFont_Dev font(instance_, font_in_family);
+ TestCompletionCallbackWithOutput<pp::TrueTypeFontDesc_Dev> cc(
+ instance_->pp_instance(), false);
+ cc.WaitForResult(font.Describe(cc.GetCallback()));
+ const pp::TrueTypeFontDesc_Dev desc = cc.output();
+
+ ASSERT_EQ(family, desc.family());
+ ASSERT_EQ(font_in_family.style(), desc.style());
+ ASSERT_EQ(font_in_family.weight(), desc.weight());
+ }
+ }
+ {
+ // Using an invalid instance should fail.
+ TestCompletionCallbackWithOutput< std::vector<pp::TrueTypeFontDesc_Dev> >
+ cc(instance_->pp_instance(), false);
+ pp::Var family("Times");
+ cc.WaitForResult(
+ ppb_truetype_font_interface_->GetFontsInFamily(
+ kInvalidInstance,
+ family.pp_var(),
+ cc.GetCallback().output(),
+ cc.GetCallback().pp_completion_callback()));
+ ASSERT_TRUE(cc.result() == PP_ERROR_FAILED ||
+ cc.result() == PP_ERROR_BADARGUMENT);
+ ASSERT_EQ(0, cc.output().size());
+ }
+
+ PASS();
+}
+
std::string TestTrueTypeFont::TestCreate() {
PP_Resource font;
PP_TrueTypeFontDesc_Dev desc = {
diff --git a/ppapi/tests/test_truetype_font.h b/ppapi/tests/test_truetype_font.h
index 90977c8..70ed8f9 100644
--- a/ppapi/tests/test_truetype_font.h
+++ b/ppapi/tests/test_truetype_font.h
@@ -23,6 +23,7 @@ class TestTrueTypeFont : public TestCase {
virtual void RunTests(const std::string& filter);
std::string TestGetFontFamilies();
+ std::string TestGetFontsInFamily();
std::string TestCreate();
std::string TestDescribe();
std::string TestGetTableTags();
diff --git a/ppapi/thunk/ppb_truetype_font_dev_thunk.cc b/ppapi/thunk/ppb_truetype_font_dev_thunk.cc
index 610914a..afed58e 100644
--- a/ppapi/thunk/ppb_truetype_font_dev_thunk.cc
+++ b/ppapi/thunk/ppb_truetype_font_dev_thunk.cc
@@ -2,7 +2,7 @@
// Use of this source code is governed by a BSD-style license that can be
// found in the LICENSE file.
-// From dev/ppb_truetype_font_dev.idl modified Wed Apr 10 11:59:27 2013.
+// From dev/ppb_truetype_font_dev.idl modified Wed Apr 17 15:38:46 2013.
#include "ppapi/c/dev/ppb_truetype_font_dev.h"
#include "ppapi/c/pp_completion_callback.h"
@@ -33,6 +33,21 @@ int32_t GetFontFamilies(PP_Instance instance,
enter.callback()));
}
+int32_t GetFontsInFamily(PP_Instance instance,
+ struct PP_Var family,
+ struct PP_ArrayOutput output,
+ struct PP_CompletionCallback callback) {
+ VLOG(4) << "PPB_TrueTypeFont_Dev::GetFontsInFamily()";
+ EnterInstanceAPI<PPB_TrueTypeFont_Singleton_API> enter(instance, callback);
+ if (enter.failed())
+ return enter.retval();
+ return enter.SetResult(enter.functions()->GetFontsInFamily(
+ instance,
+ family,
+ output,
+ enter.callback()));
+}
+
PP_Resource Create(PP_Instance instance,
const struct PP_TrueTypeFontDesc_Dev* desc) {
VLOG(4) << "PPB_TrueTypeFont_Dev::Create()";
@@ -88,6 +103,7 @@ int32_t GetTable(PP_Resource font,
const PPB_TrueTypeFont_Dev_0_1 g_ppb_truetypefont_dev_thunk_0_1 = {
&GetFontFamilies,
+ &GetFontsInFamily,
&Create,
&IsTrueTypeFont,
&Describe,
diff --git a/ppapi/thunk/ppb_truetype_font_singleton_api.h b/ppapi/thunk/ppb_truetype_font_singleton_api.h
index 514bab1..97c727d 100644
--- a/ppapi/thunk/ppb_truetype_font_singleton_api.h
+++ b/ppapi/thunk/ppb_truetype_font_singleton_api.h
@@ -24,6 +24,12 @@ class PPB_TrueTypeFont_Singleton_API {
const PP_ArrayOutput& output,
const scoped_refptr<TrackedCallback>& callback) = 0;
+ virtual int32_t GetFontsInFamily(
+ PP_Instance instance,
+ PP_Var family,
+ const PP_ArrayOutput& output,
+ const scoped_refptr<TrackedCallback>& callback) = 0;
+
static const SingletonResourceID kSingletonResourceID =
TRUETYPE_FONT_SINGLETON_ID;
};