This commit is contained in:
jiangyong 2025-10-06 11:58:32 +08:00
parent 724ee2c90b
commit b1983d6777
1 changed files with 4 additions and 0 deletions

View File

@ -4,6 +4,7 @@ import (
"fmt" "fmt"
"image/color" "image/color"
"math" "math"
"sync"
"github.com/fogleman/gg" "github.com/fogleman/gg"
) )
@ -39,6 +40,7 @@ type TableConfig struct {
} }
type TableGenerator struct { type TableGenerator struct {
lock sync.RWMutex
config *TableConfig config *TableConfig
dc *gg.Context dc *gg.Context
} }
@ -279,6 +281,8 @@ func (g *TableGenerator) drawTitle(dc *gg.Context, margin, tableWidth float64, t
// 生成自适应表格(高清版本) // 生成自适应表格(高清版本)
func (g *TableGenerator) Generate(data *TableData, filename string) error { func (g *TableGenerator) Generate(data *TableData, filename string) error {
g.lock.Lock()
defer g.lock.Unlock()
// 先创建一个临时上下文来测量文本 // 先创建一个临时上下文来测量文本
tempDC := gg.NewContext(1, 1) tempDC := gg.NewContext(1, 1)
if err := g.loadHDFont(tempDC, g.config.FontSize); err != nil { if err := g.loadHDFont(tempDC, g.config.FontSize); err != nil {