Example usage for com.lowagie.text.pdf BaseFont getFamilyFontName

List of usage examples for com.lowagie.text.pdf BaseFont getFamilyFontName

Introduction

In this page you can find the example usage for com.lowagie.text.pdf BaseFont getFamilyFontName.

Prototype

public abstract String[][] getFamilyFontName();

Source Link

Document

Gets the family name of the font.

Usage

From source file:org.eclipse.birt.report.engine.emitter.odp.util.OdpUtil.java

License:Open Source License

public static String getFontName(BaseFont baseFont) {
    String[][] familyFontNames = baseFont.getFamilyFontName();
    String[] family = familyFontNames[familyFontNames.length - 1];
    return family[family.length - 1];
}

From source file:org.eclipse.birt.report.engine.emitter.ppt.PPTWriter.java

License:Open Source License

private String getFontName(BaseFont baseFont) {
    String[][] familyFontNames = baseFont.getFamilyFontName();
    String[] family = familyFontNames[familyFontNames.length - 1];
    return family[family.length - 1];
}

From source file:org.pz.platypus.TypefaceMap.java

License:Open Source License

/**
 * Uses iText to extract the family name (or in case of .ttc the names) of the font family.
 *
 * @param fontFilename font file//from  w ww. j av a  2s.  c o  m
 * @param bf base font we create to get the family font name
 *
 * @return the font's family name(s) or an empty array if an error occurred.
 *
 * For explanation of .ttc handling, see:
 * http://itextdocs.lowagie.com/tutorial/fonts/getting/index.php
 *
 */
public String[] extractFamilyNames(String fontFilename, BaseFont bf) {
    String familyName[] = new String[1];

    String names[][];
    File f = new File(fontFilename);
    if (f.exists() || !f.isDirectory()) {
        try {
            if (fontFilename.toLowerCase().endsWith(".ttc")) {
                return (BaseFont.enumerateTTCNames(fontFilename));
            }

            bf = BaseFont.createFont(fontFilename, "winansi", BaseFont.NOT_EMBEDDED);
            names = bf.getFamilyFontName();
        } catch (IOException ioe) {
            gdd.logInfo("IOException loading " + fontFilename + " into font-family map");
            return (new String[0]);
        } catch (DocumentException de) {
            gdd.logInfo("Document Exception loading " + fontFilename + " into font-family map");
            return (new String[0]);
        }

        if (names != null && names[0] != null) {
            familyName[0] = names[0][3];
            return familyName;
        } else {
            return (new String[0]);
        }
    }
    return (new String[0]);
}

From source file:org.xhtmlrenderer.pdf.ITextFontResolver.java

License:Open Source License

public void addFont(String path, String fontFamilyNameOverride, String encoding, boolean embedded,
        String pathToPFB) throws DocumentException, IOException {
    String lower = path.toLowerCase();
    if (lower.endsWith(".otf") || lower.endsWith(".ttf") || lower.indexOf(".ttc,") != -1) {
        BaseFont font = BaseFont.createFont(path, encoding, embedded);

        String[] fontFamilyNames;
        if (fontFamilyNameOverride != null) {
            fontFamilyNames = new String[] { fontFamilyNameOverride };
        } else {/*from w  ww  .  j a  v a2 s  .  co m*/
            fontFamilyNames = TrueTypeUtil.getFamilyNames(font);
        }

        for (int i = 0; i < fontFamilyNames.length; i++) {
            String fontFamilyName = fontFamilyNames[i];
            FontFamily fontFamily = getFontFamily(fontFamilyName);

            FontDescription descr = new FontDescription(font);
            try {
                TrueTypeUtil.populateDescription(path, font, descr);
            } catch (Exception e) {
                throw new XRRuntimeException(e.getMessage(), e);
            }

            fontFamily.addFontDescription(descr);
        }
    } else if (lower.endsWith(".ttc")) {
        String[] names = BaseFont.enumerateTTCNames(path);
        for (int i = 0; i < names.length; i++) {
            addFont(path + "," + i, fontFamilyNameOverride, encoding, embedded, null);
        }
    } else if (lower.endsWith(".afm") || lower.endsWith(".pfm")) {
        if (embedded && pathToPFB == null) {
            throw new IOException("When embedding a font, path to PFB/PFA file must be specified");
        }

        BaseFont font = BaseFont.createFont(path, encoding, embedded, false, null, readFile(pathToPFB));

        String fontFamilyName;
        if (fontFamilyNameOverride != null) {
            fontFamilyName = fontFamilyNameOverride;
        } else {
            fontFamilyName = font.getFamilyFontName()[0][3];
        }

        FontFamily fontFamily = getFontFamily(fontFamilyName);

        FontDescription descr = new FontDescription(font);
        // XXX Need to set weight, underline position, etc.  This information
        // is contained in the AFM file (and even parsed by Type1Font), but
        // unfortunately it isn't exposed to the caller.
        fontFamily.addFontDescription(descr);
    } else {
        throw new IOException("Unsupported font type");
    }
}

