[librsvg: 33/37] Add text-tref-02-b.svg; make all nodes accept NodeChars children



commit 1528ed9e6d84b008fa082fb7d7829a2667672ca0
Author: Federico Mena Quintero <federico gnome org>
Date:   Tue Dec 11 18:48:19 2018 -0600

    Add text-tref-02-b.svg; make all nodes accept NodeChars children
    
    That test indicates that random nodes like literally
    
      <foo xmlns="http://example.org/foo";>
        <bar id="world">World</bar>
      </foo>
    
    are usable as a tref's referenced node.
    
    This also means that we need to change NodeSwitch to ignore NodeChars
    when trying to find the first child whose conditional processing
    attribute resolved to true.

 rsvg_internals/src/node.rs                         |  16 +----
 rsvg_internals/src/structure.rs                    |   6 +-
 rsvg_internals/src/style.rs                        |   4 --
 rsvg_internals/src/text.rs                         |   8 ---
 rsvg_internals/src/xml.rs                          |   2 +-
 .../reftests/svg1.1/text-tref-02-b-ref.png         | Bin 0 -> 8675 bytes
 tests/fixtures/reftests/svg1.1/text-tref-02-b.svg  |  79 +++++++++++++++++++++
 7 files changed, 86 insertions(+), 29 deletions(-)
