diff options
author | Federico Mena Quintero <federico@gnome.org> | 2020-11-04 19:40:26 -0600 |
---|---|---|
committer | Federico Mena Quintero <federico@gnome.org> | 2020-11-04 19:55:12 -0600 |
commit | 21b8bc12e717143a9c99c785f1877ce6ac25fe3c (patch) | |
tree | 7012f826e623902dee055a808aa81c2879f500d8 | |
parent | 2ebd2ab1c9796e90d12d3c3a9cb9526488f47367 (diff) | |
download | librsvg-21b8bc12e717143a9c99c785f1877ce6ac25fe3c.tar.gz |
text: Don't create Spans for chars nodes that end up as empty strings after xml:space normalization
The new test fails without this commit; it creates inter-line spacings
in the second <text> element.
-rw-r--r-- | src/text.rs | 30 | ||||
-rw-r--r-- | tests/fixtures/reftests/bugs/642-nested-tspan-dx-dy-ref.png | bin | 0 -> 5885 bytes | |||
-rw-r--r-- | tests/fixtures/reftests/bugs/642-nested-tspan-dx-dy.svg | 17 |
3 files changed, 34 insertions, 13 deletions
diff --git a/src/text.rs b/src/text.rs index 9fc7ab7e..e94f2020 100644 --- a/src/text.rs +++ b/src/text.rs @@ -380,16 +380,20 @@ impl Chars { dx: f64, dy: f64, depth: usize, - ) -> Span { + ) -> Option<Span> { self.ensure_normalized_string(node, values); - Span::new( - self.space_normalized.borrow().as_ref().unwrap(), - values.clone(), - dx, - dy, - depth, - ) + if self.space_normalized.borrow().as_ref().unwrap() == "" { + None + } else { + Some(Span::new( + self.space_normalized.borrow().as_ref().unwrap(), + values.clone(), + dx, + dy, + depth, + )) + } } fn to_chunks( @@ -401,12 +405,12 @@ impl Chars { dy: f64, depth: usize, ) { - let span = self.make_span(&node, values, dx, dy, depth); - - let num_chunks = chunks.len(); - assert!(num_chunks > 0); + if let Some(span) = self.make_span(&node, values, dx, dy, depth) { + let num_chunks = chunks.len(); + assert!(num_chunks > 0); - chunks[num_chunks - 1].spans.push(span); + chunks[num_chunks - 1].spans.push(span); + } } pub fn get_string(&self) -> String { diff --git a/tests/fixtures/reftests/bugs/642-nested-tspan-dx-dy-ref.png b/tests/fixtures/reftests/bugs/642-nested-tspan-dx-dy-ref.png Binary files differnew file mode 100644 index 00000000..1030c425 --- /dev/null +++ b/tests/fixtures/reftests/bugs/642-nested-tspan-dx-dy-ref.png diff --git a/tests/fixtures/reftests/bugs/642-nested-tspan-dx-dy.svg b/tests/fixtures/reftests/bugs/642-nested-tspan-dx-dy.svg new file mode 100644 index 00000000..175d00c8 --- /dev/null +++ b/tests/fixtures/reftests/bugs/642-nested-tspan-dx-dy.svg @@ -0,0 +1,17 @@ +<svg width="500" height="500" xmlns="http://www.w3.org/2000/svg" version="1.1"> + <rect x="0" y="0" width="500" height="500" fill="white"/> + + <!-- with buggy #642 these will overlap --> + <text x="100" y="100" fill="black" style="font-family: sans-serif; font-size: 20px;"> + <tspan x="100" y="100" dy="0"><tspan>one</tspan></tspan> + <tspan x="100" y="100" dy="20"><tspan>two</tspan></tspan> + <tspan x="100" y="100" dy="40"><tspan>three</tspan></tspan> + </text> + + <!-- but these won't, note the whitespace inside the outermost tspans --> + <text x="100" y="200" fill="black" style="font-family: sans-serif; font-size: 20px;"> + <tspan x="100" y="200" dy="0"> <tspan>one</tspan></tspan> + <tspan x="100" y="200" dy="20"> <tspan>two</tspan></tspan> + <tspan x="100" y="200" dy="40"> <tspan>three</tspan></tspan> + </text> +</svg> |