Example usage for com.lowagie.text FontFactory getFont

List of usage examples for com.lowagie.text FontFactory getFont

Introduction

In this page you can find the example usage for com.lowagie.text FontFactory getFont.

Prototype


public static Font getFont(String fontname, String encoding, float size, int style, Color color) 

Source Link

Document

Constructs a Font-object.

Usage

From source file:be.fedict.eid.tsl.Tsl2PdfExporter.java

License:Open Source License

public Tsl2PdfExporter() {
    initializeFontResources();//from   ww w .j  a va 2s  .  co m
    title0Font = FontFactory.getFont("DejaVuSerifCondensed-Bold", BaseFont.IDENTITY_H, true, 30, Font.BOLD);
    title1Font = FontFactory.getFont("DejaVuSerifCondensed-BoldItalic", BaseFont.IDENTITY_H, true, 16,
            Font.BOLD | Font.ITALIC);
    title2Font = FontFactory.getFont("DejaVuSerifCondensed-BoldItalic", BaseFont.IDENTITY_H, true, 16,
            Font.BOLD | Font.ITALIC);
    title3Font = FontFactory.getFont("DejaVuSerifCondensed-Italic", BaseFont.IDENTITY_H, true, 16, Font.ITALIC);
    title4Font = FontFactory.getFont("DejaVuSerifCondensed-Italic", BaseFont.IDENTITY_H, true, 12, Font.BOLD);
    labelFont = FontFactory.getFont("DejaVuSerifCondensed-Italic", BaseFont.IDENTITY_H, true, 11, Font.ITALIC);
    valueFont = FontFactory.getFont("DejaVuSerifCondensed", BaseFont.IDENTITY_H, true, 11, Font.NORMAL);
    monoFont = FontFactory.getFont("DejaVuSansMono", BaseFont.IDENTITY_H, true, 5, Font.NORMAL);
    headerFooterFont = FontFactory.getFont("DejaVuSerifCondensed", BaseFont.IDENTITY_H, true, 10, Font.NORMAL);
}

From source file:com.amphisoft.epub2pdf.content.TextFactory.java

License:Open Source License

public Paragraph newHeadline(int i) {
    if (i < 1) {
        i = 1;/*w  w w .j  a v  a 2 s .c om*/
    }
    if (i > 6) {
        i = 6;
    }
    Font hFont = FontFactory.getFont(_defaultFont.getFamilyname(), FontFactory.defaultEncoding,
            BaseFont.EMBEDDED, baseFontSize * HMULTS[i - 1], Font.BOLD);
    Paragraph h = new Paragraph();
    h.setAlignment(ITAlignment.CENTER.value);
    h.setFont(hFont);
    currentFont = hFont;
    h.setLeading(0F, getCurrentLeadingMultiplier());
    h.setSpacingAfter(_defaultFont.getSize() * 0.33F);
    currentParagraph = h;
    return h;
}

From source file:de.unigoettingen.sub.commons.contentlib.pdflib.PDFTitlePage.java

License:Apache License

/************************************************************************************
 * render paragraph into title page//from   w  w w .j  a  va 2s. c o m
 * 
 * @param pdftpp given {@link PDFTitlePageParagraph} to render
 * @param pdfdoc given {@link com.lowagie.text.Document} where to render
 * @throws DocumentException
 ************************************************************************************/
private void renderParagraph(PDFTitlePageParagraph pdftpp, com.lowagie.text.Document pdfdoc)
        throws DocumentException {
    String text = pdftpp.getContent();
    if (text == null) {
        text = "";
    }
    int fontstyle = Font.NORMAL;
    if (pdftpp.getFonttype().equals("bold")) {
        fontstyle = Font.BOLD;
    }
    if (pdftpp.getFonttype().equals("italic")) {
        fontstyle = Font.ITALIC;
    }
    if (pdftpp.getFonttype().equals("bolditalic")) {
        fontstyle = Font.BOLDITALIC;
    }
    if (pdftpp.getFonttype().equals("underline")) {
        fontstyle = Font.UNDERLINE;
    }
    if (pdftpp.getFonttype().equals("strikethru")) {
        fontstyle = Font.STRIKETHRU;
    }
    // create BaseFont for embedding
    try {
        Font font = FontFactory.getFont("Arial", BaseFont.CP1252, BaseFont.EMBEDDED, pdftpp.getFontsize(),
                fontstyle);
        Paragraph p2 = new Paragraph(new Chunk(text, font));
        // Paragraph p2=new Paragraph(text,
        // FontFactory.getFont(FontFactory.TIMES_ROMAN, 12));
        pdfdoc.add(p2);
    } catch (Exception e) {
        LOGGER.error("error occured while generating paragraph for titlepage", e);
    }
}

