mirror of
https://github.com/xiaoqidun/ofdgo.git
synced 2026-08-30 12:12:40 +08:00
+1
-18
@@ -205,9 +205,6 @@ func (r *Renderer) fontSourceMatch(fontID string, font *Font) (fontSource, bool)
|
|||||||
}
|
}
|
||||||
continue
|
continue
|
||||||
}
|
}
|
||||||
if source.kind != fontSourceSystem {
|
|
||||||
return source, true
|
|
||||||
}
|
|
||||||
family := canvas.NewFontFamily(font.FontName)
|
family := canvas.NewFontFamily(font.FontName)
|
||||||
if r.loadFontSource(family, source, style) != nil {
|
if r.loadFontSource(family, source, style) != nil {
|
||||||
return source, true
|
return source, true
|
||||||
@@ -230,7 +227,7 @@ func (r *Renderer) loadFontSource(family *canvas.FontFamily, source fontSource,
|
|||||||
err = family.LoadFontFile(source.name, style)
|
err = family.LoadFontFile(source.name, style)
|
||||||
case fontSourceFS:
|
case fontSourceFS:
|
||||||
var data []byte
|
var data []byte
|
||||||
data, err = readFontData(r.fontFS[source.index], source.name)
|
data, err = fs.ReadFile(r.fontFS[source.index], source.name)
|
||||||
if err == nil {
|
if err == nil {
|
||||||
err = family.LoadFont(data, 0, style)
|
err = family.LoadFont(data, 0, style)
|
||||||
}
|
}
|
||||||
@@ -245,20 +242,6 @@ func (r *Renderer) loadFontSource(family *canvas.FontFamily, source fontSource,
|
|||||||
return family
|
return family
|
||||||
}
|
}
|
||||||
|
|
||||||
// readFontData 读取字体文件数据
|
|
||||||
// 入参: fsys 字体文件系统, name 字体文件名
|
|
||||||
// 返回: []byte 字体文件数据, error 错误信息
|
|
||||||
func readFontData(fsys fs.FS, name string) ([]byte, error) {
|
|
||||||
if fontFS, ok := fsys.(*FontFS); ok {
|
|
||||||
data, ok := fontFS.files[cleanFontName(name)]
|
|
||||||
if !ok {
|
|
||||||
return nil, fs.ErrNotExist
|
|
||||||
}
|
|
||||||
return data, nil
|
|
||||||
}
|
|
||||||
return fs.ReadFile(fsys, name)
|
|
||||||
}
|
|
||||||
|
|
||||||
// matchFontFiles 查找字体文件
|
// matchFontFiles 查找字体文件
|
||||||
// 入参: dir 目录, patterns 模式列表, bold 是否粗体, italic 是否斜体
|
// 入参: dir 目录, patterns 模式列表, bold 是否粗体, italic 是否斜体
|
||||||
// 返回: []string 文件列表
|
// 返回: []string 文件列表
|
||||||
|
|||||||
Reference in New Issue
Block a user