1 回答

TA貢獻1818條經驗 獲得超3個贊
是的,這可以通過https://github.com/tdewolff/canvas實現(我是主要作者)。您可以在https://github.com/tdewolff/canvas/blob/master/examples/preview/main.go#L89看到一個示例(結果在https://github.com/tdewolff/canvas/blob/master/ examples/preview/out.png),我在其中加載字體并將一段文本轉換為矢量路徑。
使用 tdewolff/canvas,以下內容應該適用于您的情況(未經測試):
fontFamily := canvas.NewFontFamily("Lato")
if err := fontFamily.LoadFontFile("Lato-Bold.ttf", canvas.FontBold); err != nil {
panic(err)
}
face := fontFamily.Face(14.0, canvas.Black, canvas.FontBold, canvas.FontNormal)
path, err := face.ToPath("Change me to svg path")
if err != nil {
panic(err)
}
tpl := `<svg xmlns:xlink="http://www.w3.org/1999/xlink" xmlns="http://www.w3.org/2000/svg" height="400" width="800">
<path d="%s" />
</svg>`
fmt.Printf(tpl, path.ToSVG())
- 1 回答
- 0 關注
- 638 瀏覽
添加回答
舉報