by oefrha · 4y ago · 0 comments
I looked at the anafanafo package now and one of the first things they say in the presentation is "Built with Shields in mind"... So this package was custom made for shields.io, apparently. From a very quick check it seems to be a non-trivial amount of code, so not super simple to just port to Golang.
I don't want to have to start running Node and NPM packages, but would be very interested in any way to get this kind of functionality in a Go program.
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.