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/shared_impl/private/ppb_browser_font_trusted_shared.h" | 5 #include "ppapi/shared_impl/private/ppb_browser_font_trusted_shared.h" |
6 | 6 |
7 #include <unicode/uscript.h> | |
viettrungluu
2012/05/15 17:21:17
This is a dependency on ICU, and should be #includ
| |
8 | |
7 #include "base/string_util.h" | 9 #include "base/string_util.h" |
8 #include "base/utf_string_conversions.h" | 10 #include "base/utf_string_conversions.h" |
9 #include "ppapi/c/dev/ppb_font_dev.h" | 11 #include "ppapi/c/dev/ppb_font_dev.h" |
10 #include "ppapi/shared_impl/ppapi_preferences.h" | 12 #include "ppapi/shared_impl/ppapi_preferences.h" |
11 #include "ppapi/shared_impl/var.h" | 13 #include "ppapi/shared_impl/var.h" |
12 #include "ppapi/thunk/enter.h" | 14 #include "ppapi/thunk/enter.h" |
13 #include "ppapi/thunk/ppb_image_data_api.h" | 15 #include "ppapi/thunk/ppb_image_data_api.h" |
14 #include "ppapi/thunk/thunk.h" | 16 #include "ppapi/thunk/thunk.h" |
15 #include "skia/ext/platform_canvas.h" | 17 #include "skia/ext/platform_canvas.h" |
16 #include "third_party/skia/include/core/SkRect.h" | 18 #include "third_party/skia/include/core/SkRect.h" |
(...skipping 13 matching lines...) Expand all Loading... | |
30 using WebKit::WebFont; | 32 using WebKit::WebFont; |
31 using WebKit::WebFontDescription; | 33 using WebKit::WebFontDescription; |
32 using WebKit::WebRect; | 34 using WebKit::WebRect; |
33 using WebKit::WebTextRun; | 35 using WebKit::WebTextRun; |
34 using WebKit::WebCanvas; | 36 using WebKit::WebCanvas; |
35 | 37 |
36 namespace ppapi { | 38 namespace ppapi { |
37 | 39 |
38 namespace { | 40 namespace { |
39 | 41 |
42 const char* kCommonScript = uscript_getShortName(USCRIPT_COMMON); | |
viettrungluu
2012/05/15 17:21:17
I don't think we want to add this static initializ
brettw
2012/05/15 22:53:11
Right.
| |
43 | |
44 string16 GetFontFromMap( | |
45 const webkit_glue::WebPreferences::ScriptFontFamilyMap& map, | |
46 const std::string& script) { | |
47 webkit_glue::WebPreferences::ScriptFontFamilyMap::const_iterator it = | |
48 map.find(script); | |
49 if (it != map.end()) | |
50 return it->second; | |
51 return string16(); | |
52 } | |
53 | |
40 bool PPTextRunToWebTextRun(const PP_BrowserFont_Trusted_TextRun& text, | 54 bool PPTextRunToWebTextRun(const PP_BrowserFont_Trusted_TextRun& text, |
41 WebTextRun* run) { | 55 WebTextRun* run) { |
42 StringVar* text_string = StringVar::FromPPVar(text.text); | 56 StringVar* text_string = StringVar::FromPPVar(text.text); |
43 if (!text_string) | 57 if (!text_string) |
44 return false; | 58 return false; |
45 | 59 |
46 *run = WebTextRun(UTF8ToUTF16(text_string->value()), | 60 *run = WebTextRun(UTF8ToUTF16(text_string->value()), |
47 PP_ToBool(text.rtl), | 61 PP_ToBool(text.rtl), |
48 PP_ToBool(text.override_direction)); | 62 PP_ToBool(text.override_direction)); |
49 return true; | 63 return true; |
(...skipping 31 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... | |
81 MonospaceFamily); | 95 MonospaceFamily); |
82 | 96 |
83 StringVar* face_name = StringVar::FromPPVar(font.face); // Possibly null. | 97 StringVar* face_name = StringVar::FromPPVar(font.face); // Possibly null. |
84 | 98 |
85 WebFontDescription result; | 99 WebFontDescription result; |
86 string16 resolved_family; | 100 string16 resolved_family; |
87 if (!face_name || face_name->value().empty()) { | 101 if (!face_name || face_name->value().empty()) { |
88 // Resolve the generic family. | 102 // Resolve the generic family. |
89 switch (font.family) { | 103 switch (font.family) { |
90 case PP_BROWSERFONT_TRUSTED_FAMILY_SERIF: | 104 case PP_BROWSERFONT_TRUSTED_FAMILY_SERIF: |
91 resolved_family = prefs.serif_font_family; | 105 resolved_family = GetFontFromMap(prefs.serif_font_family_map, |
106 kCommonScript); | |
92 break; | 107 break; |
93 case PP_BROWSERFONT_TRUSTED_FAMILY_SANSSERIF: | 108 case PP_BROWSERFONT_TRUSTED_FAMILY_SANSSERIF: |
94 resolved_family = prefs.sans_serif_font_family; | 109 resolved_family = GetFontFromMap(prefs.sans_serif_font_family_map, |
110 kCommonScript); | |
95 break; | 111 break; |
96 case PP_BROWSERFONT_TRUSTED_FAMILY_MONOSPACE: | 112 case PP_BROWSERFONT_TRUSTED_FAMILY_MONOSPACE: |
97 resolved_family = prefs.fixed_font_family; | 113 resolved_family = GetFontFromMap(prefs.fixed_font_family_map, |
114 kCommonScript); | |
98 break; | 115 break; |
99 case PP_BROWSERFONT_TRUSTED_FAMILY_DEFAULT: | 116 case PP_BROWSERFONT_TRUSTED_FAMILY_DEFAULT: |
100 default: | 117 default: |
101 resolved_family = prefs.standard_font_family; | 118 resolved_family = GetFontFromMap(prefs.standard_font_family_map, |
119 kCommonScript); | |
102 break; | 120 break; |
103 } | 121 } |
104 } else { | 122 } else { |
105 // Use the exact font. | 123 // Use the exact font. |
106 resolved_family = UTF8ToUTF16(face_name->value()); | 124 resolved_family = UTF8ToUTF16(face_name->value()); |
107 } | 125 } |
108 result.family = resolved_family; | 126 result.family = resolved_family; |
109 | 127 |
110 result.genericFamily = PP_FAMILY_TO_WEB_FAMILY(font.family); | 128 result.genericFamily = PP_FAMILY_TO_WEB_FAMILY(font.family); |
111 | 129 |
112 if (font.size == 0) { | 130 if (font.size == 0) { |
113 // Resolve the default font size, using the resolved family to see if | 131 // Resolve the default font size, using the resolved family to see if |
114 // we should use the fixed or regular font size. It's difficult at this | 132 // we should use the fixed or regular font size. It's difficult at this |
115 // level to detect if the requested font is fixed width, so we only apply | 133 // level to detect if the requested font is fixed width, so we only apply |
116 // the alternate font size to the default fixed font family. | 134 // the alternate font size to the default fixed font family. |
117 if (StringToLowerASCII(resolved_family) == | 135 if (StringToLowerASCII(resolved_family) == |
118 StringToLowerASCII(prefs.fixed_font_family)) | 136 StringToLowerASCII(GetFontFromMap(prefs.fixed_font_family_map, |
137 kCommonScript))) | |
119 result.size = static_cast<float>(prefs.default_fixed_font_size); | 138 result.size = static_cast<float>(prefs.default_fixed_font_size); |
120 else | 139 else |
121 result.size = static_cast<float>(prefs.default_font_size); | 140 result.size = static_cast<float>(prefs.default_font_size); |
122 } else { | 141 } else { |
123 // Use the exact size. | 142 // Use the exact size. |
124 result.size = static_cast<float>(font.size); | 143 result.size = static_cast<float>(font.size); |
125 } | 144 } |
126 | 145 |
127 result.italic = font.italic != PP_FALSE; | 146 result.italic = font.italic != PP_FALSE; |
128 result.smallCaps = font.small_caps != PP_FALSE; | 147 result.smallCaps = font.small_caps != PP_FALSE; |
(...skipping 178 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... | |
307 } else { | 326 } else { |
308 web_clip = WebRect(clip->point.x, clip->point.y, | 327 web_clip = WebRect(clip->point.x, clip->point.y, |
309 clip->size.width, clip->size.height); | 328 clip->size.width, clip->size.height); |
310 } | 329 } |
311 | 330 |
312 font_->drawText(destination, run, web_position, color, web_clip, | 331 font_->drawText(destination, run, web_position, color, web_clip, |
313 PP_ToBool(image_data_is_opaque)); | 332 PP_ToBool(image_data_is_opaque)); |
314 } | 333 } |
315 | 334 |
316 } // namespace ppapi | 335 } // namespace ppapi |
317 | |
OLD | NEW |