Search in sources :

Example 1 with CFFFont

use of org.apache.fontbox.cff.CFFFont in project veraPDF-pdfbox-validation by veraPDF.

the class PBoxPDType1Font method getcharSetListsAllGlyphs.

@Override
public Boolean getcharSetListsAllGlyphs() {
    try {
        PDFontDescriptor fontDescriptor = pdFontLike.getFontDescriptor();
        if (fontDescriptor != null) {
            String charSet = fontDescriptor.getCharSet();
            if (charSet != null) {
                String[] splittedCharSet = fontDescriptor.getCharSet().split("/");
                // TODO : Log warning if charset doesn't start with '/'
                FontBoxFont font = ((org.apache.pdfbox.pdmodel.font.PDSimpleFont) pdFontLike).getFontBoxFont();
                for (int i = 1; i < splittedCharSet.length; i++) {
                    if (!font.hasGlyph(splittedCharSet[i])) {
                        return Boolean.FALSE;
                    }
                }
                if (font instanceof Type1Font) {
                    if (((Type1Font) font).getCharStringsDict().size() != splittedCharSet.length) {
                        return Boolean.FALSE;
                    }
                } else if (font instanceof CFFFont) {
                    if (((CFFFont) font).getNumCharStrings() != splittedCharSet.length) {
                        return Boolean.FALSE;
                    }
                }
                // }
                return Boolean.TRUE;
            }
        }
    } catch (IOException e) {
        LOGGER.debug("Error while parsing embedded font program. " + e.getMessage(), e);
    }
    return Boolean.FALSE;
}
Also used : CFFFont(org.apache.fontbox.cff.CFFFont) FontBoxFont(org.apache.fontbox.FontBoxFont) IOException(java.io.IOException) PDType1Font(org.verapdf.model.pdlayer.PDType1Font) Type1Font(org.apache.fontbox.type1.Type1Font) PDFontDescriptor(org.apache.pdfbox.pdmodel.font.PDFontDescriptor)

Example 2 with CFFFont

use of org.apache.fontbox.cff.CFFFont in project xmlgraphics-fop by apache.

the class CFFToType1Font method convertOTFToType1.

private List<InputStream> convertOTFToType1(InputStream in) throws IOException {
    CFFFont f = new CFFParser().parse(IOUtils.toByteArray(in)).get(0);
    List<InputStream> fonts = new ArrayList<InputStream>();
    Map<Integer, Integer> glyphs = cidSet.getGlyphs();
    int i = 0;
    for (Map<Integer, Integer> x : splitGlyphs(glyphs)) {
        String iStr = "." + i;
        fonts.add(convertOTFToType1(x, f, iStr));
        i++;
    }
    return fonts;
}
Also used : CFFFont(org.apache.fontbox.cff.CFFFont) ByteArrayInputStream(java.io.ByteArrayInputStream) InputStream(java.io.InputStream) ArrayList(java.util.ArrayList) CFFParser(org.apache.fontbox.cff.CFFParser)

Example 3 with CFFFont

use of org.apache.fontbox.cff.CFFFont in project xmlgraphics-fop by apache.

the class OTFSubSetFileTestCase method validateCharStrings.

/**
 * Validates the subset font CharString data by comparing it with the original.
 * @param subsetCFF The subset CFFDataReader containing the CharString data
 * @param origCFF The original CFFDataReader containing the CharString data
 * @throws IOException
 */
private void validateCharStrings(CFFDataReader subsetCFF, CFFDataReader origCFF) throws IOException {
    CFFFont sourceSansOriginal = sourceSansProBold.fileFont;
    CFFIndexData charStrings = subsetCFF.getCharStringIndex();
    List<byte[]> origCharStringData = sourceSansOriginal.getCharStringBytes();
    for (int i = 0; i < charStrings.getNumObjects(); i++) {
        byte[] origCharData = origCharStringData.get(i);
        byte[] charData = charStrings.getValue(i);
        List<BytesNumber> origOperands = getFullCharString(new Context(), origCharData, origCFF);
        List<BytesNumber> subsetOperands = getFullCharString(new Context(), charData, subsetCFF);
        for (int j = 0; j < origOperands.size(); j++) {
            assertTrue(origOperands.get(j).equals(subsetOperands.get(j)));
        }
    }
}
Also used : CFFFont(org.apache.fontbox.cff.CFFFont) BytesNumber(org.apache.fop.fonts.truetype.OTFSubSetFile.BytesNumber) CFFIndexData(org.apache.fop.fonts.cff.CFFDataReader.CFFIndexData)

Example 4 with CFFFont

use of org.apache.fontbox.cff.CFFFont in project sambox by torakiki.

the class FileSystemFontProvider method addTrueTypeFontImpl.

/**
 * Adds an OTF or TTF font to the file cache. To reduce memory, the parsed font is not cached.
 */
