ptext = text; //fixed by Kazuya Ujihara (ujihara.jp)
BaseFont ufont = getRealFont();
Color fcolor = (textColor == null) ? GrayColor.GRAYBLACK : textColor;
int rtl = checkRTL(ptext) ? PdfWriter.RUN_DIRECTION_LTR : PdfWriter.RUN_DIRECTION_NO_BIDI;
float usize = fontSize;
LwgPhrase phrase = composePhrase(ptext, ufont, fcolor, usize);
if ((options & MULTILINE) != 0) {
float width = box.getWidth() - 4 * offsetX - extraMarginLeft;
float factor = ufont.getFontDescriptor(BaseFont.BBOXURY, 1) - ufont.getFontDescriptor(BaseFont.BBOXLLY, 1);
ColumnText ct = new ColumnText(null);
if (usize == 0) {
usize = h / factor;
if (usize > 4) {
if (usize > 12)
usize = 12;
float step = Math.max((usize - 4) / 10, 0.2f);
ct.setSimpleColumn(0, -h, width, 0);
ct.setAlignment(alignment);
ct.setRunDirection(rtl);
for (; usize > 4; usize -= step) {
ct.setYLine(0);
changeFontSize(phrase, usize);
ct.setText(phrase);
ct.setLeading(factor * usize);
int status = ct.go(true);
if ((status & ColumnText.NO_MORE_COLUMN) == 0)
break;
}
}
if (usize < 4)
usize = 4;
}
changeFontSize(phrase, usize);
ct.setCanvas(app);
float leading = usize * factor;
float offsetY = offsetX + h - ufont.getFontDescriptor(BaseFont.BBOXURY, usize);
ct.setSimpleColumn(extraMarginLeft + 2 * offsetX, -20000, box.getWidth() - 2 * offsetX, offsetY + leading);
ct.setLeading(leading);
ct.setAlignment(alignment);
ct.setRunDirection(rtl);
ct.setText(phrase);
ct.go();
}
else {
if (usize == 0) {
float maxCalculatedSize = h / (ufont.getFontDescriptor(BaseFont.BBOXURX, 1) - ufont.getFontDescriptor(BaseFont.BBOXLLY, 1));
changeFontSize(phrase, 1);
float wd = ColumnText.getWidth(phrase, rtl, 0);
if (wd == 0)
usize = maxCalculatedSize;
else
usize = Math.min(maxCalculatedSize, (box.getWidth() - extraMarginLeft - 4 * offsetX) / wd);
if (usize < 4)
usize = 4;
}
changeFontSize(phrase, usize);
float offsetY = offX + ((box.getHeight() - 2*offX) - ufont.getFontDescriptor(BaseFont.ASCENT, usize)) / 2;
if (offsetY < offX)
offsetY = offX;
if (offsetY - offX < -ufont.getFontDescriptor(BaseFont.DESCENT, usize)) {
float ny = -ufont.getFontDescriptor(BaseFont.DESCENT, usize) + offX;
float dy = box.getHeight() - offX - ufont.getFontDescriptor(BaseFont.ASCENT, usize);
offsetY = Math.min(ny, Math.max(offsetY, dy));
}
if ((options & COMB) != 0 && maxCharacterLength > 0) {
int textLen = Math.min(maxCharacterLength, ptext.length());
int position = 0;
if (alignment == LwgElement.ALIGN_RIGHT)
position = maxCharacterLength - textLen;
else if (alignment == LwgElement.ALIGN_CENTER)
position = (maxCharacterLength - textLen) / 2;
float step = (box.getWidth() - extraMarginLeft) / maxCharacterLength;
float start = step / 2 + position * step;
if (textColor == null)
app.setGrayFill(0);
else
app.setColorFill(textColor);
app.beginText();
for (int k = 0; k < phrase.size(); ++k) {
Chunk ck = (Chunk)phrase.get(k);
BaseFont bf = ck.getFont().getBaseFont();
app.setFontAndSize(bf, usize);
StringBuffer sb = ck.append("");
for (int j = 0; j < sb.length(); ++j) {
String c = sb.substring(j, j + 1);