Chromium Code Reviews
chromiumcodereview-hr@appspot.gserviceaccount.com (chromiumcodereview-hr) | Please choose your nickname with Settings | Help | Chromium Project | Gerrit Changes | Sign out
(96)

Side by Side Diff: webkit/plugins/ppapi/ppb_font_impl.cc

Issue 9192038: Relanding this with fixes to the mac dbg builder (Closed) Base URL: svn://svn.chromium.org/chrome/trunk/src/
Patch Set: '' Created 8 years, 11 months ago
Use n/p to move between diff chunks; N/P to move between comments. Draft comments are only viewable by you.
Jump to:
View unified diff | Download patch | Annotate | Revision Log
« no previous file with comments | « webkit/plugins/ppapi/ppb_font_impl.h ('k') | webkit/plugins/ppapi/ppb_graphics_2d_impl.cc » ('j') | no next file with comments »
Toggle Intra-line Diffs ('i') | Expand Comments ('e') | Collapse Comments ('c') | Show Comments Hide Comments ('s')
OLDNEW
1 // Copyright (c) 2011 The Chromium Authors. All rights reserved. 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 2 // Use of this source code is governed by a BSD-style license that can be
3 // found in the LICENSE file. 3 // found in the LICENSE file.
4 4
5 #include "webkit/plugins/ppapi/ppb_font_impl.h" 5 #include "webkit/plugins/ppapi/ppb_font_impl.h"
6 6
7 #include "ppapi/c/dev/ppb_font_dev.h"
8 #include "ppapi/shared_impl/ppapi_preferences.h"
9 #include "ppapi/shared_impl/ppb_font_shared.h"
10 #include "ppapi/shared_impl/var.h"
11 #include "ppapi/thunk/enter.h"
12 #include "ppapi/thunk/thunk.h"
13 #include "webkit/plugins/ppapi/common.h"
14 #include "webkit/plugins/ppapi/plugin_module.h"
15 #include "webkit/plugins/ppapi/ppapi_plugin_instance.h" 7 #include "webkit/plugins/ppapi/ppapi_plugin_instance.h"
16 #include "webkit/plugins/ppapi/ppb_image_data_impl.h"
17 #include "webkit/plugins/ppapi/resource_helper.h"
18 #include "webkit/plugins/ppapi/string.h"
19
20 using ppapi::StringVar;
21 using ppapi::thunk::EnterResource;
22 using ppapi::thunk::PPB_ImageData_API;
23 using ppapi::WebKitForwarding;
24 8
25 namespace webkit { 9 namespace webkit {
10
26 namespace ppapi { 11 namespace ppapi {
27 12
28 namespace {
29
30 // Converts the given PP_TextRun to a TextRun, returning true on success.
31 // False means the input was invalid.
32 bool PPTextRunToTextRun(const PP_TextRun_Dev* run,
33 WebKitForwarding::Font::TextRun* output) {
34 StringVar* text_string = StringVar::FromPPVar(run->text);
35 if (!text_string)
36 return false;
37
38 output->text = text_string->value();
39 output->rtl = PPBoolToBool(run->rtl);
40 output->override_direction = PPBoolToBool(run->override_direction);
41 return true;
42 }
43
44 } // namespace
45
46 PPB_Font_Impl::PPB_Font_Impl(PP_Instance pp_instance,
47 const PP_FontDescription_Dev& desc)
48 : Resource(pp_instance) {
49 StringVar* face_name = StringVar::FromPPVar(desc.face);
50
51 WebKitForwarding::Font* result = NULL;
52 PluginInstance* plugin_instance = ResourceHelper::GetPluginInstance(this);
53 if (plugin_instance) {
54 plugin_instance->module()->GetWebKitForwarding()->CreateFontForwarding(
55 NULL, desc, face_name ? face_name->value() : std::string(),
56 plugin_instance->delegate()->GetPreferences(), &result);
57 }
58 font_forwarding_.reset(result);
59 }
60
61 PPB_Font_Impl::~PPB_Font_Impl() {
62 }
63
64 // static
65 PP_Resource PPB_Font_Impl::Create(PP_Instance instance,
66 const PP_FontDescription_Dev& description) {
67 if (!::ppapi::PPB_Font_Shared::IsPPFontDescriptionValid(description))
68 return 0;
69 return (new PPB_Font_Impl(instance, description))->GetReference();
70 }
71
72 ::ppapi::thunk::PPB_Font_API* PPB_Font_Impl::AsPPB_Font_API() {
73 return this;
74 }
75
76 PP_Bool PPB_Font_Impl::Describe(PP_FontDescription_Dev* description,
77 PP_FontMetrics_Dev* metrics) {
78 std::string face;
79 PP_Bool result = PP_FALSE;
80 font_forwarding_->Describe(NULL, description, &face, metrics, &result);
81 if (!result)
82 return PP_FALSE;
83
84 PluginModule* plugin_module = ResourceHelper::GetPluginModule(this);
85 if (!plugin_module)
86 return PP_FALSE;
87
88 // Convert the string.
89 description->face = StringVar::StringToPPVar(face);
90 return PP_TRUE;
91 }
92
93 PP_Bool PPB_Font_Impl::DrawTextAt(PP_Resource image_data,
94 const PP_TextRun_Dev* text,
95 const PP_Point* position,
96 uint32_t color,
97 const PP_Rect* clip,
98 PP_Bool image_data_is_opaque) {
99 // Get and map the image data we're painting to.
100 EnterResource<PPB_ImageData_API> enter(image_data, true);
101 if (enter.failed())
102 return PP_FALSE;
103 PPB_ImageData_Impl* image_resource =
104 static_cast<PPB_ImageData_Impl*>(enter.object());
105
106 ImageDataAutoMapper mapper(image_resource);
107 if (!mapper.is_valid())
108 return PP_FALSE;
109
110 WebKitForwarding::Font::TextRun run;
111 if (!PPTextRunToTextRun(text, &run))
112 return PP_FALSE;
113
114 font_forwarding_->DrawTextAt(NULL, WebKitForwarding::Font::DrawTextParams(
115 image_resource->mapped_canvas(), run, position,
116 color, clip, image_data_is_opaque));
117 return PP_TRUE;
118 }
119
120 int32_t PPB_Font_Impl::MeasureText(const PP_TextRun_Dev* text) {
121 int32_t result = -1;
122 WebKitForwarding::Font::TextRun run;
123 if (PPTextRunToTextRun(text, &run))
124 font_forwarding_->MeasureText(NULL, run, &result);
125 return result;
126 }
127
128 uint32_t PPB_Font_Impl::CharacterOffsetForPixel(const PP_TextRun_Dev* text,
129 int32_t pixel_position) {
130 uint32_t result = -1;
131 WebKitForwarding::Font::TextRun run;
132 if (PPTextRunToTextRun(text, &run)) {
133 font_forwarding_->CharacterOffsetForPixel(NULL, run, pixel_position,
134 &result);
135 }
136 return result;
137 }
138
139 int32_t PPB_Font_Impl::PixelOffsetForCharacter(const PP_TextRun_Dev* text,
140 uint32_t char_offset) {
141 int32_t result = -1;
142 WebKitForwarding::Font::TextRun run;
143 if (PPTextRunToTextRun(text, &run)) {
144 font_forwarding_->PixelOffsetForCharacter(NULL, run, char_offset, &result);
145 }
146 return result;
147 }
148
149 PPB_Font_FunctionImpl::PPB_Font_FunctionImpl(PluginInstance* instance) 13 PPB_Font_FunctionImpl::PPB_Font_FunctionImpl(PluginInstance* instance)
150 : instance_(instance) { 14 : instance_(instance) {
151 } 15 }
152 16
153 PPB_Font_FunctionImpl::~PPB_Font_FunctionImpl() { 17 PPB_Font_FunctionImpl::~PPB_Font_FunctionImpl() {
154 } 18 }
155 19
156 ::ppapi::thunk::PPB_Font_FunctionAPI* 20 ::ppapi::thunk::PPB_Font_FunctionAPI*
157 PPB_Font_FunctionImpl::AsFont_FunctionAPI() { 21 PPB_Font_FunctionImpl::AsFont_FunctionAPI() {
158 return this; 22 return this;
159 } 23 }
160 24
25 // TODO(ananta)
26 // We need to wire this up to the proxy.
161 PP_Var PPB_Font_FunctionImpl::GetFontFamilies(PP_Instance instance) { 27 PP_Var PPB_Font_FunctionImpl::GetFontFamilies(PP_Instance instance) {
162 return PP_MakeUndefined(); 28 return PP_MakeUndefined();
163 } 29 }
164 30
165 } // namespace ppapi 31 } // namespace ppapi
32
166 } // namespace webkit 33 } // namespace webkit
167
OLDNEW
« no previous file with comments | « webkit/plugins/ppapi/ppb_font_impl.h ('k') | webkit/plugins/ppapi/ppb_graphics_2d_impl.cc » ('j') | no next file with comments »

Powered by Google App Engine
This is Rietveld 408576698