Documentation
¶
Index ¶
Constants ¶
This section is empty.
Variables ¶
var ( // errors returned by NewController ErrTolerance = fmt.Errorf("unable to break lines using current tolerances") ErrWordSize = fmt.Errorf("source text contains an unbreakable word that is longer than the maximum line length") // errors returned by DrawText ErrWidth = fmt.Errorf("target area must be at least as wide as the maximum line width") ErrEmpty = fmt.Errorf("source text buffer is empty") ErrLeading = fmt.Errorf("font leading must be greater than 0") ErrHeight = fmt.Errorf("target area must be at least as tall as the font leading") )
Functions ¶
Types ¶
type Controller ¶
type Controller struct {
// contains filtered or unexported fields
}
A Controller is a struct that aids in writing text to a ContentStream. The Controller can break text into lines and paragraphs, determine the appropriate kerning for glyphs in a string, and draw text according to the format specified by the ControllerCfg struct.
func NewController ¶
func NewController(src FormatText, lineWidth float64, f FontFamily, cfg ControllerCfg) (Controller, error)
NewController returns a Controller that is ready to write src to ContentStreams. It returns an invalid Controller and an error if it encounters a problem while parsing and shaping src. lineWidth should be the maximum desired width, in points, of each line of the output text when drawn to a gdf.ContentStream.
func (*Controller) DrawText ¶
func (tc *Controller) DrawText(c *gdf.ContentStream, area gdf.Rect) (gdf.Point, bool, error)
DrawText draws the text from the Controller to the area of c specified by area. The return gdf.Point is the position of c's TextCursor after the text has been drawn. (This value would not be otherwise accessible because each call to DrawText encompasses a c.BeginText/EndText pair.) The returned bool indicates whether the Controller's buffer still contains additional source text. If this value is true, then future calls to DrawText can be used to draw the remaining source text - usually to different areas or ContentStreams. Changes made to c's stroking color, nonstroking color, or render mode by the Controller will continue to affect operations on c after DrawText returns, unless they are manually reverted.
type ControllerCfg ¶
type ControllerCfg struct { Alignment Justification RenderMode gdf.RenderMode FontSize float64 Leading float64 IsIndented bool NColor, SColor gdf.Color // default nonstroking and stroking colors Looseness float64 // the ratio of the maximum allowable space advance and the normal space advance in justified text Tightness float64 // the ratio of the minimum allowable space advance and the normal space advance in justified text IsBold, IsItal bool }
A ControllerCfg specifies options for the formatting of text drawn by a Controller.
func NewControllerCfg ¶
func NewControllerCfg(fontSize, leading float64) ControllerCfg
type FontFamily ¶
type FormatText ¶
type FormatText []rune
FormatText represents a slice of runes that can specify the formatting and content of the source text. The TextController applies the following rules to the formatting directives contained in FormatText:
- rune(-1) is interpreted as end of text. Any runes that appear after this character will not be parsed.
- rune(-2) is interpreted as a color indicator. This character must be followed by three comma-separated 3-digit integers in [0,255] that specify the red, green, and blue components of an RGBColor. (This is equivalent to setting the nonstroking color of the document to RGBColor{R:float64(red)/255, G:float64(green)/255, B:float64(blue)/255}).
- rune(-3) toggles bold text on and off.
- rune(-4) toggles italic text on and off. The bold and italic indicators can be used to switch among fonts in a given font family.