mirror of
https://github.com/GraphiteEditor/Graphite.git
synced 2026-10-02 17:38:12 +08:00
Fix inside stroke alignment not working in the Vello renderer (#2936)
* Fix inside stroke alignment not working in vello * cargo: fmt
This commit is contained in:
@@ -305,10 +305,7 @@ impl GraphicElementRendered for GraphicGroupTable {
|
|||||||
|
|
||||||
let opacity = instance.alpha_blending.opacity(render_params.for_mask);
|
let opacity = instance.alpha_blending.opacity(render_params.for_mask);
|
||||||
if opacity < 1. || (render_params.view_mode != ViewMode::Outline && alpha_blending.blend_mode != BlendMode::default()) {
|
if opacity < 1. || (render_params.view_mode != ViewMode::Outline && alpha_blending.blend_mode != BlendMode::default()) {
|
||||||
bounds = self
|
bounds = instance.instance.bounding_box(transform, true);
|
||||||
.instance_ref_iter()
|
|
||||||
.filter_map(|element| element.instance.bounding_box(transform, true))
|
|
||||||
.reduce(Quad::combine_bounds);
|
|
||||||
|
|
||||||
if let Some(bounds) = bounds {
|
if let Some(bounds) = bounds {
|
||||||
scene.push_layer(
|
scene.push_layer(
|
||||||
@@ -331,10 +328,7 @@ impl GraphicElementRendered for GraphicGroupTable {
|
|||||||
mask_instance_state = None;
|
mask_instance_state = None;
|
||||||
}
|
}
|
||||||
if !layer {
|
if !layer {
|
||||||
bounds = self
|
bounds = instance.instance.bounding_box(transform, true);
|
||||||
.instance_ref_iter()
|
|
||||||
.filter_map(|element| element.instance.bounding_box(transform, true))
|
|
||||||
.reduce(Quad::combine_bounds);
|
|
||||||
}
|
}
|
||||||
|
|
||||||
if let Some(bounds) = bounds {
|
if let Some(bounds) = bounds {
|
||||||
@@ -565,12 +559,9 @@ impl GraphicElementRendered for VectorDataTable {
|
|||||||
let can_draw_aligned_stroke = instance.instance.style.stroke().is_some_and(|stroke| stroke.has_renderable_stroke() && stroke.align.is_not_centered())
|
let can_draw_aligned_stroke = instance.instance.style.stroke().is_some_and(|stroke| stroke.has_renderable_stroke() && stroke.align.is_not_centered())
|
||||||
&& instance.instance.stroke_bezier_paths().all(|path| path.closed());
|
&& instance.instance.stroke_bezier_paths().all(|path| path.closed());
|
||||||
|
|
||||||
let reorder_for_outside = instance
|
let reorder_for_outside = instance.instance.style.stroke().is_some_and(|stroke| stroke.align == StrokeAlign::Outside) && !instance.instance.style.fill().is_none();
|
||||||
.instance
|
let use_layer = can_draw_aligned_stroke && !reorder_for_outside;
|
||||||
.style
|
if use_layer {
|
||||||
.stroke()
|
|
||||||
.is_some_and(|stroke| stroke.align == StrokeAlign::Outside && !instance.instance.style.fill().is_none());
|
|
||||||
if can_draw_aligned_stroke && !reorder_for_outside {
|
|
||||||
let mut fill_instance = instance.instance.clone();
|
let mut fill_instance = instance.instance.clone();
|
||||||
fill_instance.style.clear_stroke();
|
fill_instance.style.clear_stroke();
|
||||||
fill_instance.style.set_fill(Fill::solid(Color::BLACK));
|
fill_instance.style.set_fill(Fill::solid(Color::BLACK));
|
||||||
@@ -582,15 +573,15 @@ impl GraphicElementRendered for VectorDataTable {
|
|||||||
source_node_id: None,
|
source_node_id: None,
|
||||||
});
|
});
|
||||||
|
|
||||||
|
let bounds = instance.instance.bounding_box_with_transform(multiplied_transform).unwrap_or(layer_bounds);
|
||||||
let weight = instance.instance.style.stroke().unwrap().weight;
|
let weight = instance.instance.style.stroke().unwrap().weight;
|
||||||
let quad = Quad::from_box(layer_bounds).inflate(weight * element_transform.matrix2.determinant());
|
let quad = Quad::from_box(bounds).inflate(weight * element_transform.matrix2.determinant());
|
||||||
let rect = kurbo::Rect::new(quad.top_left().x, quad.top_left().y, quad.bottom_right().x, quad.bottom_right().y);
|
let bounds = quad.bounding_box();
|
||||||
|
let rect = kurbo::Rect::new(bounds[0].x, bounds[0].y, bounds[1].x, bounds[1].y);
|
||||||
|
|
||||||
let inside = instance.instance.style.stroke().unwrap().align == StrokeAlign::Inside;
|
|
||||||
let compose = if inside { peniko::Compose::SrcIn } else { peniko::Compose::SrcOut };
|
|
||||||
scene.push_layer(peniko::Mix::Normal, 1., kurbo::Affine::IDENTITY, &rect);
|
scene.push_layer(peniko::Mix::Normal, 1., kurbo::Affine::IDENTITY, &rect);
|
||||||
vector_data.render_to_vello(scene, parent_transform, _context, &render_params.for_alignment(applied_stroke_transform));
|
vector_data.render_to_vello(scene, parent_transform, _context, &render_params.for_alignment(applied_stroke_transform));
|
||||||
scene.push_layer(peniko::BlendMode::new(peniko::Mix::Clip, compose), 1., kurbo::Affine::IDENTITY, &rect);
|
scene.push_layer(peniko::BlendMode::new(peniko::Mix::Clip, peniko::Compose::SrcIn), 1., kurbo::Affine::IDENTITY, &rect);
|
||||||
}
|
}
|
||||||
|
|
||||||
// Render the path
|
// Render the path
|
||||||
@@ -624,6 +615,7 @@ impl GraphicElementRendered for VectorDataTable {
|
|||||||
true => [Op::Stroke, Op::Fill],
|
true => [Op::Stroke, Op::Fill],
|
||||||
false => [Op::Fill, Op::Stroke], // Default
|
false => [Op::Fill, Op::Stroke], // Default
|
||||||
};
|
};
|
||||||
|
|
||||||
for operation in order {
|
for operation in order {
|
||||||
match operation {
|
match operation {
|
||||||
Op::Fill => {
|
Op::Fill => {
|
||||||
@@ -723,7 +715,7 @@ impl GraphicElementRendered for VectorDataTable {
|
|||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|
||||||
if can_draw_aligned_stroke {
|
if use_layer {
|
||||||
scene.pop_layer();
|
scene.pop_layer();
|
||||||
scene.pop_layer();
|
scene.pop_layer();
|
||||||
}
|
}
|
||||||
|
|||||||
Reference in New Issue
Block a user