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

Side by Side Diff: ppapi/shared_impl/private/ppb_font_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_font_shared.h" 5 #include "ppapi/shared_impl/private/ppb_font_shared.h"
6 6
7 #include "base/debug/trace_event.h" 7 #include "base/debug/trace_event.h"
8 #include "base/string_util.h" 8 #include "base/string_util.h"
9 #include "base/utf_string_conversions.h" 9 #include "base/utf_string_conversions.h"
10 #include "ppapi/c/dev/ppb_font_dev.h" 10 #include "ppapi/c/dev/ppb_font_dev.h"
(...skipping 22 matching lines...) Expand all
33 using WebKit::WebFont; 33 using WebKit::WebFont;
34 using WebKit::WebFontDescription; 34 using WebKit::WebFontDescription;
35 using WebKit::WebRect; 35 using WebKit::WebRect;
36 using WebKit::WebTextRun; 36 using WebKit::WebTextRun;
37 using WebKit::WebCanvas; 37 using WebKit::WebCanvas;
38 38
39 namespace ppapi { 39 namespace ppapi {
40 40
41 namespace { 41 namespace {
42 42
43 const char kWebKitCommonScript[] = "Zyyy";
44
45 string16 GetFontFromMap(const WebPreferences::ScriptFontFamilyMap& map,
46 const std::string& script) {
47 WebPreferences::ScriptFontFamilyMap::const_iterator it = map.find(script);
48 if (it != map.end())
49 return it->second;
50 return string16();
51 }
52
43 // Converts the given PP_TextRun to a TextRun, returning true on success. 53 // Converts the given PP_TextRun to a TextRun, returning true on success.
44 // False means the input was invalid. 54 // False means the input was invalid.
45 bool PPTextRunToTextRun(const PP_TextRun_Dev* run, 55 bool PPTextRunToTextRun(const PP_TextRun_Dev* run,
46 WebKitForwarding::Font::TextRun* output) { 56 WebKitForwarding::Font::TextRun* output) {
47 StringVar* text_string = StringVar::FromPPVar(run->text); 57 StringVar* text_string = StringVar::FromPPVar(run->text);
48 if (!text_string) 58 if (!text_string)
49 return false; 59 return false;
50 60
51 output->text = text_string->value(); 61 output->text = text_string->value();
52 output->rtl = run->rtl == PP_TRUE ? true : false; 62 output->rtl = run->rtl == PP_TRUE ? true : false;
(...skipping 32 matching lines...) Expand 10 before | Expand all | Expand 10 after
85 COMPILE_ASSERT(WebFontDescription::GenericFamilyMonospace == 95 COMPILE_ASSERT(WebFontDescription::GenericFamilyMonospace ==
86 PP_FONTFAMILY_TO_WEB_FONTFAMILY(PP_FONTFAMILY_MONOSPACE), 96 PP_FONTFAMILY_TO_WEB_FONTFAMILY(PP_FONTFAMILY_MONOSPACE),
87 MonospaceFamily); 97 MonospaceFamily);
88 98
89 WebFontDescription result; 99 WebFontDescription result;
90 string16 resolved_family; 100 string16 resolved_family;
91 if (face.empty()) { 101 if (face.empty()) {
92 // Resolve the generic family. 102 // Resolve the generic family.
93 switch (font.family) { 103 switch (font.family) {
94 case PP_FONTFAMILY_SERIF: 104 case PP_FONTFAMILY_SERIF:
95 resolved_family = prefs.serif_font_family; 105 resolved_family = GetFontFromMap(prefs.serif_font_family_map,
106 kWebKitCommonScript);
96 break; 107 break;
97 case PP_FONTFAMILY_SANSSERIF: 108 case PP_FONTFAMILY_SANSSERIF:
98 resolved_family = prefs.sans_serif_font_family; 109 resolved_family = GetFontFromMap(prefs.sans_serif_font_family_map,
110 kWebKitCommonScript);
99 break; 111 break;
100 case PP_FONTFAMILY_MONOSPACE: 112 case PP_FONTFAMILY_MONOSPACE:
101 resolved_family = prefs.fixed_font_family; 113 resolved_family = GetFontFromMap(prefs.fixed_font_family_map,
114 kWebKitCommonScript);
102 break; 115 break;
103 case PP_FONTFAMILY_DEFAULT: 116 case PP_FONTFAMILY_DEFAULT:
104 default: 117 default:
105 resolved_family = prefs.standard_font_family; 118 resolved_family = GetFontFromMap(prefs.standard_font_family_map,
119 kWebKitCommonScript);
106 break; 120 break;
107 } 121 }
108 } else { 122 } else {
109 // Use the exact font. 123 // Use the exact font.
110 resolved_family = UTF8ToUTF16(face); 124 resolved_family = UTF8ToUTF16(face);
111 } 125 }
112 result.family = resolved_family; 126 result.family = resolved_family;
113 127
114 result.genericFamily = PP_FONTFAMILY_TO_WEB_FONTFAMILY(font.family); 128 result.genericFamily = PP_FONTFAMILY_TO_WEB_FONTFAMILY(font.family);
115 129
116 if (font.size == 0) { 130 if (font.size == 0) {
117 // 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
118 // 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
119 // 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
120 // the alternate font size to the default fixed font family. 134 // the alternate font size to the default fixed font family.
121 if (StringToLowerASCII(resolved_family) == 135 if (StringToLowerASCII(resolved_family) ==
122 StringToLowerASCII(prefs.fixed_font_family)) 136 StringToLowerASCII(GetFontFromMap(prefs.fixed_font_family_map,
137 kWebKitCommonScript)))
123 result.size = static_cast<float>(prefs.default_fixed_font_size); 138 result.size = static_cast<float>(prefs.default_fixed_font_size);
124 else 139 else
125 result.size = static_cast<float>(prefs.default_font_size); 140 result.size = static_cast<float>(prefs.default_font_size);
126 } else { 141 } else {
127 // Use the exact size. 142 // Use the exact size.
128 result.size = static_cast<float>(font.size); 143 result.size = static_cast<float>(font.size);
129 } 144 }
130 145
131 result.italic = font.italic != PP_FALSE; 146 result.italic = font.italic != PP_FALSE;
132 result.smallCaps = font.small_caps != PP_FALSE; 147 result.smallCaps = font.small_caps != PP_FALSE;
(...skipping 269 matching lines...) Expand 10 before | Expand all | Expand 10 after
402 uint32_t char_offset) { 417 uint32_t char_offset) {
403 int32_t result = -1; 418 int32_t result = -1;
404 WebKitForwarding::Font::TextRun run; 419 WebKitForwarding::Font::TextRun run;
405 if (PPTextRunToTextRun(text, &run)) { 420 if (PPTextRunToTextRun(text, &run)) {
406 font_impl_->PixelOffsetForCharacter(run, char_offset, &result); 421 font_impl_->PixelOffsetForCharacter(run, char_offset, &result);
407 } 422 }
408 return result; 423 return result;
409 } 424 }
410 425
411 } // namespace ppapi 426 } // namespace ppapi
412
OLDNEW

Powered by Google App Engine
This is Rietveld 408576698