feat(编辑能力): 修复字体编辑错配,优化来源标识
build.yaml / build (push) Successful in 37s

This commit is contained in:
xiaoqidun committed 2026-09-16 19:11:33 +08:00
1 parent 1914b5329a
commit f9646c70e9
8 files changed
+163 -68

No files matched your search

+25
View File
@@ -15,6 +15,7 @@
package ofdgo
import (
"bytes"
"encoding/xml"
"fmt"
"io"
@@ -75,6 +76,30 @@ func (r *Reader) Fonts() ([]Font, error) {
return fonts, nil
}
// FontData 读取内嵌字体,集合按声明名称和样式提取为独立字体,其他格式保留原始字节
// 入参: id 字体资源标识
// 返回: []byte 字体数据, error 资源缺失或集合解析错误
func (r *Reader) FontData(id string) ([]byte, error) {
if r.fontCache[id] == nil {
if _, err := r.Fonts(); err != nil {
return nil, err
}
}
f := r.fontCache[id]
if f == nil || f.FontFile == "" {
return nil, fmt.Errorf("embedded font %q not found", id)
}
data, err := r.ResData(f.FontFile)
if err != nil {
return nil, err
}
if bytes.HasPrefix(data, []byte("ttcf")) {
index := fontCollectionIndex(data, []string{f.FontName, f.FamilyName}, f.Bold, f.Italic)
return extractCollectionFont(data, index)
}
return data, nil
}
// FontInfos 获取OFD字体诊断信息
// 返回: []FontInfo 字体诊断列表, error 错误信息
func (r *Renderer) FontInfos() ([]FontInfo, error) {