Example usage for com.lowagie.text Chunk setFont

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

Introduction

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

Prototype

public void setFont(Font font) 

Source Link

Document

Sets the font of this Chunk.

Usage

From source file:fr.opensagres.odfdom.converter.pdf.internal.stylable.StylableAnchor.java

License:Open Source License

@SuppressWarnings("unchecked")
public Element getElement() {
    // underline font if not explicitly set
    ArrayList<Chunk> chunks = getChunks();
    for (Chunk chunk : chunks) {
        Font f = chunk.getFont();
        if (f != null && !f.isUnderlined()) {
            f = new Font(f);
            f.setStyle(f.getStyle() | Font.UNDERLINE);
            chunk.setFont(f);
        }/*from  w  ww  .j a va  2  s  .c  o m*/
    }
    return this;
}

From source file:fr.opensagres.odfdom.converter.pdf.internal.stylable.StylableHeading.java

License:Open Source License

private Chunk formatNumber(StyleListProperties listProperties, int value) {
    Chunk symbol = new Chunk("", getFont());

    StyleTextProperties textProperties = listProperties.getTextProperties();
    if (textProperties != null) {
        Font font = textProperties.getFont();
        if (font != null) {
            symbol.setFont(font);
        }//from w ww .  j  a  va2s  .c  o  m
    }

    StyleNumFormat numFormat = listProperties.getNumFormat();
    if (numFormat != null) {
        StringBuilder sbuf = new StringBuilder();

        // num-prefix
        String numPrefix = listProperties.getNumPrefix();
        if (numPrefix != null) {
            sbuf.append(numPrefix);
        }

        // number
        if (numFormat.isAlphabetical()) {
            sbuf.append(RomanAlphabetFactory.getString(value, numFormat.isLowercase()));
        } else if (numFormat.isRoman()) {
            sbuf.append(RomanNumberFactory.getString(value, numFormat.isLowercase()));
        } else {
            sbuf.append(value);
        }

        // num-suffix
        String numSuffix = listProperties.getNumSuffix();
        if (numSuffix != null) {
            sbuf.append(numSuffix);
        }

        symbol.append(sbuf.toString());
    }
    return symbol;
}

From source file:fr.opensagres.odfdom.converter.pdf.internal.stylable.StylableList.java

License:Open Source License

public void applyStyles(Style style) {
    this.lastStyleApplied = style;

    Map<Integer, StyleListProperties> listPropertiesMap = style.getListPropertiesMap();
    if (listPropertiesMap != null) {
        StyleListProperties listProperties = getListProperties(listPropertiesMap, listLevel);
        if (listProperties != null) {
            String bulletChar = listProperties.getBulletChar();
            if (bulletChar != null) {
                // list item label is a char
                Chunk symbol = new Chunk(bulletChar);

                StyleTextProperties textProperties = listProperties.getTextProperties();
                if (textProperties != null) {
                    Font font = textProperties.getFont();
                    if (font != null) {
                        symbol.setFont(font);
                    }/*from   ww w.j av  a 2  s  .  co m*/
                }

                super.setListSymbol(symbol);
            }

            Image image = listProperties.getImage();
            if (image != null) {
                // list item label is an image
                Float width = listProperties.getWidth();
                if (width != null) {
                    image.scaleAbsoluteWidth(width);
                }

                Float height = listProperties.getHeight();
                if (height != null) {
                    image.scaleAbsoluteHeight(height);
                }

                super.setListSymbol(new Chunk(image, 0.0f, 0.0f));
            }

            if (bulletChar == null && image == null) {
                // list item label is a number
                Chunk symbol = new Chunk("");

                StyleTextProperties textProperties = listProperties.getTextProperties();
                if (textProperties != null) {
                    Font font = textProperties.getFont();
                    if (font != null) {
                        symbol.setFont(font);
                    }
                }

                Integer startValue = listProperties.getStartValue();
                if (startValue != null) {
                    super.setFirst(startValue);
                }

                StyleNumFormat numFormat = listProperties.getNumFormat();
                if (numFormat != null) {
                    String numPrefix = listProperties.getNumPrefix();
                    if (numPrefix != null) {
                        super.setPreSymbol(numPrefix);
                        symbol = new Chunk(numPrefix, symbol.getFont());
                    }

                    String numSuffix = listProperties.getNumSuffix();
                    if (numSuffix != null) {
                        super.setPostSymbol(numSuffix);
                        symbol.append(numSuffix);
                    }

                    super.setNumbered(true);
                    super.setLettered(numFormat.isAlphabetical());
                    this.romanNumbered = numFormat.isRoman();
                    super.setLowercase(numFormat.isLowercase());
                }

                super.setListSymbol(symbol);
            }

            // set indentation, it is specified in different way by Open Office and MsWord
            Float marginLeft = listProperties.getMarginLeft();
            Float textIndent = listProperties.getTextIndent();
            Float spaceBefore = listProperties.getSpaceBefore();
            Float minLabelWidth = listProperties.getMinLabelWidth();
            if (marginLeft != null && textIndent != null) {
                // ODT generated by Open Office
                super.setIndentationLeft(Math.max(marginLeft + textIndent, 0.0f));
                super.setSymbolIndent(Math.max(-textIndent, 0.0f));
            } else if (spaceBefore != null && minLabelWidth != null) {
                // ODT generated by MsWord
                super.setIndentationLeft(Math.max(spaceBefore, 0.0f));
                super.setSymbolIndent(Math.max(minLabelWidth, 0.0f));
            }
        }
    }
}

