in extensions/vw/tabular/pdf/src/main/java/org/apache/causeway/extensions/tabular/pdf/factory/internal/TableCell.java [207:341]
private float writeOrCalculateParagraph(final Paragraph paragraph, final boolean onlyCalculateHeight) throws IOException {
int boldCounter = 0;
int italicCounter = 0;
if (!onlyCalculateHeight) {
tableCellContentStream.setRotated(isTextRotated());
}
// position at top of current cell descending by font height - font
// descent, because we are positioning the base line here
float cursorY = yStart - getTopPadding() - FontUtils.getHeight(getFont(), getFontSize())
- FontUtils.getDescent(getFont(), getFontSize()) - (getTopBorderStyle() == null ? 0 : getTopBorderStyle().getWidth());
float cursorX = xStart;
// loop through tokens
for (Map.Entry<Integer, List<Token>> entry : paragraph.getMapLineTokens().entrySet()) {
// calculate the width of this line
float freeSpaceWithinLine = paragraph.getMaxLineWidth() - paragraph.getLineWidth(entry.getKey());
if (isTextRotated()) {
switch (align) {
case CENTER:
cursorY += freeSpaceWithinLine / 2;
break;
case LEFT:
break;
case RIGHT:
cursorY += freeSpaceWithinLine;
break;
}
} else {
switch (align) {
case CENTER:
cursorX += freeSpaceWithinLine / 2;
break;
case LEFT:
// it doesn't matter because X position is always the same
// as row above
break;
case RIGHT:
cursorX += freeSpaceWithinLine;
break;
}
}
// iterate through tokens in current line
PDFont currentFont = paragraph.getFont(false, false);
for (Token token : entry.getValue()) {
switch (token.type()) {
case OPEN_TAG:
if ("b".equals(token.text())) {
boldCounter++;
} else if ("i".equals(token.text())) {
italicCounter++;
}
break;
case CLOSE_TAG:
if ("b".equals(token.text())) {
boldCounter = Math.max(boldCounter - 1, 0);
} else if ("i".equals(token.text())) {
italicCounter = Math.max(italicCounter - 1, 0);
}
break;
case PADDING:
cursorX += Float.parseFloat(token.text());
break;
case ORDERING:
currentFont = paragraph.getFont(boldCounter > 0, italicCounter > 0);
tableCellContentStream.setFont(currentFont, getFontSize());
if (isTextRotated()) {
// if it is not calculation then draw it
if (!onlyCalculateHeight) {
tableCellContentStream.newLineAt(cursorX, cursorY);
tableCellContentStream.showText(token.text());
}
cursorY += token.getWidth(currentFont) / 1000 * getFontSize();
} else {
// if it is not calculation then draw it
if (!onlyCalculateHeight) {
tableCellContentStream.newLineAt(cursorX, cursorY);
tableCellContentStream.showText(token.text());
}
cursorX += token.getWidth(currentFont) / 1000 * getFontSize();
}
break;
case BULLET:
float widthOfSpace = currentFont.getSpaceWidth();
float halfHeight = FontUtils.getHeight(currentFont, getFontSize()) / 2;
if (isTextRotated()) {
if (!onlyCalculateHeight) {
PDStreamUtils.rect(tableCellContentStream, cursorX + halfHeight, cursorY,
token.getWidth(currentFont) / 1000 * getFontSize(),
widthOfSpace / 1000 * getFontSize(), getTextColor());
}
// move cursorY for two characters (one for bullet, one
// for space after bullet)
cursorY += 2 * widthOfSpace / 1000 * getFontSize();
} else {
if (!onlyCalculateHeight) {
PDStreamUtils.rect(tableCellContentStream, cursorX, cursorY + halfHeight,
token.getWidth(currentFont) / 1000 * getFontSize(),
widthOfSpace / 1000 * getFontSize(), getTextColor());
}
// move cursorX for two characters (one for bullet, one
// for space after bullet)
cursorX += 2 * widthOfSpace / 1000 * getFontSize();
}
break;
case TEXT:
currentFont = paragraph.getFont(boldCounter > 0, italicCounter > 0);
tableCellContentStream.setFont(currentFont, getFontSize());
if (isTextRotated()) {
if (!onlyCalculateHeight) {
tableCellContentStream.newLineAt(cursorX, cursorY);
tableCellContentStream.showText(token.text());
}
cursorY += token.getWidth(currentFont) / 1000 * getFontSize();
} else {
if (!onlyCalculateHeight) {
tableCellContentStream.newLineAt(cursorX, cursorY);
tableCellContentStream.showText(token.text());
}
cursorX += token.getWidth(currentFont) / 1000 * getFontSize();
}
break;
case POSSIBLE_WRAP_POINT, WRAP_POINT:
break;
}
}
// reset
cursorX = xStart;
cursorY -= FontUtils.getHeight(getFont(), getFontSize());
}
return cursorY;
}