RsvgCairoClipRender: Implement the ::render_pango_layout() method, so we can clip text

With this, the test masking-path-04-b.svg passes.
parent 589e2dcf
......@@ -38,6 +38,7 @@
#include <math.h>
#include <string.h>
#include <pango/pangocairo.h>
typedef struct RsvgCairoClipRender RsvgCairoClipRender;
......@@ -63,6 +64,31 @@ rsvg_cairo_clip_apply_affine (RsvgCairoClipRender *render, cairo_matrix_t *affin
cairo_set_matrix (cairo_render->cr, &matrix);
static void
rsvg_cairo_clip_render_pango_layout (RsvgDrawingCtx * ctx, PangoLayout * layout, double x, double y)
RsvgCairoClipRender *render = RSVG_CAIRO_CLIP_RENDER (ctx->render);
RsvgCairoRender *cairo_render = &render->super;
cairo_matrix_t affine;
PangoGravity gravity = pango_context_get_gravity (pango_layout_get_context (layout));
double rotation;
affine = rsvg_drawing_ctx_get_current_state_affine (ctx);
rsvg_cairo_clip_apply_affine (render, &affine);
rotation = pango_gravity_to_rotation (gravity);
cairo_save (cairo_render->cr);
cairo_move_to (cairo_render->cr, x, y);
if (rotation != 0.)
cairo_rotate (cairo_render->cr, -rotation);
pango_cairo_update_layout (cairo_render->cr, layout);
pango_cairo_layout_path (cairo_render->cr, layout);
cairo_restore (cairo_render->cr);
static void
rsvg_cairo_clip_render_path_builder (RsvgDrawingCtx * ctx, RsvgPathBuilder *builder)
......@@ -126,7 +152,7 @@ rsvg_cairo_clip_render_new (cairo_t *cr, RsvgCairoRender *parent)
render->free = rsvg_cairo_clip_render_free;
render->create_pango_context = rsvg_cairo_create_pango_context;
render->render_pango_layout = rsvg_cairo_render_pango_layout;
render->render_pango_layout = rsvg_cairo_clip_render_pango_layout;
render->render_path_builder = rsvg_cairo_clip_render_path_builder;
render->render_surface = rsvg_cairo_clip_render_surface;
render->pop_discrete_layer = rsvg_cairo_clip_pop_discrete_layer;
<svg version="1.1" baseProfile="basic" id="svg-root"
width="100%" height="100%" viewBox="0 0 480 360"
xmlns="" xmlns:xlink="">
<!--= SVG 1.1 2nd Edition Test Case =-->
<!--= Copyright 2009 World Wide Web Consortium, (Massachusetts =-->
<!--= Institute of Technology, European Research Consortium for =-->
<!--= Informatics and Mathematics (ERCIM), Keio University). =-->
<!--= All Rights Reserved. =-->
<!--= See =-->
<d:SVGTestCase xmlns:d=""
template-version="1.4" reviewer="SVGWG" author="Chris Lilley" status="accepted"
version="$Revision: 1.5 $" testname="$RCSfile: masking-path-04-b.svg,v $">
<d:testDescription xmlns="" href="">
This test exercises basic user-specified clip paths, using a text
string (i.e., content of a 'text' element) as the clip path.
There is a rectangular image of a swirly blue pattern with large
yellow text, "Clip Test" superimposed. The image is a PNG file,
imported into the picture via the 'image' element.
The test uses the 'rect' element, as well as basic fill (solid primary
colors), stroke (black 1-pixel lines), font-family (Arial and
Impact) and font-size properties.
<d:operatorScript xmlns="">
Run the test. No interaction required.
<d:passCriteria xmlns="">
The rendered picture should match the reference image, except for
possible variations in the labelling text (per CSS2 rules).
<title id="test-title">$RCSfile: masking-path-04-b.svg,v $</title>
<font-face font-family="SVGFreeSansASCII" unicode-range="U+0-7F">
<font-face-uri xlink:href="../resources/SVGFreeSans.svg#ascii"/>
<g id="test-body-content" font-family="SVGFreeSansASCII,sans-serif" font-size="18">
<g shape-rendering="geometricPrecision">
<clipPath id="sample" clipPathUnits="userSpaceOnUse">
<text x="45" y="270" font-size="100" font-family="Impact">Clip Test</text>
<image xlink:href="resources/bluesquidj.png" preserveAspectRatio="none" x="30" y="20" width="410" height="140"/>
<text x="55" y="130" font-size="100" font-family="Impact" fill="yellow">Clip Test</text>
<image xlink:href="resources/bluesquidj.png" preserveAspectRatio="none" x="20" y="170" width="410" height="160" clip-path="url(#sample)"/>
<g font-family="SVGFreeSansASCII,sans-serif" font-size="32">
<text id="revision" x="10" y="340" stroke="none" fill="black">$Revision: 1.5 $</text>
<rect id="test-frame" x="1" y="1" width="478" height="358" fill="none" stroke="#000000"/>
<!-- comment out this watermark once the test is approved -->
<!--<g id="draft-watermark">
<rect x="1" y="1" width="478" height="20" fill="red" stroke="black" stroke-width="1"/>
<text font-family="SVGFreeSansASCII,sans-serif" font-weight="bold" font-size="20" x="240"
text-anchor="middle" y="18" stroke-width="0.5" stroke="black" fill="white">DRAFT</text>
Markdown is supported
0% or
You are about to add 0 people to the discussion. Proceed with caution.
Finish editing this message first!
Please register or to comment