From source file:jmemorize.core.io.PdfRtfBuilder.java

License:Open Source License

private static void writeCategoryHeader(Document doc, Category category) throws DocumentException {
    Chunk chunk = new Chunk(category.getPath());
    chunk.setFont(new Font(Font.HELVETICA, 12, Font.BOLD));

    Paragraph paragraph = new Paragraph(chunk);
    paragraph.setSpacingBefore(1f);//from w w w.  ja  va2s.c  o  m

    doc.add(paragraph);
}

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

License:Open Source License

protected Chunk createChunk(String text) {
    Chunk chunk = new Chunk(text);

    Font font = chunk.font();//w w w  . j av a  2 s  .c  o m
    font.setStyle(Font.NORMAL);
    font.setColor(Color.blue);

    chunk.setFont(font);

    return chunk;
}

From source file:org.displaytag.render.ItextTableWriter.java

License:Artistic License

/**
 * Makes chunk content bold./*from  w  ww.  ja v a  2s.c  o m*/
 * @param chunk The chunk whose content is to be rendered bold.
 * @param color The font color desired.
 */
private void setBoldStyle(Chunk chunk, Color color) {
    Font font = chunk.getFont();
    chunk.setFont(FontFactory.getFont(font.getFamilyname(), font.getSize(), Font.BOLD, color));
}

From source file:org.odftoolkit.odfdom.converter.internal.itext.stylable.StylableList.java

License:Open Source License

