@@ -13,6 +13,7 @@ type IText = {
13
13
y : number ;
14
14
option : IFontType | IFontOptions ;
15
15
children : string | number | undefined ;
16
+ as ?: "path" | "text" ;
16
17
} ;
17
18
18
19
const onHandFonts = {
@@ -26,7 +27,13 @@ const onHandFonts = {
26
27
} ,
27
28
} ;
28
29
29
- export const Text : React . FC < IText > = ( { x, y, option, children } ) => {
30
+ export const Text : React . FC < IText > = ( {
31
+ x,
32
+ y,
33
+ option,
34
+ children,
35
+ as = "text" ,
36
+ } ) => {
30
37
if ( ! children ) return < > </ > ;
31
38
const defaultFontFamily = defaultFont ;
32
39
@@ -40,10 +47,26 @@ export const Text: React.FC<IText> = ({ x, y, option, children }) => {
40
47
if ( typeof x === "function" )
41
48
x = x ( openTypeFont . getAdvanceWidth ( children . toString ( ) , font . size ) ) ;
42
49
43
- const path = openTypeFont . getPath ( children . toString ( ) , x , y , font . size ) ;
44
- const pathSVG = path . toPathData ( 1 ) ;
45
-
46
50
const classNames = [ "text" ] ;
47
51
if ( typeof option === "string" ) classNames . push ( option ) ;
48
- return < path className = { classNames . join ( " " ) } d = { pathSVG } /> ;
52
+
53
+ if ( as === "path" ) {
54
+ const path = openTypeFont . getPath ( children . toString ( ) , x , y , font . size ) ;
55
+ const pathSVG = path . toPathData ( 1 ) ;
56
+
57
+ return < path className = { classNames . join ( " " ) } d = { pathSVG } /> ;
58
+ } else {
59
+ classNames . push ( "websafe" ) ;
60
+ return (
61
+ < text
62
+ x = { x }
63
+ y = { y }
64
+ className = { classNames . join ( " " ) }
65
+ fontSize = { font . size }
66
+ fontWeight = { font . weight }
67
+ >
68
+ < tspan > { children } </ tspan >
69
+ </ text >
70
+ ) ;
71
+ }
49
72
} ;
0 commit comments