[PATCH] Use pangocairo in theme_render_frame() title.
Martin Minarik
minarik11 at student.fiit.stuba.sk
Tue Jun 19 07:32:19 PDT 2012
This provides support for international text in window titles.
---
configure.ac | 5 +++--
shared/cairo-util.c | 37 ++++++++++++++++++++++---------------
2 files changed, 25 insertions(+), 17 deletions(-)
diff --git a/configure.ac b/configure.ac
index ce97486..3198d16 100644
--- a/configure.ac
+++ b/configure.ac
@@ -123,9 +123,10 @@ PKG_CHECK_MODULES(WEBP, [libwebp], [have_webp=yes], [have_webp=no])
AS_IF([test "x$have_webp" = "xyes"],
[AC_DEFINE([HAVE_WEBP], [1], [Have webp])])
+PKG_CHECK_MODULES(PANGOCAIRO, [pangocairo], [have_pangocairo=yes], [have_pangocairo=no])
PKG_CHECK_MODULES(CAIRO, [cairo])
-SHARED_LIBS="$CAIRO_LIBS $PIXMAN_LIBS $PNG_LIBS $WEBP_LIBS"
-SHARED_CFLAGS="$CAIRO_CFLAGS $PIXMAN_CFLAGS $PNG_CFLAGS $WEBP_CFLAGS"
+SHARED_LIBS="$CAIRO_LIBS $PANGOCAIRO_LIBS $PIXMAN_LIBS $PNG_LIBS $WEBP_LIBS"
+SHARED_CFLAGS="$CAIRO_CFLAGS $PANGOCAIRO_CFLAGS $PIXMAN_CFLAGS $PNG_CFLAGS $WEBP_CFLAGS"
AC_SUBST(SHARED_LIBS)
AC_SUBST(SHARED_CFLAGS)
diff --git a/shared/cairo-util.c b/shared/cairo-util.c
index 649ed98..31ebcd8 100644
--- a/shared/cairo-util.c
+++ b/shared/cairo-util.c
@@ -30,6 +30,7 @@
#include <math.h>
#include <cairo.h>
#include "cairo-util.h"
+#include <pango/pangocairo.h>
#include "../shared/config-parser.h"
@@ -380,7 +381,7 @@ theme_render_frame(struct theme *t,
cairo_text_extents_t extents;
cairo_font_extents_t font_extents;
cairo_surface_t *source;
- int x, y;
+ int x, y, text_width, text_height;
cairo_set_operator(cr, CAIRO_OPERATOR_SOURCE);
cairo_set_source_rgba(cr, 0, 0, 0, 0);
@@ -401,31 +402,37 @@ theme_render_frame(struct theme *t,
width - t->margin * 2, height - t->margin * 2,
t->width, t->titlebar_height);
+ PangoFontDescription *font_d = pango_font_description_new ();
+ pango_font_description_set_family (font_d, "sans");
+ pango_font_description_set_weight (font_d, PANGO_WEIGHT_BOLD);
+ pango_font_description_set_absolute_size (font_d, 14 * PANGO_SCALE);
+
+ PangoLayout *layout = pango_cairo_create_layout(cr);
+ pango_layout_set_font_description(layout, font_d);
+ pango_layout_set_text(layout, title, -1);
+
+ pango_layout_get_size (layout, &text_width, &text_height);
+
+ x = (width - (double)text_width / PANGO_SCALE) / 2;
+ y = t->margin + t->width;
+
cairo_set_operator(cr, CAIRO_OPERATOR_OVER);
- cairo_select_font_face(cr, "sans",
- CAIRO_FONT_SLANT_NORMAL,
- CAIRO_FONT_WEIGHT_BOLD);
- cairo_set_font_size(cr, 14);
- cairo_text_extents(cr, title, &extents);
- cairo_font_extents (cr, &font_extents);
- x = (width - extents.width) / 2;
- y = t->margin +
- (t->titlebar_height -
- font_extents.ascent - font_extents.descent) / 2 +
- font_extents.ascent;
if (flags & THEME_FRAME_ACTIVE) {
cairo_move_to(cr, x + 1, y + 1);
cairo_set_source_rgb(cr, 1, 1, 1);
- cairo_show_text(cr, title);
+ pango_cairo_show_layout(cr, layout);
cairo_move_to(cr, x, y);
cairo_set_source_rgb(cr, 0, 0, 0);
- cairo_show_text(cr, title);
+ pango_cairo_show_layout(cr, layout);
} else {
cairo_move_to(cr, x, y);
cairo_set_source_rgb(cr, 0.4, 0.4, 0.4);
- cairo_show_text(cr, title);
+ pango_cairo_show_layout(cr, layout);
}
+
+ pango_font_description_free(font_d);
+ g_object_unref(layout);
}
enum theme_location
--
1.7.5.4
More information about the wayland-devel
mailing list