lock
This commit is contained in:
parent
724ee2c90b
commit
b1983d6777
4
table.go
4
table.go
|
@ -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 {
|
||||||
|
|
Loading…
Reference in New Issue