com.lowagie.text.pdf
Class ColumnText

java.lang.Object
  |
  +--com.lowagie.text.pdf.ColumnText

public class ColumnText
extends Object

Formats text in a columnwise form. The text is bound on the left and on the right by a sequence of lines. This allows the column to have any shape, not only rectangular.

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.

Author:
Paulo Soares (psoares@consiste.pt)

Field Summary
protected  int alignment
          The column alignment.
static int AR_COMPOSEDTASHKEEL
           
static int AR_LIG
           
static int AR_NOVOWEL
           
private  int arabicOptions
          Holds value of property arabicOptions.
protected  BidiLine bidiLine
          The chunks that form the text.
protected  PdfContentByte canvas
          The PdfContent where the text will be written to.
protected  int currentChunkMarker
          Marks the chunks to be eliminated when the line is written.
protected  float currentLeading
          The leading for the current line.
protected  PdfChunk currentStandbyChunk
          The chunk created by the splitting.
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
           
protected  float indent
          The first paragraph line indent.
private  boolean lastWasNewline
           
protected  ArrayList leftWall
          The left column bound.
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.
private  int linesWritten
          Holds value of property linesWritten.
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  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  int runDirection
           
private  float spaceCharRatio
          Holds value of property spaceCharRatio.
protected  String splittedChunkText
          The chunk created by the splitting.
protected  float yLine
          The current y line location.
 
Constructor Summary
ColumnText(PdfContentByte canvas)
          Creates a ColumnText.
 
Method Summary
 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.
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-leadingand the two column bounds.
 int getAlignment()
          Gets the alignment.
 int getArabicOptions()
          Gets the arabic shaping options.
 float getExtraParagraphSpace()
          Sets the extra space between paragraphs.
 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.
 float getYLine()
          Gets the yLine.
 int go()
          Outputs the lines to the document.
 int go(boolean simulate)
          Outputs the lines to the document.
 void setAlignment(int alignment)
          Sets the alignment.
 void setArabicOptions(int arabicOptions)
          Sets the arabic shaping options.
 void setColumns(float[] leftLine, float[] rightLine)
          Sets the columns bounds.
 void setExtraParagraphSpace(float extraParagraphSpace)
          Sets the extra space between paragraphs.
 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, 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.
 void setSpaceCharRatio(float spaceCharRatio)
          Sets the ratio between the extra word spacing and the extra character spacing when the text is fully justified.
 void setYLine(float yLine)
          Sets the yLine.
 
Methods inherited from class java.lang.Object
clone, equals, finalize, getClass, hashCode, notify, notifyAll, toString, wait, wait, wait
 

Field Detail

AR_NOVOWEL

public static final int AR_NOVOWEL
See Also:
Constant Field Values

AR_COMPOSEDTASHKEEL

public static final int AR_COMPOSEDTASHKEEL
See Also:
Constant Field Values

AR_LIG

public static final int AR_LIG
See Also:
Constant Field Values

runDirection

protected int runDirection

GLOBAL_SPACE_CHAR_RATIO

public static final float GLOBAL_SPACE_CHAR_RATIO
See Also:
Constant Field Values

NO_MORE_TEXT

public static final int NO_MORE_TEXT
Signals that there is no more text available.

See Also:
Constant Field Values

NO_MORE_COLUMN

public static final int NO_MORE_COLUMN
Signals that there is no more column.

See Also:
Constant Field Values

LINE_STATUS_OK

protected static final int LINE_STATUS_OK
The column is valid.

See Also:
Constant Field Values

LINE_STATUS_OFFLIMITS

protected static final int LINE_STATUS_OFFLIMITS
The line is out the column limits.

See Also:
Constant Field Values

LINE_STATUS_NOLINE

protected static final int LINE_STATUS_NOLINE
The line cannot fit this column position.

See Also:
Constant Field Values

maxY

protected float maxY
Upper bound of the column.


minY

protected float minY
Lower bound of the column.


alignment

protected int alignment
The column alignment. Default is left alignment.


leftWall

protected ArrayList leftWall
The left column bound.


rightWall

protected ArrayList rightWall
The right column bound.


bidiLine

protected BidiLine bidiLine
The chunks that form the text.


yLine

protected float yLine
The current y line location. Text will be written at this line minus the leading.


currentLeading

protected float currentLeading
The leading for the current line.


fixedLeading

protected float fixedLeading
The fixed text leading.


multipliedLeading

protected float multipliedLeading
The text leading that is multiplied by the biggest font size in the line.


canvas

protected PdfContentByte canvas
The PdfContent where the text will be written to.


lineStatus

protected int lineStatus
The line status when trying to fit a line to a column.


indent

protected float indent
The first paragraph line indent.


followingIndent

