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

Side by Side Diff: app/gfx/canvas_win.cc

Issue 1073005: Move RTL related functions from app/l10n_util to base/i18n/rtl... (Closed) Base URL: svn://svn.chromium.org/chrome/trunk/src/
Patch Set: '' Created 10 years, 9 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 | « app/gfx/canvas.cc ('k') | app/l10n_util.h » ('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) 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 "app/gfx/canvas.h" 5 #include "app/gfx/canvas.h"
6 6
7 #include <limits> 7 #include <limits>
8 8
9 #include "app/gfx/font.h" 9 #include "app/gfx/font.h"
10 #include "app/l10n_util.h" 10 #include "base/i18n/rtl.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, const std::wstring& text, 18 void DoDrawText(HDC hdc, const std::wstring& text,
19 RECT* text_bounds, int flags) { 19 RECT* text_bounds, int flags) {
20 std::wstring localized_text; 20 std::wstring localized_text;
21 const wchar_t* string_ptr = text.c_str(); 21 const wchar_t* string_ptr = text.c_str();
22 int string_size = static_cast<int>(text.length()); 22 int string_size = static_cast<int>(text.length());
23 // Only adjust string directionality if both of the following are true: 23 // Only adjust string directionality if both of the following are true:
24 // 1. The current locale is RTL. 24 // 1. The current locale is RTL.
25 // 2. The string itself has RTL directionality. 25 // 2. The string itself has RTL directionality.
26 if (flags & DT_RTLREADING) { 26 if (flags & DT_RTLREADING) {
27 if (l10n_util::AdjustStringForLocaleDirection(text, &localized_text)) { 27 if (base::i18n::AdjustStringForLocaleDirection(text, &localized_text)) {
28 string_ptr = localized_text.c_str(); 28 string_ptr = localized_text.c_str();
29 string_size = static_cast<int>(localized_text.length()); 29 string_size = static_cast<int>(localized_text.length());
30 } 30 }
31 } 31 }
32 32
33 DrawText(hdc, string_ptr, string_size, text_bounds, flags); 33 DrawText(hdc, string_ptr, string_size, text_bounds, flags);
34 } 34 }
35 35
36 // Compute the windows flags necessary to implement the provided text Canvas 36 // Compute the windows flags necessary to implement the provided text Canvas
37 // flags. 37 // flags.
38 int ComputeFormatFlags(int flags, const std::wstring& text) { 38 int ComputeFormatFlags(int flags, const std::wstring& text) {
39 // Setting the text alignment explicitly in case it hasn't already been set. 39 // Setting the text alignment explicitly in case it hasn't already been set.
40 // This will make sure that we don't align text to the left on RTL locales 40 // This will make sure that we don't align text to the left on RTL locales
41 // just because no alignment flag was passed to DrawStringInt(). 41 // just because no alignment flag was passed to DrawStringInt().
42 if (!(flags & (gfx::Canvas::TEXT_ALIGN_CENTER | 42 if (!(flags & (gfx::Canvas::TEXT_ALIGN_CENTER |
43 gfx::Canvas::TEXT_ALIGN_RIGHT | 43 gfx::Canvas::TEXT_ALIGN_RIGHT |
44 gfx::Canvas::TEXT_ALIGN_LEFT))) { 44 gfx::Canvas::TEXT_ALIGN_LEFT))) {
45 flags |= l10n_util::DefaultCanvasTextAlignment(); 45 flags |= gfx::Canvas::DefaultCanvasTextAlignment();
46 } 46 }
47 47
48 // horizontal alignment 48 // horizontal alignment
49 int f = 0; 49 int f = 0;
50 if (flags & gfx::Canvas::TEXT_ALIGN_CENTER) 50 if (flags & gfx::Canvas::TEXT_ALIGN_CENTER)
51 f |= DT_CENTER; 51 f |= DT_CENTER;
52 else if (flags & gfx::Canvas::TEXT_ALIGN_RIGHT) 52 else if (flags & gfx::Canvas::TEXT_ALIGN_RIGHT)
53 f |= DT_RIGHT; 53 f |= DT_RIGHT;
54 else 54 else
55 f |= DT_LEFT; 55 f |= DT_LEFT;
(...skipping 50 matching lines...) Expand 10 before | Expand all | Expand 10 after
106 // directionality should be set as DT_RTLREADING. 106 // directionality should be set as DT_RTLREADING.
107 // 107 //
108 // Caveat: If the string is purely LTR, don't set DTL_RTLREADING since when 108 // Caveat: If the string is purely LTR, don't set DTL_RTLREADING since when
109 // the flag is set, LRE-PDF don't have the desired effect of rendering 109 // the flag is set, LRE-PDF don't have the desired effect of rendering
110 // multiline English-only text as LTR. 110 // multiline English-only text as LTR.
111 // 111 //
112 // Note that if the caller is explicitly requesting displaying the text 112 // Note that if the caller is explicitly requesting displaying the text
113 // using RTL directionality then we respect that and pass DT_RTLREADING to 113 // using RTL directionality then we respect that and pass DT_RTLREADING to
114 // ::DrawText even if the locale is LTR. 114 // ::DrawText even if the locale is LTR.
115 if ((flags & gfx::Canvas::FORCE_RTL_DIRECTIONALITY) || 115 if ((flags & gfx::Canvas::FORCE_RTL_DIRECTIONALITY) ||
116 ((l10n_util::GetTextDirection() == l10n_util::RIGHT_TO_LEFT) && 116 (base::i18n::IsRTL() &&
117 (f & DT_RIGHT) && l10n_util::StringContainsStrongRTLChars(text))) { 117 (f & DT_RIGHT) && base::i18n::StringContainsStrongRTLChars(text))) {
118 f |= DT_RTLREADING; 118 f |= DT_RTLREADING;
119 } 119 }
120 120
121 return f; 121 return f;
122 } 122 }
123 123
124 } // anonymous namespace 124 } // anonymous namespace
125 125
126 namespace gfx { 126 namespace gfx {
127 127
(...skipping 149 matching lines...) Expand 10 before | Expand all | Expand 10 after
277 text_row[cur_x] |= 0xff << SK_A32_SHIFT; // Make opaque. 277 text_row[cur_x] |= 0xff << SK_A32_SHIFT; // Make opaque.
278 } 278 }
279 } 279 }
280 } 280 }
281 281
282 // Draw the halo bitmap with blur. 282 // Draw the halo bitmap with blur.
283 drawBitmap(text_bitmap, SkIntToScalar(x - 1), SkIntToScalar(y - 1)); 283 drawBitmap(text_bitmap, SkIntToScalar(x - 1), SkIntToScalar(y - 1));
284 } 284 }
285 285
286 } // namespace gfx 286 } // namespace gfx
OLDNEW
« no previous file with comments | « app/gfx/canvas.cc ('k') | app/l10n_util.h » ('j') | no next file with comments »

Powered by Google App Engine
This is Rietveld 408576698