private boolean isItalic(PDFontDescriptor descriptor) { if (descriptor.isItalic()) { return true; } return descriptor.getFontName().contains("Italic"); } }
private boolean isBold(PDFontDescriptor descriptor) { if (descriptor.isForceBold()) { return true; } return descriptor.getFontName().contains("Bold"); }
private boolean probablyBarcodeFont(PDFontDescriptor fontDescriptor) { String ff = fontDescriptor.getFontFamily(); if (ff == null) { ff = ""; } String fn = fontDescriptor.getFontName(); if (fn == null) { fn = ""; } return ff.startsWith("Code") || ff.toLowerCase().contains("barcode") || fn.startsWith("Code") || fn.toLowerCase().contains("barcode"); }
private void addNameTag(String tag) throws IOException { String name = fontDescriptor.getFontName(); String newName = tag + name; dict.setName(COSName.BASE_FONT, newName); fontDescriptor.setFontName(newName); cidFont.setName(COSName.BASE_FONT, newName); }
@Override protected boolean checkMandatoryFields(COSDictionary fDescriptor) { boolean result = super.checkMandatoryFields(fDescriptor); /* * if this font is a subset, the CharSet entry must be present in the FontDescriptor */ if (isSubSet(fontDescriptor.getFontName())) { String charsetStr = fontDescriptor.getCharSet(); if (charsetStr == null || "".equals(charsetStr)) { this.fContainer.push(new ValidationError(ERROR_FONTS_CHARSET_MISSING_FOR_SUBSET, fontDescriptor.getFontName() + ": The Charset entry is missing for the Type1 Subset")); result = false; } } return result; }
String fontName = fontDesc.getFontName(); String noSubSetName = fontName; if (FontDescriptorHelper.isSubSet(fontName))
@Override public PDStream extractFontFile(PDFontDescriptor fontDescriptor) { PDStream ff3 = fontDescriptor.getFontFile3(); if (ff3 != null) { // Stream validation should be done by the StreamValidateHelper. Process font specific check COSStream stream = ff3.getCOSObject(); if (stream == null) { this.fContainer.push(new ValidationError(ERROR_FONTS_FONT_FILEX_INVALID, fontDescriptor.getFontName() + ": The FontFile is missing")); this.fContainer.notEmbedded(); } else { // Length1/2/3 aren't mandatory for this type of font // But the Subtype is a mandatory field with specific values String st = stream.getNameAsString(COSName.SUBTYPE); if (!(FONT_DICTIONARY_VALUE_TYPE0C.equals(st) || FONT_DICTIONARY_VALUE_TYPE1C.equals(st))) { this.fContainer.push(new ValidationError(ERROR_FONTS_FONT_FILEX_INVALID, fontDescriptor.getFontName() + ": invalid /Subtype /" + st + " in /FontFile3 stream")); } checkCIDSet(fontDescriptor); } } return ff3; }
@Override public PDStream extractFontFile(PDFontDescriptor fontDescriptor) { PDStream fontFile = fontDescriptor.getFontFile2(); COSStream stream = (fontFile == null ? null : fontFile.getCOSObject()); if (stream == null) { this.fContainer.push(new ValidationError(ERROR_FONTS_FONT_FILEX_INVALID, fontDescriptor.getFontName() + ": The FontFile2 is missing")); this.fContainer.notEmbedded(); return null; } if (stream.getInt(COSName.LENGTH1) <= 0) { this.fContainer.push(new ValidationError(ERROR_FONTS_FONT_FILEX_INVALID, fontDescriptor.getFontName() + ": The FontFile entry /Length1 is invalid")); return null; } return fontFile; }
/** * If the embedded font is a subset, the CIDSet entry is mandatory and must be a Stream. If the CIDSet entry doesn't * respects conditions, the FontContainer is updated. * * @param pfDescriptor */ protected void checkCIDSet(PDFontDescriptor pfDescriptor) { if (isSubSet(pfDescriptor.getFontName())) { COSDocument cosDocument = context.getDocument().getDocument(); COSBase cidset = pfDescriptor.getCOSObject().getItem(COSName.getPDFName(FONT_DICTIONARY_KEY_CIDSET)); if (cidset == null || !COSUtils.isStream(cidset, cosDocument)) { this.fContainer.push(new ValidationResult.ValidationError(ERROR_FONTS_CIDSET_MISSING_FOR_SUBSET, pfDescriptor.getFontName() + ": The CIDSet entry is missing for the Composite Subset")); } } }
String name = fontDescriptor.getFontName(); if (name != null) String lower = fontDescriptor.getFontName().toLowerCase(); isBold = lower.contains("bold") || lower.contains("black") ||
/** * If the embedded font is a subset, the CIDSet entry is mandatory and must be a Stream. If the CIDSet entry doesn't * respects conditions, the FontContainer is updated. * * @param pfDescriptor */ protected void checkCIDSet(PDFontDescriptor pfDescriptor) { if (isSubSet(pfDescriptor.getFontName())) { COSDocument cosDocument = context.getDocument().getDocument(); COSBase cidset = pfDescriptor.getCOSObject().getItem(COSName.getPDFName(FONT_DICTIONARY_KEY_CIDSET)); if (cidset == null || !COSUtils.isStream(cidset, cosDocument)) { this.fContainer.push(new ValidationResult.ValidationError(ERROR_FONTS_CIDSET_MISSING_FOR_SUBSET, pfDescriptor.getFontName() + ": The CIDSet entry is missing for the Composite Subset")); } } }
fd.getFontName() + ": The Encoding is invalid for the NonSymbolic TTF")); fd.getFontName() + ": The Encoding should be missing for the Symbolic TTF"));
@Override public PDStream extractFontFile(PDFontDescriptor fontDescriptor) { PDStream ff2 = fontDescriptor.getFontFile2(); if (ff2 != null) { // Stream validation should be done by the StreamValidateHelper. Process font specific check COSStream stream = ff2.getCOSObject(); if (stream == null) { this.fContainer.push(new ValidationError(ERROR_FONTS_FONT_FILEX_INVALID, fontDescriptor.getFontName() + ": The FontFile is missing")); this.fContainer.notEmbedded(); } } checkCIDSet(fontDescriptor); return ff2; }
LOG.warn("Can't read damaged embedded Type1 font " + fd.getFontName(), e); fontIsDamaged = true; LOG.error("Can't read the embedded Type1 font " + fd.getFontName(), e); fontIsDamaged = true;
fontDescriptor.getFontName() + ": The FontFile is missing")); this.fContainer.notEmbedded(); return null; fontDescriptor.getFontName() + ": The FontFile is invalid")); return null;
LOG.warn("Found PFB but expected embedded CFF font " + fd.getFontName()); fontIsDamaged = true; LOG.error("Can't read the embedded CFF font " + fd.getFontName(), e); fontIsDamaged = true;
dict.setName(COSName.BASE_FONT, fontDescriptor.getFontName());
LOG.warn("Found CFF/OTF but expected embedded TTF font " + fd.getFontName());
private COSDictionary createCIDFont() throws IOException { COSDictionary cidFont = new COSDictionary(); // Type, Subtype cidFont.setItem(COSName.TYPE, COSName.FONT); cidFont.setItem(COSName.SUBTYPE, COSName.CID_FONT_TYPE2); // BaseFont cidFont.setName(COSName.BASE_FONT, fontDescriptor.getFontName()); // CIDSystemInfo COSDictionary info = toCIDSystemInfo("Adobe", "Identity", 0); cidFont.setItem(COSName.CIDSYSTEMINFO, info); // FontDescriptor cidFont.setItem(COSName.FONT_DESC, fontDescriptor.getCOSObject()); // W - widths buildWidths(cidFont); // Vertical metrics if (vertical) { buildVerticalMetrics(cidFont); } // CIDToGIDMap cidFont.setItem(COSName.CID_TO_GID_MAP, COSName.IDENTITY); return cidFont; }
fontDescriptor.getFontName() + ": FontFile entry is missing from FontDescriptor")); this.fContainer.notEmbedded(); fontDescriptor.getFontName() + ": They is more than one FontFile"));