use of org.apache.pdfbox.pdmodel.font.encoding.Encoding in project pdfbox by apache.
the class PDSimpleFont method readEncoding.
/**
* Reads the Encoding from the Font dictionary or the embedded or substituted font file.
* Must be called at the end of any subclass constructors.
*
* @throws IOException if the font file could not be read
*/
protected void readEncoding() throws IOException {
COSBase encoding = dict.getDictionaryObject(COSName.ENCODING);
if (encoding != null) {
if (encoding instanceof COSName) {
COSName encodingName = (COSName) encoding;
this.encoding = Encoding.getInstance(encodingName);
if (this.encoding == null) {
LOG.warn("Unknown encoding: " + encodingName.getName());
// fallback
this.encoding = readEncodingFromFont();
}
} else if (encoding instanceof COSDictionary) {
COSDictionary encodingDict = (COSDictionary) encoding;
Encoding builtIn = null;
Boolean symbolic = getSymbolicFlag();
boolean isFlaggedAsSymbolic = symbolic != null && symbolic;
COSName baseEncoding = encodingDict.getCOSName(COSName.BASE_ENCODING);
boolean hasValidBaseEncoding = baseEncoding != null && Encoding.getInstance(baseEncoding) != null;
if (!hasValidBaseEncoding && isFlaggedAsSymbolic) {
builtIn = readEncodingFromFont();
}
if (symbolic == null) {
symbolic = false;
}
this.encoding = new DictionaryEncoding(encodingDict, !symbolic, builtIn);
}
} else {
this.encoding = readEncodingFromFont();
}
// normalise the standard 14 name, e.g "Symbol,Italic" -> "Symbol"
String standard14Name = Standard14Fonts.getMappedFontName(getName());
// assign the glyph list based on the font
if ("ZapfDingbats".equals(standard14Name)) {
glyphList = GlyphList.getZapfDingbats();
} else {
// StandardEncoding and Symbol are in the AGL
glyphList = GlyphList.getAdobeGlyphList();
}
}
use of org.apache.pdfbox.pdmodel.font.encoding.Encoding in project pdfbox by apache.
the class TrueTypeFontValidator method checkEncoding.
@Override
protected void checkEncoding() {
PDTrueTypeFont ttFont = (PDTrueTypeFont) font;
PDFontDescriptor fd = ttFont.getFontDescriptor();
if (fd != null) {
/*
* only MacRomanEncoding or WinAnsiEncoding are allowed for a non symbolic font.
*/
if (fd.isNonSymbolic()) {
Encoding encodingValue = ttFont.getEncoding();
if (!(encodingValue instanceof MacRomanEncoding || encodingValue instanceof WinAnsiEncoding)) {
this.fontContainer.push(new ValidationError(ERROR_FONTS_ENCODING, fd.getFontName() + ": The Encoding is invalid for the NonSymbolic TTF"));
}
}
/*
* For symbolic font, no encoding entry is allowed and only one encoding entry is expected into the FontFile
* CMap (Check latter when the FontFile stream will be checked)
*/
if (fd.isSymbolic() && fontDictionary.getItem(COSName.ENCODING) != null) {
this.fontContainer.push(new ValidationError(ERROR_FONTS_ENCODING, fd.getFontName() + ": The Encoding should be missing for the Symbolic TTF"));
}
}
}
Aggregations