[librsvg/librsvg-2.52: 4/19] Add a test for the bounds of a text element




commit b88c4c460f479fa14d5e03616fbf48af327736c7
Author: Federico Mena Quintero <federico gnome org>
Date:   Tue Feb 1 20:43:55 2022 -0600

    Add a test for the bounds of a text element
    
    Part-of: <https://gitlab.gnome.org/GNOME/librsvg/-/merge_requests/660>

 tests/fixtures/text/bounds-ref.svg | 20 ++++++++++++++++
 tests/fixtures/text/bounds.svg     | 48 ++++++++++++++++++++++++++++++++++++++
 tests/src/text.rs                  |  6 +++++
 3 files changed, 74 insertions(+)
---
diff --git a/tests/fixtures/text/bounds-ref.svg b/tests/fixtures/text/bounds-ref.svg
new file mode 100644
index 000000000..a5555abed
--- /dev/null
+++ b/tests/fixtures/text/bounds-ref.svg
@@ -0,0 +1,20 @@
+<?xml version="1.0" encoding="utf-8"?>
+<svg xmlns="http://www.w3.org/2000/svg"; width="600" height="600">
+  <rect x="0" y="0" width="100%" height="100%" fill="white"/>
+
+  <!-- The transform is to move the squares a bit down, so they match the Ahem font's glyph extents -->
+
+  <g transform="translate(0, 10)">
+    <rect x="50" y="50" width="50" height="50" fill="lime"/>
+    <rect x="100" y="50" width="50" height="50" fill="blue"/>
+
+    <rect x="200" y="50" width="50" height="50" fill="lime"/>
+    <rect x="200" y="100" width="50" height="50" fill="blue"/>
+
+    <rect x="300" y="50" width="50" height="50" fill="lime"/>
+    <rect x="300" y="100" width="50" height="50" fill="blue"/>
+
+    <rect x="400" y="50" width="50" height="50" fill="lime"/>
+    <rect x="450" y="50" width="50" height="50" fill="blue"/>
+  </g>
+</svg>
diff --git a/tests/fixtures/text/bounds.svg b/tests/fixtures/text/bounds.svg
new file mode 100644
index 000000000..d21b79605
--- /dev/null
+++ b/tests/fixtures/text/bounds.svg
@@ -0,0 +1,48 @@
+<?xml version="1.0" encoding="utf-8"?>
+<svg xmlns="http://www.w3.org/2000/svg"; width="600" height="600">
+  <defs>
+    <linearGradient id="horizontal" gradientUnits="objectBoundingBox" x1="0" y1="0" x2="1" y2="0">
+      <stop stop-color="lime" offset="0.0"/>
+      <stop stop-color="lime" offset="0.5"/>
+      <stop stop-color="blue" offset="0.5"/>
+      <stop stop-color="blue" offset="1.0"/>
+    </linearGradient>
+
+    <linearGradient id="vertical" gradientUnits="objectBoundingBox" x1="0" y1="0" x2="0" y2="1">
+      <stop stop-color="lime" offset="0.0"/>
+      <stop stop-color="lime" offset="0.5"/>
+      <stop stop-color="blue" offset="0.5"/>
+      <stop stop-color="blue" offset="1.0"/>
+    </linearGradient>
+  </defs>
+
+  <rect x="0" y="0" width="100%" height="100%" fill="white"/>
+
+  <style type="text/css">
+    text {
+      font: 50px Ahem;
+    }
+  </style>
+
+  <!-- Test that the bounding box of <text> is correct by creating groups of two squares,
+       one green and one blue.  The gradients use objectBoundingBox, so they fill both
+       squares at the same time.
+
+       The first test is horizontal, to test the horizontal bounds.
+
+       The second test is vertical, to test the vertical bounds.
+  -->
+
+  <text x="50" y="100" fill="url(#horizontal)" stroke-width="2">XX</text>
+  <text x="0" y="-10" fill="url(#horizontal)" transform="translate(200, 60) rotate(90)">XX</text>
+
+  <text fill="url(#vertical)">
+    <tspan x="300" y="100">X</tspan>
+    <tspan x="300" y="150">X</tspan>
+  </text>
+
+  <text fill="url(#vertical)" transform="translate(490, 110) rotate(-90)">
+    <tspan x="0" y="-50">X</tspan>
+    <tspan x="0" y="0">X</tspan>
+  </text>
+</svg>
diff --git a/tests/src/text.rs b/tests/src/text.rs
index 4596cf716..f73f23926 100644
--- a/tests/src/text.rs
+++ b/tests/src/text.rs
@@ -69,3 +69,9 @@ test_svg_reference!(
     "tests/fixtures/text/visibility-hidden-x-attr.svg",
     "tests/fixtures/text/visibility-hidden-ref.svg"
 );
+
+test_svg_reference!(
+    bounds,
+    "tests/fixtures/text/bounds.svg",
+    "tests/fixtures/text/bounds-ref.svg"
+);


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