Options
All
  • Public
  • Public/Protected
  • All
Menu

Class MarkupBox

An object capable of laying out styled text by parsing plain text that is marked up with HTML-like tags. To create an object of this class, it is normally recommended that you use the markupBox(sheet) function, which will set the correct resolution and define standard tags.

Note: Because it is based on a Java class, you may use the JavaScript engine's getter/setter syntax with a MarkupBox. For example, instead of box.setDefaultStyle(style); you can write box.defaultStyle = style;

Hierarchy

  • MarkupBox

Implements

Index

Constructors

constructor

  • Creates a default markup renderer for the specified resolution. Rather than constructing a MarkupBox directly, they are usually created with the markupBox(sheet) helper function.

    Parameters

    • ppi: number

      the target resolution, in pixels per inch

    Returns MarkupBox

Methods

draw

  • Lays out and draws the current markup text within the specified region.

    Parameters

    Returns number

    the y-coordinate where the next line would have started

drawAsSingleLine

  • Lays out and draws the current markup text within the specified region without inserting any line breaks. The markup text must not contain any explicit newline characters, or the result is undefined.

    Parameters

    Returns number

    the width of the line in pixels

getAlignment

  • getAlignment(): number
  • Returns the alignment bitmask that describes how text is laid out within a drawn rectangle.

    For example:

    if((box.alignment & LAYOUT_LEFT) != 0) println( "left-aligned text" );

    Returns number

    the current alignment layout value

getDefaultStyle

  • Returns the default style applied to text when no other tags are in effect. By modifying this style you control what "normal" text looks like.

    For example:

    box.defaultStyle = new TextStyle(
        FAMILY, bodyFamily,
        SIZE,   7,
        WEIGHT, WEIGHT_BOLD
    );

    You can modify the default style instead of replacing it with a new one. The following changes just the size without affecting other attributes:

    box.defaultStyle.add(SIZE, 10);

    Returns TextStyle

    the TextStyle applied to all text by default

getHeadlineAlignment

  • getHeadlineAlignment(): number
  • Returns the current horizontal alignment setting for heading tags.

    Returns number

    the current heading alignment layout value

getLineTightness

  • getLineTightness(): number
  • Returns the current line tightness.

    Returns number

    the line spacing tightness value

getPageShape

  • Returns the shape that drawn text will conform to within the draw region.

    Returns PageShape

getParametricStyleForTag

  • Returns the style factory associated with the tag, or null if the tag does not have a style factory set (including if it has a replacement or style set).

    Parameters

    • tagName: string

      the name of the tag (without angle brackets) to get the factory for

    Returns JavaObject<"ca.cgjennings.layout.ParametricStyleFactory">

    the previously set factory for the tag, or null

getReplacementForTag

  • getReplacementForTag(tagName: string): string
  • Returns the replacement string associated with the tag, or null if the tag does not have a replacement set (including if it has a style or parametric style set).

    Parameters

    • tagName: string

      the name of the tag to return the replacement string for

    Returns string

    the replacement string for the tag, or null

getScalingLimit

  • getScalingLimit(): number
  • Returns the current scaling limit for text shrinking when the FIT_SCALE_TEXT fitting metod is enabled.

    Returns number

    the scaling limit factor

getStyleForTag

  • Returns the TextStyle associated with the tag, or null if the tag does not have a non-parametric style set (including if it has a replacement or parametric style set).

    Parameters

    • tagName: string

      the name of the tag (without angle brackets) to fetch the style of

    Returns TextStyle

    the style for the requested tag, or null if it has no, or a different kind, of definition

getTabWidths

  • getTabWidths(): number[]
  • Returns an array of tab widths, in inches. (If only one stop has been set, the length of the array is 1.)

    Returns number[]

getTextFitting

  • getTextFitting(): number
  • Returns the constant representing the text fitting method to be used to fit text within a region.

    Returns number

    the text fitting method

getTightnessLimit

  • getTightnessLimit(): number
  • Returns the current line tightness limit.

    Returns number

    the minimum line spacing tightness value

measure

  • Lays out but does not draw the current markup text, returning the height of the text.

    Parameters

    Returns number

    the height of the text in pixels

parseLibrary

  • parseLibrary(definitions: string): void
  • Processes a markup string, retaining only any definitions that it creates with <define> tags. This method clears the current markup text, and setting markup text will clear any library definitions (after using them to process the markup). Therefore, libraries must be parsed again before each call to setMarkupText.

    Parameters

    • definitions: string

      a string containing markup definitions

    Returns void

removeAllTags

  • removeAllTags(): void
  • Removes all tag definitions from the box.

    Returns void

