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

Unified Diff: app/gfx/canvas_linux.cc

Issue 115586: Unified the ways Font and Canvas get the pixel size of strings, using pango (Closed) Base URL: svn://chrome-svn/chrome/trunk/src/
Patch Set: '' Created 11 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 | app/gfx/font_skia.cc » ('j') | no next file with comments »
Expand Comments ('e') | Collapse Comments ('c') | Show Comments Hide Comments ('s')
Index: app/gfx/canvas_linux.cc
===================================================================
--- app/gfx/canvas_linux.cc (revision 16508)
+++ app/gfx/canvas_linux.cc (working copy)
@@ -57,7 +57,39 @@
void Canvas::SizeStringInt(const std::wstring& text,
const gfx::Font& font,
int* width, int* height, int flags) {
- NOTIMPLEMENTED();
+ 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);
+
+ if (flags & NO_ELLIPSIS) {
+ pango_layout_set_ellipsize(layout, PANGO_ELLIPSIZE_NONE);
+ } else {
+ pango_layout_set_ellipsize(layout, PANGO_ELLIPSIZE_END);
+ }
+
+ 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);
+ }
+
+ 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_layout_get_size(layout, width, height);
+ *width /= PANGO_SCALE;
+ *height /= PANGO_SCALE;
+ g_object_unref(layout);
+ pango_font_description_free(desc);
+ cairo_destroy(cr);
}
void Canvas::ApplySkiaMatrixToCairoContext(cairo_t* cr) {
« no previous file with comments | « no previous file | app/gfx/font_skia.cc » ('j') | no next file with comments »

Powered by Google App Engine
This is Rietveld 408576698