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

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

Introduction

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

Prototype

public static Object[] getAllFontNames(String name, String encoding, byte ttfAfm[])
        throws DocumentException, IOException 

Source Link

Document

Gets all the names from the font.

Usage

From source file:jdbreport.model.io.pdf.itext2.ReportFontMapper.java

License:Apache License

public int insertDirectory(String dir) {
    File file = new File(dir);
    if (!file.exists() || !file.isDirectory())
        return 0;
    File files[] = file.listFiles();
    if (files == null)
        return 0;
    int count = 0;
    for (File file1 : files) {
        file = file1;/*w ww .j  ava 2  s  . c o m*/
        if (file.isDirectory()) {
            count += insertDirectory(file.getPath());
        } else {
            String name = file.getPath().toLowerCase();
            try {
                if (name.endsWith(".ttf") || name.endsWith(".otf") || name.endsWith(".afm")) {
                    Object allNames[] = BaseFont.getAllFontNames(file.getPath(), BaseFont.IDENTITY_H, null);
                    insertNames(allNames, file.getPath());
                    ++count;
                } else if (name.endsWith(".ttc")) {
                    String ttcs[] = BaseFont.enumerateTTCNames(file.getPath());
                    for (int j = 0; j < ttcs.length; ++j) {
                        String nt = file.getPath() + "," + j;
                        Object allNames[] = BaseFont.getAllFontNames(nt, BaseFont.IDENTITY_H, null);
                        insertNames(allNames, nt);
                    }
                    ++count;
                }
            } catch (Exception ignored) {
            }
        }
    }
    return count;
}

From source file:jgnash.ui.report.FontRegistry.java

License:Open Source License

private void registerFont(final String path) {
    try {//  w  w w. j  a va  2 s  .c  om
        if (path.toLowerCase().endsWith(".ttf") || path.toLowerCase().endsWith(".otf")
                || path.toLowerCase().indexOf(".ttc,") > 0) {
            Object allNames[] = BaseFont.getAllFontNames(path, BaseFont.WINANSI, null);

            String[][] names = (String[][]) allNames[2]; //full name
            for (String[] name : names) {
                registeredFontMap.put(name[3].toLowerCase(), path);
            }

        } else if (path.toLowerCase().endsWith(".ttc")) {
            String[] names = BaseFont.enumerateTTCNames(path);
            for (int i = 0; i < names.length; i++) {
                registerFont(path + "," + i);
            }
        } else if (path.toLowerCase().endsWith(".afm") || path.toLowerCase().endsWith(".pfm")) {
            BaseFont bf = BaseFont.createFont(path, BaseFont.CP1252, false);
            String fullName = bf.getFullFontName()[0][3].toLowerCase();
            registeredFontMap.put(fullName, path);
        }
    } catch (DocumentException | IOException e) {
        throw new RuntimeException(e);
    }
}

From source file:nl.dykema.jxmlnote.report.pdf.MyDefaultFontMapper.java

License:Open Source License

public int insertFile(File file, int count) {
    String name = file.getPath().toLowerCase();
    try {//ww w  .  j a  va 2 s.c  om
        if (name.endsWith(".ttf") || name.endsWith(".otf") || name.endsWith(".afm")) {
            Object allNames[] = BaseFont.getAllFontNames(file.getPath(), BaseFont.CP1252, null);
            insertNames(allNames, file.getPath());
            ++count;
        } else if (name.endsWith(".ttc")) {
            String ttcs[] = BaseFont.enumerateTTCNames(file.getPath());
            for (int j = 0; j < ttcs.length; ++j) {
                String nt = file.getPath() + "," + j;
                Object allNames[] = BaseFont.getAllFontNames(nt, BaseFont.CP1252, null);
                insertNames(allNames, nt);
            }
            ++count;
        }
    } catch (Exception e) {
    }
    return count;
}