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

Side by Side Diff: ppapi/shared_impl/private/ppb_browser_font_trusted_shared.cc

Issue 10107014: Migrate WebKit "global script" font prefs. (Closed) Base URL: svn://svn.chromium.org/chrome/trunk/src
Patch Set: fix after sync Created 8 years, 7 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
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/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 "base/string_util.h" 7 #include "base/string_util.h"
8 #include "base/utf_string_conversions.h" 8 #include "base/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/shared_impl/ppapi_preferences.h" 10 #include "ppapi/shared_impl/ppapi_preferences.h"
(...skipping 19 matching lines...) Expand all
30 using WebKit::WebFont; 30 using WebKit::WebFont;
31 using WebKit::WebFontDescription; 31 using WebKit::WebFontDescription;
32 using WebKit::WebRect; 32 using WebKit::WebRect;
33 using WebKit::WebTextRun; 33 using WebKit::WebTextRun;
34 using WebKit::WebCanvas; 34 using WebKit::WebCanvas;
35 35
36 namespace ppapi { 36 namespace ppapi {
37 37
38 namespace { 38 namespace {
39 39
40 // The font family maps are from ISO 15924 script code to font. "Zyyy" is the
41 // ISO 15924 script code for undetermined script aka Common. It's the default
42 // used on WebKit's side to get/set a font setting when no script is specified.
43 const char kCommonScript[] = "Zyyy";
44
45 string16 GetFontFromMap(
46 const webkit_glue::WebPreferences::ScriptFontFamilyMap& map,
47 const std::string& script) {
48 webkit_glue::WebPreferences::ScriptFontFamilyMap::const_iterator it =
49 map.find(script);
50 if (it != map.end())
51 return it->second;
52 return string16();
53 }
54
40 bool PPTextRunToWebTextRun(const PP_BrowserFont_Trusted_TextRun& text, 55 bool PPTextRunToWebTextRun(const PP_BrowserFont_Trusted_TextRun& text,
41 WebTextRun* run) { 56 WebTextRun* run) {
42 StringVar* text_string = StringVar::FromPPVar(text.text); 57 StringVar* text_string = StringVar::FromPPVar(text.text);
43 if (!text_string) 58 if (!text_string)
44 return false; 59 return false;
45 60
46 *run = WebTextRun(UTF8ToUTF16(text_string->value()), 61 *run = WebTextRun(UTF8ToUTF16(text_string->value()),
47 PP_ToBool(text.rtl), 62 PP_ToBool(text.rtl),
48 PP_ToBool(text.override_direction)); 63 PP_ToBool(text.override_direction));
49 return true; 64 return true;
(...skipping 31 matching lines...) Expand 10 before | Expand all | Expand 10 after
81 MonospaceFamily); 96 MonospaceFamily);
82 97
83 StringVar* face_name = StringVar::FromPPVar(font.face); // Possibly null. 98 StringVar* face_name = StringVar::FromPPVar(font.face); // Possibly null.
84 99
85 WebFontDescription result; 100 WebFontDescription result;
86 string16 resolved_family; 101 string16 resolved_family;
87 if (!face_name || face_name->value().empty()) { 102 if (!face_name || face_name->value().empty()) {
88 // Resolve the generic family. 103 // Resolve the generic family.
89 switch (font.family) { 104 switch (font.family) {
90 case PP_BROWSERFONT_TRUSTED_FAMILY_SERIF: 105 case PP_BROWSERFONT_TRUSTED_FAMILY_SERIF:
91 resolved_family = prefs.serif_font_family; 106 resolved_family = GetFontFromMap(prefs.serif_font_family_map,
107 kCommonScript);
92 break; 108 break;
93 case PP_BROWSERFONT_TRUSTED_FAMILY_SANSSERIF: 109 case PP_BROWSERFONT_TRUSTED_FAMILY_SANSSERIF:
94 resolved_family = prefs.sans_serif_font_family; 110 resolved_family = GetFontFromMap(prefs.sans_serif_font_family_map,
111 kCommonScript);
95 break; 112 break;
96 case PP_BROWSERFONT_TRUSTED_FAMILY_MONOSPACE: 113 case PP_BROWSERFONT_TRUSTED_FAMILY_MONOSPACE:
97 resolved_family = prefs.fixed_font_family; 114 resolved_family = GetFontFromMap(prefs.fixed_font_family_map,
115 kCommonScript);
98 break; 116 break;
99 case PP_BROWSERFONT_TRUSTED_FAMILY_DEFAULT: 117 case PP_BROWSERFONT_TRUSTED_FAMILY_DEFAULT:
100 default: 118 default:
101 resolved_family = prefs.standard_font_family; 119 resolved_family = GetFontFromMap(prefs.standard_font_family_map,
120 kCommonScript);
102 break; 121 break;
103 } 122 }
104 } else { 123 } else {
105 // Use the exact font. 124 // Use the exact font.
106 resolved_family = UTF8ToUTF16(face_name->value()); 125 resolved_family = UTF8ToUTF16(face_name->value());
107 } 126 }
108 result.family = resolved_family; 127 result.family = resolved_family;
109 128
110 result.genericFamily = PP_FAMILY_TO_WEB_FAMILY(font.family); 129 result.genericFamily = PP_FAMILY_TO_WEB_FAMILY(font.family);
111 130
112 if (font.size == 0) { 131 if (font.size == 0) {
113 // Resolve the default font size, using the resolved family to see if 132 // 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 133 // 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 134 // 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. 135 // the alternate font size to the default fixed font family.
117 if (StringToLowerASCII(resolved_family) == 136 if (StringToLowerASCII(resolved_family) ==
118 StringToLowerASCII(prefs.fixed_font_family)) 137 StringToLowerASCII(GetFontFromMap(prefs.fixed_font_family_map,
138 kCommonScript)))
119 result.size = static_cast<float>(prefs.default_fixed_font_size); 139 result.size = static_cast<float>(prefs.default_fixed_font_size);
120 else 140 else
121 result.size = static_cast<float>(prefs.default_font_size); 141 result.size = static_cast<float>(prefs.default_font_size);
122 } else { 142 } else {
123 // Use the exact size. 143 // Use the exact size.
124 result.size = static_cast<float>(font.size); 144 result.size = static_cast<float>(font.size);
125 } 145 }
126 146
127 result.italic = font.italic != PP_FALSE; 147 result.italic = font.italic != PP_FALSE;
128 result.smallCaps = font.small_caps != PP_FALSE; 148 result.smallCaps = font.small_caps != PP_FALSE;
(...skipping 178 matching lines...) Expand 10 before | Expand all | Expand 10 after
307 } else { 327 } else {
308 web_clip = WebRect(clip->point.x, clip->point.y, 328 web_clip = WebRect(clip->point.x, clip->point.y,
309 clip->size.width, clip->size.height); 329 clip->size.width, clip->size.height);
310 } 330 }
311 331
312 font_->drawText(destination, run, web_position, color, web_clip, 332 font_->drawText(destination, run, web_position, color, web_clip,
313 PP_ToBool(image_data_is_opaque)); 333 PP_ToBool(image_data_is_opaque));
314 } 334 }
315 335
316 } // namespace ppapi 336 } // namespace ppapi
317
OLDNEW

Powered by Google App Engine
This is Rietveld 408576698