/** @return the lazily created font descriptor of this font */ protected PDFontDescriptor createFontDescriptor() { COSObject base = cosGetField(DK_FontDescriptor); if (base.isNull()) { return createBuiltinFontDescriptor(); } return (PDFontDescriptorEmbedded) PDFontDescriptorEmbedded.META.createFromCos(base); }
/** * set an encoding for the font * * @param newFontEncoding the new encoding to use */ public void setEncoding(Encoding newFontEncoding) { cachedEncoding = newFontEncoding; if (newFontEncoding != null) { COSObject ref = cachedEncoding.cosGetObject(); if (ref == null || ref.isNull()) { cosRemoveField(DK_Encoding); } else { cosSetField(DK_Encoding, ref); } } else { cosRemoveField(DK_Encoding); } }
/** * Create the encoding for the font. The encoding is specified either "by default", as a known * encoding name or a completely user defined difference encoding. * * <p>This is redefined for composite fonts, which use a different implementation. * * @return The encoding object for the font. * @throws IllegalArgumentException When the encoding defined in the font is not supported. */ protected Encoding createEncoding() { COSObject encoding = cosGetField(PDFont.DK_Encoding); if (encoding.isNull()) { return createDefaultEncoding(); } if (encoding instanceof COSName) { try { return Encoding.createNamed((COSName) encoding); } catch (Exception e) { // found PDF where the base name was /NULL... return createDefaultEncoding(); } } if (encoding instanceof COSDictionary) { return DifferenceEncoding.create((COSDictionary) encoding, this); } throw new IllegalArgumentException("encoding not supported"); }
/** * Answer true if this font's program is embedded within the document. * * @return Answer true if this font's program is embedded within the document. */ public boolean isEmbedded() { // shortcut for builtin fonts COSObject base = cosGetField(DK_FontDescriptor); if (base.isNull() && !(this instanceof PDFontType0)) { return false; } if (getFontDescriptor() == null) { return false; } if (getFontDescriptor().getFontFile() != null) { return true; } if (getFontDescriptor().getFontFile2() != null) { return true; } if (getFontDescriptor().getFontFile3() != null) { return true; } return false; }
public COSObject cosGetData() { COSObject data = cosGetField(DK_Data); return data.isNull() ? null : data; }