public class ColumnText extends Object
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.
Modifier and Type | Field and Description |
---|---|
protected int |
alignment
The column alignment.
|
static int |
AR_COMPOSEDTASHKEEL
Compose the tashkeel in the ligatures.
|
static int |
AR_LIG
Do some extra double ligatures.
|
static int |
AR_NOVOWEL
Eliminate the arabic vowels
|
protected BidiLine |
bidiLine
The chunks that form the text.
|
protected PdfContentByte |
canvas
The
PdfContent where the text will be written to. |
protected PdfContentByte[] |
canvases |
protected boolean |
composite |
protected ColumnText |
compositeColumn |
protected LinkedList |
compositeElements |
protected float |
currentLeading
The leading for the current line.
|
protected float |
descender |
static int |
DIGIT_TYPE_AN
Digit type option: Use Arabic-Indic digits (U+0660...U+0669).
|
static int |
DIGIT_TYPE_AN_EXTENDED
Digit type option: Use Eastern (Extended) Arabic-Indic digits (U+06f0...U+06f9).
|
static int |
DIGITS_AN2EN
Digit shaping option: Replace Arabic-Indic digits by European digits (U+0030...U+0039).
|
static int |
DIGITS_EN2AN
Digit shaping option: Replace European digits (U+0030...U+0039) by Arabic-Indic digits.
|
static int |
DIGITS_EN2AN_INIT_AL
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 int |
DIGITS_EN2AN_INIT_LR
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 |
extraParagraphSpace
The extra space between paragraphs.
|
protected float |
fixedLeading
The fixed text leading.
|
protected float |
followingIndent
The following paragraph lines indent.
|
static float |
GLOBAL_SPACE_CHAR_RATIO
the space char ratio
|
protected float |
indent
The first paragraph line indent.
|
protected ArrayList |
leftWall
The left column bound.
|
protected float |
leftX |
protected static int |
LINE_STATUS_NOLINE
The line cannot fit this column position.
|
protected static int |
LINE_STATUS_OFFLIMITS
The line is out the column limits.
|
protected static int |
LINE_STATUS_OK
The column is valid.
|
protected int |
lineStatus
The line status when trying to fit a line to a column.
|
protected int |
listIdx |
protected float |
maxY
Upper bound of the column.
|
protected float |
minY
Lower bound of the column.
|
protected float |
multipliedLeading
The text leading that is multiplied by the biggest font size in the line.
|
static int |
NO_MORE_COLUMN
Signals that there is no more column.
|
static int |
NO_MORE_TEXT
Signals that there is no more text available.
|
protected boolean |
rectangularMode |
protected float |
rectangularWidth
The width of the line when the column is defined as a simple rectangle.
|
protected float |
rightIndent
The right paragraph lines indent.
|
protected ArrayList |
rightWall
The right column bound.
|
protected float |
rightX |
protected int |
runDirection |
static int |
START_COLUMN
Initial value of the status.
|
protected Phrase |
waitPhrase |
protected float |
yLine
The current y line location.
|
Constructor and Description |
---|
ColumnText(PdfContentByte canvas)
Creates a
ColumnText . |
Modifier and Type | Method and Description |
---|---|
void |
addElement(Element element)
Adds an element.
|
void |
addText(Chunk chunk)
Adds a
Chunk to the current text array. |
void |
addText(Phrase phrase)
Adds a
Phrase to the current text array. |
void |
clearChunks()
Clears the chunk array.
|
protected ArrayList |
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 instance
org . |
protected float[] |
findLimitsOneLine()
Finds the intersection between the
yLine and the two
column bounds. |
protected float |
findLimitsPoint(ArrayList wall)
Finds the intersection between the
yLine and the column. |
protected float[] |
findLimitsTwoLines()
Finds the intersection between the
yLine ,
the yLine-leading and the two column bounds. |
int |
getAlignment()
Gets the alignment.
|
int |
getArabicOptions()
Gets the arabic shaping options.
|
PdfContentByte |
getCanvas()
Gets the canvas.
|
PdfContentByte[] |
getCanvases()
Gets the canvases.
|
float |
getDescender()
Gets the biggest descender value of the last line written.
|
float |
getExtraParagraphSpace()
Sets the extra space between paragraphs.
|
float |
getFilledWidth()
Gets the real width used by the largest line.
|
float |
getFollowingIndent()
Gets the following paragraph lines indent.
|
float |
getIndent()
Gets the first paragraph line indent.
|
float |
getLeading()
Gets the fixed leading.
|
int |
getLinesWritten()
Gets the number of lines written.
|
float |
getMultipliedLeading()
Gets the variable leading.
|
float |
getRightIndent()
Gets the right paragraph lines indent.
|
int |
getRunDirection()
Gets the run direction.
|
float |
getSpaceCharRatio()
Gets the space/character extra spacing ratio for fully justified text.
|
static float |
getWidth(Phrase phrase)
Gets the width that the line will occupy after writing.
|
static float |
getWidth(Phrase phrase,
int runDirection,
int arabicOptions)
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 |
isAdjustFirstLine()
Gets the first line adjustment property.
|
boolean |
isUseAscender()
Checks if UseAscender is enabled/disabled.
|
ColumnText |
setACopy(ColumnText org)
Makes this instance an independent copy of
org . |
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 |
setText(Phrase phrase)
Replaces the current text array with this
Phrase . |
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 the
filledWidth if greater than the existing one. |
boolean |
zeroHeightElement()
Checks if the element has a height of 0.
|
public static final int AR_NOVOWEL
public static final int AR_COMPOSEDTASHKEEL
public static final int AR_LIG
public static final int DIGITS_EN2AN
public static final int DIGITS_AN2EN
public static final int DIGITS_EN2AN_INIT_LR
public static final int DIGITS_EN2AN_INIT_AL
public static final int DIGIT_TYPE_AN
public static final int DIGIT_TYPE_AN_EXTENDED
protected int runDirection
public static final float GLOBAL_SPACE_CHAR_RATIO
public static final int START_COLUMN
public static final int NO_MORE_TEXT
public static final int NO_MORE_COLUMN
protected static final int LINE_STATUS_OK
protected static final int LINE_STATUS_OFFLIMITS
protected static final int LINE_STATUS_NOLINE
protected float maxY
protected float minY
protected float leftX
protected float rightX
protected int alignment
protected ArrayList leftWall
protected ArrayList rightWall
protected BidiLine bidiLine
protected float yLine
protected float currentLeading
protected float fixedLeading
protected float multipliedLeading
protected PdfContentByte canvas
PdfContent
where the text will be written to.protected PdfContentByte[] canvases
protected int lineStatus
protected float indent
protected float followingIndent
protected float rightIndent
protected float extraParagraphSpace
protected float rectangularWidth
protected boolean rectangularMode
protected float descender
protected boolean composite
protected ColumnText compositeColumn
protected LinkedList compositeElements
protected int listIdx
protected Phrase waitPhrase
public ColumnText(PdfContentByte canvas)
ColumnText
.canvas
- the place where the text will be written to. Can
be a template.public static ColumnText duplicate(ColumnText org)
org
.org
- the original ColumnText
public ColumnText setACopy(ColumnText org)
org
.org
- the original ColumnText
protected void setSimpleVars(ColumnText org)
public void addText(Phrase phrase)
Phrase
to the current text array.
Will not have any effect if addElement() was called before.phrase
- the textpublic void setText(Phrase phrase)
Phrase
.
Anything added previously with addElement() is lost.phrase
- the textpublic void addText(Chunk chunk)
Chunk
to the current text array.
Will not have any effect if addElement() was called before.chunk
- the textpublic void addElement(Element element)
Paragraph
,
List
, PdfPTable
, Image
and
Graphic
.
It removes all the text placed with addText()
.
element
- the Element
protected ArrayList convertColumn(float[] cLine)
Each array element will contain a float[4]
representing
the line x = ax + b.
cLine
- the column arrayprotected float findLimitsPoint(ArrayList wall)
yLine
and the column. It will
set the lineStatus
appropriately.wall
- the column to intersectprotected float[] findLimitsOneLine()
yLine
and the two
column bounds. It will set the lineStatus
appropriately.float[2]
with the x coordinates of the intersectionprotected float[] findLimitsTwoLines()
yLine
,
the yLine-leading
and the two column bounds.
It will set the lineStatus
appropriately.float[4]
with the x coordinates of the intersectionpublic void setColumns(float[] leftLine, float[] rightLine)
float[]
with the line points [x1,y1,x2,y2,...].
The array must have at least 4 elements.leftLine
- the left column boundrightLine
- the right column boundpublic void setSimpleColumn(Phrase phrase, float llx, float lly, float urx, float ury, float leading, int alignment)
phrase
- a Phrase
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 alignmentpublic void setSimpleColumn(float llx, float lly, float urx, float ury, float leading, int alignment)
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 alignmentpublic void setSimpleColumn(float llx, float lly, float urx, float ury)
llx
- lly
- urx
- ury
- public void setLeading(float leading)
leading
- the leadingpublic void setLeading(float fixedLeading, float multipliedLeading)
fixedLeading
- the fixed leadingmultipliedLeading
- the variable leadingpublic float getLeading()
public float getMultipliedLeading()
public void setYLine(float yLine)
yLine
- the yLinepublic float getYLine()
public void setAlignment(int alignment)
alignment
- the alignmentpublic int getAlignment()
public void setIndent(float indent)
indent
- the indentpublic float getIndent()
public void setFollowingIndent(float indent)
indent
- the indentpublic float getFollowingIndent()
public void setRightIndent(float indent)
indent
- the indentpublic float getRightIndent()
public int go() throws DocumentException
go(false)
.NO_MORE_TEXT
and/or NO_MORE_COLUMN
DocumentException
- on errorpublic int go(boolean simulate) throws DocumentException
simulate
- true
to simulate the writing to the documentNO_MORE_TEXT
and/or NO_MORE_COLUMN
DocumentException
- on errorpublic float getExtraParagraphSpace()
public void setExtraParagraphSpace(float extraParagraphSpace)
extraParagraphSpace
- the extra space between paragraphspublic void clearChunks()
go()
will always return NO_MORE_TEXT.public float getSpaceCharRatio()
public void setSpaceCharRatio(float spaceCharRatio)
spaceCharRatio
times more
than extra character spacing.
If the ratio is PdfWriter.NO_SPACE_CHAR_RATIO
then the
extra character spacing will be zero.spaceCharRatio
- the ratio between the extra word spacing and the extra character spacingpublic void setRunDirection(int runDirection)
runDirection
- the run directionpublic int getRunDirection()
public int getLinesWritten()
public int getArabicOptions()
public void setArabicOptions(int arabicOptions)
arabicOptions
- the arabic shaping optionspublic float getDescender()
public static float getWidth(Phrase phrase, int runDirection, int arabicOptions)
phrase
- the Phrase
containing the linerunDirection
- the run directionarabicOptions
- the options for the arabic shapingpublic static float getWidth(Phrase phrase)
phrase
- the Phrase
containing the linepublic static void showTextAligned(PdfContentByte canvas, int alignment, Phrase phrase, float x, float y, float rotation, int runDirection, int arabicOptions)
canvas
- where the text is to be written toalignment
- the alignment. It is not influenced by the run directionphrase
- the Phrase
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 shapingpublic static void showTextAligned(PdfContentByte canvas, int alignment, Phrase phrase, float x, float y, float rotation)
canvas
- where the text is to be written toalignment
- the alignmentphrase
- the Phrase
with the textx
- the x reference positiony
- the y reference positionrotation
- the rotation to be applied in degrees counterclockwiseprotected int goComposite(boolean simulate) throws DocumentException
DocumentException
public PdfContentByte getCanvas()
public void setCanvas(PdfContentByte canvas)
canvas
- public void setCanvases(PdfContentByte[] canvases)
canvases
- public PdfContentByte[] getCanvases()
public boolean zeroHeightElement()
public boolean isUseAscender()
public void setUseAscender(boolean useAscender)
useAscender
- enable adjustment if truepublic static boolean hasMoreText(int status)
public float getFilledWidth()
public void setFilledWidth(float filledWidth)
filledWidth
- the real width used by the largest linepublic void updateFilledWidth(float w)
filledWidth
if greater than the existing one.w
- the new filledWidth
if greater than the existing onepublic boolean isAdjustFirstLine()
public void setAdjustFirstLine(boolean adjustFirstLine)
true
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.adjustFirstLine
- true
to adjust the first line, false
otherwiseCopyright © 2018. All rights reserved.