(#497): Don't panic on paths with all-invalid commands

The path parser creates a PathBuilder with zero commands.

In turn, builder.to_cairo() does nothing, as expected.

But then we stroke_and_fill(), and the wrapper call to
with_discrete_layer() doesn't like not having bounds.

Fixes https://gitlab.gnome.org/GNOME/librsvg/issues/497
parent 6475ffbd
Pipeline #106940 failed with stages
in 8 minutes and 35 seconds
......@@ -356,6 +356,8 @@ impl PathBuilder {
}
pub fn to_cairo(&self, cr: &cairo::Context) -> Result<(), cairo::Status> {
assert!(!self.empty());
for s in &self.path_commands {
s.to_cairo(cr);
}
......@@ -376,6 +378,10 @@ impl PathBuilder {
Err(status)
}
}
pub fn empty(&self) -> bool {
self.path_commands.len() == 0
}
}
#[cfg(test)]
......
......@@ -22,23 +22,25 @@ fn render_path_builder(
render_markers: bool,
clipping: bool,
) -> Result<(), RenderingError> {
draw_ctx.with_discrete_layer(node, values, clipping, &mut |dc| {
let cr = dc.get_cairo_context();
if !builder.empty() {
draw_ctx.with_discrete_layer(node, values, clipping, &mut |dc| {
let cr = dc.get_cairo_context();
builder.to_cairo(&cr)?;
builder.to_cairo(&cr)?;
if clipping {
cr.set_fill_rule(cairo::FillRule::from(values.clip_rule));
} else {
cr.set_fill_rule(cairo::FillRule::from(values.fill_rule));
dc.stroke_and_fill(&cr, values)?;
}
if clipping {
cr.set_fill_rule(cairo::FillRule::from(values.clip_rule));
} else {
cr.set_fill_rule(cairo::FillRule::from(values.fill_rule));
dc.stroke_and_fill(&cr, values)?;
}
Ok(())
})?;
Ok(())
})?;
if render_markers {
marker::render_markers_for_path_builder(builder, draw_ctx, values, clipping)?;
if render_markers {
marker::render_markers_for_path_builder(builder, draw_ctx, values, clipping)?;
}
}
Ok(())
......
<?xml version="1.0" encoding="UTF-8"?>
<svg xmlns="hg" width="100" height="100">
<defs>
<clipPath id="one" clipPathUnits="objectBoundingBox">
<path d="M 0P5 0.0 L 1.0 0.5 L 0.5 1.0 L 0.0 0.5 Z"/>
</clipPath>
</defs>
<g clip-path="url(#one)">
<path d="M 0P5 " wiGth="40" height="40" fill="blue"/>
<rect x="50" y="50" width="40" heiKht="40" fill="#00ff00"/>
</g>
</svg>
Markdown is supported
0% or
You are about to add 0 people to the discussion. Proceed with caution.
Finish editing this message first!
Please register or to comment