BurntSushi / xgbutil

A utility library to make use of the X Go Binding easier. (Implements EWMH and ICCCM specs, key binding support, etc.)
Do What The F*ck You Want To Public License
195 stars 45 forks source link

xgraphics: package depends on code.google.com/p/jamslam-freetype-go/freetype #32

Closed bmatsuo closed 8 years ago

bmatsuo commented 8 years ago

The package "code.google.com/p/jamslam-freetype-go/freetype" is going to disappear in January (last I heard). At that point the xgraphics package will not build.

It seems that the package requires the Context.MeasureString method which iirc was not available in "code.google.com/p/freetype-go/freetype".Context. I assume this was the original reason the "jamslam-" variant was used.

I have had similar requirements in the past. And I have used "jamslam" to meet them. Most recently when dealing with and trying to avoid code.google.com I found that I could achieve the MeasureString functionality by combining "github.com/golang/freetype" and "golang.org/x/image/font". You can look at my code. There is some weird rendering stuff going on in that program. But if you just trace back the types from the call site it should be fairly straightforward.

I think what it would boil down to in xgraphics/text.go would be something like the following (with some additional logic to create a font.Drawer):

w := f.MeasureString(text)
h := int(c.PointToFixed(fontSize) >> 6)

The height calculation is basically the same thing that "jamslam" is doing.

bmatsuo commented 8 years ago

Sorry, this is a dupe of #30. I will close and add my comment there.