Class MarkupRenderer
- java.lang.Object
-
- ca.cgjennings.layout.MarkupRenderer
-
- Direct Known Subclasses:
GenderAwareMarkupRenderer
,MarkupToHTMLConverter
public class MarkupRenderer extends java.lang.Object
This class lays out paragraphs that use a specialized HTML-like markup language. The markup does not require any special introductory tags, such as <markup> or <body>. Tags which are not understood are ignored. Unlike the usual rules for HTML, sequences of more than one whitespace character are significant and retained.Users may add arbitrary new tags to the system, but the following set of tags are understood by default (as well as their closing tag when appropriate):
Renderers support six kinds of tags: built-in, replacement, user-defined, non-parametric style, parametric style, and interpreted tags.
Built-in tags perform special functions within the renderer environment and are always available.
Replacement tags are defined by the (programmer) user. They allow tags to be replaced by arbitrary text strings.
User-defined tags are essentially the same as replacement tags, but they are defined by the end user using the <define> built-in tag.
Non-parametric style tags are tags that do not take parameters and apply a
TextStyle
to the text they enclose. Examples include the <b> (bold) and <i> (italic) tags.TextStyle
s consist of one or moreTextAttribute
s and their values; a single non-parametric tag can therefore have multiple effects.Parametric style tags are tags that can include parameters which are parsed by a
ParametricStyleFactory
. The factory will return aTextStyle
based on the tag's parameters, which is then applied to the block it encloses. Examples include the <color>/<colour> and <image> tags.Interpreted tags include all tags not recognized as any of the other types. These tags are passed to
handleUnknownTag(java.lang.String, java.lang.String)
, which is given the opportunity to do something with it. Generally, if it wishes to handle the tag it will return a replacement string. TheMarkupRenderer
base class uses this to replace Unicode character tags with their equivalent Unicode characters. TheGenderAwareMarkupRenderer
subclass uses this to parse tags that include masculine and feminine variants that are selected based upon a gender supplied to the renderer (as in <his/her>).- Author:
- Chris Jennings
-
-
Nested Class Summary
Nested Classes Modifier and Type Class Description protected class
MarkupRenderer.StyledParagraph
This class provides anAttributedString
with extended information on how the string should be drawn.
-
Field Summary
Fields Modifier and Type Field Description protected boolean
currentAutoclose
protected boolean
currentHeadlineStatus
protected int
currentIndex
protected int
currentJustification
protected java.lang.String
currentParametricTag
protected int
currentPositionInUntaggedText
protected int
currentPunctuationReplacement
protected java.lang.StringBuilder
currentSourceLine
protected java.lang.String
currentTag
protected int
currentTagEndingIndex
protected java.lang.String
currentTagNoCase
protected int
currentTagStartingIndex
protected int
currentTightness
protected int
currentVerticalJustification
static boolean
DEBUG
protected java.util.LinkedList<ca.cgjennings.layout.MarkupRenderer.StyleMark>
finishedStyles
static int
FIT_BOTH
Try to fit text that is too long for the draw rectangle by first reducing spacing, then scaling down the text if that is not enough.static int
FIT_NONE
Do not try to force text that is too long to fit in the draw rectangle.static int
FIT_SCALE_TEXT
Try to fit text that is too long for the draw rectangle by scaling down the text.static int
FIT_TIGHTEN_LINE_SPACING
Try to fit text that is too long for the draw rectangle by reducing interline spacing.static int
LAYOUT_BOTTOM
Paragraphs are aligned to the bottom of the rectangle.static int
LAYOUT_CENTER
Lines are centered.static int
LAYOUT_JUSTIFY
Paragraphs should be justified.static int
LAYOUT_LEFT
Lines are left-justified.static int
LAYOUT_MIDDLE
Paragraphs are centered in the middle of the rectangle.static int
LAYOUT_RIGHT
Lines are right-justified.static int
LAYOUT_TOP
Paragraphs are aligned to the top of the rectangle.protected int
openQuotes
Depth to which quotation marks are nested, for doing punctuation replacement.protected java.util.HashMap<java.lang.String,java.util.LinkedList<ca.cgjennings.layout.MarkupRenderer.StyleMark>>
styleStackMap
protected boolean
textHasWhitespace
static boolean
USE_FAST_LINE_BREAKER
Warning: the fast line breaker is buggy; it works in most cases but sometimes incorrectly breaks a line in the middle of a word.static boolean
USE_PATCHED_LINE_BREAKER
-
Constructor Summary
Constructors Constructor Description MarkupRenderer()
Create a new markup layout engine with a set of default styles.MarkupRenderer(double dpi)
Create a new markup layout engine with a set of default styles.
-
Method Summary
All Methods Static Methods Instance Methods Concrete Methods Deprecated Methods Modifier and Type Method Description void
addLibrary(java.lang.String library)
Deprecated.protected TextStyle
adjustStyleForContext(TextStyle style)
void
appendSegments(java.awt.Graphics2D g, java.awt.geom.Rectangle2D r, java.util.List<LayoutSegment> appendList)
Instead of drawing the text, appends a sequence ofLayoutSegment
s list; these segments can then be used by the caller to evaluate, customize and/or draw the layout.protected java.lang.String[]
breakIntoParagraphs(java.lang.String source)
Breaks a source string into an array of individual lines.static java.lang.String
convertTagsToLinebreaks(java.lang.String source)
Converts aStrings
containing <br> tags into one that uses newlines instead.protected void
createDefaultParametricStyleMap()
Add default parametric style tags.protected void
createDefaultReplacementMap()
Add default replacement tags.protected void
createDefaultStyleMap()
Add default non-parametric style tags.protected MarkupRenderer.StyledParagraph
createStyledParagraph(java.lang.String source)
protected void
createStyledText()
Convert current markup into an array of StyledParagraph objects, one for each paragraph.double
draw(java.awt.Graphics2D g, java.awt.geom.Rectangle2D r)
Lay out the current markup text using the current styles and settings within the specified rectangle.double
drawAsSingleLine(java.awt.Graphics2D g, java.awt.geom.Rectangle2D r)
protected java.lang.String
findReplacementForTag()
If this tag is a replacement tag (either one defined programmatically using setReplacementForTag or one set by the user with a <define> tag), return the replacement text for this tag.int
getAlignment()
Returns the default alignment of text within the draw rectangle; the alignment can be changed using markup.boolean
getAutoclose()
Return whether outstanding tags are automatically closed at the end of each line by default.java.io.File
getBaseFile()
Returns the base file that the formatter may optionally use to complete relative path names, ornull
if none is defined.static int
getDefaultExpansionLimit()
TextStyle
getDefaultStyle()
Return the current default style applied to text before any tags are applied.static EvaluatorFactory
getEvaluatorFactory()
Get the factory used to handle script tags.int
getExpansionLimit()
int
getHeadlineAlignment()
Returns the default alignment of headline text within the draw rectangle.float
getLineTightness()
Get the current maximum line tightness.boolean
getMarkBadBox()
Get whether text that exceeds its bounding rectangle is marked with a red box.java.lang.String
getMarkupText()
Return the current markup string to be rendered by this instance.PageShape
getPageShape()
ParametricStyleFactory
getParametricStyleForTag(java.lang.String tagName)
Return theParametricStyleFactory
associated with the tag, ornull
if the tag does not have a style set (including if it has a replacement or style set).java.lang.String
getReplacementForTag(java.lang.String tagName)
Return the replacementString
associated with the tag, ornull
if the tag does not have a replacement set (including if it has a style or parametric style set).int
getScalingFractionalLimit()
double
getScalingLimit()
Get the current limit on text scaling to fit text in a rendering rectangle.protected MarkupRenderer.StyledParagraph[]
getStyledText()
TextStyle
getStyleForTag(java.lang.String tagName)
Return theTextStyle
associated with the tag, ornull
if the tag does not have a non-parametric style set (including if it has a replacement or parametric style set).double
getTabWidth()
Return the distance, in inches, between tab stops.double[]
getTabWidths()
protected java.lang.String[]
getTagParameters()
Return an array of parameters included in the current tag.int
getTextFitting()
Get the current text fitting method.float
getTightnessLimit()
Get the current minimum tighness to use when using line tightening to reduce text size.protected java.lang.String
handleUnknownTag(java.lang.String tagnameLowercase, java.lang.String tagnameOriginalCase)
This method is called when a tag is encountered that does not match any existing defined or built-in tag.protected void
invalidateLayoutCache()
Clear cached information about how markup should be processed.protected double
layout(java.awt.Graphics2D g, java.awt.geom.Rectangle2D r, boolean render)
Lay out the current markup text using the current styles and settings within the specified rectangle.double
measure(java.awt.Graphics2D g, java.awt.geom.Rectangle2D r)
Simulate rendering the current markup without drawing anything, returning the height that the text would have covered.void
parseLibrary(java.lang.String library)
Process a markup string, retaining only any definitions that are created.static double
parseMeasurement(java.lang.String p)
Try to parsep
as a measurement.void
removeAllTags()
Removes the style information associated with all tags.void
removeTag(java.lang.String tagName)
If a style or replacement is associated with this tag, the style will be removed and the tag will be treated as an unknown tag.protected double
renderText(java.awt.Graphics2D g, java.awt.geom.Rectangle2D r, double yAlignmentOffset, java.awt.font.FontRenderContext frc, boolean measureOnly, boolean restrictToSingleLine)
Render the markup on a graphics context within a specified region.protected java.lang.String
replaceMacroParameters(java.lang.String text, java.lang.String[] parameters, java.lang.String repeatKey, java.lang.String repeatValue)
Returns a string where instances of @n; intext
are replaced with the text ofparameter[n-1]
.protected void
replaceTagWith(java.lang.String replacement)
Replaces the tag currently being parsed with arbitrary text.protected void
replaceTagWithErrorMessage(java.lang.String message)
protected void
resetPunctuationSelectorState()
protected char
selectPunctuation(char curr, java.lang.StringBuilder writtenText)
void
setAlignment(int alignment)
Sets the default horizontal and vertical alignment of text within the draw rectangle.void
setAutoclose(boolean autoclose)
Set whether tags close themselves at the end of each line by default.void
setBaseFile(java.io.File baseFile)
Sets the base file that the formatter may optionally use to complete relative path names.static void
setDefaultExpansionLimit(int limit)
void
setDefaultStyle(TextStyle style)
Set the default style applied to text before any tags are applied.void
setDefinitionForTag(java.lang.String name, java.lang.String replacement)
Create a new user-defined definition.static void
setEvaluatorFactory(EvaluatorFactory factory)
Set the factory used to handle script tags.void
setExpansionLimit(int limit)
void
setHeadlineAlignment(int alignment)
Set the horizontal alignment of heading text tags (h1, h2, etc.).void
setLineTightness(float tightness)
Set the maximum line spacing value.void
setMarkBadBox(boolean mark)
Set whether text that exceeds its bounding rectangle is marked with a red box.void
setMarkupText(java.lang.String markup)
Set the markup string to be rendered.void
setPageShape(PageShape shape)
void
setParametricStyleForTag(java.lang.String tagName, ParametricStyleFactory factory)
Set a parameter-based style for the given tag.void
setReplacementForTag(java.lang.String tagName, java.lang.String replacement)
Set a replacement string to be associated with a particular tag.void
setScalingFractionalLimit(int limit)
Set the fractional increment at which text is scaled; the precision of text scaling is limited to 1/limit
.void
setScalingLimit(double factor)
Limit the text scaling algorithm to scale down to no more thanfactor
* 100% of the original size.void
setStyleForTag(java.lang.String tagName, TextStyle style)
Set the style associated with a non-parametric tag.void
setTabWidth(double gapInInches)
Set the distance, in inches, between tab stops.void
setTabWidths(double[] tabStops)
void
setTextFitting(int fittingStyle)
Set the fitting methods that will be used to shrink text that is too long to fit in its rendering rectangle.void
setTightnessLimit(float tightnessLimit)
Set the minimum tightness to use when using line tightening to reduce text size.java.lang.String
toString()
-
-
-
Field Detail
-
FIT_NONE
public static final int FIT_NONE
Do not try to force text that is too long to fit in the draw rectangle.- See Also:
- Constant Field Values
-
FIT_TIGHTEN_LINE_SPACING
public static final int FIT_TIGHTEN_LINE_SPACING
Try to fit text that is too long for the draw rectangle by reducing interline spacing.- See Also:
- Constant Field Values
-
FIT_SCALE_TEXT
public static final int FIT_SCALE_TEXT
Try to fit text that is too long for the draw rectangle by scaling down the text. Note that this can be time consuming, and that it will augment your specified styles withTextTransform
styleTextAttribute
s.- See Also:
- Constant Field Values
-
FIT_BOTH
public static final int FIT_BOTH
Try to fit text that is too long for the draw rectangle by first reducing spacing, then scaling down the text if that is not enough.- See Also:
- Constant Field Values
-
LAYOUT_LEFT
public static final int LAYOUT_LEFT
Lines are left-justified.- See Also:
- Constant Field Values
-
LAYOUT_CENTER
public static final int LAYOUT_CENTER
Lines are centered.- See Also:
- Constant Field Values
-
LAYOUT_RIGHT
public static final int LAYOUT_RIGHT
Lines are right-justified.- See Also:
- Constant Field Values
-
LAYOUT_TOP
public static final int LAYOUT_TOP
Paragraphs are aligned to the top of the rectangle.- See Also:
- Constant Field Values
-
LAYOUT_MIDDLE
public static final int LAYOUT_MIDDLE
Paragraphs are centered in the middle of the rectangle.- See Also:
- Constant Field Values
-
LAYOUT_BOTTOM
public static final int LAYOUT_BOTTOM
Paragraphs are aligned to the bottom of the rectangle.- See Also:
- Constant Field Values
-
LAYOUT_JUSTIFY
public static final int LAYOUT_JUSTIFY
Paragraphs should be justified.- See Also:
- Constant Field Values
-
currentIndex
protected int currentIndex
-
currentTagStartingIndex
protected int currentTagStartingIndex
-
currentTagEndingIndex
protected int currentTagEndingIndex
-
currentJustification
protected int currentJustification
-
currentTightness
protected int currentTightness
-
currentPositionInUntaggedText
protected int currentPositionInUntaggedText
-
currentVerticalJustification
protected int currentVerticalJustification
-
currentHeadlineStatus
protected boolean currentHeadlineStatus
-
currentAutoclose
protected boolean currentAutoclose
-
currentPunctuationReplacement
protected int currentPunctuationReplacement
-
currentTag
protected java.lang.String currentTag
-
currentTagNoCase
protected java.lang.String currentTagNoCase
-
currentParametricTag
protected java.lang.String currentParametricTag
-
currentSourceLine
protected java.lang.StringBuilder currentSourceLine
-
styleStackMap
protected java.util.HashMap<java.lang.String,java.util.LinkedList<ca.cgjennings.layout.MarkupRenderer.StyleMark>> styleStackMap
-
finishedStyles
protected java.util.LinkedList<ca.cgjennings.layout.MarkupRenderer.StyleMark> finishedStyles
-
textHasWhitespace
protected boolean textHasWhitespace
-
openQuotes
protected int openQuotes
Depth to which quotation marks are nested, for doing punctuation replacement.
-
DEBUG
public static boolean DEBUG
-
USE_PATCHED_LINE_BREAKER
public static boolean USE_PATCHED_LINE_BREAKER
-
USE_FAST_LINE_BREAKER
public static boolean USE_FAST_LINE_BREAKER
Warning: the fast line breaker is buggy; it works in most cases but sometimes incorrectly breaks a line in the middle of a word.
-
-
Constructor Detail
-
MarkupRenderer
public MarkupRenderer()
Create a new markup layout engine with a set of default styles. A resolution of 72 dots per inch (typical for screen display) is used.
-
MarkupRenderer
public MarkupRenderer(double dpi)
Create a new markup layout engine with a set of default styles. The dpi value allows scaling the output for a given resolution. This is important so that, for example, font point sizes are interpreted correctly.
-
-
Method Detail
-
setPageShape
public void setPageShape(PageShape shape)
-
getPageShape
public PageShape getPageShape()
-
setEvaluatorFactory
public static void setEvaluatorFactory(EvaluatorFactory factory)
Set the factory used to handle script tags.- Parameters:
factory
-
-
getEvaluatorFactory
public static EvaluatorFactory getEvaluatorFactory()
Get the factory used to handle script tags.- Returns:
- the script evaluator factory
-
setDefaultExpansionLimit
public static void setDefaultExpansionLimit(int limit)
-
getDefaultExpansionLimit
public static int getDefaultExpansionLimit()
-
getExpansionLimit
public int getExpansionLimit()
-
setExpansionLimit
public void setExpansionLimit(int limit)
-
createDefaultStyleMap
protected void createDefaultStyleMap()
Add default non-parametric style tags.
-
createDefaultParametricStyleMap
protected void createDefaultParametricStyleMap()
Add default parametric style tags.
-
createDefaultReplacementMap
protected void createDefaultReplacementMap()
Add default replacement tags.
-
invalidateLayoutCache
protected void invalidateLayoutCache()
Clear cached information about how markup should be processed. When a given markup string is first drawn or measured, some information will be cached to speed up subsequent redrawing.The caching process will include a final version of the text with all of the markup processed out. As a result, subclasses implement their own tags via
handleUnknownTag(java.lang.String, java.lang.String)
and that will return different results depending on some system state should call this method whenever the state changes. For example, theGenderAwareMarkupRenderer
calls this method whenever its gender setting is changed. Otherwise, repeated renderings with the same markup would always draw text that reflected the active gender at the time the markup was first drawn or measured.This method must never be called from
handleUnknownTag(java.lang.String, java.lang.String)
, as this is called while the markup is being processed (that is, while the cache is being constructed).
-
setStyleForTag
public void setStyleForTag(java.lang.String tagName, TextStyle style)
Set the style associated with a non-parametric tag. If a style was set previously for this tag, it will be replaced by the new style. Do not include the angle brackets in the tag name. If a replacement was associated with this tag, the replacement will be removed.
-
getStyleForTag
public TextStyle getStyleForTag(java.lang.String tagName)
Return theTextStyle
associated with the tag, ornull
if the tag does not have a non-parametric style set (including if it has a replacement or parametric style set).
-
setParametricStyleForTag
public void setParametricStyleForTag(java.lang.String tagName, ParametricStyleFactory factory)
Set 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.
-
getParametricStyleForTag
public ParametricStyleFactory getParametricStyleForTag(java.lang.String tagName)
Return theParametricStyleFactory
associated with the tag, ornull
if the tag does not have a style set (including if it has a replacement or style set).
-
setReplacementForTag
public void setReplacementForTag(java.lang.String tagName, java.lang.String replacement)
Set a replacement string to be associated with a particular tag. When this tag occurs in the markup text, it will be replaced by the specified repalcement.
-
getReplacementForTag
public java.lang.String getReplacementForTag(java.lang.String tagName)
Return the replacementString
associated with the tag, ornull
if the tag does not have a replacement set (including if it has a style or parametric style set).
-
removeTag
public void removeTag(java.lang.String tagName)
If a style or replacement is associated with this tag, the style will be removed and the tag will be treated as an unknown tag.
-
removeAllTags
public void removeAllTags()
Removes the style information associated with all tags. Break and heading tags will still cause line breaks.
-
setDefaultStyle
public void setDefaultStyle(TextStyle style)
Set the default style applied to text before any tags are applied. It is permissible to modify this style even if it was not created by the caller.
-
getDefaultStyle
public TextStyle getDefaultStyle()
Return the current default style applied to text before any tags are applied.
-
setAutoclose
public void setAutoclose(boolean autoclose)
Set whether tags close themselves at the end of each line by default. This is a default that can be changed within a markup block using <autoclose> or <manualclose>.
-
getAutoclose
public boolean getAutoclose()
Return whether outstanding tags are automatically closed at the end of each line by default.
-
setMarkupText
public void setMarkupText(java.lang.String markup)
Set the markup string to be rendered.
-
getMarkupText
public java.lang.String getMarkupText()
Return the current markup string to be rendered by this instance.
-
setMarkBadBox
public void setMarkBadBox(boolean mark)
Set whether text that exceeds its bounding rectangle is marked with a red box.
-
getMarkBadBox
public boolean getMarkBadBox()
Get whether text that exceeds its bounding rectangle is marked with a red box.
-
setTextFitting
public void setTextFitting(int fittingStyle)
Set the fitting methods that will be used to shrink text that is too long to fit in its rendering rectangle. One of FIT_NONE, FIT_TIGHTEN_LINE_SPACING, FIT_SCALE_TEXT, or FIT_BOTH.
-
getTextFitting
public int getTextFitting()
Get the current text fitting method.
-
setScalingLimit
public void setScalingLimit(double factor)
Limit the text scaling algorithm to scale down to no more thanfactor
* 100% of the original size.
-
setScalingFractionalLimit
public void setScalingFractionalLimit(int limit)
Set the fractional increment at which text is scaled; the precision of text scaling is limited to 1/limit
.
-
getScalingFractionalLimit
public int getScalingFractionalLimit()
-
getScalingLimit
public double getScalingLimit()
Get the current limit on text scaling to fit text in a rendering rectangle.
-
setTightnessLimit
public void setTightnessLimit(float tightnessLimit)
Set the minimum tightness to use when using line tightening to reduce text size.
-
getTightnessLimit
public float getTightnessLimit()
Get the current minimum tighness to use when using line tightening to reduce text size.
-
setLineTightness
public void setLineTightness(float tightness)
Set the maximum line spacing value. Normal line spacing is 1.0; double spaced would be 2.0. For tighter lines, use a value less than 1.0. This is a maximum value; if the text fitting method allows line tightening, the actual line spacing may be less. For minimal space between lines, use a tightnes of 0.
-
getLineTightness
public float getLineTightness()
Get the current maximum line tightness.
-
setAlignment
public void setAlignment(int alignment)
Sets the default horizontal and vertical alignment of text within the draw rectangle. This is a binary or of one ofLAYOUT_LEFT
,LAYOUT_RIGHT
, andLAYOUT_CENTER
with one ofLAYOUT_TOP
,LAYOUT_BOTTOM
, orLAYOUT_MIDDLE
, and optionally withLAYOUT_JUSTIFY
.- Parameters:
alignment
- the new alignment value
-
getAlignment
public int getAlignment()
Returns the default alignment of text within the draw rectangle; the alignment can be changed using markup.- Returns:
- the base alignment value
-
setHeadlineAlignment
public void setHeadlineAlignment(int alignment)
Set the horizontal alignment of heading text tags (h1, h2, etc.).
-
getHeadlineAlignment
public int getHeadlineAlignment()
Returns the default alignment of headline text within the draw rectangle.- Returns:
- the base alignment value
-
getTabWidth
public double getTabWidth()
Return the distance, in inches, between tab stops.
-
getTabWidths
public double[] getTabWidths()
-
setTabWidth
public void setTabWidth(double gapInInches)
Set the distance, in inches, between tab stops.
-
setTabWidths
public void setTabWidths(double[] tabStops)
-
draw
public double draw(java.awt.Graphics2D g, java.awt.geom.Rectangle2D r)
Lay out the current markup text using the current styles and settings within the specified rectangle. Returns the y-coordinate where the next line would start.
-
drawAsSingleLine
public double drawAsSingleLine(java.awt.Graphics2D g, java.awt.geom.Rectangle2D r)
-
measure
public double measure(java.awt.Graphics2D g, java.awt.geom.Rectangle2D r)
Simulate rendering the current markup without drawing anything, returning the height that the text would have covered.- Returns:
- the layout height
-
appendSegments
public void appendSegments(java.awt.Graphics2D g, java.awt.geom.Rectangle2D r, java.util.List<LayoutSegment> appendList)
Instead of drawing the text, appends a sequence ofLayoutSegment
s list; these segments can then be used by the caller to evaluate, customize and/or draw the layout. For example, by creating a segment list for an infinitely high rectangle, the resulting list of segments could be laid out on a sequence of pages for printing by adjusting their y-coordinates.
-
layout
protected double layout(java.awt.Graphics2D g, java.awt.geom.Rectangle2D r, boolean render)
Lay out the current markup text using the current styles and settings within the specified rectangle. Returns the y-coordinate where the next line would start. If render is false, does not draw the text and returns the height of the text render area (one line less than the usual return value).
-
renderText
protected double renderText(java.awt.Graphics2D g, java.awt.geom.Rectangle2D r, double yAlignmentOffset, java.awt.font.FontRenderContext frc, boolean measureOnly, boolean restrictToSingleLine)
Render the markup on a graphics context within a specified region. A y-coordinate indicating where a subsequent line would begin is returned. IfmeasureOnly
is set to true, a draw is computed but no actual rendering performed. In this case, the return value is the height of the region needed to render the text.
-
createStyledText
protected void createStyledText()
Convert current markup into an array of StyledParagraph objects, one for each paragraph.
-
parseLibrary
public void parseLibrary(java.lang.String library)
Process a markup string, retaining only any definitions that are created. Once some markup is processed (other than a library) all definitions will be cleared again. Therefore, any required libraries must be added before each call tosetMarkupText
.This method clears the current markup text.
-
addLibrary
@Deprecated public void addLibrary(java.lang.String library)
Deprecated.- Parameters:
library
- the text of the library to glean definitions from
-
getStyledText
protected MarkupRenderer.StyledParagraph[] getStyledText()
-
createStyledParagraph
protected MarkupRenderer.StyledParagraph createStyledParagraph(java.lang.String source)
-
resetPunctuationSelectorState
protected void resetPunctuationSelectorState()
-
selectPunctuation
protected char selectPunctuation(char curr, java.lang.StringBuilder writtenText)
-
findReplacementForTag
protected java.lang.String findReplacementForTag()
If this tag is a replacement tag (either one defined programmatically using setReplacementForTag or one set by the user with a <define> tag), return the replacement text for this tag. Otherwise, return null.
-
replaceMacroParameters
protected java.lang.String replaceMacroParameters(java.lang.String text, java.lang.String[] parameters, java.lang.String repeatKey, java.lang.String repeatValue)
Returns a string where instances of @n; intext
are replaced with the text ofparameter[n-1]
.
-
getTagParameters
protected java.lang.String[] getTagParameters()
Return an array of parameters included in the current tag. If there are no parameters, return an empty array. Parameters are separated from the main tag name and each other by whitespace. A parameter surrounded by quotes (") may contain whitespace. A parameter surrounded by quotes may use the escape \" to include a quote without ending the parameter.
-
replaceTagWith
protected void replaceTagWith(java.lang.String replacement)
Replaces the tag currently being parsed with arbitrary text. This text may contain tags, and if so, they will also be parsed.
-
replaceTagWithErrorMessage
protected void replaceTagWithErrorMessage(java.lang.String message)
-
setDefinitionForTag
public void setDefinitionForTag(java.lang.String name, java.lang.String replacement)
Create a new user-defined definition.
-
handleUnknownTag
protected java.lang.String handleUnknownTag(java.lang.String tagnameLowercase, java.lang.String tagnameOriginalCase)
This method is called when a tag is encountered that does not match any existing defined or built-in tag. Subclasses may override it as a simple way to extend the behaviour of this class.If the method returns a string, that string will be interpreted exactly as if it had appeared instead of the unknown tag. It may include both text and tags.
If the method does not have a suitable replacement for the unknown tag, it should return
null
.The base class parses tags of the form <u+xxxx> to insert Unicode characters from their hexidecimal code and parses <image> tags to insert images into the text stream. To remove these behaviours, override and return
null
. To extend them, return the value of the superclass implementation once you have decided you do not want to handle the tag yourself.
-
breakIntoParagraphs
protected java.lang.String[] breakIntoParagraphs(java.lang.String source)
Breaks a source string into an array of individual lines. Lines are broken on newline characters, break tags (br), and headline tags (h1, h2, h3, h4, h5, h6, h7).
-
convertTagsToLinebreaks
public static java.lang.String convertTagsToLinebreaks(java.lang.String source)
Converts aStrings
containing <br> tags into one that uses newlines instead. This is not required before sending markup to the draw system. Rather, this is intended for use when deserializing markup that has had newlines converted into <br> tags for convenience of encoding.By design, this method recognizes only the exact sequence <, b, r, >: it is case-sensitive and does not recognize </br>. It does not differentiate between regular tags and nested tags that form arguments of other tags.
-
parseMeasurement
public static double parseMeasurement(java.lang.String p)
Try to parsep
as a measurement. If is a valid measurement, returns the measurement in inches. Otherwise, returns a negative number. Measurements consist of a positive floating point number optionally followed by a unit (with no intervening whitespace). Valid units are cm, in (inches), and pt (points). The default unit is cm.
-
getBaseFile
public java.io.File getBaseFile()
Returns the base file that the formatter may optionally use to complete relative path names, ornull
if none is defined.- Returns:
- the base file for relative paths, or
null
-
setBaseFile
public void setBaseFile(java.io.File baseFile)
Sets the base file that the formatter may optionally use to complete relative path names.- Parameters:
baseFile
- the base file name to use
-
toString
public java.lang.String toString()
- Overrides:
toString
in classjava.lang.Object
-
-