Example usage for com.itextpdf.text Chunk setTextRise

List of usage examples for com.itextpdf.text Chunk setTextRise

Introduction

In this page you can find the example usage for com.itextpdf.text Chunk setTextRise.

Prototype


public Chunk setTextRise(final float rise) 

Source Link

Document

Sets the text displacement relative to the baseline.

Usage

From source file:be.roots.taconic.pricingguide.service.PDFServiceImpl.java

License:Open Source License

private Phrase processHtmlCodes(String name, Font baseFont, Font symbol) {

    final Font italicFont = new Font(baseFont);
    italicFont.setStyle(Font.FontStyle.ITALIC.getValue());

    final Font normalFont = new Font(baseFont);

    Font usedFont = normalFont;/* www  .  j a v  a  2s.c o  m*/

    final Phrase phrase = new Phrase();

    if (!StringUtils.isEmpty(name)) {

        for (String[] alphabet : GreekAlphabet.getAlphabet()) {
            name = name.replaceAll(alphabet[0], DELIMETER + alphabet[0] + DELIMETER);
        }
        name = name.replaceAll("<sup>|<SUP>", DELIMETER + "<sup>");
        name = name.replaceAll("</sup>|</SUP>", DELIMETER);
        name = name.replaceAll("<i>|<I>|<em>|<EM>", DELIMETER + "<i>");
        name = name.replaceAll("</i>|</I>|</em>|</EM>", DELIMETER + "</i>");

        final String[] tokens = name.split(DELIMETER);
        for (String token : tokens) {

            String text = token;
            if (text.startsWith("<i>")) {
                usedFont = italicFont;
                text = text.substring(3);
            } else if (text.startsWith("</i>")) {
                usedFont = normalFont;
                text = text.substring(4);
            }

            usedFont.setSize(baseFont.getSize());

            if (text.startsWith("&")) {
                final char replacement = GreekAlphabet.getReplacement(text);
                if (!Character.isWhitespace(replacement)) {
                    phrase.add(SpecialSymbol.get(replacement, symbol));
                } else {
                    phrase.add(new Chunk(text, usedFont));
                }
            } else if (text.startsWith("<sup>")) {

                final Font superScriptFont = new Font(usedFont);
                superScriptFont.setSize(baseFont.getSize() - 1.5f);

                final Chunk superScript = new Chunk(text.substring(5), superScriptFont);
                superScript.setTextRise(4f);
                phrase.add(superScript);

            } else {
                phrase.add(new Chunk(text, usedFont));
            }

        }
    }

    return phrase;
}

From source file:jdbreport.model.io.pdf.itext5.PdfWriter.java

License:Apache License

protected void writeHTMLText(CellStyle parentStyle, jdbreport.model.Cell cell, PdfPCell pdfCell) {
    if (cell.isNull() || cell.isChild())
        return;//from   w w  w  . j  av  a  2 s. c o m

    JTextComponent tc = getHTMLReportRenderer();
    tc.setText(cell.getText());
    List<Content> contentList = Content.getHTMLContentList((HTMLDocument) tc.getDocument());
    if (contentList != null) {
        Phrase phrase = new Phrase();
        for (Content content : contentList) {
            CellStyle newStyle = content.createTextStyle(parentStyle, parentStyle);
            if (newStyle == null) {
                newStyle = parentStyle;
            }
            if (newStyle != null) {
                if (newStyle.getTypeOffset() == CellStyle.SS_SUPER
                        || newStyle.getTypeOffset() == CellStyle.SS_SUB) {
                    newStyle = newStyle.deriveFont((float) newStyle.getSize() / 2);
                }
                int i = textStyles.indexOf(newStyle);
                if (i < 0) {
                    textStyles.add(newStyle);
                    i = textStyles.size() - 1;
                }
                Font font;
                String styleId = "T" + (i + 1);
                if (fonts.containsKey(styleId)) {
                    font = fonts.get(styleId);
                } else {
                    font = getFontMapper().styleToPdf(newStyle);
                    fonts.put(styleId, font);
                }
                Chunk chunk = new Chunk(content.getText(), font);
                chunk.setBackground(new BaseColor(newStyle.getBackground().getRGB()));
                if (newStyle.getTypeOffset() == CellStyle.SS_SUPER) {
                    chunk.setTextRise(newStyle.getSize() / 2);
                } else if (newStyle.getTypeOffset() == CellStyle.SS_SUB) {
                    chunk.setTextRise(-newStyle.getSize() / 2);
                }
                phrase.add(chunk);
            } else {
                phrase.add(new Chunk(content.getText()));
            }
        }
        pdfCell.setPhrase(phrase);
    }
}

From source file:se.billes.pdf.renderer.model.text.Phrase.java

License:Open Source License

public void onRender(com.itextpdf.text.Paragraph paragraph) {
    Font font = new Font(getBaseFont(), getFontSize());
    font.setColor(getBaseColor());//from   w w w  . j  a v a 2  s.  com
    if (getStyle() != null)
        font.setStyle(getStyle());
    String text = getText();
    if (text.length() == 0)
        text = " ";
    text = text.replace("&gt;", ">");
    text = text.replace("&lt;", "<");

    Chunk chunk = new Chunk(text, font);
    if (getParagraph().getHyphenationAuto() != null) {
        chunk.setHyphenation(getParagraph().getHyphenationAuto());
    }
    chunk.setTextRise(getTextRise());
    chunk.setSkew(getSkewAlpha(), getSkewBeta());
    paragraph.add(chunk);
}