impeller/text

High-level API for text, typography, font sizes, and text colors.

Types

Paragraph = object
  handle*: ImpellerParagraph
Represents a laid out paragraph.
TextStyle = object
  fontFamily*: string        ## The font family to use for this text. This should match a family registered in the TypographyContext.
  fontSize*: float32         ## The font size in pixels. This can be set directly or derived from a TypographyPreset.
  fontWeight*: FontWeight    ## The font weight (e.g. normal, bold). This can be set directly or derived from a TypographyPreset.
  fontStyle*: FontStyle      ## The font style (e.g. normal, italic).
  color*: ColorRGBA          ## The text color. This is required and cannot be none. Use rgba(0,0,0,0) as a sentinel for "not set" if needed.
  background*: Option[ColorRGBA] ## Optional background color for the text. If none, no background will be drawn.
  align*: TextAlign          ## The text alignment for this style. If not set, the paragraph's default will be used.
  direction*: TextDirection = kImpellerTextDirectionLTR ## The text direction (LTR or RTL). If not set, the paragraph's default will be used.
  decoration*: Option[ImpellerTextDecoration] ## Optional text decoration (underline, line-through). If none, no decoration will be drawn.
Represents a style for a run of text.
TypographyContext = object
  handle*: ImpellerTypographyContext
Represents a typography context for font registration and text layout.

Procs

proc drawParagraph(builder: ImpellerDisplayListBuilder; para: Paragraph;
                   x, y: float32 = 0.0) {....raises: [], tags: [], forbids: [].}
Draws the paragraph at the given position.
proc getHeight(p: Paragraph): float32 {....raises: [], tags: [], forbids: [].}
Returns the height of the paragraph.
proc getWidth(p: Paragraph): float32 {....raises: [], tags: [], forbids: [].}
Returns the max width of the paragraph.
proc layoutParagraph(ctx: TypographyContext; text: string; style: TextStyle;
                     width: float32): Paragraph {....raises: [], tags: [],
    forbids: [].}
Lays out a paragraph of text with the given style and width.
proc newTextStyle(fontFamily: string = "sans-serif"; fontSize: float32 = 14.0;
                  fontWeight: FontWeight = kImpellerFontWeight400;
                  fontStyle: FontStyle = kImpellerFontStyleNormal;
                  color: ColorRGBA = rgba(0, 0, 0, 255);
                  background: Option[ColorRGBA] = none(ColorRGBA);
                  align: TextAlign = kImpellerTextAlignmentLeft;
                  direction: TextDirection = kImpellerTextDirectionLTR;
    decoration: Option[ImpellerTextDecoration] = none(ImpellerTextDecoration)): TextStyle {.
    ...raises: [], tags: [], forbids: [].}
Creates a new text style with the specified properties
proc newTypographyContext(): TypographyContext {....raises: [], tags: [],
    forbids: [].}
Creates a new typography context.
proc registerFont(ctx: var TypographyContext; fontData: seq[byte];
                  family: string): bool {....raises: [], tags: [], forbids: [].}
Registers a font from memory for use in this context.
proc release(ctx: var TypographyContext) {....raises: [], tags: [], forbids: [].}
Releases the typography context.
proc release(p: var Paragraph) {....raises: [], tags: [], forbids: [].}
Releases the paragraph resources.