Home | History | Annotate | Download | only in thunk
      1 // Copyright (c) 2012 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/thunk/thunk.h"
      6 #include "ppapi/thunk/enter.h"
      7 #include "ppapi/thunk/ppb_browser_font_singleton_api.h"
      8 #include "ppapi/thunk/ppb_browser_font_trusted_api.h"
      9 #include "ppapi/thunk/resource_creation_api.h"
     10 
     11 namespace ppapi {
     12 namespace thunk {
     13 
     14 namespace {
     15 
     16 typedef EnterResource<PPB_BrowserFont_Trusted_API> EnterBrowserFont;
     17 
     18 PP_Var GetFontFamilies(PP_Instance instance) {
     19   EnterInstanceAPI<PPB_BrowserFont_Singleton_API> enter(instance);
     20   return enter.succeeded() ?
     21       enter.functions()->GetFontFamilies(instance) : PP_MakeUndefined();
     22 }
     23 
     24 PP_Resource Create(PP_Instance instance,
     25                    const PP_BrowserFont_Trusted_Description* description) {
     26   EnterResourceCreation enter(instance);
     27   return enter.succeeded() ?
     28       enter.functions()->CreateBrowserFont(instance, description) : 0;
     29 }
     30 
     31 PP_Bool IsBrowserFont(PP_Resource resource) {
     32   EnterBrowserFont enter(resource, false);
     33   return enter.succeeded() ? PP_TRUE : PP_FALSE;
     34 }
     35 
     36 PP_Bool Describe(PP_Resource font_id,
     37                  PP_BrowserFont_Trusted_Description* description,
     38                  PP_BrowserFont_Trusted_Metrics* metrics) {
     39   EnterBrowserFont enter(font_id, true);
     40   return enter.succeeded() ?
     41       enter.object()->Describe(description, metrics) : PP_FALSE;
     42 }
     43 
     44 PP_Bool DrawTextAt(PP_Resource font_id,
     45                    PP_Resource image_data,
     46                    const PP_BrowserFont_Trusted_TextRun* text,
     47                    const PP_Point* position,
     48                    uint32_t color,
     49                    const PP_Rect* clip,
     50                    PP_Bool image_data_is_opaque) {
     51   EnterBrowserFont enter(font_id, true);
     52   return enter.succeeded() ?
     53       enter.object()->DrawTextAt(image_data, text, position, color, clip,
     54                                  image_data_is_opaque) :
     55       PP_FALSE;
     56 }
     57 
     58 int32_t MeasureText(PP_Resource font_id,
     59                     const PP_BrowserFont_Trusted_TextRun* text) {
     60   EnterBrowserFont enter(font_id, true);
     61   return enter.succeeded() ? enter.object()->MeasureText(text) : -1;
     62 }
     63 
     64 uint32_t CharacterOffsetForPixel(PP_Resource font_id,
     65                                  const PP_BrowserFont_Trusted_TextRun* text,
     66                                  int32_t pixel_position) {
     67   EnterBrowserFont enter(font_id, true);
     68   return enter.succeeded() ?
     69       enter.object()->CharacterOffsetForPixel(text, pixel_position) :
     70       0xFFFFFFFF;
     71 }
     72 
     73 int32_t PixelOffsetForCharacter(PP_Resource font_id,
     74                                 const PP_BrowserFont_Trusted_TextRun* text,
     75                                 uint32_t char_offset) {
     76   EnterBrowserFont enter(font_id, true);
     77   return enter.succeeded() ?
     78       enter.object()->PixelOffsetForCharacter(text, char_offset) : -1;
     79 }
     80 
     81 const PPB_BrowserFont_Trusted_1_0 g_ppb_browser_font_trusted_thunk = {
     82   &GetFontFamilies,
     83   &Create,
     84   &IsBrowserFont,
     85   &Describe,
     86   &DrawTextAt,
     87   &MeasureText,
     88   &CharacterOffsetForPixel,
     89   &PixelOffsetForCharacter
     90 };
     91 
     92 }  // namespace
     93 
     94 const PPB_BrowserFont_Trusted_1_0* GetPPB_BrowserFont_Trusted_1_0_Thunk() {
     95   return &g_ppb_browser_font_trusted_thunk;
     96 }
     97 
     98 }  // namespace thunk
     99 }  // namespace ppapi
    100