| Method from com.lowagie.text.pdf.ColumnText Detail: |
public void addElement(Element element) {
if (element == null)
return;
if (element instanceof Image) {
Image img = (Image)element;
PdfPTable t = new PdfPTable(1);
float w = img.getWidthPercentage();
if (w == 0) {
t.setTotalWidth(img.getScaledWidth());
t.setLockedWidth(true);
}
else
t.setWidthPercentage(w);
t.setSpacingAfter(img.getSpacingAfter());
t.setSpacingBefore(img.getSpacingBefore());
switch (img.getAlignment()) {
case Image.LEFT:
t.setHorizontalAlignment(Element.ALIGN_LEFT);
break;
case Image.RIGHT:
t.setHorizontalAlignment(Element.ALIGN_RIGHT);
break;
default:
t.setHorizontalAlignment(Element.ALIGN_CENTER);
break;
}
PdfPCell c = new PdfPCell(img, true);
c.setPadding(0);
c.setBorder(img.getBorder());
c.setBorderColor(img.getBorderColor());
c.setBorderWidth(img.getBorderWidth());
c.setBackgroundColor(img.getBackgroundColor());
t.addCell(c);
element = t;
}
if (element.type() == Element.CHUNK) {
element = new Paragraph((Chunk)element);
}
else if (element.type() == Element.PHRASE) {
element = new Paragraph((Phrase)element);
}
if (element instanceof SimpleTable) {
try {
element = ((SimpleTable)element).createPdfPTable();
} catch (DocumentException e) {
throw new IllegalArgumentException("Element not allowed.");
}
}
else if (element.type() != Element.PARAGRAPH && element.type() != Element.LIST && element.type() != Element.PTABLE && element.type() != Element.YMARK)
throw new IllegalArgumentException("Element not allowed.");
if (!composite) {
composite = true;
compositeElements = new LinkedList();
bidiLine = null;
waitPhrase = null;
}
compositeElements.add(element);
}
|
public void addText(Phrase phrase) {
if (phrase == null || composite)
return;
addWaitingPhrase();
if (bidiLine == null) {
waitPhrase = phrase;
return;
}
for (Iterator j = phrase.getChunks().iterator(); j.hasNext();) {
bidiLine.addChunk(new PdfChunk((Chunk)j.next(), null));
}
}
Adds a Phrase to the current text array.
Will not have any effect if addElement() was called before. |
public void addText(Chunk chunk) {
if (chunk == null || composite)
return;
addText(new Phrase(chunk));
}
Adds a Chunk to the current text array.
Will not have any effect if addElement() was called before. |
public void clearChunks() {
if (bidiLine != null)
bidiLine.clearChunks();
}
Clears the chunk array. A call to go() will always return
NO_MORE_TEXT. |
protected ArrayList convertColumn(float[] cLine) {
if (cLine.length < 4)
throw new RuntimeException("No valid column line found.");
ArrayList cc = new ArrayList();
for (int k = 0; k < cLine.length - 2; k += 2) {
float x1 = cLine[k];
float y1 = cLine[k + 1];
float x2 = cLine[k + 2];
float y2 = cLine[k + 3];
if (y1 == y2)
continue;
// x = ay + b
float a = (x1 - x2) / (y1 - y2);
float b = x1 - a * y1;
float r[] = new float[4];
r[0] = Math.min(y1, y2);
r[1] = Math.max(y1, y2);
r[2] = a;
r[3] = b;
cc.add(r);
maxY = Math.max(maxY, r[1]);
minY = Math.min(minY, r[0]);
}
if (cc.isEmpty())
throw new RuntimeException("No valid column line found.");
return cc;
}
|
public static ColumnText duplicate(ColumnText org) {
ColumnText ct = new ColumnText(null);
ct.setACopy(org);
return ct;
}
Creates an independent duplicated of the instance org. |
protected float[] findLimitsOneLine() {
float x1 = findLimitsPoint(leftWall);
if (lineStatus == LINE_STATUS_OFFLIMITS || lineStatus == LINE_STATUS_NOLINE)
return null;
float x2 = findLimitsPoint(rightWall);
if (lineStatus == LINE_STATUS_NOLINE)
return null;
return new float[]{x1, x2};
}
Finds the intersection between the yLine and the two
column bounds. It will set the lineStatus appropriately. |
protected float findLimitsPoint(ArrayList wall) {
lineStatus = LINE_STATUS_OK;
if (yLine < minY || yLine > maxY) {
lineStatus = LINE_STATUS_OFFLIMITS;
return 0;
}
for (int k = 0; k < wall.size(); ++k) {
float r[] = (float[])wall.get(k);
if (yLine < r[0] || yLine > r[1])
continue;
return r[2] * yLine + r[3];
}
lineStatus = LINE_STATUS_NOLINE;
return 0;
}
Finds the intersection between the yLine and the column. It will
set the lineStatus appropriately. |
protected float[] findLimitsTwoLines() {
boolean repeat = false;
for (;;) {
if (repeat && currentLeading == 0)
return null;
repeat = true;
float x1[] = findLimitsOneLine();
if (lineStatus == LINE_STATUS_OFFLIMITS)
return null;
yLine -= currentLeading;
if (lineStatus == LINE_STATUS_NOLINE) {
continue;
}
float x2[] = findLimitsOneLine();
if (lineStatus == LINE_STATUS_OFFLIMITS)
return null;
if (lineStatus == LINE_STATUS_NOLINE) {
yLine -= currentLeading;
continue;
}
if (x1[0] >= x2[1] || x2[0] >= x1[1])
continue;
return new float[]{x1[0], x1[1], x2[0], x2[1]};
}
}
Finds the intersection between the yLine,
the yLine-leadingand the two
column bounds. It will set the lineStatus appropriately. |
public int getAlignment() {
return alignment;
}
|
public int getArabicOptions() {
return this.arabicOptions;
}
Gets the arabic shaping options. |
public PdfContentByte getCanvas() {
return canvas;
}
|
public PdfContentByte[] getCanvases() {
return canvases;
}
|
public float getDescender() {
return descender;
}
Gets the biggest descender value of the last line written. |
public float getExtraParagraphSpace() {
return extraParagraphSpace;
}
Sets the extra space between paragraphs. |
public float getFilledWidth() {
return this.filledWidth;
}
Gets the real width used by the largest line. |
public float getFollowingIndent() {
return followingIndent;
}
Gets the following paragraph lines indent. |
public float getIndent() {
return indent;
}
Gets the first paragraph line indent. |
public float getLeading() {
return fixedLeading;
}
|
public int getLinesWritten() {
return this.linesWritten;
}
Gets the number of lines written. |
public float getMultipliedLeading() {
return multipliedLeading;
}
Gets the variable leading |
public float getRightIndent() {
return rightIndent;
}
Gets the right paragraph lines indent. |
public int getRunDirection() {
return runDirection;
}
|
public float getSpaceCharRatio() {
return spaceCharRatio;
}
Gets the space/character extra spacing ratio for
fully justified text. |
public static float getWidth(Phrase phrase) {
return getWidth(phrase, PdfWriter.RUN_DIRECTION_NO_BIDI, 0);
}
Gets the width that the line will occupy after writing.
Only the width of the first line is returned. |
public static float getWidth(Phrase phrase,
int runDirection,
int arabicOptions) {
ColumnText ct = new ColumnText(null);
ct.addText(phrase);
ct.addWaitingPhrase();
PdfLine line = ct.bidiLine.processLine(0, 20000, Element.ALIGN_LEFT, runDirection, arabicOptions);
if (line == null)
return 0;
else
return 20000 - line.widthLeft();
}
Gets the width that the line will occupy after writing.
Only the width of the first line is returned. |
public float getYLine() {
return yLine;
}
|
public int go() throws DocumentException {
return go(false);
}
Outputs the lines to the document. It is equivalent to go(false). |
public int go(boolean simulate) throws DocumentException {
if (composite)
return goComposite(simulate);
addWaitingPhrase();
if (bidiLine == null)
return NO_MORE_TEXT;
descender = 0;
linesWritten = 0;
boolean dirty = false;
float ratio = spaceCharRatio;
Object currentValues[] = new Object[2];
PdfFont currentFont = null;
Float lastBaseFactor = new Float(0);
currentValues[1] = lastBaseFactor;
PdfDocument pdf = null;
PdfContentByte graphics = null;
PdfContentByte text = null;
firstLineY = Float.NaN;
int localRunDirection = PdfWriter.RUN_DIRECTION_NO_BIDI;
if (runDirection != PdfWriter.RUN_DIRECTION_DEFAULT)
localRunDirection = runDirection;
if (canvas != null) {
graphics = canvas;
pdf = canvas.getPdfDocument();
text = canvas.getDuplicate();
}
else if (!simulate)
throw new NullPointerException("ColumnText.go with simulate==false and text==null.");
if (!simulate) {
if (ratio == GLOBAL_SPACE_CHAR_RATIO)
ratio = text.getPdfWriter().getSpaceCharRatio();
else if (ratio < 0.001f)
ratio = 0.001f;
}
float firstIndent = 0;
int status = 0;
if (rectangularMode) {
for (;;) {
firstIndent = (lastWasNewline ? indent : followingIndent);
if (rectangularWidth < = firstIndent + rightIndent) {
status = NO_MORE_COLUMN;
if (bidiLine.isEmpty())
status |= NO_MORE_TEXT;
break;
}
if (bidiLine.isEmpty()) {
status = NO_MORE_TEXT;
break;
}
PdfLine line = bidiLine.processLine(leftX, rectangularWidth - firstIndent - rightIndent, alignment, localRunDirection, arabicOptions);
if (line == null) {
status = NO_MORE_TEXT;
break;
}
float maxSize = line.getMaxSizeSimple();
if (isUseAscender() && Float.isNaN(firstLineY)) {
currentLeading = line.getAscender();
}
else {
currentLeading = fixedLeading + maxSize * multipliedLeading;
}
if (yLine > maxY || yLine - currentLeading < minY ) {
status = NO_MORE_COLUMN;
bidiLine.restore();
break;
}
yLine -= currentLeading;
if (!simulate && !dirty) {
text.beginText();
dirty = true;
}
if (Float.isNaN(firstLineY)) {
firstLineY = yLine;
}
updateFilledWidth(rectangularWidth - line.widthLeft());
if (!simulate) {
currentValues[0] = currentFont;
text.setTextMatrix(leftX + (line.isRTL() ? rightIndent : firstIndent) + line.indentLeft(), yLine);
pdf.writeLineToContent(line, text, graphics, currentValues, ratio);
currentFont = (PdfFont)currentValues[0];
}
lastWasNewline = line.isNewlineSplit();
yLine -= line.isNewlineSplit() ? extraParagraphSpace : 0;
++linesWritten;
descender = line.getDescender();
}
}
else {
currentLeading = fixedLeading;
for (;;) {
firstIndent = (lastWasNewline ? indent : followingIndent);
float yTemp = yLine;
float xx[] = findLimitsTwoLines();
if (xx == null) {
status = NO_MORE_COLUMN;
if (bidiLine.isEmpty())
status |= NO_MORE_TEXT;
yLine = yTemp;
break;
}
if (bidiLine.isEmpty()) {
status = NO_MORE_TEXT;
yLine = yTemp;
break;
}
float x1 = Math.max(xx[0], xx[2]);
float x2 = Math.min(xx[1], xx[3]);
if (x2 - x1 < = firstIndent + rightIndent)
continue;
if (!simulate && !dirty) {
text.beginText();
dirty = true;
}
PdfLine line = bidiLine.processLine(x1, x2 - x1 - firstIndent - rightIndent, alignment, localRunDirection, arabicOptions);
if (line == null) {
status = NO_MORE_TEXT;
yLine = yTemp;
break;
}
if (!simulate) {
currentValues[0] = currentFont;
text.setTextMatrix(x1 + (line.isRTL() ? rightIndent : firstIndent) + line.indentLeft(), yLine);
pdf.writeLineToContent(line, text, graphics, currentValues, ratio);
currentFont = (PdfFont)currentValues[0];
}
lastWasNewline = line.isNewlineSplit();
yLine -= line.isNewlineSplit() ? extraParagraphSpace : 0;
++linesWritten;
descender = line.getDescender();
}
}
if (dirty) {
text.endText();
canvas.add(text);
}
return status;
}
Outputs the lines to the document. The output can be simulated. |
protected int goComposite(boolean simulate) throws DocumentException {
if (!rectangularMode)
throw new DocumentException("Irregular columns are not supported in composite mode.");
linesWritten = 0;
descender = 0;
boolean firstPass = adjustFirstLine;
main_loop:
while (true) {
if (compositeElements.isEmpty())
return NO_MORE_TEXT;
Element element = (Element)compositeElements.getFirst();
if (element.type() == Element.PARAGRAPH) {
Paragraph para = (Paragraph)element;
int status = 0;
for (int keep = 0; keep < 2; ++keep) {
float lastY = yLine;
boolean createHere = false;
if (compositeColumn == null) {
compositeColumn = new ColumnText(canvas);
compositeColumn.setUseAscender(firstPass ? useAscender : false);
compositeColumn.setAlignment(para.getAlignment());
compositeColumn.setIndent(para.getIndentationLeft() + para.getFirstLineIndent());
compositeColumn.setExtraParagraphSpace(para.getExtraParagraphSpace());
compositeColumn.setFollowingIndent(para.getIndentationLeft());
compositeColumn.setRightIndent(para.getIndentationRight());
compositeColumn.setLeading(para.getLeading(), para.getMultipliedLeading());
compositeColumn.setRunDirection(runDirection);
compositeColumn.setArabicOptions(arabicOptions);
compositeColumn.setSpaceCharRatio(spaceCharRatio);
compositeColumn.addText(para);
if (!firstPass) {
yLine -= para.spacingBefore();
}
createHere = true;
}
compositeColumn.leftX = leftX;
compositeColumn.rightX = rightX;
compositeColumn.yLine = yLine;
compositeColumn.rectangularWidth = rectangularWidth;
compositeColumn.rectangularMode = rectangularMode;
compositeColumn.minY = minY;
compositeColumn.maxY = maxY;
boolean keepCandidate = (para.getKeepTogether() && createHere && !firstPass);
status = compositeColumn.go(simulate || (keepCandidate && keep == 0));
updateFilledWidth(compositeColumn.filledWidth);
if ((status & NO_MORE_TEXT) == 0 && keepCandidate) {
compositeColumn = null;
yLine = lastY;
return NO_MORE_COLUMN;
}
if (simulate || !keepCandidate)
break;
if (keep == 0) {
compositeColumn = null;
yLine = lastY;
}
}
firstPass = false;
yLine = compositeColumn.yLine;
linesWritten += compositeColumn.linesWritten;
descender = compositeColumn.descender;
if ((status & NO_MORE_TEXT) != 0) {
compositeColumn = null;
compositeElements.removeFirst();
yLine -= para.spacingAfter();
}
if ((status & NO_MORE_COLUMN) != 0) {
return NO_MORE_COLUMN;
}
}
else if (element.type() == Element.LIST) {
com.lowagie.text.List list = (com.lowagie.text.List)element;
ArrayList items = list.getItems();
ListItem item = null;
float listIndentation = list.getIndentationLeft();
int count = 0;
Stack stack = new Stack();
for (int k = 0; k < items.size(); ++k) {
Object obj = items.get(k);
if (obj instanceof ListItem) {
if (count == listIdx) {
item = (ListItem)obj;
break;
}
else ++count;
}
else if (obj instanceof com.lowagie.text.List) {
stack.push(new Object[]{list, new Integer(k), new Float(listIndentation)});
list = (com.lowagie.text.List)obj;
items = list.getItems();
listIndentation += list.getIndentationLeft();
k = -1;
continue;
}
if (k == items.size() - 1) {
if (!stack.isEmpty()) {
Object objs[] = (Object[])stack.pop();
list = (com.lowagie.text.List)objs[0];
items = list.getItems();
k = ((Integer)objs[1]).intValue();
listIndentation = ((Float)objs[2]).floatValue();
}
}
}
int status = 0;
for (int keep = 0; keep < 2; ++keep) {
float lastY = yLine;
boolean createHere = false;
if (compositeColumn == null) {
if (item == null) {
listIdx = 0;
compositeElements.removeFirst();
continue main_loop;
}
compositeColumn = new ColumnText(canvas);
compositeColumn.setUseAscender(firstPass ? useAscender : false);
compositeColumn.setAlignment(item.getAlignment());
compositeColumn.setIndent(item.getIndentationLeft() + listIndentation + item.getFirstLineIndent());
compositeColumn.setExtraParagraphSpace(item.getExtraParagraphSpace());
compositeColumn.setFollowingIndent(compositeColumn.getIndent());
compositeColumn.setRightIndent(item.getIndentationRight() + list.getIndentationRight());
compositeColumn.setLeading(item.getLeading(), item.getMultipliedLeading());
compositeColumn.setRunDirection(runDirection);
compositeColumn.setArabicOptions(arabicOptions);
compositeColumn.setSpaceCharRatio(spaceCharRatio);
compositeColumn.addText(item);
if (!firstPass) {
yLine -= item.spacingBefore();
}
createHere = true;
}
compositeColumn.leftX = leftX;
compositeColumn.rightX = rightX;
compositeColumn.yLine = yLine;
compositeColumn.rectangularWidth = rectangularWidth;
compositeColumn.rectangularMode = rectangularMode;
compositeColumn.minY = minY;
compositeColumn.maxY = maxY;
boolean keepCandidate = (item.getKeepTogether() && createHere && !firstPass);
status = compositeColumn.go(simulate || (keepCandidate && keep == 0));
updateFilledWidth(compositeColumn.filledWidth);
if ((status & NO_MORE_TEXT) == 0 && keepCandidate) {
compositeColumn = null;
yLine = lastY;
return NO_MORE_COLUMN;
}
if (simulate || !keepCandidate)
break;
if (keep == 0) {
compositeColumn = null;
yLine = lastY;
}
}
firstPass = false;
yLine = compositeColumn.yLine;
linesWritten += compositeColumn.linesWritten;
descender = compositeColumn.descender;
if (!Float.isNaN(compositeColumn.firstLineY) && !compositeColumn.firstLineYDone) {
if (!simulate)
showTextAligned(canvas, Element.ALIGN_LEFT, new Phrase(item.getListSymbol()), compositeColumn.leftX + listIndentation, compositeColumn.firstLineY, 0);
compositeColumn.firstLineYDone = true;
}
if ((status & NO_MORE_TEXT) != 0) {
compositeColumn = null;
++listIdx;
yLine -= item.spacingAfter();
}
if ((status & NO_MORE_COLUMN) != 0) {
return NO_MORE_COLUMN;
}
}
else if (element.type() == Element.PTABLE) {
// don't write anything in the current column if there's no more space available
if (yLine < minY || yLine > maxY)
return NO_MORE_COLUMN;
// get the PdfPTable element
PdfPTable table = (PdfPTable)element;
// we ignore tables without a body
if (table.size() < = table.getHeaderRows()) {
compositeElements.removeFirst();
continue;
}
// offsets
float yTemp = yLine;
if (!firstPass && listIdx == 0) {
yTemp -= table.spacingBefore();
}
float yLineWrite = yTemp;
// don't write anything in the current column if there's no more space available
if (yTemp < minY || yTemp > maxY) {
return NO_MORE_COLUMN;
}
// coordinates
currentLeading = 0;
float x1 = leftX;
float tableWidth;
if (table.isLockedWidth()) {
tableWidth = table.getTotalWidth();
updateFilledWidth(tableWidth);
}
else {
tableWidth = rectangularWidth * table.getWidthPercentage() / 100f;
table.setTotalWidth(tableWidth);
}
// how many header rows are real header rows; how many are footer rows?
int headerRows = table.getHeaderRows();
int footerRows = table.getFooterRows();
if (footerRows > headerRows)
footerRows = headerRows;
int realHeaderRows = headerRows - footerRows;
float headerHeight = table.getHeaderHeight();
float footerHeight = table.getFooterHeight();
// make sure the header and footer fit on the page
boolean skipHeader = (!firstPass && table.isSkipFirstHeader() && listIdx < = headerRows);
if (!skipHeader) {
yTemp -= headerHeight;
if (yTemp < minY || yTemp > maxY) {
if (firstPass) {
compositeElements.removeFirst();
continue;
}
return NO_MORE_COLUMN;
}
}
// how many real rows (not header or footer rows) fit on a page?
int k;
if (listIdx < headerRows) {
listIdx = headerRows;
}
if (!table.isComplete()) {
yTemp -= footerHeight;
}
for (k = listIdx; k < table.size(); ++k) {
float rowHeight = table.getRowHeight(k);
if (yTemp - rowHeight < minY)
break;
yTemp -= rowHeight;
}
if (!table.isComplete()) {
yTemp += footerHeight;
}
// either k is the first row that doesn't fit on the page (break);
if (k < table.size()) {
if (table.isSplitRows() && (!table.isSplitLate() || (k == listIdx && firstPass))) {
if (!splittedRow) {
splittedRow = true;
table = new PdfPTable(table);
compositeElements.set(0, table);
ArrayList rows = table.getRows();
for (int i = headerRows; i < listIdx; ++i)
rows.set(i, null);
}
float h = yTemp - minY;
PdfPRow newRow = table.getRow(k).splitRow(h);
if (newRow == null) {
if (k == listIdx) {
return NO_MORE_COLUMN;
}
}
else {
yTemp = minY;
table.getRows().add(++k, newRow);
}
}
else if (!table.isSplitRows() && k == listIdx && firstPass) {
compositeElements.removeFirst();
splittedRow = false;
continue;
}
else if (k == listIdx && !firstPass && (!table.isSplitRows() || table.isSplitLate()) && (table.getFooterRows() == 0 || table.isComplete())) {
return NO_MORE_COLUMN;
}
}
// or k is the number of rows in the table (for loop was done).
firstPass = false;
// we draw the table (for real now)
if (!simulate) {
// set the alignment
switch (table.getHorizontalAlignment()) {
case Element.ALIGN_LEFT:
break;
case Element.ALIGN_RIGHT:
x1 += rectangularWidth - tableWidth;
break;
default:
x1 += (rectangularWidth - tableWidth) / 2f;
}
// copy the rows that fit on the page in a new table nt
PdfPTable nt = PdfPTable.shallowCopy(table);
ArrayList rows = table.getRows();
ArrayList sub = nt.getRows();
// first we add the real header rows (if necessary)
if (!skipHeader) {
for (int j = 0; j < realHeaderRows; ++j) {
PdfPRow headerRow = (PdfPRow)rows.get(j);
sub.add(headerRow);
}
}
else {
nt.setHeaderRows(footerRows);
}
// then we add the real content
for (int j = listIdx; j < k; ++j) {
sub.add(rows.get(j));
}
// if k < table.size(), we must indicate that the new table is complete;
// otherwise no footers will be added (because iText thinks the table continues on the same page)
if (k < table.size()) {
nt.setComplete(true);
}
// we add the footer rows if necessary (not for incomplete tables)
for (int j = 0; j < footerRows && nt.isComplete(); ++j) {
sub.add(rows.get(j + realHeaderRows));
}
// we need a correction if the last row needs to be extended
float rowHeight = 0;
if (table.isExtendLastRow()) {
PdfPRow last = (PdfPRow)sub.get(sub.size() - 1 - footerRows);
rowHeight = last.getMaxHeights();
last.setMaxHeights(yTemp - minY + rowHeight);
yTemp = minY;
}
// now we render the rows of the new table
if (canvases != null)
nt.writeSelectedRows(0, -1, x1, yLineWrite, canvases);
else
nt.writeSelectedRows(0, -1, x1, yLineWrite, canvas);
if (table.isExtendLastRow()) {
PdfPRow last = (PdfPRow)sub.get(sub.size() - 1 - footerRows);
last.setMaxHeights(rowHeight);
}
}
else if (table.isExtendLastRow() && minY > PdfPRow.BOTTOM_LIMIT) {
yTemp = minY;
}
yLine = yTemp;
if (!(skipHeader || table.isComplete())) {
yLine += footerHeight;
}
if (k >= table.size()) {
yLine -= table.spacingAfter();
compositeElements.removeFirst();
splittedRow = false;
listIdx = 0;
}
else {
if (splittedRow) {
ArrayList rows = table.getRows();
for (int i = listIdx; i < k; ++i)
rows.set(i, null);
}
listIdx = k;
return NO_MORE_COLUMN;
}
}
else if (element.type() == Element.YMARK) {
if (!simulate) {
DrawInterface zh = (DrawInterface)element;
zh.draw(canvas, leftX, minY, rightX, maxY, yLine);
}
compositeElements.removeFirst();
}
else
compositeElements.removeFirst();
}
}
|
public static boolean hasMoreText(int status) {
return (status & ColumnText.NO_MORE_TEXT) == 0;
}
Checks the status variable and looks if there's still some text. |
public boolean isAdjustFirstLine() {
return this.adjustFirstLine;
}
Gets the first line adjustment property. |
public boolean isUseAscender() {
return useAscender;
}
Checks if UseAscender is enabled/disabled. |
public ColumnText setACopy(ColumnText org) {
setSimpleVars(org);
if (org.bidiLine != null)
bidiLine = new BidiLine(org.bidiLine);
return this;
}
Makes this instance an independent copy of org. |
public void setAdjustFirstLine(boolean adjustFirstLine) {
this.adjustFirstLine = 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 is
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. |
public void setAlignment(int alignment) {
this.alignment = alignment;
}
|
public void setArabicOptions(int arabicOptions) {
this.arabicOptions = arabicOptions;
}
Sets the arabic shaping options. The option can be AR_NOVOWEL,
AR_COMPOSEDTASHKEEL and AR_LIG. |
public void setCanvas(PdfContentByte canvas) {
this.canvas = canvas;
this.canvases = null;
if (compositeColumn != null)
compositeColumn.setCanvas(canvas);
}
|
public void setCanvases(PdfContentByte[] canvases) {
this.canvases = canvases;
this.canvas = canvases[PdfPTable.TEXTCANVAS];
if (compositeColumn != null)
compositeColumn.setCanvases(canvases);
}
|
public void setColumns(float[] leftLine,
float[] rightLine) {
maxY = -10e20f;
minY = 10e20f;
rightWall = convertColumn(rightLine);
leftWall = convertColumn(leftLine);
rectangularWidth = -1;
rectangularMode = false;
}
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. |
public void setExtraParagraphSpace(float extraParagraphSpace) {
this.extraParagraphSpace = extraParagraphSpace;
}
Sets the extra space between paragraphs. |
public void setFilledWidth(float filledWidth) {
this.filledWidth = filledWidth;
}
Sets the real width used by the largest line. Only used to set it
to zero to start another measurement. |
public void setFollowingIndent(float indent) {
this.followingIndent = indent;
lastWasNewline = true;
}
Sets the following paragraph lines indent. |
public void setIndent(float indent) {
this.indent = indent;
lastWasNewline = true;
}
Sets the first paragraph line indent. |
public void setLeading(float leading) {
fixedLeading = leading;
multipliedLeading = 0;
}
Sets the leading to fixed |
public void setLeading(float fixedLeading,
float multipliedLeading) {
this.fixedLeading = fixedLeading;
this.multipliedLeading = 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. |
public void setRightIndent(float indent) {
this.rightIndent = indent;
lastWasNewline = true;
}
Sets the right paragraph lines indent. |
public void setRunDirection(int runDirection) {
if (runDirection < PdfWriter.RUN_DIRECTION_DEFAULT || runDirection > PdfWriter.RUN_DIRECTION_RTL)
throw new RuntimeException("Invalid run direction: " + runDirection);
this.runDirection = runDirection;
}
|
public void setSimpleColumn(float llx,
float lly,
float urx,
float ury) {
leftX = Math.min(llx, urx);
maxY = Math.max(lly, ury);
minY = Math.min(lly, ury);
rightX = Math.max(llx, urx);
yLine = maxY;
rectangularWidth = rightX - leftX;
if (rectangularWidth < 0)
rectangularWidth = 0;
rectangularMode = true;
}
Simplified method for rectangular columns. |
public void setSimpleColumn(float llx,
float lly,
float urx,
float ury,
float leading,
int alignment) {
setLeading(leading);
this.alignment = alignment;
setSimpleColumn(llx, lly, urx, ury);
}
Simplified method for rectangular columns. |
public void setSimpleColumn(Phrase phrase,
float llx,
float lly,
float urx,
float ury,
float leading,
int alignment) {
addText(phrase);
setSimpleColumn(llx, lly, urx, ury, leading, alignment);
}
Simplified method for rectangular columns. |
protected void setSimpleVars(ColumnText org) {
maxY = org.maxY;
minY = org.minY;
alignment = org.alignment;
leftWall = null;
if (org.leftWall != null)
leftWall = new ArrayList(org.leftWall);
rightWall = null;
if (org.rightWall != null)
rightWall = new ArrayList(org.rightWall);
yLine = org.yLine;
currentLeading = org.currentLeading;
fixedLeading = org.fixedLeading;
multipliedLeading = org.multipliedLeading;
canvas = org.canvas;
canvases = org.canvases;
lineStatus = org.lineStatus;
indent = org.indent;
followingIndent = org.followingIndent;
rightIndent = org.rightIndent;
extraParagraphSpace = org.extraParagraphSpace;
rectangularWidth = org.rectangularWidth;
rectangularMode = org.rectangularMode;
spaceCharRatio = org.spaceCharRatio;
lastWasNewline = org.lastWasNewline;
linesWritten = org.linesWritten;
arabicOptions = org.arabicOptions;
runDirection = org.runDirection;
descender = org.descender;
composite = org.composite;
splittedRow = org.splittedRow;
if (org.composite) {
compositeElements = new LinkedList(org.compositeElements);
if (splittedRow) {
PdfPTable table = (PdfPTable)compositeElements.getFirst();
compositeElements.set(0, new PdfPTable(table));
}
if (org.compositeColumn != null)
compositeColumn = duplicate(org.compositeColumn);
}
listIdx = org.listIdx;
firstLineY = org.firstLineY;
leftX = org.leftX;
rightX = org.rightX;
firstLineYDone = org.firstLineYDone;
waitPhrase = org.waitPhrase;
useAscender = org.useAscender;
filledWidth = org.filledWidth;
adjustFirstLine = org.adjustFirstLine;
}
|
public void setSpaceCharRatio(float spaceCharRatio) {
this.spaceCharRatio = 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. |
public void setText(Phrase phrase) {
bidiLine = null;
composite = false;
compositeColumn = null;
compositeElements = null;
listIdx = 0;
splittedRow = false;
waitPhrase = phrase;
}
Replaces the current text array with this Phrase.
Anything added previously with addElement() is lost. |
public void setUseAscender(boolean use) {
useAscender = use;
}
Enables/Disables adjustment of first line height based on max ascender. |
public void setYLine(float yLine) {
this.yLine = yLine;
}
Sets the yLine. The line will be written to yLine-leading. |
public static void showTextAligned(PdfContentByte canvas,
int alignment,
Phrase phrase,
float x,
float y,
float rotation) {
showTextAligned(canvas, alignment, phrase, x, y, rotation, PdfWriter.RUN_DIRECTION_NO_BIDI, 0);
}
Shows a line of text. Only the first line is written. |
public static void showTextAligned(PdfContentByte canvas,
int alignment,
Phrase phrase,
float x,
float y,
float rotation,
int runDirection,
int arabicOptions) {
if (alignment != Element.ALIGN_LEFT && alignment != Element.ALIGN_CENTER
&& alignment != Element.ALIGN_RIGHT)
alignment = Element.ALIGN_LEFT;
canvas.saveState();
ColumnText ct = new ColumnText(canvas);
if (rotation == 0) {
if (alignment == Element.ALIGN_LEFT)
ct.setSimpleColumn(phrase, x, y - 1, 20000 + x, y + 2, 2, alignment);
else if (alignment == Element.ALIGN_RIGHT)
ct.setSimpleColumn(phrase, x-20000, y-1, x, y+2, 2, alignment);
else
ct.setSimpleColumn(phrase, x-20000, y-1, x+20000, y+2, 2, alignment);
}
else {
double alpha = rotation * Math.PI / 180.0;
float cos = (float)Math.cos(alpha);
float sin = (float)Math.sin(alpha);
canvas.concatCTM(cos, sin, -sin, cos, x, y);
if (alignment == Element.ALIGN_LEFT)
ct.setSimpleColumn(phrase, 0, -1, 20000, 2, 2, alignment);
else if (alignment == Element.ALIGN_RIGHT)
ct.setSimpleColumn(phrase, -20000, -1, 0, 2, 2, alignment);
else
ct.setSimpleColumn(phrase, -20000, -1, 20000, 2, 2, alignment);
}
if (runDirection == PdfWriter.RUN_DIRECTION_RTL) {
if (alignment == Element.ALIGN_LEFT)
alignment = Element.ALIGN_RIGHT;
else if (alignment == Element.ALIGN_RIGHT)
alignment = Element.ALIGN_LEFT;
}
ct.setAlignment(alignment);
ct.setArabicOptions(arabicOptions);
ct.setRunDirection(runDirection);
try {
ct.go();
}
catch (DocumentException e) {
throw new ExceptionConverter(e);
}
canvas.restoreState();
}
Shows a line of text. Only the first line is written. |
public void updateFilledWidth(float w) {
if (w > filledWidth)
filledWidth = w;
}
Replaces the filledWidth if greater than the existing one. |
public boolean zeroHeightElement() {
return composite && !compositeElements.isEmpty() && ((Element)compositeElements.getFirst()).type() == Element.YMARK;
}
Checks if the element has a height of 0. |