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.
the target resolution, in pixels per inch
Lays out and draws the current markup text within the specified region.
the graphics context to render the box content into
the rectangular area of the graphics context to lay out the content within
the y-coordinate where the next line would have started
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.
the graphics context to render the box content into
the rectangular area of the graphics context to lay out the content within
the width of the line in pixels
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" );
the current alignment layout value
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);
the TextStyle applied to all text by default
Returns the current horizontal alignment setting for heading tags.
the current heading alignment layout value
Returns the current line tightness.
the line spacing tightness value
Returns the shape that drawn text will conform to within the draw region.
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).
the name of the tag (without angle brackets) to get the factory for
the previously set factory for the tag, or null
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).
the name of the tag to return the replacement string for
the replacement string for the tag, or null
Returns the current scaling limit for text shrinking when the FIT_SCALE_TEXT
fitting metod is enabled.
the scaling limit factor
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).
the name of the tag (without angle brackets) to fetch the style of
the style for the requested tag, or null if it has no, or a different kind, of definition
Returns an array of tab widths, in inches. (If only one stop has been set, the length of the array is 1.)
Returns the constant representing the text fitting method to be used to fit text within a region.
the text fitting method
Returns the current line tightness limit.
the minimum line spacing tightness value
Lays out but does not draw the current markup text, returning the height of the text.
the graphics context to render the box content into
the rectangular area of the graphics context to lay out the content within
the height of the text in pixels
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
.
a string containing markup definitions
Removes all tag definitions from the box.
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;
a bitmask of alignment options
Sets the default style that is applied to text when no other tags affect it.
the TextStyle applied to all text by default
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.
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.)
the tightness of interline spacing (normally 1.0)
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.
the desired PageShape
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
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", "©" );
the name of the replacement tag
the text to replace the tag with
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.
the limit, greater than 0 and less than or equal to 1, to apply to scaling
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);
the name of the tag (without angle brackets)
the TextStyle to be applied to text within this tag
Sets the distance, in inches, between tab stops.
the gap between tab stops
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.
the gaps between tab stops
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
.
the fitting method to use
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.
the smallest amount that line tightness can be reduced to when fitting text
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 writebox.defaultStyle = style;