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

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

Powered by Google App Engine
This is Rietveld 408576698