Example usage for com.itextpdf.text Font isItalic

List of usage examples for com.itextpdf.text Font isItalic

Introduction

In this page you can find the example usage for com.itextpdf.text Font isItalic.

Prototype

public boolean isItalic() 

Source Link

Document

checks if this font is italic.

Usage

From source file:adams.core.io.PdfFont.java

License:Open Source License

/**
 * Generates a list of font style names from the given font setup.
 *
 * @param font   the font to analyze// ww  w.j a v  a  2s  . c om
 * @return      the list of font names
 */
public static String[] getFontFaces(Font font) {
    List<String> result;

    result = new ArrayList<String>();
    if (font.isBold())
        result.add(BOLD);
    if (font.isItalic())
        result.add(ITALIC);
    if (font.isStrikethru())
        result.add(STRIKETHRU);
    if (font.isUnderlined())
        result.add(UNDERLINE);
    if (result.size() == 0)
        result.add(NORMAL);

    return result.toArray(new String[result.size()]);
}

From source file:fenix.planner.pdf.PDFGenerator.java

License:Open Source License

private void parseAndAddBodyTextLineToParagraph(Paragraph paragraph, String line, Font font) {
    // TODO add support for additional styles
    // TODO add better error checking and reporting
    Font currentFont = new Font(font);
    StringBuilder sb = new StringBuilder();
    for (char c : line.toCharArray()) {
        if (c == '*') {
            if (sb.length() > 0) {
                paragraph.add(new Phrase(sb.toString(), currentFont));
                sb = new StringBuilder();
            }//from w ww  . j a  v a2 s . c  om
            if (currentFont.isBold()) {
                currentFont = deriveWithStyle(currentFont, currentFont.getStyle() & ~Font.BOLD);
            } else {
                currentFont = deriveWithStyle(currentFont, currentFont.getStyle() | Font.BOLD);
            }
        } else if (c == '_') {
            if (sb.length() > 0) {
                paragraph.add(new Phrase(sb.toString(), currentFont));
                sb = new StringBuilder();
            }
            if (currentFont.isItalic()) {
                currentFont = deriveWithStyle(currentFont, currentFont.getStyle() & ~Font.ITALIC);
            } else {
                currentFont = deriveWithStyle(currentFont, currentFont.getStyle() | Font.ITALIC);
            }
        } else {
            sb.append(c);
        }
    }
    paragraph.add(new Phrase(sb.toString(), currentFont));
}