Search in sources :

Example 1 with Type1Font

use of com.tom_roush.fontbox.type1.Type1Font in project PdfBox-Android by TomRoush.

the class FontMapperImpl method findFontBoxFont.

/**
 * Finds a font with the given PostScript name, or a suitable substitute, or null.
 *
 * @param postScriptName PostScript font name
 */
private FontBoxFont findFontBoxFont(String postScriptName) {
    Type1Font t1 = (Type1Font) findFont(FontFormat.PFB, postScriptName);
    if (t1 != null) {
        return t1;
    }
    TrueTypeFont ttf = (TrueTypeFont) findFont(FontFormat.TTF, postScriptName);
    if (ttf != null) {
        return ttf;
    }
    OpenTypeFont otf = (OpenTypeFont) findFont(FontFormat.OTF, postScriptName);
    if (otf != null) {
        return otf;
    }
    return null;
}
Also used : TrueTypeFont(com.tom_roush.fontbox.ttf.TrueTypeFont) OpenTypeFont(com.tom_roush.fontbox.ttf.OpenTypeFont) Type1Font(com.tom_roush.fontbox.type1.Type1Font)

Example 2 with Type1Font

use of com.tom_roush.fontbox.type1.Type1Font in project pdfbox by apache.

the class FileSystemFontProvider method addType1Font.

/**
 * Adds a Type 1 font to the file cache. To reduce memory, the parsed font is not cached.
 */
private void addType1Font(File pfbFile) throws IOException {
    try (InputStream input = new FileInputStream(pfbFile)) {
        Type1Font type1 = Type1Font.createWithPFB(input);
        if (type1.getName() == null) {
            fontInfoList.add(new FSIgnored(pfbFile, FontFormat.PFB, "*skipnoname*"));
            LOG.warn("Missing 'name' entry for PostScript name in font " + pfbFile);
            return;
        }
        if (type1.getName().contains("|")) {
            fontInfoList.add(new FSIgnored(pfbFile, FontFormat.PFB, "*skippipeinname*"));
            LOG.warn("Skipping font with '|' in name " + type1.getName() + " in file " + pfbFile);
            return;
        }
        fontInfoList.add(new FSFontInfo(pfbFile, FontFormat.PFB, type1.getName(), null, -1, -1, 0, 0, -1, null, this));
        if (LOG.isTraceEnabled()) {
            LOG.trace("PFB: '" + type1.getName() + "' / '" + type1.getFamilyName() + "' / '" + type1.getWeight() + "'");
        }
    } catch (IOException e) {
        LOG.warn("Could not load font file: " + pfbFile, e);
    }
}
Also used : FileInputStream(java.io.FileInputStream) InputStream(java.io.InputStream) IOException(java.io.IOException) Type1Font(org.apache.fontbox.type1.Type1Font) FileInputStream(java.io.FileInputStream)

Example 3 with Type1Font

use of com.tom_roush.fontbox.type1.Type1Font 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 4 with Type1Font

use of com.tom_roush.fontbox.type1.Type1Font in project xmlgraphics-fop by apache.

the class OTFToType1TestCase method testFont.

@Test
public void testFont() throws IOException {
    Type1Font t1 = getFont("test/resources/fonts/otf/SourceSansProBold.otf");
    Assert.assertEquals(t1.getFontName(), "SourceSansPro-Bold.0");
    Assert.assertEquals(t1.getCharStringsDict().keySet().toString(), "[.notdef, d]");
    t1 = getFont("test/resources/fonts/otf/AlexBrushRegular.otf");
    Assert.assertEquals(t1.getFontName(), "AlexBrush-Regular.0");
}
Also used : Type1Font(org.apache.fontbox.type1.Type1Font) CFFToType1Font(org.apache.fop.fonts.CFFToType1Font) Test(org.junit.Test)

Example 5 with Type1Font

use of com.tom_roush.fontbox.type1.Type1Font in project xmlgraphics-fop by apache.

the class OTFToType1TestCase method testCIDFont.

@Test
public void testCIDFont() throws IOException {
    CFFToType1Font realFont = (CFFToType1Font) getRealFont("test/resources/fonts/otf/AlexBrush-Regular-cid.otf");
    for (int i = 0; i < 10240; i++) {
        realFont.mapChar((char) i);
    }
    List<InputStream> fonts = realFont.getInputStreams();
    InputStream is = fonts.get(0);
    Type1Font t1 = Type1Font.createWithPFB(is);
    Assert.assertEquals(t1.getFontName(), "AlexBrush-Regular.0");
    Assert.assertTrue(t1.getCharStringsDict().keySet().contains(".notdef"));
    Assert.assertTrue(t1.getCharStringsDict().keySet().contains("gid_1"));
}
Also used : InputStream(java.io.InputStream) CFFToType1Font(org.apache.fop.fonts.CFFToType1Font) Type1Font(org.apache.fontbox.type1.Type1Font) CFFToType1Font(org.apache.fop.fonts.CFFToType1Font) Test(org.junit.Test)

Aggregations

Type1Font (org.apache.fontbox.type1.Type1Font)8 InputStream (java.io.InputStream)5 FileInputStream (java.io.FileInputStream)4 IOException (java.io.IOException)3 Type1Font (com.tom_roush.fontbox.type1.Type1Font)2 OpenTypeFont (org.apache.fontbox.ttf.OpenTypeFont)2 TrueTypeFont (org.apache.fontbox.ttf.TrueTypeFont)2 CFFToType1Font (org.apache.fop.fonts.CFFToType1Font)2 Test (org.junit.Test)2 OpenTypeFont (com.tom_roush.fontbox.ttf.OpenTypeFont)1 TrueTypeFont (com.tom_roush.fontbox.ttf.TrueTypeFont)1 FontBoxFont (org.apache.fontbox.FontBoxFont)1 CFFFont (org.apache.fontbox.cff.CFFFont)1 BuiltInEncoding (org.apache.fontbox.encoding.BuiltInEncoding)1 PDFontDescriptor (org.apache.pdfbox.pdmodel.font.PDFontDescriptor)1 Test (org.junit.jupiter.api.Test)1 PDType1Font (org.verapdf.model.pdlayer.PDType1Font)1