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

Unified Diff: ui/gfx/canvas_skia.cc

Issue 10384168: Fix incorrect forcing of text directionality in canvas_skia.cc. (Closed) Base URL: svn://svn.chromium.org/chrome/trunk/src/
Patch Set: Created 8 years, 7 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 side-by-side diff with in-line comments
Download patch
« no previous file with comments | « no previous file | no next file » | no next file with comments »
Expand Comments ('e') | Collapse Comments ('c') | Show Comments Hide Comments ('s')
Index: ui/gfx/canvas_skia.cc
===================================================================
--- ui/gfx/canvas_skia.cc (revision 136986)
+++ ui/gfx/canvas_skia.cc (working copy)
@@ -19,14 +19,38 @@
namespace {
-// Based on |flags| and |text| content, returns whether text should be
-// rendered right-to-left.
-bool IsTextRTL(int flags, const string16& text) {
- if (flags & gfx::Canvas::FORCE_RTL_DIRECTIONALITY)
+// If necessary, wraps |text| with RTL/LTR directionality characters based on
+// |flags| and |text| content.
+// Returns true if the text will be rendered right-to-left.
+bool AdjustStringDirection(int flags, string16* text) {
+ if (text->empty())
+ return false;
+
+ // First, if RTL was forced, simply apply it.
+ if (flags & gfx::Canvas::FORCE_RTL_DIRECTIONALITY) {
+ base::i18n::WrapStringWithRTLFormatting(text);
return true;
- if (flags & gfx::Canvas::FORCE_LTR_DIRECTIONALITY)
+ }
+
+ // If RTL wasn't forced and the string does not have strong RTL chars, it
+ // will be rendered LTR already, so no need to do anything special.
+ if (!base::i18n::StringContainsStrongRTLChars(*text))
return false;
- return base::i18n::IsRTL() && base::i18n::StringContainsStrongRTLChars(text);
+
+ // If LTR is forced for a string with strong RTL characters, apply it here.
+ if (flags & gfx::Canvas::FORCE_LTR_DIRECTIONALITY) {
+ base::i18n::WrapStringWithLTRFormatting(text);
xji 2012/05/15 19:42:07 I think in our current Uniscribe implementation of
+ return false;
+ }
+
+ // Finally, if a direction wasn't forced but the UI language is RTL and there
+ // were strong RTL characters, ensure RTL is applied.
+ if (base::i18n::IsRTL()) {
+ base::i18n::WrapStringWithRTLFormatting(text);
+ return true;
+ }
+
+ return false;
xji 2012/05/15 19:42:07 I'd prefer the old 'if'/'else' structure.
}
// Checks each pixel immediately adjacent to the given pixel in the bitmap. If
@@ -250,8 +274,7 @@
string16 adjusted_text = text;
#if defined(OS_WIN)
- if (IsTextRTL(flags, adjusted_text))
- base::i18n::AdjustStringForLocaleDirection(&adjusted_text);
+ AdjustStringDirection(flags, &adjusted_text);
#endif
scoped_ptr<RenderText> render_text(RenderText::CreateRenderText());
@@ -392,9 +415,7 @@
scoped_ptr<RenderText> render_text(RenderText::CreateRenderText());
string16 clipped_text = text;
- const bool is_rtl = IsTextRTL(flags, text);
- if (is_rtl)
- base::i18n::AdjustStringForLocaleDirection(&clipped_text);
+ const bool is_rtl = AdjustStringDirection(flags, &clipped_text);
switch (truncate_mode) {
case TruncateFadeTail:
« no previous file with comments | « no previous file | no next file » | no next file with comments »

Powered by Google App Engine
This is Rietveld 408576698