diff options
author | davemoore@chromium.org <davemoore@chromium.org@0039d316-1c4b-4281-b951-d872f2087c98> | 2009-08-13 23:59:55 +0000 |
---|---|---|
committer | davemoore@chromium.org <davemoore@chromium.org@0039d316-1c4b-4281-b951-d872f2087c98> | 2009-08-13 23:59:55 +0000 |
commit | 5e26030d358f16265cf80d3ed387ed51d0d1abec (patch) | |
tree | ba9b071f8d051076a35a637243bbdf4ea1bac3fd /app | |
parent | 007ad6d9b7a082e5820068413e3e52a8b7bc0c06 (diff) | |
download | chromium_src-5e26030d358f16265cf80d3ed387ed51d0d1abec.zip chromium_src-5e26030d358f16265cf80d3ed387ed51d0d1abec.tar.gz chromium_src-5e26030d358f16265cf80d3ed387ed51d0d1abec.tar.bz2 |
Show favicon in panel title, highlight focused panel, fix breakage
recent search box changes
Review URL: http://codereview.chromium.org/164425
git-svn-id: svn://svn.chromium.org/chrome/trunk/src@23395 0039d316-1c4b-4281-b951-d872f2087c98
Diffstat (limited to 'app')
-rw-r--r-- | app/gfx/canvas_linux.cc | 89 |
1 files changed, 39 insertions, 50 deletions
diff --git a/app/gfx/canvas_linux.cc b/app/gfx/canvas_linux.cc index c42df59..d1d391b 100644 --- a/app/gfx/canvas_linux.cc +++ b/app/gfx/canvas_linux.cc @@ -124,42 +124,62 @@ Canvas::Canvas() : skia::PlatformCanvas() { Canvas::~Canvas() { } -// static -void Canvas::SizeStringInt(const std::wstring& text, - const gfx::Font& font, - int* width, int* height, int flags) { - cairo_surface_t* surface = - cairo_image_surface_create(CAIRO_FORMAT_ARGB32, 0, 0); - cairo_t* cr = cairo_create(surface); - PangoLayout* layout = pango_cairo_create_layout(cr); +static void SetupPangoLayout(PangoLayout* layout, + const gfx::Font& font, + 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); - if (flags & NO_ELLIPSIS) { + // Callers of DrawStringInt handle RTL layout themselves, so tell pango to not + // scope out RTL characters. + pango_layout_set_auto_dir(layout, FALSE); + + if (flags & Canvas::NO_ELLIPSIS) { pango_layout_set_ellipsize(layout, PANGO_ELLIPSIZE_NONE); } else { pango_layout_set_ellipsize(layout, PANGO_ELLIPSIZE_END); } - if (flags & TEXT_ALIGN_CENTER) { + if (flags & Canvas::TEXT_ALIGN_CENTER) { pango_layout_set_alignment(layout, PANGO_ALIGN_CENTER); - } else if (flags & TEXT_ALIGN_RIGHT) { + } else if (flags & Canvas::TEXT_ALIGN_RIGHT) { pango_layout_set_alignment(layout, PANGO_ALIGN_RIGHT); } - if (flags & MULTI_LINE) { + if (flags & Canvas::MULTI_LINE) { pango_layout_set_wrap(layout, - (flags & CHARACTER_BREAK) ? PANGO_WRAP_WORD_CHAR : PANGO_WRAP_WORD); + (flags & Canvas::CHARACTER_BREAK) ? + PANGO_WRAP_WORD_CHAR : PANGO_WRAP_WORD); } - std::string utf8 = WideToUTF8(text); - pango_layout_set_text(layout, utf8.data(), utf8.size()); PangoFontDescription* desc = PangoFontFromGfxFont(font); pango_layout_set_font_description(layout, desc); + pango_font_description_free(desc); +} + +// static +void Canvas::SizeStringInt(const std::wstring& text, + const gfx::Font& font, + int* width, int* height, int flags) { + cairo_surface_t* surface = + cairo_image_surface_create(CAIRO_FORMAT_ARGB32, 0, 0); + cairo_t* cr = cairo_create(surface); + PangoLayout* layout = pango_cairo_create_layout(cr); + + SetupPangoLayout(layout, font, flags); + + std::string utf8 = WideToUTF8(text); + pango_layout_set_text(layout, utf8.data(), utf8.size()); pango_layout_get_size(layout, width, height); *width /= PANGO_SCALE; *height /= PANGO_SCALE; + g_object_unref(layout); - pango_font_description_free(desc); cairo_destroy(cr); cairo_surface_destroy(surface); } @@ -171,50 +191,19 @@ void Canvas::DrawStringInt(const std::wstring& text, cairo_t* cr = beginPlatformPaint(); PangoLayout* layout = pango_cairo_create_layout(cr); - 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); + SetupPangoLayout(layout, font, flags); - // Callers of DrawStringInt handle RTL layout themselves, so tell pango to not - // scope out RTL characters. - pango_layout_set_auto_dir(layout, FALSE); + pango_layout_set_width(layout, w * PANGO_SCALE); + pango_layout_set_height(layout, h * PANGO_SCALE); cairo_set_source_rgb(cr, SkColorGetR(color) / 255.0, SkColorGetG(color) / 255.0, SkColorGetB(color) / 255.0); - // TODO(deanm): Implement the rest of the Canvas flags. - if (!(flags & Canvas::NO_ELLIPSIS)) - pango_layout_set_ellipsize(layout, PANGO_ELLIPSIZE_END); - - pango_layout_set_width(layout, w * PANGO_SCALE); - pango_layout_set_height(layout, h * PANGO_SCALE); - - if (flags & TEXT_ALIGN_CENTER) { - pango_layout_set_alignment(layout, PANGO_ALIGN_CENTER); - } else if (flags & TEXT_ALIGN_RIGHT) { - pango_layout_set_alignment(layout, PANGO_ALIGN_RIGHT); - } - - if (flags & MULTI_LINE) { - pango_layout_set_wrap(layout, - (flags & CHARACTER_BREAK) ? PANGO_WRAP_WORD_CHAR : PANGO_WRAP_WORD); - } - - if (flags & NO_ELLIPSIS) - pango_layout_set_ellipsize(layout, PANGO_ELLIPSIZE_NONE); - std::string utf8 = WideToUTF8(text); pango_layout_set_text(layout, utf8.data(), utf8.size()); - PangoFontDescription* desc = PangoFontFromGfxFont(font); - pango_layout_set_font_description(layout, desc); - pango_font_description_free(desc); - int width, height; pango_layout_get_size(layout, &width, &height); |