feat(字体图像): 优化字体图像并修正签章裁剪
build.yaml / build (push) Successful in 3m41s

This commit is contained in:
xiaoqidun committed 2026-10-12 23:04:11 +08:00
1 parent 5d1fd593cd
commit f8263f798f
21 files changed
+1029 -336

No files matched your search

+36
View File
@@ -16,6 +16,8 @@ package ofdgo
import (
"container/list"
"image"
"reflect"
)
// renderCache 按估算字节数限制派生渲染数据,淘汰不修改源资源
@@ -85,3 +87,37 @@ func rasterCommandCost(command RasterCommand) int {
}
return cost
}
// rasterCommandsCost 估算整组指令保留的内存,同一图片实例只计一次
// 入参: commands 绘制指令, limit 缓存预算
// 返回: int 估算字节数,超预算时返回预算加一
func rasterCommandsCost(commands []RasterCommand, limit int) int {
limit = max(0, limit)
cost := 0
var images map[image.Image]bool
for _, command := range commands {
part := rasterCommandCost(command)
if part < 0 || part > limit-cost {
return limit + 1
}
cost += part
if command.Image == nil {
continue
}
if reflect.ValueOf(command.Image).Kind() == reflect.Pointer {
if images[command.Image] {
continue
}
if images == nil {
images = make(map[image.Image]bool)
}
images[command.Image] = true
}
part = imageResourceCost(command.Image, limit-cost)
if part > limit-cost {
return limit + 1
}
cost += part
}
return cost
}