Commit 720e1e62 authored by bbudge@chromium.org's avatar bbudge@chromium.org

Add Pepper TrueType font API call to enumerate fonts in a given family.

Adds a new function, GetFontsInFamily, to the PPB_TrueTypeFont_Dev interface.
This method returns an array of descriptors for every font in the given family
on the host platform.

Tests are currently disabled for Windows and Mac, since I got failures on XP and OSX 10.6 when landing them originally. I will re-enable them in follow on patches, which will be easier to land / revert if necessary. The tests pass locally for me on all platforms.

BUG=79375,230130
TEST=browser_tests, gtest_filter="PPAPIOutOfProcessTest.TrueTypeFont"

Review URL: https://chromiumcodereview.appspot.com/13913006

git-svn-id: svn://svn.chromium.org/chrome/trunk/src@195082 0039d316-1c4b-4281-b951-d872f2087c98
parent 76de6d1c
...@@ -8,6 +8,12 @@ ...@@ -8,6 +8,12 @@
#include <string> #include <string>
#include <vector> #include <vector>
namespace ppapi {
namespace proxy {
struct SerializedTrueTypeFontDesc;
}
}
namespace content { namespace content {
// Adds font family names on the host platform to the vector of strings. // Adds font family names on the host platform to the vector of strings.
...@@ -16,6 +22,15 @@ namespace content { ...@@ -16,6 +22,15 @@ namespace content {
// sure not to call this on a time-critical thread like the UI or I/O threads. // 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); 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 } // namespace content
#endif // CONTENT_BROWSER_RENDERER_HOST_PEPPER_PEPPER_TRUETYPE_FONT_LIST_H_ #endif // CONTENT_BROWSER_RENDERER_HOST_PEPPER_PEPPER_TRUETYPE_FONT_LIST_H_
...@@ -11,4 +11,10 @@ void GetFontFamilies_SlowBlocking(std::vector<std::string>* font_families) { ...@@ -11,4 +11,10 @@ void GetFontFamilies_SlowBlocking(std::vector<std::string>* font_families) {
NOTIMPLEMENTED(); // Font API isn't implemented on Android. 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 } // namespace content
...@@ -36,8 +36,10 @@ class FontMessageFilter : public ppapi::host::ResourceMessageFilter { ...@@ -36,8 +36,10 @@ class FontMessageFilter : public ppapi::host::ResourceMessageFilter {
private: private:
virtual ~FontMessageFilter(); virtual ~FontMessageFilter();
// Message handler. // Message handlers.
int32_t OnHostMsgGetFontFamilies(ppapi::host::HostMessageContext* context); int32_t OnHostMsgGetFontFamilies(ppapi::host::HostMessageContext* context);
int32_t OnHostMsgGetFontsInFamily(ppapi::host::HostMessageContext* context,
const std::string& family);
DISALLOW_COPY_AND_ASSIGN(FontMessageFilter); DISALLOW_COPY_AND_ASSIGN(FontMessageFilter);
}; };
...@@ -65,6 +67,9 @@ int32_t FontMessageFilter::OnResourceMessageReceived( ...@@ -65,6 +67,9 @@ int32_t FontMessageFilter::OnResourceMessageReceived(
PPAPI_DISPATCH_HOST_RESOURCE_CALL_0( PPAPI_DISPATCH_HOST_RESOURCE_CALL_0(
PpapiHostMsg_TrueTypeFontSingleton_GetFontFamilies, PpapiHostMsg_TrueTypeFontSingleton_GetFontFamilies,
OnHostMsgGetFontFamilies) OnHostMsgGetFontFamilies)
PPAPI_DISPATCH_HOST_RESOURCE_CALL(
PpapiHostMsg_TrueTypeFontSingleton_GetFontsInFamily,
OnHostMsgGetFontsInFamily)
IPC_END_MESSAGE_MAP() IPC_END_MESSAGE_MAP()
return PP_ERROR_FAILED; return PP_ERROR_FAILED;
} }
...@@ -86,6 +91,23 @@ int32_t FontMessageFilter::OnHostMsgGetFontFamilies( ...@@ -86,6 +91,23 @@ int32_t FontMessageFilter::OnHostMsgGetFontFamilies(
return result; 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 } // namespace
PepperTrueTypeFontListHost::PepperTrueTypeFontListHost( PepperTrueTypeFontListHost::PepperTrueTypeFontListHost(
......
...@@ -15,8 +15,8 @@ class BrowserPpapiHost; ...@@ -15,8 +15,8 @@ class BrowserPpapiHost;
class PepperTrueTypeFontListHost : public ppapi::host::ResourceHost { class PepperTrueTypeFontListHost : public ppapi::host::ResourceHost {
public: public:
PepperTrueTypeFontListHost(BrowserPpapiHost* host, PepperTrueTypeFontListHost(BrowserPpapiHost* host,
PP_Instance instance, PP_Instance instance,
PP_Resource resource); PP_Resource resource);
virtual ~PepperTrueTypeFontListHost(); virtual ~PepperTrueTypeFontListHost();
private: private:
......
...@@ -9,6 +9,8 @@ ...@@ -9,6 +9,8 @@
#include <string> #include <string>
#include "ppapi/proxy/serialized_structs.h"
namespace content { namespace content {
void GetFontFamilies_SlowBlocking(std::vector<std::string>* font_families) { void GetFontFamilies_SlowBlocking(std::vector<std::string>* font_families) {
...@@ -17,9 +19,46 @@ 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; int num_families = 0;
::pango_font_map_list_families(font_map, &families, &num_families); ::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])); font_families->push_back(::pango_font_family_get_name(families[i]));
g_free(families); 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 } // namespace content
...@@ -8,9 +8,32 @@ ...@@ -8,9 +8,32 @@
#include "base/mac/scoped_nsautorelease_pool.h" #include "base/mac/scoped_nsautorelease_pool.h"
#include "base/strings/sys_string_conversions.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 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) { void GetFontFamilies_SlowBlocking(std::vector<std::string>* font_families) {
base::mac::ScopedNSAutoreleasePool autorelease_pool; base::mac::ScopedNSAutoreleasePool autorelease_pool;
NSFontManager* fontManager = [[[NSFontManager alloc] init] autorelease]; NSFontManager* fontManager = [[[NSFontManager alloc] init] autorelease];
...@@ -20,4 +43,40 @@ void GetFontFamilies_SlowBlocking(std::vector<std::string>* font_families) { ...@@ -20,4 +43,40 @@ void GetFontFamilies_SlowBlocking(std::vector<std::string>* font_families) {
font_families->push_back(base::SysNSStringToUTF8(family_name)); 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 } // namespace content
...@@ -8,17 +8,21 @@ ...@@ -8,17 +8,21 @@
#include "base/utf_string_conversions.h" #include "base/utf_string_conversions.h"
#include "base/win/scoped_hdc.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 content {
namespace { namespace {
static int CALLBACK EnumFontFamExProc(ENUMLOGFONTEXW* logical_font, typedef std::vector<std::string> FontFamilyList;
NEWTEXTMETRICEXW* physical_font, typedef std::vector<ppapi::proxy::SerializedTrueTypeFontDesc> FontDescList;
DWORD font_type,
LPARAM lparam) { static int CALLBACK EnumFontFamiliesProc(ENUMLOGFONTEXW* logical_font,
std::vector<std::string>* font_families = NEWTEXTMETRICEXW* physical_font,
reinterpret_cast<std::vector<std::string>*>(lparam); DWORD font_type,
LPARAM lparam) {
FontFamilyList* font_families = reinterpret_cast<FontFamilyList*>(lparam);
if (font_families) { if (font_families) {
const LOGFONTW& lf = logical_font->elfLogFont; const LOGFONTW& lf = logical_font->elfLogFont;
if (lf.lfFaceName[0] && lf.lfFaceName[0] != '@' && if (lf.lfFaceName[0] && lf.lfFaceName[0] != '@' &&
...@@ -30,15 +34,50 @@ static int CALLBACK EnumFontFamExProc(ENUMLOGFONTEXW* logical_font, ...@@ -30,15 +34,50 @@ static int CALLBACK EnumFontFamExProc(ENUMLOGFONTEXW* logical_font,
return 1; 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 } // namespace
void GetFontFamilies_SlowBlocking(std::vector<std::string>* font_families) { void GetFontFamilies_SlowBlocking(FontFamilyList* font_families) {
LOGFONTW logfont; LOGFONTW logfont;
memset(&logfont, 0, sizeof(logfont)); memset(&logfont, 0, sizeof(logfont));
logfont.lfCharSet = DEFAULT_CHARSET; logfont.lfCharSet = DEFAULT_CHARSET;
base::win::ScopedCreateDC hdc(::GetDC(NULL)); base::win::ScopedCreateDC hdc(::GetDC(NULL));
::EnumFontFamiliesExW(hdc, &logfont, (FONTENUMPROCW)&EnumFontFamExProc, ::EnumFontFamiliesExW(hdc, &logfont, (FONTENUMPROCW)&EnumFontFamiliesProc,
(LPARAM)font_families, 0); (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 } // namespace content
...@@ -21,6 +21,15 @@ namespace content { ...@@ -21,6 +21,15 @@ namespace content {
namespace { 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) { float GetMacWeight(PP_TrueTypeFontWeight_Dev weight) {
// Map values from NORMAL (400) to HEAVY (900) to the range [0 .. 1], and // 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. // values below NORMAL to the range [-0.6 .. 0]. NORMAL should map to 0.
...@@ -234,28 +243,18 @@ int32_t PepperTrueTypeFontMac::Describe( ...@@ -234,28 +243,18 @@ int32_t PepperTrueTypeFontMac::Describe(
if (symbolic_traits & kCTFontBoldTrait) { if (symbolic_traits & kCTFontBoldTrait) {
desc->weight = PP_TRUETYPEFONTWEIGHT_BOLD; desc->weight = PP_TRUETYPEFONTWEIGHT_BOLD;
} else { } else {
base::mac::ScopedCFTypeRef<CFNumberRef> weight_trait_ref( float weight;
static_cast<CFNumberRef>( if (FindFloat(traits_ref, kCTFontWeightTrait, &weight))
CFDictionaryGetValue(traits_ref, kCTFontWeightTrait))); desc->weight = GetPepperWeight(weight);
if (weight_trait_ref) {
float weight;
if (CFNumberGetValue(weight_trait_ref, kCFNumberFloat32Type, &weight))
desc->weight = GetPepperWeight(weight);
}
} }
if (symbolic_traits & kCTFontCondensedTrait) { if (symbolic_traits & kCTFontCondensedTrait) {
desc->width = PP_TRUETYPEFONTWIDTH_CONDENSED; desc->width = PP_TRUETYPEFONTWIDTH_CONDENSED;
} else if (symbolic_traits & kCTFontExpandedTrait) { } else if (symbolic_traits & kCTFontExpandedTrait) {
desc->width = PP_TRUETYPEFONTWIDTH_EXPANDED; desc->width = PP_TRUETYPEFONTWIDTH_EXPANDED;
} else { } else {
base::mac::ScopedCFTypeRef<CFNumberRef> width_trait_ref( float width;
static_cast<CFNumberRef>( if (FindFloat(traits_ref, kCTFontWidthTrait, &width))
CFDictionaryGetValue(traits_ref, kCTFontWidthTrait))); desc->width = GetPepperWidth(width);
if (width_trait_ref) {
float width;
if (CFNumberGetValue(width_trait_ref, kCFNumberFloat32Type, &width))
desc->width = GetPepperWidth(width);
}
} }
// Character set isn't supported on Mac. // Character set isn't supported on Mac.
......
...@@ -113,7 +113,7 @@ int32_t PepperTrueTypeFontWin::Describe( ...@@ -113,7 +113,7 @@ int32_t PepperTrueTypeFontWin::Describe(
desc->style = font_desc.lfItalic ? PP_TRUETYPEFONTSTYLE_ITALIC : desc->style = font_desc.lfItalic ? PP_TRUETYPEFONTSTYLE_ITALIC :
PP_TRUETYPEFONTSTYLE_NORMAL; PP_TRUETYPEFONTSTYLE_NORMAL;
desc->weight = static_cast<PP_TrueTypeFontWeight_Dev>(font_desc.lfWeight); 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 = desc->charset =
static_cast<PP_TrueTypeFontCharset_Dev>(font_desc.lfCharSet); static_cast<PP_TrueTypeFontCharset_Dev>(font_desc.lfCharSet);
......
...@@ -34,7 +34,7 @@ enum PP_TrueTypeFontFamily_Dev { ...@@ -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)] [assert_size(4)]
enum PP_TrueTypeFontStyle_Dev { enum PP_TrueTypeFontStyle_Dev {
...@@ -43,7 +43,7 @@ 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)] [assert_size(4)]
enum PP_TrueTypeFontWeight_Dev { enum PP_TrueTypeFontWeight_Dev {
...@@ -59,7 +59,7 @@ 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)] [assert_size(4)]
enum PP_TrueTypeFontWidth_Dev { enum PP_TrueTypeFontWidth_Dev {
...@@ -75,7 +75,7 @@ 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)] [assert_size(4)]
enum PP_TrueTypeFontCharset_Dev { enum PP_TrueTypeFontCharset_Dev {
...@@ -101,8 +101,8 @@ enum PP_TrueTypeFontCharset_Dev { ...@@ -101,8 +101,8 @@ enum PP_TrueTypeFontCharset_Dev {
}; };
/** /**
* The <code>PP_TrueTypeFontDesc</code> structure describes a TrueType font. It * The <code>PP_TrueTypeFontDesc</code> struct describes a TrueType font. It is
* is passed to Create, and returned by Describe. * passed to Create(), and returned by Describe().
*/ */
[assert_size(40)] [assert_size(40)]
struct PP_TrueTypeFontDesc_Dev { struct PP_TrueTypeFontDesc_Dev {
...@@ -117,14 +117,19 @@ 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 /** This value specifies a generic font family. If a family name string is
* provided when creating a font, this is ignored. */ * provided when creating a font, this is ignored. */
PP_TrueTypeFontFamily_Dev generic_family; PP_TrueTypeFontFamily_Dev generic_family;
/** This value specifies the font style. */ /** This value specifies the font style. */
PP_TrueTypeFontStyle_Dev style; PP_TrueTypeFontStyle_Dev style;
/** This value specifies the font weight. */ /** This value specifies the font weight. */
PP_TrueTypeFontWeight_Dev weight; PP_TrueTypeFontWeight_Dev weight;
/** This value specifies the font width, for condensed or expanded fonts */ /** This value specifies the font width, for condensed or expanded fonts */
PP_TrueTypeFontWidth_Dev width; PP_TrueTypeFontWidth_Dev width;
/** This value specifies a character set. */ /** This value specifies a character set. */
PP_TrueTypeFontCharset_Dev charset; PP_TrueTypeFontCharset_Dev charset;
/** /**
* Ensure that this struct is 40-bytes wide by padding the end. In some * 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 * compilers, PP_Var is 8-byte aligned, so those compilers align this struct
...@@ -154,6 +159,30 @@ interface PPB_TrueTypeFont_Dev { ...@@ -154,6 +159,30 @@ interface PPB_TrueTypeFont_Dev {
[in] PP_ArrayOutput output, [in] PP_ArrayOutput output,
[in] PP_CompletionCallback callback); [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 * Creates a font resource matching the given font characteristics. The
* resource id will be non-zero on success, or zero on failure. * resource id will be non-zero on success, or zero on failure.
...@@ -168,7 +197,7 @@ interface PPB_TrueTypeFont_Dev { ...@@ -168,7 +197,7 @@ interface PPB_TrueTypeFont_Dev {
/** /**
* Determines if the given resource is a TrueType font. * 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 * @return <code>PP_TRUE</code> if the resource is a
* <code>PPB_TrueTypeFont_Dev</code>, <code>PP_FALSE</code> otherwise. * <code>PPB_TrueTypeFont_Dev</code>, <code>PP_FALSE</code> otherwise.
...@@ -197,8 +226,8 @@ interface PPB_TrueTypeFont_Dev { ...@@ -197,8 +226,8 @@ interface PPB_TrueTypeFont_Dev {
[in] PP_CompletionCallback callback); [in] PP_CompletionCallback callback);
/** /**
* Gets an array of identifying tags for each table in the font. * Gets an array of identifying tags for each table in the font. These tags
* These tags can be used to request specific tables using GetTable. * can be used to request specific tables using GetTable.
* *
* @param[in] font A <code>PP_Resource</code> corresponding to a font. * @param[in] font A <code>PP_Resource</code> corresponding to a font.
* @param[in] output A <code>PP_ArrayOutput</code> to hold the tags. * @param[in] output A <code>PP_ArrayOutput</code> to hold the tags.
......
...@@ -3,7 +3,7 @@ ...@@ -3,7 +3,7 @@
* found in the LICENSE file. * 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_ #ifndef PPAPI_C_DEV_PPB_TRUETYPE_FONT_DEV_H_
#define PPAPI_C_DEV_PPB_TRUETYPE_FONT_DEV_H_ #define PPAPI_C_DEV_PPB_TRUETYPE_FONT_DEV_H_
...@@ -51,7 +51,7 @@ typedef enum { ...@@ -51,7 +51,7 @@ typedef enum {
PP_COMPILE_ASSERT_SIZE_IN_BYTES(PP_TrueTypeFontFamily_Dev, 4); 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 { typedef enum {
PP_TRUETYPEFONTSTYLE_NORMAL = 0, PP_TRUETYPEFONTSTYLE_NORMAL = 0,
...@@ -60,7 +60,7 @@ typedef enum { ...@@ -60,7 +60,7 @@ typedef enum {
PP_COMPILE_ASSERT_SIZE_IN_BYTES(PP_TrueTypeFontStyle_Dev, 4); 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 { typedef enum {
PP_TRUETYPEFONTWEIGHT_THIN = 100, PP_TRUETYPEFONTWEIGHT_THIN = 100,
...@@ -76,7 +76,7 @@ typedef enum { ...@@ -76,7 +76,7 @@ typedef enum {
PP_COMPILE_ASSERT_SIZE_IN_BYTES(PP_TrueTypeFontWeight_Dev, 4); 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 { typedef enum {
PP_TRUETYPEFONTWIDTH_ULTRACONDENSED = 0, PP_TRUETYPEFONTWIDTH_ULTRACONDENSED = 0,
...@@ -92,7 +92,7 @@ typedef enum { ...@@ -92,7 +92,7 @@ typedef enum {
PP_COMPILE_ASSERT_SIZE_IN_BYTES(PP_TrueTypeFontWidth_Dev, 4); 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 { typedef enum {
PP_TRUETYPEFONTCHARSET_ANSI = 0, PP_TRUETYPEFONTCHARSET_ANSI = 0,
...@@ -125,8 +125,8 @@ PP_COMPILE_ASSERT_SIZE_IN_BYTES(PP_TrueTypeFontCharset_Dev, 4); ...@@ -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 * The <code>PP_TrueTypeFontDesc</code> struct describes a TrueType font. It is
* is passed to Create, and returned by Describe. * passed to Create(), and returned by Describe().
*/ */
struct PP_TrueTypeFontDesc_Dev { struct PP_TrueTypeFontDesc_Dev {
/** /**
...@@ -182,6 +182,28 @@ struct PPB_TrueTypeFont_Dev_0_1 { ...@@ -182,6 +182,28 @@ struct PPB_TrueTypeFont_Dev_0_1 {
int32_t (*GetFontFamilies)(PP_Instance instance, int32_t (*GetFontFamilies)(PP_Instance instance,
struct PP_ArrayOutput output, struct PP_ArrayOutput output,
struct PP_CompletionCallback callback); 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 * Creates a font resource matching the given font characteristics. The
* resource id will be non-zero on success, or zero on failure. * resource id will be non-zero on success, or zero on failure.
...@@ -195,7 +217,7 @@ struct PPB_TrueTypeFont_Dev_0_1 { ...@@ -195,7 +217,7 @@ struct PPB_TrueTypeFont_Dev_0_1 {
/** /**
* Determines if the given resource is a TrueType font. * 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 * @return <code>PP_TRUE</code> if the resource is a
* <code>PPB_TrueTypeFont_Dev</code>, <code>PP_FALSE</code> otherwise. * <code>PPB_TrueTypeFont_Dev</code>, <code>PP_FALSE</code> otherwise.
...@@ -222,8 +244,8 @@ struct PPB_TrueTypeFont_Dev_0_1 { ...@@ -222,8 +244,8 @@ struct PPB_TrueTypeFont_Dev_0_1 {
struct PP_TrueTypeFontDesc_Dev* desc, struct PP_TrueTypeFontDesc_Dev* desc,
struct PP_CompletionCallback callback); struct PP_CompletionCallback callback);
/** /**
* Gets an array of identifying tags for each table in the font. * Gets an array of identifying tags for each table in the font. These tags
* These tags can be used to request specific tables using GetTable. * can be used to request specific tables using GetTable.
* *
* @param[in] font A <code>PP_Resource</code> corresponding to a font. * @param[in] font A <code>PP_Resource</code> corresponding to a font.
* @param[in] output A <code>PP_ArrayOutput</code> to hold the tags. * @param[in] output A <code>PP_ArrayOutput</code> to hold the tags.
......
...@@ -4,7 +4,6 @@ ...@@ -4,7 +4,6 @@
#include "ppapi/cpp/dev/truetype_font_dev.h" #include "ppapi/cpp/dev/truetype_font_dev.h"
#include <stdio.h>
#include <string.h> // memcpy #include <string.h> // memcpy
#include "ppapi/c/dev/ppb_truetype_font_dev.h" #include "ppapi/c/dev/ppb_truetype_font_dev.h"
...@@ -41,7 +40,7 @@ TrueTypeFontDesc_Dev::TrueTypeFontDesc_Dev( ...@@ -41,7 +40,7 @@ TrueTypeFontDesc_Dev::TrueTypeFontDesc_Dev(
PassRef, PassRef,
const PP_TrueTypeFontDesc_Dev& pp_desc) { const PP_TrueTypeFontDesc_Dev& pp_desc) {
desc_ = 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) { TrueTypeFontDesc_Dev::TrueTypeFontDesc_Dev(const TrueTypeFontDesc_Dev& other) {
...@@ -61,12 +60,12 @@ TrueTypeFontDesc_Dev& TrueTypeFontDesc_Dev::operator=( ...@@ -61,12 +60,12 @@ TrueTypeFontDesc_Dev& TrueTypeFontDesc_Dev::operator=(
if (this == &other) if (this == &other)
return *this; return *this;
desc_ = other.desc_; set_family(other.family());
// Be careful about the refcount of the string, the assignment above doesn't set_generic_family(other.generic_family());
// copy a ref. The assignments below take a ref to the new name and copy the set_style(other.style());
// PP_Var into the wrapped descriptor. set_weight(other.weight());
family_ = other.family(); set_width(other.width());
desc_.family = family_.pp_var(); set_charset(other.charset());
return *this; return *this;
} }
...@@ -104,6 +103,21 @@ int32_t TrueTypeFont_Dev::GetFontFamilies( ...@@ -104,6 +103,21 @@ int32_t TrueTypeFont_Dev::GetFontFamilies(
return cc.MayForce(PP_ERROR_NOINTERFACE); 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( int32_t TrueTypeFont_Dev::Describe(
const CompletionCallbackWithOutput<TrueTypeFontDesc_Dev>& cc) { const CompletionCallbackWithOutput<TrueTypeFontDesc_Dev>& cc) {
if (has_interface<PPB_TrueTypeFont_Dev_0_1>()) { if (has_interface<PPB_TrueTypeFont_Dev_0_1>()) {
......
...@@ -27,14 +27,17 @@ class TrueTypeFontDesc_Dev { ...@@ -27,14 +27,17 @@ class TrueTypeFontDesc_Dev {
/// Default constructor for creating a <code>TrueTypeFontDesc_Dev</code> /// Default constructor for creating a <code>TrueTypeFontDesc_Dev</code>
/// object. /// object.
TrueTypeFontDesc_Dev(); TrueTypeFontDesc_Dev();
/// Constructor that takes an existing <code>PP_TrueTypeFontDesc_Dev</code> /// Constructor that takes an existing <code>PP_TrueTypeFontDesc_Dev</code>
/// structure. The 'family' PP_Var field in the structure will be managed by /// structure. The 'family' PP_Var field in the structure will be managed by
/// this instance. /// this instance.
TrueTypeFontDesc_Dev(PassRef, const PP_TrueTypeFontDesc_Dev& pp_desc); TrueTypeFontDesc_Dev(PassRef, const PP_TrueTypeFontDesc_Dev& pp_desc);
/// The copy constructor for <code>TrueTypeFontDesc_Dev</code>. /// The copy constructor for <code>TrueTypeFontDesc_Dev</code>.
/// ///
/// @param[in] other A reference to a <code>TrueTypeFontDesc_Dev</code>. /// @param[in] other A reference to a <code>TrueTypeFontDesc_Dev</code>.
TrueTypeFontDesc_Dev(const TrueTypeFontDesc_Dev& other); TrueTypeFontDesc_Dev(const TrueTypeFontDesc_Dev& other);
~TrueTypeFontDesc_Dev(); ~TrueTypeFontDesc_Dev();
TrueTypeFontDesc_Dev& operator=(const TrueTypeFontDesc_Dev& other); TrueTypeFontDesc_Dev& operator=(const TrueTypeFontDesc_Dev& other);
...@@ -81,8 +84,6 @@ class TrueTypeFontDesc_Dev { ...@@ -81,8 +84,6 @@ class TrueTypeFontDesc_Dev {
} }
private: private:
friend class TrueTypeFont_Dev;
pp::Var family_; // This manages the PP_Var embedded in desc_. pp::Var family_; // This manages the PP_Var embedded in desc_.
PP_TrueTypeFontDesc_Dev desc_; PP_TrueTypeFontDesc_Dev desc_;
}; };
...@@ -125,7 +126,26 @@ class TrueTypeFont_Dev : public Resource { ...@@ -125,7 +126,26 @@ class TrueTypeFont_Dev : public Resource {
/// code from <code>pp_errors.h</code>. /// code from <code>pp_errors.h</code>.
static int32_t GetFontFamilies( static int32_t GetFontFamilies(
const InstanceHandle& instance, 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 /// Returns a description of the given font resource. This description may
/// differ from the description passed to Create, reflecting the host's font /// differ from the description passed to Create, reflecting the host's font
...@@ -137,7 +157,7 @@ class TrueTypeFont_Dev : public Resource { ...@@ -137,7 +157,7 @@ class TrueTypeFont_Dev : public Resource {
/// @return A return code from <code>pp_errors.h</code>. If an error code is /// @return A return code from <code>pp_errors.h</code>. If an error code is
/// returned, the descriptor will be left unchanged. /// returned, the descriptor will be left unchanged.
int32_t Describe( 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. /// Gets an array of identifying tags for each table in the font.
/// These tags can be used to request specific tables using GetTable. /// These tags can be used to request specific tables using GetTable.
...@@ -148,7 +168,7 @@ class TrueTypeFont_Dev : public Resource { ...@@ -148,7 +168,7 @@ class TrueTypeFont_Dev : public Resource {
/// @return If >= 0, the number of table tags returned, otherwise an error /// @return If >= 0, the number of table tags returned, otherwise an error
/// code from <code>pp_errors.h</code>. /// code from <code>pp_errors.h</code>.
int32_t GetTableTags( 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. /// Copies the given font table into client memory.
/// ///
...@@ -158,8 +178,6 @@ class TrueTypeFont_Dev : public Resource { ...@@ -158,8 +178,6 @@ class TrueTypeFont_Dev : public Resource {
/// @param[in] offset The offset into the font table. /// @param[in] offset The offset into the font table.
/// @param[in] max_data_length The maximum number of bytes to transfer from /// @param[in] max_data_length The maximum number of bytes to transfer from
/// <code>offset</code>. /// <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 /// @param[in] callback A <code>CompletionCallbackWithOutput</code> to be
/// called upon completion of GetTable. /// called upon completion of GetTable.
/// ///
...@@ -169,7 +187,7 @@ class TrueTypeFont_Dev : public Resource { ...@@ -169,7 +187,7 @@ class TrueTypeFont_Dev : public Resource {
uint32_t table, uint32_t table,
int32_t offset, int32_t offset,
int32_t max_data_length, int32_t max_data_length,
const CompletionCallbackWithOutput<std::vector<char> >& cc); const CompletionCallbackWithOutput<std::vector<char> >& callback);
}; };
namespace internal { namespace internal {
...@@ -192,6 +210,53 @@ struct CallbackOutputTraits<TrueTypeFontDesc_Dev> { ...@@ -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 internal
} // namespace pp } // namespace pp
......
...@@ -2214,6 +2214,12 @@ int32_t Pnacl_M26_PPB_TrueTypeFont_Dev_GetFontFamilies(PP_Instance instance, str ...@@ -2214,6 +2214,12 @@ int32_t Pnacl_M26_PPB_TrueTypeFont_Dev_GetFontFamilies(PP_Instance instance, str
return iface->GetFontFamilies(instance, output, callback); return iface->GetFontFamilies(instance, output, callback);
} }
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)) static __attribute__((pnaclcall))
PP_Resource Pnacl_M26_PPB_TrueTypeFont_Dev_Create(PP_Instance instance, const struct PP_TrueTypeFontDesc_Dev* desc) { 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; const struct PPB_TrueTypeFont_Dev_0_1 *iface = Pnacl_WrapperInfo_PPB_TrueTypeFont_Dev_0_1.real_iface;
...@@ -4597,6 +4603,7 @@ struct PPB_Testing_Dev_0_91 Pnacl_Wrappers_PPB_Testing_Dev_0_91 = { ...@@ -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 = { 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, .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, .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, .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, .Describe = (int32_t (*)(PP_Resource font, struct PP_TrueTypeFontDesc_Dev* desc, struct PP_CompletionCallback callback))&Pnacl_M26_PPB_TrueTypeFont_Dev_Describe,
......
...@@ -1445,6 +1445,11 @@ IPC_MESSAGE_CONTROL0(PpapiHostMsg_TrueTypeFontSingleton_Create) ...@@ -1445,6 +1445,11 @@ IPC_MESSAGE_CONTROL0(PpapiHostMsg_TrueTypeFontSingleton_Create)
IPC_MESSAGE_CONTROL0(PpapiHostMsg_TrueTypeFontSingleton_GetFontFamilies) IPC_MESSAGE_CONTROL0(PpapiHostMsg_TrueTypeFontSingleton_GetFontFamilies)
IPC_MESSAGE_CONTROL1(PpapiPluginMsg_TrueTypeFontSingleton_GetFontFamiliesReply, IPC_MESSAGE_CONTROL1(PpapiPluginMsg_TrueTypeFontSingleton_GetFontFamiliesReply,
std::vector<std::string> /* font_families */) 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, IPC_MESSAGE_CONTROL1(PpapiHostMsg_TrueTypeFont_Create,
ppapi::proxy::SerializedTrueTypeFontDesc /* desc */) ppapi::proxy::SerializedTrueTypeFontDesc /* desc */)
IPC_MESSAGE_CONTROL0(PpapiHostMsg_TrueTypeFont_Describe) IPC_MESSAGE_CONTROL0(PpapiHostMsg_TrueTypeFont_Describe)
......
...@@ -44,7 +44,6 @@ PPB_TrueTypeFont_API* TrueTypeFontResource::AsPPB_TrueTypeFont_API() { ...@@ -44,7 +44,6 @@ PPB_TrueTypeFont_API* TrueTypeFontResource::AsPPB_TrueTypeFont_API() {
int32_t TrueTypeFontResource::Describe( int32_t TrueTypeFontResource::Describe(
PP_TrueTypeFontDesc_Dev* desc, PP_TrueTypeFontDesc_Dev* desc,
scoped_refptr<TrackedCallback> callback) { scoped_refptr<TrackedCallback> callback) {
Call<PpapiPluginMsg_TrueTypeFont_DescribeReply>(RENDERER, Call<PpapiPluginMsg_TrueTypeFont_DescribeReply>(RENDERER,
PpapiHostMsg_TrueTypeFont_Describe(), PpapiHostMsg_TrueTypeFont_Describe(),
base::Bind(&TrueTypeFontResource::OnPluginMsgDescribeComplete, this, base::Bind(&TrueTypeFontResource::OnPluginMsgDescribeComplete, this,
...@@ -83,6 +82,7 @@ void TrueTypeFontResource::OnPluginMsgDescribeComplete( ...@@ -83,6 +82,7 @@ void TrueTypeFontResource::OnPluginMsgDescribeComplete(
int32_t result = params.result(); int32_t result = params.result();
if (result == PP_OK) if (result == PP_OK)
desc.CopyToPPTrueTypeFontDesc(pp_desc); desc.CopyToPPTrueTypeFontDesc(pp_desc);
callback->Run(result); callback->Run(result);
} }
......
...@@ -5,9 +5,12 @@ ...@@ -5,9 +5,12 @@
#include "ppapi/proxy/truetype_font_singleton_resource.h" #include "ppapi/proxy/truetype_font_singleton_resource.h"
#include "ppapi/proxy/ppapi_messages.h" #include "ppapi/proxy/ppapi_messages.h"
#include "ppapi/proxy/serialized_structs.h"
#include "ppapi/shared_impl/array_writer.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/tracked_callback.h"
#include "ppapi/shared_impl/var.h" #include "ppapi/shared_impl/var.h"
#include "ppapi/shared_impl/var_tracker.h"
namespace ppapi { namespace ppapi {
namespace proxy { namespace proxy {
...@@ -39,11 +42,30 @@ int32_t TrueTypeFontSingletonResource::GetFontFamilies( ...@@ -39,11 +42,30 @@ int32_t TrueTypeFontSingletonResource::GetFontFamilies(
return PP_OK_COMPLETIONPENDING; 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( void TrueTypeFontSingletonResource::OnPluginMsgGetFontFamiliesComplete(
scoped_refptr<TrackedCallback> callback, scoped_refptr<TrackedCallback> callback,
PP_ArrayOutput array_output, PP_ArrayOutput array_output,
const ResourceMessageReplyParams& params, const ResourceMessageReplyParams& params,
const std::vector<std::string>& font_families) { const std::vector<std::string>& font_families) {
if (!TrackedCallback::IsPending(callback))
return;
// The result code should contain the data size if it's positive. // The result code should contain the data size if it's positive.
int32_t result = params.result(); int32_t result = params.result();
DCHECK((result < 0 && font_families.size() == 0) || DCHECK((result < 0 && font_families.size() == 0) ||
...@@ -64,5 +86,36 @@ void TrueTypeFontSingletonResource::OnPluginMsgGetFontFamiliesComplete( ...@@ -64,5 +86,36 @@ void TrueTypeFontSingletonResource::OnPluginMsgGetFontFamiliesComplete(
callback->Run(result); 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 proxy
} // namespace ppapi } // namespace ppapi
...@@ -18,7 +18,7 @@ class TrackedCallback; ...@@ -18,7 +18,7 @@ class TrackedCallback;
namespace proxy { namespace proxy {
struct SerializedTrueTypeFontDescription; struct SerializedTrueTypeFontDesc;
// This handles the singleton calls (that don't take a PP_Resource parameter) // This handles the singleton calls (that don't take a PP_Resource parameter)
// on the TrueType font interface. // on the TrueType font interface.
...@@ -38,6 +38,11 @@ class TrueTypeFontSingletonResource ...@@ -38,6 +38,11 @@ class TrueTypeFontSingletonResource
PP_Instance instance, PP_Instance instance,
const PP_ArrayOutput& output, const PP_ArrayOutput& output,
const scoped_refptr<TrackedCallback>& callback) OVERRIDE; 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: private:
void OnPluginMsgGetFontFamiliesComplete( void OnPluginMsgGetFontFamiliesComplete(
...@@ -45,6 +50,11 @@ class TrueTypeFontSingletonResource ...@@ -45,6 +50,11 @@ class TrueTypeFontSingletonResource
PP_ArrayOutput array_output, PP_ArrayOutput array_output,
const ResourceMessageReplyParams& params, const ResourceMessageReplyParams& params,
const std::vector<std::string>& data); 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); DISALLOW_COPY_AND_ASSIGN(TrueTypeFontSingletonResource);
}; };
......
...@@ -6,7 +6,6 @@ ...@@ -6,7 +6,6 @@
#include "ppapi/tests/test_truetype_font.h" #include "ppapi/tests/test_truetype_font.h"
#include <stdio.h>
#include <string.h> #include <string.h>
#include <algorithm> #include <algorithm>
#include <limits> #include <limits>
...@@ -86,6 +85,7 @@ TestTrueTypeFont::~TestTrueTypeFont() { ...@@ -86,6 +85,7 @@ TestTrueTypeFont::~TestTrueTypeFont() {
void TestTrueTypeFont::RunTests(const std::string& filter) { void TestTrueTypeFont::RunTests(const std::string& filter) {
RUN_TEST(GetFontFamilies, filter); RUN_TEST(GetFontFamilies, filter);
RUN_TEST(GetFontsInFamily, filter);
RUN_TEST(Create, filter); RUN_TEST(Create, filter);
RUN_TEST(Describe, filter); RUN_TEST(Describe, filter);
RUN_TEST(GetTableTags, filter); RUN_TEST(GetTableTags, filter);
...@@ -123,6 +123,67 @@ std::string TestTrueTypeFont::TestGetFontFamilies() { ...@@ -123,6 +123,67 @@ std::string TestTrueTypeFont::TestGetFontFamilies() {
PASS(); 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() { std::string TestTrueTypeFont::TestCreate() {
PP_Resource font; PP_Resource font;
PP_TrueTypeFontDesc_Dev desc = { PP_TrueTypeFontDesc_Dev desc = {
......
...@@ -23,6 +23,7 @@ class TestTrueTypeFont : public TestCase { ...@@ -23,6 +23,7 @@ class TestTrueTypeFont : public TestCase {
virtual void RunTests(const std::string& filter); virtual void RunTests(const std::string& filter);
std::string TestGetFontFamilies(); std::string TestGetFontFamilies();
std::string TestGetFontsInFamily();
std::string TestCreate(); std::string TestCreate();
std::string TestDescribe(); std::string TestDescribe();
std::string TestGetTableTags(); std::string TestGetTableTags();
......
...@@ -2,7 +2,7 @@ ...@@ -2,7 +2,7 @@
// Use of this source code is governed by a BSD-style license that can be // Use of this source code is governed by a BSD-style license that can be
// found in the LICENSE file. // 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/dev/ppb_truetype_font_dev.h"
#include "ppapi/c/pp_completion_callback.h" #include "ppapi/c/pp_completion_callback.h"
...@@ -33,6 +33,21 @@ int32_t GetFontFamilies(PP_Instance instance, ...@@ -33,6 +33,21 @@ int32_t GetFontFamilies(PP_Instance instance,
enter.callback())); 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, PP_Resource Create(PP_Instance instance,
const struct PP_TrueTypeFontDesc_Dev* desc) { const struct PP_TrueTypeFontDesc_Dev* desc) {
VLOG(4) << "PPB_TrueTypeFont_Dev::Create()"; VLOG(4) << "PPB_TrueTypeFont_Dev::Create()";
...@@ -88,6 +103,7 @@ int32_t GetTable(PP_Resource font, ...@@ -88,6 +103,7 @@ int32_t GetTable(PP_Resource font,
const PPB_TrueTypeFont_Dev_0_1 g_ppb_truetypefont_dev_thunk_0_1 = { const PPB_TrueTypeFont_Dev_0_1 g_ppb_truetypefont_dev_thunk_0_1 = {
&GetFontFamilies, &GetFontFamilies,
&GetFontsInFamily,
&Create, &Create,
&IsTrueTypeFont, &IsTrueTypeFont,
&Describe, &Describe,
......
...@@ -24,6 +24,12 @@ class PPB_TrueTypeFont_Singleton_API { ...@@ -24,6 +24,12 @@ class PPB_TrueTypeFont_Singleton_API {
const PP_ArrayOutput& output, const PP_ArrayOutput& output,
const scoped_refptr<TrackedCallback>& callback) = 0; 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 = static const SingletonResourceID kSingletonResourceID =
TRUETYPE_FONT_SINGLETON_ID; TRUETYPE_FONT_SINGLETON_ID;
}; };
......
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