diff --git a/table.go b/table.go index 15ebd87..947e083 100644 --- a/table.go +++ b/table.go @@ -4,6 +4,7 @@ import ( "fmt" "image/color" "math" + "sync" "github.com/fogleman/gg" ) @@ -39,6 +40,7 @@ type TableConfig struct { } type TableGenerator struct { + lock sync.RWMutex config *TableConfig 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 { + g.lock.Lock() + defer g.lock.Unlock() // 先创建一个临时上下文来测量文本 tempDC := gg.NewContext(1, 1) if err := g.loadHDFont(tempDC, g.config.FontSize); err != nil {