diff options
author | bbudge@chromium.org <bbudge@chromium.org@0039d316-1c4b-4281-b951-d872f2087c98> | 2013-04-19 03:50:35 +0000 |
---|---|---|
committer | bbudge@chromium.org <bbudge@chromium.org@0039d316-1c4b-4281-b951-d872f2087c98> | 2013-04-19 03:50:35 +0000 |
commit | 720e1e622e14c79677bbe27604e6638bf294ec4d (patch) | |
tree | b120d55625d4836bd5b21d190d519b497bb12471 /ppapi/cpp | |
parent | 76de6d1c423858d6e3bae517fcff0c8cddf1a090 (diff) | |
download | chromium_src-720e1e622e14c79677bbe27604e6638bf294ec4d.zip chromium_src-720e1e622e14c79677bbe27604e6638bf294ec4d.tar.gz chromium_src-720e1e622e14c79677bbe27604e6638bf294ec4d.tar.bz2 |
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
Diffstat (limited to 'ppapi/cpp')
-rw-r--r-- | ppapi/cpp/dev/truetype_font_dev.cc | 30 | ||||
-rw-r--r-- | ppapi/cpp/dev/truetype_font_dev.h | 81 |
2 files changed, 95 insertions, 16 deletions
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 |