[gtk-engines] support: Add ge_cairo_transform_for_layout()
- From: Benjamin Otte <otte src gnome org>
- To: commits-list gnome org
- Cc:
- Subject: [gtk-engines] support: Add ge_cairo_transform_for_layout()
- Date: Mon, 16 Aug 2010 00:40:52 +0000 (UTC)
commit 7b5801707ce5494f7b244da902c75b22b773f1c3
Author: Benjamin Otte <otte redhat com>
Date: Thu Aug 12 19:52:24 2010 +0200
support: Add ge_cairo_transform_for_layout()
This function does the voodoo that is required to get a rotated
PangoLayout to show up just like the GTK2 drawing code expects it. You
can use the "rotating label" example in GTK source's tests/testgtk to
reproduce it.
https://bugzilla.gnome.org/show_bug.cgi?id=626678
engines/support/cairo-support.c | 32 ++++++++++++++++++++++++++++++++
engines/support/cairo-support.h | 2 ++
2 files changed, 34 insertions(+), 0 deletions(-)
---
diff --git a/engines/support/cairo-support.c b/engines/support/cairo-support.c
index d20896b..4344a72 100644
--- a/engines/support/cairo-support.c
+++ b/engines/support/cairo-support.c
@@ -875,6 +875,38 @@ ge_cairo_pattern_destroy(CairoPattern *pattern)
}
}
+void
+ge_cairo_transform_for_layout (cairo_t *cr,
+ PangoLayout *layout,
+ int x,
+ int y)
+{
+ const PangoMatrix *matrix;
+
+ matrix = pango_context_get_matrix (pango_layout_get_context (layout));
+ if (matrix)
+ {
+ cairo_matrix_t cairo_matrix;
+ PangoRectangle rect;
+
+ cairo_matrix_init (&cairo_matrix,
+ matrix->xx, matrix->yx,
+ matrix->xy, matrix->yy,
+ matrix->x0, matrix->y0);
+
+ pango_layout_get_extents (layout, NULL, &rect);
+ pango_matrix_transform_rectangle (matrix, &rect);
+ pango_extents_to_pixels (&rect, NULL);
+
+ cairo_matrix.x0 += x - rect.x;
+ cairo_matrix.y0 += y - rect.y;
+
+ cairo_set_matrix (cr, &cairo_matrix);
+ }
+ else
+ cairo_translate (cr, x, y);
+}
+
/*
* The following function will be called by GTK+ when the module
* is loaded and checks to see if we are compatible with the
diff --git a/engines/support/cairo-support.h b/engines/support/cairo-support.h
index 60cce1d..4e15c40 100644
--- a/engines/support/cairo-support.h
+++ b/engines/support/cairo-support.h
@@ -147,3 +147,5 @@ GE_INTERNAL CairoPattern *ge_cairo_pixbuf_pattern(GdkPixbuf *pixbuf);
GE_INTERNAL CairoPattern *ge_cairo_pixmap_pattern(GdkPixmap *pixmap);
GE_INTERNAL CairoPattern *ge_cairo_linear_shade_gradient_pattern(CairoColor *base, gdouble shade1, gdouble shade2, gboolean vertical);
GE_INTERNAL void ge_cairo_pattern_destroy(CairoPattern *pattern);
+
+GE_INTERNAL void ge_cairo_transform_for_layout (cairo_t *cr, PangoLayout *layout, int x, int y);
[
Date Prev][
Date Next] [
Thread Prev][
Thread Next]
[
Thread Index]
[
Date Index]
[
Author Index]