Documentation ¶
Overview ¶
Package font is for typeface and font handling.
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 © 2017–2021 Norbert Pillmayer <norbert@pillmayer.com>
Index ¶
- Constants
- func ClosestMatch(fdescs []Descriptor, pattern string, style xfont.Style, weight xfont.Weight) (match Descriptor, variant string, confidence MatchConfidence)
- func GuessStyleAndWeight(fontfilename string) (xfont.Style, xfont.Weight)
- func Matches(fontfilename, pattern string, style xfont.Style, weight xfont.Weight) bool
- func NormalizeFontname(fname string, style xfont.Style, weight xfont.Weight) string
- type Descriptor
- type MatchConfidence
- type Registry
- type ScalableFont
- type TypeCase
Constants ¶
const ( StyleNormal = xfont.StyleNormal StyleItalic = xfont.StyleItalic )
const ( WeightLight = xfont.WeightLight WeightNormal = xfont.WeightNormal WeightSemiBold = xfont.WeightSemiBold WeightBold = xfont.WeightBold )
Variables ¶
This section is empty.
Functions ¶
func ClosestMatch ¶
func ClosestMatch(fdescs []Descriptor, pattern string, style xfont.Style, weight xfont.Weight) (match Descriptor, variant string, confidence MatchConfidence)
ClosestMatch scans a list of font desriptors and returns the closest match for a given set of parametesrs. If no variant matches, returns `NoConfidence`.
func GuessStyleAndWeight ¶
GuessStyleAndWeight trys to guess a font's style and weight from the font's file name.
Types ¶
type Descriptor ¶
type Descriptor struct { Family string `json:"family"` Variants []string `json:"variants"` Path string // only used if just a single variant }
Descriptor represents all the known variants of a font.
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 xfont.Style) MatchConfidence
MatchStyle trys to match a font-variant to a given style.
func MatchWeight ¶
func MatchWeight(variantName string, weight xfont.Weight) MatchConfidence
MatchWeight trys to match a font-variant to a given weight.
type Registry ¶
Registry is a type for holding information about loaded fonts for a typesetter.
func GlobalRegistry ¶
func GlobalRegistry() *Registry
GlobalRegistry is an application-wide singleton to hold information about loaded fonts and typecases.
func NewRegistry ¶
func NewRegistry() *Registry
func (*Registry) LogFontList ¶
func (fr *Registry) LogFontList()
LogFontList is a helper function to dump the list of known fonts and typecases in a registry to the trace-file (log-level Info).
func (*Registry) StoreFont ¶
func (fr *Registry) StoreFont(normalizedName string, f *ScalableFont)
StoreFont pushes a font into the registry if it isn't contained yet.
The font will be stored using the normalized font name as a key. If this key is already associated with a font, that font will not be overridden.
func (*Registry) TypeCase ¶
TypeCase returns a concrete typecase with a given font, style, weight and size. If a suitable typecase has already been cached, TypeCase will return the cached typecase. If a suitable font has previously been stored under key `normalizedName`, a typecase will be derived from this font.
If not typecase can be produced, TypeCase will derive one from a system-wide fallback font and return it, together with an error message.
type ScalableFont ¶
type ScalableFont struct { Fontname string Filepath string // file path Binary []byte // raw data SFNT *sfnt.Font // the font's container // TODO: not threadsafe??? }
ScalableFont is an internal representation of an outline-font of type TTF of OTF.
func FallbackFont ¶
func FallbackFont() *ScalableFont
FallbackFont returns a font to be used if everything else failes. It is always present. Currently we use Go Sans.
func LoadOpenTypeFont ¶
func LoadOpenTypeFont(fontfile string) (*ScalableFont, error)
LoadOpenTypeFont loads an OpenType font (TTF or OTF) from a file.
func ParseOpenTypeFont ¶
func ParseOpenTypeFont(fbytes []byte) (f *ScalableFont, err error)
ParseOpenTypeFont loads an OpenType font (TTF or OTF) from memory.
func (*ScalableFont) PrepareCase ¶
func (sf *ScalableFont) PrepareCase(fontsize float64) (*TypeCase, error)
PrepareCase prepares a typecase in a given point size, e.g. "Helvetica bold 10pt" from an existing font "Helvetiva bold", which has been previously loaded.
type TypeCase ¶
type TypeCase struct {
// contains filtered or unexported fields
}
TypeCase represents a font at a specific point size, e.g. "Helvetica bold 10pt".
func NullTypeCase ¶
func NullTypeCase() *TypeCase
func (*TypeCase) ScalableFontParent ¶
func (tc *TypeCase) ScalableFontParent() *ScalableFont
ScalableFontParent returns the unscaled font a typecase has been derived from.
Directories ¶
Path | Synopsis |
---|---|
opentype
|
|
ot
Package ot provides access to OpenType font tables and features.
|
Package ot provides access to OpenType font tables and features. |
otlayout
Package otlayout provides access to OpenType font layout features.
|
Package otlayout provides access to OpenType font layout features. |
otquery
Package otquery queries metrics and other information from OpenType fonts.
|
Package otquery queries metrics and other information from OpenType fonts. |
otshape
Package otshape is work in progress.
|
Package otshape is work in progress. |