From 32beda3c90afd164858668e3f392c0a279899067 Mon Sep 17 00:00:00 2001 From: =?UTF-8?q?P=C5=99emysl=20Janouch?= Date: Thu, 23 Aug 2018 02:46:56 +0200 Subject: xgb-render: slightly simplify --- prototypes/xgb-xrender.go | 54 ++++++++++++++++++++--------------------------- 1 file changed, 23 insertions(+), 31 deletions(-) (limited to 'prototypes') diff --git a/prototypes/xgb-xrender.go b/prototypes/xgb-xrender.go index 6e07b4e..5fbdf36 100644 --- a/prototypes/xgb-xrender.go +++ b/prototypes/xgb-xrender.go @@ -11,6 +11,7 @@ import ( "golang.org/x/image/font/gofont/goregular" "golang.org/x/image/math/fixed" "image" + "image/draw" "log" "math/rand" ) @@ -223,33 +224,13 @@ func main() { log.Fatalln(err) } - c := freetype.NewContext() - c.SetDPI(96) // TODO: Take this from the screen or monitor. - c.SetFont(f) - c.SetFontSize(9) - c.SetSrc(image.White) - c.SetHinting(font.HintingFull) - // TODO: Seems like we want to use NRGBA. Or RGBA if the A is always 1. - // Or implement our own image.Image for direct gamma-corrected RGB! - nrgb := image.NewRGBA(image.Rect(0, 0, 36, 36)) - c.SetClip(nrgb.Bounds()) - c.SetDst(nrgb) - - bounds := f.Bounds(c.PointToFixed(9 /* FIXME: Duplication. */)) - log.Println("+%v", bounds) - - // FIXME: Duplication. - opts := truetype.Options{ - Size: 9, - DPI: 96, + opts := &truetype.Options{ + Size: 9, + DPI: 96, // TODO: Take this from the screen or monitor. + Hinting: font.HintingFull, } + face := truetype.NewFace(f, opts) - // TODO: Seems this satisfies the sfnt interface, DrawString just adds - // kerning and DrawMask on top. - face := truetype.NewFace(f, &opts) - _ = face - - // TODO: Figure out a way to load glyphs into XRender. var rgbFormat render.Pictformat for _, pf := range pformats.Formats { // Hopefully. Might want to check ARGB/BGRA. @@ -268,17 +249,28 @@ func main() { // NOTE: A depth of 24 will not work, the server always rejects it. _ = render.CreateGlyphSet(X, gsid, rgbFormat) + //bounds := f.Bounds(c.PointToFixed(opts.Size)) + //log.Println("+%v", bounds) + + // TODO: Seems like we want to use NRGBA. Or RGBA if the A is always 1. + // Or implement our own image.Image for direct gamma-corrected RGB! + nrgb := image.NewRGBA(image.Rect(0, 0, 36, 36)) + //nrgb.Bounds() + for r := rune(32); r < 128; r++ { + dr, mask, maskp, advance, ok := face.Glyph( + fixed.P(0, 18) /* subpixel destination location */, r) + if !ok { + log.Println("skip") + continue + } + for i := 0; i < len(nrgb.Pix); i++ { nrgb.Pix[i] = 0 } - advance, err := c.DrawString(string(r), fixed.P(18, 18)) - _, _ = advance, err - if err != nil { - log.Println("skip") - continue - } + draw.Draw(nrgb, dr, mask, maskp, draw.Src) + _ = advance _ = render.AddGlyphs(X, gsid, 1, []uint32{uint32(r)}, []render.Glyphinfo{{ -- cgit v1.2.3