Skip to content

Commit e6f1ad9

Browse files
authored
Fix inside stroke alignment not working in the Vello renderer (#2936)
* Fix inside stroke alignment not working in vello * cargo: fmt
1 parent 72f1047 commit e6f1ad9

File tree

1 file changed

+12
-20
lines changed

1 file changed

+12
-20
lines changed

node-graph/gsvg-renderer/src/renderer.rs

Lines changed: 12 additions & 20 deletions
Original file line numberDiff line numberDiff line change
@@ -305,10 +305,7 @@ impl GraphicElementRendered for GraphicGroupTable {
305305

306306
let opacity = instance.alpha_blending.opacity(render_params.for_mask);
307307
if opacity < 1. || (render_params.view_mode != ViewMode::Outline && alpha_blending.blend_mode != BlendMode::default()) {
308-
bounds = self
309-
.instance_ref_iter()
310-
.filter_map(|element| element.instance.bounding_box(transform, true))
311-
.reduce(Quad::combine_bounds);
308+
bounds = instance.instance.bounding_box(transform, true);
312309

313310
if let Some(bounds) = bounds {
314311
scene.push_layer(
@@ -331,10 +328,7 @@ impl GraphicElementRendered for GraphicGroupTable {
331328
mask_instance_state = None;
332329
}
333330
if !layer {
334-
bounds = self
335-
.instance_ref_iter()
336-
.filter_map(|element| element.instance.bounding_box(transform, true))
337-
.reduce(Quad::combine_bounds);
331+
bounds = instance.instance.bounding_box(transform, true);
338332
}
339333

340334
if let Some(bounds) = bounds {
@@ -565,12 +559,9 @@ impl GraphicElementRendered for VectorDataTable {
565559
let can_draw_aligned_stroke = instance.instance.style.stroke().is_some_and(|stroke| stroke.has_renderable_stroke() && stroke.align.is_not_centered())
566560
&& instance.instance.stroke_bezier_paths().all(|path| path.closed());
567561

568-
let reorder_for_outside = instance
569-
.instance
570-
.style
571-
.stroke()
572-
.is_some_and(|stroke| stroke.align == StrokeAlign::Outside && !instance.instance.style.fill().is_none());
573-
if can_draw_aligned_stroke && !reorder_for_outside {
562+
let reorder_for_outside = instance.instance.style.stroke().is_some_and(|stroke| stroke.align == StrokeAlign::Outside) && !instance.instance.style.fill().is_none();
563+
let use_layer = can_draw_aligned_stroke && !reorder_for_outside;
564+
if use_layer {
574565
let mut fill_instance = instance.instance.clone();
575566
fill_instance.style.clear_stroke();
576567
fill_instance.style.set_fill(Fill::solid(Color::BLACK));
@@ -582,15 +573,15 @@ impl GraphicElementRendered for VectorDataTable {
582573
source_node_id: None,
583574
});
584575

576+
let bounds = instance.instance.bounding_box_with_transform(multiplied_transform).unwrap_or(layer_bounds);
585577
let weight = instance.instance.style.stroke().unwrap().weight;
586-
let quad = Quad::from_box(layer_bounds).inflate(weight * element_transform.matrix2.determinant());
587-
let rect = kurbo::Rect::new(quad.top_left().x, quad.top_left().y, quad.bottom_right().x, quad.bottom_right().y);
578+
let quad = Quad::from_box(bounds).inflate(weight * element_transform.matrix2.determinant());
579+
let bounds = quad.bounding_box();
580+
let rect = kurbo::Rect::new(bounds[0].x, bounds[0].y, bounds[1].x, bounds[1].y);
588581

589-
let inside = instance.instance.style.stroke().unwrap().align == StrokeAlign::Inside;
590-
let compose = if inside { peniko::Compose::SrcIn } else { peniko::Compose::SrcOut };
591582
scene.push_layer(peniko::Mix::Normal, 1., kurbo::Affine::IDENTITY, &rect);
592583
vector_data.render_to_vello(scene, parent_transform, _context, &render_params.for_alignment(applied_stroke_transform));
593-
scene.push_layer(peniko::BlendMode::new(peniko::Mix::Clip, compose), 1., kurbo::Affine::IDENTITY, &rect);
584+
scene.push_layer(peniko::BlendMode::new(peniko::Mix::Clip, peniko::Compose::SrcIn), 1., kurbo::Affine::IDENTITY, &rect);
594585
}
595586

596587
// Render the path
@@ -624,6 +615,7 @@ impl GraphicElementRendered for VectorDataTable {
624615
true => [Op::Stroke, Op::Fill],
625616
false => [Op::Fill, Op::Stroke], // Default
626617
};
618+
627619
for operation in order {
628620
match operation {
629621
Op::Fill => {
@@ -723,7 +715,7 @@ impl GraphicElementRendered for VectorDataTable {
723715
}
724716
}
725717

726-
if can_draw_aligned_stroke {
718+
if use_layer {
727719
scene.pop_layer();
728720
scene.pop_layer();
729721
}

0 commit comments

Comments
 (0)