Merge Chromium + Blink git repositories
[chromium-blink-merge.git] / ppapi / thunk / ppb_browser_font_trusted_thunk.cc
blobdb39982d52f801adfe2c9fc2cca246ff984d36ff
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.
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"
11 namespace ppapi {
12 namespace thunk {
14 namespace {
16 typedef EnterResource<PPB_BrowserFont_Trusted_API> EnterBrowserFont;
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();
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;
31 PP_Bool IsBrowserFont(PP_Resource resource) {
32 EnterBrowserFont enter(resource, false);
33 return enter.succeeded() ? PP_TRUE : PP_FALSE;
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;
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;
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;
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;
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;
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
92 } // namespace
94 const PPB_BrowserFont_Trusted_1_0* GetPPB_BrowserFont_Trusted_1_0_Thunk() {
95 return &g_ppb_browser_font_trusted_thunk;
98 } // namespace thunk
99 } // namespace ppapi