OLD | NEW |
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/proxy/browser_font_resource_trusted.h" | 5 #include "content/child/browser_font_resource_trusted.h" |
6 | 6 |
7 #include "base/strings/string_util.h" | 7 #include "base/strings/string_util.h" |
8 #include "base/strings/utf_string_conversions.h" | 8 #include "base/strings/utf_string_conversions.h" |
9 #include "ppapi/c/dev/ppb_font_dev.h" | 9 #include "ppapi/c/dev/ppb_font_dev.h" |
| 10 #include "ppapi/proxy/connection.h" |
10 #include "ppapi/shared_impl/ppapi_preferences.h" | 11 #include "ppapi/shared_impl/ppapi_preferences.h" |
11 #include "ppapi/shared_impl/var.h" | 12 #include "ppapi/shared_impl/var.h" |
12 #include "ppapi/thunk/enter.h" | 13 #include "ppapi/thunk/enter.h" |
13 #include "ppapi/thunk/ppb_image_data_api.h" | 14 #include "ppapi/thunk/ppb_image_data_api.h" |
14 #include "ppapi/thunk/thunk.h" | 15 #include "ppapi/thunk/thunk.h" |
15 #include "skia/ext/platform_canvas.h" | 16 #include "skia/ext/platform_canvas.h" |
16 #include "third_party/WebKit/public/platform/WebCanvas.h" | 17 #include "third_party/WebKit/public/platform/WebCanvas.h" |
17 #include "third_party/WebKit/public/platform/WebFloatPoint.h" | 18 #include "third_party/WebKit/public/platform/WebFloatPoint.h" |
18 #include "third_party/WebKit/public/platform/WebFloatRect.h" | 19 #include "third_party/WebKit/public/platform/WebFloatRect.h" |
19 #include "third_party/WebKit/public/platform/WebRect.h" | 20 #include "third_party/WebKit/public/platform/WebRect.h" |
20 #include "third_party/WebKit/public/web/WebFont.h" | 21 #include "third_party/WebKit/public/web/WebFont.h" |
21 #include "third_party/WebKit/public/web/WebFontDescription.h" | 22 #include "third_party/WebKit/public/web/WebFontDescription.h" |
22 #include "third_party/WebKit/public/web/WebTextRun.h" | 23 #include "third_party/WebKit/public/web/WebTextRun.h" |
23 #include "third_party/icu/source/common/unicode/ubidi.h" | 24 #include "third_party/icu/source/common/unicode/ubidi.h" |
24 #include "third_party/skia/include/core/SkRect.h" | 25 #include "third_party/skia/include/core/SkRect.h" |
25 | 26 |
26 using ppapi::StringVar; | 27 using ppapi::StringVar; |
27 using ppapi::thunk::EnterResourceNoLock; | 28 using ppapi::thunk::EnterResourceNoLock; |
28 using ppapi::thunk::PPB_ImageData_API; | 29 using ppapi::thunk::PPB_ImageData_API; |
29 using WebKit::WebFloatPoint; | 30 using WebKit::WebFloatPoint; |
30 using WebKit::WebFloatRect; | 31 using WebKit::WebFloatRect; |
31 using WebKit::WebFont; | 32 using WebKit::WebFont; |
32 using WebKit::WebFontDescription; | 33 using WebKit::WebFontDescription; |
33 using WebKit::WebRect; | 34 using WebKit::WebRect; |
34 using WebKit::WebTextRun; | 35 using WebKit::WebTextRun; |
35 using WebKit::WebCanvas; | 36 using WebKit::WebCanvas; |
36 | 37 |
37 namespace ppapi { | 38 namespace content { |
38 namespace proxy { | |
39 | 39 |
40 namespace { | 40 namespace { |
41 | 41 |
42 // Same as WebPreferences::kCommonScript. I'd use that directly here, but get an | 42 // Same as WebPreferences::kCommonScript. I'd use that directly here, but get an |
43 // undefined reference linker error. | 43 // undefined reference linker error. |
44 const char kCommonScript[] = "Zyyy"; | 44 const char kCommonScript[] = "Zyyy"; |
45 | 45 |
46 string16 GetFontFromMap( | 46 string16 GetFontFromMap( |
47 const webkit_glue::ScriptFontFamilyMap& map, | 47 const webkit_glue::ScriptFontFamilyMap& map, |
48 const std::string& script) { | 48 const std::string& script) { |
(...skipping 87 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
136 // The PP_* version lacks "None", so is just one value shifted from the | 136 // The PP_* version lacks "None", so is just one value shifted from the |
137 // WebFontDescription version. These values are checked in | 137 // WebFontDescription version. These values are checked in |
138 // PPFontDescToWebFontDesc to make sure the conversion is correct. This is a | 138 // PPFontDescToWebFontDesc to make sure the conversion is correct. This is a |
139 // macro so it can also be used in the COMPILE_ASSERTS. | 139 // macro so it can also be used in the COMPILE_ASSERTS. |
140 #define PP_FAMILY_TO_WEB_FAMILY(f) \ | 140 #define PP_FAMILY_TO_WEB_FAMILY(f) \ |
141 static_cast<WebFontDescription::GenericFamily>(f + 1) | 141 static_cast<WebFontDescription::GenericFamily>(f + 1) |
142 | 142 |
143 // Assumes the given PP_FontDescription has been validated. | 143 // Assumes the given PP_FontDescription has been validated. |
144 WebFontDescription PPFontDescToWebFontDesc( | 144 WebFontDescription PPFontDescToWebFontDesc( |
145 const PP_BrowserFont_Trusted_Description& font, | 145 const PP_BrowserFont_Trusted_Description& font, |
146 const Preferences& prefs) { | 146 const ppapi::Preferences& prefs) { |
147 // Verify that the enums match so we can just static cast. | 147 // Verify that the enums match so we can just static cast. |
148 COMPILE_ASSERT(static_cast<int>(WebFontDescription::Weight100) == | 148 COMPILE_ASSERT(static_cast<int>(WebFontDescription::Weight100) == |
149 static_cast<int>(PP_BROWSERFONT_TRUSTED_WEIGHT_100), | 149 static_cast<int>(PP_BROWSERFONT_TRUSTED_WEIGHT_100), |
150 FontWeight100); | 150 FontWeight100); |
151 COMPILE_ASSERT(static_cast<int>(WebFontDescription::Weight900) == | 151 COMPILE_ASSERT(static_cast<int>(WebFontDescription::Weight900) == |
152 static_cast<int>(PP_BROWSERFONT_TRUSTED_WEIGHT_900), | 152 static_cast<int>(PP_BROWSERFONT_TRUSTED_WEIGHT_900), |
153 FontWeight900); | 153 FontWeight900); |
154 COMPILE_ASSERT(WebFontDescription::GenericFamilyStandard == | 154 COMPILE_ASSERT(WebFontDescription::GenericFamilyStandard == |
155 PP_FAMILY_TO_WEB_FAMILY(PP_FONTFAMILY_DEFAULT), | 155 PP_FAMILY_TO_WEB_FAMILY(PP_FONTFAMILY_DEFAULT), |
156 StandardFamily); | 156 StandardFamily); |
(...skipping 84 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
241 return false; | 241 return false; |
242 | 242 |
243 // Check for excessive sizes which may cause layout to get confused. | 243 // Check for excessive sizes which may cause layout to get confused. |
244 if (desc.size > 200) | 244 if (desc.size > 200) |
245 return false; | 245 return false; |
246 | 246 |
247 return true; | 247 return true; |
248 } | 248 } |
249 | 249 |
250 BrowserFontResource_Trusted::BrowserFontResource_Trusted( | 250 BrowserFontResource_Trusted::BrowserFontResource_Trusted( |
251 Connection connection, | 251 ppapi::proxy::Connection connection, |
252 PP_Instance instance, | 252 PP_Instance instance, |
253 const PP_BrowserFont_Trusted_Description& desc, | 253 const PP_BrowserFont_Trusted_Description& desc, |
254 const Preferences& prefs) | 254 const ppapi::Preferences& prefs) |
255 : PluginResource(connection, instance), | 255 : PluginResource(connection, instance), |
256 font_(WebFont::create(PPFontDescToWebFontDesc(desc, prefs))) { | 256 font_(WebFont::create(PPFontDescToWebFontDesc(desc, prefs))) { |
257 } | 257 } |
258 | 258 |
259 BrowserFontResource_Trusted::~BrowserFontResource_Trusted() { | 259 BrowserFontResource_Trusted::~BrowserFontResource_Trusted() { |
260 } | 260 } |
261 | 261 |
262 thunk::PPB_BrowserFont_Trusted_API* | 262 ppapi::thunk::PPB_BrowserFont_Trusted_API* |
263 BrowserFontResource_Trusted::AsPPB_BrowserFont_Trusted_API() { | 263 BrowserFontResource_Trusted::AsPPB_BrowserFont_Trusted_API() { |
264 return this; | 264 return this; |
265 } | 265 } |
266 | 266 |
267 PP_Bool BrowserFontResource_Trusted::Describe( | 267 PP_Bool BrowserFontResource_Trusted::Describe( |
268 PP_BrowserFont_Trusted_Description* description, | 268 PP_BrowserFont_Trusted_Description* description, |
269 PP_BrowserFont_Trusted_Metrics* metrics) { | 269 PP_BrowserFont_Trusted_Metrics* metrics) { |
270 if (description->face.type != PP_VARTYPE_UNDEFINED) | 270 if (description->face.type != PP_VARTYPE_UNDEFINED) |
271 return PP_FALSE; | 271 return PP_FALSE; |
272 | 272 |
(...skipping 145 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
418 PP_ToBool(image_data_is_opaque)); | 418 PP_ToBool(image_data_is_opaque)); |
419 | 419 |
420 // Advance to the next run. Note that we avoid doing this for the last run | 420 // Advance to the next run. Note that we avoid doing this for the last run |
421 // since it's unnecessary, measuring text is slow, and most of the time | 421 // since it's unnecessary, measuring text is slow, and most of the time |
422 // there will be only one run anyway. | 422 // there will be only one run anyway. |
423 if (i != runs.num_runs() - 1) | 423 if (i != runs.num_runs() - 1) |
424 web_position.x += font_->calculateWidth(run); | 424 web_position.x += font_->calculateWidth(run); |
425 } | 425 } |
426 } | 426 } |
427 | 427 |
428 } // namespace proxy | 428 } // namespace content |
429 } // namespace ppapi | |
OLD | NEW |