Chromium Code Reviews| Index: ppapi/cpp/dev/truetype_font_dev.h |
| diff --git a/ppapi/cpp/dev/truetype_font_dev.h b/ppapi/cpp/dev/truetype_font_dev.h |
| index a2c436943e70a53f7e7daef7384956223942395a..91f2f0eaef8ba04996591b86414eb0ca91af6601 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_; |
| }; |
| @@ -127,6 +128,28 @@ class TrueTypeFont_Dev : public Resource { |
| const InstanceHandle& instance, |
| const CompletionCallbackWithOutput<std::vector<Var> >& cc); |
| + /// 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] output A <code>PP_ArrayOutput</code> to hold the descriptors. |
| + /// The output is an array of <code>TrueTypeFontDesc_Dev</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. |
|
dmichael (off chromium)
2013/04/12 23:34:18
nit: Your params need to be updated for the C++ in
bbudge
2013/04/13 00:44:44
Done.
|
| + /// |
| + /// @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> >& |
| + cc); |
| + |
| /// Returns a description of the given font resource. This description may |
| /// differ from the description passed to Create, reflecting the host's font |
| /// matching and fallback algorithm. |
| @@ -192,6 +215,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 |