@@ -4,8 +4,8 @@ pub use quad::Quad;
44pub use rect:: Rect ;
55
66use crate :: raster:: { BlendMode , Image , ImageFrame } ;
7- use crate :: transform:: Transform ;
8- use crate :: uuid:: generate_uuid;
7+ use crate :: transform:: { self , Footprint , Transform } ;
8+ use crate :: uuid:: { generate_uuid, NodeId } ;
99use crate :: vector:: style:: { Fill , Stroke , ViewMode } ;
1010use crate :: vector:: PointId ;
1111use crate :: Raster ;
@@ -16,6 +16,7 @@ use bezier_rs::Subpath;
1616use base64:: Engine ;
1717use glam:: { DAffine2 , DVec2 } ;
1818use num_traits:: Zero ;
19+ use std:: collections:: HashMap ;
1920use std:: fmt:: Write ;
2021#[ cfg( feature = "vello" ) ]
2122use vello:: * ;
@@ -272,7 +273,7 @@ pub trait GraphicElementRendered {
272273 fn render_svg ( & self , render : & mut SvgRender , render_params : & RenderParams ) ;
273274 fn bounding_box ( & self , transform : DAffine2 ) -> Option < [ DVec2 ; 2 ] > ;
274275 fn add_click_targets ( & self , click_targets : & mut Vec < ClickTarget > ) ;
275- fn add_footprints ( & self , footprints : & mut HashMap < NodeId , Footprint > )
276+ fn add_footprints ( & self , footprints : & mut HashMap < NodeId , ( Footprint , DAffine2 ) > , footprint : Footprint , element_id : Option < NodeId > ) ;
276277 #[ cfg( feature = "vello" ) ]
277278 fn to_vello_scene ( & self , transform : DAffine2 , context : & mut RenderContext ) -> Scene {
278279 let mut scene = vello:: Scene :: new ( ) ;
@@ -328,6 +329,19 @@ impl GraphicElementRendered for GraphicGroup {
328329 }
329330 }
330331
332+ fn add_footprints ( & self , footprints : & mut HashMap < NodeId , ( Footprint , DAffine2 ) > , mut footprint : Footprint , _: Option < NodeId > ) {
333+ log:: debug!( "Transform for graphic group: {:?}" , self . transform) ;
334+ footprint. transform *= self . transform ;
335+ for ( element, optional_node_id) in self . elements . iter ( ) {
336+ log:: debug!( "Optional node id: {:?}" , optional_node_id) ;
337+ if let Some ( element_id) = optional_node_id {
338+ let mut new_footprints = HashMap :: new ( ) ;
339+ element. add_footprints ( & mut new_footprints, footprint, Some ( * element_id) ) ;
340+ footprints. extend ( new_footprints) ;
341+ }
342+ }
343+ }
344+
331345 #[ cfg( feature = "vello" ) ]
332346 fn render_to_vello ( & self , scene : & mut Scene , transform : DAffine2 , context : & mut RenderContext ) {
333347 let child_transform = transform * self . transform ;
@@ -411,6 +425,8 @@ impl GraphicElementRendered for VectorData {
411425 click_targets. extend ( self . stroke_bezier_paths ( ) . map ( fill) . map ( |subpath| ClickTarget :: new ( subpath, stroke_width) ) ) ;
412426 }
413427
428+ fn add_footprints ( & self , footprints : & mut HashMap < NodeId , ( Footprint , DAffine2 ) > , footprint : Footprint , _: Option < NodeId > ) { }
429+
414430 #[ cfg( feature = "vello" ) ]
415431 fn render_to_vello ( & self , scene : & mut Scene , transform : DAffine2 , _: & mut RenderContext ) {
416432 use crate :: vector:: style:: GradientType ;
@@ -626,35 +642,52 @@ impl GraphicElementRendered for Artboard {
626642 click_targets. push ( ClickTarget :: new ( subpath, 0. ) ) ;
627643 }
628644
645+ fn add_footprints ( & self , footprints : & mut HashMap < NodeId , ( Footprint , DAffine2 ) > , mut footprint : Footprint , node_id : Option < NodeId > ) {
646+ log:: debug!( "Adding footprints for artboard" ) ;
647+ let mut graphic_group_footprint = footprint. clone ( ) ;
648+ graphic_group_footprint. transform *= self . transform ( ) ;
649+ self . graphic_group . add_footprints ( footprints, graphic_group_footprint, None ) ;
650+ // footprint.transform *= self.transform();
651+ if let Some ( node_id) = node_id {
652+ footprints. insert ( node_id, ( footprint, DAffine2 :: from_translation ( self . location . as_dvec2 ( ) ) ) ) ;
653+ }
654+ }
655+
629656 fn contains_artboard ( & self ) -> bool {
630657 true
631658 }
632659}
633660
634661impl GraphicElementRendered for crate :: ArtboardGroup {
635662 fn render_svg ( & self , render : & mut SvgRender , render_params : & RenderParams ) {
636- for artboard in & self . artboards {
663+ for ( artboard, _ ) in & self . artboards {
637664 artboard. render_svg ( render, render_params) ;
638665 }
639666 }
640667
641668 fn bounding_box ( & self , transform : DAffine2 ) -> Option < [ DVec2 ; 2 ] > {
642- self . artboards . iter ( ) . filter_map ( |element| element. bounding_box ( transform) ) . reduce ( Quad :: combine_bounds)
669+ self . artboards . iter ( ) . filter_map ( |( element, _ ) | element. bounding_box ( transform) ) . reduce ( Quad :: combine_bounds)
643670 }
644671
645672 fn add_click_targets ( & self , click_targets : & mut Vec < ClickTarget > ) {
646- for artboard in & self . artboards {
673+ for ( artboard, _ ) in & self . artboards {
647674 artboard. add_click_targets ( click_targets) ;
648675 }
649676 }
650677
651678 #[ cfg( feature = "vello" ) ]
652679 fn render_to_vello ( & self , scene : & mut Scene , transform : DAffine2 , context : & mut RenderContext ) {
653- for artboard in & self . artboards {
680+ for ( artboard, _ ) in & self . artboards {
654681 artboard. render_to_vello ( scene, transform, context)
655682 }
656683 }
657684
685+ fn add_footprints ( & self , footprints : & mut HashMap < NodeId , ( Footprint , DAffine2 ) > , footprint : Footprint , _: Option < NodeId > ) {
686+ for ( artboard, node_id) in & self . artboards {
687+ artboard. add_footprints ( footprints, footprint, * node_id)
688+ }
689+ }
690+
658691 fn contains_artboard ( & self ) -> bool {
659692 !self . artboards . is_empty ( )
660693 }
@@ -706,6 +739,12 @@ impl GraphicElementRendered for ImageFrame<Color> {
706739 click_targets. push ( ClickTarget :: new ( subpath, 0. ) ) ;
707740 }
708741
742+ fn add_footprints ( & self , footprints : & mut HashMap < NodeId , ( Footprint , DAffine2 ) > , footprint : Footprint , element_id : Option < NodeId > ) {
743+ if let Some ( element_id) = element_id {
744+ footprints. insert ( element_id, ( footprint, self . transform ) ) ;
745+ }
746+ }
747+
709748 #[ cfg( feature = "vello" ) ]
710749 fn render_to_vello ( & self , scene : & mut Scene , transform : DAffine2 , _: & mut RenderContext ) {
711750 use vello:: peniko;
@@ -776,6 +815,10 @@ impl GraphicElementRendered for Raster {
776815 click_targets. push ( ClickTarget :: new ( subpath, 0. ) ) ;
777816 }
778817
818+ fn add_footprints ( & self , footprints : & mut HashMap < NodeId , ( Footprint , DAffine2 ) > , footprint : Footprint , element_id : Option < NodeId > ) {
819+ //footprints.insert(element_id, (transform, self.transform));
820+ }
821+
779822 #[ cfg( feature = "vello" ) ]
780823 fn render_to_vello ( & self , scene : & mut Scene , transform : DAffine2 , context : & mut RenderContext ) {
781824 use vello:: peniko;
@@ -841,6 +884,17 @@ impl GraphicElementRendered for GraphicElement {
841884 }
842885 }
843886
887+ fn add_footprints ( & self , footprints : & mut HashMap < NodeId , ( Footprint , DAffine2 ) > , footprint : Footprint , element_id : Option < NodeId > ) {
888+ if let Some ( element_id) = element_id {
889+ footprints. insert ( element_id, ( footprint, self . transform ( ) ) ) ;
890+ }
891+ match self {
892+ GraphicElement :: VectorData ( vector_data) => vector_data. add_footprints ( footprints, footprint, None ) ,
893+ GraphicElement :: Raster ( raster) => raster. add_footprints ( footprints, footprint, None ) ,
894+ GraphicElement :: GraphicGroup ( graphic_group) => graphic_group. add_footprints ( footprints, footprint, None ) ,
895+ }
896+ }
897+
844898 #[ cfg( feature = "vello" ) ]
845899 fn render_to_vello ( & self , scene : & mut Scene , transform : DAffine2 , context : & mut RenderContext ) {
846900 match self {
@@ -883,6 +937,7 @@ impl<T: Primitive> GraphicElementRendered for T {
883937 }
884938
885939 fn add_click_targets ( & self , _click_targets : & mut Vec < ClickTarget > ) { }
940+ fn add_footprints ( & self , footprints : & mut HashMap < NodeId , ( Footprint , DAffine2 ) > , footprint : Footprint , element_id : Option < NodeId > ) { }
886941}
887942
888943impl GraphicElementRendered for Option < Color > {
@@ -910,6 +965,8 @@ impl GraphicElementRendered for Option<Color> {
910965 }
911966
912967 fn add_click_targets ( & self , _click_targets : & mut Vec < ClickTarget > ) { }
968+
969+ fn add_footprints ( & self , footprints : & mut HashMap < NodeId , ( Footprint , DAffine2 ) > , footprint : Footprint , element_id : Option < NodeId > ) { }
913970}
914971
915972impl GraphicElementRendered for Vec < Color > {
@@ -933,6 +990,8 @@ impl GraphicElementRendered for Vec<Color> {
933990 }
934991
935992 fn add_click_targets ( & self , _click_targets : & mut Vec < ClickTarget > ) { }
993+
994+ fn add_footprints ( & self , footprints : & mut HashMap < NodeId , ( Footprint , DAffine2 ) > , footprint : Footprint , element_id : Option < NodeId > ) { }
936995}
937996
938997/// A segment of an svg string to allow for embedding blob urls
0 commit comments