@@ -14,7 +14,7 @@ use graphene_std::Color;
1414use graphene_std:: renderer:: Quad ;
1515use graphene_std:: renderer:: convert_usvg_path:: { convert_tiny_skia_path, convert_usvg_path} ;
1616use graphene_std:: table:: Table ;
17- use graphene_std:: text:: { Font , TextAnchor , TypesettingConfig } ;
17+ use graphene_std:: text:: { Font , TypesettingConfig } ;
1818use graphene_std:: vector:: style:: { Fill , Gradient , GradientStop , GradientStops , GradientType , PaintOrder , Stroke , StrokeAlign , StrokeCap , StrokeJoin } ;
1919#[ derive( ExtractField ) ]
2020pub struct GraphOperationMessageContext < ' a > {
@@ -394,7 +394,7 @@ impl MessageHandler<GraphOperationMessage, GraphOperationMessageContext<'_>> for
394394 center,
395395 } => {
396396 let mut options = usvg:: Options :: default ( ) ;
397- options. fontdb_mut ( ) . load_font_data ( include_bytes ! ( "../../../../font .ttf" ) . to_vec ( ) ) ;
397+ options. fontdb_mut ( ) . load_font_data ( include_bytes ! ( "../overlays/source-sans-pro-regular .ttf" ) . to_vec ( ) ) ;
398398 options. font_family = "Source Sans Pro" . to_string ( ) ;
399399
400400 let svg = svg. replace ( "font-family=\" sans-serif\" " , "font-family=\" Source Sans Pro\" " ) ;
@@ -552,7 +552,6 @@ fn import_usvg_node(
552552 insert_index : usize ,
553553 graphite_gradient_stops : & HashMap < String , GradientStops > ,
554554) {
555- log:: error!( "DIAGNOSTIC: Visiting node root: {:?}" , node) ;
556555 let layer = modify_inputs. create_layer ( id) ;
557556
558557 modify_inputs. network_interface . move_layer_to_stack ( layer, parent, insert_index, & [ ] ) ;
@@ -597,7 +596,7 @@ fn import_usvg_node(
597596 warn ! ( "Skip image" ) ;
598597 }
599598 usvg:: Node :: Text ( text) => {
600- import_usvg_text ( modify_inputs, text, node. abs_transform ( ) , layer) ;
599+ import_usvg_text ( modify_inputs, text, node. abs_transform ( ) , layer, parent , insert_index ) ;
601600 }
602601 }
603602}
@@ -643,7 +642,7 @@ fn import_usvg_node_inner(
643642 0
644643 }
645644 usvg:: Node :: Text ( text) => {
646- import_usvg_text ( modify_inputs, text, node. abs_transform ( ) , layer) ;
645+ import_usvg_text ( modify_inputs, text, node. abs_transform ( ) , layer, parent , insert_index ) ;
647646 0
648647 }
649648 usvg:: Node :: Path ( path) => {
@@ -676,23 +675,31 @@ fn import_usvg_path(modify_inputs: &mut ModifyInputsContext, node: &usvg::Node,
676675 }
677676}
678677
679- fn import_usvg_text ( modify_inputs : & mut ModifyInputsContext , text : & usvg:: Text , transform : usvg:: Transform , layer : LayerNodeIdentifier ) {
678+ fn import_usvg_text ( modify_inputs : & mut ModifyInputsContext , text : & usvg:: Text , transform : usvg:: Transform , layer : LayerNodeIdentifier , parent : LayerNodeIdentifier , insert_index : usize ) {
680679 use graphene_std:: text:: TextAnchor ;
681- let font_family = text
682- . chunks ( )
683- . first ( )
684- . and_then ( |chunk| chunk. spans ( ) . first ( ) )
685- . and_then ( |span| span. font ( ) . families ( ) . first ( ) . map ( |f| f. to_string ( ) ) )
686- . unwrap_or_else ( || graphene_std:: consts:: DEFAULT_FONT_FAMILY . to_string ( ) ) ;
687- let font_style = graphene_std:: consts:: DEFAULT_FONT_STYLE . to_string ( ) ;
688- let font = Font :: new ( font_family, font_style) ;
689680
690- let full_text: String = text. chunks ( ) . iter ( ) . map ( |chunk| chunk. text ( ) ) . collect ( ) ;
681+ for ( i, chunk) in text. chunks ( ) . iter ( ) . enumerate ( ) {
682+ let current_layer = if i == 0 {
683+ layer
684+ } else {
685+ let new_id = NodeId :: new ( ) ;
686+ let new_layer = modify_inputs. create_layer ( new_id) ;
687+ modify_inputs. network_interface . move_layer_to_stack_for_import ( new_layer, parent, insert_index, & [ ] ) ;
688+ new_layer
689+ } ;
690+ modify_inputs. layer_node = Some ( current_layer) ;
691691
692- // Check if any chunk uses text-on-path (TextFlow::Path)
693- let text_path_chunk = text. chunks ( ) . iter ( ) . find ( |chunk| matches ! ( chunk. text_flow( ) , usvg:: TextFlow :: Path ( _) ) ) ;
692+ let font_family = chunk
693+ . spans ( )
694+ . first ( )
695+ . and_then ( |span| span. font ( ) . families ( ) . first ( ) . map ( |f| f. to_string ( ) ) )
696+ . unwrap_or_else ( || graphene_std:: consts:: DEFAULT_FONT_FAMILY . to_string ( ) ) ;
697+ let font_style = graphene_std:: consts:: DEFAULT_FONT_STYLE . to_string ( ) ;
698+ let font = Font :: new ( font_family, font_style) ;
699+
700+ let font_size = chunk. spans ( ) . first ( ) . map ( |s| s. font_size ( ) . get ( ) ) . unwrap_or ( 24.0 ) as f64 ;
701+ let letter_spacing = chunk. spans ( ) . first ( ) . map ( |s| s. letter_spacing ( ) ) . unwrap_or ( 0.0 ) as f64 ;
694702
695- if let Some ( chunk) = text_path_chunk {
696703 if let usvg:: TextFlow :: Path ( text_path) = chunk. text_flow ( ) {
697704 let path_subpaths = convert_tiny_skia_path ( text_path. path ( ) ) ;
698705 let start_offset = text_path. start_offset ( ) as f64 ;
@@ -701,8 +708,6 @@ fn import_usvg_text(modify_inputs: &mut ModifyInputsContext, text: &usvg::Text,
701708 usvg:: TextAnchor :: Middle => TextAnchor :: Middle ,
702709 usvg:: TextAnchor :: End => TextAnchor :: End ,
703710 } ;
704- let font_size = chunk. spans ( ) . first ( ) . map ( |s| s. font_size ( ) . get ( ) ) . unwrap_or ( 24.0 ) as f64 ;
705- let letter_spacing = chunk. spans ( ) . first ( ) . map ( |s| s. letter_spacing ( ) ) . unwrap_or ( 0.0 ) as f64 ;
706711
707712 let affine = DAffine2 :: from_cols_array ( & [
708713 transform. sx as f64 ,
@@ -712,15 +717,14 @@ fn import_usvg_text(modify_inputs: &mut ModifyInputsContext, text: &usvg::Text,
712717 transform. tx as f64 ,
713718 transform. ty as f64 ,
714719 ] ) ;
715- modify_inputs. insert_text_on_path ( full_text, font, font_size, letter_spacing, path_subpaths, start_offset, anchor, affine, layer) ;
720+ modify_inputs. insert_text_on_path ( chunk. text ( ) . to_string ( ) , font, font_size, letter_spacing, path_subpaths, start_offset, anchor, affine, current_layer) ;
721+ modify_inputs. fill_set ( Fill :: Solid ( Color :: BLACK ) ) ;
722+ } else {
723+ // Regular text fallback
724+ modify_inputs. insert_text ( chunk. text ( ) . to_string ( ) , font, TypesettingConfig { font_size, ..Default :: default ( ) } , current_layer) ;
716725 modify_inputs. fill_set ( Fill :: Solid ( Color :: BLACK ) ) ;
717- return ;
718726 }
719727 }
720-
721- // Fallback: regular text
722- modify_inputs. insert_text ( full_text, font, TypesettingConfig :: default ( ) , layer) ;
723- modify_inputs. fill_set ( Fill :: Solid ( Color :: BLACK ) ) ;
724728}
725729
726730/// Set correct positions for all imported layers in a single top-down O(n) pass.
0 commit comments