mirror of
https://github.com/xiaoqidun/ofdgo.git
synced 2026-10-29 17:27:08 +08:00
1 parent
6c3068b813
commit
cfbaa8a177
5 files changed
+28
-21
No files matched your search
@@ -21,9 +21,9 @@ import (
|
|||||||
)
|
)
|
||||||
|
|
||||||
// compressionFontUsage 按文档合并共享字体用字,版本编辑仅统计选中入口
|
// compressionFontUsage 按文档合并共享字体用字,版本编辑仅统计选中入口
|
||||||
// 入参: ctx 取消上下文, parts 输出改动, generated 自产页面引用, documents 文档入口, resources 资源索引, references 各文件引用, read 输出文件读取方法
|
// 入参: ctx 取消上下文, documents 文档入口, resources 资源索引, references 各文件引用, read 输出文件读取方法
|
||||||
// 返回: map[string]*editorFontUsage 各字体文件的用字,无法确定作用域时为空, error 读取或取消错误
|
// 返回: map[string]*editorFontUsage 各字体文件的用字,无法确定作用域时为空, error 读取或取消错误
|
||||||
func (r *Reader) compressionFontUsage(ctx context.Context, parts map[string][]byte, generated map[string]editorGeneratedReferences, documents map[string]bool, resources []string, references map[string]*editorResourceRefs, read func(string) ([]byte, error)) (map[string]*editorFontUsage, error) {
|
func (r *Reader) compressionFontUsage(ctx context.Context, documents map[string]bool, resources []string, references map[string]*editorResourceRefs, read func(string) ([]byte, error)) (map[string]*editorFontUsage, error) {
|
||||||
selected := ""
|
selected := ""
|
||||||
if r.OFD.DocBody[r.documentIndex].versioned {
|
if r.OFD.DocBody[r.documentIndex].versioned {
|
||||||
var err error
|
var err error
|
||||||
@@ -32,7 +32,7 @@ func (r *Reader) compressionFontUsage(ctx context.Context, parts map[string][]by
|
|||||||
return nil, err
|
return nil, err
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
scoped, err := r.resourceReferenceScopes(ctx, parts, generated, documents, resources, references, selected)
|
scoped, err := resourceReferenceScopes(ctx, documents, resources, references, selected)
|
||||||
if err != nil || scoped == nil {
|
if err != nil || scoped == nil {
|
||||||
return nil, err
|
return nil, err
|
||||||
}
|
}
|
||||||
|
|||||||
@@ -92,7 +92,7 @@ func (e *Editor) compressResourceReferences(parts map[string][]byte, reader *Rea
|
|||||||
}
|
}
|
||||||
}
|
}
|
||||||
collect := reader != nil && reader.DocumentCount() > 1 && e.backends.FontResources != nil
|
collect := reader != nil && reader.DocumentCount() > 1 && e.backends.FontResources != nil
|
||||||
refs, resources, fontReferences, safe, err := scanEditorResources(e.output.ctx, reader, parts, generated, names, nil, collect)
|
refs, resources, references, safe, err := scanEditorResources(e.output.ctx, reader, parts, generated, names, nil, collect)
|
||||||
if err != nil || !safe {
|
if err != nil || !safe {
|
||||||
return err
|
return err
|
||||||
}
|
}
|
||||||
@@ -143,8 +143,8 @@ func (e *Editor) compressResourceReferences(parts map[string][]byte, reader *Rea
|
|||||||
}
|
}
|
||||||
}
|
}
|
||||||
var fontUsage map[string]*editorFontUsage
|
var fontUsage map[string]*editorFontUsage
|
||||||
if fontReferences != nil {
|
if references != nil {
|
||||||
fontUsage, err = reader.compressionFontUsage(e.output.ctx, parts, generated, refs.documents, resources, fontReferences, read)
|
fontUsage, err = reader.compressionFontUsage(e.output.ctx, refs.documents, resources, references, read)
|
||||||
if err != nil {
|
if err != nil {
|
||||||
return err
|
return err
|
||||||
}
|
}
|
||||||
|
|||||||
@@ -133,7 +133,7 @@ func scanEditorResources(ctx context.Context, reader *Reader, parts map[string][
|
|||||||
if resource {
|
if resource {
|
||||||
resources = append(resources, name)
|
resources = append(resources, name)
|
||||||
}
|
}
|
||||||
if collect && (resource || len(local.ids) != 0 || len(local.fonts) != 0) {
|
if collect {
|
||||||
references[name] = local
|
references[name] = local
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|||||||
@@ -20,10 +20,10 @@ import (
|
|||||||
"slices"
|
"slices"
|
||||||
)
|
)
|
||||||
|
|
||||||
// resourceReferenceScopes 按文档归集资源标识和字体用字,同文档索引共用只读结果,跨文档索引独立合并
|
// resourceReferenceScopes 复用结构依赖归集文档引用,同文档索引共用只读结果,跨文档索引独立合并
|
||||||
// 入参: ctx 取消上下文, parts 输出改动, generated 自产页面引用, documents 文档入口, resources 资源索引, references 文件引用, selected 限定的文档入口,空值统计全部文档
|
// 入参: ctx 取消上下文, documents 文档入口, resources 资源索引, references 文件引用, selected 限定的文档入口,空值统计全部文档
|
||||||
// 返回: map[string]*editorResourceRefs 各资源索引的引用,存在无法归属的引用时为空, error 读取或取消错误
|
// 返回: map[string]*editorResourceRefs 各资源索引的引用,依赖不完整或引用无法归属时为空, error 取消错误
|
||||||
func (r *Reader) resourceReferenceScopes(ctx context.Context, parts map[string][]byte, generated map[string]editorGeneratedReferences, documents map[string]bool, resources []string, references map[string]*editorResourceRefs, selected string) (map[string]*editorResourceRefs, error) {
|
func resourceReferenceScopes(ctx context.Context, documents map[string]bool, resources []string, references map[string]*editorResourceRefs, selected string) (map[string]*editorResourceRefs, error) {
|
||||||
indexes := make(map[string]bool, len(resources))
|
indexes := make(map[string]bool, len(resources))
|
||||||
for _, name := range resources {
|
for _, name := range resources {
|
||||||
indexes[name] = true
|
indexes[name] = true
|
||||||
@@ -32,19 +32,26 @@ func (r *Reader) resourceReferenceScopes(ctx context.Context, parts map[string][
|
|||||||
result := make(map[string]*editorResourceRefs)
|
result := make(map[string]*editorResourceRefs)
|
||||||
shared := make(map[string]bool)
|
shared := make(map[string]bool)
|
||||||
for _, entry := range slices.Sorted(maps.Keys(documents)) {
|
for _, entry := range slices.Sorted(maps.Keys(documents)) {
|
||||||
scope, err := r.versionFileDependencies(ctx, entry, parts, generated)
|
scope := map[string]bool{entry: true}
|
||||||
if err != nil {
|
queue := []string{entry}
|
||||||
return nil, err
|
|
||||||
}
|
|
||||||
refs := &editorResourceRefs{ids: make(map[string]bool), fonts: make(map[string]*editorFontUsage)}
|
refs := &editorResourceRefs{ids: make(map[string]bool), fonts: make(map[string]*editorFontUsage)}
|
||||||
for name := range scope {
|
for position := 0; position < len(queue); position++ {
|
||||||
if err := ctx.Err(); err != nil {
|
if err := ctx.Err(); err != nil {
|
||||||
return nil, err
|
return nil, err
|
||||||
}
|
}
|
||||||
if source := references[name]; source != nil {
|
name := queue[position]
|
||||||
used[name] = true
|
source := references[name]
|
||||||
if selected == "" || selected == entry {
|
if source == nil {
|
||||||
refs.merge(&editorResourceRefs{ids: source.ids, fonts: source.fonts})
|
return nil, ctx.Err()
|
||||||
|
}
|
||||||
|
used[name] = true
|
||||||
|
if selected == "" || selected == entry {
|
||||||
|
refs.merge(&editorResourceRefs{ids: source.ids, fonts: source.fonts})
|
||||||
|
}
|
||||||
|
for target, role := range source.roles {
|
||||||
|
if role&packageReferenceXML != 0 && !scope[target] {
|
||||||
|
scope[target] = true
|
||||||
|
queue = append(queue, target)
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|||||||
@@ -101,7 +101,7 @@ func (e *Editor) compactSourceReferences(parts map[string][]byte, progress edito
|
|||||||
return nil, err
|
return nil, err
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
scoped, err = reader.resourceReferenceScopes(ctx, parts, generated, refs.documents, resources, references, selected)
|
scoped, err = resourceReferenceScopes(ctx, refs.documents, resources, references, selected)
|
||||||
if err != nil || scoped == nil {
|
if err != nil || scoped == nil {
|
||||||
return nil, err
|
return nil, err
|
||||||
}
|
}
|
||||||
|
|||||||
Reference in new issue
Block a user