From 7cf1b6ced3b14cce1d66ca0ddc713851f0d37536 Mon Sep 17 00:00:00 2001 From: "ben@chromium.org" Date: Sat, 20 Mar 2010 06:37:01 +0000 Subject: Move RTL related functions from app/l10n_util to base/i18n/rtl TBR=darin BUG=none TEST=none Review URL: http://codereview.chromium.org/1073005 git-svn-id: svn://svn.chromium.org/chrome/trunk/src@42182 0039d316-1c4b-4281-b951-d872f2087c98 --- app/gfx/canvas.cc | 10 +++++++++- app/gfx/canvas.h | 9 +++++++++ app/gfx/canvas_win.cc | 10 +++++----- 3 files changed, 23 insertions(+), 6 deletions(-) (limited to 'app/gfx') diff --git a/app/gfx/canvas.cc b/app/gfx/canvas.cc index 75f8011..75ec0a1 100644 --- a/app/gfx/canvas.cc +++ b/app/gfx/canvas.cc @@ -8,6 +8,7 @@ #include "app/gfx/font.h" #include "app/l10n_util.h" +#include "base/i18n/rtl.h" #include "base/logging.h" #include "gfx/rect.h" #include "third_party/skia/include/core/SkShader.h" @@ -218,7 +219,7 @@ void Canvas::DrawStringInt(const std::wstring& text, const SkColor& color, int x, int y, int w, int h) { DrawStringInt(text, font, color, x, y, w, h, - l10n_util::DefaultCanvasTextAlignment()); + gfx::Canvas::DefaultCanvasTextAlignment()); } void Canvas::DrawStringInt(const std::wstring& text, @@ -267,4 +268,11 @@ SkBitmap Canvas::ExtractBitmap() const { return result; } +// static +int Canvas::DefaultCanvasTextAlignment() { + if (!base::i18n::IsRTL()) + return gfx::Canvas::TEXT_ALIGN_LEFT; + return gfx::Canvas::TEXT_ALIGN_RIGHT; +} + } // namespace gfx diff --git a/app/gfx/canvas.h b/app/gfx/canvas.h index 79eed9c..ea4fbf3 100644 --- a/app/gfx/canvas.h +++ b/app/gfx/canvas.h @@ -211,6 +211,15 @@ class Canvas : public skia::PlatformCanvas { static void SizeStringInt(const std::wstring& test, const gfx::Font& font, int *width, int* height, int flags); + // Returns the default text alignment to be used when drawing text on a + // gfx::Canvas based on the directionality of the system locale language. This + // function is used by gfx::Canvas::DrawStringInt when the text alignment is + // not specified. + // + // This function returns either gfx::Canvas::TEXT_ALIGN_LEFT or + // gfx::Canvas::TEXT_ALIGN_RIGHT. + static int DefaultCanvasTextAlignment(); + private: #if defined(OS_WIN) // Draws text with the specified color, font and location. The text is diff --git a/app/gfx/canvas_win.cc b/app/gfx/canvas_win.cc index de9d45a..abe722c 100644 --- a/app/gfx/canvas_win.cc +++ b/app/gfx/canvas_win.cc @@ -7,7 +7,7 @@ #include #include "app/gfx/font.h" -#include "app/l10n_util.h" +#include "base/i18n/rtl.h" #include "gfx/rect.h" #include "third_party/skia/include/core/SkShader.h" @@ -24,7 +24,7 @@ void DoDrawText(HDC hdc, const std::wstring& text, // 1. The current locale is RTL. // 2. The string itself has RTL directionality. if (flags & DT_RTLREADING) { - if (l10n_util::AdjustStringForLocaleDirection(text, &localized_text)) { + if (base::i18n::AdjustStringForLocaleDirection(text, &localized_text)) { string_ptr = localized_text.c_str(); string_size = static_cast(localized_text.length()); } @@ -42,7 +42,7 @@ int ComputeFormatFlags(int flags, const std::wstring& text) { if (!(flags & (gfx::Canvas::TEXT_ALIGN_CENTER | gfx::Canvas::TEXT_ALIGN_RIGHT | gfx::Canvas::TEXT_ALIGN_LEFT))) { - flags |= l10n_util::DefaultCanvasTextAlignment(); + flags |= gfx::Canvas::DefaultCanvasTextAlignment(); } // horizontal alignment @@ -113,8 +113,8 @@ int ComputeFormatFlags(int flags, const std::wstring& text) { // using RTL directionality then we respect that and pass DT_RTLREADING to // ::DrawText even if the locale is LTR. if ((flags & gfx::Canvas::FORCE_RTL_DIRECTIONALITY) || - ((l10n_util::GetTextDirection() == l10n_util::RIGHT_TO_LEFT) && - (f & DT_RIGHT) && l10n_util::StringContainsStrongRTLChars(text))) { + (base::i18n::IsRTL() && + (f & DT_RIGHT) && base::i18n::StringContainsStrongRTLChars(text))) { f |= DT_RTLREADING; } -- cgit v1.1