feat(编辑能力): 修复字体切换预览残留
build.yaml / build (push) Successful in 53s

This commit is contained in:
xiaoqidun committed 2026-10-13 19:47:53 +08:00
1 parent ddf0dda283
commit aedc1493fb
3 files changed
+28 -7

No files matched your search

+6
View File
@@ -62,6 +62,7 @@ type FontProcessOptions struct {
type editorFontChange struct { type editorFontChange struct {
patches map[string][]editorXMLPatch patches map[string][]editorXMLPatch
files map[string][]byte files map[string][]byte
fonts []string
} }
// editorBindingFontCache 仅保留当前文档最近读取的字体文件及最近解析结果,操作结束后释放 // editorBindingFontCache 仅保留当前文档最近读取的字体文件及最近解析结果,操作结束后释放
@@ -197,6 +198,7 @@ func (e *Editor) ProcessFontsWithOptions(ctx context.Context, options FontProces
pending.patches[name] = append(pending.patches[name], patches...) pending.patches[name] = append(pending.patches[name], patches...)
} }
maps.Copy(pending.files, change.files) maps.Copy(pending.files, change.files)
pending.fonts = append(pending.fonts, change.fonts...)
} }
report = append(report, item) report = append(report, item)
if err := progress("fonts", len(report), total); err != nil { if err := progress("fonts", len(report), total); err != nil {
@@ -378,6 +380,7 @@ func (e *Editor) prepareFontBinding(ctx context.Context, scan *editorFontDocumen
return nil, err return nil, err
} }
change.patches[declaration.file.name] = append(change.patches[declaration.file.name], editorXMLPatch{node.start, node.end, fragment}) change.patches[declaration.file.name] = append(change.patches[declaration.file.name], editorXMLPatch{node.start, node.end, fragment})
change.fonts = append(change.fonts, editorResourceID(id))
return change, nil return change, nil
} }
@@ -398,6 +401,9 @@ func (c *editorFontChange) apply(ctx context.Context, scan *editorFontDocument)
} }
changes[name] = editorPatchXML(scan.files[name].data, patches) changes[name] = editorPatchXML(scan.files[name].data, patches)
} }
if err := invalidateResourcePreviews(ctx, scan, changes, c.fonts...); err != nil {
return err
}
return scan.apply(ctx, changes) return scan.apply(ctx, changes)
} }
+21 -6
View File
@@ -274,7 +274,7 @@ func (e *Editor) changeResource(ctx context.Context, kind, id string, replace fu
return nil return nil
} }
if replace != nil && kind == "Image" { if replace != nil && kind == "Image" {
if err := invalidateResourcePreviews(ctx, catalog.scan, item.ID, changes); err != nil { if err := invalidateResourcePreviews(ctx, catalog.scan, changes, item.ID); err != nil {
return err return err
} }
} }
@@ -346,16 +346,30 @@ func validateResourceImageMask(ctx context.Context, catalog *resourceCatalog, id
return ctx.Err() return ctx.Err()
} }
// invalidateResourcePreviews 沿颜色、绘制参数和复合引用移除资源变化后失效的替换图及底纹预览 // invalidateResourcePreviews 沿字体、颜色、绘制参数和复合引用移除资源变化后失效的替换图及底纹预览
// 入参: ctx 取消上下文, scan 当前文档结构, id 资源标识, changes 待提交文件 // 入参: ctx 取消上下文, scan 当前文档结构, changes 待提交文件, ids 资源标识
// 返回: error 解析或取消错误 // 返回: error 解析或取消错误
func invalidateResourcePreviews(ctx context.Context, scan *editorFontDocument, id string, changes map[string][]byte) error { func invalidateResourcePreviews(ctx context.Context, scan *editorFontDocument, changes map[string][]byte, ids ...string) error {
doc, err := scan.reader.DocContext(ctx) if len(ids) == 0 {
return ctx.Err()
}
reader := scan.reader
if scan.index != reader.DocumentIndex() {
var err error
reader, err = reader.DocumentContext(ctx, scan.index)
if err != nil {
return err
}
}
doc, err := reader.DocContext(ctx)
if err != nil { if err != nil {
return err return err
} }
defaultCS := strconv.Itoa(doc.CommonData.DefaultCS) defaultCS := strconv.Itoa(doc.CommonData.DefaultCS)
affected := map[string]bool{id: true} affected := make(map[string]bool, len(ids))
for _, id := range ids {
affected[editorResourceID(id)] = true
}
for { for {
count := len(affected) count := len(affected)
for name, file := range scan.files { for name, file := range scan.files {
@@ -378,6 +392,7 @@ func invalidateResourcePreviews(ctx context.Context, scan *editorFontDocument, i
} }
primary := affected[editorResourceID(node.attr("ResourceID"))] || affected[editorResourceID(node.attr("ImageMask"))] primary := affected[editorResourceID(node.attr("ResourceID"))] || affected[editorResourceID(node.attr("ImageMask"))]
changed := primary || affected[editorResourceID(node.attr("Substitution"))] || affected[editorResourceID(node.attr("DrawParam"))] || affected[editorResourceID(node.attr("ColorSpace"))] changed := primary || affected[editorResourceID(node.attr("Substitution"))] || affected[editorResourceID(node.attr("DrawParam"))] || affected[editorResourceID(node.attr("ColorSpace"))]
changed = changed || affected[editorResourceID(node.attr("Font"))]
if resourceColorNode(node) && node.attr("ColorSpace") == "" { if resourceColorNode(node) && node.attr("ColorSpace") == "" {
changed = changed || affected[defaultCS] changed = changed || affected[defaultCS]
} }
+1 -1
View File
@@ -431,7 +431,7 @@ func replaceResourceStyle(ctx context.Context, catalog *resourceCatalog, item Re
if err := validateResourceStyleGraph(ctx, catalog, item.ID, changes); err != nil { if err := validateResourceStyleGraph(ctx, catalog, item.ID, changes); err != nil {
return err return err
} }
return invalidateResourcePreviews(ctx, catalog.scan, item.ID, changes) return invalidateResourcePreviews(ctx, catalog.scan, changes, item.ID)
} }
// resourceColorNode 判断可携带基本颜色或复杂填充的标准节点 // resourceColorNode 判断可携带基本颜色或复杂填充的标准节点