[librsvg: 1/2] (#703): Ignore elements in an error state inside the <switch> element
- From: Federico Mena Quintero <federico src gnome org>
- To: commits-list gnome org
- Cc:
- Subject: [librsvg: 1/2] (#703): Ignore elements in an error state inside the <switch> element
- Date: Tue, 30 Mar 2021 01:46:40 +0000 (UTC)
commit 645b85f4de3ae2f8c2b5459fca6650218871261f
Author: Federico Mena Quintero <federico gnome org>
Date: Mon Mar 29 18:08:07 2021 -0600
(#703): Ignore elements in an error state inside the <switch> element
It turns out that the implementation for <switch> needs to be aware of
elements that have been set in an error state while parsing their
attributes. For example, getting an error while parsing
`systemLanguage` for an element inside a <switch> should cause *that*
element to be ignored while picking which of `<switch>`'s children to
render.
Fixes https://gitlab.gnome.org/GNOME/librsvg/-/issues/703
src/structure.rs | 9 ++++-----
tests/src/bugs.rs | 50 +++++++++++++++++++++++++++++++++++++++++++++++++-
2 files changed, 53 insertions(+), 6 deletions(-)
---
diff --git a/src/structure.rs b/src/structure.rs
index 185deba2..d783b5f5 100644
--- a/src/structure.rs
+++ b/src/structure.rs
@@ -68,11 +68,10 @@ impl Draw for Switch {
let values = cascaded.get();
draw_ctx.with_discrete_layer(node, acquired_nodes, values, clipping, &mut |an, dc| {
- if let Some(child) = node
- .children()
- .filter(|c| c.is_element())
- .find(|c| c.borrow_element().get_cond())
- {
+ if let Some(child) = node.children().filter(|c| c.is_element()).find(|c| {
+ let elt = c.borrow_element();
+ elt.get_cond() && !elt.is_in_error()
+ }) {
child.draw(an, &CascadedValues::new(cascaded, &child), dc, clipping)
} else {
Ok(dc.empty_bbox())
diff --git a/tests/src/bugs.rs b/tests/src/bugs.rs
index 320d364b..344a9503 100644
--- a/tests/src/bugs.rs
+++ b/tests/src/bugs.rs
@@ -7,7 +7,7 @@ use librsvg::{CairoRenderer, Loader, LoadingError, SvgHandle};
use matches::matches;
use crate::reference_utils::{Compare, Evaluate, Reference};
-use crate::utils::{load_svg, render_document, setup_font_map, SurfaceSize};
+use crate::utils::{load_svg, render_document, setup_font_map, setup_language, SurfaceSize};
// https://gitlab.gnome.org/GNOME/librsvg/issues/335
#[test]
@@ -354,3 +354,51 @@ fn test_text_bounds(name: &str) {
// was not being computed correctly at all.
assert!(ink_r.y > 48.0 && ink_r.y < 49.0);
}
+
+// https://gitlab.gnome.org/GNOME/librsvg/-/issues/703
+#[test]
+fn switch_element_should_ignore_elements_in_error() {
+ setup_language();
+
+ let svg = load_svg(
+ br##"<?xml version="1.0" encoding="UTF-8"?>
+<svg xmlns="http://www.w3.org/2000/svg" width="100" height="100">
+ <switch>
+ <rect x="10" y="10" width="10" height="10" systemLanguage="es_MX" id="es" fill="red"/>
+ <rect x="10" y="10" width="10" height="10" id="no_lang" fill="blue"/>
+ </switch>
+</svg>
+"##,
+ )
+ .unwrap();
+
+ let output_surf = render_document(
+ &svg,
+ SurfaceSize(100, 100),
+ |_| (),
+ cairo::Rectangle {
+ x: 0.0,
+ y: 0.0,
+ width: 100.0,
+ height: 100.0,
+ },
+ )
+ .unwrap();
+
+ let reference_surf = cairo::ImageSurface::create(cairo::Format::ARgb32, 100, 100).unwrap();
+
+ {
+ let cr = cairo::Context::new(&reference_surf);
+
+ cr.rectangle(10.0, 10.0, 10.0, 10.0);
+ cr.set_source_rgba(0.0, 0.0, 1.0, 1.0);
+ cr.fill();
+ }
+
+ Reference::from_surface(reference_surf)
+ .compare(&output_surf)
+ .evaluate(
+ &output_surf,
+ "switch_element_should_ignore_elements_in_error",
+ );
+}
[
Date Prev][
Date Next] [
Thread Prev][
Thread Next]
[
Thread Index]
[
Date Index]
[
Author Index]