Home | History | Annotate | Download | only in dev
      1 // Copyright (c) 2013 The Chromium Authors. All rights reserved.
      2 // Use of this source code is governed by a BSD-style license that can be
      3 // found in the LICENSE file.
      4 
      5 #include "ppapi/cpp/dev/truetype_font_dev.h"
      6 
      7 #include <string.h>  // memcpy
      8 
      9 #include "ppapi/c/dev/ppb_truetype_font_dev.h"
     10 #include "ppapi/c/pp_errors.h"
     11 #include "ppapi/c/ppb_var.h"
     12 #include "ppapi/cpp/completion_callback.h"
     13 #include "ppapi/cpp/instance_handle.h"
     14 #include "ppapi/cpp/module.h"
     15 #include "ppapi/cpp/module_impl.h"
     16 #include "ppapi/cpp/var.h"
     17 
     18 namespace pp {
     19 
     20 namespace {
     21 
     22 template <> const char* interface_name<PPB_TrueTypeFont_Dev_0_1>() {
     23   return PPB_TRUETYPEFONT_DEV_INTERFACE_0_1;
     24 }
     25 
     26 }  // namespace
     27 
     28 // TrueTypeFontDesc_Dev --------------------------------------------------------
     29 
     30 TrueTypeFontDesc_Dev::TrueTypeFontDesc_Dev() {
     31   desc_.family = family_.pp_var();
     32   set_generic_family(PP_TRUETYPEFONTFAMILY_SERIF);
     33   set_style(PP_TRUETYPEFONTSTYLE_NORMAL);
     34   set_weight(PP_TRUETYPEFONTWEIGHT_NORMAL);
     35   set_width(PP_TRUETYPEFONTWIDTH_NORMAL);
     36   set_charset(PP_TRUETYPEFONTCHARSET_DEFAULT);
     37 }
     38 
     39 TrueTypeFontDesc_Dev::TrueTypeFontDesc_Dev(
     40     PassRef,
     41     const PP_TrueTypeFontDesc_Dev& pp_desc) {
     42   desc_ = pp_desc;
     43   set_family(Var(PASS_REF, pp_desc.family));
     44 }
     45 
     46 TrueTypeFontDesc_Dev::TrueTypeFontDesc_Dev(const TrueTypeFontDesc_Dev& other) {
     47   set_family(other.family());
     48   set_generic_family(other.generic_family());
     49   set_style(other.style());
     50   set_weight(other.weight());
     51   set_width(other.width());
     52   set_charset(other.charset());
     53 }
     54 
     55 TrueTypeFontDesc_Dev::~TrueTypeFontDesc_Dev() {
     56 }
     57 
     58 TrueTypeFontDesc_Dev& TrueTypeFontDesc_Dev::operator=(
     59     const TrueTypeFontDesc_Dev& other) {
     60   if (this == &other)
     61     return *this;
     62 
     63   set_family(other.family());
     64   set_generic_family(other.generic_family());
     65   set_style(other.style());
     66   set_weight(other.weight());
     67   set_width(other.width());
     68   set_charset(other.charset());
     69 
     70   return *this;
     71 }
     72 
     73 // TrueTypeFont_Dev ------------------------------------------------------------
     74 
     75 TrueTypeFont_Dev::TrueTypeFont_Dev() {
     76 }
     77 
     78 TrueTypeFont_Dev::TrueTypeFont_Dev(const InstanceHandle& instance,
     79                                    const TrueTypeFontDesc_Dev& desc) {
     80   if (!has_interface<PPB_TrueTypeFont_Dev_0_1>())
     81     return;
     82   PassRefFromConstructor(get_interface<PPB_TrueTypeFont_Dev_0_1>()->Create(
     83       instance.pp_instance(), &desc.pp_desc()));
     84 }
     85 
     86 TrueTypeFont_Dev::TrueTypeFont_Dev(const TrueTypeFont_Dev& other)
     87     : Resource(other) {
     88 }
     89 
     90 TrueTypeFont_Dev::TrueTypeFont_Dev(PassRef, PP_Resource resource)
     91     : Resource(PASS_REF, resource) {
     92 }
     93 
     94 // static
     95 int32_t TrueTypeFont_Dev::GetFontFamilies(
     96     const InstanceHandle& instance,
     97     const CompletionCallbackWithOutput<std::vector<Var> >& cc) {
     98   if (has_interface<PPB_TrueTypeFont_Dev_0_1>()) {
     99     return get_interface<PPB_TrueTypeFont_Dev_0_1>()->GetFontFamilies(
    100         instance.pp_instance(),
    101         cc.output(), cc.pp_completion_callback());
    102   }
    103   return cc.MayForce(PP_ERROR_NOINTERFACE);
    104 }
    105 
    106 // static
    107 int32_t TrueTypeFont_Dev::GetFontsInFamily(
    108     const InstanceHandle& instance,
    109     const Var& family,
    110     const CompletionCallbackWithOutput<std::vector<TrueTypeFontDesc_Dev> >& cc)
    111         {
    112   if (has_interface<PPB_TrueTypeFont_Dev_0_1>()) {
    113     return get_interface<PPB_TrueTypeFont_Dev_0_1>()->GetFontsInFamily(
    114         instance.pp_instance(),
    115         family.pp_var(),
    116         cc.output(), cc.pp_completion_callback());
    117   }
    118   return cc.MayForce(PP_ERROR_NOINTERFACE);
    119 }
    120 
    121 int32_t TrueTypeFont_Dev::Describe(
    122     const CompletionCallbackWithOutput<TrueTypeFontDesc_Dev>& cc) {
    123   if (has_interface<PPB_TrueTypeFont_Dev_0_1>()) {
    124     int32_t result =
    125         get_interface<PPB_TrueTypeFont_Dev_0_1>()->Describe(
    126             pp_resource(), cc.output(), cc.pp_completion_callback());
    127     return result;
    128   }
    129   return cc.MayForce(PP_ERROR_NOINTERFACE);
    130 }
    131 
    132 int32_t TrueTypeFont_Dev::GetTableTags(
    133     const CompletionCallbackWithOutput<std::vector<uint32_t> >& cc) {
    134   if (has_interface<PPB_TrueTypeFont_Dev_0_1>()) {
    135     return get_interface<PPB_TrueTypeFont_Dev_0_1>()->GetTableTags(
    136         pp_resource(),
    137         cc.output(), cc.pp_completion_callback());
    138   }
    139   return cc.MayForce(PP_ERROR_NOINTERFACE);
    140 }
    141 
    142 int32_t TrueTypeFont_Dev::GetTable(
    143     uint32_t table,
    144     int32_t offset,
    145     int32_t max_data_length,
    146     const CompletionCallbackWithOutput<std::vector<char> >& cc) {
    147   if (has_interface<PPB_TrueTypeFont_Dev_0_1>()) {
    148     return get_interface<PPB_TrueTypeFont_Dev_0_1>()->GetTable(
    149         pp_resource(),
    150         table, offset, max_data_length,
    151         cc.output(), cc.pp_completion_callback());
    152   }
    153   return cc.MayForce(PP_ERROR_NOINTERFACE);
    154 }
    155 
    156 }  // namespace pp
    157