---
diff --git a/rsvg_internals/src/node.rs b/rsvg_internals/src/node.rs
index 4b15b286..44e18d2e 100644
--- a/rsvg_internals/src/node.rs
+++ b/rsvg_internals/src/node.rs
@@ -109,10 +109,6 @@ pub trait NodeTrait: Downcast {
     /// from defaults in the node's `State`.
     fn set_overridden_properties(&self, _state: &mut State) {}
 
-    fn accept_chars(&self) -> bool {
-        false
-    }
-
     fn draw(
         &self,
         _node: &RsvgNode,
@@ -626,10 +622,6 @@ impl Node {
         state.values.overflow = SpecifiedValue::Specified(Overflow::Hidden);
     }
 
-    pub fn accept_chars(&self) -> bool {
-        self.data.node_impl.accept_chars()
-    }
-
     // find the last Chars node so that we can coalesce
     // the text and avoid screwing up the Pango layouts
     pub fn find_last_chars_child(&self) -> Option<Rc<Node>> {
@@ -637,13 +629,7 @@ impl Node {
             match child.get_type() {
                 NodeType::Chars => return Some(child),
 
-                // If a node that accepts chars is encountered before
-                // any chars node (which means for instance that there
-                // is a tspan node after any chars nodes, because this
-                // is backwards iteration), return None.
-                _ if child.accept_chars() => return None,
-
-                _ => {}
+                _ => return None,
             }
         }
 
diff --git a/rsvg_internals/src/structure.rs b/rsvg_internals/src/structure.rs
index 7aaf123f..e3c59e6b 100644
--- a/rsvg_internals/src/structure.rs
+++ b/rsvg_internals/src/structure.rs
@@ -86,7 +86,11 @@ impl NodeTrait for NodeSwitch {
         let values = cascaded.get();
 
         draw_ctx.with_discrete_layer(node, values, clipping, &mut |dc| {
-            if let Some(child) = node.children().find(|c| c.get_cond()) {
+            if let Some(child) = node
+                .children()
+                .filter(|c| c.get_type() != NodeType::Chars)
+                .find(|c| c.get_cond())
+            {
                 dc.draw_node_from_stack(&CascadedValues::new(cascaded, &child), &child, clipping)
             } else {
                 Ok(())
diff --git a/rsvg_internals/src/style.rs b/rsvg_internals/src/style.rs
index 55b93fc8..8363d77c 100644
--- a/rsvg_internals/src/style.rs
+++ b/rsvg_internals/src/style.rs
@@ -65,8 +65,4 @@ impl NodeTrait for NodeStyle {
 
         Ok(())
     }
-
-    fn accept_chars(&self) -> bool {
-        true
-    }
 }
diff --git a/rsvg_internals/src/text.rs b/rsvg_internals/src/text.rs
index 1322246c..617182c9 100644
--- a/rsvg_internals/src/text.rs
+++ b/rsvg_internals/src/text.rs
@@ -488,10 +488,6 @@ impl NodeTrait for NodeText {
         Ok(())
     }
 
-    fn accept_chars(&self) -> bool {
-        true
-    }
-
     fn draw(
         &self,
         node: &RsvgNode,
@@ -677,10 +673,6 @@ impl NodeTrait for NodeTSpan {
 
         Ok(())
     }
-
-    fn accept_chars(&self) -> bool {
-        true
-    }
 }
 
 fn to_pango_units(v: f64) -> i32 {
diff --git a/rsvg_internals/src/xml.rs b/rsvg_internals/src/xml.rs
index 1eeb8c82..283919d4 100644
--- a/rsvg_internals/src/xml.rs
+++ b/rsvg_internals/src/xml.rs
@@ -317,7 +317,7 @@ impl XmlState {
     fn element_creation_characters(&self, text: &str) {
         let node = self.current_node.as_ref().unwrap();
 
-        if text.len() != 0 && node.accept_chars() {
+        if text.len() != 0 {
             let chars_node = if let Some(child) = node.find_last_chars_child() {
                 child
             } else {
diff --git a/tests/fixtures/reftests/svg1.1/text-tref-02-b-ref.png 
b/tests/fixtures/reftests/svg1.1/text-tref-02-b-ref.png
new file mode 100644
index 00000000..7a7599c0
Binary files /dev/null and b/tests/fixtures/reftests/svg1.1/text-tref-02-b-ref.png differ
diff --git a/tests/fixtures/reftests/svg1.1/text-tref-02-b.svg 
b/tests/fixtures/reftests/svg1.1/text-tref-02-b.svg
new file mode 100644
index 00000000..7773c95e
--- /dev/null
+++ b/tests/fixtures/reftests/svg1.1/text-tref-02-b.svg
@@ -0,0 +1,79 @@
+<!DOCTYPE svg [
+<!ATTLIST bar id ID #REQUIRED>
+]>
+<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="ED" author="CL" status="accepted"
+    version="$Revision: 1.5 $" testname="$RCSfile: text-tref-02-b.svg,v $">
+    <d:testDescription xmlns="http://www.w3.org/1999/xhtml"; 
href="http://www.w3.org/TR/SVG11/text.html#TRefElement";>
+        <p>
+          Test viewer capability to handle  'tref' elements
+          which point to text strings outside the current SVG document fragment.
+        </p>
+        <p>
+          The test case consists of two sub-tests; one results in the word "Hello" and the second, the word 
"World".
+        </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 test is passed if the phrase "Hello World" is displayed, in green.
+      </p>
+    </d:passCriteria>
+  </d:SVGTestCase>
+  <title id="test-title">$RCSfile: text-tref-02-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">
+    <!-- Test case label -->
+    <text x="75" y="25" font-family="SVGFreeSansASCII,sans-serif" font-size="12" fill="blue">Test 'tref' 
element pointing outside the SVG document fragment.</text>
+
+    <text x="75" y="200" font-size="36" font-family="SVGFreeSansASCII,sans-serif" fill="green">
+      <tref xlink:href="#hello"/>
+     <tref xlink:href="#world"/>
+    </text>
+<!-- now make a new SVG document fragment, and hide it from being rendered -->
+<defs>
+  <foreignObject>
+    <svg>
+       <text id="hello">Hello</text>
+    </svg>
+  </foreignObject>
+</defs>
+<!-- and another way to make a separate document fragment -->
+<foo xmlns="http://example.org/foo";>
+  <bar id="world">World</bar>
+</foo>
+
+  </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>


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