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

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: compile fixes Created 8 years, 8 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 const char kWebKitCommonScript[] = "Zyyy";
41
42 string16 GetFontFromMap(const WebPreferences::ScriptFontFamilyMap& map,
43 const std::string& script) {
44 WebPreferences::ScriptFontFamilyMap::const_iterator it = map.find(script);
45 if (it != map.end())
46 return it->second;
47 return string16();
48 }
49
40 bool PPTextRunToWebTextRun(const PP_BrowserFont_Trusted_TextRun& text, 50 bool PPTextRunToWebTextRun(const PP_BrowserFont_Trusted_TextRun& text,
41 WebTextRun* run) { 51 WebTextRun* run) {
42 StringVar* text_string = StringVar::FromPPVar(text.text); 52 StringVar* text_string = StringVar::FromPPVar(text.text);
43 if (!text_string) 53 if (!text_string)
44 return false; 54 return false;
45 55
46 *run = WebTextRun(UTF8ToUTF16(text_string->value()), 56 *run = WebTextRun(UTF8ToUTF16(text_string->value()),
47 PP_ToBool(text.rtl), 57 PP_ToBool(text.rtl),
48 PP_ToBool(text.override_direction)); 58 PP_ToBool(text.override_direction));
49 return true; 59 return true;
(...skipping 31 matching lines...) Expand 10 before | Expand all | Expand 10 after
81 MonospaceFamily); 91 MonospaceFamily);
82 92
83 StringVar* face_name = StringVar::FromPPVar(font.face); // Possibly null. 93 StringVar* face_name = StringVar::FromPPVar(font.face); // Possibly null.
84 94
85 WebFontDescription result; 95 WebFontDescription result;
86 string16 resolved_family; 96 string16 resolved_family;
87 if (!face_name || face_name->value().empty()) { 97 if (!face_name || face_name->value().empty()) {
88 // Resolve the generic family. 98 // Resolve the generic family.
89 switch (font.family) { 99 switch (font.family) {
90 case PP_BROWSERFONT_TRUSTED_FAMILY_SERIF: 100 case PP_BROWSERFONT_TRUSTED_FAMILY_SERIF:
91 resolved_family = prefs.serif_font_family; 101 resolved_family = GetFontFromMap(prefs.serif_font_family_map,
102 kWebKitCommonScript);
92 break; 103 break;
93 case PP_BROWSERFONT_TRUSTED_FAMILY_SANSSERIF: 104 case PP_BROWSERFONT_TRUSTED_FAMILY_SANSSERIF:
94 resolved_family = prefs.sans_serif_font_family; 105 resolved_family = GetFontFromMap(prefs.sans_serif_font_family_map,
106 kWebKitCommonScript);
95 break; 107 break;
96 case PP_BROWSERFONT_TRUSTED_FAMILY_MONOSPACE: 108 case PP_BROWSERFONT_TRUSTED_FAMILY_MONOSPACE:
97 resolved_family = prefs.fixed_font_family; 109 resolved_family = GetFontFromMap(prefs.fixed_font_family_map,
110 kWebKitCommonScript);
98 break; 111 break;
99 case PP_BROWSERFONT_TRUSTED_FAMILY_DEFAULT: 112 case PP_BROWSERFONT_TRUSTED_FAMILY_DEFAULT:
100 default: 113 default:
101 resolved_family = prefs.standard_font_family; 114 resolved_family = GetFontFromMap(prefs.standard_font_family_map,
115 kWebKitCommonScript);
102 break; 116 break;
103 } 117 }
104 } else { 118 } else {
105 // Use the exact font. 119 // Use the exact font.
106 resolved_family = UTF8ToUTF16(face_name->value()); 120 resolved_family = UTF8ToUTF16(face_name->value());
107 } 121 }
108 result.family = resolved_family; 122 result.family = resolved_family;
109 123
110 result.genericFamily = PP_FAMILY_TO_WEB_FAMILY(font.family); 124 result.genericFamily = PP_FAMILY_TO_WEB_FAMILY(font.family);
111 125
112 if (font.size == 0) { 126 if (font.size == 0) {
113 // Resolve the default font size, using the resolved family to see if 127 // 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 128 // 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 129 // 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. 130 // the alternate font size to the default fixed font family.
117 if (StringToLowerASCII(resolved_family) == 131 if (StringToLowerASCII(resolved_family) ==
118 StringToLowerASCII(prefs.fixed_font_family)) 132 StringToLowerASCII(GetFontFromMap(prefs.fixed_font_family_map,
133 kWebKitCommonScript)))
119 result.size = static_cast<float>(prefs.default_fixed_font_size); 134 result.size = static_cast<float>(prefs.default_fixed_font_size);
120 else 135 else
121 result.size = static_cast<float>(prefs.default_font_size); 136 result.size = static_cast<float>(prefs.default_font_size);
122 } else { 137 } else {
123 // Use the exact size. 138 // Use the exact size.
124 result.size = static_cast<float>(font.size); 139 result.size = static_cast<float>(font.size);
125 } 140 }
126 141
127 result.italic = font.italic != PP_FALSE; 142 result.italic = font.italic != PP_FALSE;
128 result.smallCaps = font.small_caps != PP_FALSE; 143 result.smallCaps = font.small_caps != PP_FALSE;
(...skipping 186 matching lines...) Expand 10 before | Expand all | Expand 10 after
315 WebCanvas* canvas = skia::GetBitmapContext(skia::GetTopDevice(*destination)); 330 WebCanvas* canvas = skia::GetBitmapContext(skia::GetTopDevice(*destination));
316 #else 331 #else
317 NOTIMPLEMENTED(); 332 NOTIMPLEMENTED();
318 return; 333 return;
319 #endif 334 #endif
320 font_->drawText(canvas, run, web_position, color, web_clip, 335 font_->drawText(canvas, run, web_position, color, web_clip,
321 PP_ToBool(image_data_is_opaque)); 336 PP_ToBool(image_data_is_opaque));
322 } 337 }
323 338
324 } // namespace ppapi 339 } // namespace ppapi
325
OLDNEW

Powered by Google App Engine
This is Rietveld 408576698