OLD | NEW |
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 "content/child/browser_font_resource_trusted.h" | 5 #include "content/child/browser_font_resource_trusted.h" |
6 | 6 |
7 #include "base/strings/string_util.h" | 7 #include "base/strings/string_util.h" |
8 #include "base/strings/utf_string_conversions.h" | 8 #include "base/strings/utf_string_conversions.h" |
9 #include "content/public/common/web_preferences.h" | 9 #include "content/public/common/web_preferences.h" |
10 #include "ppapi/c/dev/ppb_font_dev.h" | 10 #include "ppapi/c/dev/ppb_font_dev.h" |
(...skipping 117 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
128 | 128 |
129 *run = WebTextRun(base::UTF8ToUTF16(text_string->value()), | 129 *run = WebTextRun(base::UTF8ToUTF16(text_string->value()), |
130 PP_ToBool(text.rtl), | 130 PP_ToBool(text.rtl), |
131 PP_ToBool(text.override_direction)); | 131 PP_ToBool(text.override_direction)); |
132 return true; | 132 return true; |
133 } | 133 } |
134 | 134 |
135 // The PP_* version lacks "None", so is just one value shifted from the | 135 // The PP_* version lacks "None", so is just one value shifted from the |
136 // WebFontDescription version. These values are checked in | 136 // WebFontDescription version. These values are checked in |
137 // PPFontDescToWebFontDesc to make sure the conversion is correct. This is a | 137 // PPFontDescToWebFontDesc to make sure the conversion is correct. This is a |
138 // macro so it can also be used in the COMPILE_ASSERTS. | 138 // macro so it can also be used in the static_asserts. |
139 #define PP_FAMILY_TO_WEB_FAMILY(f) \ | 139 #define PP_FAMILY_TO_WEB_FAMILY(f) \ |
140 static_cast<WebFontDescription::GenericFamily>(f + 1) | 140 static_cast<WebFontDescription::GenericFamily>(f + 1) |
141 | 141 |
142 // Assumes the given PP_FontDescription has been validated. | 142 // Assumes the given PP_FontDescription has been validated. |
143 WebFontDescription PPFontDescToWebFontDesc( | 143 WebFontDescription PPFontDescToWebFontDesc( |
144 const PP_BrowserFont_Trusted_Description& font, | 144 const PP_BrowserFont_Trusted_Description& font, |
145 const ppapi::Preferences& prefs) { | 145 const ppapi::Preferences& prefs) { |
146 // Verify that the enums match so we can just static cast. | 146 // Verify that the enums match so we can just static cast. |
147 COMPILE_ASSERT(static_cast<int>(WebFontDescription::Weight100) == | 147 static_assert(static_cast<int>(WebFontDescription::Weight100) == |
148 static_cast<int>(PP_BROWSERFONT_TRUSTED_WEIGHT_100), | 148 static_cast<int>(PP_BROWSERFONT_TRUSTED_WEIGHT_100), |
149 FontWeight100); | 149 "font Weight100"); |
150 COMPILE_ASSERT(static_cast<int>(WebFontDescription::Weight900) == | 150 static_assert(static_cast<int>(WebFontDescription::Weight900) == |
151 static_cast<int>(PP_BROWSERFONT_TRUSTED_WEIGHT_900), | 151 static_cast<int>(PP_BROWSERFONT_TRUSTED_WEIGHT_900), |
152 FontWeight900); | 152 "font Weight900"); |
153 COMPILE_ASSERT(WebFontDescription::GenericFamilyStandard == | 153 static_assert(WebFontDescription::GenericFamilyStandard == |
154 PP_FAMILY_TO_WEB_FAMILY(PP_FONTFAMILY_DEFAULT), | 154 PP_FAMILY_TO_WEB_FAMILY(PP_FONTFAMILY_DEFAULT), |
155 StandardFamily); | 155 "FamilyStandard"); |
156 COMPILE_ASSERT(WebFontDescription::GenericFamilySerif == | 156 static_assert(WebFontDescription::GenericFamilySerif == |
157 PP_FAMILY_TO_WEB_FAMILY(PP_FONTFAMILY_SERIF), | 157 PP_FAMILY_TO_WEB_FAMILY(PP_FONTFAMILY_SERIF), |
158 SerifFamily); | 158 "FamilySerif"); |
159 COMPILE_ASSERT(WebFontDescription::GenericFamilySansSerif == | 159 static_assert(WebFontDescription::GenericFamilySansSerif == |
160 PP_FAMILY_TO_WEB_FAMILY(PP_FONTFAMILY_SANSSERIF), | 160 PP_FAMILY_TO_WEB_FAMILY(PP_FONTFAMILY_SANSSERIF), |
161 SansSerifFamily); | 161 "FamilySansSerif"); |
162 COMPILE_ASSERT(WebFontDescription::GenericFamilyMonospace == | 162 static_assert(WebFontDescription::GenericFamilyMonospace == |
163 PP_FAMILY_TO_WEB_FAMILY(PP_FONTFAMILY_MONOSPACE), | 163 PP_FAMILY_TO_WEB_FAMILY(PP_FONTFAMILY_MONOSPACE), |
164 MonospaceFamily); | 164 "FamilyMonospace"); |
165 | 165 |
166 StringVar* face_name = StringVar::FromPPVar(font.face); // Possibly null. | 166 StringVar* face_name = StringVar::FromPPVar(font.face); // Possibly null. |
167 | 167 |
168 WebFontDescription result; | 168 WebFontDescription result; |
169 base::string16 resolved_family; | 169 base::string16 resolved_family; |
170 if (!face_name || face_name->value().empty()) { | 170 if (!face_name || face_name->value().empty()) { |
171 // Resolve the generic family. | 171 // Resolve the generic family. |
172 switch (font.family) { | 172 switch (font.family) { |
173 case PP_BROWSERFONT_TRUSTED_FAMILY_SERIF: | 173 case PP_BROWSERFONT_TRUSTED_FAMILY_SERIF: |
174 resolved_family = GetFontFromMap(prefs.serif_font_family_map, | 174 resolved_family = GetFontFromMap(prefs.serif_font_family_map, |
(...skipping 244 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
419 | 419 |
420 // Advance to the next run. Note that we avoid doing this for the last run | 420 // Advance to the next run. Note that we avoid doing this for the last run |
421 // since it's unnecessary, measuring text is slow, and most of the time | 421 // since it's unnecessary, measuring text is slow, and most of the time |
422 // there will be only one run anyway. | 422 // there will be only one run anyway. |
423 if (i != runs.num_runs() - 1) | 423 if (i != runs.num_runs() - 1) |
424 web_position.x += font_->calculateWidth(run); | 424 web_position.x += font_->calculateWidth(run); |
425 } | 425 } |
426 } | 426 } |
427 | 427 |
428 } // namespace content | 428 } // namespace content |
OLD | NEW |