Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Modify the GetGlyph() interface to ensure that const2bit works properly #46

Merged
merged 2 commits into from
Oct 19, 2024
Merged
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
28 changes: 13 additions & 15 deletions concrete.go
Original file line number Diff line number Diff line change
Expand Up @@ -19,9 +19,10 @@ type Glyph struct {

// Font is a struct that implements Fonter interface.
type Font struct {
BBox [4]int8 // width, height, minX, minY
Glyphs []Glyph
YAdvance uint8
BBox [4]int8 // width, height, minX, minY
Glyphs []Glyph
YAdvance uint8
EmptyGlyph Glyph
}

// Draw sets a single glyph in the buffer of the display.
Expand Down Expand Up @@ -72,7 +73,7 @@ func (f *Font) GetYAdvance() uint8 {
var emptyBitmap [1]byte

// GetGlyph returns the glyph corresponding to the specified rune in the font.
func (font *Font) GetGlyph(r rune) Glyph {
func (font *Font) GetGlyph(r rune) Glypher {
s := 0
e := len(font.Glyphs) - 1

Expand All @@ -87,17 +88,14 @@ func (font *Font) GetGlyph(r rune) Glyph {
}

if s == len(font.Glyphs) || font.Glyphs[s].Info().Rune != r {
g := Glyph{
Rune: r,
Width: 0,
Height: 0,
XAdvance: font.Glyphs[0].Info().XAdvance,
XOffset: font.Glyphs[0].Info().XOffset,
YOffset: font.Glyphs[0].Info().YOffset,
Bitmaps: emptyBitmap[:],
}
return g
font.EmptyGlyph.Width = 0
font.EmptyGlyph.Height = 0
font.EmptyGlyph.XAdvance = font.Glyphs[0].Info().XAdvance
font.EmptyGlyph.XOffset = font.Glyphs[0].Info().XOffset
font.EmptyGlyph.YOffset = font.Glyphs[0].Info().YOffset
font.EmptyGlyph.Bitmaps = emptyBitmap[:]
return &(font.EmptyGlyph)
}

return font.Glyphs[s]
return &(font.Glyphs[s])
}
4 changes: 2 additions & 2 deletions tinyfont.go
Original file line number Diff line number Diff line change
Expand Up @@ -30,7 +30,7 @@ type GlyphInfo struct {

// Fonter is an interface that represents a set of glyphs.
type Fonter interface {
GetGlyph(r rune) Glyph
GetGlyph(r rune) Glypher
GetYAdvance() uint8
}

Expand Down Expand Up @@ -120,6 +120,6 @@ func LineWidth(f Fonter, str string) (innerWidth uint32, outboxWidth uint32) {
}

// GetGlyph returns the glyph corresponding to the specified rune in the font.
func GetGlyph(f Fonter, r rune) Glyph {
func GetGlyph(f Fonter, r rune) Glypher {
deadprogram marked this conversation as resolved.
Show resolved Hide resolved
return f.GetGlyph(r)
}
Loading