Documentation
¶
Overview ¶
Package fontfind is for typeface and font finding and loading.
There is a certain confusion with the nomenclature of typesetting. We will stick to the following definitions:
▪︎ A "typeface" is a family of fonts. An example is "Helvetica". This corresponds to a TrueType "collection" (*.ttc).
▪︎ A "scalable font" is a font, i.e. a variant of a typeface with a certain weight, slant, etc. An example is "Helvetica regular".
▪︎ A "typecase" is a scaled font, i.e. a font in a certain size for a certain script and language. The name is reminiscend on the wooden boxes of typesetters in the era of metal type. An example is "Helvetica regular 11pt, Latin, en_US".
Please note that Go (Golang) does use the terms "font" and "face" differently–actually more or less in an opposite manner.
Status ¶
Does not yet contain methods for font collections (*.ttc), e.g., /System/Library/Fonts/Helvetica.ttc on Mac OS.
License ¶
Governed by a 3-Clause BSD license. License file may be found in the root folder of this module.
Copyright © Norbert Pillmayer <norbert@pillmayer.com>
Index ¶
- Constants
- Variables
- func ClosestMatch(fdescs []FontVariantsLocation, pattern string, style font.Style, ...) (match FontVariantsLocation, variant string, confidence MatchConfidence)
- func GuessStyleAndWeight(fontfilename string) (font.Style, font.Weight)
- func Matches(fontfilename, pattern string, style font.Style, weight font.Weight) bool
- func PpEm(ptSize fixed.Int26_6, dpi float32) fixed.Int26_6
- func RasterCoords(u sfnt.Units, sfont *sfnt.Font, ptSize fixed.Int26_6, dpi float32) fixed.Int26_6
- type Descriptor
- type FontVariantsLocation
- type MatchConfidence
- type ScalableFont
Constants ¶
const ( StyleNormal = font.StyleNormal StyleItalic = font.StyleItalic )
const ( WeightLight = font.WeightLight WeightNormal = font.WeightNormal WeightSemiBold = font.WeightSemiBold WeightBold = font.WeightBold )
Variables ¶
var NullFont = ScalableFont{}
NullFont is the zero-value marker used when no scalable font could be resolved.
PtIn is 72.27, i.e. printer's points per inch.
Functions ¶
func ClosestMatch ¶
func ClosestMatch(fdescs []FontVariantsLocation, pattern string, style font.Style, weight font.Weight) (match FontVariantsLocation, variant string, confidence MatchConfidence)
ClosestMatch scans a list of font descriptors and returns the closest match for a given set of parameters.
If no variant matches, returns `NoConfidence`.
func GuessStyleAndWeight ¶
GuessStyleAndWeight tries to guess a font's style and weight from the font's file name.
func Matches ¶
Matches returns true if a font's filename contains pattern and indicators for a given style and weight.
Types ¶
type Descriptor ¶
Descriptor describes a requested scalable font by family pattern, style, and weight.
type FontVariantsLocation ¶
type FontVariantsLocation struct {
Family string `json:"family"`
Variants []string `json:"variants"`
Path string // used for local font sources
}
FontVariantsLocation describes known variants and location info for a font family.
type MatchConfidence ¶
type MatchConfidence int
MatchConfidence is a type for expressing the confidence level of font matching.
const ( NoConfidence MatchConfidence = 0 LowConfidence MatchConfidence = 2 HighConfidence MatchConfidence = 3 PerfectConfidence MatchConfidence = 4 )
func MatchStyle ¶
func MatchStyle(variantName string, style font.Style) MatchConfidence
MatchStyle tries to match a font-variant to a given style.
func MatchWeight ¶
func MatchWeight(variantName string, weight font.Weight) MatchConfidence
MatchWeight tries to match a font-variant to a given weight.
type ScalableFont ¶
type ScalableFont struct {
Name string
Style font.Style
Weight font.Weight
// contains filtered or unexported fields
}
ScalableFont describes a concrete font variant and where to load it from.
func FallbackFont ¶
func FallbackFont() ScalableFont
FallbackFont returns the default packaged fallback font.
func (*ScalableFont) Path ¶
func (f *ScalableFont) Path() string
Path returns the path of the font file inside the configured file-system.
func (*ScalableFont) ReadFontData ¶
func (f *ScalableFont) ReadFontData() ([]byte, error)
ReadFontData reads the raw bytes of this scalable font from its configured file-system.
Directories
¶
| Path | Synopsis |
|---|---|
|
Package fontregistry manages a registry for loaded fonts.
|
Package fontregistry manages a registry for loaded fonts. |
|
Package locate defines resolver function types and async font resolution helpers.
|
Package locate defines resolver function types and async font resolution helpers. |