Example usage for com.lowagie.text Chunk setHyphenation

List of usage examples for com.lowagie.text Chunk setHyphenation

Introduction

In this page you can find the example usage for com.lowagie.text Chunk setHyphenation.

Prototype

public Chunk setHyphenation(HyphenationEvent hyphenation) 

Source Link

Document

sets the hyphenation engine to this Chunk.

Usage

From source file:ambit.data.qmrf.Qmrf_Xml_Pdf.java

License:Open Source License

protected int getText(org.w3c.dom.Node node, Phrase phrase, Font currentFont, ScriptMode scriptMode,
        boolean trim, int paragraphs) {

    if (node.getNodeType() == node.ELEMENT_NODE) {
        if ("head".equals(node.getNodeName()))
            return paragraphs;
        if ("html".equals(node.getNodeName()))
            trim = true;/* w  ww.  j  a  v a 2s  . co m*/
        else if ("body".equals(node.getNodeName()))
            trim = true;
        else if ("p".equals(node.getNodeName()))
            trim = true;
        else
            trim = false;
        //if ("p".equals(node.getNodeName())) trim=true;
        //           System.out.println(node.getNodeName() + ' ' + trim);   
        //System.out.println(paragraphs);   
        Font f = currentFont;
        int fweight = currentFont.style();
        float fsize = currentFont.size();
        Color clr = currentFont.color();
        boolean modify = false;
        if ("b".equals(node.getNodeName())) {
            if ((currentFont.style() == Font.ITALIC) || (currentFont.style() == Font.BOLDITALIC))
                fweight = Font.BOLDITALIC;
            else
                fweight = Font.BOLD;
            modify = true;
        }
        if ("i".equals(node.getNodeName())) {
            if ((currentFont.style() == Font.BOLD) || (currentFont.style() == Font.BOLDITALIC))
                fweight = Font.BOLDITALIC;
            else
                fweight = Font.ITALIC;
            modify = true;
        }
        if ("sub".equals(node.getNodeName())) {
            scriptMode = ScriptMode.subscript;
        }
        if ("sup".equals(node.getNodeName())) {
            scriptMode = ScriptMode.superscript;
        }
        if ("font".equals(node.getNodeName())) {
            String r = ((org.w3c.dom.Element) node).getAttribute("color");
            if (r != null)
                try {
                    clr = Hex2Color(r.substring(1));
                    modify = true;
                } catch (Exception x) {
                    clr = currentFont.color();
                }
            String z = ((org.w3c.dom.Element) node).getAttribute("size");
            if (z != null) {
                try {
                    fsize = Integer.parseInt(z);
                    modify = true;
                } catch (Exception x) {
                    fsize = currentFont.size();
                }
            }
        }
        if (modify) {
            f = FontFactory.getFont(currentFont.getFamilyname(), fsize, fweight, clr);
        }
        if ("p".equals(node.getNodeName())) {
            if (paragraphs > 0)
                phrase.add(new Chunk('\n', f));
            paragraphs++;

        }

        //f = FontFactory.getFont(currentFont.getFamilyname(),curr)
        NodeList nodes = node.getChildNodes();
        for (int i = 0; i < nodes.getLength(); i++)
            paragraphs += getText(nodes.item(i), phrase, f, scriptMode, trim, paragraphs);

    } else if (node.getNodeType() == node.TEXT_NODE) {

        String value = node.getNodeValue();
        if (trim)
            value = replaceNewLine(value);
        if ("".equals(value))
            return paragraphs;
        //System.out.println(value);
        Chunk chunk = new Chunk(value, currentFont);
        HyphenationAuto autoEN = new HyphenationAuto("en", "GB", 2, 2);
        chunk.setHyphenation(autoEN);
        switch (scriptMode) {
        case superscript:
            chunk.setTextRise(currentFont.size() * 0.3f);
            break;
        case subscript:
            chunk.setTextRise(-currentFont.size() * 0.3f);
            break;

        default:
            break;
        }
        phrase.add(chunk);
    }
    return paragraphs;
}