summaryrefslogtreecommitdiff
path: root/pango/pangocairo-render.c
diff options
context:
space:
mode:
authorBehdad Esfahbod <behdad@gnome.org>2007-05-04 11:33:14 +0000
committerBehdad Esfahbod <behdad@src.gnome.org>2007-05-04 11:33:14 +0000
commit0defecb84e0beabd95a1a39801dc715d327c3b59 (patch)
treecc2c4e11060dc43d7d5938d7fff40b9f4be2fd96 /pango/pangocairo-render.c
parent7dfb3c077cc7b2234fe9ab098a237c11e8de55da (diff)
downloadpango-0defecb84e0beabd95a1a39801dc715d327c3b59.tar.gz
New API
2007-05-04 Behdad Esfahbod <behdad@gnome.org> * pango/pangocairo.h: * pango/pangocairo-context.c: * pango/pangocairo-render.c: New API PangoCairoShapeRendererFunc and pango_cairo_context_[sg]et_shape_renderer() * docs/pango-sections.txt, docs/tmpl/pangocairo.sgml: Document new * API. * examples/Makefile.am, examples/cairoshape.c: New example to show off new API/feature. svn path=/trunk/; revision=2261
Diffstat (limited to 'pango/pangocairo-render.c')
-rw-r--r--pango/pangocairo-render.c35
1 files changed, 34 insertions, 1 deletions
diff --git a/pango/pangocairo-render.c b/pango/pangocairo-render.c
index 9ec2e682..4c0baf29 100644
--- a/pango/pangocairo-render.c
+++ b/pango/pangocairo-render.c
@@ -36,6 +36,8 @@ struct _PangoCairoRenderer
cairo_t *cr;
gboolean do_path;
double x_offset, y_offset;
+ PangoCairoShapeRendererFunc shape_renderer;
+ gpointer shape_renderer_data;
};
struct _PangoCairoRendererClass
@@ -69,7 +71,6 @@ _pango_cairo_renderer_draw_frame (PangoCairoRenderer *crenderer,
{
if (crenderer->do_path)
{
- cairo_t *cr = crenderer->cr;
double d2 = line_width * .5, d = line_width;
/* we draw an outer box in one winding direction and an inner one in the
@@ -406,6 +407,31 @@ pango_cairo_renderer_draw_error_underline (PangoRenderer *renderer,
}
static void
+pango_cairo_renderer_draw_shape (PangoRenderer *renderer,
+ PangoAttrShape *attr,
+ int x,
+ int y)
+{
+ PangoCairoRenderer *crenderer = (PangoCairoRenderer *) (renderer);
+ cairo_t *cr = crenderer->cr;
+ double base_x = crenderer->x_offset + (double)x / PANGO_SCALE;
+ double base_y = crenderer->y_offset + (double)y / PANGO_SCALE;
+
+ if (!crenderer->shape_renderer)
+ return;
+
+ cairo_save (cr);
+ if (!crenderer->do_path)
+ set_color (crenderer, PANGO_RENDER_PART_FOREGROUND);
+
+ cairo_move_to (cr, base_x, base_y);
+
+ crenderer->shape_renderer (cr, attr, crenderer->do_path, crenderer->shape_renderer_data);
+
+ cairo_restore (cr);
+}
+
+static void
pango_cairo_renderer_init (PangoCairoRenderer *renderer)
{
}
@@ -418,6 +444,7 @@ pango_cairo_renderer_class_init (PangoCairoRendererClass *klass)
renderer_class->draw_glyphs = pango_cairo_renderer_draw_glyphs;
renderer_class->draw_rectangle = pango_cairo_renderer_draw_rectangle;
renderer_class->draw_error_underline = pango_cairo_renderer_draw_error_underline;
+ renderer_class->draw_shape = pango_cairo_renderer_draw_shape;
}
static PangoCairoRenderer *cached_renderer = NULL;
@@ -454,6 +481,8 @@ release_renderer (PangoCairoRenderer *renderer, gboolean free_renderer)
{
renderer->cr = NULL;
renderer->do_path = FALSE;
+ renderer->shape_renderer = NULL;
+ renderer->shape_renderer_data = NULL;
renderer->x_offset = 0.;
renderer->y_offset = 0.;
@@ -516,6 +545,8 @@ _pango_cairo_do_layout_line (cairo_t *cr,
crenderer->cr = cr;
crenderer->do_path = do_path;
+ crenderer->shape_renderer = pango_cairo_context_get_shape_renderer (pango_layout_get_context (line->layout),
+ &crenderer->shape_renderer_data);
cairo_get_current_point (cr, &crenderer->x_offset, &crenderer->y_offset);
pango_renderer_draw_layout_line (renderer, line, 0, 0);
@@ -534,6 +565,8 @@ _pango_cairo_do_layout (cairo_t *cr,
crenderer->cr = cr;
crenderer->do_path = do_path;
+ crenderer->shape_renderer = pango_cairo_context_get_shape_renderer (pango_layout_get_context (layout),
+ &crenderer->shape_renderer_data);
cairo_get_current_point (cr, &crenderer->x_offset, &crenderer->y_offset);
pango_renderer_draw_layout (renderer, layout, 0, 0);