font

package
v0.0.0-...-1a7aca4 Latest Latest
Warning

This package is not in the latest version of its module.

Go to latest
Published: Jun 16, 2018 License: MIT Imports: 0 Imported by: 0

Documentation

Index

Constants

This section is empty.

Variables

This section is empty.

Functions

This section is empty.

Types

type Font

type Font struct {
	// The name of the font
	Name string

	// The width of each glyph in pixels.
	GlyphWidth uint32

	// The height of each glyph in pixels.
	GlyphHeight uint32

	// The recommended console resolution for this font.
	RecommendedWidth  uint32
	RecommendedHeight uint32

	// Font priority (lower is better). When auto-detecting a font to use, the font with
	// the lowest priority will be preferred
	Priority uint32

	// The number of bytes describing a row in a glyph.
	BytesPerRow uint32

	// The font bitmap. Each character consists of BytesPerRow * Height
	// bytes where each bit indicates whether a pixel should be set to the
	// foreground or the background color.
	Data []byte
}

Font describes a bitmap font that can be used by a console device.

func BestFit

func BestFit(consoleWidth, consoleHeight uint32) *Font

BestFit returns the best font from the available font list given the specified console dimensions. If multiple fonts match the dimension criteria then their priority attribute is used to select one.

The algorithm for selecting the best font is the following:

For each font:
  - calculate the sum of abs differences between the font recommended dimension
    and the console dimensions.
  - if the font score is lower than the current best font's score then the
    font becomes the new best font.
  - if the font score is equal to the current best font's score then the
    font with the lowest priority becomes the new best font.

func FindByName

func FindByName(name string) *Font

FindByName looks up a font instance by name. If the font is not found then the function returns nil.

Jump to

Keyboard shortcuts

? : This menu
/ : Search site
f or F : Jump to
y or Y : Canonical URL