*/
public static void process(FOUserAgent userAgent, InputStream in, OutputStream out,
FontInfo fontInfo, ResourceTracker resTracker, Map formResources, int pageCount)
throws DSCException, IOException {
DSCParser parser = new DSCParser(in);
PSGenerator gen = new PSGenerator(out);
parser.setNestedDocumentHandler(new DefaultNestedDocumentHandler(gen));
//Skip DSC header
DSCHeaderComment header = DSCTools.checkAndSkipDSC30Header(parser);
header.generate(gen);
parser.setFilter(new DSCFilter() {
private final Set filtered = new java.util.HashSet();
{
//We rewrite those as part of the processing
filtered.add(DSCConstants.PAGES);
filtered.add(DSCConstants.DOCUMENT_NEEDED_RESOURCES);
filtered.add(DSCConstants.DOCUMENT_SUPPLIED_RESOURCES);
}
public boolean accept(DSCEvent event) {
if (event.isDSCComment()) {
//Filter %%Pages which we add manually from a parameter
return !(filtered.contains(event.asDSCComment().getName()));
} else {
return true;
}
}
});
//Get PostScript language level (may be missing)
while (true) {
DSCEvent event = parser.nextEvent();
if (event == null) {
reportInvalidDSC();
}
if (DSCTools.headerCommentsEndHere(event)) {
//Set number of pages
DSCCommentPages pages = new DSCCommentPages(pageCount);
pages.generate(gen);
PSFontUtils.determineSuppliedFonts(resTracker, fontInfo, fontInfo.getUsedFonts());
registerSuppliedForms(resTracker, formResources);
//Supplied Resources
DSCCommentDocumentSuppliedResources supplied
= new DSCCommentDocumentSuppliedResources(
resTracker.getDocumentSuppliedResources());
supplied.generate(gen);
//Needed Resources
DSCCommentDocumentNeededResources needed
= new DSCCommentDocumentNeededResources(
resTracker.getDocumentNeededResources());
needed.generate(gen);
//Write original comment that ends the header comments
event.generate(gen);
break;
}
if (event.isDSCComment()) {
DSCComment comment = event.asDSCComment();
if (DSCConstants.LANGUAGE_LEVEL.equals(comment.getName())) {
DSCCommentLanguageLevel level = (DSCCommentLanguageLevel)comment;
gen.setPSLevel(level.getLanguageLevel());
}
}
event.generate(gen);
}