Documentation
¶
Index ¶
- Constants
- Variables
- func AddFamily(rts FontName, fam string) string
- func ColorFromRune(r rune) color.RGBA
- func ColorToRune(c color.Color) rune
- func FamiliesToList(fam string) []string
- func RuneFromDecoration(d Decorations) rune
- func RuneFromDirection(d Directions) rune
- func RuneFromFamily(d Family) rune
- func RuneFromSlant(d Slants) rune
- func RuneFromSpecial(d Specials) rune
- func RuneFromStretch(d Stretch) rune
- func RuneFromStyle(s *Style) rune
- func RuneFromWeight(d Weights) rune
- func RuneToStyle(s *Style, r rune)
- func SpanLen(s []rune) (sn int, rn int)
- type Decorations
- func (i Decorations) BitIndexString() string
- func (i Decorations) Desc() string
- func (i *Decorations) HasFlag(f enums.BitFlag) bool
- func (i Decorations) Int64() int64
- func (i Decorations) MarshalText() ([]byte, error)
- func (d Decorations) NumColors() int
- func (i *Decorations) SetFlag(on bool, f ...enums.BitFlag)
- func (i *Decorations) SetInt64(in int64)
- func (i *Decorations) SetString(s string) error
- func (i *Decorations) SetStringOr(s string) error
- func (i Decorations) String() string
- func (i *Decorations) UnmarshalText(text []byte) error
- func (i Decorations) Values() []enums.Enum
- type Directions
- func (i Directions) Desc() string
- func (i Directions) Int64() int64
- func (d Directions) IsVertical() bool
- func (i Directions) MarshalText() ([]byte, error)
- func (i *Directions) SetInt64(in int64)
- func (i *Directions) SetString(s string) error
- func (i Directions) String() string
- func (d Directions) ToGoText() di.Direction
- func (i *Directions) UnmarshalText(text []byte) error
- func (i Directions) Values() []enums.Enum
- type Family
- func (i Family) Desc() string
- func (i Family) Int64() int64
- func (i Family) MarshalText() ([]byte, error)
- func (i *Family) SetInt64(in int64)
- func (i *Family) SetString(s string) error
- func (i Family) String() string
- func (i *Family) UnmarshalText(text []byte) error
- func (i Family) Values() []enums.Enum
- type FontName
- type Hyperlink
- type Settings
- type Slants
- func (i Slants) Desc() string
- func (i Slants) Int64() int64
- func (i Slants) MarshalText() ([]byte, error)
- func (i *Slants) SetInt64(in int64)
- func (i *Slants) SetString(s string) error
- func (i Slants) String() string
- func (i *Slants) UnmarshalText(text []byte) error
- func (i Slants) Values() []enums.Enum
- type Specials
- func (i Specials) Desc() string
- func (i Specials) Int64() int64
- func (i Specials) MarshalText() ([]byte, error)
- func (i *Specials) SetInt64(in int64)
- func (i *Specials) SetString(s string) error
- func (i Specials) String() string
- func (i *Specials) UnmarshalText(text []byte) error
- func (i Specials) Values() []enums.Enum
- type Stretch
- func (i Stretch) Desc() string
- func (i Stretch) Int64() int64
- func (i Stretch) MarshalText() ([]byte, error)
- func (i *Stretch) SetInt64(in int64)
- func (i *Stretch) SetString(s string) error
- func (i Stretch) String() string
- func (s Stretch) ToFloat32() float32
- func (i *Stretch) UnmarshalText(text []byte) error
- func (i Stretch) Values() []enums.Enum
- type Style
- func (s *Style) Background() color.Color
- func (s *Style) Clone() *Style
- func (s *Style) Defaults()
- func (s *Style) FillColor() color.Color
- func (s *Style) FontFamily(ctx *Settings) string
- func (s *Style) FromProperties(parent *Style, properties map[string]any, ctxt colors.Context)
- func (s *Style) FromProperty(parent *Style, key string, val any, cc colors.Context)
- func (s *Style) FromRunes(rs []rune) []rune
- func (s *Style) InheritFields(parent *Style)
- func (s *Style) IsMath() bool
- func (s *Style) SetBackground(clr color.Color) *Style
- func (s *Style) SetDecoration(deco ...Decorations) *Style
- func (t *Style) SetDirection(v Directions) *Style
- func (t *Style) SetFamily(v Family) *Style
- func (s *Style) SetFillColor(clr color.Color) *Style
- func (s *Style) SetFromHTMLTag(tag string) bool
- func (s *Style) SetLink(url string) *Style
- func (s *Style) SetLinkStyle() *Style
- func (t *Style) SetSize(v float32) *Style
- func (t *Style) SetSlant(v Slants) *Style
- func (t *Style) SetSpecial(v Specials) *Style
- func (t *Style) SetStretch(v Stretch) *Style
- func (s *Style) SetStrokeColor(clr color.Color) *Style
- func (t *Style) SetURL(v string) *Style
- func (t *Style) SetWeight(v Weights) *Style
- func (s *Style) String() string
- func (s *Style) StrokeColor() color.Color
- func (s *Style) ToRunes() []rune
- type Text
- func (tx *Text) AddLink(s *Style, url, label string) *Text
- func (tx *Text) AddMathDisplay(s *Style, text string) *Text
- func (tx *Text) AddMathInline(s *Style, text string) *Text
- func (tx *Text) AddRunes(r []rune) *Text
- func (tx *Text) AddSpan(s *Style, r []rune) *Text
- func (tx *Text) AddSpanString(s *Style, r string) *Text
- func (tx *Text) AddSub(s *Style, text string) *Text
- func (tx *Text) AddSuper(s *Style, text string) *Text
- func (tx Text) At(li int) rune
- func (tx Text) AtTry(li int) (rune, bool)
- func (tx Text) Clone() Text
- func (tx Text) DebugDump()
- func (tx *Text) EndSpecial() *Text
- func (tx Text) GetLinks() []Hyperlink
- func (tx Text) Index(li int) (span, stylen, ridx int)
- func (tx *Text) InsertEndSpecial(at int) *Text
- func (tx *Text) InsertSpan(at int, s *Style, r []rune) *Text
- func (tx Text) Join() []rune
- func (tx Text) Len() int
- func (tx Text) NumSpans() int
- func (tx Text) Range(span int) (start, end int)
- func (tx *Text) SetSpanRunes(si int, r []rune) *Text
- func (tx *Text) SetSpanStyle(si int, nsty *Style) *Text
- func (tx Text) Span(si int) (*Style, []rune)
- func (tx Text) SpecialRange(si int) textpos.Range
- func (tx Text) Split() [][]rune
- func (tx Text) SplitCopy() [][]rune
- func (tx *Text) SplitSpaces()
- func (tx *Text) SplitSpan(li int) int
- func (tx *Text) StartSpecial(s *Style, special Specials, r []rune) *Text
- func (tx Text) String() string
- type Weights
- func (i Weights) Desc() string
- func (w Weights) HTMLTag() string
- func (i Weights) Int64() int64
- func (i Weights) MarshalText() ([]byte, error)
- func (i *Weights) SetInt64(in int64)
- func (i *Weights) SetString(s string) error
- func (i Weights) String() string
- func (w Weights) ToFloat32() float32
- func (i *Weights) UnmarshalText(text []byte) error
- func (i Weights) Values() []enums.Enum
Constants ¶
const ( DecorationStart = 0 DecorationMask = 0x000007FF // 11 bits reserved for deco SlantStart = 11 SlantMask = 0x00000800 // 1 bit for slant SpecialStart = 12 SpecialMask = 0x0000F000 StretchStart = 16 StretchMask = 0x000F0000 WeightStart = 20 WeightMask = 0x00F00000 FamilyStart = 24 FamilyMask = 0x0F000000 DirectionStart = 28 DirectionMask = 0xF0000000 )
Variables ¶
var FontSizes = map[string]float32{
"xx-small": 6.0 / 12.0,
"x-small": 8.0 / 12.0,
"small": 10.0 / 12.0,
"smallf": 10.0 / 12.0,
"medium": 1,
"large": 14.0 / 12.0,
"x-large": 18.0 / 12.0,
"xx-large": 24.0 / 12.0,
}
FontSizePoints maps standard font names to standard point sizes -- we use dpi zoom scaling instead of rescaling "medium" font size, so generally use these values as-is. smaller and larger relative scaling can move in 2pt increments
Functions ¶
func AddFamily ¶
AddFamily adds a family specifier to the given font string, handling the comma properly.
func ColorFromRune ¶
ColorFromRune converts given color from a rune uint32 value.
func ColorToRune ¶
ColorToRune converts given color to a rune uint32 value.
func FamiliesToList ¶
FamiliesToList returns a list of the families, split by comma and space removed.
func RuneFromDecoration ¶
func RuneFromDecoration(d Decorations) rune
RuneFromDecoration returns the rune bit values for given decoration.
func RuneFromDirection ¶
func RuneFromDirection(d Directions) rune
RuneFromDirection returns the rune bit values for given direction.
func RuneFromFamily ¶
RuneFromFamily returns the rune bit values for given family.
func RuneFromSlant ¶
RuneFromSlant returns the rune bit values for given slant.
func RuneFromSpecial ¶
RuneFromSpecial returns the rune bit values for given special.
func RuneFromStretch ¶
RuneFromStretch returns the rune bit values for given stretch.
func RuneFromStyle ¶
RuneFromStyle returns the style rune that encodes the given style values.
func RuneFromWeight ¶
RuneFromWeight returns the rune bit values for given weight.
func RuneToStyle ¶
RuneToStyle sets all the style values decoded from given rune.
Types ¶
type Decorations ¶
type Decorations int64 //enums:bitflag -transform kebab
Decorations are underline, line-through, etc, as bit flags that must be set using [Font.SetDecoration].
const ( // Underline indicates to place a line below text. Underline Decorations = iota // Overline indicates to place a line above text. Overline // LineThrough indicates to place a line through text. LineThrough // DottedUnderline is used for abbr tag. DottedUnderline // ParagraphStart indicates that this text is the start of a paragraph, // and therefore may be indented according to [text.Style] settings. ParagraphStart )
const DecorationsN Decorations = 5
DecorationsN is the highest valid value for type Decorations, plus one.
func DecorationsValues ¶
func DecorationsValues() []Decorations
DecorationsValues returns all possible values for the type Decorations.
func RuneToDecoration ¶
func RuneToDecoration(r rune) Decorations
RuneToDecoration returns the Decoration bit values from given rune.
func (Decorations) BitIndexString ¶
func (i Decorations) BitIndexString() string
BitIndexString returns the string representation of this Decorations value if it is a bit index value (typically an enum constant), and not an actual bit flag value.
func (Decorations) Desc ¶
func (i Decorations) Desc() string
Desc returns the description of the Decorations value.
func (*Decorations) HasFlag ¶
func (i *Decorations) HasFlag(f enums.BitFlag) bool
HasFlag returns whether these bit flags have the given bit flag set.
func (Decorations) Int64 ¶
func (i Decorations) Int64() int64
Int64 returns the Decorations value as an int64.
func (Decorations) MarshalText ¶
func (i Decorations) MarshalText() ([]byte, error)
MarshalText implements the encoding.TextMarshaler interface.
func (Decorations) NumColors ¶
func (d Decorations) NumColors() int
NumColors returns the number of colors used by this decoration setting.
func (*Decorations) SetFlag ¶
func (i *Decorations) SetFlag(on bool, f ...enums.BitFlag)
SetFlag sets the value of the given flags in these flags to the given value.
func (*Decorations) SetInt64 ¶
func (i *Decorations) SetInt64(in int64)
SetInt64 sets the Decorations value from an int64.
func (*Decorations) SetString ¶
func (i *Decorations) SetString(s string) error
SetString sets the Decorations value from its string representation, and returns an error if the string is invalid.
func (*Decorations) SetStringOr ¶
func (i *Decorations) SetStringOr(s string) error
SetStringOr sets the Decorations value from its string representation while preserving any bit flags already set, and returns an error if the string is invalid.
func (Decorations) String ¶
func (i Decorations) String() string
String returns the string representation of this Decorations value.
func (*Decorations) UnmarshalText ¶
func (i *Decorations) UnmarshalText(text []byte) error
UnmarshalText implements the encoding.TextUnmarshaler interface.
func (Decorations) Values ¶
func (i Decorations) Values() []enums.Enum
Values returns all possible values for the type Decorations.
type Directions ¶
type Directions int32 //enums:enum -transform kebab
Directions specifies the text layout direction.
const ( // LTR is Left-to-Right text. LTR Directions = iota // RTL is Right-to-Left text. RTL // TTB is Top-to-Bottom text. TTB // BTT is Bottom-to-Top text. BTT // Default uses the [text.Style] default direction. Default )
const DirectionsN Directions = 5
DirectionsN is the highest valid value for type Directions, plus one.
func DirectionsValues ¶
func DirectionsValues() []Directions
DirectionsValues returns all possible values for the type Directions.
func RuneToDirection ¶
func RuneToDirection(r rune) Directions
RuneToDirection returns the Directions value from given rune.
func (Directions) Desc ¶
func (i Directions) Desc() string
Desc returns the description of the Directions value.
func (Directions) Int64 ¶
func (i Directions) Int64() int64
Int64 returns the Directions value as an int64.
func (Directions) IsVertical ¶
func (d Directions) IsVertical() bool
IsVertical returns true if given text is vertical.
func (Directions) MarshalText ¶
func (i Directions) MarshalText() ([]byte, error)
MarshalText implements the encoding.TextMarshaler interface.
func (*Directions) SetInt64 ¶
func (i *Directions) SetInt64(in int64)
SetInt64 sets the Directions value from an int64.
func (*Directions) SetString ¶
func (i *Directions) SetString(s string) error
SetString sets the Directions value from its string representation, and returns an error if the string is invalid.
func (Directions) String ¶
func (i Directions) String() string
String returns the string representation of this Directions value.
func (Directions) ToGoText ¶
func (d Directions) ToGoText() di.Direction
ToGoText returns the go-text version of direction.
func (*Directions) UnmarshalText ¶
func (i *Directions) UnmarshalText(text []byte) error
UnmarshalText implements the encoding.TextUnmarshaler interface.
func (Directions) Values ¶
func (i Directions) Values() []enums.Enum
Values returns all possible values for the type Directions.
type Family ¶
type Family int32 //enums:enum -trim-prefix Family -transform kebab
Family specifies the generic family of typeface to use, where the specific named values to use for each are provided in the Settings.
const ( // SansSerif is a font without serifs, where glyphs have plain stroke endings, // without ornamentation. Example sans-serif fonts include Arial, Helvetica, // Open Sans, Fira Sans, Lucida Sans, Lucida Sans Unicode, Trebuchet MS, // Liberation Sans, and Nimbus Sans L. SansSerif Family = iota // Serif is a small line or stroke attached to the end of a larger stroke // in a letter. In serif fonts, glyphs have finishing strokes, flared or // tapering ends. Examples include Times New Roman, Lucida Bright, // Lucida Fax, Palatino, Palatino Linotype, Palladio, and URW Palladio. Serif // Monospace fonts have all glyphs with he same fixed width. // Example monospace fonts include Fira Mono, DejaVu Sans Mono, // Menlo, Consolas, Liberation Mono, Monaco, and Lucida Console. Monospace // Cursive glyphs generally have either joining strokes or other cursive // characteristics beyond those of italic typefaces. The glyphs are partially // or completely connected, and the result looks more like handwritten pen or // brush writing than printed letter work. Example cursive fonts include // Brush Script MT, Brush Script Std, Lucida Calligraphy, Lucida Handwriting, // and Apple Chancery. Cursive // Fantasy fonts are primarily decorative fonts that contain playful // representations of characters. Example fantasy fonts include Papyrus, // Herculanum, Party LET, Curlz MT, and Harrington. Fantasy // Math fonts are for displaying mathematical expressions, for example // superscript and subscript, brackets that cross several lines, nesting // expressions, and double-struck glyphs with distinct meanings. Math // Emoji fonts are specifically designed to render emoji. Emoji // Fangsong are a particular style of Chinese characters that are between // serif-style Song and cursive-style Kai forms. This style is often used // for government documents. Fangsong // Custom is a custom font name that is specified in the [text.Style] // CustomFont name. Custom )
const FamilyN Family = 9
FamilyN is the highest valid value for type Family, plus one.
func FamilyValues ¶
func FamilyValues() []Family
FamilyValues returns all possible values for the type Family.
func RuneToFamily ¶
RuneToFamily returns the Familys value from given rune.
func (Family) MarshalText ¶
MarshalText implements the encoding.TextMarshaler interface.
func (*Family) SetString ¶
SetString sets the Family value from its string representation, and returns an error if the string is invalid.
func (*Family) UnmarshalText ¶
UnmarshalText implements the encoding.TextUnmarshaler interface.
type FontName ¶
type FontName string
FontName is a special string that provides a font chooser. It is aliased to [core.FontName] as well.
type Hyperlink ¶
type Hyperlink struct { // Label is the text label for the link. Label string // URL is the full URL for the link. URL string // Range defines the starting and ending positions of the link, // in terms of source rune indexes. Range textpos.Range }
Hyperlink represents a hyperlink within shaped text.
type Settings ¶
type Settings struct { // Language is the preferred language used for rendering text. Language language.Language // Script is the specific writing system used for rendering text. // todo: no idea how to set this based on language or anything else. Script language.Script `display:"-"` // SansSerif is a font without serifs, where glyphs have plain stroke endings, // without ornamentation. Example sans-serif fonts include Arial, Helvetica, // Noto Sans, Open Sans, Fira Sans, Lucida Sans, Lucida Sans Unicode, Trebuchet MS, // Liberation Sans, Nimbus Sans L, Roboto. // This can be a list of comma-separated names, tried in order. // "sans-serif" will be added automatically as a final backup. SansSerif FontName `default:"Noto Sans"` // Serif is a small line or stroke attached to the end of a larger stroke // in a letter. In serif fonts, glyphs have finishing strokes, flared or // tapering ends. Examples include Times New Roman, Lucida Bright, // Lucida Fax, Palatino, Palatino Linotype, Palladio, and URW Palladio. // This can be a list of comma-separated names, tried in order. // "serif" will be added automatically as a final backup. Serif FontName // Monospace fonts have all glyphs with he same fixed width. // Example monospace fonts include Roboto Mono, Fira Mono, DejaVu Sans Mono, // Menlo, Consolas, Liberation Mono, Monaco, and Lucida Console. // This can be a list of comma-separated names. serif will be added // automatically as a final backup. // This can be a list of comma-separated names, tried in order. // "monospace" will be added automatically as a final backup. Monospace FontName `default:"Roboto Mono"` // Cursive glyphs generally have either joining strokes or other cursive // characteristics beyond those of italic typefaces. The glyphs are partially // or completely connected, and the result looks more like handwritten pen or // brush writing than printed letter work. Example cursive fonts include // Brush Script MT, Brush Script Std, Lucida Calligraphy, Lucida Handwriting, // and Apple Chancery. // This can be a list of comma-separated names, tried in order. // "cursive" will be added automatically as a final backup. Cursive FontName // Fantasy fonts are primarily decorative fonts that contain playful // representations of characters. Example fantasy fonts include Papyrus, // Herculanum, Party LET, Curlz MT, and Harrington. // This can be a list of comma-separated names, tried in order. // "fantasy" will be added automatically as a final backup. Fantasy FontName // Math fonts are for displaying mathematical expressions, for example // superscript and subscript, brackets that cross several lines, nesting // expressions, and double-struck glyphs with distinct meanings. // This can be a list of comma-separated names, tried in order. // "math" will be added automatically as a final backup. Math FontName // Emoji fonts are specifically designed to render emoji. // This can be a list of comma-separated names, tried in order. // "emoji" will be added automatically as a final backup. Emoji FontName // Fangsong are a particular style of Chinese characters that are between // serif-style Song and cursive-style Kai forms. This style is often used // for government documents. // This can be a list of comma-separated names, tried in order. // "fangsong" will be added automatically as a final backup. Fangsong FontName }
Settings holds the global settings for rich text styling, including language, script, and preferred font faces for each category of font.
var DefaultSettings Settings
DefaultSettings contains the default global text settings. This will be updated from rich.DefaultSettings.
type Slants ¶
type Slants int32 //enums:enum -trim-prefix Slant -transform kebab
Slants (also called style) allows italic or oblique faces to be selected.
const SlantsN Slants = 2
SlantsN is the highest valid value for type Slants, plus one.
func RuneToSlant ¶
RuneToSlant returns the Slants value from given rune.
func SlantsValues ¶
func SlantsValues() []Slants
SlantsValues returns all possible values for the type Slants.
func (Slants) MarshalText ¶
MarshalText implements the encoding.TextMarshaler interface.
func (*Slants) SetString ¶
SetString sets the Slants value from its string representation, and returns an error if the string is invalid.
func (*Slants) UnmarshalText ¶
UnmarshalText implements the encoding.TextUnmarshaler interface.
type Specials ¶
type Specials int32 //enums:enum -transform kebab
Specials are special additional mutually exclusive formatting factors that are not otherwise captured by changes in font rendering properties or decorations. Each special must be terminated by an End span element, on its own, which pops the stack on the last special that was started. Use Text.StartSpecial and Text.EndSpecial to manage the specials, avoiding the potential for repeating the start of a given special.
const ( // Nothing special. Nothing Specials = iota // Super starts super-scripted text. Super // Sub starts sub-scripted text. Sub // Link starts a hyperlink, which is in the URL field of the // style, and encoded in the runes after the style runes. // It also identifies this span for functional interactions // such as hovering and clicking. It does not specify the styling, // which therefore must be set in addition. Link // MathInline starts a TeX formatted math sequence, styled for // inclusion inline with other text. MathInline // MathDisplay starts a TeX formatted math sequence, styled as // a larger standalone display. MathDisplay // Quote starts an indented paragraph-level quote. Quote // End must be added to terminate the last Special started: use [Text.AddEnd]. // The renderer maintains a stack of special elements. End )
const SpecialsN Specials = 8
SpecialsN is the highest valid value for type Specials, plus one.
func RuneToSpecial ¶
RuneToSpecial returns the Specials value from given rune.
func SpecialsValues ¶
func SpecialsValues() []Specials
SpecialsValues returns all possible values for the type Specials.
func (Specials) MarshalText ¶
MarshalText implements the encoding.TextMarshaler interface.
func (*Specials) SetString ¶
SetString sets the Specials value from its string representation, and returns an error if the string is invalid.
func (*Specials) UnmarshalText ¶
UnmarshalText implements the encoding.TextUnmarshaler interface.
type Stretch ¶
type Stretch int32 //enums:enum -trim-prefix Stretch -transform kebab
Stretch is the width of a font as an approximate fraction of the normal width. Widths range from 0.5 to 2.0 inclusive, with 1.0 as the normal width.
const ( // Ultra-condensed width (50%), the narrowest possible. UltraCondensed Stretch = iota // Extra-condensed width (62.5%). ExtraCondensed // Condensed width (75%). Condensed // Semi-condensed width (87.5%). SemiCondensed // Normal width (100%). StretchNormal // Semi-expanded width (112.5%). SemiExpanded // Expanded width (125%). Expanded // Extra-expanded width (150%). ExtraExpanded // Ultra-expanded width (200%), the widest possible. UltraExpanded )
const StretchN Stretch = 9
StretchN is the highest valid value for type Stretch, plus one.
func RuneToStretch ¶
RuneToStretch returns the Stretch value from given rune.
func StretchValues ¶
func StretchValues() []Stretch
StretchValues returns all possible values for the type Stretch.
func (Stretch) MarshalText ¶
MarshalText implements the encoding.TextMarshaler interface.
func (*Stretch) SetString ¶
SetString sets the Stretch value from its string representation, and returns an error if the string is invalid.
func (*Stretch) UnmarshalText ¶
UnmarshalText implements the encoding.TextUnmarshaler interface.
type Style ¶
type Style struct { // Size is the font size multiplier relative to the standard font size // specified in the [text.Style]. Size float32 // Family indicates the generic family of typeface to use, where the // specific named values to use for each are provided in the [Settings], // or [text.Style] for [Custom]. Family Family // Slant allows italic or oblique faces to be selected. Slant Slants // Weights are the degree of blackness or stroke thickness of a font. // This value ranges from 100.0 to 900.0, with 400.0 as normal. Weight Weights // Stretch is the width of a font as an approximate fraction of the normal width. // Widths range from 0.5 to 2.0 inclusive, with 1.0 as the normal width. Stretch Stretch // Special additional formatting factors that are not otherwise // captured by changes in font rendering properties or decorations. // See [Specials] for usage information: use [Text.StartSpecial] // and [Text.EndSpecial] to set. Special Specials // Decorations are underline, line-through, etc, as bit flags // that must be set using [Decorations.SetFlag]. Decoration Decorations `set:"-"` // Direction is the direction to render the text. Direction Directions // URL is the URL for a link element. It is encoded in runes after the style runes. URL string // contains filtered or unexported fields }
Style contains all of the rich text styling properties, that apply to one span of text. These are encoded into a uint32 rune value in rich.Text. See [text.Style] and Settings for additional context needed for full specification.
func NewStyleFromRunes ¶
NewStyleFromRunes returns a new style initialized with data from given runes, returning the remaining actual rune string content after style data.
func (*Style) Background ¶
func (*Style) FontFamily ¶
FontFamily returns the font family name(s) based on [Style.Family] and the values specified in the given Settings.
func (*Style) FromProperties ¶
FromProperties sets style field values based on the given property list.
func (*Style) FromProperty ¶
FromProperty sets style field values based on the given property key and value.
func (*Style) FromRunes ¶
FromRunes sets the Style properties from the given rune encodings which must be the proper length including colors. Any remaining runes after the style runes are returned: this is the source string.
func (*Style) InheritFields ¶
InheritFields from parent
func (*Style) SetBackground ¶
SetBackground sets the background color to given color, setting the Decoration flag and the color value. The background is not normally colored so it renders over any background.
func (*Style) SetDecoration ¶
func (s *Style) SetDecoration(deco ...Decorations) *Style
SetDecoration sets given decoration flag(s) on.
func (*Style) SetDirection ¶
func (t *Style) SetDirection(v Directions) *Style
SetDirection sets the [Style.Direction]: Direction is the direction to render the text.
func (*Style) SetFamily ¶
SetFamily sets the [Style.Family]: Family indicates the generic family of typeface to use, where the specific named values to use for each are provided in the Settings, or [text.Style] for Custom.
func (*Style) SetFillColor ¶
SetFillColor sets the fill color to given color, setting the Decoration flag and the color value.
func (*Style) SetFromHTMLTag ¶
SetFromHTMLTag sets the styling parameters for simple HTML style tags. Returns true if handled.
func (*Style) SetLink ¶
SetLink sets the given style as a hyperlink, with given URL, and default link styling.
func (*Style) SetLinkStyle ¶
SetLinkStyle sets the default hyperlink styling: primary.Base color (e.g., blue) and Underline.
func (*Style) SetSize ¶
SetSize sets the [Style.Size]: Size is the font size multiplier relative to the standard font size specified in the [text.Style].
func (*Style) SetSlant ¶
SetSlant sets the [Style.Slant]: Slant allows italic or oblique faces to be selected.
func (*Style) SetSpecial ¶
SetSpecial sets the [Style.Special]: Special additional formatting factors that are not otherwise captured by changes in font rendering properties or decorations. See Specials for usage information: use Text.StartSpecial and Text.EndSpecial to set.
func (*Style) SetStretch ¶
SetStretch sets the [Style.Stretch]: Stretch is the width of a font as an approximate fraction of the normal width. Widths range from 0.5 to 2.0 inclusive, with 1.0 as the normal width.
func (*Style) SetStrokeColor ¶
SetStrokeColor sets the stroke color to given color, setting the Decoration flag and the color value. This is normally not set: it looks like an outline of the glyph at larger font sizes, and will make smaller font sizes look significantly thicker.
func (*Style) SetURL ¶
SetURL sets the [Style.URL]: URL is the URL for a link element. It is encoded in runes after the style runes.
func (*Style) SetWeight ¶
SetWeight sets the [Style.Weight]: Weights are the degree of blackness or stroke thickness of a font. This value ranges from 100.0 to 900.0, with 400.0 as normal.
func (*Style) StrokeColor ¶
type Text ¶
type Text [][]rune
Text is the basic rich text representation, with spans of []rune unicode characters that share a common set of text styling properties, which are represented by the first rune(s) in each span. If custom colors are used, they are encoded after the first style and size runes. This compact and efficient representation can be Join'd back into the raw unicode source, and indexing by rune index in the original is fast. It provides a GPU-compatible representation, and is the text equivalent of the [ppath.Path] encoding.
func NewPlainText ¶
NewPlainText returns a new Text starting with default style and runes string, which can be empty.
func NewText ¶
NewText returns a new Text starting with given style and runes string, which can be empty.
func (*Text) AddLink ¶
AddLink adds a Link special with given url and label text. This calls StartSpecial and EndSpecial for you. If the link requires further formatting, use those functions separately.
func (*Text) AddMathDisplay ¶
AddMathDisplay adds a MathDisplay special with given text. This calls StartSpecial and EndSpecial for you. If the Math requires further formatting, use those functions separately.
func (*Text) AddMathInline ¶
AddMathInline adds a MathInline special with given text. This calls StartSpecial and EndSpecial for you. If the Math requires further formatting, use those functions separately.
func (*Text) AddRunes ¶
AddRunes adds given runes to current span. If no existing span, then a new default one is made.
func (*Text) AddSpan ¶
AddSpan adds a span to the Text using the given Style and runes. The Text is modified for convenience in the high-frequency use-case. Clone first to avoid changing the original.
func (*Text) AddSpanString ¶
AddSpanString adds a span to the Text using the given Style and string content. The Text is modified for convenience in the high-frequency use-case. Clone first to avoid changing the original.
func (*Text) AddSub ¶
AddSub adds a Sub special with given text. This calls StartSpecial and EndSpecial for you. If the Sub requires further formatting, use those functions separately.
func (*Text) AddSuper ¶
AddSuper adds a Super special with given text. This calls StartSpecial and EndSpecial for you. If the Super requires further formatting, use those functions separately.
func (Text) At ¶
At returns the rune at given logical index into the original source rune slice without any styling elements. Returns 0 if index is invalid. See AtTry for a version that also returns a bool indicating whether the index is valid.
func (Text) AtTry ¶
AtTry returns the rune at given logical index, as in the original source rune slice without any styling elements. Returns 0 and false if index is invalid.
func (Text) Clone ¶
Clone returns a deep copy clone of the current text, safe for subsequent modification without affecting this one.
func (*Text) EndSpecial ¶
EndSpecial adds an End Special to the Text, to terminate the current Special. All Specials must be terminated with this empty end tag.
func (Text) Index ¶
Index returns the span index, number of style runes at start of span, and index into actual runes within the span after style runes, for the given logical index into the original source rune slice without spans or styling elements. If the logical index is invalid for the text returns -1,-1,-1.
func (*Text) InsertEndSpecial ¶
InsertEndSpecial inserts an End Special to the Text at given span index, to terminate the current Special. All Specials must be terminated with this empty end tag.
func (*Text) InsertSpan ¶
InsertSpan inserts a span to the Text at given span index, using the given Style and runes. The Text is modified for convenience in the high-frequency use-case. Clone first to avoid changing the original.
func (Text) Range ¶
Range returns the start, end range of indexes into original source for given span index.
func (*Text) SetSpanRunes ¶
SetSpanRunes sets the runes for given span.
func (*Text) SetSpanStyle ¶
SetSpanStyle sets the style for given span, updating the runes to encode it.
func (Text) Span ¶
Span returns the Style and []rune content for given span index. Returns nil if out of range.
func (Text) SpecialRange ¶
SpecialRange returns the range of spans for the special starting at given span index. Returns -1 if span at given index is not a special.
func (Text) Split ¶
Split returns the raw rune spans without any styles. The rune span slices here point directly into the Text rune slices. See SplitCopy for a version that makes a copy instead.
func (Text) SplitCopy ¶
SplitCopy returns the raw rune spans without any styles. The rune span slices here are new copies; see also Text.Split.
func (*Text) SplitSpaces ¶
func (tx *Text) SplitSpaces()
SplitSpaces splits this text after first unicode space after non-space.
func (*Text) SplitSpan ¶
SplitSpan splits an existing span at the given logical source index, with the span containing that logical index truncated to contain runes just before the index, and a new span inserted starting at that index, with the remaining contents of the original containing span. If that logical index is already the start of a span, or the logical index is invalid, nothing happens. Returns the index of span, which will be negative if the logical index is out of range.
func (*Text) StartSpecial ¶
StartSpecial adds a Span of given Special type to the Text, using given style and rune text. This creates a new style with the special value set, to avoid accidentally repeating the start of new specials.
type Weights ¶
type Weights int32 //enums:enum -transform kebab
Weights are the degree of blackness or stroke thickness of a font. The corresponding value ranges from 100.0 to 900.0, with 400.0 as normal.
const ( // Thin weight (100), the thinnest value. Thin Weights = iota // Extra light weight (200). ExtraLight // Light weight (300). Light // Normal (400). Normal // Medium weight (500, higher than normal). Medium // Semibold weight (600). Semibold // Bold weight (700). Bold // Extra-bold weight (800). ExtraBold // Black weight (900), the thickest value. Black )
const WeightsN Weights = 9
WeightsN is the highest valid value for type Weights, plus one.
func RuneToWeight ¶
RuneToWeight returns the Weights value from given rune.
func WeightsValues ¶
func WeightsValues() []Weights
WeightsValues returns all possible values for the type Weights.
func (Weights) MarshalText ¶
MarshalText implements the encoding.TextMarshaler interface.
func (*Weights) SetString ¶
SetString sets the Weights value from its string representation, and returns an error if the string is invalid.
func (*Weights) UnmarshalText ¶
UnmarshalText implements the encoding.TextUnmarshaler interface.