Class ColumnText
Several parameters can be set like the first paragraph line indent and extra space between paragraphs.
A call to the method go
will return one of the following situations: the column ended or the text
ended.
I the column ended, a new column definition can be loaded with the method
setColumns
and the method go
can be called again.
If the text ended, more text can be loaded with addText
and the method go
can be called
again.
The only limitation is that one or more complete paragraphs must be loaded each time.
Full bidirectional reordering is supported. If the run direction is
PdfWriter.RUN_DIRECTION_RTL
the meaning of the horizontal
alignments and margins is mirrored.
-
Field Summary
FieldsModifier and TypeFieldDescriptionprivate boolean
protected int
The column alignment.static final int
Compose the tashkeel in the ligatures.static final int
Do some extra double ligatures.static final int
Eliminate the arabic vowelsprivate int
Holds value of property arabicOptions.protected BidiLine
The chunks that form the text.protected PdfContentByte
ThePdfContent
where the text will be written to.protected PdfContentByte[]
protected boolean
protected ColumnText
protected LinkedList
<Element> protected float
The leading for the current line.protected float
static final int
Digit type option: Use Arabic-Indic digits (U+0660...U+0669).static final int
Digit type option: Use Eastern (Extended) Arabic-Indic digits (U+06f0...U+06f9).static final int
Digit shaping option: Replace Arabic-Indic digits by European digits (U+0030...U+0039).static final int
Digit shaping option: Replace European digits (U+0030...U+0039) by Arabic-Indic digits.static final int
Digit shaping option: Replace European digits (U+0030...U+0039) by Arabic-Indic digits if the most recent strongly directional character is an Arabic letter (its Bidi direction value is RIGHT_TO_LEFT_ARABIC).static final int
Digit shaping option: Replace European digits (U+0030...U+0039) by Arabic-Indic digits if the most recent strongly directional character is an Arabic letter (its Bidi direction value is RIGHT_TO_LEFT_ARABIC).protected float
The extra space between paragraphs.private float
Holds value of property filledWidth.private float
private boolean
protected float
The fixed text leading.protected float
The following paragraph lines indent.static final float
the space char ratioprotected float
The first paragraph line indent.private boolean
protected List
<float[]> The left column bound.protected float
protected static final int
The line cannot fit this column position.protected static final int
The line is out the column limits.protected static final int
The column is valid.protected int
The line status when trying to fit a line to a column.private int
Holds value of property linesWritten.protected int
protected float
Upper bound of the column.protected float
Lower bound of the column.protected float
The text leading that is multiplied by the biggest font size in the line.static final int
Signals that there is no more column.static final int
Signals that there is no more text available.protected boolean
protected float
The width of the line when the column is defined as a simple rectangle.protected float
The right paragraph lines indent.protected List
<float[]> The right column bound.protected float
protected int
private float
Holds value of property spaceCharRatio.private boolean
static final int
Initial value of the status.private boolean
if true, first line height is adjusted so that the max ascender touches the topprotected Phrase
protected float
The current y line location. -
Constructor Summary
Constructors -
Method Summary
Modifier and TypeMethodDescriptionvoid
addElement
(Element element) Adds an element.void
Adds aChunk
to the current text array.void
Adds aPhrase
to the current text array.private void
void
Clears the chunk array.protected List
<float[]> convertColumn
(float[] cLine) Converts a sequence of lines representing one of the column bounds into an internal format.static ColumnText
duplicate
(ColumnText org) Creates an independent duplicated of the instanceorg
.protected float[]
Finds the intersection between theyLine
and the two column bounds.protected float
findLimitsPoint
(List<float[]> wall) Finds the intersection between theyLine
and the column.protected float[]
Finds the intersection between theyLine
, theyLine-leading
and the two column bounds.int
Gets the alignment.int
Gets the arabic shaping options.Gets the canvas.Gets the canvases.float
Gets the biggest descender value of the last line written.float
Sets the extra space between paragraphs.float
Gets the real width used by the largest line.float
Gets the following paragraph lines indent.float
Gets the first paragraph line indent.float
Gets the fixed leading.int
Gets the number of lines written.float
Gets the variable leading.float
Gets the right paragraph lines indent.int
Gets the run direction.float
Gets the space/character extra spacing ratio for fully justified text.static float
Gets the width that the line will occupy after writing.static float
Gets the width that the line will occupy after writing.float
getYLine()
Gets the yLine.int
go()
Outputs the lines to the document.int
go
(boolean simulate) Outputs the lines to the document.protected int
goComposite
(boolean simulate) static boolean
hasMoreText
(int status) Checks the status variable and looks if there's still some text.boolean
Gets the first line adjustment property.boolean
Checks if UseAscender is enabled/disabled.setACopy
(ColumnText org) Makes this instance an independent copy oforg
.void
setAdjustFirstLine
(boolean adjustFirstLine) Sets the first line adjustment.void
setAlignment
(int alignment) Sets the alignment.void
setArabicOptions
(int arabicOptions) Sets the arabic shaping options.void
setCanvas
(PdfContentByte canvas) Sets the canvas.void
setCanvases
(PdfContentByte[] canvases) Sets the canvases.void
setColumns
(float[] leftLine, float[] rightLine) Sets the columns bounds.void
setExtraParagraphSpace
(float extraParagraphSpace) Sets the extra space between paragraphs.void
setFilledWidth
(float filledWidth) Sets the real width used by the largest line.void
setFollowingIndent
(float indent) Sets the following paragraph lines indent.void
setIndent
(float indent) Sets the first paragraph line indent.void
setLeading
(float leading) Sets the leading to fixed.void
setLeading
(float fixedLeading, float multipliedLeading) Sets the leading fixed and variable.void
setRightIndent
(float indent) Sets the right paragraph lines indent.void
setRunDirection
(int runDirection) Sets the run direction.void
setSimpleColumn
(float llx, float lly, float urx, float ury) Simplified method for rectangular columns.void
setSimpleColumn
(float llx, float lly, float urx, float ury, float leading, int alignment) Simplified method for rectangular columns.void
setSimpleColumn
(Phrase phrase, float llx, float lly, float urx, float ury, float leading, int alignment) Simplified method for rectangular columns.protected void
setSimpleVars
(ColumnText org) void
setSpaceCharRatio
(float spaceCharRatio) Sets the ratio between the extra word spacing and the extra character spacing when the text is fully justified.void
Replaces the current text array with thisPhrase
.void
setUseAscender
(boolean useAscender) Enables/Disables adjustment of first line height based on max ascender.void
setYLine
(float yLine) Sets the yLine.static void
showTextAligned
(PdfContentByte canvas, int alignment, Phrase phrase, float x, float y, float rotation) Shows a line of text.static void
showTextAligned
(PdfContentByte canvas, int alignment, Phrase phrase, float x, float y, float rotation, int runDirection, int arabicOptions) Shows a line of text.void
updateFilledWidth
(float w) Replaces thefilledWidth
if greater than the existing one.boolean
Checks if the element has a height of 0.
-
Field Details
-
AR_NOVOWEL
public static final int AR_NOVOWELEliminate the arabic vowels- See Also:
-
AR_COMPOSEDTASHKEEL
public static final int AR_COMPOSEDTASHKEELCompose the tashkeel in the ligatures.- See Also:
-
AR_LIG
public static final int AR_LIGDo some extra double ligatures.- See Also:
-
DIGITS_EN2AN
public static final int DIGITS_EN2ANDigit shaping option: Replace European digits (U+0030...U+0039) by Arabic-Indic digits.- See Also:
-
DIGITS_AN2EN
public static final int DIGITS_AN2ENDigit shaping option: Replace Arabic-Indic digits by European digits (U+0030...U+0039).- See Also:
-
DIGITS_EN2AN_INIT_LR
public static final int DIGITS_EN2AN_INIT_LRDigit shaping option: Replace European digits (U+0030...U+0039) by Arabic-Indic digits if the most recent strongly directional character is an Arabic letter (its Bidi direction value is RIGHT_TO_LEFT_ARABIC). The initial state at the start of the text is assumed to be not an Arabic, letter, so European digits at the start of the text will not change. Compare to DIGITS_ALEN2AN_INIT_AL.- See Also:
-
DIGITS_EN2AN_INIT_AL
public static final int DIGITS_EN2AN_INIT_ALDigit shaping option: Replace European digits (U+0030...U+0039) by Arabic-Indic digits if the most recent strongly directional character is an Arabic letter (its Bidi direction value is RIGHT_TO_LEFT_ARABIC). The initial state at the start of the text is assumed to be an Arabic, letter, so European digits at the start of the text will change. Compare to DIGITS_ALEN2AN_INT_LR.- See Also:
-
DIGIT_TYPE_AN
public static final int DIGIT_TYPE_ANDigit type option: Use Arabic-Indic digits (U+0660...U+0669).- See Also:
-
DIGIT_TYPE_AN_EXTENDED
public static final int DIGIT_TYPE_AN_EXTENDEDDigit type option: Use Eastern (Extended) Arabic-Indic digits (U+06f0...U+06f9).- See Also:
-
GLOBAL_SPACE_CHAR_RATIO
public static final float GLOBAL_SPACE_CHAR_RATIOthe space char ratio- See Also:
-
START_COLUMN
public static final int START_COLUMNInitial value of the status.- See Also:
-
NO_MORE_TEXT
public static final int NO_MORE_TEXTSignals that there is no more text available.- See Also:
-
NO_MORE_COLUMN
public static final int NO_MORE_COLUMNSignals that there is no more column.- See Also:
-
LINE_STATUS_OK
protected static final int LINE_STATUS_OKThe column is valid.- See Also:
-
LINE_STATUS_OFFLIMITS
protected static final int LINE_STATUS_OFFLIMITSThe line is out the column limits.- See Also:
-
LINE_STATUS_NOLINE
protected static final int LINE_STATUS_NOLINEThe line cannot fit this column position.- See Also:
-
runDirection
protected int runDirection -
maxY
protected float maxYUpper bound of the column. -
minY
protected float minYLower bound of the column. -
leftX
protected float leftX -
rightX
protected float rightX -
alignment
protected int alignmentThe column alignment. Default is left alignment. -
leftWall
The left column bound. -
rightWall
The right column bound. -
bidiLine
The chunks that form the text. -
yLine
protected float yLineThe current y line location. Text will be written at this line minus the leading. -
currentLeading
protected float currentLeadingThe leading for the current line. -
fixedLeading
protected float fixedLeadingThe fixed text leading. -
multipliedLeading
protected float multipliedLeadingThe text leading that is multiplied by the biggest font size in the line. -
canvas
ThePdfContent
where the text will be written to. -
canvases
-
lineStatus
protected int lineStatusThe line status when trying to fit a line to a column. -
indent
protected float indentThe first paragraph line indent. -
followingIndent
protected float followingIndentThe following paragraph lines indent. -
rightIndent
protected float rightIndentThe right paragraph lines indent. -
extraParagraphSpace
protected float extraParagraphSpaceThe extra space between paragraphs. -
rectangularWidth
protected float rectangularWidthThe width of the line when the column is defined as a simple rectangle. -
rectangularMode
protected boolean rectangularMode -
descender
protected float descender -
composite
protected boolean composite -
compositeColumn
-
compositeElements
-
listIdx
protected int listIdx -
waitPhrase
-
spaceCharRatio
private float spaceCharRatioHolds value of property spaceCharRatio. -
lastWasNewline
private boolean lastWasNewline -
linesWritten
private int linesWrittenHolds value of property linesWritten. -
firstLineY
private float firstLineY -
firstLineYDone
private boolean firstLineYDone -
arabicOptions
private int arabicOptionsHolds value of property arabicOptions. -
splittedRow
private boolean splittedRow -
useAscender
private boolean useAscenderif true, first line height is adjusted so that the max ascender touches the top -
filledWidth
private float filledWidthHolds value of property filledWidth. -
adjustFirstLine
private boolean adjustFirstLine
-
-
Constructor Details
-
ColumnText
Creates aColumnText
.- Parameters:
canvas
- the place where the text will be written to. Can be a template.
-
-
Method Details
-
duplicate
Creates an independent duplicated of the instanceorg
.- Parameters:
org
- the originalColumnText
- Returns:
- the duplicated
-
getWidth
Gets the width that the line will occupy after writing. Only the width of the first line is returned.- Parameters:
phrase
- thePhrase
containing the linerunDirection
- the run directionarabicOptions
- the options for the arabic shaping- Returns:
- the width of the line
-
getWidth
Gets the width that the line will occupy after writing. Only the width of the first line is returned.- Parameters:
phrase
- thePhrase
containing the line- Returns:
- the width of the line
-
showTextAligned
public static void showTextAligned(PdfContentByte canvas, int alignment, Phrase phrase, float x, float y, float rotation, int runDirection, int arabicOptions) Shows a line of text. Only the first line is written.- Parameters:
canvas
- where the text is to be written toalignment
- the alignment. It is not influenced by the run directionphrase
- thePhrase
with the textx
- the x reference positiony
- the y reference positionrotation
- the rotation to be applied in degrees counterclockwiserunDirection
- the run directionarabicOptions
- the options for the arabic shaping
-
showTextAligned
public static void showTextAligned(PdfContentByte canvas, int alignment, Phrase phrase, float x, float y, float rotation) Shows a line of text. Only the first line is written.- Parameters:
canvas
- where the text is to be written toalignment
- the alignmentphrase
- thePhrase
with the textx
- the x reference positiony
- the y reference positionrotation
- the rotation to be applied in degrees counterclockwise
-
hasMoreText
public static boolean hasMoreText(int status) Checks the status variable and looks if there's still some text.- Parameters:
status
- statues variable- Returns:
true
if there's still some text elsefalse
-
setACopy
Makes this instance an independent copy oforg
.- Parameters:
org
- the originalColumnText
- Returns:
- itself
-
setSimpleVars
-
addWaitingPhrase
private void addWaitingPhrase() -
addText
Adds aPhrase
to the current text array. Will not have any effect if addElement() was called before.- Parameters:
phrase
- the text
-
setText
Replaces the current text array with thisPhrase
. Anything added previously with addElement() is lost.- Parameters:
phrase
- the text
-
addText
Adds aChunk
to the current text array. Will not have any effect if addElement() was called before.- Parameters:
chunk
- the text
-
addElement
Adds an element. Elements supported areParagraph
,List
,PdfPTable
,Image
andGraphic
.It removes all the text placed with
addText()
.- Parameters:
element
- theElement
-
convertColumn
Converts a sequence of lines representing one of the column bounds into an internal format.Each array element will contain a
float[4]
representing the line x = ax + b.- Parameters:
cLine
- the column array- Returns:
- the converted array
-
findLimitsPoint
Finds the intersection between theyLine
and the column. It will set thelineStatus
appropriately.- Parameters:
wall
- the column to intersect- Returns:
- the x coordinate of the intersection
-
findLimitsOneLine
protected float[] findLimitsOneLine()Finds the intersection between theyLine
and the two column bounds. It will set thelineStatus
appropriately.- Returns:
- a
float[2]
with the x coordinates of the intersection
-
findLimitsTwoLines
protected float[] findLimitsTwoLines()Finds the intersection between theyLine
, theyLine-leading
and the two column bounds. It will set thelineStatus
appropriately.- Returns:
- a
float[4]
with the x coordinates of the intersection
-
setColumns
public void setColumns(float[] leftLine, float[] rightLine) Sets the columns bounds. Each column bound is described by afloat[]
with the line points [x1,y1,x2,y2,...]. The array must have at least 4 elements.- Parameters:
leftLine
- the left column boundrightLine
- the right column bound
-
setSimpleColumn
public void setSimpleColumn(Phrase phrase, float llx, float lly, float urx, float ury, float leading, int alignment) Simplified method for rectangular columns.- Parameters:
phrase
- aPhrase
llx
- the lower left x cornerlly
- the lower left y cornerurx
- the upper right x cornerury
- the upper right y cornerleading
- the leadingalignment
- the column alignment
-
setSimpleColumn
public void setSimpleColumn(float llx, float lly, float urx, float ury, float leading, int alignment) Simplified method for rectangular columns.- Parameters:
llx
- the lower left x cornerlly
- the lower left y cornerurx
- the upper right x cornerury
- the upper right y cornerleading
- the leadingalignment
- the column alignment
-
setSimpleColumn
public void setSimpleColumn(float llx, float lly, float urx, float ury) Simplified method for rectangular columns.- Parameters:
llx
- lower-left-xlly
- lower-left-yurx
- upper-right-xury
- upper-right-y
-
setLeading
public void setLeading(float fixedLeading, float multipliedLeading) Sets the leading fixed and variable. The resultant leading will be fixedLeading+multipliedLeading*maxFontSize where maxFontSize is the size of the biggest font in the line.- Parameters:
fixedLeading
- the fixed leadingmultipliedLeading
- the variable leading
-
getLeading
public float getLeading()Gets the fixed leading.- Returns:
- the leading
-
setLeading
public void setLeading(float leading) Sets the leading to fixed.- Parameters:
leading
- the leading
-
getMultipliedLeading
public float getMultipliedLeading()Gets the variable leading.- Returns:
- the leading
-
getYLine
public float getYLine()Gets the yLine.- Returns:
- the yLine
-
setYLine
public void setYLine(float yLine) Sets the yLine. The line will be written to yLine-leading.- Parameters:
yLine
- the yLine
-
getAlignment
public int getAlignment()Gets the alignment.- Returns:
- the alignment
-
setAlignment
public void setAlignment(int alignment) Sets the alignment.- Parameters:
alignment
- the alignment
-
getIndent
public float getIndent()Gets the first paragraph line indent.- Returns:
- the indent
-
setIndent
public void setIndent(float indent) Sets the first paragraph line indent.- Parameters:
indent
- the indent
-
getFollowingIndent
public float getFollowingIndent()Gets the following paragraph lines indent.- Returns:
- the indent
-
setFollowingIndent
public void setFollowingIndent(float indent) Sets the following paragraph lines indent.- Parameters:
indent
- the indent
-
getRightIndent
public float getRightIndent()Gets the right paragraph lines indent.- Returns:
- the indent
-
setRightIndent
public void setRightIndent(float indent) Sets the right paragraph lines indent.- Parameters:
indent
- the indent
-
go
Outputs the lines to the document. It is equivalent togo(false)
.- Returns:
- returns the result of the operation. It can be
NO_MORE_TEXT
and/orNO_MORE_COLUMN
- Throws:
DocumentException
- on error
-
go
Outputs the lines to the document. The output can be simulated.- Parameters:
simulate
-true
to simulate the writing to the document- Returns:
- returns the result of the operation. It can be
NO_MORE_TEXT
and/orNO_MORE_COLUMN
- Throws:
DocumentException
- on error
-
getExtraParagraphSpace
public float getExtraParagraphSpace()Sets the extra space between paragraphs.- Returns:
- the extra space between paragraphs
-
setExtraParagraphSpace
public void setExtraParagraphSpace(float extraParagraphSpace) Sets the extra space between paragraphs.- Parameters:
extraParagraphSpace
- the extra space between paragraphs
-
clearChunks
public void clearChunks()Clears the chunk array. A call togo()
will always return NO_MORE_TEXT. -
getSpaceCharRatio
public float getSpaceCharRatio()Gets the space/character extra spacing ratio for fully justified text.- Returns:
- the space/character extra spacing ratio
-
setSpaceCharRatio
public void setSpaceCharRatio(float spaceCharRatio) Sets the ratio between the extra word spacing and the extra character spacing when the text is fully justified. Extra word spacing will growspaceCharRatio
times more than extra character spacing. If the ratio isPdfWriter.NO_SPACE_CHAR_RATIO
then the extra character spacing will be zero.- Parameters:
spaceCharRatio
- the ratio between the extra word spacing and the extra character spacing
-
getRunDirection
public int getRunDirection()Gets the run direction.- Returns:
- the run direction
-
setRunDirection
public void setRunDirection(int runDirection) Sets the run direction.- Parameters:
runDirection
- the run direction
-
getLinesWritten
public int getLinesWritten()Gets the number of lines written.- Returns:
- the number of lines written
-
getArabicOptions
public int getArabicOptions()Gets the arabic shaping options.- Returns:
- the arabic shaping options
-
setArabicOptions
public void setArabicOptions(int arabicOptions) Sets the arabic shaping options. The option can be AR_NOVOWEL, AR_COMPOSEDTASHKEEL and AR_LIG.- Parameters:
arabicOptions
- the arabic shaping options
-
getDescender
public float getDescender()Gets the biggest descender value of the last line written.- Returns:
- the biggest descender value of the last line written
-
goComposite
- Throws:
DocumentException
-
getCanvas
Gets the canvas. If a set of four canvases exists, the TEXTCANVAS is returned.- Returns:
- a PdfContentByte.
-
setCanvas
Sets the canvas. If before a set of four canvases was set, it is being unset.- Parameters:
canvas
- an object ofPdfContentByte
-
getCanvases
Gets the canvases.- Returns:
- an array of PdfContentByte
-
setCanvases
Sets the canvases.- Parameters:
canvases
- an array ofPdfContentByte
-
zeroHeightElement
public boolean zeroHeightElement()Checks if the element has a height of 0.- Returns:
- true or false
- Since:
- 2.1.2
-
isUseAscender
public boolean isUseAscender()Checks if UseAscender is enabled/disabled.- Returns:
- true is the adjustment of the first line height is based on max ascender.
-
setUseAscender
public void setUseAscender(boolean useAscender) Enables/Disables adjustment of first line height based on max ascender.- Parameters:
useAscender
- enable adjustment if true
-
getFilledWidth
public float getFilledWidth()Gets the real width used by the largest line.- Returns:
- the real width used by the largest line
-
setFilledWidth
public void setFilledWidth(float filledWidth) Sets the real width used by the largest line. Only used to set it to zero to start another measurement.- Parameters:
filledWidth
- the real width used by the largest line
-
updateFilledWidth
public void updateFilledWidth(float w) Replaces thefilledWidth
if greater than the existing one.- Parameters:
w
- the newfilledWidth
if greater than the existing one
-
isAdjustFirstLine
public boolean isAdjustFirstLine()Gets the first line adjustment property.- Returns:
- the first line adjustment property.
-
setAdjustFirstLine
public void setAdjustFirstLine(boolean adjustFirstLine) Sets the first line adjustment. Some objects have properties, like spacing before, that behave differently if the object is the first to be written after go() or not. The first line adjustment istrue
by default but can be changed if several objects are to be placed one after the other in the same column calling go() several times.- Parameters:
adjustFirstLine
-true
to adjust the first line,false
otherwise
-