Example usage for com.itextpdf.text.pdf BaseFont getFullFontName

List of usage examples for com.itextpdf.text.pdf BaseFont getFullFontName

Introduction

In this page you can find the example usage for com.itextpdf.text.pdf BaseFont getFullFontName.

Prototype

public abstract String[][] getFullFontName();

Source Link

Document

Gets the full name of the font.

Usage

From source file:org.javad.pdf.fonts.FontRegistry.java

License:Apache License

/**
 * This method will attempt to find the named font with the specified size and style
 * using a naming roll-off technique based on some of the naming conventions observed.
 * <ul><li>//from w w  w .  j  a  v  a  2s.c  o  m
 * If the style is bold and italic, a font with the name <code>"[name]-bolditalic"</code>
 * will attempted. </li>
 * <li>If the style is both a name like <code>"[name] bold"</code> will be
 * attempted.</li>
 * <li>If the font is italic, the names <code>"[name] italic"</code> and then
 * <code>"[name]-italic"</code> will be tried.</li>
 * <li> Finally if none of these styled fonts can be located, the <code>"[name]"</code> will be tried.</li>
 * </ul>
 * 
 * @param name
 * @param bean
 * @return
 */
Font findFont(String name, PdfFontBean bean) {
    String form = (bean.isI18N()) ? BaseFont.IDENTITY_H : BaseFont.CP1252;
    Font f = null;
    if (bean.isBold() && bean.isItalic()) {
        f = FontFactory.getFont(name + "-bolditalic", form, bean.getSize(), bean.getStyle());
    }
    if (isFontInvalid(f) && bean.isBold()) {
        f = FontFactory.getFont(name + " bold", form, bean.getSize(), bean.getStyle());
    }
    if (isFontInvalid(f) && bean.isItalic()) {
        f = FontFactory.getFont(name + " italic", form, bean.getSize(), bean.getStyle());
        if (isFontInvalid(f)) {
            f = FontFactory.getFont(name + "-italic", form, bean.getSize(), bean.getStyle());
        }
    }
    if (isFontInvalid(f)) {
        f = FontFactory.getFont(name, form, bean.getSize(), bean.getStyle());
    }
    if (logger.isLoggable(Level.FINER)) {
        @SuppressWarnings("null")
        BaseFont bf = f.getBaseFont();
        if (bf != null) {
            String[][] fullName = bf.getFullFontName();
            if (fullName != null && fullName.length >= 1 && fullName[0].length >= 4) {
                logger.log(Level.FINER, "The calculated font name is \"{0}\"", fullName[0][3]);
            } else {
                logger.finer("The base font full name was not parseable.");
            }
        } else {
            logger.log(Level.FINER, "The base font was null for \"{0}\" with style {1}",
                    new Object[] { name, bean.getStyle() });
        }
    }
    return f;
}