|
|
|
|
|
by oefrha
1568 days ago
|
|
I took a quick glance at anafanafo and couldn't tell if porting to Go would be easy, since the structure seems slightly convoluted. Anyway, if the lookup table approach used by anafanafo isn't easy to implement, there's always the rendering approach, using something like Cairo. Code I whipped up in a few minutes: 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. |
|