aboutsummaryrefslogtreecommitdiff
path: root/prototypes
diff options
context:
space:
mode:
authorPřemysl Janouch <p@janouch.name>2018-08-23 02:46:56 +0200
committerPřemysl Janouch <p@janouch.name>2018-09-02 18:25:35 +0200
commit32beda3c90afd164858668e3f392c0a279899067 (patch)
tree3be7b66e553bb29fbf926e88d6c8bfb904818a53 /prototypes
parent30f2366f9a2b13cdc2775c3a972d08f1297acdaa (diff)
downloadhaven-32beda3c90afd164858668e3f392c0a279899067.tar.gz
haven-32beda3c90afd164858668e3f392c0a279899067.tar.xz
haven-32beda3c90afd164858668e3f392c0a279899067.zip
xgb-render: slightly simplify
Diffstat (limited to 'prototypes')
-rw-r--r--prototypes/xgb-xrender.go54
1 files changed, 23 insertions, 31 deletions
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{{