setAlignment

  • setAlignment(layoutBits: number): void
  • Sets the horizontal and vertical alignment of text within a drawn rectangle. This is the logical or of one of LAYOUT_LEFT, LAYOUT_RIGHT, or LAYOUT_CENTER with one of LAYOUT_TOP, LAYOUT_BOTTOM, or LAYOUT_MIDDLE. In addition, if the LAYOUT_JUSTIFY bit is set, then paragraphs will be fully justified so that they fill the entire region width.

    For example:

    box.alignment = LAYOUT_CENTER | LAYOUT_TOP | LAYOUT_JUSTIFY;

    Parameters

    • layoutBits: number

      a bitmask of alignment options

    Returns void

setDefaultStyle

  • Sets the default style that is applied to text when no other tags affect it.

    Parameters

    • style: TextStyle

      the TextStyle applied to all text by default

    Returns void

setHeadlineAlignment

  • setHeadlineAlignment(layoutBits: number): void
  • Sets the horizontal alignment used for text in heading tags (<h1>, <h2>, and so on). This is similar to setAlignment, but only the horizontal alignment component is used.

    Parameters

    • layoutBits: number

    Returns void

setLineTightness

  • setLineTightness(tightness: number): void
  • Sets how tightly lines are grouped together. For normal line spacing, use 1.0; double-spaced lines would be 2.0. Values less than 1 reduce the standard amount of space between lines; at 0 the bottom of one line will normally touch or overlap the top of the next. (The exact effect of this setting depends * on the font being used.)

    Parameters

    • tightness: number

      the tightness of interline spacing (normally 1.0)

    Returns void

setPageShape

  • Sets the shape that lines of text will conform to. A PageShape is used to flow text around other elements of a component. The default shape is PageShape.RECTANGLE_SHAPE, which allows text to cover the entire region passed to the draw method.

    Parameters

    Returns any

setParametricStyleForTag

  • Sets a parameter-based style for the given tag. When this tag occurs in the markup text, the factory will be used to create the actual style based on the tag's parameters. This is an advanced feature.

    The factory is an object that implements the interface ca.cgjennings.layout.ParametricStyleFactory, which consists of the single method: TextStyle createStyle(java.lang.String[] parameters).

    tagName : the name of the tag (without angle brackets) to set the factory for factory : a ParametricStyleFactory to be used to generate styles for this tag

    Parameters

    Returns void

setReplacementForTag

  • setReplacementForTag(tagName: string, replacement: string): void
  • Sets a replacement string to be associated with a particular tag. When this exact tag occurs in the markup text, it will be replaced by the replacement string.

    For example:

    // make the <copyright> tag produce the text © when rendering
    box.setReplacementForTag( "copyright", "©" );

    Parameters

    • tagName: string

      the name of the replacement tag

    • replacement: string

      the text to replace the tag with

    Returns void

setScalingLimit

  • setScalingLimit(factor: number): void
  • Sets the limit for shrinking text when the FIT_SCALE_TEXT fitting metod is enabled. Text will be scaled down to no more than factor * 100% of the original size.

    Parameters

    • factor: number

      the limit, greater than 0 and less than or equal to 1, to apply to scaling

    Returns void

setStyleForTag

  • setStyleForTag(tagName: string, style: TextStyle): void
  • Sets the style associated with a simple (non-parametric) tag. If a style was set previously for this tag, it will be replaced by the new style. If a replacement was associated with this tag, the replacement will be removed. Do not include the angle brackets in the tag name.

    For example:

    // define a <light>...</light> tag
    var style = new TextStyle(WEIGHT, WEIGHT_LIGHT);
    box.setStyleForTag("light", style);

    Parameters

    • tagName: string

      the name of the tag (without angle brackets)

    • style: TextStyle

      the TextStyle to be applied to text within this tag

    Returns void

setTabWidth

  • setTabWidth(tabWidthInInches: number): void
  • setTabWidth(tabWidthsInInches: number[]): void
  • Sets the distance, in inches, between tab stops.

    Parameters

    • tabWidthInInches: number

      the gap between tab stops

    Returns void

  • Sets the distance, in inches, between tab stops. This method accepts multiple tab positions as an array, which sets a series of variable-width tab stops instead of a fixed tab size.

    Parameters

    • tabWidthsInInches: number[]

      the gaps between tab stops

    Returns void

setTextFitting

  • setTextFitting(fittingMethod: number): void
  • Sets the fitting methods that will be used to shrink text that is too long to fit in the text region. One of FIT_NONE, FIT_TIGHTEN_LINE_SPACING, FIT_SCALE_TEXT, or FIT_BOTH.

    Parameters

    • fittingMethod: number

      the fitting method to use

    Returns void

setTightnessLimit

  • setTightnessLimit(minTightness: number): void
  • Sets the minimum line tightness that can be used when line spacing is reduced to fit long text due to the FIT_TIGHTEN_LINE_SPACING text fitting method.

    Parameters

    • minTightness: number

      the smallest amount that line tightness can be reduced to when fitting text

    Returns void