Example usage for com.lowagie.text.pdf PdfTextArray PdfTextArray

List of usage examples for com.lowagie.text.pdf PdfTextArray PdfTextArray

Introduction

In this page you can find the example usage for com.lowagie.text.pdf PdfTextArray PdfTextArray.

Prototype

public PdfTextArray(String str) 

Source Link

Usage

From source file:org.eclipse.birt.report.engine.emitter.pdf.PDFPage.java

License:Open Source License

private void drawText(String text, float textX, float textY, FontInfo fontInfo, float characterSpacing,
        float wordSpacing, Color color, CSSValue align) {
    contentByte.saveState();//from   w  w w.  j a va2 s.co  m
    // start drawing the text content
    contentByte.beginText();
    if (null != color && !Color.BLACK.equals(color)) {
        contentByte.setColorFill(color);
        contentByte.setColorStroke(color);
    }
    BaseFont font = getBaseFont(fontInfo);
    float fontSize = fontInfo.getFontSize();
    try {
        contentByte.setFontAndSize(font, fontSize);
    } catch (IllegalArgumentException e) {
        logger.log(Level.WARNING, e.getMessage());
        // close to zero , increase by one MIN_FONT_SIZE step
        contentByte.setFontAndSize(font, MIN_FONT_SIZE * 2);
    }
    if (characterSpacing != 0) {
        contentByte.setCharacterSpacing(characterSpacing);
    }
    if (wordSpacing != 0) {
        contentByte.setWordSpacing(wordSpacing);
    }
    setTextMatrix(contentByte, fontInfo, textX, transformY(textY, 0, containerHeight));
    if ((font.getFontType() == BaseFont.FONT_TYPE_TTUNI) && IStyle.JUSTIFY_VALUE.equals(align)
            && wordSpacing > 0) {
        int idx = text.indexOf(' ');
        if (idx >= 0) {
            float spaceCorrection = -wordSpacing * 1000 / fontSize;
            PdfTextArray textArray = new PdfTextArray(text.substring(0, idx));
            int lastIdx = idx;
            while ((idx = text.indexOf(' ', lastIdx + 1)) >= 0) {
                textArray.add(spaceCorrection);
                textArray.add(text.substring(lastIdx, idx));
                lastIdx = idx;
            }
            textArray.add(spaceCorrection);
            textArray.add(text.substring(lastIdx));
            contentByte.showText(textArray);
        } else {
            contentByte.showText(text);
        }
    } else {
        contentByte.showText(text);
    }
    contentByte.endText();
    contentByte.restoreState();
}