3 ms·
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
by oefrha 5y 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.
- rlonn 5y agoThat looks interesting. I'm installing Cairo right now - a bit of a beast though. I'll test it but might try to port the anafanafo functionality anyway. It'd be very nice to just have 100 lines of Go code and a JSON data file to deal with.