Package com.reportmill.shape
Class RMText
- java.lang.Object
-
- com.reportmill.base.RMObject
-
- com.reportmill.shape.RMShape
-
- com.reportmill.shape.RMRectangle
-
- com.reportmill.shape.RMText
-
- All Implemented Interfaces:
RMArchiver.Archiving
,java.lang.Cloneable
- Direct Known Subclasses:
RBText
,RMCell
,RMLinkedText
public class RMText extends RMRectangle
This class is an RMShape subclass for handling rich text. Text is probably the most common and useful element in a ReportMill template. You might use this class to programatically build or modify a template, like this:RMXString xstring = new RMXString("Hello world!", RMFont.getFont("Arial", 12), RMColor.red); RMText text = new RMText(xstring); template.getPage(0).addChild(text); text.setXY(36, 36); text.setSizeToFit();
-
-
Field Summary
Fields Modifier and Type Field Description static byte
ALIGN_BOTTOM
static byte
ALIGN_CENTER
static byte
ALIGN_FULL
static byte
ALIGN_LEFT
static byte
ALIGN_MIDDLE
static byte
ALIGN_RIGHT
static byte
ALIGN_TOP
static byte
WRAP_BASIC
static byte
WRAP_NONE
static byte
WRAP_SCALE
-
Fields inherited from class com.reportmill.shape.RMShape
WRAP_TYPE_BOTH, WRAP_TYPE_NONE
-
-
Method Summary
All Methods Instance Methods Concrete Methods Modifier and Type Method Description java.lang.Object
clone()
Standard clone implementation.void
copy(java.lang.Object anObj)
Copies attributes from given object.boolean
equals(java.lang.Object anObj)
Standard equals implementation.java.lang.Object
fromXML(RXArchiver anArchiver, RXElement anElement)
XML unarchival.void
fromXMLFinish(RXArchiver anArchiver, RXElement anElement)
XML reference unarchival - to unarchive linked text.byte
getAlign()
Returns the alignment for char 0.java.lang.String
getAlignString()
Returns the alignment as a string, one of: "left", "center" or "right".byte
getAlignVertical()
Returns the vertical alignment.java.lang.String
getAlignVerticalString()
Returns the vertical alignment as a string, one of: "top", "middle" or "bottom".RMRect
getBoundsFromTextBounds(RMRect aRect)
Returns bounds from given text bounds, adjusted to account for text margins.float
getCharSpacing()
Returns the char spacing at char 0.boolean
getCoalesceNewlines()
Returns whether text should coalesce consecutive newlines in rpgClone.boolean
getDrawsSelectionRect()
Returns whether text should always draw at least a light gray border (useful when editing).RMFont
getFont()
Returns the font for char 0.float
getFontScale()
Returns the scale to apply to all fonts in text's XString (defaults to 1).RMFormat
getFormat()
Returns the format for char 0.float
getHeightToFit()
Returns the ideal height for this RMText.float
getHeightToFit(boolean includeFinalEmptyLine)
Returns the ideal height for this RMText.float
getLineGap()
Returns the line gap at char 0.float
getLineHeightMax()
Returns the maximum line height at char 0.float
getLineHeightMin()
Returns the minimum line height at char 0.float
getLineSpacing()
Returns the line spacing at char 0.RMLinkedText
getLinkedText()
Returns the linked text for this text (if any).float
getMarginBottom()
Returns the bottom margin of the text (defaults to 0).float
getMarginLeft()
Returns the left margin of the text (default to 2).float
getMarginRight()
Returns the right margin of the text (defaults to 2).float
getMarginTop()
Returns the top margin of the text (defaults to 1).RMXString.Outline
getOutline()
Returns the outline for char 0.RMPath
getPath()
Returns the path for this shape.RMPath
getPathInBounds()
Overrides shape implementation to pass through getPathInBounds(inset).RMPath
getPathInBounds(int inset)
Returns the shape's path scaled to the shape's current bounds.RMShape
getPathShape()
Returns the shape that provides the path for this text to wrap text to.boolean
getPerformsWrap()
Returns whether text should wrap around other shapes that cause wrap.RMPolygon
getPolygonForFrag(RMTextFrag aFrag)
Returns a polygon shape for the glyphs in a given text frag.java.lang.String
getText()
Returns the text associated with this RMText as a plain String.RMRect
getTextBounds()
Returns the actual bounding rect of the text (currently just inset 2 pixels on either side).RMColor
getTextColor()
Returns the color of the first character of the xstring associated with this RMText.RMTextLayout
getTextLayout()
Returns a text layout configured for this text, with layout already performed.RMTextLayout
getTextLayout(boolean performLayout)
Returns a text layout configured for this text, with an option to perform layout.RMPoint
getTextOrigin()
Returns the point inside this text where the first character is placed.int
getVisibleEnd()
Returns the last character index visible in this text.int
getVisibleStart()
Returns the first character index visible in this text.float
getWidthToFit()
Returns the ideal width for this RMText.byte
getWraps()
Returns the wrapping behavior for over-filled rpgCloned text (NONE, WRAP, SHRINK).RMXString
getXString()
Returns the XString associated with this RMText.java.lang.Object
initWithArchiver(RMArchiver anArchiver)
Legacy unarchival.boolean
isAllTextVisible()
Returns whether all characters can be visibly rendered in text bounds.boolean
isStructured()
Editor method.boolean
isUnderlined()
Returns if char 0 is underlined.int
length()
Returns the length, in characters, of the XString associated with this RMText.void
peerDidChange(RMShape aShape)
This notification method is called when any peer is changed.void
resolvePageReferences(ReportMill aReportMill, java.lang.Object userInfo)
Re-does the RPG clone to resolve any @Page@ keys (assumed to be present in userInfo).RMShape
rpgClone(ReportMill aReportMill)
This method clones the RMText, performing subtition on the XString.void
rpgClonePreprocess(ReportMill aReportMill)
This standard rpgClone hook allows texts set to wrap to perform the wrap.void
scaleTextToFit()
Scales font sizes of all text in an RMText shape to fit in bounds.void
setAlign(int align)
Sets the align for all chars.void
setAlignVertical(byte anAlignment)
Sets the vertical alginment.void
setCharSpacing(float aValue)
Sets the char spacing for the text string.void
setCoalesceNewlines(boolean aFlag)
Sets whether text should coalesce consecutive newlines in rpgClone.void
setDrawsSelectionRect(boolean aValue)
Sets whether text should always draw at least a light-gray border (useful when editing).void
setFont(RMFont aFont)
Sets the font for all characters.void
setFontScale(float aFactor)
Sets the scale to apply to all fonts in text's XString.void
setFormat(RMFormat aFormat)
Sets the format for all characters.void
setHeight(double aValue)
Overrides shape implementation to reset height to fit.void
setHeightToFit(float aValue)
Sets the text's height to fit (often called with -1 to force recalc).void
setLineGap(float aHeight)
Sets the line gap for all chars.void
setLineHeightMax(float aHeight)
Sets the maximum line height for all chars.void
setLineHeightMin(float aHeight)
Sets the minimum line height for all chars.void
setLineSpacing(float aHeight)
Sets the line spacing for all chars.void
setLinkedText(RMLinkedText anLinkedText)
Sets the linked text for this text (if any).void
setNeedsRepaint()
Editor method - passes on repaints to linked text.void
setOutline(RMXString.Outline anOutline)
Sets the Outline for all characters.void
setPathShape(RMShape aShape)
Sets the shape that provides the path for this text to wrap text to.void
setPerformsWrap(boolean aFlag)
Sets whether text should wrap around other shapes that cause wrap.void
setRadius(float aValue)
Overrides rectangle implementation to potentially force text relayout.void
setText(RMXString anXString)
Sets the XString associated with this RMText.void
setText(java.lang.String aString)
Replaces the current text associated with this RMText with the given String.void
setTextColor(RMColor aColor)
Sets the color of the characters in the XString associated with this RMText.void
setUnderlined(boolean aFlag)
Sets all chars to be underlined.void
setWraps(byte aValue)
Sets the wrapping behavior for over-filled rpgCloned text (NONE, WRAP, SHRINK).void
setXString(RMXString s)
Sets the XString associated with this RMText.boolean
superSelectable()
Editor method - indicates that this shape can be super selected.java.lang.String
toString()
Standard toSring implementation.RXElement
toXML(RXArchiver anArchiver)
XML archival.RMShape
turnToChars(boolean inPlace)
Returns a group shape with an RMText shape for each glyph in the text.RMShape
turnToPath(boolean inPlace)
Returns an RMPolygon shape with the glyph path for the chars in this text.-
Methods inherited from class com.reportmill.shape.RMRectangle
getRadius
-
Methods inherited from class com.reportmill.shape.RMShape
acceptsChildren, acceptsDragKeys, acceptsFormat, acceptsMouse, addChild, addChild, addChildBelowLastChild, bounds, boundsChanged, boundsChanged, bringShapesToFront, canBeUngrouped, childrenSuperSelectImmediately, cloneDeep, contains, convertedPointFromShape, convertedPointToShape, convertedRectFromShape, convertedRectToShape, convertedSizeFromShape, convertedSizeToShape, convertedVectorFromShape, convertedVectorToShape, convertFromShape, convertPathFromShape, convertPathToShape, convertPointFromShape, convertPointToShape, convertRectFromShape, convertRectToShape, convertSizeFromShape, convertSizeToShape, convertToShape, convertVectorFromShape, convertVectorToShape, copyShape, delete, didChange, divideShapeFromEdge, divideShapeFromTop, dragExit, dragKeyAtPoint, dropKeyAtPoint, fromXMLDeep, get, getActionScript, getAnim, getAnim, getAnimator, getAnimator, getAutosizeHeight, getAutosizing, getBounds, getBoundsInside, getBoundsMarked, getBoundsOfChildren, getBoundsOfChildren, getBoundsSuperSelected, getCausesWrap, getCausesWrapType, getChild, getChildAnimator, getChildAnimator, getChildContaining, getChildCount, getChildLast, getChildren, getChildrenIntersecting, getChildrenWhoCauseWrap, getChildrenWhoDraw, getChildrenWhoHitTest, getChildSortedByX, getChildWithClass, getChildWithName, getColor, getCommonAncestor, getDocument, getFill, getFill, getFill, getFillCount, getFills, getFrame, getFrame, getFrameMaxX, getFrameMaxY, getFrameX, getFrameXY, getFrameY, getGroupShape, getHeight, getImageFill, getLineWidth, getListKey, getListKeyDeep, getListKeyShape, getMaxX, getMaxY, getName, getOpacity, getOpacityDeep, getPageCount, getPageShape, getParent, getParentCount, getParents, getPropertyKey, getPropertyKeyCount, getPropertyKeyName, getRoll, getRootShape, getScaleX, getScaleY, getShapesToAncestor, getShapesToDescendant, getShapesToShape, getSize, getSizeP, getSkewX, getSkewY, getStroke, getStrokeColor, getToolClassName, getTransform, getTransformFromShape, getTransformInverse, getTransformToShape, getUndoer, getUrl, getWidth, getX, getXY, getXYP, getY, groupShapes, hasPageBreaks, height, indexOf, indexOf, intersects, isAncestor, isDescendant, isLocked, isRoot, mouseDragged, mouseEntered, mouseExited, mouseMoved, mousePressed, mouseReleased, notRSS, offsetChildrenXY, offsetXY, page, pageBreakMax, pageBreakPageMax, pageMax, put, putPropertyKey, reclaimChildren, removeChild, removeChild, removeChildren, removeChildren, removeFromParent, rpgCloneBase, rpgCloneChildren, rpgCloneConclude, rpgCloneNotification, rpgClonePrepare, rpgCloneUrl, sendShapesToBack, setActionScript, setAnim, setAutosizeHeight, setAutosizing, setBounds, setBounds, setCausesWrapType, setChildren, setColor, setFill, setFrame, setFrame, setFrameSize, setFrameX, setFrameXY, setFrameXY, setFrameY, setHeightDeep, setHeightDeep, setHeightToFit, setLineWidth, setListKey, setLocked, setName, setNeedsRepaint, setOpacity, setParent, setRoll, setScaleX, setScaleXY, setScaleY, setSize, setSize, setSizeDeep, setSizeP, setSizeToFit, setSizeToFit, setSkewX, setSkewXY, setSkewY, setStroke, setStrokeColor, setTime, setUrl, setWidth, setWidthDeep, setWidthDeep, setWidthToFit, setX, setXY, setXY, setXYP, setY, sizesToFitChildren, undoClone, undoCopy, undoEquals, undoerAddDirtyObject, undoerDisable, undoerEnable, undoerSetUndoTitle, width, willChange, willChange, x, y
-
Methods inherited from class com.reportmill.base.RMObject
didUndo, getAnimAttribute, getClassNameShort
-
-
-
-
Field Detail
-
ALIGN_LEFT
public static final byte ALIGN_LEFT
- See Also:
- Constant Field Values
-
ALIGN_CENTER
public static final byte ALIGN_CENTER
- See Also:
- Constant Field Values
-
ALIGN_RIGHT
public static final byte ALIGN_RIGHT
- See Also:
- Constant Field Values
-
ALIGN_FULL
public static final byte ALIGN_FULL
- See Also:
- Constant Field Values
-
ALIGN_TOP
public static final byte ALIGN_TOP
- See Also:
- Constant Field Values
-
ALIGN_MIDDLE
public static final byte ALIGN_MIDDLE
- See Also:
- Constant Field Values
-
ALIGN_BOTTOM
public static final byte ALIGN_BOTTOM
- See Also:
- Constant Field Values
-
WRAP_NONE
public static final byte WRAP_NONE
- See Also:
- Constant Field Values
-
WRAP_BASIC
public static final byte WRAP_BASIC
- See Also:
- Constant Field Values
-
WRAP_SCALE
public static final byte WRAP_SCALE
- See Also:
- Constant Field Values
-
-
Constructor Detail
-
RMText
public RMText()
Creates an empty text instance.
-
RMText
public RMText(RMXString string)
Creates a text instance initialized with the given RMXString.
-
RMText
public RMText(java.lang.String plainText)
Creates a text instance initialized with the given plain text String.
-
-
Method Detail
-
getXString
public RMXString getXString()
Returns the XString associated with this RMText.
-
setXString
public void setXString(RMXString s)
Sets the XString associated with this RMText.
-
length
public int length()
Returns the length, in characters, of the XString associated with this RMText.
-
getText
public java.lang.String getText()
Returns the text associated with this RMText as a plain String.
-
setText
public void setText(java.lang.String aString)
Replaces the current text associated with this RMText with the given String.
-
setText
public void setText(RMXString anXString)
Sets the XString associated with this RMText.
-
getVisibleStart
public int getVisibleStart()
Returns the first character index visible in this text.
-
getVisibleEnd
public int getVisibleEnd()
Returns the last character index visible in this text.
-
isAllTextVisible
public boolean isAllTextVisible()
Returns whether all characters can be visibly rendered in text bounds.
-
setFont
public void setFont(RMFont aFont)
Sets the font for all characters.
-
getFormat
public RMFormat getFormat()
Returns the format for char 0.
-
setFormat
public void setFormat(RMFormat aFormat)
Sets the format for all characters.
-
getTextColor
public RMColor getTextColor()
Returns the color of the first character of the xstring associated with this RMText.- Overrides:
getTextColor
in classRMShape
-
setTextColor
public void setTextColor(RMColor aColor)
Sets the color of the characters in the XString associated with this RMText.- Overrides:
setTextColor
in classRMShape
-
isUnderlined
public boolean isUnderlined()
Returns if char 0 is underlined.- Overrides:
isUnderlined
in classRMShape
-
setUnderlined
public void setUnderlined(boolean aFlag)
Sets all chars to be underlined.- Overrides:
setUnderlined
in classRMShape
-
getOutline
public RMXString.Outline getOutline()
Returns the outline for char 0.- Overrides:
getOutline
in classRMShape
-
setOutline
public void setOutline(RMXString.Outline anOutline)
Sets the Outline for all characters.- Overrides:
setOutline
in classRMShape
-
getAlign
public byte getAlign()
Returns the alignment for char 0.
-
setAlign
public void setAlign(int align)
Sets the align for all chars.
-
getAlignString
public java.lang.String getAlignString()
Returns the alignment as a string, one of: "left", "center" or "right".
-
getAlignVertical
public byte getAlignVertical()
Returns the vertical alignment.
-
setAlignVertical
public void setAlignVertical(byte anAlignment)
Sets the vertical alginment.
-
getAlignVerticalString
public java.lang.String getAlignVerticalString()
Returns the vertical alignment as a string, one of: "top", "middle" or "bottom".
-
getWraps
public byte getWraps()
Returns the wrapping behavior for over-filled rpgCloned text (NONE, WRAP, SHRINK).
-
setWraps
public void setWraps(byte aValue)
Sets the wrapping behavior for over-filled rpgCloned text (NONE, WRAP, SHRINK).
-
getPerformsWrap
public boolean getPerformsWrap()
Returns whether text should wrap around other shapes that cause wrap.
-
setPerformsWrap
public void setPerformsWrap(boolean aFlag)
Sets whether text should wrap around other shapes that cause wrap.
-
getCoalesceNewlines
public boolean getCoalesceNewlines()
Returns whether text should coalesce consecutive newlines in rpgClone.
-
setCoalesceNewlines
public void setCoalesceNewlines(boolean aFlag)
Sets whether text should coalesce consecutive newlines in rpgClone.
-
getDrawsSelectionRect
public boolean getDrawsSelectionRect()
Returns whether text should always draw at least a light gray border (useful when editing).
-
setDrawsSelectionRect
public void setDrawsSelectionRect(boolean aValue)
Sets whether text should always draw at least a light-gray border (useful when editing).
-
getCharSpacing
public float getCharSpacing()
Returns the char spacing at char 0.
-
setCharSpacing
public void setCharSpacing(float aValue)
Sets the char spacing for the text string.
-
getLineSpacing
public float getLineSpacing()
Returns the line spacing at char 0.
-
setLineSpacing
public void setLineSpacing(float aHeight)
Sets the line spacing for all chars.
-
getLineGap
public float getLineGap()
Returns the line gap at char 0.
-
setLineGap
public void setLineGap(float aHeight)
Sets the line gap for all chars.
-
getLineHeightMin
public float getLineHeightMin()
Returns the minimum line height at char 0.
-
setLineHeightMin
public void setLineHeightMin(float aHeight)
Sets the minimum line height for all chars.
-
getLineHeightMax
public float getLineHeightMax()
Returns the maximum line height at char 0.
-
setLineHeightMax
public void setLineHeightMax(float aHeight)
Sets the maximum line height for all chars.
-
getTextOrigin
public RMPoint getTextOrigin()
Returns the point inside this text where the first character is placed.
-
getMarginLeft
public float getMarginLeft()
Returns the left margin of the text (default to 2).
-
getMarginRight
public float getMarginRight()
Returns the right margin of the text (defaults to 2).
-
getMarginTop
public float getMarginTop()
Returns the top margin of the text (defaults to 1).
-
getMarginBottom
public float getMarginBottom()
Returns the bottom margin of the text (defaults to 0).
-
getTextBounds
public RMRect getTextBounds()
Returns the actual bounding rect of the text (currently just inset 2 pixels on either side).
-
getBoundsFromTextBounds
public RMRect getBoundsFromTextBounds(RMRect aRect)
Returns bounds from given text bounds, adjusted to account for text margins.
-
getPath
public RMPath getPath()
Returns the path for this shape.- Overrides:
getPath
in classRMRectangle
-
getPathInBounds
public RMPath getPathInBounds()
Overrides shape implementation to pass through getPathInBounds(inset).- Overrides:
getPathInBounds
in classRMShape
-
getPathInBounds
public RMPath getPathInBounds(int inset)
Returns the shape's path scaled to the shape's current bounds.
-
peerDidChange
public void peerDidChange(RMShape aShape)
This notification method is called when any peer is changed.
-
getPathShape
public RMShape getPathShape()
Returns the shape that provides the path for this text to wrap text to.
-
setPathShape
public void setPathShape(RMShape aShape)
Sets the shape that provides the path for this text to wrap text to.
-
setHeight
public void setHeight(double aValue)
Overrides shape implementation to reset height to fit.
-
setRadius
public void setRadius(float aValue)
Overrides rectangle implementation to potentially force text relayout.- Overrides:
setRadius
in classRMRectangle
-
getLinkedText
public RMLinkedText getLinkedText()
Returns the linked text for this text (if any).
-
setLinkedText
public void setLinkedText(RMLinkedText anLinkedText)
Sets the linked text for this text (if any).
-
getTextLayout
public RMTextLayout getTextLayout()
Returns a text layout configured for this text, with layout already performed.
-
getTextLayout
public RMTextLayout getTextLayout(boolean performLayout)
Returns a text layout configured for this text, with an option to perform layout.
-
getWidthToFit
public float getWidthToFit()
Returns the ideal width for this RMText.- Overrides:
getWidthToFit
in classRMShape
-
getHeightToFit
public float getHeightToFit()
Returns the ideal height for this RMText.- Overrides:
getHeightToFit
in classRMShape
-
getHeightToFit
public float getHeightToFit(boolean includeFinalEmptyLine)
Returns the ideal height for this RMText. Provides an option to include the height of trailing newlines.
-
setHeightToFit
public void setHeightToFit(float aValue)
Sets the text's height to fit (often called with -1 to force recalc).
-
scaleTextToFit
public void scaleTextToFit()
Scales font sizes of all text in an RMText shape to fit in bounds. Caches font scale factor in xstring.
-
getFontScale
public float getFontScale()
Returns the scale to apply to all fonts in text's XString (defaults to 1).
-
setFontScale
public void setFontScale(float aFactor)
Sets the scale to apply to all fonts in text's XString.
-
rpgClone
public RMShape rpgClone(ReportMill aReportMill)
This method clones the RMText, performing subtition on the XString.
-
rpgClonePreprocess
public void rpgClonePreprocess(ReportMill aReportMill)
This standard rpgClone hook allows texts set to wrap to perform the wrap.- Overrides:
rpgClonePreprocess
in classRMShape
-
resolvePageReferences
public void resolvePageReferences(ReportMill aReportMill, java.lang.Object userInfo)
Re-does the RPG clone to resolve any @Page@ keys (assumed to be present in userInfo).- Overrides:
resolvePageReferences
in classRMShape
-
toString
public java.lang.String toString()
Standard toSring implementation.
-
turnToChars
public RMShape turnToChars(boolean inPlace)
Returns a group shape with an RMText shape for each glyph in the text.
-
turnToPath
public RMShape turnToPath(boolean inPlace)
Returns an RMPolygon shape with the glyph path for the chars in this text. Assumes one frag.
-
getPolygonForFrag
public RMPolygon getPolygonForFrag(RMTextFrag aFrag)
Returns a polygon shape for the glyphs in a given text frag.
-
superSelectable
public boolean superSelectable()
Editor method - indicates that this shape can be super selected.- Overrides:
superSelectable
in classRMShape
-
isStructured
public boolean isStructured()
Editor method.
-
setNeedsRepaint
public void setNeedsRepaint()
Editor method - passes on repaints to linked text.- Overrides:
setNeedsRepaint
in classRMShape
-
clone
public java.lang.Object clone()
Standard clone implementation.
-
equals
public boolean equals(java.lang.Object anObj)
Standard equals implementation.- Overrides:
equals
in classRMRectangle
-
copy
public void copy(java.lang.Object anObj)
Copies attributes from given object.- Overrides:
copy
in classRMRectangle
-
initWithArchiver
public java.lang.Object initWithArchiver(RMArchiver anArchiver)
Legacy unarchival.- Specified by:
initWithArchiver
in interfaceRMArchiver.Archiving
- Overrides:
initWithArchiver
in classRMRectangle
-
toXML
public RXElement toXML(RXArchiver anArchiver)
XML archival.- Overrides:
toXML
in classRMRectangle
-
fromXML
public java.lang.Object fromXML(RXArchiver anArchiver, RXElement anElement)
XML unarchival.- Overrides:
fromXML
in classRMRectangle
-
fromXMLFinish
public void fromXMLFinish(RXArchiver anArchiver, RXElement anElement)
XML reference unarchival - to unarchive linked text.
-
-