Example usage for com.itextpdf.text SpecialSymbol get

List of usage examples for com.itextpdf.text SpecialSymbol get

Introduction

In this page you can find the example usage for com.itextpdf.text SpecialSymbol get.

Prototype

public static Chunk get(char c, Font font) 

Source Link

Document

Gets a chunk with a symbol character.

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;//from   www. ja va2s .  com

    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;
}