-
Notifications
You must be signed in to change notification settings - Fork 3
/
text.go
797 lines (736 loc) · 17.8 KB
/
text.go
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
60
61
62
63
64
65
66
67
68
69
70
71
72
73
74
75
76
77
78
79
80
81
82
83
84
85
86
87
88
89
90
91
92
93
94
95
96
97
98
99
100
101
102
103
104
105
106
107
108
109
110
111
112
113
114
115
116
117
118
119
120
121
122
123
124
125
126
127
128
129
130
131
132
133
134
135
136
137
138
139
140
141
142
143
144
145
146
147
148
149
150
151
152
153
154
155
156
157
158
159
160
161
162
163
164
165
166
167
168
169
170
171
172
173
174
175
176
177
178
179
180
181
182
183
184
185
186
187
188
189
190
191
192
193
194
195
196
197
198
199
200
201
202
203
204
205
206
207
208
209
210
211
212
213
214
215
216
217
218
219
220
221
222
223
224
225
226
227
228
229
230
231
232
233
234
235
236
237
238
239
240
241
242
243
244
245
246
247
248
249
250
251
252
253
254
255
256
257
258
259
260
261
262
263
264
265
266
267
268
269
270
271
272
273
274
275
276
277
278
279
280
281
282
283
284
285
286
287
288
289
290
291
292
293
294
295
296
297
298
299
300
301
302
303
304
305
306
307
308
309
310
311
312
313
314
315
316
317
318
319
320
321
322
323
324
325
326
327
328
329
330
331
332
333
334
335
336
337
338
339
340
341
342
343
344
345
346
347
348
349
350
351
352
353
354
355
356
357
358
359
360
361
362
363
364
365
366
367
368
369
370
371
372
373
374
375
376
377
378
379
380
381
382
383
384
385
386
387
388
389
390
391
392
393
394
395
396
397
398
399
400
401
402
403
404
405
406
407
408
409
410
411
412
413
414
415
416
417
418
419
420
421
422
423
424
425
426
427
428
429
430
431
432
433
434
435
436
437
438
439
440
441
442
443
444
445
446
447
448
449
450
451
452
453
454
455
456
457
458
459
460
461
462
463
464
465
466
467
468
469
470
471
472
473
474
475
476
477
478
479
480
481
482
483
484
485
486
487
488
489
490
491
492
493
494
495
496
497
498
499
500
501
502
503
504
505
506
507
508
509
510
511
512
513
514
515
516
517
518
519
520
521
522
523
524
525
526
527
528
529
530
531
532
533
534
535
536
537
538
539
540
541
542
543
544
545
546
547
548
549
550
551
552
553
554
555
556
557
558
559
560
561
562
563
564
565
566
567
568
569
570
571
572
573
574
575
576
577
578
579
580
581
582
583
584
585
586
587
588
589
590
591
592
593
594
595
596
597
598
599
600
601
602
603
604
605
606
607
608
609
610
611
612
613
614
615
616
617
618
619
620
621
622
623
624
625
626
627
628
629
630
631
632
633
634
635
636
637
638
639
640
641
642
643
644
645
646
647
648
649
650
651
652
653
654
655
656
657
658
659
660
661
662
663
664
665
666
667
668
669
670
671
672
673
674
675
676
677
678
679
680
681
682
683
684
685
686
687
688
689
690
691
692
693
694
695
696
697
698
699
700
701
702
703
704
705
706
707
708
709
710
711
712
713
714
715
716
717
718
719
720
721
722
723
724
725
726
727
728
729
730
731
732
733
734
735
736
737
738
739
740
741
742
743
744
745
746
747
748
749
750
751
752
753
754
755
756
757
758
759
760
761
762
763
764
765
766
767
768
769
770
771
772
773
774
775
776
777
778
779
780
781
782
783
784
785
786
787
788
789
790
791
792
793
794
795
796
797
package imagedraw
import (
"github.com/golang/freetype"
"github.com/golang/freetype/truetype"
"github.com/yeyudekuangxiang/imagedraw/fonts"
"golang.org/x/image/font"
"golang.org/x/image/font/opentype"
"golang.org/x/image/math/fixed"
"image"
"image/color"
"image/draw"
"io/ioutil"
"math"
"net/http"
)
var (
SiYuanHeiYi = func() IDrawString { return NewTTFDraw(mustLoadTTFBytes(fonts.SiYuanHeiTiTTF())) }
SiYuanHeiYiBold = func() IDrawString { return NewOTFDraw(mustLoadOTFBytes(fonts.SiYuanHeiTiOTFBold())) }
)
// SplitText 带有字符串长度的结构体
type SplitText struct {
//字符串
Str string
//字符串的长度 单位px
Width float64
//字符串的高度 单位px
Height float64
//此行文本相对原点位置 最小y点
MinY float64
//此行文本相对原点位置 最大y点
MaxY float64
}
func Int26ToFloat(d fixed.Int26_6) float64 {
return float64(d>>6) + float64(d&(1<<6-1))*0.01
}
//将一个字符串根据字体和最大长度 分割成行
func splitText(face font.Face, s string, maxWidth float64) []SplitText {
runeList := []rune(s)
stList := make([]SplitText, 0)
st := SplitText{
MaxY: float64(1 - 1<<16),
MinY: float64(1<<16 - 1),
}
for i, r := range runeList {
//返回字体高度、宽度
bounds, advance, _ := face.GlyphBounds(r)
maxY := Int26ToFloat(bounds.Max.Y)
minY := Int26ToFloat(bounds.Min.Y)
width := Int26ToFloat(advance)
if math.Ceil(st.Width+width) >= maxWidth {
stList = append(stList, st)
st = SplitText{
Str: string(r),
Width: width,
Height: maxY - minY,
MaxY: maxY,
MinY: minY,
}
} else {
st.Width += width
st.Str += string(r)
if st.MaxY < maxY {
st.MaxY = maxY
}
if st.MinY > minY {
st.MinY = minY
}
st.Height = st.MaxY - st.MinY
}
if i == len(runeList)-1 {
stList = append(stList, st)
}
}
return stList
}
//计算字符串的长度
func str2SplitText(face font.Face, str string) SplitText {
runeList := []rune(str)
st := SplitText{
MaxY: float64(1 - 1<<16),
MinY: float64(1<<16 - 1),
Str: str,
}
for _, r := range runeList {
bounds, advance, _ := face.GlyphBounds(r)
st.Width += Int26ToFloat(advance)
if maxY := Int26ToFloat(bounds.Max.Y); maxY > st.MaxY {
st.MaxY = maxY
}
if minY := Int26ToFloat(bounds.Min.Y); minY < st.MinY {
st.MinY = minY
}
}
st.Height = st.MaxY - st.MinY
return st
}
//处理多行超出提示
func dealLineOut(face font.Face, list []SplitText, outStr, outStrPosition string, maxLineNum int) []SplitText {
if maxLineNum <= 0 || len(list) <= maxLineNum {
return list
}
if len(outStr) == 0 {
return list[:maxLineNum]
}
outStrRune := []rune(outStr)
outStrWidth := 0.00
MaxY := float64(1 - 1<<16)
MinY := float64(1<<16 - 1)
for _, s := range outStrRune {
bounds, advance, _ := face.GlyphBounds(s)
outStrWidth += Int26ToFloat(advance)
if maxY := Int26ToFloat(bounds.Max.Y); maxY > MaxY {
MaxY = maxY
}
if minY := Int26ToFloat(bounds.Min.Y); minY < MinY {
MinY = minY
}
}
list2 := list[:maxLineNum]
lastLine := list2[maxLineNum-1]
lastRuneList := []rune(lastLine.Str)
total := 0.00
if outStrPosition == "left" {
for i := len(lastRuneList) - 1; i >= 0; i-- {
advance, _ := face.GlyphAdvance(lastRuneList[i])
total += Int26ToFloat(advance)
if total >= outStrWidth {
lastRuneList = append(lastRuneList[:i], outStrRune...)
list2[maxLineNum-1].Str = string(lastRuneList)
list2[maxLineNum-1].Width = list2[maxLineNum-1].Width - total + outStrWidth
if list2[maxLineNum-1].MaxY < MaxY {
list2[maxLineNum-1].MaxY = MaxY
}
if list2[maxLineNum-1].MinY > MinY {
list2[maxLineNum-1].MinY = MinY
}
break
}
}
} else {
for i := len(lastRuneList) - 1; i >= 0; i-- {
advance, _ := face.GlyphAdvance(lastRuneList[i])
total += Int26ToFloat(advance)
if total >= outStrWidth {
lastRuneList = append(lastRuneList[:i], outStrRune...)
list2[maxLineNum-1].Str = string(lastRuneList)
list2[maxLineNum-1].Width = list2[maxLineNum-1].Width - total + outStrWidth
if list2[maxLineNum-1].MaxY < MaxY {
list2[maxLineNum-1].MaxY = MaxY
}
if list2[maxLineNum-1].MinY > MinY {
list2[maxLineNum-1].MinY = MinY
}
break
}
}
}
return list2
}
//处理单行文本超出提示
func dealSingleOut(face font.Face, str SplitText, outStr, outStrPosition string, maxWidth float64) SplitText {
if str.Width <= maxWidth {
return str
}
outStrRune := []rune(outStr)
outStrWidth := 0.00
MaxY := float64(1 - 1<<16)
MinY := float64(1<<16 - 1)
for _, s := range outStrRune {
bounds, advance, _ := face.GlyphBounds(s)
outStrWidth += Int26ToFloat(advance)
if maxY := Int26ToFloat(bounds.Max.Y); maxY > MaxY {
MaxY = maxY
}
if minY := Int26ToFloat(bounds.Min.Y); minY < MinY {
MinY = minY
}
}
strRuneList := []rune(str.Str)
total := 0.00
if outStrPosition == "left" {
for i := len(strRuneList) - 1; i >= 0; i-- {
advance, _ := face.GlyphAdvance(strRuneList[i])
w := Int26ToFloat(advance)
if math.Ceil(total+w+outStrWidth) >= maxWidth {
if str.MaxY > MaxY {
MaxY = str.MaxY
}
if str.MinY < MinY {
MinY = str.MinY
}
return SplitText{
Str: outStr + string(strRuneList[i+1:]),
Width: total + outStrWidth,
MinY: MinY,
MaxY: MaxY,
}
}
total += w
}
}
for i := 0; i < len(strRuneList); i++ {
advance, _ := face.GlyphAdvance(strRuneList[i])
w := Int26ToFloat(advance)
if math.Ceil(total+w+outStrWidth) >= maxWidth {
if str.MaxY > MaxY {
MaxY = str.MaxY
}
if str.MinY < MinY {
MinY = str.MinY
}
return SplitText{
Str: string(strRuneList[:i]) + outStr,
Width: total + outStrWidth,
MinY: MinY,
MaxY: MaxY,
}
}
total += w
}
return str
}
//像素转换成磅
func pxToPoint(px float64, dpi float64) float64 {
return px * dpi / 72
}
type Text struct {
d IDrawString
fontSize int
dpi int
textAlign string
area image.Rectangle
maxLineNum int
outStr string
outStrPosition string
color color.RGBA
lineHeight int
overHidden bool
s string
//是否自动分行
autoLine bool
lines []string
}
func NewText(s string) *Text {
return &Text{
d: SiYuanHeiYi(),
fontSize: 24,
dpi: 72,
textAlign: "left",
color: color.RGBA{A: 255},
s: s,
autoLine: true,
outStrPosition: "right",
overHidden: true,
}
}
func NewLineText(linesText []string) *Text {
return &Text{
d: SiYuanHeiYi(),
fontSize: 24,
dpi: 72,
textAlign: "left",
color: color.RGBA{A: 255},
lines: linesText,
}
}
// SetTextAlign 设置字体对齐方式 left right center 默认left
func (t *Text) SetTextAlign(textAlign string) *Text {
if textAlign != "left" && textAlign != "right" && textAlign != "center" {
textAlign = "left"
}
t.textAlign = textAlign
return t
}
// SetArea 设置文本放置的区域 默认整个图片 (x,y)起点坐标 w宽度 h长度
func (t *Text) SetArea(x, y, w, h int) *Text {
t.area = image.Rect(x, y, x+w, y+h)
return t
}
// SetFontSize 设置字体大小 单位像素 默认24px
func (t *Text) SetFontSize(px int) *Text {
t.fontSize = px
return t
}
// SetDpi 设置dpi 默认72
func (t *Text) SetDpi(dpi int) *Text {
t.dpi = dpi
return t
}
// SetMaxLineNum 设置文本最大行数 默认不限制但超出区域返回后的行会截取掉
func (t *Text) SetMaxLineNum(num int) *Text {
t.maxLineNum = num
return t
}
// SetOutStr 设置文本超出后提示符 如`...` 默认空字符串
func (t *Text) SetOutStr(str string) *Text {
t.outStr = str
return t
}
// SetOutStrPosition 设置字符串省略的位置 left左边 right右边 默认右边
func (t *Text) SetOutStrPosition(position string) *Text {
if position == "left" || position == "right" {
t.outStrPosition = position
} else {
t.outStrPosition = "right"
}
return t
}
// SetFont 设置字体 默认字体思源黑体
func (t *Text) SetFont(drawString IDrawString) *Text {
t.d = drawString
return t
}
// SetLineHeight 设置行高 默认字体高度
func (t *Text) SetLineHeight(h int) *Text {
t.lineHeight = h
return t
}
// SetColor 设置字体颜色 默认黑色
func (t *Text) SetColor(rgba color.RGBA) *Text {
t.color = rgba
return t
}
// SetText 设置字符串
func (t *Text) SetText(s string) *Text {
t.s = s
t.lines = nil
return t
}
// SetAutoLine 设置字符串文本是否自动分行 autoLine文本是否自动分行 false不自动分行 true自动分行 默认true
func (t *Text) SetAutoLine(autoLine bool) *Text {
t.autoLine = autoLine
return t
}
// SetLineText 自定义多行字符串 每行字符串超出后都会按照 outStr处理
func (t *Text) SetLineText(lines []string) {
t.lines = lines
t.s = ""
}
func (t *Text) SetOverHidden(overHidden bool) *Text {
t.overHidden = overHidden
return t
}
//实现FillItem接口
func (t *Text) draw(dst draw.Image) (draw.Image, error) {
t.initDraw()
face, err := t.d.Face()
if err != nil {
return nil, err
}
//行高
lineHeight := t.lineHeight
if lineHeight <= 0 {
lineHeight = t.fontSize
}
//绘制区域
area := t.area
if area.Max.X == 0 && area.Max.Y == 0 {
area.Max = dst.Bounds().Max
}
maxWidth := float64(area.Max.X - area.Min.X)
maxHeight := float64(area.Max.Y - area.Min.Y)
var splitTextList []SplitText
if t.s != "" {
//将一个字符串按最大绘制宽度分割成多行字体
splitTextList, err = t.dealText(face, maxWidth, maxHeight, lineHeight)
} else {
//将一个字符串按最大绘制宽度分割成多行字体
splitTextList, err = t.dealLineText(face, maxWidth, maxHeight, lineHeight)
}
if err != nil {
return nil, err
}
//绘制字体
for i, text := range splitTextList {
//计算相对于绘制区域开始绘制位置
var startX float64
switch t.textAlign {
case "left":
startX = 0
case "center":
startX = (maxWidth - text.Width) / 2
case "right":
startX = maxWidth - text.Width
}
//计算偏移量
deviation := int(float64(lineHeight)/2 - text.MaxY + (text.MaxY-text.MinY)/2)
t.d.SetDot(freetype.Pt(area.Min.X+int(startX), area.Min.Y+i*lineHeight+deviation))
err = t.d.DrawString(text.Str, dst)
if err != nil {
return nil, err
}
}
return dst, nil
}
func (t *Text) Copy() *Text {
return &Text{
d: t.d,
fontSize: t.fontSize,
dpi: t.dpi,
textAlign: t.textAlign,
area: t.area,
maxLineNum: t.maxLineNum,
outStr: t.outStr,
outStrPosition: t.outStrPosition,
color: t.color,
lineHeight: t.lineHeight,
s: t.s,
lines: t.lines,
autoLine: t.autoLine,
overHidden: t.overHidden,
}
}
type CalcTextResult struct {
LineHeight int
MaxWidth float64
SplitTextList []SplitText
Height int
Width int
}
func (t *Text) Calc() (*CalcTextResult, error) {
t.initDraw()
//用于计算字体长度
face, err := t.d.Face()
if err != nil {
return nil, err
}
//行高
lineHeight := t.lineHeight
if lineHeight <= 0 {
lineHeight = t.fontSize
}
//用于存储绘制的最大长度
var maxWidth float64
//绘制区域
area := t.area
maxWidth = float64(area.Max.X - area.Min.X)
maxHeight := float64(area.Max.Y - area.Min.Y)
var splitTextList []SplitText
if t.s != "" {
//将一个字符串按最大绘制宽度分割成多行字体
splitTextList, err = t.dealText(face, maxWidth, maxHeight, lineHeight)
} else {
//将一个字符串按最大绘制宽度分割成多行字体
splitTextList, err = t.dealLineText(face, maxWidth, maxHeight, lineHeight)
}
if err != nil {
return nil, err
}
width := 0.00
height := 0
for _, item := range splitTextList {
if width < item.Width {
width = item.Width
}
height += lineHeight
}
return &CalcTextResult{
LineHeight: lineHeight,
MaxWidth: maxWidth,
SplitTextList: splitTextList,
Height: height,
Width: int(width),
}, nil
}
//转换自己设置的多行文本
func (t *Text) dealLineText(face font.Face, maxWidth, maxHeight float64, lineHeight int) ([]SplitText, error) {
list := make([]SplitText, 0)
var lines []string
maxLineNum := t.maxLineNum
if t.overHidden && int(maxHeight/float64(lineHeight)) < maxLineNum {
maxLineNum = int(maxHeight / float64(lineHeight))
}
if len(t.lines) > maxLineNum {
lines = t.lines[:maxLineNum]
}
for _, line := range lines {
list = append(list, dealSingleOut(face, str2SplitText(face, line), t.outStr, t.outStrPosition, maxWidth))
}
return list, nil
}
//转换字符串
func (t Text) dealText(face font.Face, maxWidth, maxHeight float64, lineHeight int) ([]SplitText, error) {
if t.autoLine == false {
return []SplitText{dealSingleOut(face, str2SplitText(face, t.s), t.outStr, t.outStrPosition, maxWidth)}, nil
}
maxLineNum := t.maxLineNum
if t.overHidden && int(maxHeight/float64(lineHeight)) < maxLineNum {
maxLineNum = int(maxHeight / float64(lineHeight))
}
return dealLineOut(face, splitText(face, t.s, maxWidth), t.outStr, t.outStrPosition, maxLineNum), nil
}
func (t *Text) Width() (int, error) {
result, err := t.Calc()
if err != nil {
return 0, err
}
return result.Width, nil
}
func (t *Text) Height() (int, error) {
result, err := t.Calc()
if err != nil {
return 0, err
}
return result.Height, nil
}
func (t *Text) initDraw() {
t.d.SetDpi(float64(t.dpi))
t.d.SetColor(t.color)
t.d.SetSize(float64(t.fontSize))
}
type IDrawString interface {
SetSize(size float64)
SetDpi(dpi float64)
SetDot(p fixed.Point26_6)
SetColor(c color.RGBA)
DrawString(s string, dst draw.Image) error
Face() (font.Face, error)
}
type OTFDraw struct {
font *opentype.Font
color color.RGBA
fontSize float64
dpi float64
dot fixed.Point26_6
}
func (o *OTFDraw) SetColor(c color.RGBA) {
o.color = c
}
func NewOTFDraw(font *opentype.Font) *OTFDraw {
return &OTFDraw{
font: font,
}
}
func NewOTFDrawFromFile(path string) *OTFDraw {
return &OTFDraw{
font: MustLoadOTF(path),
}
}
func NewOTFDrawFromHttp(url string) *OTFDraw {
return &OTFDraw{
font: MustLoadOTFHttp(url),
}
}
func (o *OTFDraw) Face() (font.Face, error) {
return o.face()
}
func (o *OTFDraw) face() (font.Face, error) {
return opentype.NewFace(o.font, &opentype.FaceOptions{
Size: o.fontSize,
DPI: o.dpi,
Hinting: font.HintingNone,
})
}
func (o *OTFDraw) SetSize(size float64) {
o.fontSize = size
}
func (o *OTFDraw) SetDpi(dpi float64) {
o.dpi = dpi
}
func (o *OTFDraw) SetDot(p fixed.Point26_6) {
o.dot = p
}
func (o *OTFDraw) DrawString(s string, dst draw.Image) error {
face, err := o.face()
if err != nil {
return err
}
d := font.Drawer{
Dst: dst,
Src: image.NewUniform(o.color),
Face: face,
Dot: o.dot,
}
d.DrawString(s)
return nil
}
type TTFDraw struct {
font *truetype.Font
color color.RGBA
fontSize float64
dpi float64
dot fixed.Point26_6
}
func NewTTFDrawFromFile(path string) *TTFDraw {
return &TTFDraw{
font: MustLoadTTF(path),
}
}
func NewTTFDrawFromHttp(url string) *TTFDraw {
return &TTFDraw{
font: MustLoadTTFHttp(url),
}
}
func NewTTFDraw(font *truetype.Font) *TTFDraw {
return &TTFDraw{
font: font,
}
}
func (t *TTFDraw) SetColor(c color.RGBA) {
t.color = c
}
func (t *TTFDraw) SetSize(size float64) {
t.fontSize = size
}
func (t *TTFDraw) SetDpi(dpi float64) {
t.dpi = dpi
}
func (t *TTFDraw) SetDot(p fixed.Point26_6) {
t.dot = p
}
func (t *TTFDraw) face() font.Face {
return truetype.NewFace(t.font, &truetype.Options{
Size: t.fontSize,
DPI: t.dpi,
Hinting: font.HintingNone,
})
}
func (t *TTFDraw) DrawString(s string, dst draw.Image) error {
ctx := t.context()
ctx.SetDst(dst)
ctx.SetClip(dst.Bounds())
_, err := ctx.DrawString(s, t.dot)
return err
}
func (t *TTFDraw) context() *freetype.Context {
ctx := freetype.NewContext()
//设置要绘制的图像
ctx.SetSrc(image.NewUniform(t.color))
//设置字体大小
ctx.SetFontSize(pxToPoint(t.fontSize, t.dpi))
//设置字体
ctx.SetFont(t.font)
//设置dpi
ctx.SetDPI(t.dpi)
return ctx
}
func (t *TTFDraw) Face() (font.Face, error) {
return t.face(), nil
}
func LoadTTF(path string) (*truetype.Font, error) {
data, err := ioutil.ReadFile(path)
if err != nil {
return nil, err
}
parseFont, err := freetype.ParseFont(data)
if err != nil {
return nil, err
}
return parseFont, nil
}
func LoadTTFHttp(url string) (*truetype.Font, error) {
resp, err := http.Get(url)
if err != nil {
return nil, err
}
defer resp.Body.Close()
data, err := ioutil.ReadAll(resp.Body)
if err != nil {
return nil, err
}
parseFont, err := freetype.ParseFont(data)
if err != nil {
return nil, err
}
return parseFont, nil
}
func MustLoadTTF(path string) *truetype.Font {
f, err := LoadTTF(path)
if err != nil {
panic(f)
}
return f
}
func MustLoadTTFHttp(url string) *truetype.Font {
f, err := LoadTTFHttp(url)
if err != nil {
panic(f)
}
return f
}
func mustLoadTTFBytes(data []byte) *truetype.Font {
parseFont, err := freetype.ParseFont(data)
if err != nil {
panic(err)
}
return parseFont
}
func LoadOTF(path string) (*opentype.Font, error) {
data, err := ioutil.ReadFile(path)
if err != nil {
return nil, err
}
parseFont, err := opentype.Parse(data)
if err != nil {
return nil, err
}
return parseFont, nil
}
func LoadOTFHttp(url string) (*opentype.Font, error) {
resp, err := http.Get(url)
if err != nil {
return nil, err
}
defer resp.Body.Close()
data, err := ioutil.ReadAll(resp.Body)
if err != nil {
return nil, err
}
parseFont, err := opentype.Parse(data)
if err != nil {
return nil, err
}
return parseFont, nil
}
func MustLoadOTF(path string) *opentype.Font {
f, err := LoadOTF(path)
if err != nil {
panic(f)
}
return f
}
func MustLoadOTFHttp(url string) *opentype.Font {
f, err := LoadOTFHttp(url)
if err != nil {
panic(f)
}
return f
}
func mustLoadOTFBytes(data []byte) *opentype.Font {
parseFont, err := opentype.Parse(data)
if err != nil {
panic(err)
}
return parseFont
}