@@ -619,11 +619,14 @@ fn escape_xml_attr(value: &str) -> String {
619619
620620#[ derive( Debug , Default , Clone ) ]
621621struct TextPathAttrs {
622+ pub start_offset : Option < String > ,
622623 pub method : Option < String > ,
623624 pub spacing : Option < String > ,
624625 pub side : Option < String > ,
625626 pub text_length : Option < f64 > ,
626627 pub length_adjust : Option < String > ,
628+ pub path_length : Option < f64 > ,
629+ pub direction : Option < String > ,
627630}
628631
629632fn pre_parse_textpath_attrs ( svg : & str ) -> std:: collections:: HashMap < String , Vec < TextPathAttrs > > {
@@ -638,11 +641,14 @@ fn pre_parse_textpath_attrs(svg: &str) -> std::collections::HashMap<String, Vec<
638641 continue ;
639642 } ;
640643 map. entry ( path_id) . or_default ( ) . push ( TextPathAttrs {
644+ start_offset : node. attribute ( "startOffset" ) . map ( str:: to_string) ,
641645 method : node. attribute ( "method" ) . map ( str:: to_string) ,
642646 spacing : node. attribute ( "spacing" ) . map ( str:: to_string) ,
643647 side : node. attribute ( "side" ) . map ( str:: to_string) ,
644648 text_length : node. attribute ( "textLength" ) . and_then ( |v| v. parse ( ) . ok ( ) ) ,
645649 length_adjust : node. attribute ( "lengthAdjust" ) . map ( str:: to_string) ,
650+ path_length : node. attribute ( "pathLength" ) . and_then ( |v| v. parse ( ) . ok ( ) ) ,
651+ direction : node. attribute ( "direction" ) . or_else ( || node. attribute ( "style" ) . and_then ( |s| s. split ( ';' ) . find ( |p| p. trim ( ) . starts_with ( "direction" ) ) . and_then ( |p| p. split ( ':' ) . last ( ) ) . map ( |v| v. trim ( ) ) ) ) . map ( str:: to_string) ,
646652 } ) ;
647653 }
648654 }
@@ -802,20 +808,21 @@ fn import_usvg_text(
802808 text : & usvg:: Text ,
803809 transform : usvg:: Transform ,
804810 layer : LayerNodeIdentifier ,
805- parent : LayerNodeIdentifier ,
806- insert_index : usize ,
811+ _parent : LayerNodeIdentifier ,
812+ _insert_index : usize ,
807813 textpath_attrs : & mut HashMap < String , Vec < TextPathAttrs > > ,
808814) {
809815 log:: info!( "Importing usvg text node with {} chunks" , text. chunks( ) . len( ) ) ;
810816
811- for ( i, chunk) in text. chunks ( ) . iter ( ) . enumerate ( ) {
812- let current_layer = if i == 0 {
813- layer
814- } else {
817+ let chunks = text. chunks ( ) ;
818+ for ( i, chunk) in chunks. iter ( ) . enumerate ( ) {
819+ let current_layer = if chunks. len ( ) > 1 {
815820 let new_id = NodeId :: new ( ) ;
816821 let new_layer = modify_inputs. create_layer ( new_id) ;
817- modify_inputs. network_interface . move_layer_to_stack_for_import ( new_layer, parent , insert_index , & [ ] ) ;
822+ modify_inputs. network_interface . move_layer_to_stack_for_import ( new_layer, layer , i , & [ ] ) ;
818823 new_layer
824+ } else {
825+ layer
819826 } ;
820827 modify_inputs. layer_node = Some ( current_layer) ;
821828
@@ -834,7 +841,12 @@ fn import_usvg_text(
834841 let tp_id = text_path. id ( ) ;
835842 let tp_attrs = take_textpath_attrs ( textpath_attrs, tp_id) ;
836843 let path_subpaths = convert_tiny_skia_path ( text_path. path ( ) ) ;
837- let start_offset = text_path. start_offset ( ) as f64 ;
844+
845+ let ( start_offset, start_offset_percent) = match tp_attrs. start_offset . as_deref ( ) {
846+ Some ( s) if s. ends_with ( '%' ) => ( s. trim_end_matches ( '%' ) . parse :: < f64 > ( ) . unwrap_or ( 0.0 ) / 100.0 , true ) ,
847+ Some ( s) => ( s. parse :: < f64 > ( ) . unwrap_or ( 0.0 ) , false ) ,
848+ None => ( text_path. start_offset ( ) as f64 , false ) ,
849+ } ;
838850
839851 modify_inputs. insert_text_on_path (
840852 chunk. text ( ) . to_string ( ) ,
@@ -843,12 +855,15 @@ fn import_usvg_text(
843855 letter_spacing,
844856 path_subpaths,
845857 start_offset,
858+ start_offset_percent,
846859 text_anchor ( chunk. anchor ( ) ) ,
847860 text_path_side ( & tp_attrs) ,
848861 text_path_method ( & tp_attrs) ,
849862 text_path_spacing ( & tp_attrs) ,
850863 tp_attrs. text_length ,
851864 text_length_adjust ( & tp_attrs) ,
865+ tp_attrs. path_length ,
866+ tp_attrs. direction . as_deref ( ) == Some ( "rtl" ) ,
852867 usvg_transform ( transform) ,
853868 current_layer,
854869 ) ;
0 commit comments