public void applyStyles(Style style) {
    this.lastStyleApplied = style;

    Map<Integer, StyleListProperties> listPropertiesMap = style.getListPropertiesMap();
    if (listPropertiesMap != null) {
        StyleListProperties listProperties = null;
        for (int i = listLevel; i >= 0 && listProperties == null; i--) {
            // find style for current or nearest lower list level
            listProperties = listPropertiesMap.get(i);
        }//from   w ww . java 2s  .com
        if (listProperties != null) {
            String bulletChar = listProperties.getBulletChar();
            if (bulletChar != null) {
                // list item label is a char
                Chunk symbol = new Chunk(bulletChar);

                StyleTextProperties textProperties = style.getTextProperties();
                if (textProperties != null) {
                    Font font = textProperties.getFont();
                    if (font != null) {
                        symbol.setFont(font);
                    }
                }

                super.setListSymbol(symbol);
            }

            Image image = listProperties.getImage();
            if (image != null) {
                // list item label is an image
                Float width = listProperties.getWidth();
                if (width != null) {
                    image.scaleAbsoluteWidth(width);
                }

                Float height = listProperties.getHeight();
                if (height != null) {
                    image.scaleAbsoluteHeight(height);
                }

                super.setListSymbol(new Chunk(image, 0.0f, 0.0f));
            }

            if (bulletChar == null && image == null) {
                // list item label is a number
                Chunk symbol = new Chunk("");

                StyleTextProperties textProperties = style.getTextProperties();
                if (textProperties != null) {
                    Font font = textProperties.getFont();
                    if (font != null) {
                        symbol.setFont(font);
                    }
                }

                Integer startValue = listProperties.getStartValue();
                if (startValue != null) {
                    super.setFirst(startValue);
                }

                String numPrefix = listProperties.getNumPrefix();
                if (numPrefix != null) {
                    super.setPreSymbol(numPrefix);
                    symbol = new Chunk(numPrefix, symbol.getFont());
                }

                String numSuffix = listProperties.getNumSuffix();
                if (numSuffix != null) {
                    super.setPostSymbol(numSuffix);
                    symbol.append(numSuffix);
                }

                StyleNumFormat numFormat = listProperties.getNumFormat();
                if (numFormat != null) {
                    super.setNumbered(true);
                    super.setLettered(numFormat.isAlphabetical());
                    this.romanNumbered = numFormat.isRoman();
                    super.setLowercase(numFormat.isLowercase());
                }

                super.setListSymbol(symbol);
            }

            Float marginLeft = listProperties.getMarginLeft();
            Float textIndent = listProperties.getTextIndent();
            if (marginLeft != null && textIndent != null) {
                super.setIndentationLeft(Math.max(marginLeft + textIndent, 0.0f));
                super.setSymbolIndent(Math.max(-textIndent, 0.0f));
                super.setAutoindent(false);
            }
        }
    }
}

From source file:org.tellervo.desktop.print.SeriesReport.java

License:Open Source License

private Chunk certaintyToNaturalString(String certainty) {
    Chunk c = new Chunk();

    if (certainty.equalsIgnoreCase("exact")) {
        c.append("in exactly ");
    } else if (certainty.equalsIgnoreCase("after")) {
        c.append("after ");
    } else if (certainty.equalsIgnoreCase("before")) {
        c.append("before ");
    } else {/*from w  w  w. ja  v  a  2 s . c om*/
        c.append("in " + certainty.toLowerCase() + " ");
    }

    c.setFont(bodyFont);
    return c;
}

From source file:textdisplay.TagFilter.java

License:Educational Community License

/**Apply a style (font) to a chunk of pdf text*/
private void styleChunk(Chunk c, styles s) {
    try {//from  ww  w  .  java2 s .c o  m

        BaseFont bf = BaseFont.createFont("/usr/Junicode.ttf", BaseFont.IDENTITY_H, BaseFont.EMBEDDED);
        BaseFont ita = BaseFont.createFont("/usr/Junicode-Italic.ttf", BaseFont.IDENTITY_H, BaseFont.EMBEDDED);
        BaseFont bol = BaseFont.createFont("/usr/Junicode-Italic.ttf", BaseFont.IDENTITY_H, BaseFont.EMBEDDED);
        if (bf.charExists(540)) {
            System.out.print("font cant do 540\n");
        }
        Font italic = new Font(ita, 12, Font.ITALIC);
        Font bold = new Font(bol, 12, Font.BOLD);
        Font underlined = new Font(bf, 12, Font.UNDERLINE);
        Font superscript = new Font(bf, 9, Font.NORMAL);

        if (s == styles.bold) {
            c.setFont(bold);
        }
        if (s == styles.italic) {
            c.setFont(italic);
        }
        if (s == styles.underlined) {
            c.setFont(underlined);
        }
        if (s == styles.superscript) {
            c.setTextRise(7.0f);
            c.setFont(superscript);

        }

        //wipe out that content

    } catch (DocumentException ex) {
        Logger.getLogger(TagFilter.class.getName()).log(Level.SEVERE, null, ex);
    } catch (IOException ex) {
        Logger.getLogger(TagFilter.class.getName()).log(Level.SEVERE, null, ex);
    }
}