List of usage examples for org.apache.pdfbox.pdmodel.font PDType0Font getDescendantFont
public PDCIDFont getDescendantFont()
From source file:at.gv.egiz.pdfas.lib.impl.stamping.pdfbox2.PDFAsVisualSignatureBuilder.java
License:EUPL
public void removeCidSet(PDDocument document) throws IOException { PDDocumentCatalog catalog = document.getDocumentCatalog(); COSName cidSet = COSName.getPDFName("CIDSet"); Iterator<PDPage> pdPageIterator = catalog.getPages().iterator(); while (pdPageIterator.hasNext()) { PDPage page = pdPageIterator.next(); Iterator<COSName> cosNameIterator = page.getResources().getFontNames().iterator(); while (cosNameIterator.hasNext()) { COSName fontName = cosNameIterator.next(); PDFont pdFont = page.getResources().getFont(fontName); if (pdFont instanceof PDType0Font) { PDType0Font typedFont = (PDType0Font) pdFont; if (typedFont.getDescendantFont() != null) { if (typedFont.getDescendantFont().getFontDescriptor() != null) { typedFont.getDescendantFont().getFontDescriptor().getCOSObject().removeItem(cidSet); }//from ww w .j a v a 2 s .c o m } } } } }
From source file:com.yiyihealth.tools.test.DrawPrintTextLocations.java
License:Apache License
private Shape calculateGlyphBounds(Matrix textRenderingMatrix, PDFont font, int code) throws IOException { GeneralPath path = null;//from w w w . j a va 2 s .c o m AffineTransform at = textRenderingMatrix.createAffineTransform(); at.concatenate(font.getFontMatrix().createAffineTransform()); if (font instanceof PDType3Font) { PDType3Font t3Font = (PDType3Font) font; PDType3CharProc charProc = t3Font.getCharProc(code); if (charProc != null) { PDRectangle glyphBBox = charProc.getGlyphBBox(); if (glyphBBox != null) { path = glyphBBox.toGeneralPath(); } } } else if (font instanceof PDVectorFont) { PDVectorFont vectorFont = (PDVectorFont) font; path = vectorFont.getPath(code); if (font instanceof PDTrueTypeFont) { PDTrueTypeFont ttFont = (PDTrueTypeFont) font; int unitsPerEm = ttFont.getTrueTypeFont().getHeader().getUnitsPerEm(); at.scale(1000d / unitsPerEm, 1000d / unitsPerEm); } if (font instanceof PDType0Font) { PDType0Font t0font = (PDType0Font) font; if (t0font.getDescendantFont() instanceof PDCIDFontType2) { int unitsPerEm = ((PDCIDFontType2) t0font.getDescendantFont()).getTrueTypeFont().getHeader() .getUnitsPerEm(); at.scale(1000d / unitsPerEm, 1000d / unitsPerEm); } } } else if (font instanceof PDSimpleFont) { PDSimpleFont simpleFont = (PDSimpleFont) font; // these two lines do not always work, e.g. for the TT fonts in file 032431.pdf // which is why PDVectorFont is tried first. String name = simpleFont.getEncoding().getName(code); path = simpleFont.getPath(name); } else { // shouldn't happen, please open issue in JIRA System.out.println("Unknown font class: " + font.getClass()); } if (path == null) { return null; } return at.createTransformedShape(path.getBounds2D()); }
From source file:org.mabb.fontverter.converter.PsType0ToOpenTypeConverter.java
License:Open Source License
public FVFont convert(PDType0Font type0Font) throws IOException, IllegalAccessException, InstantiationException { this.type0Font = type0Font; PDCIDFont descendantFont = type0Font.getDescendantFont(); otfFont = getOtfFromDescendantFont(descendantFont); // so the descendant ttf font will usually have some important tables missing from it // that we need to create ourselves from data in the parent type 0 font. // always build cmap from type0 parent ourselves, cmaps existing in the ttf child tend to have some // issues in certain browsers and apps. convertCmap();/*from w w w .j a v a2 s . c om*/ if (otfFont.getNameTable() == null || isCffDescendant()) convertNameRecords(); otfFont.finalizeFont(); otfFont.normalize(); return otfFont; }