xgb-render: slightly simplify

This commit is contained in:
Přemysl Eric Janouch 2018-08-23 02:46:56 +02:00
parent 30f2366f9a
commit 32beda3c90
Signed by: p
GPG Key ID: A0420B94F92B9493
1 changed files with 23 additions and 31 deletions

View File

@ -11,6 +11,7 @@ import (
"golang.org/x/image/font/gofont/goregular" "golang.org/x/image/font/gofont/goregular"
"golang.org/x/image/math/fixed" "golang.org/x/image/math/fixed"
"image" "image"
"image/draw"
"log" "log"
"math/rand" "math/rand"
) )
@ -223,33 +224,13 @@ func main() {
log.Fatalln(err) log.Fatalln(err)
} }
c := freetype.NewContext() opts := &truetype.Options{
c.SetDPI(96) // TODO: Take this from the screen or monitor. Size: 9,
c.SetFont(f) DPI: 96, // TODO: Take this from the screen or monitor.
c.SetFontSize(9) Hinting: font.HintingFull,
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,
} }
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 var rgbFormat render.Pictformat
for _, pf := range pformats.Formats { for _, pf := range pformats.Formats {
// Hopefully. Might want to check ARGB/BGRA. // 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. // NOTE: A depth of 24 will not work, the server always rejects it.
_ = render.CreateGlyphSet(X, gsid, rgbFormat) _ = 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++ { 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++ { for i := 0; i < len(nrgb.Pix); i++ {
nrgb.Pix[i] = 0 nrgb.Pix[i] = 0
} }
advance, err := c.DrawString(string(r), fixed.P(18, 18)) draw.Draw(nrgb, dr, mask, maskp, draw.Src)
_, _ = advance, err _ = advance
if err != nil {
log.Println("skip")
continue
}
_ = render.AddGlyphs(X, gsid, 1, []uint32{uint32(r)}, _ = render.AddGlyphs(X, gsid, 1, []uint32{uint32(r)},
[]render.Glyphinfo{{ []render.Glyphinfo{{