/** * Create the validation object for CIDType0 Font */ protected FontValidator<? extends FontContainer<PDCIDFontType0>> createCIDType0FontValidator(COSDictionary fDict) { try { return new CIDType0FontValidator(context, new PDCIDFontType0(fDict, (PDType0Font)font)); } catch (IOException e) { this.fontContainer.push(new ValidationError(ERROR_FONTS_CID_DAMAGED, font.getName() + ": The CIDType0 font is damaged", e)); return null; } }
@Override public boolean hasGlyph(int code) throws IOException { int cid = codeToCID(code); Type2CharString charstring = getType2CharString(cid); if (charstring != null) { return charstring.getGID() != 0; } else if (isEmbedded && t1Font instanceof CFFType1Font) { return ((CFFType1Font)t1Font).getType2CharString(cid).getGID() != 0; } else { return t1Font.hasGlyph(getGlyphName(code)); } }
@Override public boolean hasGlyph(int code) throws IOException { return font.codeToGID(code) != 0; } }
@Override public float getHeight(int code) throws IOException { int cid = codeToCID(code); float height = 0; if (!glyphHeights.containsKey(cid)) { height = (float) getType2CharString(cid).getBounds().getHeight(); glyphHeights.put(cid, height); } return height; }
PDFontDescriptor fd = getFontDescriptor(); byte[] bytes = null; if (fd != null) t1Font = cffFont; cid2gid = readCIDToGIDMap(); isEmbedded = true; isDamaged = false; .getCIDFont(getBaseFont(), getFontDescriptor(), getCIDSystemInfo()); FontBoxFont font; if (mapping.isCIDFont()) getBaseFont()); fontMatrixTransform = getFontMatrix().createAffineTransform(); fontMatrixTransform.scale(1000, 1000);
@Override public byte[] getBytes() throws IOException { PDStream ff3Stream = getFontDescriptor().getFontFile3(); return IOUtils.toByteArray(ff3Stream.createInputStream()); } }
@Override public float getAverageFontWidth() { if (avgWidth == null) { avgWidth = getAverageCharacterWidth(); } return avgWidth; }
@Override public BoundingBox getBoundingBox() { if (fontBBox == null) { fontBBox = generateBoundingBox(); } return fontBBox; }
@Override public int codeToGID(int code) { int cid = codeToCID(code); if (cidFont != null) { // The CIDs shall be used to determine the GID value for the glyph procedure using the // charset table in the CFF program return cidFont.getCharset().getGIDForCID(cid); } else { // The CIDs shall be used directly as GID values return cid; } }
/** * Constructor. * * @param font Type 0 CIDFont */ CIDType0Glyph2D(PDCIDFontType0 font) // todo: what about PDCIDFontType2? { this.font = font; fontName = font.getBaseFont(); }
PDFontDescriptor fd = getFontDescriptor(); byte[] bytes = null; if (fd != null) t1Font = cffFont; cid2gid = readCIDToGIDMap(); isEmbedded = true; isDamaged = false; .getCIDFont(getBaseFont(), getFontDescriptor(), getCIDSystemInfo()); FontBoxFont font; if (mapping.isCIDFont()) getBaseFont()); fontMatrixTransform = getFontMatrix().createAffineTransform(); fontMatrixTransform.scale(1000, 1000);
@Override public float getHeight(int code) throws IOException { int cid = codeToCID(code); float height = 0; if (!glyphHeights.containsKey(cid)) { height = (float) getType2CharString(cid).getBounds().getHeight(); glyphHeights.put(cid, height); } return height; }
private BoundingBox generateBoundingBox() { if (getFontDescriptor() != null) { PDRectangle bbox = getFontDescriptor().getFontBoundingBox(); if (bbox != null && (Float.compare(bbox.getLowerLeftX(),0) != 0 || Float.compare(bbox.getLowerLeftY(),0) != 0 || Float.compare(bbox.getUpperRightX(),0) != 0 || Float.compare(bbox.getUpperRightY(),0) != 0)) { return new BoundingBox(bbox.getLowerLeftX(), bbox.getLowerLeftY(), bbox.getUpperRightX(), bbox.getUpperRightY()); } } if (cidFont != null) { return cidFont.getFontBBox(); } else { try { return t1Font.getFontBBox(); } catch (IOException e) { LOG.debug("Couldn't get font bounding box - returning default value", e); return new BoundingBox(); } } }
@Override public float getAverageFontWidth() { if (avgWidth == null) { avgWidth = getAverageCharacterWidth(); } return avgWidth; }
@Override public BoundingBox getBoundingBox() { if (fontBBox == null) { fontBBox = generateBoundingBox(); } return fontBBox; }
@Override public int codeToGID(int code) { int cid = codeToCID(code); if (cidFont != null) { // The CIDs shall be used to determine the GID value for the glyph procedure using the // charset table in the CFF program return cidFont.getCharset().getGIDForCID(cid); } else { // The CIDs shall be used directly as GID values return cid; } }
@Override public GeneralPath getPath(int code) throws IOException { int cid = codeToCID(code); if (cid2gid != null && isEmbedded) { // PDFBOX-4093: despite being a type 0 font, there is a CIDToGIDMap cid = cid2gid[cid]; } Type2CharString charstring = getType2CharString(cid); if (charstring != null) { return charstring.getPath(); } else if (isEmbedded && t1Font instanceof CFFType1Font) { return ((CFFType1Font)t1Font).getType2CharString(cid).getPath(); } else { return t1Font.getPath(getGlyphName(code)); } }
PDFontDescriptor fd = getFontDescriptor(); byte[] bytes = null; if (fd != null) .getCIDFont(getBaseFont(), getFontDescriptor(), getCIDSystemInfo()); FontBoxFont font; if (mapping.isCIDFont()) getBaseFont()); fontMatrixTransform = getFontMatrix().createAffineTransform(); fontMatrixTransform.scale(1000, 1000);
/** * Creates a new PDCIDFont instance with the appropriate subclass. * * @param dictionary descendant font dictionary * @return a PDCIDFont instance, based on the SubType entry of the dictionary * @throws IOException if something goes wrong */ static PDCIDFont createDescendantFont(COSDictionary dictionary, PDType0Font parent) throws IOException { COSName type = dictionary.getCOSName(COSName.TYPE, COSName.FONT); if (!COSName.FONT.equals(type)) { throw new IllegalArgumentException("Expected 'Font' dictionary but found '" + type.getName() + "'"); } COSName subType = dictionary.getCOSName(COSName.SUBTYPE); if (COSName.CID_FONT_TYPE0.equals(subType)) { return new PDCIDFontType0(dictionary, parent); } else if (COSName.CID_FONT_TYPE2.equals(subType)) { return new PDCIDFontType2(dictionary, parent); } else { throw new IOException("Invalid font type: " + type); } }
@Override public float getHeight(int code) throws IOException { int cid = codeToCID(code); float height = 0; if (!glyphHeights.containsKey(cid)) { height = (float) getType2CharString(cid).getBounds().getHeight(); glyphHeights.put(cid, height); } return height; }