Load an actual font

This commit is contained in:
Sasha Koshka 2022-11-10 12:38:02 -05:00
parent 23a04a9cdb
commit 1afbcdb6bc

View File

@ -1,8 +1,8 @@
package x
import "image"
// import "golang.org/x/image/font"
// import "golang.org/x/image/font/basicfont"
import "golang.org/x/image/font"
import "golang.org/x/image/font/basicfont"
import "github.com/jezek/xgb"
import "github.com/jezek/xgbutil"
@ -12,6 +12,7 @@ import "github.com/jezek/xgbutil/xevent"
import "github.com/jezek/xgbutil/xwindow"
import "github.com/jezek/xgbutil/xgraphics"
import "git.tebibyte.media/sashakoshka/stone"
type Backend struct {
@ -27,6 +28,10 @@ type Backend struct {
after chan(struct { })
quit chan(struct { })
}
font struct {
face font.Face
}
metrics struct {
windowWidth int
@ -141,6 +146,7 @@ func (backend *Backend) handleXEvent (event xgb.Event) {
// backend.canvas.Scale (
// backend.metrics.windowWidth,
// backend.metrics.windowHeight)
backend.drawRune(8, 16, 'X')
backend.bindCanvas()
}
}
@ -193,6 +199,10 @@ func (backend *Backend) bindCanvas () {
backend.canvas.XPaint(backend.window.Id)
}
func (backend *Backend) drawRune (x, y int, character rune) {
}
// factory instantiates an X backend.
func factory (application *stone.Application) (output stone.Backend, err error) {
backend := &Backend {
@ -200,10 +210,16 @@ func factory (application *stone.Application) (output stone.Backend, err error)
config: application.Config(),
}
// load font
// TODO: load this from a file
backend.font.face = basicfont.Face7x13
// calculate metrics
// TODO: base these off of font metrics
backend.metrics.cellWidth = 8
backend.metrics.cellHeight = 16
metrics := backend.font.face.Metrics()
glyphAdvance, _ := backend.font.face.GlyphAdvance('M')
backend.metrics.cellWidth = glyphAdvance.Round()
backend.metrics.cellHeight = metrics.Height.Round()
backend.metrics.descent = metrics.Descent.Round()
backend.metrics.padding =
backend.config.Padding() *
backend.metrics.cellHeight