@@ -332,7 +332,6 @@ impl GraphicElementRendered for GraphicGroupTable {
332
332
333
333
let mut layer = false ;
334
334
if let Some ( bounds) = self . instances ( ) . filter_map ( |element| element. instance . bounding_box ( transform) ) . reduce ( Quad :: combine_bounds) {
335
- // Always respect opacity, but use different blend modes based on view mode
336
335
let blend_mode = match render_params. view_mode {
337
336
ViewMode :: Outline => peniko:: Mix :: Normal ,
338
337
_ => alpha_blending. blend_mode . into ( ) ,
@@ -466,12 +465,11 @@ impl GraphicElementRendered for VectorDataTable {
466
465
467
466
#[ cfg( feature = "vello" ) ]
468
467
fn render_to_vello ( & self , scene : & mut Scene , parent_transform : DAffine2 , _: & mut RenderContext , render_params : & RenderParams ) {
469
- use crate :: vector:: style:: GradientType ;
468
+ use crate :: vector:: style:: { GradientType , LineCap , LineJoin } ;
469
+ use vello:: kurbo:: { Cap , Join } ;
470
470
use vello:: peniko;
471
471
472
472
for instance in self . instances ( ) {
473
- let mut layer = false ;
474
-
475
473
let multiplied_transform = parent_transform * * instance. transform ;
476
474
let has_real_stroke = instance. instance . style . stroke ( ) . filter ( |stroke| stroke. weight ( ) > 0. ) ;
477
475
let set_stroke_transform = has_real_stroke. map ( |stroke| stroke. transform ) . filter ( |transform| transform. matrix2 . determinant ( ) != 0. ) ;
@@ -485,25 +483,33 @@ impl GraphicElementRendered for VectorDataTable {
485
483
for subpath in instance. instance . stroke_bezier_paths ( ) {
486
484
subpath. to_vello_path ( applied_stroke_transform, & mut path) ;
487
485
}
486
+
487
+ // If we're using opacity or a blend mode, we need to push a layer
488
+ let blend_mode = match render_params. view_mode {
489
+ ViewMode :: Outline => peniko:: Mix :: Normal ,
490
+ _ => instance. alpha_blending . blend_mode . into ( ) ,
491
+ } ;
492
+ let mut layer = false ;
493
+ if instance. alpha_blending . opacity < 1. || instance. alpha_blending . blend_mode != BlendMode :: default ( ) {
494
+ layer = true ;
495
+ scene. push_layer (
496
+ peniko:: BlendMode :: new ( blend_mode, peniko:: Compose :: SrcOver ) ,
497
+ instance. alpha_blending . opacity ,
498
+ kurbo:: Affine :: new ( multiplied_transform. to_cols_array ( ) ) ,
499
+ & kurbo:: Rect :: new ( layer_bounds[ 0 ] . x , layer_bounds[ 0 ] . y , layer_bounds[ 1 ] . x , layer_bounds[ 1 ] . y ) ,
500
+ ) ;
501
+ }
502
+
503
+ // Render the path
488
504
match render_params. view_mode {
489
505
ViewMode :: Outline => {
490
- if instance. alpha_blending . opacity < 1. {
491
- layer = true ;
492
- scene. push_layer (
493
- peniko:: BlendMode :: new ( peniko:: Mix :: Normal , peniko:: Compose :: SrcOver ) ,
494
- instance. alpha_blending . opacity ,
495
- kurbo:: Affine :: new ( multiplied_transform. to_cols_array ( ) ) ,
496
- & kurbo:: Rect :: new ( layer_bounds[ 0 ] . x , layer_bounds[ 0 ] . y , layer_bounds[ 1 ] . x , layer_bounds[ 1 ] . y ) ,
497
- ) ;
498
- }
499
-
500
506
let outline_stroke = kurbo:: Stroke {
501
507
width : LAYER_OUTLINE_STROKE_WEIGHT ,
502
- miter_limit : 4.0 ,
508
+ miter_limit : 4. ,
503
509
join : kurbo:: Join :: Miter ,
504
510
start_cap : kurbo:: Cap :: Butt ,
505
511
end_cap : kurbo:: Cap :: Butt ,
506
- dash_pattern : vec ! [ ] . into ( ) ,
512
+ dash_pattern : Default :: default ( ) ,
507
513
dash_offset : 0. ,
508
514
} ;
509
515
let outline_color = peniko:: Color :: new ( [
@@ -516,15 +522,6 @@ impl GraphicElementRendered for VectorDataTable {
516
522
scene. stroke ( & outline_stroke, kurbo:: Affine :: new ( element_transform. to_cols_array ( ) ) , outline_color, None , & path) ;
517
523
}
518
524
_ => {
519
- if instance. alpha_blending . opacity < 1. || instance. alpha_blending . blend_mode != BlendMode :: default ( ) {
520
- layer = true ;
521
- scene. push_layer (
522
- peniko:: BlendMode :: new ( instance. alpha_blending . blend_mode . into ( ) , peniko:: Compose :: SrcOver ) ,
523
- instance. alpha_blending . opacity ,
524
- kurbo:: Affine :: new ( multiplied_transform. to_cols_array ( ) ) ,
525
- & kurbo:: Rect :: new ( layer_bounds[ 0 ] . x , layer_bounds[ 0 ] . y , layer_bounds[ 1 ] . x , layer_bounds[ 1 ] . y ) ,
526
- ) ;
527
- }
528
525
match instance. instance . style . fill ( ) {
529
526
Fill :: Solid ( color) => {
530
527
let fill = peniko:: Brush :: Solid ( peniko:: Color :: new ( [ color. r ( ) , color. g ( ) , color. b ( ) , color. a ( ) ] ) ) ;
@@ -573,16 +570,14 @@ impl GraphicElementRendered for VectorDataTable {
573
570
let brush_transform = kurbo:: Affine :: new ( ( inverse_element_transform * parent_transform) . to_cols_array ( ) ) ;
574
571
scene. fill ( peniko:: Fill :: NonZero , kurbo:: Affine :: new ( element_transform. to_cols_array ( ) ) , & fill, Some ( brush_transform) , & path) ;
575
572
}
576
- Fill :: None => ( ) ,
573
+ Fill :: None => { }
577
574
} ;
578
575
579
576
if let Some ( stroke) = instance. instance . style . stroke ( ) {
580
577
let color = match stroke. color {
581
578
Some ( color) => peniko:: Color :: new ( [ color. r ( ) , color. g ( ) , color. b ( ) , color. a ( ) ] ) ,
582
579
None => peniko:: Color :: TRANSPARENT ,
583
580
} ;
584
- use crate :: vector:: style:: { LineCap , LineJoin } ;
585
- use vello:: kurbo:: { Cap , Join } ;
586
581
let cap = match stroke. line_cap {
587
582
LineCap :: Butt => Cap :: Butt ,
588
583
LineCap :: Round => Cap :: Round ,
@@ -602,12 +597,16 @@ impl GraphicElementRendered for VectorDataTable {
602
597
dash_pattern : stroke. dash_lengths . into ( ) ,
603
598
dash_offset : stroke. dash_offset ,
604
599
} ;
600
+
601
+ // Draw the stroke if it's visible
605
602
if stroke. width > 0. {
606
603
scene. stroke ( & stroke, kurbo:: Affine :: new ( element_transform. to_cols_array ( ) ) , color, None , & path) ;
607
604
}
608
605
}
609
606
}
610
607
}
608
+
609
+ // If we pushed a layer for opacity or a blend mode, we need to pop it
611
610
if layer {
612
611
scene. pop_layer ( ) ;
613
612
}
0 commit comments