@@ -7,6 +7,7 @@ use super::vectorimage::VectorImage;
77use super :: { Content , TextStroke } ;
88use crate :: fileformats:: xoppformat:: { self , XoppColor } ;
99use crate :: store:: chrono_comp:: StrokeLayer ;
10+ use crate :: strokes:: textstroke:: TextStyle ;
1011use crate :: { Drawable , utils} ;
1112use crate :: { Engine , render} ;
1213use p2d:: bounding_volume:: Aabb ;
@@ -427,6 +428,29 @@ impl Stroke {
427428 Ok ( Stroke :: BitmapImage ( BitmapImage { image, rectangle } ) )
428429 }
429430
431+ pub fn from_xopptext (
432+ xopp_text : xoppformat:: XoppText ,
433+ offset : na:: Vector2 < f64 > ,
434+ target_dpi : f64 ,
435+ ) -> Result < Self , anyhow:: Error > {
436+ let pos: na:: Vector2 < f64 > = na:: Vector2 :: < f64 > :: new (
437+ crate :: utils:: convert_value_dpi ( xopp_text. x , xoppformat:: XoppFile :: DPI , target_dpi) ,
438+ crate :: utils:: convert_value_dpi ( xopp_text. y , xoppformat:: XoppFile :: DPI , target_dpi) ,
439+ ) ;
440+
441+ let mut textstyle = TextStyle :: default ( ) ;
442+ textstyle. color = crate :: utils:: color_from_xopp ( xopp_text. color ) ;
443+ textstyle. font_size =
444+ crate :: utils:: convert_value_dpi ( xopp_text. size , xoppformat:: XoppFile :: DPI , target_dpi) ;
445+ textstyle. font_family = xopp_text. font ;
446+
447+ Ok ( Stroke :: TextStroke ( TextStroke :: new (
448+ xopp_text. text ,
449+ pos + offset,
450+ textstyle,
451+ ) ) )
452+ }
453+
430454 pub fn into_xopp ( self , current_dpi : f64 ) -> Option < xoppformat:: XoppStrokeType > {
431455 match self {
432456 Stroke :: BrushStroke ( brushstroke) => {
0 commit comments