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

Side by Side Diff: ppapi/cpp/trusted/browser_font_trusted.cc

Issue 1428653002: PPAPI: Remove PPB_Font_Dev. (Closed) Base URL: https://chromium.googlesource.com/chromium/src.git@master
Patch Set: rebase Created 5 years, 1 month 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
« no previous file with comments | « ppapi/cpp/private/flash_font_file.cc ('k') | ppapi/examples/ime/ime.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) 2012 The Chromium Authors. All rights reserved. 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 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 "ppapi/cpp/trusted/browser_font_trusted.h" 5 #include "ppapi/cpp/trusted/browser_font_trusted.h"
6 6
7 #include <algorithm> 7 #include <algorithm>
8 8
9 #include "ppapi/c/dev/ppb_font_dev.h"
10 #include "ppapi/cpp/image_data.h" 9 #include "ppapi/cpp/image_data.h"
11 #include "ppapi/cpp/instance_handle.h" 10 #include "ppapi/cpp/instance_handle.h"
12 #include "ppapi/cpp/point.h" 11 #include "ppapi/cpp/point.h"
13 #include "ppapi/cpp/rect.h" 12 #include "ppapi/cpp/rect.h"
14 #include "ppapi/cpp/module_impl.h" 13 #include "ppapi/cpp/module_impl.h"
15 14
16 namespace pp { 15 namespace pp {
17 16
18 namespace { 17 namespace {
19 18
20 template <> const char* interface_name<PPB_BrowserFont_Trusted_1_0>() { 19 template <> const char* interface_name<PPB_BrowserFont_Trusted_1_0>() {
21 return PPB_BROWSERFONT_TRUSTED_INTERFACE_1_0; 20 return PPB_BROWSERFONT_TRUSTED_INTERFACE_1_0;
22 } 21 }
23 template <> const char* interface_name<PPB_Font_Dev_0_6>() {
24 return PPB_FONT_DEV_INTERFACE_0_6;
25 }
26
27 // This class provides backwards compat for PPB_Font, which is binary
28 // compatible with the BrowserFont interface.
29 // TODO(brettw) remove PPB_Font altogether when Flash is updated.
30 const PP_FontDescription_Dev* BrowserFontDescToFontDesc(
31 const PP_BrowserFont_Trusted_Description* desc) {
32 return reinterpret_cast<const PP_FontDescription_Dev*>(desc);
33 }
34 PP_FontDescription_Dev* BrowserFontDescToFontDesc(
35 PP_BrowserFont_Trusted_Description* desc) {
36 return reinterpret_cast<PP_FontDescription_Dev*>(desc);
37 }
38 PP_FontMetrics_Dev* BrowserFontMetricsToFontMetrics(
39 PP_BrowserFont_Trusted_Metrics* metrics) {
40 return reinterpret_cast<PP_FontMetrics_Dev*>(metrics);
41 }
42 const PP_TextRun_Dev* BrowserFontTextRunToFontTextRun(
43 const PP_BrowserFont_Trusted_TextRun* run) {
44 return reinterpret_cast<const PP_TextRun_Dev*>(run);
45 }
46 22
47 } // namespace 23 } // namespace
48 24
49 // BrowserFontDescription ------------------------------------------------------ 25 // BrowserFontDescription ------------------------------------------------------
50 26
51 BrowserFontDescription::BrowserFontDescription() { 27 BrowserFontDescription::BrowserFontDescription() {
52 pp_font_description_.face = face_.pp_var(); 28 pp_font_description_.face = face_.pp_var();
53 set_family(PP_BROWSERFONT_TRUSTED_FAMILY_DEFAULT); 29 set_family(PP_BROWSERFONT_TRUSTED_FAMILY_DEFAULT);
54 set_size(0); 30 set_size(0);
55 set_weight(PP_BROWSERFONT_TRUSTED_WEIGHT_NORMAL); 31 set_weight(PP_BROWSERFONT_TRUSTED_WEIGHT_NORMAL);
(...skipping 74 matching lines...) Expand 10 before | Expand all | Expand 10 after
130 : Resource(resource) { 106 : Resource(resource) {
131 } 107 }
132 108
133 BrowserFont_Trusted::BrowserFont_Trusted( 109 BrowserFont_Trusted::BrowserFont_Trusted(
134 const InstanceHandle& instance, 110 const InstanceHandle& instance,
135 const BrowserFontDescription& description) { 111 const BrowserFontDescription& description) {
136 if (has_interface<PPB_BrowserFont_Trusted_1_0>()) { 112 if (has_interface<PPB_BrowserFont_Trusted_1_0>()) {
137 PassRefFromConstructor(get_interface<PPB_BrowserFont_Trusted_1_0>()->Create( 113 PassRefFromConstructor(get_interface<PPB_BrowserFont_Trusted_1_0>()->Create(
138 instance.pp_instance(), 114 instance.pp_instance(),
139 &description.pp_font_description())); 115 &description.pp_font_description()));
140 } else if (!has_interface<PPB_Font_Dev_0_6>()) {
141 PassRefFromConstructor(get_interface<PPB_Font_Dev_0_6>()->Create(
142 instance.pp_instance(),
143 BrowserFontDescToFontDesc(&description.pp_font_description())));
144 } 116 }
145 } 117 }
146 118
147 BrowserFont_Trusted::BrowserFont_Trusted(const BrowserFont_Trusted& other) 119 BrowserFont_Trusted::BrowserFont_Trusted(const BrowserFont_Trusted& other)
148 : Resource(other) { 120 : Resource(other) {
149 } 121 }
150 122
151 BrowserFont_Trusted& BrowserFont_Trusted::operator=( 123 BrowserFont_Trusted& BrowserFont_Trusted::operator=(
152 const BrowserFont_Trusted& other) { 124 const BrowserFont_Trusted& other) {
153 Resource::operator=(other); 125 Resource::operator=(other);
154 return *this; 126 return *this;
155 } 127 }
156 128
157 // static 129 // static
158 Var BrowserFont_Trusted::GetFontFamilies(const InstanceHandle& instance) { 130 Var BrowserFont_Trusted::GetFontFamilies(const InstanceHandle& instance) {
159 if (!has_interface<PPB_Font_Dev_0_6>()) 131 if (!has_interface<PPB_BrowserFont_Trusted_1_0>())
160 return Var(); 132 return Var();
133
161 return Var(PASS_REF, 134 return Var(PASS_REF,
162 get_interface<PPB_Font_Dev_0_6>()->GetFontFamilies( 135 get_interface<PPB_BrowserFont_Trusted_1_0>()->GetFontFamilies(
163 instance.pp_instance())); 136 instance.pp_instance()));
164 } 137 }
165 138
166 bool BrowserFont_Trusted::Describe( 139 bool BrowserFont_Trusted::Describe(
167 BrowserFontDescription* description, 140 BrowserFontDescription* description,
168 PP_BrowserFont_Trusted_Metrics* metrics) const { 141 PP_BrowserFont_Trusted_Metrics* metrics) const {
169 // Be careful with ownership of the |face| string. It will come back with 142 // Be careful with ownership of the |face| string. It will come back with
170 // a ref of 1, which we want to assign to the |face_| member of the C++ class. 143 // a ref of 1, which we want to assign to the |face_| member of the C++ class.
171 if (has_interface<PPB_BrowserFont_Trusted_1_0>()) { 144 if (has_interface<PPB_BrowserFont_Trusted_1_0>()) {
172 if (!get_interface<PPB_BrowserFont_Trusted_1_0>()->Describe( 145 if (!get_interface<PPB_BrowserFont_Trusted_1_0>()->Describe(
173 pp_resource(), &description->pp_font_description_, metrics)) 146 pp_resource(), &description->pp_font_description_, metrics))
174 return false; 147 return false;
175 } else if (!has_interface<PPB_Font_Dev_0_6>()) {
176 if (!get_interface<PPB_Font_Dev_0_6>()->Describe(
177 pp_resource(),
178 BrowserFontDescToFontDesc(&description->pp_font_description_),
179 BrowserFontMetricsToFontMetrics(metrics)))
180 return false;
181 } 148 }
182 description->face_ = Var(PASS_REF, 149 description->face_ = Var(PASS_REF,
183 description->pp_font_description_.face); 150 description->pp_font_description_.face);
184 return true; 151 return true;
185 } 152 }
186 153
187 bool BrowserFont_Trusted::DrawTextAt(ImageData* dest, 154 bool BrowserFont_Trusted::DrawTextAt(ImageData* dest,
188 const BrowserFontTextRun& text, 155 const BrowserFontTextRun& text,
189 const Point& position, 156 const Point& position,
190 uint32_t color, 157 uint32_t color,
191 const Rect& clip, 158 const Rect& clip,
192 bool image_data_is_opaque) const { 159 bool image_data_is_opaque) const {
193 if (has_interface<PPB_BrowserFont_Trusted_1_0>()) { 160 if (has_interface<PPB_BrowserFont_Trusted_1_0>()) {
194 return PP_ToBool(get_interface<PPB_BrowserFont_Trusted_1_0>()->DrawTextAt( 161 return PP_ToBool(get_interface<PPB_BrowserFont_Trusted_1_0>()->DrawTextAt(
195 pp_resource(), 162 pp_resource(),
196 dest->pp_resource(), 163 dest->pp_resource(),
197 &text.pp_text_run(), 164 &text.pp_text_run(),
198 &position.pp_point(), 165 &position.pp_point(),
199 color, 166 color,
200 &clip.pp_rect(), 167 &clip.pp_rect(),
201 PP_FromBool(image_data_is_opaque))); 168 PP_FromBool(image_data_is_opaque)));
202 } else if (!has_interface<PPB_Font_Dev_0_6>()) {
203 return PP_ToBool(get_interface<PPB_Font_Dev_0_6>()->DrawTextAt(
204 pp_resource(),
205 dest->pp_resource(),
206 BrowserFontTextRunToFontTextRun(&text.pp_text_run()),
207 &position.pp_point(),
208 color,
209 &clip.pp_rect(),
210 PP_FromBool(image_data_is_opaque)));
211 } 169 }
212 return false; 170 return false;
213 } 171 }
214 172
215 int32_t BrowserFont_Trusted::MeasureText(const BrowserFontTextRun& text) const { 173 int32_t BrowserFont_Trusted::MeasureText(const BrowserFontTextRun& text) const {
216 if (has_interface<PPB_BrowserFont_Trusted_1_0>()) { 174 if (has_interface<PPB_BrowserFont_Trusted_1_0>()) {
217 return get_interface<PPB_BrowserFont_Trusted_1_0>()->MeasureText( 175 return get_interface<PPB_BrowserFont_Trusted_1_0>()->MeasureText(
218 pp_resource(), 176 pp_resource(),
219 &text.pp_text_run()); 177 &text.pp_text_run());
220 } else if (!has_interface<PPB_Font_Dev_0_6>()) {
221 return get_interface<PPB_Font_Dev_0_6>()->MeasureText(
222 pp_resource(),
223 BrowserFontTextRunToFontTextRun(&text.pp_text_run()));
224 } 178 }
225 return -1; 179 return -1;
226 } 180 }
227 181
228 uint32_t BrowserFont_Trusted::CharacterOffsetForPixel( 182 uint32_t BrowserFont_Trusted::CharacterOffsetForPixel(
229 const BrowserFontTextRun& text, 183 const BrowserFontTextRun& text,
230 int32_t pixel_position) const { 184 int32_t pixel_position) const {
231 if (has_interface<PPB_BrowserFont_Trusted_1_0>()) { 185 if (has_interface<PPB_BrowserFont_Trusted_1_0>()) {
232 return get_interface<PPB_BrowserFont_Trusted_1_0>()-> 186 return get_interface<PPB_BrowserFont_Trusted_1_0>()->
233 CharacterOffsetForPixel( 187 CharacterOffsetForPixel(
234 pp_resource(), 188 pp_resource(),
235 &text.pp_text_run(), 189 &text.pp_text_run(),
236 pixel_position); 190 pixel_position);
237 } else if (!has_interface<PPB_Font_Dev_0_6>()) {
238 return get_interface<PPB_Font_Dev_0_6>()->CharacterOffsetForPixel(
239 pp_resource(),
240 BrowserFontTextRunToFontTextRun(&text.pp_text_run()),
241 pixel_position);
242 } 191 }
243 return 0; 192 return 0;
244 } 193 }
245 194
246 int32_t BrowserFont_Trusted::PixelOffsetForCharacter( 195 int32_t BrowserFont_Trusted::PixelOffsetForCharacter(
247 const BrowserFontTextRun& text, 196 const BrowserFontTextRun& text,
248 uint32_t char_offset) const { 197 uint32_t char_offset) const {
249 if (has_interface<PPB_BrowserFont_Trusted_1_0>()) { 198 if (has_interface<PPB_BrowserFont_Trusted_1_0>()) {
250 return get_interface<PPB_BrowserFont_Trusted_1_0>()-> 199 return get_interface<PPB_BrowserFont_Trusted_1_0>()->
251 PixelOffsetForCharacter( 200 PixelOffsetForCharacter(
252 pp_resource(), 201 pp_resource(),
253 &text.pp_text_run(), 202 &text.pp_text_run(),
254 char_offset); 203 char_offset);
255 } else if (!has_interface<PPB_Font_Dev_0_6>()) {
256 return get_interface<PPB_Font_Dev_0_6>()->PixelOffsetForCharacter(
257 pp_resource(),
258 BrowserFontTextRunToFontTextRun(&text.pp_text_run()),
259 char_offset);
260 } 204 }
261 return 0; 205 return 0;
262 } 206 }
263 207
264 bool BrowserFont_Trusted::DrawSimpleText( 208 bool BrowserFont_Trusted::DrawSimpleText(
265 ImageData* dest, 209 ImageData* dest,
266 const std::string& text, 210 const std::string& text,
267 const Point& position, 211 const Point& position,
268 uint32_t color, 212 uint32_t color,
269 bool image_data_is_opaque) const { 213 bool image_data_is_opaque) const {
270 return DrawTextAt(dest, BrowserFontTextRun(text), position, color, 214 return DrawTextAt(dest, BrowserFontTextRun(text), position, color,
271 Rect(dest->size()), image_data_is_opaque); 215 Rect(dest->size()), image_data_is_opaque);
272 } 216 }
273 217
274 int32_t BrowserFont_Trusted::MeasureSimpleText(const std::string& text) const { 218 int32_t BrowserFont_Trusted::MeasureSimpleText(const std::string& text) const {
275 return MeasureText(BrowserFontTextRun(text)); 219 return MeasureText(BrowserFontTextRun(text));
276 } 220 }
277 221
278 } // namespace pp 222 } // namespace pp
OLDNEW
« no previous file with comments | « ppapi/cpp/private/flash_font_file.cc ('k') | ppapi/examples/ime/ime.cc » ('j') | no next file with comments »

Powered by Google App Engine
This is Rietveld 408576698