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 if (enter.failed()) 21 return PP_MakeUndefined(); 22 return enter.functions()->GetFontFamilies(instance); 23 } 24 25 PP_Resource Create(PP_Instance instance, 26 const PP_BrowserFont_Trusted_Description* description) { 27 EnterResourceCreation enter(instance); 28 if (enter.failed()) 29 return 0; 30 return enter.functions()->CreateBrowserFont(instance, description); 31 } 32 33 PP_Bool IsBrowserFont(PP_Resource resource) { 34 EnterBrowserFont enter(resource, false); 35 return enter.succeeded() ? PP_TRUE : PP_FALSE; 36 } 37 38 PP_Bool Describe(PP_Resource font_id, 39 PP_BrowserFont_Trusted_Description* description, 40 PP_BrowserFont_Trusted_Metrics* metrics) { 41 EnterBrowserFont enter(font_id, true); 42 if (enter.failed()) 43 return PP_FALSE; 44 return enter.object()->Describe(description, metrics); 45 } 46 47 PP_Bool DrawTextAt(PP_Resource font_id, 48 PP_Resource image_data, 49 const PP_BrowserFont_Trusted_TextRun* text, 50 const PP_Point* position, 51 uint32_t color, 52 const PP_Rect* clip, 53 PP_Bool image_data_is_opaque) { 54 EnterBrowserFont enter(font_id, true); 55 if (enter.failed()) 56 return PP_FALSE; 57 return enter.object()->DrawTextAt(image_data, text, position, color, clip, 58 image_data_is_opaque); 59 } 60 61 int32_t MeasureText(PP_Resource font_id, 62 const PP_BrowserFont_Trusted_TextRun* text) { 63 EnterBrowserFont enter(font_id, true); 64 if (enter.failed()) 65 return -1; 66 return enter.object()->MeasureText(text); 67 } 68 69 uint32_t CharacterOffsetForPixel(PP_Resource font_id, 70 const PP_BrowserFont_Trusted_TextRun* text, 71 int32_t pixel_position) { 72 EnterBrowserFont enter(font_id, true); 73 if (enter.failed()) 74 return -1; 75 return enter.object()->CharacterOffsetForPixel(text, pixel_position); 76 } 77 78 int32_t PixelOffsetForCharacter(PP_Resource font_id, 79 const PP_BrowserFont_Trusted_TextRun* text, 80 uint32_t char_offset) { 81 EnterBrowserFont enter(font_id, true); 82 if (enter.failed()) 83 return -1; 84 return enter.object()->PixelOffsetForCharacter(text, char_offset); 85 } 86 87 const PPB_BrowserFont_Trusted_1_0 g_ppb_browser_font_trusted_thunk = { 88 &GetFontFamilies, 89 &Create, 90 &IsBrowserFont, 91 &Describe, 92 &DrawTextAt, 93 &MeasureText, 94 &CharacterOffsetForPixel, 95 &PixelOffsetForCharacter 96 }; 97 98 } // namespace 99 100 const PPB_BrowserFont_Trusted_1_0* GetPPB_BrowserFont_Trusted_1_0_Thunk() { 101 return &g_ppb_browser_font_trusted_thunk; 102 } 103 104 } // namespace thunk 105 } // namespace ppapi 106