mirror of
https://github.com/xiaoqidun/ofdgo.git
synced 2026-10-29 08:46:55 +08:00
1 parent
81e6657c65
commit
0508029387
13 files changed
+1135
-1079
No files matched your search
+1
-35
@@ -85,7 +85,7 @@ func (e *Editor) SetPageCompiler(compiler PageCompiler) {
|
||||
// 入参: backends 后端组合,未配置的能力不会沿用默认实现
|
||||
func (e *Editor) SetRenderBackends(backends RenderBackends) {
|
||||
fontsChanged := !sameBackend(e.backends.Fonts, backends.Fonts)
|
||||
if !sameBackend(e.backends.Resources, backends.Resources) {
|
||||
if !sameBackend(e.backends.FontResources, backends.FontResources) {
|
||||
e.fonts = make(map[string]*FontResource)
|
||||
for i := range e.resources {
|
||||
e.resources[i].subset = nil
|
||||
@@ -565,40 +565,6 @@ func (e *Editor) nextID() string {
|
||||
return strconv.Itoa(e.maxID)
|
||||
}
|
||||
|
||||
// AddFont 注册OpenType字体,集合字体按索引提取,重复资源复用标识,引用后写入文档
|
||||
// 入参: file 字体文件, index 集合内字体索引,单字体为0
|
||||
// 返回: string 字体资源标识, error 错误信息
|
||||
func (e *Editor) AddFont(file FontFile, index int) (string, error) {
|
||||
if e.backends.Resources == nil {
|
||||
return "", fmt.Errorf("font resources: %w", ErrBackendUnavailable)
|
||||
}
|
||||
parsed, err := e.backends.Resources.OpenFontResource(file, index)
|
||||
if err != nil {
|
||||
return "", err
|
||||
}
|
||||
data := parsed.Data
|
||||
key := editorResourceKey{checksum: sha256.Sum256(data)}
|
||||
if id, ok := e.resourceID[key]; ok {
|
||||
return id, nil
|
||||
}
|
||||
if err := e.prepareSourceIDs(); err != nil {
|
||||
return "", err
|
||||
}
|
||||
id := e.nextID()
|
||||
definition := parsed.Font
|
||||
definition.ID = id
|
||||
resource := editorResource{
|
||||
name: e.packageName("Res/Fonts/Font_" + id + parsed.Extension),
|
||||
data: data,
|
||||
font: &definition,
|
||||
}
|
||||
resource.font.FontFile = "/" + resource.name
|
||||
e.resources = append(e.resources, resource)
|
||||
e.fonts[id] = parsed
|
||||
e.resourceID[key] = id
|
||||
return id, nil
|
||||
}
|
||||
|
||||
// AddImage 注册PNG或JPEG图片,重复资源复用标识,引用后写入文档
|
||||
// 不透明纯黑白PNG仅在无损JBIG2编码更小时转换,其他图片保留原始编码
|
||||
// 入参: data 图片数据
|
||||
|
||||
Reference in new issue
Block a user