Documentation ¶
Index ¶
- func CanBreakText(fc FontConfiguration, t []rune) pr.MaybeBool
- func CharacterRatio(style_ pr.ElementStyle, cache pr.TextRatioCache, isCh bool, ...) pr.Float
- func GetLangQuotes(lang string) (open, close pr.Strings)
- func GetLastWordEnd(fc FontConfiguration, t []rune) int
- func PangoUnitsFromFloat(v pr.Fl) int32
- func PangoUnitsToFloat(v pango.Unit) pr.Fl
- func StrutLayout(style_ pr.StyleAccessor, context TextLayoutContext) (result [2]pr.Float)
- type EngineLayout
- type Feature
- type FontConfiguration
- type FontConfigurationPango
- type FontOrigin
- type FontStretch
- type FontStyle
- type HyphenDictKey
- type HyphenateZone
- type Hyphens
- type LineMetrics
- type OverflowWrap
- type Splitted
- type StrutLayoutKey
- type TabSize
- type TextLayoutContext
- type TextLayoutPango
- func (p *TextLayoutPango) ApplyJustification()
- func (p *TextLayoutPango) GetFirstLine() (*pango.LayoutLine, int)
- func (p *TextLayoutPango) Justification() pr.Float
- func (p *TextLayoutPango) Metrics() *LineMetrics
- func (p *TextLayoutPango) SetJustification(spacing pr.Float)
- func (p *TextLayoutPango) SetText(text string)
- func (p *TextLayoutPango) Text() []rune
- type TextStyle
- type Variation
- type Whitespace
- type WordBreak
Constants ¶
This section is empty.
Variables ¶
This section is empty.
Functions ¶
func CanBreakText ¶
func CanBreakText(fc FontConfiguration, t []rune) pr.MaybeBool
func CharacterRatio ¶ added in v0.0.3
func CharacterRatio(style_ pr.ElementStyle, cache pr.TextRatioCache, isCh bool, fonts FontConfiguration) pr.Float
CharacterRatio returns the ratio 1ex/font_size or 1ch/font_size, according to given style. It should be used with a valid text context to get accurate result. Otherwise, if context is `nil`, it returns 1 as a default value. It does not query WordSpacing or LetterSpacing from the style.
func GetLangQuotes ¶ added in v0.0.10
func GetLastWordEnd ¶
func GetLastWordEnd(fc FontConfiguration, t []rune) int
GetLastWordEnd returns the index in `t` of the last word, or -1
func PangoUnitsFromFloat ¶
func StrutLayout ¶
func StrutLayout(style_ pr.StyleAccessor, context TextLayoutContext) (result [2]pr.Float)
StrutLayout returns a tuple of the used value of `line-height` and the baseline. The baseline is given from the top edge of line height. context is mandatory for the text layout.
Types ¶
type EngineLayout ¶ added in v0.0.8
type EngineLayout interface { // Text returns a readonly slice of the text in the layout Text() []rune // Metrics may return nil when [TextDecorationLine] is empty Metrics() *LineMetrics // Justification returns the current justification Justification() pr.Float // SetJustification add an additional spacing between words // to justify text. Depending on the implementation, it // may be ignored until [ApplyJustification] is called. SetJustification(spacing pr.Float) ApplyJustification() }
EngineLayout stores the text engine dependant version of the laid out text.
Is is only meant to be consumed by the text/draw package.
type FontConfiguration ¶
type FontConfiguration interface { // FontContent returns the content of the given font, which may be needed // in the final output. FontContent(font FontOrigin) []byte // AddFontFace load a font file from an external source, using // the given [urlFetcher], which must be valid. // // It returns the file name of the loaded file. AddFontFace(ruleDescriptors validation.FontFaceDescriptors, urlFetcher utils.UrlFetcher) string // contains filtered or unexported methods }
FontConfiguration holds information about the available fonts on the system. It is used for text layout at various steps of the rendering process.
It is implemented by and totaly tighted to text engines, either pango or go-text.
type FontConfigurationPango ¶ added in v0.0.8
type FontConfigurationPango struct {
// contains filtered or unexported fields
}
FontConfigurationPango holds information about the available fonts on the system. It is used for text layout at various steps of the process.
func NewFontConfigurationPango ¶ added in v0.0.8
func NewFontConfigurationPango(fontmap *fcfonts.FontMap) *FontConfigurationPango
NewFontConfigurationPango uses a fontconfig database to create a new font configuration
func (*FontConfigurationPango) AddFontFace ¶ added in v0.0.8
func (f *FontConfigurationPango) AddFontFace(ruleDescriptors validation.FontFaceDescriptors, urlFetcher utils.UrlFetcher) string
func (*FontConfigurationPango) FontContent ¶ added in v0.0.8
func (f *FontConfigurationPango) FontContent(font FontOrigin) []byte
FontContent returns the content of the given face, which may be needed in the final output.
func (*FontConfigurationPango) LoadFace ¶ added in v0.0.8
func (f *FontConfigurationPango) LoadFace(key fonts.FaceID, format fc.FontFormat) (fonts.Face, error)
type FontOrigin ¶ added in v0.0.8
type FontOrigin struct { File string // The filename or identifier of the font file. // The index of the face in a collection. It is always 0 for // single font files. Index uint16 // For variable fonts, stores 1 + the instance index. // (0 to ignore variations). Instance uint16 }
FontOrigin is a reference to a binary font file, either on disk or stored in memory.
type FontStretch ¶ added in v0.0.7
type FontStretch uint8
const ( FSeUltraCondensed FontStretch = iota // ultra condensed width FSeExtraCondensed // extra condensed width FSeCondensed // condensed width FSeSemiCondensed // semi condensed width FSeNormal // the normal width FSeSemiExpanded // semi expanded width FSeExpanded // expanded width FSeExtraExpanded // extra expanded width FSeUltraExpanded // ultra expanded width )
type HyphenDictKey ¶
type HyphenDictKey struct {
// contains filtered or unexported fields
}
type HyphenateZone ¶ added in v0.0.7
type LineMetrics ¶ added in v0.0.7
type LineMetrics struct { // Distance from the baseline to the logical top of a line of text. // (The logical top may be above or below the top of the // actual drawn ink. It is necessary to lay out the text to figure // where the ink will be.) Ascent pr.Fl // Distance above the baseline of the top of the underline. // Since most fonts have underline positions beneath the baseline, this value is typically negative. UnderlinePosition pr.Fl // Suggested thickness to draw for the underline. UnderlineThickness pr.Fl // Distance above the baseline of the top of the strikethrough. StrikethroughPosition pr.Fl // Suggested thickness to draw for the strikethrough. StrikethroughThickness pr.Fl }
type OverflowWrap ¶ added in v0.0.7
type OverflowWrap uint8
const ( ONormal OverflowWrap = iota OAnywhere OBreakWord )
type Splitted ¶
type Splitted struct { // Output layout containing (at least) the first line Layout EngineLayout // Length in runes of the first line Length int // ResumeAt is the number of runes to skip for the next line. // May be -1 if the whole text fits in one line. // This may be greater than [Length] in case of preserved // newline characters. ResumeAt int // Width is the width in pixels of the first line Width pr.Float // Height is the height in pixels of the first line Height pr.Float // Baseline is the baseline in pixels of the first line Baseline pr.Float FirstLineRTL bool // true is the first line direction is RTL }
Splitted exposes the result of laying out one line of text
func SplitFirstLine ¶
func SplitFirstLine(text_ string, style_ pr.StyleAccessor, context TextLayoutContext, maxWidth pr.MaybeFloat, minimum, isLineStart bool, ) Splitted
SplitFirstLine fit as much text from [text_] as possible in the available width given by [maxWidth] minimum=False
type StrutLayoutKey ¶
type StrutLayoutKey struct {
// contains filtered or unexported fields
}
type TextLayoutContext ¶
type TextLayoutContext interface { Fonts() FontConfiguration HyphenCache() map[HyphenDictKey]hyphen.Hyphener StrutLayoutsCache() map[StrutLayoutKey][2]pr.Float }
type TextLayoutPango ¶ added in v0.0.8
type TextLayoutPango struct { Style *TextStyle MaxWidth pr.MaybeFloat Layout pango.Layout // contains filtered or unexported fields }
TextLayoutPango wraps a pango.Layout object
func (*TextLayoutPango) ApplyJustification ¶ added in v0.0.8
func (p *TextLayoutPango) ApplyJustification()
ApplyJustification re-layout the text, applying justification.
func (*TextLayoutPango) GetFirstLine ¶ added in v0.0.8
func (p *TextLayoutPango) GetFirstLine() (*pango.LayoutLine, int)
GetFirstLine returns the first line and the index of the second line, or -1.
func (*TextLayoutPango) Justification ¶ added in v0.0.8
func (p *TextLayoutPango) Justification() pr.Float
func (*TextLayoutPango) Metrics ¶ added in v0.0.8
func (p *TextLayoutPango) Metrics() *LineMetrics
func (*TextLayoutPango) SetJustification ¶ added in v0.0.8
func (p *TextLayoutPango) SetJustification(spacing pr.Float)
func (*TextLayoutPango) SetText ¶ added in v0.0.8
func (p *TextLayoutPango) SetText(text string)
func (*TextLayoutPango) Text ¶ added in v0.0.8
func (p *TextLayoutPango) Text() []rune
Text returns a readonly slice of the text used in the layout.
type TextStyle ¶ added in v0.0.7
type TextStyle struct { TextDecorationLine pr.Decorations // FontFeatures stores the resolved value // for all the CSS properties related : // "font-kerning" // "font-variant-ligatures" // "font-variant-position" // "font-variant-caps" // "font-variant-numeric" // "font-variant-alternates" // "font-variant-east-asian" // "font-feature-settings" FontFeatures []Feature FontFamily []string FontStyle FontStyle FontStretch FontStretch FontWeight int FontSize pr.Fl FontVariationSettings []Variation // empty for 'normal' FontLanguageOverride fontLanguageOverride Lang string WhiteSpace Whitespace OverflowWrap OverflowWrap WordBreak WordBreak Hyphens Hyphens HyphenateCharacter string HyphenateLimitChars pr.Ints3 HyphenateLimitZone HyphenateZone WordSpacing pr.Fl LetterSpacing pr.Fl // 0 for 'normal' TabSize TabSize }
TextStyle exposes the subset of a pr.Style required to layout text.
func NewTextStyle ¶ added in v0.0.7
func NewTextStyle(style pr.StyleAccessor, ignoreSpacing bool) *TextStyle
If ignoreSpacing is true, 'word-spacing' and 'letter-spacing' are not queried from [style]
type Whitespace ¶ added in v0.0.7
type Whitespace uint8
const ( WNormal Whitespace = iota WNowrap WPre WPreWrap WPreLine WBreakSpaces )
Directories ¶
Path | Synopsis |
---|---|
Package draw use a backend and a layout object to draw glyphs on the ouput.
|
Package draw use a backend and a layout object to draw glyphs on the ouput. |
Package hyphen hyphenates text using existing Hunspell hyphenation dictionaries.
|
Package hyphen hyphenates text using existing Hunspell hyphenation dictionaries. |