org.apache.fontbox.ttf.OTFParser Java Examples
The following examples show how to use
org.apache.fontbox.ttf.OTFParser.
You can vote up the ones you like or vote down the ones you don't like,
and go to the original project or source file by following the links above each example. You may check out the related API usage on the sidebar.
Example #1
Source File: FileSystemFontProvider.java From gcs with Mozilla Public License 2.0 | 6 votes |
private OpenTypeFont getOTFFont(String postScriptName, File file) { try { // todo JH: we don't yet support loading CFF fonts from OTC collections
 OTFParser parser = new OTFParser(false, true); OpenTypeFont otf = parser.parse(file); if (LOG.isDebugEnabled()) { LOG.debug("Loaded " + postScriptName + " from " + file); } return otf; } catch (IOException e) { LOG.error("Could not load font file: " + file, e); } return null; }
Example #2
Source File: FileSystemFontProvider.java From sambox with Apache License 2.0 | 6 votes |
private static OpenTypeFont getOTFFont(String postScriptName, File file) { try { // todo JH: we don't yet support loading CFF fonts from OTC collections OTFParser parser = new OTFParser(false, true); OpenTypeFont otf = parser.parse(file); LOG.debug("Loaded {} from {}", postScriptName, file); return otf; } catch (IOException e) { LOG.error("Could not load font file: " + file, e); } return null; }
Example #3
Source File: TestUtils.java From FontVerter with GNU Lesser General Public License v3.0 | 5 votes |
public static void fontboxValidate(byte[] file) throws IOException { // fontbox for validating generated fonts, fontbox has good pdf type font parsing no generation tho // but font classes have package local constructors OTFParser parser = new OTFParser(); org.apache.fontbox.ttf.OpenTypeFont font = parser.parse(new ByteArrayInputStream(file)); font.getName(); }
Example #4
Source File: PDCIDFontType2.java From sambox with Apache License 2.0 | 4 votes |
/** * Constructor. * * @param fontDictionary The font dictionary according to the PDF specification. * @param parent The parent font. * @param trueTypeFont The true type font used to create the parent font * @throws IOException */ public PDCIDFontType2(COSDictionary fontDictionary, PDType0Font parent, TrueTypeFont trueTypeFont) throws IOException { super(fontDictionary, parent); PDFontDescriptor fd = getFontDescriptor(); if (trueTypeFont != null) { ttf = trueTypeFont; isEmbedded = true; isDamaged = false; } else { boolean fontIsDamaged = false; TrueTypeFont ttfFont = null; PDStream stream = null; if (fd != null) { stream = fd.getFontFile2(); if (stream == null) { stream = fd.getFontFile3(); } if (stream == null) { // Acrobat looks in FontFile too, even though it is not in the spec, see PDFBOX-2599 stream = fd.getFontFile(); } } if (stream != null) { try { // embedded OTF or TTF OTFParser otfParser = new OTFParser(true); OpenTypeFont otf = otfParser.parse(stream.createInputStream()); ttfFont = otf; if (otf.isPostScript()) { // PDFBOX-3344 contains PostScript outlines instead of TrueType fontIsDamaged = true; LOG.warn( "Found CFF/OTF but expected embedded TTF font " + fd.getFontName()); } } catch (NullPointerException | IOException e) // TTF parser is buggy { fontIsDamaged = true; LOG.warn("Could not read embedded OTF for font " + getBaseFont(), e); } } isEmbedded = ttfFont != null; isDamaged = fontIsDamaged; if (ttfFont == null) { ttfFont = findFontOrSubstitute(); } ttf = ttfFont; } cmap = ttf.getUnicodeCmapLookup(false); cid2gid = readCIDToGIDMap(); if (cid2gid != null) { for (int cid = 0; cid < cid2gid.length; cid++) { int gid = cid2gid[cid]; if (gid != 0) { gid2cid.put(gid, cid); } } } }