Class AbstractPLText<IMPLTYPE extends AbstractPLText<IMPLTYPE>>
- java.lang.Object
-
- com.helger.pdflayout.base.AbstractPLObject<IMPLTYPE>
-
- com.helger.pdflayout.base.AbstractPLRenderableObject<IMPLTYPE>
-
- com.helger.pdflayout.base.AbstractPLElement<IMPLTYPE>
-
- com.helger.pdflayout.base.AbstractPLInlineElement<IMPLTYPE>
-
- com.helger.pdflayout.element.text.AbstractPLText<IMPLTYPE>
-
- Type Parameters:
IMPLTYPE- Implementation type
- All Implemented Interfaces:
com.helger.commons.id.IHasID<String>,com.helger.commons.traits.IGenericImplTrait<IMPLTYPE>,IPLElement<IMPLTYPE>,IPLHasBorder<IMPLTYPE>,IPLHasFillColor<IMPLTYPE>,IPLHasHorizontalAlignment<IMPLTYPE>,IPLHasMargin<IMPLTYPE>,IPLHasMarginBorderPadding<IMPLTYPE>,IPLHasOutline,IPLHasPadding<IMPLTYPE>,IPLInlineElement<IMPLTYPE>,IPLObject<IMPLTYPE>,IPLRenderableObject<IMPLTYPE>,IPLSplittableObject<IMPLTYPE,IMPLTYPE>,IPLVisitable
- Direct Known Subclasses:
PLText
public abstract class AbstractPLText<IMPLTYPE extends AbstractPLText<IMPLTYPE>> extends AbstractPLInlineElement<IMPLTYPE> implements IPLHasHorizontalAlignment<IMPLTYPE>, IPLSplittableObject<IMPLTYPE,IMPLTYPE>
Render text- Author:
- Philip Helger
-
-
Field Summary
Fields Modifier and Type Field Description static floatDEFAULT_LINE_SPACINGstatic intDEFAULT_MAX_ROWSstatic booleanDEFAULT_REPLACE_PLACEHOLDERSprotected com.helger.commons.collection.impl.ICommonsList<TextAndWidthSpec>m_aPreparedLinesprotected com.helger.commons.collection.impl.ICommonsList<TextAndWidthSpec>m_aPreparedLinesUnmodifiedprotected floatm_fDescentprotected floatm_fTextHeightprotected intm_nPreparedLineCountUnmodified-
Fields inherited from interface com.helger.pdflayout.base.IPLElement
DEFAULT_MAX_SIZE, DEFAULT_MIN_SIZE
-
Fields inherited from interface com.helger.pdflayout.base.IPLHasBorder
DEFAULT_BORDER
-
Fields inherited from interface com.helger.pdflayout.base.IPLHasFillColor
DEFAULT_FILL_COLOR
-
Fields inherited from interface com.helger.pdflayout.base.IPLHasHorizontalAlignment
DEFAULT_HORZ_ALIGNMENT
-
Fields inherited from interface com.helger.pdflayout.base.IPLHasMargin
DEFAULT_MARGIN
-
Fields inherited from interface com.helger.pdflayout.base.IPLHasPadding
DEFAULT_PADDING
-
Fields inherited from interface com.helger.pdflayout.base.IPLSplittableObject
DEFAULT_VERT_SPLITTABLE
-
-
Constructor Summary
Constructors Constructor Description AbstractPLText(String sText, FontSpec aFontSpec)
-
Method Summary
All Methods Static Methods Instance Methods Concrete Methods Modifier and Type Method Description com.helger.commons.state.EChangebeforeRender(PagePreRenderContext aCtx)Called after the page was created but before the content stream is created.com.helger.commons.collection.impl.ICommonsList<TextAndWidthSpec>getAllPreparedLinesUnmodified()static StringgetCleanedPLText(String sText)floatgetCustomAscentFirstLine()protected floatgetDisplayHeightOfLineCount(int nLineCount, boolean bLineSpacingAlsoOnLastLine)FontSpecgetFontSpec()EHorzAlignmentgetHorzAlign()floatgetLineSpacing()intgetMaxRows()intgetPreparedLineCountUnmodified()StringgetText()booleanhasNoText()booleanhasText()booleanisReplacePlaceholder()booleanisVertSplittable()protected voidonMarkAsNotPrepared()PL objects need to overwrite this method to reset their preparation state.protected SizeSpeconPrepare(PreparationContext aCtx)The abstract method that must be implemented by all subclasses.protected voidonRender(PageRenderContext aCtx)Abstract method to be implemented by subclasses.IMPLTYPEsetBasicDataFrom(IMPLTYPE aSource)For copying stuff internally.IMPLTYPEsetCustomAscentFirstLine(float fCustomAscentFirstLine)Set a custom ascent to the first lineIMPLTYPEsetHorzAlign(EHorzAlignment eHorzAlign)Set the horizontal alignment of this element.IMPLTYPEsetLineSpacing(float fLineSpacing)Set the line spacing to use.IMPLTYPEsetMaxRows(int nMaxRows)Set the maximum number of rows to render.IMPLTYPEsetReplacePlaceholder(boolean bReplacePlaceholder)Change whether placeholders should be replaced or not.IMPLTYPEsetVertSplittable(boolean bVertSplittable)Change the vertical splitability of this object.PLSplitResultsplitElementVert(float fElementWidth, float fAvailableHeight)Split this element vertically into sub-elements according to the available height.StringtoString()-
Methods inherited from class com.helger.pdflayout.base.AbstractPLElement
getBorder, getFillColor, getMargin, getMaxSize, getMinSize, getPadding, getRenderSize, setBorder, setFillColor, setMargin, setMaxSize, setMinSize, setPadding
-
Methods inherited from class com.helger.pdflayout.base.AbstractPLRenderableObject
getPrepareAvailableSize, getPreparedSize, getRenderSize, internalCheckAlreadyPrepared, internalCheckNotPrepared, internalMarkAsNotPrepared, internalMarkAsNotPreparedDontPropagate, internalMarkAsPrepared, isPrepared, onRenderSizeChange, prepare, render, visit
-
Methods inherited from class com.helger.pdflayout.base.AbstractPLObject
getDebugID, getID, onAfterSetID, setID
-
Methods inherited from class java.lang.Object
clone, equals, finalize, getClass, hashCode, notify, notifyAll, wait, wait, wait
-
Methods inherited from interface com.helger.pdflayout.base.IPLElement
getMaxHeight, getMaxSize, getMaxWidth, getMinHeight, getMinSize, getMinWidth, setExactHeight, setExactSize, setExactWidth, setMaxHeight, setMaxSize, setMaxSize, setMaxWidth, setMinHeight, setMinSize, setMinSize, setMinWidth
-
Methods inherited from interface com.helger.pdflayout.base.IPLHasBorder
getBorder, getBorderBottomWidth, getBorderLeftWidth, getBorderRightWidth, getBorderTopWidth, getBorderXSumWidth, getBorderYSumWidth, setBorder, setBorder, setBorder, setBorder, setBorder, setBorderBottom, setBorderLeft, setBorderRight, setBorderTop, setBorderX, setBorderY
-
Methods inherited from interface com.helger.pdflayout.base.IPLHasFillColor
getFillColor, hasFillColor, setFillColor
-
Methods inherited from interface com.helger.pdflayout.base.IPLHasHorizontalAlignment
getIndentX
-
Methods inherited from interface com.helger.pdflayout.base.IPLHasMargin
addMarginBottom, addMarginLeft, addMarginRight, addMarginTop, addMarginX, addMarginY, getMargin, getMarginBottom, getMarginLeft, getMarginRight, getMarginTop, getMarginXSum, getMarginYSum, setMargin, setMargin, setMargin, setMargin, setMarginBottom, setMarginLeft, setMarginRight, setMarginTop, setMarginX, setMarginY
-
Methods inherited from interface com.helger.pdflayout.base.IPLHasMarginBorderPadding
getOutlineBottom, getOutlineLeft, getOutlineRight, getOutlineTop, getOutlineXSum, getOutlineYSum
-
Methods inherited from interface com.helger.pdflayout.base.IPLHasPadding
addPaddingBottom, addPaddingLeft, addPaddingRight, addPaddingTop, addPaddingX, addPaddingY, getPadding, getPaddingBottom, getPaddingLeft, getPaddingRight, getPaddingTop, getPaddingXSum, getPaddingYSum, setPadding, setPadding, setPadding, setPadding, setPaddingBottom, setPaddingLeft, setPaddingRight, setPaddingTop, setPaddingX, setPaddingY
-
Methods inherited from interface com.helger.pdflayout.base.IPLObject
getAsSplittable, getDebugID, hasID
-
Methods inherited from interface com.helger.pdflayout.base.IPLRenderableObject
getPreparedHeight, getPreparedSize, getPreparedWidth, getRenderHeight, getRenderSize, getRenderWidth, isPrepared, prepare, render
-
Methods inherited from interface com.helger.pdflayout.base.IPLSplittableObject
internalCreateNewVertSplitObject
-
Methods inherited from interface com.helger.pdflayout.base.IPLVisitable
visit
-
-
-
-
Field Detail
-
DEFAULT_LINE_SPACING
public static final float DEFAULT_LINE_SPACING
- See Also:
- Constant Field Values
-
DEFAULT_MAX_ROWS
public static final int DEFAULT_MAX_ROWS
- See Also:
- Constant Field Values
-
DEFAULT_REPLACE_PLACEHOLDERS
public static final boolean DEFAULT_REPLACE_PLACEHOLDERS
- See Also:
- Constant Field Values
-
m_fTextHeight
protected float m_fTextHeight
-
m_fDescent
protected float m_fDescent
-
m_nPreparedLineCountUnmodified
protected int m_nPreparedLineCountUnmodified
-
m_aPreparedLinesUnmodified
protected com.helger.commons.collection.impl.ICommonsList<TextAndWidthSpec> m_aPreparedLinesUnmodified
-
m_aPreparedLines
protected com.helger.commons.collection.impl.ICommonsList<TextAndWidthSpec> m_aPreparedLines
-
-
Method Detail
-
setBasicDataFrom
@Nonnull @OverridingMethodsMustInvokeSuper public IMPLTYPE setBasicDataFrom(@Nonnull IMPLTYPE aSource)
Description copied from interface:IPLObjectFor copying stuff internally. Must always call super method- Specified by:
setBasicDataFromin interfaceIPLObject<IMPLTYPE extends AbstractPLText<IMPLTYPE>>- Overrides:
setBasicDataFromin classAbstractPLInlineElement<IMPLTYPE extends AbstractPLText<IMPLTYPE>>- Parameters:
aSource- Source object to copy from. May not benull.- Returns:
- this for chaining
-
getText
@Nonnull public final String getText()
- Returns:
- The original text provided in the constructor, with newlines
unified. Never
null.
-
hasText
public final boolean hasText()
- Returns:
trueif the contained text has at least one character,falseif it is empty.
-
hasNoText
public final boolean hasNoText()
- Returns:
trueif the text provided in the constructor contains no character,falseotherwise.
-
getFontSpec
@Nonnull public final FontSpec getFontSpec()
- Returns:
- The font specification to be used as provided in the constructor.
Never
null.
-
getLineSpacing
public final float getLineSpacing()
- Returns:
- The line height factor. Defaults to
DEFAULT_LINE_SPACINGwhich means 100%.
-
setLineSpacing
@Nonnull public final IMPLTYPE setLineSpacing(@Nonnegative float fLineSpacing)
Set the line spacing to use. The line spacing is the distance between 2 consecutive lines. The line spacing is not considered if there is a single line of text.- Parameters:
fLineSpacing- A value of 1 means 100%, 1.05 means 105% etc. Must be > 0.- Returns:
- this for chaining
-
getHorzAlign
@Nonnull public final EHorzAlignment getHorzAlign()
- Specified by:
getHorzAlignin interfaceIPLHasHorizontalAlignment<IMPLTYPE extends AbstractPLText<IMPLTYPE>>- Returns:
- The horizontal alignment of this element. By default it is
EHorzAlignment.DEFAULT. Nevernull. The horizontal alignment may only be applied to contained children!
-
setHorzAlign
@Nonnull public final IMPLTYPE setHorzAlign(@Nonnull EHorzAlignment eHorzAlign)
Description copied from interface:IPLHasHorizontalAlignmentSet the horizontal alignment of this element. The horizontal alignment may only be applied to contained children!- Specified by:
setHorzAlignin interfaceIPLHasHorizontalAlignment<IMPLTYPE extends AbstractPLText<IMPLTYPE>>- Parameters:
eHorzAlign- The new horizontal alignment. May not benull.- Returns:
- this
-
getMaxRows
@CheckForSigned public final int getMaxRows()
- Returns:
- The maximum number of rows to be rendered. If this value is ≤ 0
than all rows are rendered. The default value is
DEFAULT_MAX_ROWSmeaning all rows are rendered.
-
setMaxRows
@Nonnull public final IMPLTYPE setMaxRows(int nMaxRows)
Set the maximum number of rows to render.- Parameters:
nMaxRows- Maximum number of rows. If ≤ 0 than all lines are rendered.- Returns:
- this for chaining
-
isVertSplittable
public final boolean isVertSplittable()
- Specified by:
isVertSplittablein interfaceIPLObject<IMPLTYPE extends AbstractPLText<IMPLTYPE>>- Specified by:
isVertSplittablein interfaceIPLSplittableObject<IMPLTYPE extends AbstractPLText<IMPLTYPE>,IMPLTYPE extends AbstractPLText<IMPLTYPE>>- Returns:
trueif this element is splittable,falseotherwise.
-
setVertSplittable
@Nonnull public final IMPLTYPE setVertSplittable(boolean bVertSplittable)
Description copied from interface:IPLSplittableObjectChange the vertical splitability of this object.- Specified by:
setVertSplittablein interfaceIPLSplittableObject<IMPLTYPE extends AbstractPLText<IMPLTYPE>,IMPLTYPE extends AbstractPLText<IMPLTYPE>>- Parameters:
bVertSplittable-trueif this element is splittable,falseotherwise.- Returns:
- this for chaining
-
isReplacePlaceholder
public final boolean isReplacePlaceholder()
- Returns:
trueif placeholders should be replaced,falseotherwise. The default value isDEFAULT_REPLACE_PLACEHOLDERSso false.
-
setReplacePlaceholder
@Nonnull public final IMPLTYPE setReplacePlaceholder(boolean bReplacePlaceholder)
Change whether placeholders should be replaced or not. Enabling this slows down the execution of rendering. Enable this only if absolutely necessary.- Parameters:
bReplacePlaceholder-trueif placeholders should be replaced,falseotherwise.- Returns:
- this for chaining
-
getCustomAscentFirstLine
public final float getCustomAscentFirstLine()
- Returns:
- A custom ascent to the first line. Defaults to 0.
- Since:
- 5.1.0
-
setCustomAscentFirstLine
@Nonnull public final IMPLTYPE setCustomAscentFirstLine(float fCustomAscentFirstLine)
Set a custom ascent to the first line- Parameters:
fCustomAscentFirstLine- The value to use. 0 means no change.- Returns:
- this for chaining
- Since:
- 5.1.0
-
onPrepare
protected SizeSpec onPrepare(@Nonnull PreparationContext aCtx)
Description copied from class:AbstractPLRenderableObjectThe abstract method that must be implemented by all subclasses. It is ensured that this method is called only once per instance!- Specified by:
onPreparein classAbstractPLRenderableObject<IMPLTYPE extends AbstractPLText<IMPLTYPE>>- Parameters:
aCtx- Preparation context. Nevernull.- Returns:
- The size of the rendered element without padding, border and
margin. May not be
null.
-
onMarkAsNotPrepared
protected void onMarkAsNotPrepared()
Description copied from class:AbstractPLRenderableObjectPL objects need to overwrite this method to reset their preparation state. They also need to propagate this to their children!- Specified by:
onMarkAsNotPreparedin classAbstractPLRenderableObject<IMPLTYPE extends AbstractPLText<IMPLTYPE>>
-
getPreparedLineCountUnmodified
@Nonnegative public int getPreparedLineCountUnmodified()
- Returns:
- The total number of prepared lines, not taking the maxRows into consideration. Always ≥ 0.
-
getAllPreparedLinesUnmodified
@Nonnull @ReturnsMutableCopy public com.helger.commons.collection.impl.ICommonsList<TextAndWidthSpec> getAllPreparedLinesUnmodified()
-
getDisplayHeightOfLineCount
protected final float getDisplayHeightOfLineCount(@Nonnegative int nLineCount, boolean bLineSpacingAlsoOnLastLine)
-
splitElementVert
@Nullable public PLSplitResult splitElementVert(float fElementWidth, float fAvailableHeight)
Description copied from interface:IPLSplittableObjectSplit this element vertically into sub-elements according to the available height. Splitting is always done after preparation and must return prepared objects!- Specified by:
splitElementVertin interfaceIPLSplittableObject<IMPLTYPE extends AbstractPLText<IMPLTYPE>,IMPLTYPE extends AbstractPLText<IMPLTYPE>>- Parameters:
fElementWidth- The available width without outline of the element.fAvailableHeight- The available height without outline of this element. Must be ≥ 0.- Returns:
nullif splitting makes no sense.
-
beforeRender
@Nonnull public com.helger.commons.state.EChange beforeRender(@Nonnull PagePreRenderContext aCtx) throws IOException
Description copied from interface:IPLRenderableObjectCalled after the page was created but before the content stream is created. This is e.g. used for images to create their XObjects upfront.- Specified by:
beforeRenderin interfaceIPLRenderableObject<IMPLTYPE extends AbstractPLText<IMPLTYPE>>- Parameters:
aCtx- The current page render context. Nevernull.- Returns:
EChange.CHANGEDif something changed. May not benull.- Throws:
IOException- In case of a PDFBox error
-
onRender
protected void onRender(@Nonnull PageRenderContext aCtx) throws IOException
Description copied from class:AbstractPLRenderableObjectAbstract method to be implemented by subclasses.- Specified by:
onRenderin classAbstractPLRenderableObject<IMPLTYPE extends AbstractPLText<IMPLTYPE>>- Parameters:
aCtx- Rendering context. Nevernull.- Throws:
IOException- In case of a PDFBox error
-
toString
public String toString()
- Overrides:
toStringin classAbstractPLElement<IMPLTYPE extends AbstractPLText<IMPLTYPE>>
-
-