protected float followingIndent
The following paragraph lines indent.


rightIndent

protected float rightIndent
The right paragraph lines indent.


extraParagraphSpace

protected float extraParagraphSpace
The extra space between paragraphs.


currentChunkMarker

protected int currentChunkMarker
Marks the chunks to be eliminated when the line is written.


currentStandbyChunk

protected PdfChunk currentStandbyChunk
The chunk created by the splitting.


splittedChunkText

protected String splittedChunkText
The chunk created by the splitting.


rectangularWidth

protected float rectangularWidth
The width of the line when the column is defined as a simple rectangle.


spaceCharRatio

private float spaceCharRatio
Holds value of property spaceCharRatio.


lastWasNewline

private boolean lastWasNewline

linesWritten

private int linesWritten
Holds value of property linesWritten.


arabicOptions

private int arabicOptions
Holds value of property arabicOptions.

Constructor Detail

ColumnText

public ColumnText(PdfContentByte canvas)
Creates a ColumnText.

Parameters:
canvas - the place where the text will be written to. Can be a template.
Method Detail

addText

public void addText(Phrase phrase)
Adds a Phrase to the current text array.

Parameters:
phrase - the text

addText

public void addText(Chunk chunk)
Adds a Chunk to the current text array.

Parameters:
chunk - the text

convertColumn

protected ArrayList convertColumn(float[] cLine)
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

protected float findLimitsPoint(ArrayList wall)
Finds the intersection between the yLine and the column. It will set the lineStatus apropriatly.

Parameters:
wall - the column to intersect
Returns:
the x coordinate of the intersection

findLimitsOneLine

protected float[] findLimitsOneLine()
Finds the intersection between the yLine and the two column bounds. It will set the lineStatus apropriatly.

Returns:
a float[2]with the x coordinates of the intersection

findLimitsTwoLines

protected float[] findLimitsTwoLines()
Finds the intersection between the yLine, the yLine-leadingand the two column bounds. It will set the lineStatus apropriatly.

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 a float[] with the line points [x1,y1,x2,y2,...]. The array must have at least 4 elements.

Parameters:
leftLine - the left column bound
rightLine - 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 - a Phrase
llx - the lower left x corner
lly - the lower left y corner
urx - the upper right x corner
ury - the upper right y corner
leading - the leading
alignment - 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 corner
lly - the lower left y corner
urx - the upper right x corner
ury - the upper right y corner
leading - the leading
alignment - the column alignment

setLeading

public void setLeading(float leading)
Sets the leading to fixed

Parameters:
leading - the leading

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 bigest font in the line.

Parameters:
fixedLeading - the fixed leading
multipliedLeading - the variable leading

getLeading

public float getLeading()
Gets the fixed leading

Returns:
the leading

getMultipliedLeading

public float getMultipliedLeading()
Gets the variable leading

Returns:
the leading

setYLine

public void setYLine(float yLine)
Sets the yLine. The line will be written to yLine-leading.

Parameters:
yLine - the yLine

getYLine

public float getYLine()
Gets the yLine.

Returns:
the yLine

setAlignment

public void setAlignment(int alignment)
Sets the alignment.

Parameters:
alignment - the alignment

getAlignment

public int getAlignment()
Gets the alignment.

Returns:
the alignment

setIndent

public void setIndent(float indent)
Sets the first paragraph line indent.

Parameters:
indent - the indent

getIndent

public float getIndent()
Gets the first paragraph line indent.

Returns:
the indent

setFollowingIndent

public void setFollowingIndent(float indent)
Sets the following paragraph lines indent.

Parameters:
indent - the indent

getFollowingIndent

public float getFollowingIndent()
Gets the following paragraph lines indent.

Returns:
the indent

setRightIndent

public void setRightIndent(float indent)
Sets the right paragraph lines indent.

Parameters:
indent - the indent

getRightIndent

public float getRightIndent()
Gets the right paragraph lines indent.

Returns:
the indent

go

public int go()
       throws DocumentException
Outputs the lines to the document. It is equivalent to go(false).

Returns:
returns the result of the operation. It can be NO_MORE_TEXT and/or NO_MORE_COLUMN
Throws:
DocumentException - on error

go

public int go(boolean simulate)
       throws DocumentException
Outputs the lines to the document. The output can be simulated.

Parameters:
simulate - true to simulate the writting to the document
Returns:
returns the result of the operation. It can be NO_MORE_TEXT and/or NO_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 to go() 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 grow spaceCharRatio times more than extra character spacing. If the ratio is PdfWriter.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

setRunDirection

public void setRunDirection(int runDirection)
Sets the run direction.

Parameters:
runDirection - the run direction

getRunDirection

public int getRunDirection()
Gets the run direction.

Returns:
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