*/
public void exportText(JRPrintText text) throws IOException, JRException {
// use styled text
JRStyledText styledText = getStyledText(text);
if (styledText == null)
{
return;
}
int width = text.getWidth();
int height = text.getHeight();
int textHeight = (int)text.getTextHeight();
if(textHeight <= 0) {
if(height <= 0 ){
throw new JRException("Invalid text height");
}
textHeight = height;
}
/* */
startElement(text);
// padding for the text
int topPadding = text.getLineBox().getTopPadding().intValue();
int leftPadding = text.getLineBox().getLeftPadding().intValue();
int bottomPadding = text.getLineBox().getBottomPadding().intValue();
int rightPadding = text.getLineBox().getRightPadding().intValue();
String rotation = null;
switch (text.getRotationValue())
{
case LEFT :
{
switch (text.getVerticalAlignmentValue())
{
case TOP:
{
break;
}
case MIDDLE:
{
leftPadding = Math.max(leftPadding, (width - rightPadding - textHeight) / 2);
break;
}
case BOTTOM:
{
leftPadding = Math.max(leftPadding, width - rightPadding - textHeight);
break;
}
}
rotation = "{\\sp{\\sn txflTextFlow}{\\sv 2}}";
break;
}
case RIGHT :
{
switch (text.getVerticalAlignmentValue())
{
case TOP:
{
break;
}
case MIDDLE:
{
rightPadding = Math.max(rightPadding, (width - leftPadding - textHeight) / 2);
break;
}
case BOTTOM:
{
rightPadding = Math.max(rightPadding, width - leftPadding - textHeight);
break;
}
}
rotation = "{\\sp{\\sn txflTextFlow}{\\sv 3}}";
break;
}
case UPSIDE_DOWN :
{
switch (text.getVerticalAlignmentValue())
{
case TOP:
{
topPadding = Math.max(topPadding, height - bottomPadding - textHeight);
break;
}
case MIDDLE:
{
topPadding = Math.max(topPadding, (height - bottomPadding - textHeight) / 2);
break;
}
case BOTTOM:
{
break;
}
}
rotation = "";
break;
}
case NONE :
default :
{
switch (text.getVerticalAlignmentValue())
{
case TOP:
{
break;
}
case MIDDLE:
{
topPadding = Math.max(topPadding, (height - bottomPadding - textHeight) / 2);
break;
}
case BOTTOM:
{
topPadding = Math.max(topPadding, height - bottomPadding - textHeight);
break;
}
}
rotation = "";
}
}
writer.write(rotation);
writer.write("{\\sp{\\sn dyTextTop}{\\sv ");
writer.write(String.valueOf(LengthUtil.emu(topPadding)));
writer.write("}}");
writer.write("{\\sp{\\sn dxTextLeft}{\\sv ");
writer.write(String.valueOf(LengthUtil.emu(leftPadding)));
writer.write("}}");
writer.write("{\\sp{\\sn dyTextBottom}{\\sv ");
writer.write(String.valueOf(LengthUtil.emu(bottomPadding)));
writer.write("}}");
writer.write("{\\sp{\\sn dxTextRight}{\\sv ");
writer.write(String.valueOf(LengthUtil.emu(rightPadding)));
writer.write("}}");
writer.write("{\\sp{\\sn fLine}{\\sv 0}}");
writer.write("{\\shptxt{\\pard ");
writer.write("\\fi" + LengthUtil.twip(text.getParagraph().getFirstLineIndent().intValue()) + " ");
writer.write("\\li" + LengthUtil.twip(text.getParagraph().getLeftIndent().intValue()) + " ");
writer.write("\\ri" + LengthUtil.twip(text.getParagraph().getRightIndent().intValue()) + " ");
writer.write("\\sb" + LengthUtil.twip(text.getParagraph().getSpacingBefore().intValue()) + " ");
writer.write("\\sa" + LengthUtil.twip(text.getParagraph().getSpacingAfter().intValue()) + " ");
TabStop[] tabStops = text.getParagraph().getTabStops();
if (tabStops != null && tabStops.length > 0)
{
for (int i = 0; i < tabStops.length; i++)
{
TabStop tabStop = tabStops[i];
String tabStopAlign = "";
switch (tabStop.getAlignment())
{
case CENTER:
tabStopAlign = "\\tqc";
break;
case RIGHT:
tabStopAlign = "\\tqr";
break;
case LEFT:
default:
tabStopAlign = "";
break;
}
writer.write(tabStopAlign + "\\tx" + LengthUtil.twip(tabStop.getPosition()) + " ");
}
}
JRFont font = text;
if (text.getRunDirectionValue() == RunDirectionEnum.RTL)
{
writer.write("\\rtlch");
}
// writer.write("\\f");
// writer.write(String.valueOf(getFontIndex(font)));
// writer.write("\\cf");
// writer.write(String.valueOf(getColorIndex(text.getForecolor())));
writer.write("\\cb");
writer.write(String.valueOf(getColorIndex(text.getBackcolor())));
writer.write(" ");
// if (font.isBold())
// writer.write("\\b");
// if (font.isItalic())
// writer.write("\\i");
// if (font.isStrikeThrough())
// writer.write("\\strike");
// if (font.isUnderline())
// writer.write("\\ul");
// writer.write("\\fs");
// writer.write(String.valueOf(font.getFontSize() * 2));
switch (text.getHorizontalAlignmentValue())
{
case LEFT:
writer.write("\\ql");
break;
case CENTER:
writer.write("\\qc");
break;
case RIGHT:
writer.write("\\qr");
break;
case JUSTIFIED:
writer.write("\\qj");
break;
default:
writer.write("\\ql");
break;
}
switch (text.getParagraph().getLineSpacing())
{
case AT_LEAST:
{
writer.write("\\sl" + LengthUtil.twip(text.getParagraph().getLineSpacingSize().floatValue()));
writer.write(" \\slmult0 ");
break;
}
case FIXED:
{
writer.write("\\sl-" + LengthUtil.twip(text.getParagraph().getLineSpacingSize().floatValue()));
writer.write(" \\slmult0 ");
break;
}
case PROPORTIONAL:
{
writer.write("\\sl" + (int)(text.getParagraph().getLineSpacingSize().floatValue() * LINE_SPACING_FACTOR));
writer.write(" \\slmult1 ");
break;
}
case DOUBLE:
{
writer.write("\\sl" + (int)(2f * LINE_SPACING_FACTOR));
writer.write(" \\slmult1 ");
break;
}
case ONE_AND_HALF:
{
writer.write("\\sl" + (int)(1.5f * LINE_SPACING_FACTOR));
writer.write(" \\slmult1 ");
break;
}
case SINGLE:
default:
{
writer.write("\\sl" + (int)(1f * LINE_SPACING_FACTOR));
writer.write(" \\slmult1 ");
break;
}
}
if (text.getAnchorName() != null)
{
writeAnchor(text.getAnchorName());
}
exportHyperlink(text);
// add parameters in case of styled text element
String plainText = styledText.getText();
int runLimit = 0;
AttributedCharacterIterator iterator = styledText.getAttributedString().getIterator();
while (
runLimit < styledText.length()
&& (runLimit = iterator.getRunLimit()) <= styledText.length()
)
{
Map styledTextAttributes = iterator.getAttributes();
JRFont styleFont = new JRBaseFont(styledTextAttributes);