Documentation
¶
Index ¶
- Constants
- Variables
- func EqualFontFamily(a, b FontFamily) bool
- func EqualFontSynthesis(a, b *FontSynthesis) bool
- func FromGioFont(gf giofont.Font) (FontFamily, FontWeight, FontStyle)
- func IsFontSynthesis(f *FontSynthesis) bool
- func IsSpecifiedFontFamily(f FontFamily) bool
- func ResolveGioTypeface(f FontFamily) string
- func SameFontSynthesis(a, b *FontSynthesis) bool
- func SemanticEqualFontSynthesis(a, b *FontSynthesis) bool
- func StringFont(f Font) string
- func StringFontFamily(f FontFamily) string
- func StringFontSynthesis(f *FontSynthesis) string
- func ToGioFont(f FontFamily, w FontWeight, s FontStyle) giofont.Font
- func ToGioStyle(s FontStyle) giofont.Style
- func ToGioWeight(w FontWeight) giofont.Weight
- type DefaultFontFamily
- type DefaultFontFamilyResolver
- type FileBasedFontFamily
- type Font
- type FontFamily
- func CoalesceFontFamily(ptr, def FontFamily) FontFamily
- func FontFamilyFromFonts(fonts ...Font) FontFamily
- func FontFamilyFromTypeface(typeface Typeface) FontFamily
- func FromGioTypeface(t giofont.Typeface) FontFamily
- func TakeOrElseFontFamily(a, b FontFamily) FontFamily
- func ToFontFamily(f Font) FontFamily
- type FontFamilyResolver
- type FontListFontFamily
- type FontLoadingStrategy
- type FontStyle
- type FontSynthesis
- type FontWeight
- type GenericFontFamily
- type LoadedFontFamily
- type ResolvedTypeface
- type SystemFontFamily
- type Typeface
- type UrlFont
Constants ¶
const ( // Aliases for standard weights FontWeightThin = FontWeightW100 FontWeightExtraLight = FontWeightW200 FontWeightLight = FontWeightW300 FontWeightNormal = FontWeightW400 FontWeightMedium = FontWeightW500 FontWeightSemiBold = FontWeightW600 FontWeightBold = FontWeightW700 FontWeightExtraBold = FontWeightW800 FontWeightBlack = FontWeightW900 )
const MaximumAsyncTimeoutMillis = 15_000
MaximumAsyncTimeoutMillis is the global timeout for fetching an async font. After this timeout, a font load may no longer trigger text reflow.
Variables ¶
var ( FontSynthesisUnspecified = &FontSynthesis{value: -1} // FontSynthesisNone turns off font synthesis. // Neither bold nor slanted faces are synthesized. FontSynthesisNone = &FontSynthesis{value: 0} // FontSynthesisWeight synthesizes only bold font if not available. // Slanted fonts will not be synthesized. FontSynthesisWeight = &FontSynthesis{value: synthesisWeightFlag} // FontSynthesisStyle synthesizes only slanted font if not available. // Bold fonts will not be synthesized. FontSynthesisStyle = &FontSynthesis{value: synthesisStyleFlag} // FontSynthesisAll synthesizes both bold and slanted fonts if either // is not available in the FontFamily. FontSynthesisAll = &FontSynthesis{value: synthesisAllFlags} )
Functions ¶
func EqualFontFamily ¶
func EqualFontFamily(a, b FontFamily) bool
func EqualFontSynthesis ¶
func EqualFontSynthesis(a, b *FontSynthesis) bool
func FromGioFont ¶
func FromGioFont(gf giofont.Font) (FontFamily, FontWeight, FontStyle)
FromGioFont converts a gio font.Font to go-compose font attributes.
func IsFontSynthesis ¶
func IsFontSynthesis(f *FontSynthesis) bool
func IsSpecifiedFontFamily ¶
func IsSpecifiedFontFamily(f FontFamily) bool
func ResolveGioTypeface ¶
func ResolveGioTypeface(f FontFamily) string
ResolveGioTypeface resolves a FontFamily to a gio Typeface string.
func SemanticEqualFontSynthesis ¶
func SemanticEqualFontSynthesis(a, b *FontSynthesis) bool
Semantic equality (field-by-field, 20 ns)
func StringFont ¶
func StringFontFamily ¶
func StringFontFamily(f FontFamily) string
func StringFontSynthesis ¶
func StringFontSynthesis(f *FontSynthesis) string
func ToGioFont ¶
func ToGioFont(f FontFamily, w FontWeight, s FontStyle) giofont.Font
ToGioFont converts go-compose font attributes to a gio font.Font.
func ToGioStyle ¶
ToGioStyle converts a go-compose FontStyle to a gio font.Style.
func ToGioWeight ¶
func ToGioWeight(w FontWeight) giofont.Weight
ToGioWeight converts a go-compose FontWeight to a gio font.Weight. Gio weights are offset from 0 (Normal/400). 100 -> -300 (Thin) 400 -> 0 (Normal) 700 -> 300 (Bold)
Types ¶
type DefaultFontFamily ¶
type DefaultFontFamily struct{}
DefaultFontFamily is the platform default font family.
func (*DefaultFontFamily) Equals ¶
func (d *DefaultFontFamily) Equals(other FontFamily) bool
func (*DefaultFontFamily) String ¶
func (d *DefaultFontFamily) String() string
String returns the font family display name.
type DefaultFontFamilyResolver ¶
type DefaultFontFamilyResolver struct{}
DefaultFontFamilyResolver is a basic FontFamilyResolver implementation that provides system-default font handling. It does not do any actual font resolution but provides a no-op implementation suitable for basic use cases.
func NewDefaultFontFamilyResolver ¶
func NewDefaultFontFamilyResolver() *DefaultFontFamilyResolver
NewDefaultFontFamilyResolver creates a new DefaultFontFamilyResolver.
func (*DefaultFontFamilyResolver) Preload ¶
func (r *DefaultFontFamilyResolver) Preload(fontFamily FontFamily)
Preload is a no-op in the default resolver.
func (*DefaultFontFamilyResolver) Resolve ¶
func (r *DefaultFontFamilyResolver) Resolve( fontFamily FontFamily, fontWeight FontWeight, fontStyle FontStyle, fontSynthesis FontSynthesis, ) state.Value
Resolve returns a state.Value containing the resolved typeface. The default resolver returns a static value representing the default system font.
type FileBasedFontFamily ¶
type FileBasedFontFamily interface {
FontFamily
// contains filtered or unexported methods
}
FileBasedFontFamily is a base type for FontFamilies created from file sources.
type Font ¶
type Font interface {
// Weight returns the weight of the font.
// The system uses this to match a font to a font request.
Weight() FontWeight
// Style returns the style of the font, normal or italic.
// The system uses this to match a font to a font request.
Style() FontStyle
// LoadingStrategy returns the loading strategy for this font.
LoadingStrategy() FontLoadingStrategy
}
Font is the interface of the font resource.
type FontFamily ¶
type FontFamily interface {
Equals(other FontFamily) bool
// contains filtered or unexported methods
}
FontFamily is the primary typography interface for Compose applications.
var ( // FontFamilyDefault is the platform default font. FontFamilyDefault FontFamily = &DefaultFontFamily{} // FontFamilySansSerif is a font family with low contrast and plain stroke endings. FontFamilySansSerif FontFamily = NewGenericFontFamily("sans-serif", "FontFamily.SansSerif") // FontFamilySerif is the formal text style for scripts. FontFamilySerif FontFamily = NewGenericFontFamily("serif", "FontFamily.Serif") // FontFamilyMonospace is a font family where glyphs have the same fixed width. FontFamilyMonospace FontFamily = NewGenericFontFamily("monospace", "FontFamily.Monospace") // FontFamilyCursive is a cursive, hand-written like font family. FontFamilyCursive FontFamily = NewGenericFontFamily("cursive", "FontFamily.Cursive") )
Standard font family constants
func CoalesceFontFamily ¶
func CoalesceFontFamily(ptr, def FontFamily) FontFamily
func FontFamilyFromFonts ¶
func FontFamilyFromFonts(fonts ...Font) FontFamily
FontFamilyFromFonts creates a FontFamily from a list of fonts.
func FontFamilyFromTypeface ¶
func FontFamilyFromTypeface(typeface Typeface) FontFamily
FontFamilyFromTypeface creates a FontFamily from a loaded typeface.
func FromGioTypeface ¶
func FromGioTypeface(t giofont.Typeface) FontFamily
FromGioTypeface converts a gio font.Typeface to a go-compose FontFamily. For named typefaces, this creates a GenericFontFamily. For empty typefaces, this returns FontFamilyDefault.
func TakeOrElseFontFamily ¶
func TakeOrElseFontFamily(a, b FontFamily) FontFamily
func ToFontFamily ¶
func ToFontFamily(f Font) FontFamily
ToFontFamily creates a FontFamily from a single Font.
type FontFamilyResolver ¶
type FontFamilyResolver interface {
// Preload resolves and caches all fonts reachable in a FontFamily.
Preload(fontFamily FontFamily)
// Resolve resolves a typeface using any appropriate logic for the FontFamily.
// Returns a state.Value that contains the platform-specific Typeface.
Resolve(
fontFamily FontFamily,
fontWeight FontWeight,
fontStyle FontStyle,
fontSynthesis FontSynthesis,
) state.Value
}
FontFamilyResolver is the main interface for resolving FontFamily into a platform-specific typeface.
type FontListFontFamily ¶
type FontListFontFamily struct {
// Fonts is the fallback list of fonts used for resolving typefaces.
Fonts []Font
}
FontListFontFamily defines a font family with a list of Fonts.
func NewFontListFontFamily ¶
func NewFontListFontFamily(fonts []Font) *FontListFontFamily
NewFontListFontFamily creates a FontListFontFamily from a list of fonts. Panics if the fonts list is empty.
func (*FontListFontFamily) Equals ¶
func (f *FontListFontFamily) Equals(other FontFamily) bool
func (*FontListFontFamily) String ¶
func (f *FontListFontFamily) String() string
String returns a string representation of the FontListFontFamily.
type FontLoadingStrategy ¶
type FontLoadingStrategy int
FontLoadingStrategy controls how font loading resolves when displaying text.
const ( // FontLoadingStrategyBlocking resolves the font by blocking until loaded. // This means the first frame that uses this font will always display using // the desired font, and text will never reflow. // Should be used for fonts stored on-device. FontLoadingStrategyBlocking FontLoadingStrategy = 0 // FontLoadingStrategyOptionalLocal is best-effort loading from a local resource // that MAY be available. Resolution is expected to fail when the resource is // not available, which will fallback to the next font in the FontFamily. FontLoadingStrategyOptionalLocal FontLoadingStrategy = 1 // FontLoadingStrategyAsync loads the font in the background without blocking. // During loading, the app will use a fallback font. When the font finishes // loading, text will reflow with the resolved typeface. // Should be used for fonts fetched from a remote source. FontLoadingStrategyAsync FontLoadingStrategy = 2 )
func (FontLoadingStrategy) String ¶
func (s FontLoadingStrategy) String() string
String returns a string representation of the FontLoadingStrategy.
func (FontLoadingStrategy) Value ¶
func (s FontLoadingStrategy) Value() int
Value returns the underlying integer value.
type FontStyle ¶
type FontStyle int
FontStyle defines whether the font is Italic or Normal.
func FontStyleValues ¶
func FontStyleValues() []FontStyle
FontStyleValues returns a list of possible FontStyle values.
func FromGioStyle ¶
FromGioStyle converts a gio font.Style to a go-compose FontStyle.
func (FontStyle) IsSpecified ¶
func (FontStyle) TakeOrElse ¶
type FontSynthesis ¶
type FontSynthesis struct {
// contains filtered or unexported fields
}
FontSynthesis specifies whether the system should fake bold or slanted glyphs when the FontFamily used does not contain bold or oblique Fonts.
func CoalesceFontSynthesis ¶
func CoalesceFontSynthesis(ptr, def *FontSynthesis) *FontSynthesis
func FontSynthesisValueOf ¶
func FontSynthesisValueOf(value int) (*FontSynthesis, error)
FontSynthesisValueOf creates a FontSynthesis from an integer value. Returns an error if the value is not recognized.
func TakeOrElseFontSynthesis ¶
func TakeOrElseFontSynthesis(f, defaultFontSynthesis *FontSynthesis) *FontSynthesis
func (FontSynthesis) IsStyleOn ¶
func (f FontSynthesis) IsStyleOn() bool
IsStyleOn returns true if style synthesis is enabled.
func (FontSynthesis) IsWeightOn ¶
func (f FontSynthesis) IsWeightOn() bool
IsWeightOn returns true if weight synthesis is enabled.
func (FontSynthesis) Value ¶
func (f FontSynthesis) Value() int
Value returns the underlying integer value.
type FontWeight ¶
type FontWeight int
FontWeight represents the thickness of the glyphs, in a range of [1, 1000].
const ( // FontWeightW100 is the thinnest font weight (Thin) FontWeightW100 FontWeight = 100 // FontWeightW200 is extra light weight FontWeightW200 FontWeight = 200 // FontWeightW300 is light weight FontWeightW300 FontWeight = 300 // FontWeightW400 is normal/regular weight FontWeightW400 FontWeight = 400 // FontWeightW500 is medium weight FontWeightW500 FontWeight = 500 // FontWeightW600 is semi-bold weight FontWeightW600 FontWeight = 600 // FontWeightW700 is bold weight FontWeightW700 FontWeight = 700 // FontWeightW800 is extra-bold weight FontWeightW800 FontWeight = 800 // FontWeightW900 is black (heaviest) weight FontWeightW900 FontWeight = 900 )
Standard font weight constants
const (
FontWeightUnspecified FontWeight = weightUnspecified
)
func FontWeightValues ¶
func FontWeightValues() []FontWeight
FontWeightValues returns a list of all standard font weights.
func FromGioWeight ¶
func FromGioWeight(w giofont.Weight) FontWeight
FromGioWeight converts a gio font.Weight to a go-compose FontWeight. Gio weights are offset from 0 (Normal/400), so we add 400 to get CSS weight. -300 (Thin) -> 100 0 (Normal) -> 400 300 (Bold) -> 700
func LerpFontWeight ¶
func LerpFontWeight(start, stop FontWeight, fraction float32) FontWeight
LerpFontWeight linearly interpolates between two FontWeights. The fraction represents position on the timeline: 0.0 returns start, 1.0 returns stop.
func NewFontWeight ¶
func NewFontWeight(weight int) FontWeight
NewFontWeight creates a FontWeight with validation. Panics if weight is not in range [1, 1000].
func (FontWeight) Compare ¶
func (w FontWeight) Compare(other FontWeight) int
Compare compares two FontWeights. Returns -1 if w < other, 0 if equal, 1 if w > other.
func (FontWeight) Equals ¶
func (w FontWeight) Equals(other FontWeight) bool
Equals checks if two FontWeights are equal.
func (FontWeight) IsFontWeight ¶
func (w FontWeight) IsFontWeight() bool
func (FontWeight) String ¶
func (w FontWeight) String() string
String returns a string representation of the FontWeight.
func (FontWeight) TakeOrElse ¶
func (w FontWeight) TakeOrElse(other FontWeight) FontWeight
func (FontWeight) Weight ¶
func (w FontWeight) Weight() int
Weight returns the underlying weight value.
type GenericFontFamily ¶
type GenericFontFamily struct {
// contains filtered or unexported fields
}
GenericFontFamily represents a font family with a generic font family name. If the platform cannot find the passed generic font family, it uses the platform default.
func NewGenericFontFamily ¶
func NewGenericFontFamily(name, fontFamilyName string) *GenericFontFamily
NewGenericFontFamily creates a new GenericFontFamily.
func (*GenericFontFamily) Equals ¶
func (g *GenericFontFamily) Equals(other FontFamily) bool
func (*GenericFontFamily) Name ¶
func (g *GenericFontFamily) Name() string
Name returns the generic font family name (e.g., "sans-serif", "serif").
func (*GenericFontFamily) String ¶
func (g *GenericFontFamily) String() string
String returns the font family display name.
type LoadedFontFamily ¶
type LoadedFontFamily struct {
Typeface Typeface
}
LoadedFontFamily defines a font family that is already a loaded Typeface.
func NewLoadedFontFamily ¶
func NewLoadedFontFamily(typeface Typeface) *LoadedFontFamily
NewLoadedFontFamily creates a LoadedFontFamily from a typeface.
func (*LoadedFontFamily) Equals ¶
func (l *LoadedFontFamily) Equals(other FontFamily) bool
Equals checks if two LoadedFontFamilies are equal.
func (*LoadedFontFamily) String ¶
func (l *LoadedFontFamily) String() string
String returns a string representation of the LoadedFontFamily.
type ResolvedTypeface ¶
type ResolvedTypeface struct {
FontFamily FontFamily
FontWeight FontWeight
FontStyle FontStyle
}
ResolvedTypeface represents a resolved font configuration.
type SystemFontFamily ¶
type SystemFontFamily interface {
FontFamily
// contains filtered or unexported methods
}
SystemFontFamily is a base type for FontFamilies installed on the system.
type Typeface ¶
type Typeface interface {
// FontFamily returns the font family used for creating this Typeface.
// If a platform Typeface was used, it will return nil.
FontFamily() FontFamily
}
Typeface is a class that can be used for changing the font used in text.
type UrlFont ¶
type UrlFont struct {
// contains filtered or unexported fields
}
UrlFont represents a font that is loaded from a URL.
func NewUrlFont ¶
func NewUrlFont(url string, weight FontWeight, style FontStyle, loadingStrategy FontLoadingStrategy) *UrlFont
NewUrlFont creates a new UrlFont.
func (*UrlFont) LoadingStrategy ¶
func (u *UrlFont) LoadingStrategy() FontLoadingStrategy
LoadingStrategy returns the loading strategy of the font.
func (*UrlFont) Weight ¶
func (u *UrlFont) Weight() FontWeight
Weight returns the weight of the font.