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

Added function to extract the glyph texture id from a font #24

Open
wants to merge 1 commit into
base: master
Choose a base branch
from
Open
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
20 changes: 20 additions & 0 deletions font.go
Original file line number Diff line number Diff line change
Expand Up @@ -21,6 +21,10 @@ type Font struct {
maxGlyphHeight int // Largest glyph height.
}

func (f *Font) Texture() uint32 {
return f.texture
}

// loadFont loads the given font data. This does not deal with font scaling.
// Scaling should be handled by the independent Bitmap/Truetype loaders.
// We therefore expect the supplied image and charset to already be adjusted
Expand Down Expand Up @@ -144,6 +148,22 @@ func (f *Font) Metrics(text string) (int, int) {
return f.advanceSize(text), gh
}

// GlyphMetrics returns the pixel width and height for the given glyph index.
// This takes the scale and rendering direction of the font into account.
//
// Unknown runes will be counted as having the maximum glyph bounds as
// defined by Font.GlyphBounds().
func (f *Font) GlyphMetrics(index uint32) (int, int) {

gw, gh := f.GlyphBounds()
advance := f.config.Glyphs[index].Advance
if f.config.Dir == TopToBottom {
return gw, advance
}

return advance, gh
}

// advanceSize computes the pixel width or height for the given single-line
// input string. This iterates over all of its runes, finds the matching
// Charset entry and adds up the Advance values.
Expand Down