Chromium Code Reviews| Index: ui/gfx/canvas_skia.cc |
| diff --git a/ui/gfx/canvas_skia.cc b/ui/gfx/canvas_skia.cc |
| index 29f6f773063167ce12b6431ea46899a9ba45345b..d33567e88370a7061c9da082bd6f1c9256f70b50 100644 |
| --- a/ui/gfx/canvas_skia.cc |
| +++ b/ui/gfx/canvas_skia.cc |
| @@ -19,37 +19,22 @@ |
| namespace { |
| -// 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. |
| -// TODO(msw): Nix this, now that RenderTextWin supports directionality directly. |
| -bool AdjustStringDirection(int flags, string16* text) { |
| - // TODO(msw): FORCE_LTR_DIRECTIONALITY does not work for RTL text now. |
| - |
| - // If the string is empty or LTR was forced, simply return false since the |
| - // default RenderText directionality is already LTR. |
| - if (text->empty() || (flags & gfx::Canvas::FORCE_LTR_DIRECTIONALITY)) |
| - return false; |
| - |
| - // If RTL is forced, apply it to the string. |
| - if (flags & gfx::Canvas::FORCE_RTL_DIRECTIONALITY) { |
| - base::i18n::WrapStringWithRTLFormatting(text); |
| - return true; |
| - } |
| +// If necessary, force RTL/LTR base directionality. |
| +// Returns true if the text will be rendered with an RTL base direction. |
|
Alexei Svitkine (slow)
2012/07/31 23:33:29
Remove the return value here and use GetTextDirect
msw
2012/08/01 17:30:10
Good point! Done.
|
| +bool AdjustStringDirection(int flags, |
| + const string16& text, |
| + gfx::RenderText* render_text) { |
| + if (flags & gfx::Canvas::FORCE_LTR_DIRECTIONALITY) |
| + render_text->SetDirectionalityMode(gfx::DIRECTIONALITY_FORCE_LTR); |
| + else if (flags & gfx::Canvas::FORCE_RTL_DIRECTIONALITY) |
| + render_text->SetDirectionalityMode(gfx::DIRECTIONALITY_FORCE_RTL); |
| // 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::StringContainsStrongRTLChars(*text)) { |
| - base::i18n::WrapStringWithRTLFormatting(text); |
| - return true; |
| - } |
| + if (base::i18n::IsRTL() && base::i18n::StringContainsStrongRTLChars(text)) |
| + render_text->SetDirectionalityMode(gfx::DIRECTIONALITY_FROM_UI); |
| - // In the default case, the string should be rendered as LTR. RenderText's |
| - // default directionality is LTR, so the text doesn't need to be wrapped. |
| - // Note that individual runs within the string may still be rendered RTL |
| - // (which will be the case for RTL text under non-RTL locales, since under RTL |
| - // locales it will be handled by the if statement above). |
| - return false; |
| + return render_text->GetTextDirection() == base::i18n::RIGHT_TO_LEFT; |
| } |
| // Checks each pixel immediately adjacent to the given pixel in the bitmap. If |
| @@ -203,8 +188,10 @@ void Canvas::SizeStringInt(const string16& text, |
| flags = AdjustPlatformSpecificFlags(text, flags); |
| string16 adjusted_text = text; |
| + scoped_ptr<RenderText> render_text(RenderText::CreateInstance()); |
| + |
| #if defined(OS_WIN) |
| - AdjustStringDirection(flags, &adjusted_text); |
| + AdjustStringDirection(flags, adjusted_text, render_text.get()); |
| #endif |
| if ((flags & MULTI_LINE) && *width != 0) { |
| @@ -218,7 +205,6 @@ void Canvas::SizeStringInt(const string16& text, |
| std::vector<string16> strings; |
| ui::ElideRectangleText(adjusted_text, font, rect.width(), rect.height(), |
| wrap_behavior, &strings); |
| - scoped_ptr<RenderText> render_text(RenderText::CreateInstance()); |
| UpdateRenderText(rect, string16(), font, flags, 0, render_text.get()); |
| int h = 0; |
| @@ -240,7 +226,6 @@ void Canvas::SizeStringInt(const string16& text, |
| *width = adjusted_text.length() * font.GetAverageCharacterWidth(); |
| *height = font.GetHeight(); |
| } else { |
| - scoped_ptr<RenderText> render_text(RenderText::CreateInstance()); |
| gfx::Rect rect(*width, *height); |
| StripAcceleratorChars(flags, &adjusted_text); |
| UpdateRenderText(rect, adjusted_text, font, flags, 0, render_text.get()); |
| @@ -280,13 +265,13 @@ void Canvas::DrawStringWithShadows(const string16& text, |
| gfx::Rect rect(text_bounds); |
| string16 adjusted_text = text; |
| -#if defined(OS_WIN) |
| - AdjustStringDirection(flags, &adjusted_text); |
| -#endif |
| - |
| scoped_ptr<RenderText> render_text(RenderText::CreateInstance()); |
| render_text->SetTextShadows(shadows); |
| +#if defined(OS_WIN) |
| + AdjustStringDirection(flags, adjusted_text, render_text.get()); |
| +#endif |
| + |
| if (flags & MULTI_LINE) { |
| ui::WordWrapBehavior wrap_behavior = ui::IGNORE_LONG_WORDS; |
| if (flags & CHARACTER_BREAK) |
| @@ -423,7 +408,8 @@ void Canvas::DrawFadeTruncatingString( |
| scoped_ptr<RenderText> render_text(RenderText::CreateInstance()); |
| string16 clipped_text = text; |
| - const bool is_rtl = AdjustStringDirection(flags, &clipped_text); |
| + const bool is_rtl = |
| + AdjustStringDirection(flags, clipped_text, render_text.get()); |
| switch (truncate_mode) { |
| case TruncateFadeTail: |