feat(后端架构): 优化多后端渲染,修复描边与字形校验
build.yaml / build (push) Successful in 40s

This commit is contained in:
xiaoqidun committed 2026-09-23 20:04:48 +08:00
1 parent f44d0d8a60
commit 580e7043c4
31 files changed
+1488 -204

No files matched your search

+9 -4
View File
@@ -15,6 +15,7 @@
package ofdgo
import (
"crypto/sha256"
"fmt"
"math"
"strings"
@@ -47,14 +48,18 @@ type glyphOutlineKey struct {
// 入参: prepared 已包装字体
// 返回: FontMetrics 字体度量, error 字体解析错误
func (r *Renderer) preparedMetrics(prepared *PreparedFont) (FontMetrics, error) {
if metrics := r.fontMetrics[prepared]; metrics != nil {
if prepared.digest == ([32]byte{}) {
prepared.digest = sha256.Sum256(prepared.Data)
}
key := prepared.digest
if metrics, ok := r.fontMetrics.get(key); ok {
return metrics, nil
}
metrics, err := r.backends.Fonts.OpenFont(prepared.Data)
if err != nil {
return nil, err
}
r.fontMetrics[prepared] = metrics
r.fontMetrics.put(key, metrics, len(prepared.Data)*2+256)
return metrics, nil
}
@@ -63,7 +68,7 @@ func (r *Renderer) preparedMetrics(prepared *PreparedFont) (FontMetrics, error)
// 返回: GeometryPath 字形路径, error 能力或解析错误
func (r *Renderer) preparedOutline(prepared *PreparedFont, metrics FontMetrics, glyph uint16, size float64) (GeometryPath, error) {
key := glyphOutlineKey{prepared, glyph, size}
if path, ok := r.glyphOutlines[key]; ok {
if path, ok := r.glyphOutlines.get(key); ok {
return path, nil
}
provider, ok := metrics.(FontOutlines)
@@ -72,7 +77,7 @@ func (r *Renderer) preparedOutline(prepared *PreparedFont, metrics FontMetrics,
}
path, err := provider.GlyphOutline(glyph, size)
if err == nil {
r.glyphOutlines[key] = path
r.glyphOutlines.put(key, path, len(path)*96+128)
}
return path, err
}