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

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: 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_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 // Same as WebPreferences::kCommonScript. I'd use that directly here, but get an
44 // undefined reference linker error.
45 const char kCommonScript[] = "Zyyy";
46
47 string16 GetFontFromMap(
48 const webkit_glue::WebPreferences::ScriptFontFamilyMap& map,
49 const std::string& script) {
50 webkit_glue::WebPreferences::ScriptFontFamilyMap::const_iterator it =
51 map.find(script);
52 if (it != map.end())
53 return it->second;
54 return string16();
55 }
56
43 // Converts the given PP_TextRun to a TextRun, returning true on success. 57 // Converts the given PP_TextRun to a TextRun, returning true on success.
44 // False means the input was invalid. 58 // False means the input was invalid.
45 bool PPTextRunToTextRun(const PP_TextRun_Dev* run, 59 bool PPTextRunToTextRun(const PP_TextRun_Dev* run,
46 WebKitForwarding::Font::TextRun* output) { 60 WebKitForwarding::Font::TextRun* output) {
47 StringVar* text_string = StringVar::FromPPVar(run->text); 61 StringVar* text_string = StringVar::FromPPVar(run->text);
48 if (!text_string) 62 if (!text_string)
49 return false; 63 return false;
50 64
51 output->text = text_string->value(); 65 output->text = text_string->value();
52 output->rtl = run->rtl == PP_TRUE ? true : false; 66 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 == 99 COMPILE_ASSERT(WebFontDescription::GenericFamilyMonospace ==
86 PP_FONTFAMILY_TO_WEB_FONTFAMILY(PP_FONTFAMILY_MONOSPACE), 100 PP_FONTFAMILY_TO_WEB_FONTFAMILY(PP_FONTFAMILY_MONOSPACE),
87 MonospaceFamily); 101 MonospaceFamily);
88 102
89 WebFontDescription result; 103 WebFontDescription result;
90 string16 resolved_family; 104 string16 resolved_family;
91 if (face.empty()) { 105 if (face.empty()) {
92 // Resolve the generic family. 106 // Resolve the generic family.
93 switch (font.family) { 107 switch (font.family) {
94 case PP_FONTFAMILY_SERIF: 108 case PP_FONTFAMILY_SERIF:
95 resolved_family = prefs.serif_font_family; 109 resolved_family = GetFontFromMap(prefs.serif_font_family_map,
110 kCommonScript);
96 break; 111 break;
97 case PP_FONTFAMILY_SANSSERIF: 112 case PP_FONTFAMILY_SANSSERIF:
98 resolved_family = prefs.sans_serif_font_family; 113 resolved_family = GetFontFromMap(prefs.sans_serif_font_family_map,
114 kCommonScript);
99 break; 115 break;
100 case PP_FONTFAMILY_MONOSPACE: 116 case PP_FONTFAMILY_MONOSPACE:
101 resolved_family = prefs.fixed_font_family; 117 resolved_family = GetFontFromMap(prefs.fixed_font_family_map,
118 kCommonScript);
102 break; 119 break;
103 case PP_FONTFAMILY_DEFAULT: 120 case PP_FONTFAMILY_DEFAULT:
104 default: 121 default:
105 resolved_family = prefs.standard_font_family; 122 resolved_family = GetFontFromMap(prefs.standard_font_family_map,
123 kCommonScript);
106 break; 124 break;
107 } 125 }
108 } else { 126 } else {
109 // Use the exact font. 127 // Use the exact font.
110 resolved_family = UTF8ToUTF16(face); 128 resolved_family = UTF8ToUTF16(face);
111 } 129 }
112 result.family = resolved_family; 130 result.family = resolved_family;
113 131
114 result.genericFamily = PP_FONTFAMILY_TO_WEB_FONTFAMILY(font.family); 132 result.genericFamily = PP_FONTFAMILY_TO_WEB_FONTFAMILY(font.family);
115 133
116 if (font.size == 0) { 134 if (font.size == 0) {
117 // Resolve the default font size, using the resolved family to see if 135 // 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 136 // 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 137 // 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. 138 // the alternate font size to the default fixed font family.
121 if (StringToLowerASCII(resolved_family) == 139 if (StringToLowerASCII(resolved_family) ==
122 StringToLowerASCII(prefs.fixed_font_family)) 140 StringToLowerASCII(GetFontFromMap(prefs.fixed_font_family_map,
141 kCommonScript)))
123 result.size = static_cast<float>(prefs.default_fixed_font_size); 142 result.size = static_cast<float>(prefs.default_fixed_font_size);
124 else 143 else
125 result.size = static_cast<float>(prefs.default_font_size); 144 result.size = static_cast<float>(prefs.default_font_size);
126 } else { 145 } else {
127 // Use the exact size. 146 // Use the exact size.
128 result.size = static_cast<float>(font.size); 147 result.size = static_cast<float>(font.size);
129 } 148 }
130 149
131 result.italic = font.italic != PP_FALSE; 150 result.italic = font.italic != PP_FALSE;
132 result.smallCaps = font.small_caps != PP_FALSE; 151 result.smallCaps = font.small_caps != PP_FALSE;
(...skipping 261 matching lines...) Expand 10 before | Expand all | Expand 10 after
394 uint32_t char_offset) { 413 uint32_t char_offset) {
395 int32_t result = -1; 414 int32_t result = -1;
396 WebKitForwarding::Font::TextRun run; 415 WebKitForwarding::Font::TextRun run;
397 if (PPTextRunToTextRun(text, &run)) { 416 if (PPTextRunToTextRun(text, &run)) {
398 font_impl_->PixelOffsetForCharacter(run, char_offset, &result); 417 font_impl_->PixelOffsetForCharacter(run, char_offset, &result);
399 } 418 }
400 return result; 419 return result;
401 } 420 }
402 421
403 } // namespace ppapi 422 } // namespace ppapi
404
OLDNEW

Powered by Google App Engine
This is Rietveld 408576698