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

Side by Side Diff: content/child/browser_font_resource_trusted.cc

Issue 121033002: Update uses of UTF conversions in content/ to use the base:: namespace. (Closed) Base URL: svn://svn.chromium.org/chrome/trunk/src
Patch Set: Created 6 years, 12 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
« no previous file with comments | « content/browser/worker_host/worker_process_host.cc ('k') | content/child/child_process.cc » ('j') | no next file with comments »
Toggle Intra-line Diffs ('i') | Expand Comments ('e') | Collapse Comments ('c') | Show Comments Hide Comments ('s')
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 "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 "ppapi/c/dev/ppb_font_dev.h" 9 #include "ppapi/c/dev/ppb_font_dev.h"
10 #include "ppapi/proxy/connection.h" 10 #include "ppapi/proxy/connection.h"
(...skipping 47 matching lines...) Expand 10 before | Expand all | Expand 10 after
58 // but the font drawing and measurement routines we call happen after this 58 // but the font drawing and measurement routines we call happen after this
59 // step. So for correct rendering of RTL content, we need to do it ourselves. 59 // step. So for correct rendering of RTL content, we need to do it ourselves.
60 class TextRunCollection { 60 class TextRunCollection {
61 public: 61 public:
62 explicit TextRunCollection(const PP_BrowserFont_Trusted_TextRun& run) 62 explicit TextRunCollection(const PP_BrowserFont_Trusted_TextRun& run)
63 : bidi_(NULL), 63 : bidi_(NULL),
64 num_runs_(0) { 64 num_runs_(0) {
65 StringVar* text_string = StringVar::FromPPVar(run.text); 65 StringVar* text_string = StringVar::FromPPVar(run.text);
66 if (!text_string) 66 if (!text_string)
67 return; // Leave num_runs_ = 0 so we'll do nothing. 67 return; // Leave num_runs_ = 0 so we'll do nothing.
68 text_ = UTF8ToUTF16(text_string->value()); 68 text_ = base::UTF8ToUTF16(text_string->value());
69 69
70 if (run.override_direction) { 70 if (run.override_direction) {
71 // Skip autodetection. 71 // Skip autodetection.
72 num_runs_ = 1; 72 num_runs_ = 1;
73 override_run_ = WebTextRun(text_, PP_ToBool(run.rtl), true); 73 override_run_ = WebTextRun(text_, PP_ToBool(run.rtl), true);
74 } else { 74 } else {
75 bidi_ = ubidi_open(); 75 bidi_ = ubidi_open();
76 UErrorCode uerror = U_ZERO_ERROR; 76 UErrorCode uerror = U_ZERO_ERROR;
77 ubidi_setPara(bidi_, text_.data(), text_.size(), run.rtl, NULL, &uerror); 77 ubidi_setPara(bidi_, text_.data(), text_.size(), run.rtl, NULL, &uerror);
78 if (U_SUCCESS(uerror)) 78 if (U_SUCCESS(uerror))
(...skipping 41 matching lines...) Expand 10 before | Expand all | Expand 10 after
120 120
121 DISALLOW_COPY_AND_ASSIGN(TextRunCollection); 121 DISALLOW_COPY_AND_ASSIGN(TextRunCollection);
122 }; 122 };
123 123
124 bool PPTextRunToWebTextRun(const PP_BrowserFont_Trusted_TextRun& text, 124 bool PPTextRunToWebTextRun(const PP_BrowserFont_Trusted_TextRun& text,
125 WebTextRun* run) { 125 WebTextRun* run) {
126 StringVar* text_string = StringVar::FromPPVar(text.text); 126 StringVar* text_string = StringVar::FromPPVar(text.text);
127 if (!text_string) 127 if (!text_string)
128 return false; 128 return false;
129 129
130 *run = WebTextRun(UTF8ToUTF16(text_string->value()), 130 *run = WebTextRun(base::UTF8ToUTF16(text_string->value()),
131 PP_ToBool(text.rtl), 131 PP_ToBool(text.rtl),
132 PP_ToBool(text.override_direction)); 132 PP_ToBool(text.override_direction));
133 return true; 133 return true;
134 } 134 }
135 135
136 // The PP_* version lacks "None", so is just one value shifted from the 136 // The PP_* version lacks "None", so is just one value shifted from the
137 // WebFontDescription version. These values are checked in 137 // WebFontDescription version. These values are checked in
138 // PPFontDescToWebFontDesc to make sure the conversion is correct. This is a 138 // PPFontDescToWebFontDesc to make sure the conversion is correct. This is a
139 // macro so it can also be used in the COMPILE_ASSERTS. 139 // macro so it can also be used in the COMPILE_ASSERTS.
140 #define PP_FAMILY_TO_WEB_FAMILY(f) \ 140 #define PP_FAMILY_TO_WEB_FAMILY(f) \
(...skipping 43 matching lines...) Expand 10 before | Expand all | Expand 10 after
184 kCommonScript); 184 kCommonScript);
185 break; 185 break;
186 case PP_BROWSERFONT_TRUSTED_FAMILY_DEFAULT: 186 case PP_BROWSERFONT_TRUSTED_FAMILY_DEFAULT:
187 default: 187 default:
188 resolved_family = GetFontFromMap(prefs.standard_font_family_map, 188 resolved_family = GetFontFromMap(prefs.standard_font_family_map,
189 kCommonScript); 189 kCommonScript);
190 break; 190 break;
191 } 191 }
192 } else { 192 } else {
193 // Use the exact font. 193 // Use the exact font.
194 resolved_family = UTF8ToUTF16(face_name->value()); 194 resolved_family = base::UTF8ToUTF16(face_name->value());
195 } 195 }
196 result.family = resolved_family; 196 result.family = resolved_family;
197 197
198 result.genericFamily = PP_FAMILY_TO_WEB_FAMILY(font.family); 198 result.genericFamily = PP_FAMILY_TO_WEB_FAMILY(font.family);
199 199
200 if (font.size == 0) { 200 if (font.size == 0) {
201 // Resolve the default font size, using the resolved family to see if 201 // Resolve the default font size, using the resolved family to see if
202 // we should use the fixed or regular font size. It's difficult at this 202 // we should use the fixed or regular font size. It's difficult at this
203 // level to detect if the requested font is fixed width, so we only apply 203 // level to detect if the requested font is fixed width, so we only apply
204 // the alternate font size to the default fixed font family. 204 // the alternate font size to the default fixed font family.
(...skipping 61 matching lines...) Expand 10 before | Expand all | Expand 10 after
266 266
267 PP_Bool BrowserFontResource_Trusted::Describe( 267 PP_Bool BrowserFontResource_Trusted::Describe(
268 PP_BrowserFont_Trusted_Description* description, 268 PP_BrowserFont_Trusted_Description* description,
269 PP_BrowserFont_Trusted_Metrics* metrics) { 269 PP_BrowserFont_Trusted_Metrics* metrics) {
270 if (description->face.type != PP_VARTYPE_UNDEFINED) 270 if (description->face.type != PP_VARTYPE_UNDEFINED)
271 return PP_FALSE; 271 return PP_FALSE;
272 272
273 // While converting the other way in PPFontDescToWebFontDesc we validated 273 // While converting the other way in PPFontDescToWebFontDesc we validated
274 // that the enums can be casted. 274 // that the enums can be casted.
275 WebFontDescription web_desc = font_->fontDescription(); 275 WebFontDescription web_desc = font_->fontDescription();
276 description->face = StringVar::StringToPPVar(UTF16ToUTF8(web_desc.family)); 276 description->face =
277 StringVar::StringToPPVar(base::UTF16ToUTF8(web_desc.family));
277 description->family = 278 description->family =
278 static_cast<PP_BrowserFont_Trusted_Family>(web_desc.genericFamily); 279 static_cast<PP_BrowserFont_Trusted_Family>(web_desc.genericFamily);
279 description->size = static_cast<uint32_t>(web_desc.size); 280 description->size = static_cast<uint32_t>(web_desc.size);
280 description->weight = static_cast<PP_BrowserFont_Trusted_Weight>( 281 description->weight = static_cast<PP_BrowserFont_Trusted_Weight>(
281 web_desc.weight); 282 web_desc.weight);
282 description->italic = web_desc.italic ? PP_TRUE : PP_FALSE; 283 description->italic = web_desc.italic ? PP_TRUE : PP_FALSE;
283 description->small_caps = web_desc.smallCaps ? PP_TRUE : PP_FALSE; 284 description->small_caps = web_desc.smallCaps ? PP_TRUE : PP_FALSE;
284 description->letter_spacing = static_cast<int32_t>(web_desc.letterSpacing); 285 description->letter_spacing = static_cast<int32_t>(web_desc.letterSpacing);
285 description->word_spacing = static_cast<int32_t>(web_desc.wordSpacing); 286 description->word_spacing = static_cast<int32_t>(web_desc.wordSpacing);
286 287
(...skipping 132 matching lines...) Expand 10 before | Expand all | Expand 10 after
419 420
420 // Advance to the next run. Note that we avoid doing this for the last run 421 // 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 422 // since it's unnecessary, measuring text is slow, and most of the time
422 // there will be only one run anyway. 423 // there will be only one run anyway.
423 if (i != runs.num_runs() - 1) 424 if (i != runs.num_runs() - 1)
424 web_position.x += font_->calculateWidth(run); 425 web_position.x += font_->calculateWidth(run);
425 } 426 }
426 } 427 }
427 428
428 } // namespace content 429 } // namespace content
OLDNEW
« no previous file with comments | « content/browser/worker_host/worker_process_host.cc ('k') | content/child/child_process.cc » ('j') | no next file with comments »

Powered by Google App Engine
This is Rietveld 408576698