@@ -22,6 +22,7 @@ use graphic_types::vector_types::vector::click_target::{ClickTarget, FreePoint};
2222use graphic_types:: vector_types:: vector:: style:: { Fill , PaintOrder , RenderMode , Stroke , StrokeAlign } ;
2323use graphic_types:: { Artboard , Graphic } ;
2424use kurbo:: Affine ;
25+ use kurbo:: Shape ;
2526use num_traits:: Zero ;
2627use std:: collections:: { HashMap , HashSet } ;
2728use std:: fmt:: Write ;
@@ -729,10 +730,10 @@ impl Render for Table<Vector> {
729730 let can_draw_aligned_stroke = path_is_closed && vector. style . stroke ( ) . is_some_and ( |stroke| stroke. has_renderable_stroke ( ) && stroke. align . is_not_centered ( ) ) ;
730731 let can_use_paint_order = !( row. element . style . fill ( ) . is_none ( ) || !row. element . style . fill ( ) . is_opaque ( ) || mask_type == MaskType :: Clip ) ;
731732
732- let needs_separate_fill = can_draw_aligned_stroke && !can_use_paint_order;
733+ let needs_separate_alignment_fill = can_draw_aligned_stroke && !can_use_paint_order;
733734 let wants_stroke_below = vector. style . stroke ( ) . map ( |s| s. paint_order ) == Some ( PaintOrder :: StrokeBelow ) ;
734735
735- if needs_separate_fill && !wants_stroke_below {
736+ if needs_separate_alignment_fill && !wants_stroke_below {
736737 render. leaf_tag ( "path" , |attributes| {
737738 attributes. push ( "d" , path. clone ( ) ) ;
738739 let matrix = format_transform_matrix ( element_transform) ;
@@ -753,7 +754,7 @@ impl Render for Table<Vector> {
753754 } ) ;
754755 }
755756
756- let push_id = needs_separate_fill . then_some ( {
757+ let push_id = needs_separate_alignment_fill . then_some ( {
757758 let id = format ! ( "alignment-{}" , generate_uuid( ) ) ;
758759
759760 let mut element = row. element . clone ( ) ;
@@ -770,6 +771,32 @@ impl Render for Table<Vector> {
770771 ( id, mask_type, vector_row)
771772 } ) ;
772773
774+ if vector. is_branching ( ) {
775+ for mut face_path in vector. construct_faces ( ) . filter ( |face| !( face. area ( ) < 0.0 ) ) {
776+ face_path. apply_affine ( Affine :: new ( applied_stroke_transform. to_cols_array ( ) ) ) ;
777+
778+ let face_d = face_path. to_svg ( ) ;
779+ render. leaf_tag ( "path" , |attributes| {
780+ attributes. push ( "d" , face_d. clone ( ) ) ;
781+ let matrix = format_transform_matrix ( element_transform) ;
782+ if !matrix. is_empty ( ) {
783+ attributes. push ( "transform" , matrix) ;
784+ }
785+ let mut style = row. element . style . clone ( ) ;
786+ style. clear_stroke ( ) ;
787+ let fill_only = style. render (
788+ & mut attributes. 0 . svg_defs ,
789+ element_transform,
790+ applied_stroke_transform,
791+ bounds_matrix,
792+ transformed_bounds_matrix,
793+ render_params,
794+ ) ;
795+ attributes. push_val ( fill_only) ;
796+ } ) ;
797+ }
798+ }
799+
773800 render. leaf_tag ( "path" , |attributes| {
774801 attributes. push ( "d" , path. clone ( ) ) ;
775802 let matrix = format_transform_matrix ( element_transform) ;
@@ -807,7 +834,7 @@ impl Render for Table<Vector> {
807834 render_params. override_paint_order = can_draw_aligned_stroke && can_use_paint_order;
808835
809836 let mut style = row. element . style . clone ( ) ;
810- if needs_separate_fill {
837+ if needs_separate_alignment_fill || vector . is_branching ( ) {
811838 style. clear_fill ( ) ;
812839 }
813840
@@ -830,7 +857,7 @@ impl Render for Table<Vector> {
830857 } ) ;
831858
832859 // When splitting passes and stroke is below, draw the fill after the stroke.
833- if needs_separate_fill && wants_stroke_below {
860+ if needs_separate_alignment_fill && wants_stroke_below {
834861 render. leaf_tag ( "path" , |attributes| {
835862 attributes. push ( "d" , path) ;
836863 let matrix = format_transform_matrix ( element_transform) ;
@@ -916,10 +943,10 @@ impl Render for Table<Vector> {
916943 let wants_stroke_below = row. element . style . stroke ( ) . is_some_and ( |s| s. paint_order == vector:: style:: PaintOrder :: StrokeBelow ) ;
917944
918945 // Closures to avoid duplicated fill/stroke drawing logic
919- let do_fill = |scene : & mut Scene | match row. element . style . fill ( ) {
946+ let do_fill_path = |scene : & mut Scene , path : & kurbo :: BezPath | match row. element . style . fill ( ) {
920947 Fill :: Solid ( color) => {
921948 let fill = peniko:: Brush :: Solid ( peniko:: Color :: new ( [ color. r ( ) , color. g ( ) , color. b ( ) , color. a ( ) ] ) ) ;
922- scene. fill ( peniko:: Fill :: NonZero , kurbo:: Affine :: new ( element_transform. to_cols_array ( ) ) , & fill, None , & path) ;
949+ scene. fill ( peniko:: Fill :: NonZero , kurbo:: Affine :: new ( element_transform. to_cols_array ( ) ) , & fill, None , path) ;
923950 }
924951 Fill :: Gradient ( gradient) => {
925952 let mut stops = peniko:: ColorStops :: new ( ) ;
@@ -971,11 +998,28 @@ impl Render for Table<Vector> {
971998 Default :: default ( )
972999 } ;
9731000 let brush_transform = kurbo:: Affine :: new ( ( inverse_element_transform * parent_transform) . to_cols_array ( ) ) ;
974- scene. fill ( peniko:: Fill :: NonZero , kurbo:: Affine :: new ( element_transform. to_cols_array ( ) ) , & fill, Some ( brush_transform) , & path) ;
1001+ scene. fill ( peniko:: Fill :: NonZero , kurbo:: Affine :: new ( element_transform. to_cols_array ( ) ) , & fill, Some ( brush_transform) , path) ;
9751002 }
9761003 Fill :: None => { }
9771004 } ;
9781005
1006+ let do_fill = |scene : & mut Scene | {
1007+ if row. element . is_branching ( ) {
1008+ // For branching paths, fill each face separately
1009+ for mut face_path in row. element . construct_faces ( ) . filter ( |face| !( face. area ( ) < 0.0 ) ) {
1010+ face_path. apply_affine ( Affine :: new ( applied_stroke_transform. to_cols_array ( ) ) ) ;
1011+ let mut kurbo_path = kurbo:: BezPath :: new ( ) ;
1012+ for element in face_path {
1013+ kurbo_path. push ( element) ;
1014+ }
1015+ do_fill_path ( scene, & kurbo_path) ;
1016+ }
1017+ } else {
1018+ // Simple fill of the entire path
1019+ do_fill_path ( scene, & path) ;
1020+ }
1021+ } ;
1022+
9791023 let do_stroke = |scene : & mut Scene , width_scale : f64 | {
9801024 if let Some ( stroke) = row. element . style . stroke ( ) {
9811025 let color = match stroke. color {
@@ -1090,7 +1134,7 @@ impl Render for Table<Vector> {
10901134 false => [ Op :: Fill , Op :: Stroke ] , // Default
10911135 } ;
10921136
1093- for operation in order {
1137+ for operation in & order {
10941138 match operation {
10951139 Op :: Fill => do_fill ( scene) ,
10961140 Op :: Stroke => do_stroke ( scene, 1. ) ,
0 commit comments