if (descriptor == null) {
//Usually Base 14 fonts
PDFFont font = new PDFFont(fontname, FontType.TYPE1, basefont, encoding);
getDocument().registerObject(font);
if (forceToUnicode && !PDFEncoding.isPredefinedEncoding(encoding)) {
SingleByteEncoding mapping;
if (encoding != null) {
mapping = CodePointMapping.getMapping(encoding);
} else {
//for Symbol and ZapfDingbats where encoding must be null in PDF
Typeface tf = (Typeface)metrics;
mapping = CodePointMapping.getMapping(tf.getEncodingName());
}
generateToUnicodeCmap(font, mapping);
}
return font;
} else {
FontType fonttype = metrics.getFontType();
String fontPrefix = descriptor.isSubsetEmbedded() ? createSubsetFontPrefix() : "";
String subsetFontName = fontPrefix + basefont;
PDFFontDescriptor pdfdesc = makeFontDescriptor(descriptor, fontPrefix);
PDFFont font = null;
font = PDFFont.createFont(fontname, fonttype, subsetFontName, null);
getDocument().registerObject(font);
if (fonttype == FontType.TYPE0) {
font.setEncoding(encoding);
CIDFont cidMetrics;
if (metrics instanceof LazyFont) {
cidMetrics = (CIDFont)((LazyFont) metrics).getRealFont();
} else {
cidMetrics = (CIDFont)metrics;
}
PDFCIDSystemInfo sysInfo
= new PDFCIDSystemInfo(cidMetrics.getRegistry(),
cidMetrics.getOrdering(),
cidMetrics.getSupplement());
PDFCIDFont cidFont = new PDFCIDFont(subsetFontName,
cidMetrics.getCIDType(),
cidMetrics.getDefaultWidth(),
getSubsetWidths(cidMetrics), sysInfo,
(PDFCIDFontDescriptor)pdfdesc);
getDocument().registerObject(cidFont);
PDFCMap cmap = new PDFToUnicodeCMap(
cidMetrics.getCIDSubset().getSubsetChars(),
"fop-ucs-H",
new PDFCIDSystemInfo("Adobe",
"Identity",
0), false);
getDocument().registerObject(cmap);
((PDFFontType0)font).setCMAP(cmap);
((PDFFontType0)font).setDescendantFonts(cidFont);
} else {
PDFFontNonBase14 nonBase14 = (PDFFontNonBase14)font;
nonBase14.setDescriptor(pdfdesc);
SingleByteFont singleByteFont;
if (metrics instanceof LazyFont) {
singleByteFont = (SingleByteFont)((LazyFont)metrics).getRealFont();
} else {
singleByteFont = (SingleByteFont)metrics;
}
int firstChar = singleByteFont.getFirstChar();
int lastChar = singleByteFont.getLastChar();
nonBase14.setWidthMetrics(firstChar,
lastChar,
new PDFArray(null, metrics.getWidths()));
//Handle encoding
SingleByteEncoding mapping = singleByteFont.getEncoding();
if (singleByteFont.isSymbolicFont()) {
//no encoding, use the font's encoding
if (forceToUnicode) {
generateToUnicodeCmap(nonBase14, mapping);
}
} else if (PDFEncoding.isPredefinedEncoding(mapping.getName())) {
font.setEncoding(mapping.getName());
//No ToUnicode CMap necessary if PDF 1.4, chapter 5.9 (page 368) is to be
//believed.
} else {
Object pdfEncoding = createPDFEncoding(mapping,
singleByteFont.getFontName());