Index: ui/gfx/canvas_skia_linux.cc |
=================================================================== |
--- ui/gfx/canvas_skia_linux.cc (revision 96870) |
+++ ui/gfx/canvas_skia_linux.cc (working copy) |
@@ -107,88 +107,6 @@ |
g_free(rgba_style); |
} |
-// Pass a width > 0 to force wrapping and elliding. |
-void SetupPangoLayout(PangoLayout* layout, |
- const string16& text, |
- const gfx::Font& font, |
- int width, |
- base::i18n::TextDirection text_direction, |
- int flags) { |
- if (!cairo_font_options) |
- UpdateCairoFontOptions(); |
- // This needs to be done early on; it has no effect when called just before |
- // pango_cairo_show_layout(). |
- pango_cairo_context_set_font_options( |
- pango_layout_get_context(layout), cairo_font_options); |
- |
- // Callers of DrawStringInt handle RTL layout themselves, so tell pango to not |
- // scope out RTL characters. |
- pango_layout_set_auto_dir(layout, FALSE); |
- |
- if (width > 0) |
- pango_layout_set_width(layout, width * PANGO_SCALE); |
- |
- if (flags & gfx::Canvas::TEXT_ALIGN_CENTER) { |
- // We don't support center aligned w/ eliding. |
- DCHECK(gfx::Canvas::NO_ELLIPSIS); |
- pango_layout_set_alignment(layout, PANGO_ALIGN_CENTER); |
- } else if (flags & gfx::Canvas::TEXT_ALIGN_RIGHT) { |
- pango_layout_set_alignment(layout, PANGO_ALIGN_RIGHT); |
- } |
- |
- if (flags & gfx::Canvas::NO_ELLIPSIS) { |
- pango_layout_set_ellipsize(layout, PANGO_ELLIPSIZE_NONE); |
- if (flags & gfx::Canvas::MULTI_LINE) { |
- pango_layout_set_wrap(layout, |
- (flags & gfx::Canvas::CHARACTER_BREAK) ? |
- PANGO_WRAP_WORD_CHAR : PANGO_WRAP_WORD); |
- } |
- } else if (text_direction == base::i18n::RIGHT_TO_LEFT){ |
- pango_layout_set_ellipsize(layout, PANGO_ELLIPSIZE_END); |
- } else { |
- // Fading the text will be handled in the draw operation. |
- // that the text is only on one line. |
- pango_layout_set_ellipsize(layout, PANGO_ELLIPSIZE_NONE); |
- pango_layout_set_width(layout, -1); |
msw
2011/08/19 23:16:59
You removed this line amidst the function move, an
xji
2011/08/22 23:57:28
The condition checking was changed from base:i18n:
|
- } |
- |
- // Set the resolution to match that used by Gtk. If we don't set the |
- // resolution and the resolution differs from the default, Gtk and Chrome end |
- // up drawing at different sizes. |
- double resolution = gfx::GetPangoResolution(); |
- if (resolution > 0) { |
- pango_cairo_context_set_resolution(pango_layout_get_context(layout), |
- resolution); |
- } |
- |
- PangoFontDescription* desc = font.GetNativeFont(); |
- pango_layout_set_font_description(layout, desc); |
- pango_font_description_free(desc); |
- |
- // Set text and accelerator character if needed. |
- std::string utf8 = UTF16ToUTF8(text); |
- if (flags & gfx::Canvas::SHOW_PREFIX) { |
- // Escape the text string to be used as markup. |
- gchar* escaped_text = g_markup_escape_text(utf8.c_str(), utf8.size()); |
- pango_layout_set_markup_with_accel(layout, |
- escaped_text, |
- strlen(escaped_text), |
- kAcceleratorChar, NULL); |
- g_free(escaped_text); |
- } else if (flags & gfx::Canvas::HIDE_PREFIX) { |
- // Remove the ampersand character. A double ampersand is output as |
- // a single ampersand. |
- DCHECK_EQ(1, g_unichar_to_utf8(kAcceleratorChar, NULL)); |
- const std::string accelerator_removed = |
- gfx::RemoveAcceleratorChar(utf8, static_cast<char>(kAcceleratorChar)); |
- |
- pango_layout_set_text(layout, |
- accelerator_removed.data(), accelerator_removed.size()); |
- } else { |
- pango_layout_set_text(layout, utf8.data(), utf8.size()); |
- } |
-} |
- |
// A class to encapsulate string drawing params and operations. |
class DrawStringContext { |
public: |
@@ -249,7 +167,7 @@ |
cr_ = skia::BeginPlatformPaint(canvas_); |
layout_ = pango_cairo_create_layout(cr_); |
- SetupPangoLayout( |
+ gfx::SetupPangoLayout( |
layout_, text, font, bounds_.width(), text_direction_, flags_); |
pango_layout_set_height(layout_, bounds_.height() * PANGO_SCALE); |
@@ -390,6 +308,90 @@ |
namespace gfx { |
+// Pass a width > 0 to force wrapping and elliding. |
+void SetupPangoLayout(PangoLayout* layout, |
+ const string16& text, |
+ const Font& font, |
+ int width, |
+ base::i18n::TextDirection text_direction, |
+ int flags) { |
+ if (!cairo_font_options) |
+ UpdateCairoFontOptions(); |
+ // This needs to be done early on; it has no effect when called just before |
+ // pango_cairo_show_layout(). |
+ pango_cairo_context_set_font_options( |
+ pango_layout_get_context(layout), cairo_font_options); |
+ |
+ // Callers of DrawStringInt handle RTL layout themselves, so tell pango to not |
+ // scope out RTL characters. |
+ pango_layout_set_auto_dir(layout, FALSE); |
+ |
+ if (width > 0) |
+ pango_layout_set_width(layout, width * PANGO_SCALE); |
+ |
+ if (flags & Canvas::TEXT_ALIGN_CENTER) { |
+ // We don't support center aligned w/ eliding. |
+ DCHECK(gfx::Canvas::NO_ELLIPSIS); |
+ pango_layout_set_alignment(layout, PANGO_ALIGN_CENTER); |
+ } else if (flags & Canvas::TEXT_ALIGN_RIGHT) { |
+ pango_layout_set_alignment(layout, PANGO_ALIGN_RIGHT); |
+ } |
+ |
+ if (flags & Canvas::NO_ELLIPSIS) { |
+ pango_layout_set_ellipsize(layout, PANGO_ELLIPSIZE_NONE); |
+ if (flags & Canvas::MULTI_LINE) { |
+ pango_layout_set_wrap(layout, |
+ (flags & Canvas::CHARACTER_BREAK) ? |
+ PANGO_WRAP_WORD_CHAR : PANGO_WRAP_WORD); |
+ } |
+ } else if (text_direction == base::i18n::RIGHT_TO_LEFT) { |
+ pango_layout_set_ellipsize(layout, PANGO_ELLIPSIZE_END); |
+ } else { |
+ // Fading the text will be handled in the draw operation. |
+ // that the text is only on one line. |
msw
2011/08/19 23:16:59
Can you clarify (or at least complete) the second
xji
2011/08/22 23:57:28
the comments was added by davemoore in http://code
|
+ pango_layout_set_ellipsize(layout, PANGO_ELLIPSIZE_NONE); |
+ } |
+ |
+ if (!base::i18n::IsRTL()) |
+ pango_layout_set_width(layout, -1); |
+ |
+ // Set the resolution to match that used by Gtk. If we don't set the |
+ // resolution and the resolution differs from the default, Gtk and Chrome end |
+ // up drawing at different sizes. |
+ double resolution = GetPangoResolution(); |
+ if (resolution > 0) { |
+ pango_cairo_context_set_resolution(pango_layout_get_context(layout), |
+ resolution); |
+ } |
+ |
+ PangoFontDescription* desc = font.GetNativeFont(); |
+ pango_layout_set_font_description(layout, desc); |
+ pango_font_description_free(desc); |
+ |
+ // Set text and accelerator character if needed. |
+ std::string utf8 = UTF16ToUTF8(text); |
+ if (flags & Canvas::SHOW_PREFIX) { |
+ // Escape the text string to be used as markup. |
+ gchar* escaped_text = g_markup_escape_text(utf8.c_str(), utf8.size()); |
+ pango_layout_set_markup_with_accel(layout, |
+ escaped_text, |
+ strlen(escaped_text), |
+ kAcceleratorChar, NULL); |
+ g_free(escaped_text); |
+ } else if (flags & Canvas::HIDE_PREFIX) { |
+ // Remove the ampersand character. A double ampersand is output as |
+ // a single ampersand. |
+ DCHECK_EQ(1, g_unichar_to_utf8(kAcceleratorChar, NULL)); |
+ const std::string accelerator_removed = |
+ RemoveAcceleratorChar(utf8, static_cast<char>(kAcceleratorChar)); |
+ |
+ pango_layout_set_text(layout, |
+ accelerator_removed.data(), accelerator_removed.size()); |
+ } else { |
+ pango_layout_set_text(layout, utf8.data(), utf8.size()); |
+ } |
+} |
+ |
CanvasSkia::CanvasSkia(int width, int height, bool is_opaque) |
: skia::PlatformCanvas(width, height, is_opaque) { |
} |