Drawer now draws tofu

Closes #2
This commit is contained in:
Sasha Koshka 2024-09-03 17:59:07 -04:00
parent b0e80ce961
commit 021dd288b6
2 changed files with 46 additions and 6 deletions

View File

@ -25,13 +25,19 @@ func (drawer Drawer) Draw (
char rune,
position fixed.Point26_6,
) bool {
// leave empty space for space characters
if unicode.IsSpace(char){
return true
}
dot := fixed.P (
offset.X + position.X.Round(),
offset.Y + position.Y.Round())
destinationRectangle,
mask, maskPoint, _, ok := drawer.face.Glyph (
fixed.P (
offset.X + position.X.Round(),
offset.Y + position.Y.Round()),
char)
if !ok || unicode.IsSpace(char) || char == 0 {
mask, maskPoint, _, ok := drawer.face.Glyph(dot, char)
// tofu
if !ok {
drawer.drawTofu(char, destination, color, dot)
return true
}
@ -50,3 +56,29 @@ func (drawer Drawer) Draw (
})
return
}
func (drawer Drawer) drawTofu (
char rune,
destination draw.Image,
col color.Color,
position fixed.Point26_6,
) {
bounds, _ := tofuBounds(drawer.face)
rectBounds := image.Rect (
bounds.Min.X.Round(),
bounds.Min.Y.Round(),
bounds.Max.X.Round(),
bounds.Max.Y.Round()).Add(image.Pt(
position.X.Round(),
position.Y.Round()))
for x := rectBounds.Min.X; x < rectBounds.Max.X; x ++ {
destination.Set(x, rectBounds.Min.Y, col)
}
for y := rectBounds.Min.Y; y < rectBounds.Max.Y; y ++ {
destination.Set(rectBounds.Min.X, y, col)
destination.Set(rectBounds.Max.X - 1, y, col)
}
for x := rectBounds.Min.X; x < rectBounds.Max.X; x ++ {
destination.Set(x, rectBounds.Max.Y - 1, col)
}
}

View File

@ -220,3 +220,11 @@ func tofuAdvance (face font.Face) fixed.Int26_6 {
return 16
}
}
func tofuBounds (face font.Face) (fixed.Rectangle26_6, fixed.Int26_6) {
if bounds, advance, ok := face.GlyphBounds('M'); ok {
return bounds, advance
} else {
return fixed.R(0, -16, 14, 0), 16
}
}