reduced dependancy on Configuration git-svn-id: https://svn.apache.org/repos/asf/xmlgraphics/fop/trunk@195039 13f79535-47bb-0310-9956-ffa450edef68pull/30/head
package org.apache.fop.configuration; | package org.apache.fop.configuration; | ||||
import org.apache.fop.render.pdf.EmbedFontInfo; | |||||
import org.apache.fop.render.pdf.FontTriplet; | |||||
// sax | // sax | ||||
import org.xml.sax.helpers.DefaultHandler; | import org.xml.sax.helpers.DefaultHandler; | ||||
import org.xml.sax.Attributes; | import org.xml.sax.Attributes; | ||||
private ArrayList fontList = null; | private ArrayList fontList = null; | ||||
// stores information on one font | // stores information on one font | ||||
private FontInfo fontInfo = null; | |||||
private EmbedFontInfo fontInfo = null; | |||||
// stores information on a font triplet | // stores information on a font triplet | ||||
private FontTriplet fontTriplet = null; | private FontTriplet fontTriplet = null; | ||||
} else if (localName.equals("fonts")) { | } else if (localName.equals("fonts")) { | ||||
this.store("standard", "fonts", fontList); | this.store("standard", "fonts", fontList); | ||||
} else if (localName.equals("font")) { | } else if (localName.equals("font")) { | ||||
fontInfo = new FontInfo(fontName, metricsFile, kerning, | |||||
fontInfo = new EmbedFontInfo(fontName, metricsFile, kerning, | |||||
fontTriplets, embedFile); | fontTriplets, embedFile); | ||||
fontList.add(fontInfo); | fontList.add(fontInfo); | ||||
fontTriplets = null; | fontTriplets = null; |
public MIFHandler(OutputStream os) { | public MIFHandler(OutputStream os) { | ||||
outStream = os; | outStream = os; | ||||
// use pdf fonts for now, this is only for resolving names | // use pdf fonts for now, this is only for resolving names | ||||
org.apache.fop.render.pdf.FontSetup.setup(fontInfo); | |||||
org.apache.fop.render.pdf.FontSetup.setup(fontInfo, org.apache.fop.configuration.Configuration.getFonts()); | |||||
} | } | ||||
public FontInfo getFontInfo() { | public FontInfo getFontInfo() { |
* time to work out, and is so obvious now. Sigh. | * time to work out, and is so obvious now. Sigh. | ||||
* mark-fop@inomial.com. Maybe I should do a PDF course. | * mark-fop@inomial.com. Maybe I should do a PDF course. | ||||
*/ | */ | ||||
public PDFDocument() { | |||||
public PDFDocument(String prod) { | |||||
/* create the /Root, /Info and /Resources objects */ | /* create the /Root, /Info and /Resources objects */ | ||||
this.pages = makePages(); | this.pages = makePages(); | ||||
this.resources = makeResources(); | this.resources = makeResources(); | ||||
// Make the /Info record | // Make the /Info record | ||||
this.info = makeInfo(); | |||||
this.info = makeInfo(prod); | |||||
} | } | ||||
/** | /** | ||||
* @param producer string indicating application producing the PDF | * @param producer string indicating application producing the PDF | ||||
* @return the created /Info object | * @return the created /Info object | ||||
*/ | */ | ||||
protected PDFInfo makeInfo() { | |||||
protected PDFInfo makeInfo(String prod) { | |||||
/* | /* | ||||
* create a PDFInfo with the next object number and add to | * create a PDFInfo with the next object number and add to | ||||
*/ | */ | ||||
PDFInfo pdfInfo = new PDFInfo(++this.objectcount); | PDFInfo pdfInfo = new PDFInfo(++this.objectcount); | ||||
// set the default producer | // set the default producer | ||||
pdfInfo.setProducer(org.apache.fop.apps.Version.getVersion()); | |||||
pdfInfo.setProducer(prod); | |||||
this.objects.add(pdfInfo); | this.objects.add(pdfInfo); | ||||
return pdfInfo; | return pdfInfo; | ||||
} | } | ||||
* Create a PDFICCStream | * Create a PDFICCStream | ||||
@see PDFXObject | @see PDFXObject | ||||
@see org.apache.fop.image.JpegImage | @see org.apache.fop.image.JpegImage | ||||
@see org.apache.fop.datatypes.ColorSpace | |||||
@see org.apache.fop.pdf.PDFColorSpace | |||||
*/ | */ | ||||
public PDFICCStream makePDFICCStream() { | public PDFICCStream makePDFICCStream() { | ||||
PDFICCStream iccStream = new PDFICCStream(++this.objectcount); | PDFICCStream iccStream = new PDFICCStream(++this.objectcount); |
*/ | */ | ||||
public void setupFontInfo(FontInfo fontInfo) { | public void setupFontInfo(FontInfo fontInfo) { | ||||
this.fontInfo = fontInfo; | this.fontInfo = fontInfo; | ||||
FontSetup.setup(fontInfo); | |||||
FontSetup.setup(fontInfo, org.apache.fop.configuration.Configuration.getFonts()); | |||||
} | } | ||||
/** | /** |
* LICENSE file included with these sources. | * LICENSE file included with these sources. | ||||
*/ | */ | ||||
package org.apache.fop.configuration; | |||||
package org.apache.fop.render.pdf; | |||||
import java.util.ArrayList; | import java.util.ArrayList; | ||||
/** | /** | ||||
* FontInfo contains meta information on fonts (where is the metrics file etc.) | * FontInfo contains meta information on fonts (where is the metrics file etc.) | ||||
*/ | */ | ||||
public class FontInfo { | |||||
public class EmbedFontInfo { | |||||
private String metricsFile, embedFile, name; | private String metricsFile, embedFile, name; | ||||
private boolean kerning; | private boolean kerning; | ||||
private ArrayList fontTriplets; | private ArrayList fontTriplets; | ||||
public FontInfo(String name, String metricsFile, boolean kerning, | |||||
public EmbedFontInfo(String name, String metricsFile, boolean kerning, | |||||
ArrayList fontTriplets, String embedFile) { | ArrayList fontTriplets, String embedFile) { | ||||
this.name = name; | this.name = name; | ||||
this.metricsFile = metricsFile; | this.metricsFile = metricsFile; |
import org.apache.fop.layout.FontDescriptor; | import org.apache.fop.layout.FontDescriptor; | ||||
import org.apache.fop.pdf.PDFDocument; | import org.apache.fop.pdf.PDFDocument; | ||||
import org.apache.fop.pdf.PDFResources; | import org.apache.fop.pdf.PDFResources; | ||||
import org.apache.fop.configuration.Configuration; | |||||
import org.apache.fop.configuration.FontTriplet; | |||||
// Java | // Java | ||||
import java.util.HashMap; | import java.util.HashMap; | ||||
* | * | ||||
* @param fontInfo the font info object to set up | * @param fontInfo the font info object to set up | ||||
*/ | */ | ||||
public static void setup(FontInfo fontInfo) { | |||||
public static void setup(FontInfo fontInfo, ArrayList embedList) { | |||||
fontInfo.addMetrics("F1", new Helvetica()); | fontInfo.addMetrics("F1", new Helvetica()); | ||||
fontInfo.addMetrics("F2", new HelveticaOblique()); | fontInfo.addMetrics("F2", new HelveticaOblique()); | ||||
"normal", FontInfo.NORMAL); | "normal", FontInfo.NORMAL); | ||||
/* Add configured fonts */ | /* Add configured fonts */ | ||||
addConfiguredFonts(fontInfo, 15); | |||||
addConfiguredFonts(fontInfo, embedList, 15); | |||||
} | } | ||||
/** | /** | ||||
* Add fonts from configuration file starting with | * Add fonts from configuration file starting with | ||||
* internalnames F<num> | * internalnames F<num> | ||||
*/ | */ | ||||
public static void addConfiguredFonts(FontInfo fontInfo, int num) { | |||||
public static void addConfiguredFonts(FontInfo fontInfo, ArrayList fontInfos, int num) { | |||||
if (fontInfos == null) | |||||
return; | |||||
String internalName = null; | String internalName = null; | ||||
FontReader reader = null; | FontReader reader = null; | ||||
ArrayList fontInfos = Configuration.getFonts(); | |||||
if (fontInfos == null) | |||||
return; | |||||
for (int count = 0; count < fontInfos.size(); count++) { | for (int count = 0; count < fontInfos.size(); count++) { | ||||
org.apache.fop.configuration.FontInfo configFontInfo = | |||||
(org.apache.fop.configuration.FontInfo)fontInfos.get(count); | |||||
EmbedFontInfo configFontInfo = | |||||
(EmbedFontInfo)fontInfos.get(count); | |||||
try { | |||||
String metricsFile = configFontInfo.getMetricsFile(); | String metricsFile = configFontInfo.getMetricsFile(); | ||||
if (metricsFile != null) { | if (metricsFile != null) { | ||||
internalName = "F" + num; | internalName = "F" + num; | ||||
weight); | weight); | ||||
} | } | ||||
} | } | ||||
} catch (Exception ex) { | |||||
//log.error("Failed to read font metrics file " | |||||
// + configFontInfo.getMetricsFile() | |||||
// + " : " + ex.getMessage()); | |||||
} | |||||
} | } | ||||
} | } | ||||
font.encoding(), font, desc)); | font.encoding(), font, desc)); | ||||
} | } | ||||
} | } | ||||
} | } | ||||
* LICENSE file included with these sources. | * LICENSE file included with these sources. | ||||
*/ | */ | ||||
package org.apache.fop.configuration; | |||||
package org.apache.fop.render.pdf; | |||||
/** | /** | ||||
* FontTriplet contains information on name, weight, style of one font | * FontTriplet contains information on name, weight, style of one font | ||||
*/ | */ | ||||
public class FontTriplet { | public class FontTriplet { | ||||
private String name, weight, style; | private String name, weight, style; | ||||
public FontTriplet(String name, String weight, String style) { | public FontTriplet(String name, String weight, String style) { | ||||
public String getStyle() { | public String getStyle() { | ||||
return style; | return style; | ||||
} | } | ||||
} | } | ||||
import org.apache.fop.fo.FOUserAgent; | import org.apache.fop.fo.FOUserAgent; | ||||
import org.apache.fop.image.*; | import org.apache.fop.image.*; | ||||
import org.apache.fop.apps.FOPException; | import org.apache.fop.apps.FOPException; | ||||
import org.apache.fop.apps.Version; | |||||
import org.apache.fop.fo.properties.*; | import org.apache.fop.fo.properties.*; | ||||
import org.apache.fop.datatypes.*; | import org.apache.fop.datatypes.*; | ||||
import org.apache.fop.pdf.*; | import org.apache.fop.pdf.*; | ||||
public void startRenderer(OutputStream stream) throws IOException { | public void startRenderer(OutputStream stream) throws IOException { | ||||
ostream = stream; | ostream = stream; | ||||
this.pdfDoc = new PDFDocument(); | |||||
this.pdfDoc = new PDFDocument(Version.getVersion()); | |||||
this.pdfDoc.setProducer(producer); | this.pdfDoc.setProducer(producer); | ||||
pdfDoc.outputHeader(stream); | pdfDoc.outputHeader(stream); | ||||
} | } |
*/ | */ | ||||
public void setupFontInfo(FontInfo fontInfo) { | public void setupFontInfo(FontInfo fontInfo) { | ||||
/* use PDF's font setup to get PDF metrics */ | /* use PDF's font setup to get PDF metrics */ | ||||
org.apache.fop.render.pdf.FontSetup.setup(fontInfo); | |||||
org.apache.fop.render.pdf.FontSetup.setup(fontInfo, org.apache.fop.configuration.Configuration.getFonts()); | |||||
this.fontInfo = fontInfo; | this.fontInfo = fontInfo; | ||||
} | } | ||||
public void setupFontInfo(FontInfo fontInfo) { | public void setupFontInfo(FontInfo fontInfo) { | ||||
/* use PDF's font setup to get PDF metrics */ | /* use PDF's font setup to get PDF metrics */ | ||||
org.apache.fop.render.pdf.FontSetup.setup(fontInfo); | |||||
org.apache.fop.render.pdf.FontSetup.setup(fontInfo, org.apache.fop.configuration.Configuration.getFonts()); | |||||
} | } | ||||
private boolean isCoarseXml() { | private boolean isCoarseXml() { |
if(!textAsShapes) { | if(!textAsShapes) { | ||||
fontInfo = new FontInfo(); | fontInfo = new FontInfo(); | ||||
FontSetup.setup(fontInfo); | |||||
FontSetup.setup(fontInfo, null); | |||||
//FontState fontState = new FontState("Helvetica", "normal", | //FontState fontState = new FontState("Helvetica", "normal", | ||||
// FontInfo.NORMAL, 12, 0); | // FontInfo.NORMAL, 12, 0); | ||||
} | } | ||||
standalone = true; | standalone = true; | ||||
this.pdfDoc = new PDFDocument(); | |||||
this.pdfDoc.setProducer("FOP SVG Renderer"); | |||||
this.pdfDoc = new PDFDocument("FOP SVG Renderer"); | |||||
graphicsState = new PDFState(); | graphicsState = new PDFState(); | ||||
Rectangle2D rect = pp.getPatternRect(); | Rectangle2D rect = pp.getPatternRect(); | ||||
FontInfo fi = new FontInfo(); | FontInfo fi = new FontInfo(); | ||||
FontSetup.setup(fi); | |||||
FontSetup.setup(fi, null); | |||||
PDFResources res = pdfDoc.makeResources(); | PDFResources res = pdfDoc.makeResources(); | ||||
PDFResourceContext context = new PDFResourceContext(0, pdfDoc, res); | PDFResourceContext context = new PDFResourceContext(0, pdfDoc, res); |