...

Source file src/github.com/golang/freetype/truetype/face_test.go

Documentation: github.com/golang/freetype/truetype

     1  // Copyright 2015 The Freetype-Go Authors. All rights reserved.
     2  // Use of this source code is governed by your choice of either the
     3  // FreeType License or the GNU General Public License version 2 (or
     4  // any later version), both of which can be found in the LICENSE file.
     5  
     6  package truetype
     7  
     8  import (
     9  	"image"
    10  	"image/draw"
    11  	"io/ioutil"
    12  	"strings"
    13  	"testing"
    14  
    15  	"golang.org/x/image/font"
    16  	"golang.org/x/image/math/fixed"
    17  )
    18  
    19  func BenchmarkDrawString(b *testing.B) {
    20  	data, err := ioutil.ReadFile("../licenses/gpl.txt")
    21  	if err != nil {
    22  		b.Fatal(err)
    23  	}
    24  	lines := strings.Split(string(data), "\n")
    25  	data, err = ioutil.ReadFile("../testdata/luxisr.ttf")
    26  	if err != nil {
    27  		b.Fatal(err)
    28  	}
    29  	f, err := Parse(data)
    30  	if err != nil {
    31  		b.Fatal(err)
    32  	}
    33  	dst := image.NewRGBA(image.Rect(0, 0, 800, 600))
    34  	draw.Draw(dst, dst.Bounds(), image.White, image.ZP, draw.Src)
    35  	d := &font.Drawer{
    36  		Dst:  dst,
    37  		Src:  image.Black,
    38  		Face: NewFace(f, nil),
    39  	}
    40  	b.ReportAllocs()
    41  	b.ResetTimer()
    42  	for i := 0; i < b.N; i++ {
    43  		for j, line := range lines {
    44  			d.Dot = fixed.P(0, (j*16)%600)
    45  			d.DrawString(line)
    46  		}
    47  	}
    48  }
    49  

View as plain text