private void addTrueTypeFontImpl(TrueTypeFont ttf, File file) throws IOException {
    try {
        // read PostScript name, if any
        if (ttf.getName() != null) {
            // ignore bitmap fonts
            if (ttf.getHeader() == null) {
                fontInfoList.add(new FSIgnored(file, FontFormat.TTF, ttf.getName()));
                return;
            }
            int macStyle = ttf.getHeader().getMacStyle();
            int sFamilyClass = -1;
            int usWeightClass = -1;
            int ulCodePageRange1 = 0;
            int ulCodePageRange2 = 0;
            byte[] panose = null;
            OS2WindowsMetricsTable os2WindowsMetricsTable = ttf.getOS2Windows();
            // Apple's AAT fonts don't have an OS/2 table
            if (nonNull(os2WindowsMetricsTable)) {
                sFamilyClass = os2WindowsMetricsTable.getFamilyClass();
                usWeightClass = os2WindowsMetricsTable.getWeightClass();
                ulCodePageRange1 = (int) os2WindowsMetricsTable.getCodePageRange1();
                ulCodePageRange2 = (int) os2WindowsMetricsTable.getCodePageRange2();
                panose = os2WindowsMetricsTable.getPanose();
            }
            String format;
            if (ttf instanceof OpenTypeFont && ((OpenTypeFont) ttf).isPostScript()) {
                format = "OTF";
                CFFFont cff = ((OpenTypeFont) ttf).getCFF().getFont();
                CIDSystemInfo ros = null;
                if (cff instanceof CFFCIDFont) {
                    CFFCIDFont cidFont = (CFFCIDFont) cff;
                    String registry = cidFont.getRegistry();
                    String ordering = cidFont.getOrdering();
                    int supplement = cidFont.getSupplement();
                    ros = new CIDSystemInfo(registry, ordering, supplement);
                }
                fontInfoList.add(new FSFontInfo(file, FontFormat.OTF, ttf.getName(), ros, usWeightClass, sFamilyClass, ulCodePageRange1, ulCodePageRange2, macStyle, panose, this));
            } else {
                CIDSystemInfo ros = null;
                if (ttf.getTableMap().containsKey("gcid")) {
                    // Apple's AAT fonts have a "gcid" table with CID info
                    byte[] bytes = ttf.getTableBytes(ttf.getTableMap().get("gcid"));
                    String reg = new String(bytes, 10, 64, StandardCharsets.US_ASCII);
                    String registryName = reg.substring(0, reg.indexOf('\0'));
                    String ord = new String(bytes, 76, 64, StandardCharsets.US_ASCII);
                    String orderName = ord.substring(0, ord.indexOf('\0'));
                    int supplementVersion = bytes[140] << 8 & (bytes[141] & 0xFF);
                    ros = new CIDSystemInfo(registryName, orderName, supplementVersion);
                }
                format = "TTF";
                fontInfoList.add(new FSFontInfo(file, FontFormat.TTF, ttf.getName(), ros, usWeightClass, sFamilyClass, ulCodePageRange1, ulCodePageRange2, macStyle, panose, this));
            }
            if (LOG.isTraceEnabled()) {
                NamingTable name = ttf.getNaming();
                if (name != null) {
                    LOG.trace(format + ": '" + name.getPostScriptName() + "' / '" + name.getFontFamily() + "' / '" + name.getFontSubFamily() + "'");
                }
            }
        } else {
            fontInfoList.add(new FSIgnored(file, FontFormat.TTF, "*skipnoname*"));
            LOG.warn("Missing 'name' entry for PostScript name in font " + file);
        }
    } catch (IOException e) {
        fontInfoList.add(new FSIgnored(file, FontFormat.TTF, "*skipexception*"));
        LOG.warn("Could not load font file: " + file, e);
    } finally {
        IOUtils.close(ttf);
    }
}
Also used : CFFFont(org.apache.fontbox.cff.CFFFont) OpenTypeFont(org.apache.fontbox.ttf.OpenTypeFont) NamingTable(org.apache.fontbox.ttf.NamingTable) IOException(java.io.IOException) OS2WindowsMetricsTable(org.apache.fontbox.ttf.OS2WindowsMetricsTable) CFFCIDFont(org.apache.fontbox.cff.CFFCIDFont)

Example 5 with CFFFont

use of org.apache.fontbox.cff.CFFFont in project docx4j by plutext.

the class CFFToType1Font method convertOTFToType1.

private List<InputStream> convertOTFToType1(InputStream in) throws IOException {
    CFFFont f = new CFFParser().parse(IOUtils.toByteArray(in)).get(0);
    List<InputStream> fonts = new ArrayList<InputStream>();
    Map<Integer, Integer> glyphs = cidSet.getGlyphs();
    int i = 0;
    for (Map<Integer, Integer> x : splitGlyphs(glyphs)) {
        String iStr = "." + i;
        fonts.add(convertOTFToType1(x, f, iStr));
        i++;
    }
    return fonts;
}
Also used : CFFFont(org.apache.fontbox.cff.CFFFont) ByteArrayInputStream(java.io.ByteArrayInputStream) InputStream(java.io.InputStream) ArrayList(java.util.ArrayList) CFFParser(org.apache.fontbox.cff.CFFParser)

Aggregations

CFFFont (org.apache.fontbox.cff.CFFFont)5 ByteArrayInputStream (java.io.ByteArrayInputStream)2 IOException (java.io.IOException)2 InputStream (java.io.InputStream)2 ArrayList (java.util.ArrayList)2 CFFParser (org.apache.fontbox.cff.CFFParser)2 FontBoxFont (org.apache.fontbox.FontBoxFont)1 CFFCIDFont (org.apache.fontbox.cff.CFFCIDFont)1 NamingTable (org.apache.fontbox.ttf.NamingTable)1 OS2WindowsMetricsTable (org.apache.fontbox.ttf.OS2WindowsMetricsTable)1 OpenTypeFont (org.apache.fontbox.ttf.OpenTypeFont)1 Type1Font (org.apache.fontbox.type1.Type1Font)1 CFFIndexData (org.apache.fop.fonts.cff.CFFDataReader.CFFIndexData)1 BytesNumber (org.apache.fop.fonts.truetype.OTFSubSetFile.BytesNumber)1 PDFontDescriptor (org.apache.pdfbox.pdmodel.font.PDFontDescriptor)1 PDType1Font (org.verapdf.model.pdlayer.PDType1Font)1