Documentation ¶
Index ¶
- Constants
- type Font
- type FontFace
- type FontFamily
- func (family *FontFamily) Destroy()
- func (family *FontFamily) Face(size float64, col color.Color, style FontStyle, variant FontVariant) *FontFace
- func (family *FontFamily) FindLocalFont(name string, style FontStyle) string
- func (family *FontFamily) LoadFont(b []byte, index int, style FontStyle) error
- func (family *FontFamily) LoadFontCollection(filename string, index int, style FontStyle) error
- func (family *FontFamily) LoadFontFile(filename string, style FontStyle) error
- func (family *FontFamily) LoadLocalFont(name string, style FontStyle) error
- func (family *FontFamily) Name() string
- func (family *FontFamily) SetFeatures(features string)
- func (family *FontFamily) SetVariations(variations string)
- type FontMetrics
- type FontStyle
- type FontVariant
- type Rect
- type Resolution
- type RichText
- func (rt *RichText) Add(face *FontFace, text string) *RichText
- func (rt *RichText) Reset()
- func (rt *RichText) SetFace(face *FontFace)
- func (rt *RichText) SetFaceSpan(face *FontFace, start, end int)
- func (rt *RichText) SetWritingMode(mode WritingMode)
- func (rt *RichText) ToText(width, height float64, halign, valign TextAlign, indent, lineStretch float64) *Text
- type Text
- type TextAlign
- type TextSpan
- type WritingMode
Constants ¶
const DefaultResolution = Resolution(96.0 * inchPerMm)
DefaultResolution is the default resolution used for font PPEMs and is set to 96 DPI.
Variables ¶
This section is empty.
Functions ¶
This section is empty.
Types ¶
type Font ¶
Font defines an SFNT font such as TTF or OTF.
func (*Font) Destroy ¶
func (f *Font) Destroy()
Destroy should be called when using HarfBuzz to free the C resources.
func (*Font) SetFeatures ¶
SetFeatures sets the font features (not yet supported).
func (*Font) SetVariations ¶
SetVariations sets the font variations (not yet supported).
type FontFace ¶
type FontFace struct { Font *Font Size float64 // in pt Style FontStyle Variant FontVariant Color color.RGBA // faux styles for bold, italic, and sub- and superscript FauxBold, FauxItalic float64 XOffset, YOffset int32 Language string Script text.Script Direction text.Direction // contains filtered or unexported fields }
FontFace defines a font face from a given font. It specifies the font size, color, faux styles and font decorations.
func (*FontFace) Metrics ¶
func (face *FontFace) Metrics() FontMetrics
Metrics returns the font metrics. See https://developer.apple.com/library/archive/documentation/TextFonts/Conceptual/CocoaTextArchitecture/Art/glyph_metrics_2x.png for an explanation of the different metrics.
func (*FontFace) PPEM ¶
func (face *FontFace) PPEM(resolution Resolution) uint16
PPEM returns the pixels-per-EM for a given resolution of the font face.
type FontFamily ¶
type FontFamily struct {
// contains filtered or unexported fields
}
FontFamily contains a family of fonts (bold, italic, ...). Allowing to select an italic style as the native italic font or to use faux italic if not present.
func NewFontFamily ¶
func NewFontFamily(name string) *FontFamily
NewFontFamily returns a new font family.
func (*FontFamily) Destroy ¶
func (family *FontFamily) Destroy()
Destroy should be called when using HarfBuzz to free the C resources.
func (*FontFamily) Face ¶
func (family *FontFamily) Face(size float64, col color.Color, style FontStyle, variant FontVariant) *FontFace
Face gets the font face given by the font size in points and its style.
func (*FontFamily) FindLocalFont ¶
func (family *FontFamily) FindLocalFont(name string, style FontStyle) string
FindLocalFont finds the path to a font from the system's fonts.
func (*FontFamily) LoadFont ¶
func (family *FontFamily) LoadFont(b []byte, index int, style FontStyle) error
LoadFont loads a font from memory.
func (*FontFamily) LoadFontCollection ¶
func (family *FontFamily) LoadFontCollection(filename string, index int, style FontStyle) error
LoadFontCollection loads a font from a collection file and uses the font at the specified index.
func (*FontFamily) LoadFontFile ¶
func (family *FontFamily) LoadFontFile(filename string, style FontStyle) error
LoadFontFile loads a font from a file.
func (*FontFamily) LoadLocalFont ¶
func (family *FontFamily) LoadLocalFont(name string, style FontStyle) error
LoadLocalFont loads a font from the system's fonts.
func (*FontFamily) Name ¶
func (family *FontFamily) Name() string
Name returns the name of the font family.
func (*FontFamily) SetFeatures ¶
func (family *FontFamily) SetFeatures(features string)
SetFeatures sets the font features (not yet supported).
func (*FontFamily) SetVariations ¶
func (family *FontFamily) SetVariations(variations string)
SetVariations sets the font variations (not yet supported).
type FontMetrics ¶
type FontMetrics struct { LineHeight float64 Ascent float64 Descent float64 LineGap float64 XHeight float64 CapHeight float64 XMin, YMin float64 XMax, YMax float64 }
FontMetrics contains a number of metrics that define a font face. See https://developer.apple.com/library/archive/documentation/TextFonts/Conceptual/CocoaTextArchitecture/Art/glyph_metrics_2x.png for an explanation of the different metrics.
func (FontMetrics) String ¶
func (m FontMetrics) String() string
type FontStyle ¶
type FontStyle int
FontStyle defines the font style to be used for the font. It specifies a boldness with optionally italic, e.g. FontBlack | FontItalic will specify a black boldness (a font-weight of 800 in CSS) and italic.
const ( FontRegular FontStyle = iota // 400 FontExtraLight // 100 FontLight // 200 FontBook // 300 FontMedium // 500 FontSemibold // 600 FontBold // 700 FontBlack // 800 FontExtraBlack // 900 FontItalic FontStyle = 1 << 8 )
see FontStyle
type FontVariant ¶
type FontVariant int
FontVariant defines the font variant to be used for the font, such as subscript or smallcaps.
const ( FontNormal FontVariant = iota FontSubscript FontSuperscript FontSmallcaps )
see FontVariant
type Rect ¶
type Rect struct {
X, Y, W, H float64
}
Rect is a rectangle in 2D defined by a position and its width and height.
type Resolution ¶
type Resolution float64
Resolution is used for rasterizing. Higher resolutions will result in larger images.
func DPI ¶
func DPI(dpi float64) Resolution
DPI (dots-per-inch) for the resolution of rasterization.
func DPMM ¶
func DPMM(dpmm float64) Resolution
DPMM (dots-per-millimeter) for the resolution of rasterization.
func (Resolution) DPI ¶
func (res Resolution) DPI() float64
DPI returns the resolution in dots-per-inch.
func (Resolution) DPMM ¶
func (res Resolution) DPMM() float64
DPMM returns the resolution in dots-per-millimeter.
type RichText ¶
RichText allows to build up a rich text with text spans of different font faces and fitting that into a box using Donald Knuth's line breaking algorithm. TODO: RichText add support for decoration spans to properly underline the spaces betwee words too
func NewRichText ¶
NewRichText returns a new rich text with the given default font face.
func (*RichText) Reset ¶
func (rt *RichText) Reset()
Reset resets the rich text to its initial state.
func (*RichText) SetFaceSpan ¶
SetFaceSpan sets the font face between start and end measured in bytes.
func (*RichText) SetWritingMode ¶
func (rt *RichText) SetWritingMode(mode WritingMode)
SetWritingMode sets the final writing mode of the rich text.
type Text ¶
type Text struct { Face *FontFace Mode WritingMode // contains filtered or unexported fields }
Text holds the representation of a text object.
func NewTextBox ¶
func NewTextBox(face *FontFace, s string, width, height float64, halign, valign TextAlign, indent, lineStretch float64) *Text
NewTextBox is an advanced text formatter that will format text placement based on the settings. It takes a single font face, a string, the width or height of the box (can be zero to disable), horizontal and vertical alignment (Left, Center, Right, Top, Bottom or Justify), text indentation for the first line and line stretch (percentage to stretch the line based on the line height).
func NewTextLine ¶
NewTextLine is a simple text line using a single font face, a string (supporting new lines) and horizontal alignment (Left, Center, Right). The text's baseline will be drawn on the current coordinate.
func (*Text) Heights ¶
Heights returns the top and bottom position of the first and last line respectively.
func (*Text) MaxWordCountPerLine ¶ added in v1.0.2
MaxWordCountPerLine returns a maximum number of words in a line
type TextAlign ¶
type TextAlign int
TextAlign specifies how the text should align or whether it should be justified.
type TextSpan ¶
type TextSpan struct { Width float64 Face *FontFace Text string Glyphs []canvasText.Glyph Direction canvasText.Direction // contains filtered or unexported fields }
TextSpan is a span of text.
type WritingMode ¶
type WritingMode int
WritingMode specifies how the text lines should be laid out.
const ( HorizontalTB WritingMode = iota VerticalRL VerticalLR )
see WritingMode
func (WritingMode) String ¶
func (wm WritingMode) String() string