OLD | NEW |
(Empty) | |
| 1 // Copyright (c) 2011 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_font_api.h" |
| 8 #include "ppapi/thunk/resource_creation_api.h" |
| 9 |
| 10 namespace ppapi { |
| 11 namespace thunk { |
| 12 |
| 13 namespace { |
| 14 |
| 15 PP_Resource Create(PP_Instance instance, |
| 16 const PP_FontDescription_Dev* description) { |
| 17 EnterFunction<ResourceCreationAPI> enter(instance, true); |
| 18 if (enter.failed()) |
| 19 return 0; |
| 20 return enter.functions()->CreateFontObject(instance, description); |
| 21 } |
| 22 |
| 23 PP_Bool IsFont(PP_Resource resource) { |
| 24 EnterResource<PPB_Font_API> enter(resource, false); |
| 25 return enter.succeeded() ? PP_TRUE : PP_FALSE; |
| 26 } |
| 27 |
| 28 PP_Bool Describe(PP_Resource font_id, |
| 29 PP_FontDescription_Dev* description, |
| 30 PP_FontMetrics_Dev* metrics) { |
| 31 EnterResource<PPB_Font_API> enter(font_id, true); |
| 32 if (enter.failed()) |
| 33 return PP_FALSE; |
| 34 return enter.object()->Describe(description, metrics); |
| 35 } |
| 36 |
| 37 PP_Bool DrawTextAt(PP_Resource font_id, |
| 38 PP_Resource image_data, |
| 39 const PP_TextRun_Dev* text, |
| 40 const PP_Point* position, |
| 41 uint32_t color, |
| 42 const PP_Rect* clip, |
| 43 PP_Bool image_data_is_opaque) { |
| 44 EnterResource<PPB_Font_API> enter(font_id, true); |
| 45 if (enter.failed()) |
| 46 return PP_FALSE; |
| 47 return enter.object()->DrawTextAt(image_data, text, position, color, clip, |
| 48 image_data_is_opaque); |
| 49 } |
| 50 |
| 51 int32_t MeasureText(PP_Resource font_id, const PP_TextRun_Dev* text) { |
| 52 EnterResource<PPB_Font_API> enter(font_id, true); |
| 53 if (enter.failed()) |
| 54 return -1; |
| 55 return enter.object()->MeasureText(text); |
| 56 } |
| 57 |
| 58 uint32_t CharacterOffsetForPixel(PP_Resource font_id, |
| 59 const PP_TextRun_Dev* text, |
| 60 int32_t pixel_position) { |
| 61 EnterResource<PPB_Font_API> enter(font_id, true); |
| 62 if (enter.failed()) |
| 63 return -1; |
| 64 return enter.object()->CharacterOffsetForPixel(text, pixel_position); |
| 65 } |
| 66 |
| 67 int32_t PixelOffsetForCharacter(PP_Resource font_id, |
| 68 const PP_TextRun_Dev* text, |
| 69 uint32_t char_offset) { |
| 70 EnterResource<PPB_Font_API> enter(font_id, true); |
| 71 if (enter.failed()) |
| 72 return -1; |
| 73 return enter.object()->PixelOffsetForCharacter(text, char_offset); |
| 74 } |
| 75 |
| 76 const PPB_Font_Dev g_ppb_font_thunk = { |
| 77 &Create, |
| 78 &IsFont, |
| 79 &Describe, |
| 80 &DrawTextAt, |
| 81 &MeasureText, |
| 82 &CharacterOffsetForPixel, |
| 83 &PixelOffsetForCharacter |
| 84 }; |
| 85 |
| 86 } // namespace |
| 87 |
| 88 const PPB_Font_Dev* GetPPB_Font_Thunk() { |
| 89 return &g_ppb_font_thunk; |
| 90 } |
| 91 |
| 92 } // namespace thunk |
| 93 } // namespace ppapi |
OLD | NEW |