diff options
author | xji@chromium.org <xji@chromium.org@0039d316-1c4b-4281-b951-d872f2087c98> | 2011-08-18 23:32:34 +0000 |
---|---|---|
committer | xji@chromium.org <xji@chromium.org@0039d316-1c4b-4281-b951-d872f2087c98> | 2011-08-18 23:32:34 +0000 |
commit | 3f49b8167ced932005ae75e29adb1f9f7f5908da (patch) | |
tree | e93c4bfe9860bc8c5c3c446da32b80bd6c3bbad7 /ui/gfx | |
parent | 606788603dbb0d5ce1e9eac0e6009b5bcc308b65 (diff) | |
download | chromium_src-3f49b8167ced932005ae75e29adb1f9f7f5908da.zip chromium_src-3f49b8167ced932005ae75e29adb1f9f7f5908da.tar.gz chromium_src-3f49b8167ced932005ae75e29adb1f9f7f5908da.tar.bz2 |
Introduce FORCE_LTR_DIRECTIONALTY in Canvas.
For strings coming from webpage (such as alert in JS), its directionality is set according to the directionality of its first strong character's directionality.
For chrome's UI string, its directionality is set as RTL if the UI is RTL and the string contains strong RTL characters.
BUG=91698
TEST=start chrome in RTL locale, check about:crash, "!" should be displayed at very left. check the directionality of alert() with bidi text in LTR and RTL chrome, the directionality should be determined by its first strong directionality character.
Review URL: http://codereview.chromium.org/7655037
git-svn-id: svn://svn.chromium.org/chrome/trunk/src@97392 0039d316-1c4b-4281-b951-d872f2087c98
Diffstat (limited to 'ui/gfx')
-rw-r--r-- | ui/gfx/canvas.h | 4 | ||||
-rw-r--r-- | ui/gfx/canvas_skia_win.cc | 19 |
2 files changed, 16 insertions, 7 deletions
diff --git a/ui/gfx/canvas.h b/ui/gfx/canvas.h index 5fdce31..5fa067e 100644 --- a/ui/gfx/canvas.h +++ b/ui/gfx/canvas.h @@ -68,6 +68,10 @@ class UI_EXPORT Canvas { // installed) don't support these characters. Thus, this flag should be // used to render text using RTL directionality when the locale is LTR. FORCE_RTL_DIRECTIONALITY = 2048, + + // Similar to FORCE_RTL_DIRECTIONALITY, but left-to-right. + // See FORCE_RTL_DIRECTIONALITY for details. + FORCE_LTR_DIRECTIONALITY = 4096, }; virtual ~Canvas() {} diff --git a/ui/gfx/canvas_skia_win.cc b/ui/gfx/canvas_skia_win.cc index 001c55b..e71fefd 100644 --- a/ui/gfx/canvas_skia_win.cc +++ b/ui/gfx/canvas_skia_win.cc @@ -112,12 +112,15 @@ int ComputeFormatFlags(int flags, const string16& text) { // first character with strong directionality. If the directionality of the // first character with strong directionality in the text is LTR, the // alignment is set to DT_LEFT, and the directionality should not be set as - // DT_RTLREADING. + // DT_RTLREADING. If the directionality of the first character with strong + // directionality in the text is RTL, its alignment is set to DT_RIGHT, and + // its directionality is set as DT_RTLREADING through + // FORCE_RTL_DIRECTIONALITY. // // This heuristic doesn't work for Chrome UI strings since even in RTL // locales, some of those might start with English text but we know they're - // localized so we always want them to be right aligned, and their - // directionality should be set as DT_RTLREADING. + // localized so their directionality should be set as DT_RTLREADING if it + // contains strong RTL characters. // // Caveat: If the string is purely LTR, don't set DTL_RTLREADING since when // the flag is set, LRE-PDF don't have the desired effect of rendering @@ -126,11 +129,13 @@ int ComputeFormatFlags(int flags, const string16& text) { // Note that if the caller is explicitly requesting displaying the 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) || - (base::i18n::IsRTL() && - (f & DT_RIGHT) && base::i18n::StringContainsStrongRTLChars(text))) { + int force_rtl = (flags & gfx::Canvas::FORCE_RTL_DIRECTIONALITY); + int force_ltr = (flags & gfx::Canvas::FORCE_LTR_DIRECTIONALITY); + bool is_rtl = base::i18n::IsRTL(); + bool string_contains_strong_rtl_chars = + base::i18n::StringContainsStrongRTLChars(text); + if (force_rtl || (!force_ltr && is_rtl && string_contains_strong_rtl_chars)) f |= DT_RTLREADING; - } return f; } |