This commit is contained in:
bloeys
2023-02-17 04:43:15 +04:00
parent 45c0858789
commit 2d3f89e290
2 changed files with 14 additions and 13 deletions

View File

@ -41,12 +41,12 @@ type FontAtlasGlyph struct {
Advance float32 Advance float32
} }
//NewFontAtlasFromFile reads a TTF or TTC file and produces a font texture atlas containing // NewFontAtlasFromFile reads a TTF or TTC file and produces a font texture atlas containing
//all its characters using the specified options. The atlas uses equally sized tiles // all its characters using the specified options. The atlas uses equally sized tiles
//such that all characters use an equal horizontal/vertical on the atlas. // such that all characters use an equal horizontal/vertical on the atlas.
//If the character is smaller than the tile then the rest of the tile is empty. // If the character is smaller than the tile then the rest of the tile is empty.
// //
//Only monospaced fonts are supported // Only monospaced fonts are supported
func NewFontAtlasFromFile(fontFile string, fontOptions *truetype.Options) (*FontAtlas, error) { func NewFontAtlasFromFile(fontFile string, fontOptions *truetype.Options) (*FontAtlas, error) {
fBytes, err := os.ReadFile(fontFile) fBytes, err := os.ReadFile(fontFile)
@ -129,12 +129,12 @@ func calcNeededAtlasSize(glyphs []rune, face font.Face, charPaddingXFixed, charP
return atlasSizeX, atlasSizeY return atlasSizeX, atlasSizeY
} }
//NewFontAtlasFromFile uses the passed font to produce a font texture atlas containing // NewFontAtlasFromFile uses the passed font to produce a font texture atlas containing
//all its characters using the specified options. The atlas uses equally sized tiles // all its characters using the specified options. The atlas uses equally sized tiles
//such that all characters use an equal horizontal/vertical on the atlas. // such that all characters use an equal horizontal/vertical on the atlas.
//If the character is smaller than the tile then the rest of the tile is empty. // If the character is smaller than the tile then the rest of the tile is empty.
// //
//Only monospaced fonts are supported. // Only monospaced fonts are supported.
func NewFontAtlasFromFont(f *truetype.Font, face font.Face, pointSize uint) (*FontAtlas, error) { func NewFontAtlasFromFont(f *truetype.Font, face font.Face, pointSize uint) (*FontAtlas, error) {
const maxAtlasSize = 8192 const maxAtlasSize = 8192
@ -379,7 +379,7 @@ func SaveImgToPNG(img image.Image, file string) error {
return nil return nil
} }
//getGlyphRangesFromFont returns a list of ranges, each range is: [i][0]<=range<[i][1] // getGlyphRangesFromFont returns a list of ranges, each range is: [i][0]<=range<[i][1]
func getGlyphRangesFromFont(f *truetype.Font) (ret [][2]rune) { func getGlyphRangesFromFont(f *truetype.Font) (ret [][2]rune) {
isRuneInPrivateUseArea := func(r rune) bool { isRuneInPrivateUseArea := func(r rune) bool {
@ -411,7 +411,7 @@ func getGlyphRangesFromFont(f *truetype.Font) (ret [][2]rune) {
return ret return ret
} }
//getGlyphsFromRuneRanges takes ranges of runes and produces an array of all the runes in these ranges // getGlyphsFromRuneRanges takes ranges of runes and produces an array of all the runes in these ranges
func getGlyphsFromRuneRanges(ranges [][2]rune) []rune { func getGlyphsFromRuneRanges(ranges [][2]rune) []rune {
out := make([]rune, 0) out := make([]rune, 0)

View File

@ -131,7 +131,8 @@ var (
yOff float32 = 0 yOff float32 = 0
) )
// @TODO: We should 'draw' and apply ansi operations on an in-mem grid and send the final grid for rendering // @TODO: Convert most operations to use glyphGrid instead of drawing directly to glyphRend
// @TODO: Implement SDF glyph rendering
func main() { func main() {