Map fonts = fontInfo.getFonts();
Map fontResources = new java.util.HashMap();
Iterator iter = fonts.keySet().iterator();
while (iter.hasNext()) {
String key = (String)iter.next();
Typeface tf = (Typeface)fonts.get(key);
if (tf instanceof LazyFont) {
tf = ((LazyFont)tf).getRealFont();
}
if (tf == null) {
//This is to avoid an NPE if a malconfigured font is in the configuration but not
//used in the document. If it were used, we wouldn't get this far.
String fallbackKey = fontInfo.getInternalFontKey(Font.DEFAULT_FONT);
tf = (Typeface)fonts.get(fallbackKey);
}
PSResource fontRes = new PSResource("font", tf.getFontName());
fontResources.put(key, fontRes);
boolean embeddedFont = false;
if (FontType.TYPE1 == tf.getFontType()) {
if (tf instanceof CustomFont) {
CustomFont cf = (CustomFont)tf;
InputStream in = getInputStreamOnFont(gen, cf);
if (in != null) {
gen.writeDSCComment(DSCConstants.BEGIN_RESOURCE,
fontRes);
embedType1Font(gen, in);
gen.writeDSCComment(DSCConstants.END_RESOURCE);
gen.notifyResourceUsage(fontRes, false);
embeddedFont = true;
}
}
}
if (!embeddedFont) {
gen.writeDSCComment(DSCConstants.INCLUDE_RESOURCE, fontRes);
//Resource usage shall be handled by renderer
//gen.notifyResourceUsage(fontRes, true);
}
gen.commentln("%FOPBeginFontKey: " + key);
gen.writeln("/" + key + " /" + tf.getFontName() + " def");
gen.commentln("%FOPEndFontKey");
}
gen.writeln("end def");
gen.commentln("%FOPEndFontDict");
gen.commentln("%FOPBeginFontReencode");
defineWinAnsiEncoding(gen);
//Rewrite font encodings
iter = fonts.keySet().iterator();
while (iter.hasNext()) {
String key = (String)iter.next();
Typeface fm = (Typeface)fonts.get(key);
if (fm instanceof LazyFont && ((LazyFont)fm).getRealFont() == null) {
continue;
} else if (null == fm.getEncoding()) {
//ignore (ZapfDingbats and Symbol run through here
//TODO: ZapfDingbats and Symbol should get getEncoding() fixed!
} else if ("WinAnsiEncoding".equals(fm.getEncoding())) {
gen.writeln("/" + fm.getFontName() + " findfont");
gen.writeln("dup length dict begin");
gen.writeln(" {1 index /FID ne {def} {pop pop} ifelse} forall");
gen.writeln(" /Encoding " + fm.getEncoding() + " def");
gen.writeln(" currentdict");
gen.writeln("end");
gen.writeln("/" + fm.getFontName() + " exch definefont pop");
} else {
gen.commentln("%WARNING: Only WinAnsiEncoding is supported. Font '"
+ fm.getFontName() + "' asks for: " + fm.getEncoding());
}
}
gen.commentln("%FOPEndFontReencode");
return fontResources;
}