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