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

Side by Side Diff: gfx/canvas_skia_win.cc

Issue 5154009: Cleanup AdjustStringForLocaleDirection() (Closed) Base URL: svn://svn.chromium.org/chrome/trunk/src
Patch Set: further fixes Created 10 years, 1 month 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) 2010 The Chromium Authors. All rights reserved. 1 // Copyright (c) 2010 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 "gfx/canvas_skia.h" 5 #include "gfx/canvas_skia.h"
6 6
7 #include <limits> 7 #include <limits>
8 8
9 #include "base/i18n/rtl.h" 9 #include "base/i18n/rtl.h"
10 #include "gfx/font.h" 10 #include "gfx/font.h"
11 #include "gfx/rect.h" 11 #include "gfx/rect.h"
12 #include "third_party/skia/include/core/SkShader.h" 12 #include "third_party/skia/include/core/SkShader.h"
13 13
14 namespace { 14 namespace {
15 15
16 // We make sure that LTR text we draw in an RTL context is modified 16 // We make sure that LTR text we draw in an RTL context is modified
17 // appropriately to make sure it maintains it LTR orientation. 17 // appropriately to make sure it maintains it LTR orientation.
18 void DoDrawText(HDC hdc, 18 void DoDrawText(HDC hdc,
19 const std::wstring& text, 19 const std::wstring& text,
20 RECT* text_bounds, 20 RECT* text_bounds,
21 int flags) { 21 int flags) {
22 std::wstring localized_text;
23 const wchar_t* string_ptr = text.c_str();
24 int string_size = static_cast<int>(text.length());
25 // Only adjust string directionality if both of the following are true: 22 // Only adjust string directionality if both of the following are true:
26 // 1. The current locale is RTL. 23 // 1. The current locale is RTL.
27 // 2. The string itself has RTL directionality. 24 // 2. The string itself has RTL directionality.
25 const wchar_t* string_ptr = text.c_str();
26 int string_size = static_cast<int>(text.length());
27
28 std::wstring localized_text;
28 if (flags & DT_RTLREADING) { 29 if (flags & DT_RTLREADING) {
29 if (base::i18n::AdjustStringForLocaleDirection(text, &localized_text)) { 30 localized_text = text;
30 string_ptr = localized_text.c_str(); 31 base::i18n::AdjustStringForLocaleDirection(&localized_text);
31 string_size = static_cast<int>(localized_text.length()); 32 string_ptr = localized_text.c_str();
32 } 33 string_size = static_cast<int>(localized_text.length());
33 } 34 }
34 35
35 DrawText(hdc, string_ptr, string_size, text_bounds, flags); 36 DrawText(hdc, string_ptr, string_size, text_bounds, flags);
36 } 37 }
37 38
38 // Compute the windows flags necessary to implement the provided text Canvas 39 // Compute the windows flags necessary to implement the provided text Canvas
39 // flags. 40 // flags.
40 int ComputeFormatFlags(int flags, const std::wstring& text) { 41 int ComputeFormatFlags(int flags, const std::wstring& text) {
41 // Setting the text alignment explicitly in case it hasn't already been set. 42 // Setting the text alignment explicitly in case it hasn't already been set.
42 // This will make sure that we don't align text to the left on RTL locales 43 // This will make sure that we don't align text to the left on RTL locales
(...skipping 248 matching lines...) Expand 10 before | Expand all | Expand 10 after
291 text_row[cur_x] |= 0xff << SK_A32_SHIFT; // Make opaque. 292 text_row[cur_x] |= 0xff << SK_A32_SHIFT; // Make opaque.
292 } 293 }
293 } 294 }
294 } 295 }
295 296
296 // Draw the halo bitmap with blur. 297 // Draw the halo bitmap with blur.
297 DrawBitmapInt(text_bitmap, x - 1, y - 1); 298 DrawBitmapInt(text_bitmap, x - 1, y - 1);
298 } 299 }
299 300
300 } // namespace gfx 301 } // namespace gfx
OLDNEW

Powered by Google App Engine
This is Rietveld 408576698