From source file:org.xhtmlrenderer.pdf.ITextFontResolver.java

License:Open Source License

private void addFontFaceFont(String fontFamilyNameOverride, IdentValue fontWeightOverride,
        IdentValue fontStyleOverride, String uri, String encoding, boolean embedded, byte[] afmttf, byte[] pfb)
        throws DocumentException, IOException {
    String lower = uri.toLowerCase();
    if (lower.endsWith(".otf") || lower.endsWith(".ttf") || lower.indexOf(".ttc,") != -1) {
        BaseFont font = BaseFont.createFont(uri, encoding, embedded, false, afmttf, pfb);

        String[] fontFamilyNames;
        if (fontFamilyNameOverride != null) {
            fontFamilyNames = new String[] { fontFamilyNameOverride };
        } else {//ww  w  . j av  a 2s  .  c  o  m
            fontFamilyNames = TrueTypeUtil.getFamilyNames(font);
        }

        for (int i = 0; i < fontFamilyNames.length; i++) {
            FontFamily fontFamily = getFontFamily(fontFamilyNames[i]);

            FontDescription descr = new FontDescription(font);
            try {
                TrueTypeUtil.populateDescription(uri, afmttf, font, descr);
            } catch (Exception e) {
                throw new XRRuntimeException(e.getMessage(), e);
            }

            descr.setFromFontFace(true);

            if (fontWeightOverride != null) {
                descr.setWeight(convertWeightToInt(fontWeightOverride));
            }

            if (fontStyleOverride != null) {
                descr.setStyle(fontStyleOverride);
            }

            fontFamily.addFontDescription(descr);
        }
    } else if (lower.endsWith(".afm") || lower.endsWith(".pfm") || lower.endsWith(".pfb")
            || lower.endsWith(".pfa")) {
        if (embedded && pfb == null) {
            throw new IOException("When embedding a font, path to PFB/PFA file must be specified");
        }

        String name = uri.substring(0, uri.length() - 4) + ".afm";
        BaseFont font = BaseFont.createFont(name, encoding, embedded, false, afmttf, pfb);

        String fontFamilyName = font.getFamilyFontName()[0][3];
        FontFamily fontFamily = getFontFamily(fontFamilyName);

        FontDescription descr = new FontDescription(font);
        descr.setFromFontFace(true);
        // XXX Need to set weight, underline position, etc.  This information
        // is contained in the AFM file (and even parsed by Type1Font), but
        // unfortunately it isn't exposed to the caller.
        fontFamily.addFontDescription(descr);
    } else {
        throw new IOException("Unsupported font type");
    }
}

From source file:org.xhtmlrenderer.pdf.TrueTypeUtil.java

License:Open Source License

public static String[] getFamilyNames(BaseFont font) {
    String names[][] = font.getFamilyFontName();
    if (names.length == 1) {
        return new String[] { names[0][3] };
    }//from ww  w . jav a2  s.  co  m

    List result = new ArrayList();
    for (int k = 0; k < names.length; ++k) {
        String name[] = names[k];
        if ((name[0].equals("1") && name[1].equals("0")) || name[2].equals("1033")) {
            result.add(name[3]);
        }
    }
    return (String[]) result.toArray(new String[result.size()]);
}