Example usage for com.lowagie.text Font size

List of usage examples for com.lowagie.text Font size

Introduction

In this page you can find the example usage for com.lowagie.text Font size.

Prototype

float size

To view the source code for com.lowagie.text Font size.

Click Source Link

Document

the value of the fontsize.

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  va  2 s .  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;
}

From source file:is.idega.idegaweb.egov.printing.business.DocumentBusinessBean.java

License:Open Source License

public void createHeaderDate(Document document, PdfWriter writer, String dateString) throws DocumentException {
    /*/*from   www  .  j a v  a  2  s. c  o  m*/
     * final PdfPTable header = new PdfPTable(new float[]{1}); header.setWidthPercentage(100f); final PdfPCell defaultCell = header.getDefaultCell();
     * defaultCell.setBorder(0); //defaultCell.setFixedHeight(getPointsFromMM(40)); defaultCell.setPadding(0); defaultCell.setNoWrap(true);
     * defaultCell.setVerticalAlignment(align); header.addCell(new Phrase(new Chunk(dateString, getDefaultParagraphFont()))); document.add(header);
     */
    PdfContentByte cb = writer.getDirectContent();
    cb.beginText();
    Font font = getDefaultParagraphFont();

    try {
        BaseFont bf = BaseFont.createFont(font.getFamilyname(), BaseFont.CP1252, BaseFont.NOT_EMBEDDED);
        cb.setFontAndSize(bf, font.size());
        // we show some text starting on some absolute position with a given
        // alignment
        cb.showTextAligned(PdfContentByte.ALIGN_RIGHT, dateString, getPointsFromMM(210 - 20),
                getPointsFromMM(297 - 20), 0);
        cb.endText();
    }

    catch (IOException e) {
        e.printStackTrace();
    }
}

From source file:is.idega.idegaweb.egov.printing.business.DocumentBusinessBean.java

License:Open Source License

private String encodeFont(Font font) {
    StringBuffer fontBuffer = new StringBuffer();
    fontBuffer.append(font.getFamilyname()).append("-");
    fontBuffer.append(font.size()).append("-");
    fontBuffer.append(encodeFontStyle(font)).append("-");
    if (font.color() != null) {
        fontBuffer.append(IWColor.getHexColorString(font.color()));
    }/*from  w  w w .j a  v  a2 s  .  co  m*/
    return fontBuffer.toString();
}

From source file:org.areasy.common.doclet.document.elements.LinkPhrase.java

License:Open Source License

/**
 * Creates a hyperlink chunk./*  w  w w  . j av  a2  s. com*/
 *
 * @param destination The original destination as defined
 *                    in the javadoc.
 * @param label       The text label for the link
 * @param font        The base font for the link (for example, could be
 *                    a bold italic font in case of a "deprecated" tag).
 */
public LinkPhrase(String destination, String label, Font font) {
    super("");

    Font newFont = null;
    float size = font.size();

    if (size == 0)
        size = 9;

    if (!DefaultConfiguration.isLinksCreationActive())
        destination = "";

    destination = normalizeDestination(destination);

    if (Destinations.isValid(destination)) {
        if (font.family() == Font.TIMES_ROMAN)
            newFont = Fonts.getFont(TEXT_FONT, LINK, (int) size);
        else
            newFont = Fonts.getFont(CODE_FONT, LINK, (int) size);
    } else if (font.family() == Font.TIMES_ROMAN)
        newFont = Fonts.getFont(TEXT_FONT, (int) size);
    else
        newFont = Fonts.getFont(CODE_FONT, (int) size);

    init(destination, label, newFont);
}

From source file:org.areasy.common.doclet.document.tags.HtmlTag.java

License:Open Source License

/**
 * Returns the leading for this type of HTML tag
 * in the PDF document. For most tags it's just
 * about the font size./*  w w w .  ja v  a 2 s . co  m*/
 *
 * @return The leading for this tag.
 */
public float getLeading() {
    Font font = getFont();
    float leading = (float) font.size() + (float) 1.0;

    return leading;
}