@Override public String toString() { return getClass().getSimpleName() + " " + getName(); } }
/** * Returns true if this font is one of the "Standard 14" fonts and receives special handling. */ public boolean isStandard14() { // this logic is based on Acrobat's behaviour, see PDFBOX-2372 // embedded fonts never get special treatment if (isEmbedded()) { return false; } // if the name matches, this is a Standard 14 font return Standard14Fonts.containsName(getName()); }
private void initUI(String fontReferenceName, PDResources resources) { PDFont font = null; for (COSName name: resources.getFontNames()) { if (name.getName().equals(fontReferenceName)) { try { font = resources.getFont(name); } catch (IOException e) { e.printStackTrace(); } } } if (font != null) { markup = "<html>" + font.getName() + "</html>"; } }
protected FontValidator<? extends FontContainer<? extends PDCIDFont>> createDescendantValidator(COSDictionary cidFont) { String subtype = cidFont.getNameAsString(COSName.SUBTYPE); FontValidator<? extends FontContainer<? extends PDCIDFont>> cidFontValidator = null; if (FONT_DICTIONARY_VALUE_TYPE0.equals(subtype)) { cidFontValidator = createCIDType0FontValidator(cidFont); } else if (FONT_DICTIONARY_VALUE_TYPE2.equals(subtype)) { cidFontValidator = createCIDType2FontValidator(cidFont); } else { this.fontContainer.push(new ValidationError(ERROR_FONTS_DICTIONARY_INVALID, font.getName() + ": Type and/or Subtype keys are missing")); } return cidFontValidator; }
LOG.warn("attempting to use subset font " + font.getName() + " without proper context");
protected void checkCMapEncoding(COSBase encoding) { if (COSUtils.isString(encoding, cosDocument)) { // if encoding is a string, only 2 values are allowed String str = COSUtils.getAsString(encoding, cosDocument); if (!(FONT_DICTIONARY_VALUE_CMAP_IDENTITY_V.equals(str) || FONT_DICTIONARY_VALUE_CMAP_IDENTITY_H .equals(str))) { this.fontContainer.push(new ValidationError(ERROR_FONTS_CIDKEYED_INVALID, font.getName() + ": The CMap is a string but it isn't an Identity-H/V")); return; } } else if (COSUtils.isStream(encoding, cosDocument)) { /* * If the CMap is a stream, some fields are mandatory and the CIDSytemInfo must be compared with the * CIDSystemInfo entry of the CIDFont. */ processCMapAsStream(COSUtils.getAsStream(encoding, cosDocument)); } else { // CMap type is invalid this.fontContainer.push(new ValidationError(ERROR_FONTS_CIDKEYED_CMAP_INVALID_OR_MISSING, font.getName() + ": The CMap type is invalid")); } }
/** * 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; } }
/** * Create the validation object for CIDType2 Font * * @param fDict a CIDType2 font dictionary. * @return a CIDType2 tont font validator. */ protected FontValidator<? extends FontContainer<PDCIDFontType2>> createCIDType2FontValidator(COSDictionary fDict) { try { return new CIDType2FontValidator(context, new PDCIDFontType2(fDict, (PDType0Font)font)); } catch (IOException e) { this.fontContainer.push(new ValidationError(ERROR_FONTS_CID_DAMAGED, font.getName() + ": The CIDType2 font is damaged", e)); return null; } }
font.getName() + ": Some elements in the CMap dictionary are missing or invalid")); font.getName() + ": CMapName or WMode is inconsistent")); font.getName() + ": The CMap type is invalid")); this.fontContainer.push(new ValidationError(ERROR_FONTS_CID_CMAP_DAMAGED, font.getName() + ": The CMap type is damaged", e));
/** * This methods extracts from the Font dictionary all mandatory fields. If a mandatory field is missing, the list of * ValidationError in the FontContainer is updated. */ protected void checkMandatoryFields() { COSDictionary fontDictionary = font.getCOSObject(); boolean areFieldsPResent = fontDictionary.containsKey(COSName.TYPE); areFieldsPResent &= fontDictionary.containsKey(COSName.SUBTYPE); areFieldsPResent &= fontDictionary.containsKey(COSName.BASE_FONT); areFieldsPResent &= fontDictionary.containsKey(COSName.DESCENDANT_FONTS); areFieldsPResent &= fontDictionary.containsKey(COSName.ENCODING); if (!areFieldsPResent) { this.fontContainer.push(new ValidationError(ERROR_FONTS_DICTIONARY_INVALID, font.getName() + ": Some keys are missing from composite font dictionary")); } }
@Override public String toString() { return getClass().getSimpleName() + " " + getName(); } }
/** * The CIDSystemInfo must have the same Registry and Ordering for CMap and CIDFont. This control is useless if CMap * is Identity-H or Identity-V so this method is called by the checkCMap method. * * @param cmap */ private void compareCIDSystemInfo(COSDictionary cmap) { COSDictionary fontDictionary = font.getCOSObject(); COSArray array = COSUtils.getAsArray(fontDictionary.getItem(COSName.DESCENDANT_FONTS), cosDocument); if (array != null && array.size() > 0) { COSDictionary cidFont = COSUtils.getAsDictionary(array.get(0), cosDocument); COSDictionary cmsi = COSUtils.getAsDictionary(cmap.getItem(COSName.CIDSYSTEMINFO), cosDocument); COSDictionary cfsi = COSUtils.getAsDictionary(cidFont.getItem(COSName.CIDSYSTEMINFO), cosDocument); String regCM = COSUtils.getAsString(cmsi.getItem(COSName.REGISTRY), cosDocument); String ordCM = COSUtils.getAsString(cmsi.getItem(COSName.ORDERING), cosDocument); String regCF = COSUtils.getAsString(cfsi.getItem(COSName.REGISTRY), cosDocument); String ordCF = COSUtils.getAsString(cfsi.getItem(COSName.ORDERING), cosDocument); if (!regCF.equals(regCM) || !ordCF.equals(ordCM)) { this.fontContainer.push(new ValidationError(ERROR_FONTS_CIDKEYED_SYSINFO, font.getName() + ": The CIDSystemInfo is inconsistent")); } } } }
@Override public String toString() { return getClass().getSimpleName() + " " + getName(); } }
@Override public void process(TrueTypeFont ttf) throws IOException { PDFont pdFont = PDType0Font.load(env.getDocument(), ttf, true); fontMap.put(fontEntry.overrideName, pdFont); fontMap.put(pdFont.getName(), pdFont); } });
public boolean equalToPDFont(PDFont compare) { // Appears you can have two different fonts with the same actual font name since text position font // references go off a seperate dict lookup name. PDFBox doesn't include the lookup name with the // PDFont, so might have to submit a change there to be really sure fonts are indeed the same. return compare.getName().equals(baseFont.getName()) && compare.getType().equals(baseFont.getType()) && compare.getSubType().equals(baseFont.getSubType()); }
/** * Returns true if this font is one of the "Standard 14" fonts and receives special handling. */ public boolean isStandard14() { // this logic is based on Acrobat's behaviour, see PDFBOX-2372 // embedded fonts never get special treatment if (isEmbedded()) { return false; } // if the name matches, this is a Standard 14 font return Standard14Fonts.containsName(getName()); }
public void addEntry(PDFont font) { FontTable.Entry entry = get(font); if (entry == null) { String fontName = font.getName(); String family = findFontFamily(fontName); String usedName = nextUsedName(family); FontTable.Entry newEntry = new FontTable.Entry(font.getName(), usedName, font); if (newEntry.isEntryValid()) add(newEntry); } }