/** * 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"); }