[librsvg/librsvg-2.40] RsvgCairoClipRender: Implement the ::render_pango_layout() method, so we can clip text



commit 63ddae44a21405b6cb2dae9e465574d3c48c47d9
Author: Federico Mena Quintero <federico gnome org>
Date:   Fri Sep 1 09:39:30 2017 -0500

    RsvgCairoClipRender: Implement the ::render_pango_layout() method, so we can clip text
    
    With this, the test masking-path-04-b.svg passes.

 rsvg-cairo-clip.c                                  |   28 +++++++-
 .../reftests/svg1.1/masking-path-04-b-ref.png      |  Bin 88260 -> 92911 bytes
 .../fixtures/reftests/svg1.1/masking-path-04-b.svg |   79 ++++++++++++++++++++
 .../reftests/svg1.1/resources/bluesquidj.png       |  Bin 0 -> 37497 bytes
 4 files changed, 106 insertions(+), 1 deletions(-)
---
diff --git a/rsvg-cairo-clip.c b/rsvg-cairo-clip.c
index 334c9d3..909a89f 100644
--- a/rsvg-cairo-clip.c
+++ b/rsvg-cairo-clip.c
@@ -35,6 +35,7 @@
 
 #include <math.h>
 #include <string.h>
+#include <pango/pangocairo.h>
 
 typedef struct RsvgCairoClipRender RsvgCairoClipRender;
 
@@ -61,6 +62,31 @@ rsvg_cairo_clip_apply_affine (RsvgCairoClipRender *render, cairo_matrix_t *affin
 }
 
 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 = ctx->state->affine;
+    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 (RsvgDrawingCtx * ctx, const cairo_path_t *path)
 {
     RsvgCairoClipRender *render = RSVG_CAIRO_CLIP_RENDER (ctx->render);
@@ -123,7 +149,7 @@ rsvg_cairo_clip_render_new (cairo_t *cr, RsvgCairoRender *parent)
     render->type = RSVG_RENDER_TYPE_CAIRO_CLIP;
     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 = rsvg_cairo_clip_render_path;
     render->render_surface = rsvg_cairo_clip_render_surface;
     render->pop_discrete_layer = rsvg_cairo_clip_pop_discrete_layer;
diff --git a/tests/fixtures/reftests/svg1.1/masking-path-04-b-ref.png 
b/tests/fixtures/reftests/svg1.1/masking-path-04-b-ref.png
index 7a66001..5c3e1d1 100644
Binary files a/tests/fixtures/reftests/svg1.1/masking-path-04-b-ref.png and 
b/tests/fixtures/reftests/svg1.1/masking-path-04-b-ref.png differ
diff --git a/tests/fixtures/reftests/svg1.1/masking-path-04-b.svg 
b/tests/fixtures/reftests/svg1.1/masking-path-04-b.svg
new file mode 100644
index 0000000..2f5ef6f
--- /dev/null
+++ b/tests/fixtures/reftests/svg1.1/masking-path-04-b.svg
@@ -0,0 +1,79 @@
+<svg version="1.1" baseProfile="basic" id="svg-root"
+  width="100%" height="100%" viewBox="0 0 480 360"
+  xmlns="http://www.w3.org/2000/svg"; xmlns:xlink="http://www.w3.org/1999/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 http://www.w3.org/Consortium/Legal/.                          =-->
+  <!--======================================================================-->
+  <d:SVGTestCase xmlns:d="http://www.w3.org/2000/02/svg/testsuite/description/";
+    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="http://www.w3.org/1999/xhtml"; 
href="http://www.w3.org/TR/SVG11/masking.html#ClippingPaths";>
+      <p>
+        This test exercises basic user-specified clip paths, using a text
+        string (i.e., content of a 'text' element) as the clip path.
+      </p>
+      <p>
+        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.
+      </p>
+      <p>
+        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.
+      </p>
+    </d:testDescription>
+    <d:operatorScript xmlns="http://www.w3.org/1999/xhtml";>
+      <p>
+        Run the test. No interaction required.
+      </p>
+    </d:operatorScript>
+    <d:passCriteria xmlns="http://www.w3.org/1999/xhtml";>
+      <p>
+        The rendered picture should match the reference image, except for
+        possible variations in the labelling text (per CSS2 rules).
+      </p>
+    </d:passCriteria>
+  </d:SVGTestCase>
+  <title id="test-title">$RCSfile: masking-path-04-b.svg,v $</title>
+  <defs>
+    <font-face font-family="SVGFreeSansASCII" unicode-range="U+0-7F">
+      <font-face-src>
+        <font-face-uri xlink:href="../resources/SVGFreeSans.svg#ascii"/>
+      </font-face-src>
+    </font-face>
+  </defs>
+  <g id="test-body-content" font-family="SVGFreeSansASCII,sans-serif" font-size="18">
+    <g shape-rendering="geometricPrecision">
+      <defs>
+        <clipPath id="sample" clipPathUnits="userSpaceOnUse">
+          <text x="45" y="270" font-size="100" font-family="Impact">Clip Test</text>
+        </clipPath>
+      </defs>
+
+      <g>
+        <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>
+      </g>
+      <g>
+        <image xlink:href="resources/bluesquidj.png" preserveAspectRatio="none" x="20" y="170" width="410" 
height="160" clip-path="url(#sample)"/>
+      </g>
+    </g>
+  </g>
+  <g font-family="SVGFreeSansASCII,sans-serif" font-size="32">
+    <text id="revision" x="10" y="340" stroke="none" fill="black">$Revision: 1.5 $</text>
+  </g>
+  <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>
+  </g>-->
+</svg>
diff --git a/tests/fixtures/reftests/svg1.1/resources/bluesquidj.png 
b/tests/fixtures/reftests/svg1.1/resources/bluesquidj.png
new file mode 100644
index 0000000..9f5c558
Binary files /dev/null and b/tests/fixtures/reftests/svg1.1/resources/bluesquidj.png differ


[Date Prev][Date Next]   [Thread Prev][Thread Next]   [Thread Index] [Date Index] [Author Index]