by oefrha · 4y ago · 0 comments
package main
import (
"fmt"
"github.com/gotk3/gotk3/cairo"
)
var _cr *cairo.Context
func init() {
_cr = cairo.Create(cairo.CreateImageSurface(cairo.FORMAT_RGB24, 1000, 50))
_cr.SelectFontFace("Verdana", cairo.FONT_SLANT_NORMAL, cairo.FONT_WEIGHT_NORMAL)
_cr.SetFontSize(11)
}
func measureTextWidth(t string) float64 {
return _cr.TextExtents(t).Width
}
func main() {
measureAndPrint := func(t string) {
fmt.Println(t, measureTextWidth(t))
}
measureAndPrint("build")
// build 24.7177734375
measureAndPrint("passing")
// passing 39.767578125
}
Not sure if performance would be acceptable, though.