removed all trickery, left only plain draw2d calls
This commit is contained in:
parent
eca7b76ebc
commit
7c57ea38bb
1 changed files with 3 additions and 55 deletions
58
sync_test.go
58
sync_test.go
|
@ -1,23 +1,19 @@
|
||||||
// See also test_test.go
|
// go test --race -test.v sync_test.go
|
||||||
|
|
||||||
package draw2d_test
|
package draw2d_test
|
||||||
|
|
||||||
import (
|
import (
|
||||||
"fmt"
|
"fmt"
|
||||||
"github.com/golang/freetype/truetype"
|
|
||||||
"github.com/llgcode/draw2d"
|
"github.com/llgcode/draw2d"
|
||||||
"github.com/llgcode/draw2d/draw2dimg"
|
"github.com/llgcode/draw2d/draw2dimg"
|
||||||
"github.com/llgcode/draw2d/draw2dkit"
|
"github.com/llgcode/draw2d/draw2dkit"
|
||||||
"image"
|
"image"
|
||||||
"io/ioutil"
|
|
||||||
"path/filepath"
|
|
||||||
"sync"
|
|
||||||
"testing"
|
"testing"
|
||||||
)
|
)
|
||||||
|
|
||||||
func TestSync(t *testing.T) {
|
func TestSync(t *testing.T) {
|
||||||
ch := make(chan int)
|
ch := make(chan int)
|
||||||
limit := 200
|
limit := 2000
|
||||||
for i := 0; i < limit; i++ {
|
for i := 0; i < limit; i++ {
|
||||||
go Draw(i, ch)
|
go Draw(i, ch)
|
||||||
}
|
}
|
||||||
|
@ -29,8 +25,7 @@ func TestSync(t *testing.T) {
|
||||||
}
|
}
|
||||||
|
|
||||||
func Draw(i int, ch chan<- int) {
|
func Draw(i int, ch chan<- int) {
|
||||||
draw2d.SetFontCache(testCache)
|
draw2d.SetFontFolder("./resource/font")
|
||||||
|
|
||||||
// Draw a rounded rectangle using default colors
|
// Draw a rounded rectangle using default colors
|
||||||
dest := image.NewRGBA(image.Rect(0, 0, 297, 210.0))
|
dest := image.NewRGBA(image.Rect(0, 0, 297, 210.0))
|
||||||
gc := draw2dimg.NewGraphicContext(dest)
|
gc := draw2dimg.NewGraphicContext(dest)
|
||||||
|
@ -48,50 +43,3 @@ func Draw(i int, ch chan<- int) {
|
||||||
|
|
||||||
ch <- i
|
ch <- i
|
||||||
}
|
}
|
||||||
|
|
||||||
//testFontCache closely follows draw2d's defaultFontCache
|
|
||||||
type testFontCache struct {
|
|
||||||
fonts map[string]*truetype.Font
|
|
||||||
folder string
|
|
||||||
namer draw2d.FontFileNamer
|
|
||||||
}
|
|
||||||
|
|
||||||
func (cache *testFontCache) Load(fontData draw2d.FontData) (font *truetype.Font, err error) {
|
|
||||||
if font = cache.fonts[cache.namer(fontData)]; font != nil {
|
|
||||||
return font, nil
|
|
||||||
}
|
|
||||||
|
|
||||||
var data []byte
|
|
||||||
var file = cache.namer(fontData)
|
|
||||||
|
|
||||||
if data, err = ioutil.ReadFile(filepath.Join(cache.folder, file)); err != nil {
|
|
||||||
return
|
|
||||||
}
|
|
||||||
|
|
||||||
if font, err = truetype.Parse(data); err != nil {
|
|
||||||
return
|
|
||||||
}
|
|
||||||
|
|
||||||
var mu sync.Mutex
|
|
||||||
mu.Lock()
|
|
||||||
cache.fonts[file] = font
|
|
||||||
mu.Unlock()
|
|
||||||
return
|
|
||||||
}
|
|
||||||
|
|
||||||
func (cache *testFontCache) Store(fontData draw2d.FontData, font *truetype.Font) {
|
|
||||||
var mu sync.Mutex
|
|
||||||
mu.Lock()
|
|
||||||
cache.fonts[cache.namer(fontData)] = font
|
|
||||||
mu.Unlock()
|
|
||||||
}
|
|
||||||
|
|
||||||
var (
|
|
||||||
testFonts = &testFontCache{
|
|
||||||
fonts: make(map[string]*truetype.Font),
|
|
||||||
folder: "./resource/font",
|
|
||||||
namer: draw2d.FontFileName,
|
|
||||||
}
|
|
||||||
|
|
||||||
testCache draw2d.FontCache = testFonts
|
|
||||||
)
|
|
||||||
|
|
Loading…
Reference in a new issue