From source file:fr.opensagres.xdocreport.itext.extension.font.AbstractFontRegistry.java

License:Open Source License

public Font getFont(String familyName, String encoding, float size, int style, Color color) {
    initFontRegistryIfNeeded();/* w ww .j  a  v a2 s  .  c  o m*/
    if (familyName != null) {
        familyName = resolveFamilyName(familyName, style);
    }
    try {
        return FontFactory.getFont(familyName, encoding, size, style, color);
    } catch (ExceptionConverter e) {
        // TODO manage options of font not found + add some logs
        return new Font(Font.UNDEFINED, size, style, color);
    }
}

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

License:Open Source License

/**
 * Returns the appropriate PDF font for this
 * HTML tag. The font is created based on the
 * type and attributes of the tag.//from w  w  w.jav a  2s. co  m
 *
 * @return The PDF document font.
 */
public Font getFont() {
    Font font;

    int faceId = TEXT_FONT;
    boolean parentIsFixedFont = false;

    if (isCode() || isPre())
        faceId = CODE_FONT;

    if (parent != null) {
        if (getFontSize() == DEFAULT_FONT_SIZE)
            setFontSize(parent.getFontSize());
        parentIsFixedFont = parent.isCode() || parent.isPre();
    }

    // Pre-formatted text parts tend to appear bigger, so make them 1 point smaller
    if ((isCode() || isPre()) && !parentIsFixedFont)
        setFontSize(getFontSize() - 1);

    if (type == TAG_I)
        setItalic(true);
    if (type == TAG_B)
        setBold(true);
    if (type == TAG_U)
        setUnderline(true);

    if (type == TAG_H1)
        setFontSize(26);
    if (type == TAG_H2)
        setFontSize(22);
    if (type == TAG_H3)
        setFontSize(19);
    if (type == TAG_H4)
        setFontSize(16);
    if (type == TAG_H5)
        setFontSize(13);
    if (type == TAG_H6)
        setFontSize(10);

    int style = 0;

    if (isBold() && isItalic())
        style = BOLD + ITALIC;
    else if (isBold())
        style = BOLD;
    else if (isItalic())
        style = ITALIC;

    if (isLink())
        style = style + LINK;
    if (isUnderline())
        style = style + UNDERLINE;
    if (isStrikethrough())
        style = style + STRIKETHROUGH;

    if (type == TAG_BODY && Locale.getDefault().getLanguage().equals(Locale.JAPANESE.getLanguage()))
        font = FontFactory.getFont("HeiseiMin-W3", "UniJIS-UCS2-HW-H", getFontSize(), style, getFontColor());
    else
        font = Fonts.getFont(faceId, style, getFontSize());

    if (getFontColor() == null && parent != null && parent.getFontColor() != null)
        setFontColor(parent.getFontColor());
    if (getFontFace() == null && parent != null && parent.getFontFace() != null)
        setFontFace(parent.getFontFace());

    if (getFontColor() != null)
        font.setColor(getFontColor());
    if (StringUtility.isNotEmpty(getFontFace()))
        font.setFamily(getFontFace());

    return font;
}

From source file:org.eclipse.birt.report.engine.layout.pdf.font.FontMappingManagerFactory.java

License:Open Source License

/**
 * Creates iText BaseFont with the given font family name.
 * //from  www. ja  v  a2s  .c om
 * @param ffn
 *            the specified font family name.
 * @return the created BaseFont.
 */
public BaseFont createFont(String familyName, int fontStyle) {
    String key = familyName + fontStyle;
    BaseFont bf = null;
    synchronized (baseFonts) {
        if (baseFonts.containsKey(key)) {
            bf = (BaseFont) baseFonts.get(key);
        } else {
            try {
                String fontEncoding = (String) fontEncodings.get(familyName);
                if (fontEncoding == null) {
                    fontEncoding = BaseFont.IDENTITY_H;
                }
                bf = FontFactory.getFont(familyName, fontEncoding, BaseFont.EMBEDDED, 14, fontStyle)
                        .getBaseFont();
            } catch (Throwable de) {
                logger.log(Level.WARNING, de.getMessage(), de);
            }
            baseFonts.put(key, bf);
        }
        if (bf == null && fontStyle != Font.NORMAL) {
            return createFont(familyName, Font.NORMAL);
        }
    }
    return bf;
}

