5
5
using System . Linq ;
6
6
using System . Text ;
7
7
using System . Threading . Tasks ;
8
+ using System . Windows ;
8
9
using System . Windows . Media ;
9
10
10
11
namespace OpenBoardAnim . Utils
@@ -22,11 +23,33 @@ public GeometryWithFill(Geometry geometry, Brush brush)
22
23
public Brush Brush { get ; set ; }
23
24
}
24
25
25
- public class SVGHelper
26
+ public class GeometryHelper
26
27
{
27
-
28
+ public static PathGeometry ConvertTextToGeometry ( string text , FontFamily fontFamily , FontStyle fontStyle , FontWeight fontWeight , double fontSize )
29
+ {
30
+ Typeface typeface = new Typeface ( fontFamily , fontStyle , fontWeight , FontStretches . Normal ) ;
31
+ // Create a formatted text
32
+ FormattedText formattedText = new FormattedText (
33
+ text ,
34
+ System . Globalization . CultureInfo . CurrentCulture ,
35
+ FlowDirection . LeftToRight ,
36
+ typeface ,
37
+ fontSize ,
38
+ Brushes . Black ,
39
+ VisualTreeHelper . GetDpi ( Application . Current . MainWindow ) . PixelsPerDip ) ;
40
+
41
+ // Create a geometry from the formatted text
42
+ Geometry textGeometry = formattedText . BuildGeometry ( new Point ( 0 , 0 ) ) ;
43
+
44
+ // Convert to PathGeometry
45
+ PathGeometry pathGeometry = PathGeometry . CreateFromGeometry ( textGeometry ) ;
46
+
47
+ return pathGeometry ;
48
+ }
49
+
28
50
public static DrawingGroup GetPathGeometryFromSVG ( string filePath )
29
51
{
52
+ if ( string . IsNullOrEmpty ( filePath ) ) return null ;
30
53
var svgFileReader = new FileSvgReader ( new WpfDrawingSettings ( ) ) ;
31
54
return svgFileReader . Read ( filePath ) ;
32
55
}
@@ -44,15 +67,15 @@ public static List<GeometryWithFill> ConvertToGeometry(DrawingGroup drawingGroup
44
67
Geometry geometry = geometryDrawing . Geometry ;
45
68
if ( geometry . Transform != null )
46
69
{
47
- clone . Children . Add ( geometry . Transform ) ;
70
+ clone . Children . Insert ( 0 , geometry . Transform ) ;
48
71
}
49
72
geometry . Transform = clone ;
50
73
geometrylist . Add ( new GeometryWithFill ( geometry , geometryDrawing . Brush ) ) ;
51
74
}
52
75
else if ( drawing is DrawingGroup innerGroup )
53
76
{
54
77
if ( innerGroup . Transform != null )
55
- clone . Children . Add ( innerGroup . Transform ) ;
78
+ clone . Children . Insert ( 0 , innerGroup . Transform ) ;
56
79
geometrylist . AddRange ( ConvertToGeometry ( innerGroup , clone ) ) ;
57
80
}
58
81
}
0 commit comments