Set the cairo path only once when filling/stroking are sequential
With !360 (closed) librsvg supports the paint-order
property from SVG2. However, the new code in DrawingCtx.draw_path
looks like this
cr.set_fill_rule(cairo::FillRule::from(values.fill_rule()));
path.to_cairo(&cr, is_square_linecap)?;
let bbox = compute_stroke_and_fill_box(&cr, &values);
cr.new_path();
for &target in &values.paint_order().targets {
match target {
PaintTarget::Fill if !clipping => {
path.to_cairo(&cr, is_square_linecap)?;
dc.fill(&cr, an, values, &bbox, current_color)?;
cr.new_path();
}
PaintTarget::Stroke if !clipping => {
path.to_cairo(&cr, is_square_linecap)?;
dc.stroke(&cr, an, values, &bbox, current_color)?;
cr.new_path();
}
PaintTarget::Markers if markers == Markers::Yes => {
marker::render_markers_for_path(path, dc, an, values, clipping)?;
}
_ => {}
}
}
That is, with the cr.new_path()
it resets the path between each iteration, as leaving it around could cause trouble in case the paint-order is something like fill markers stroke
- the markers don't want to have a current path present.
It should be possible to devise a strategy to set the cairo path as few times as possible. To note:
- markers don't need the bbox.
- there is
cr.stroke_preserve()
andcr.fill_preserve()
which can be used to avoid consuming the current path.