From source file:org.pz.platypus.plugin.html.HtmlFont.java

License:Open Source License

/**
 * Creates an iText Font object based on the class fields
 * @param f the PdfFont containing the parameters for the font
 * @return the iText Font object/*  ww w  .jav  a 2 s .c om*/
 */
Font createFont(final HtmlFont f) {
    int style = 0;
    //       Color col  = new Color( color.getR(), color.getG(), color.getB() );
    Font font;

    String iTextFontName = createItextFontName(f);
    if (!isBase14Font(f.typeface)) {
        style = computeItextStyle();
    }

    try {
        font = FontFactory.getFont(iTextFontName, BaseFont.CP1252, BaseFont.EMBEDDED, size, style);
    } catch (Exception ex) {
        System.out.println("Exception in PdfFont.createFont() for FontFactory.getFont() for " + iTextFontName);
        font = null;
    }

    if (font == null || font.getBaseFont() == null) {
        gdd.logWarning("iText could not find font for: " + iTextFontName + ". Using Times-Roman");
        font = FontFactory.getFont(BaseFont.TIMES_ROMAN, BaseFont.CP1252, BaseFont.EMBEDDED, size, style);
    }

    return (font);
}

From source file:org.pz.platypus.plugin.rtf.RtfFont.java

License:Open Source License

/**
 * Creates an iText Font object based on the class fields
 * @param f the PdfFont containing the parameters for the font
 * @return the iText Font object//from  w  w w  .  j av a  2  s  .c  om
 */
Font createFont(final RtfFont f) {
    int style = 0;
    //       Color col  = new Color( color.getR(), color.getG(), color.getB() );
    Font font = null;

    String iTextFontName = createItextFontName(f);
    if (iTextFontName == null) { // if the font is not in the fontlist nor is it a Base14 font
        f.typeface = DefaultValues.FONT_TYPEFACE;
        iTextFontName = BaseFont.TIMES_ROMAN;
    }

    if (!isBase14Font(f.typeface)) {
        style = computeItextStyle();
        font = getIdentityHFont(iTextFontName, size, style);
    }

    if (font == null) {
        font = getCp1252Font(iTextFontName, size, style);
    }

    if (font == null || font.getBaseFont() == null) { //TODO: Make error msg use literals
        gdd.logWarning("iText could not find font for: " + iTextFontName + ". Using Times-Roman");
        font = FontFactory.getFont(BaseFont.TIMES_ROMAN, BaseFont.CP1252, BaseFont.EMBEDDED, size, style);
    }

    return (font);
}

From source file:org.pz.platypus.plugin.rtf.RtfFont.java

License:Open Source License

/**
 * Opens a font using the IDENTITY-H encoding.
 *
 * @param fontName  the name assigned to the font in the font list
 * @param size the size in points/*from   www.j a v  a2  s.c  o  m*/
 * @param style bold, italic, etc.
 * @return the Font if opened; null if the file could not be opened or an error occurred.
 */
Font getIdentityHFont(final String fontName, float size, int style) {
    // for the time being, if the font is an .otf font, don't open it with IDENTITY-H. Symbola is an
    // exception that seems to work.
    // need to explore the problem further in iText. It's recorded as PLATYPUS-32 in JIRA at Codehaus.
    // returning null forces the calling routine to open the font with CP1252 encoding, which is
    // fine for .otf fonts
    if (isFileOtf(fontName) && (!fontName.toLowerCase().equals("symbola"))) {
        return (null);
    }

    Font font;
    try {
        font = FontFactory.getFont(fontName, BaseFont.IDENTITY_H, BaseFont.EMBEDDED, size, style);
    } catch (Exception ex) {
        font = null;
    }

    return (font);
}

From source file:org.pz.platypus.plugin.rtf.RtfFont.java

License:Open Source License

/**
 * Gets the font with CP1252 (aka WINANSI) encoding
 * @param fontName name of font to get//from  www .  j  av a  2  s. c o m
 * @param size  size in points
 * @param style bold, italic, etc.
 * @return the font, or null if an error occurred.
 */
Font getCp1252Font(final String fontName, float size, int style) {
    Font font;
    try {

        font = FontFactory.getFont(fontName, BaseFont.CP1252, BaseFont.EMBEDDED, size, style);
    } catch (Exception ex) {
        font = null;
    }

    return (font);
}