浏览代码

Extended to allow generating the renderer and painter PDF alongside each other for visual inspection.

git-svn-id: https://svn.apache.org/repos/asf/xmlgraphics/fop/branches/Temp_AreaTreeNewDesign@686229 13f79535-47bb-0310-9956-ffa450edef68
pull/17/head
Jeremias Maerki 16 年前
父节点
当前提交
d62008677f

+ 14
- 6
test/java/org/apache/fop/visual/AbstractPSPDFBitmapProducer.java 查看文件

import org.apache.avalon.framework.configuration.Configuration; import org.apache.avalon.framework.configuration.Configuration;
import org.apache.avalon.framework.configuration.ConfigurationException; import org.apache.avalon.framework.configuration.ConfigurationException;
import org.apache.commons.io.IOUtils; import org.apache.commons.io.IOUtils;

import org.apache.fop.apps.FOUserAgent; import org.apache.fop.apps.FOUserAgent;
import org.apache.fop.apps.Fop; import org.apache.fop.apps.Fop;
import org.apache.fop.apps.FopFactory; import org.apache.fop.apps.FopFactory;


private String converter; private String converter;
private boolean deleteTempFiles; private boolean deleteTempFiles;
/** the bitmap producer's target format */
protected String targetFormat;


/** @see org.apache.avalon.framework.configuration.Configurable */
/** {@inheritDoc} */
public void configure(Configuration cfg) throws ConfigurationException { public void configure(Configuration cfg) throws ConfigurationException {
this.converter = cfg.getChild("converter").getValue(); this.converter = cfg.getChild("converter").getValue();
this.deleteTempFiles = cfg.getChild("delete-temp-files").getValueAsBoolean(true); this.deleteTempFiles = cfg.getChild("delete-temp-files").getValueAsBoolean(true);
if (cfg.getChild("target-format", false) != null) {
this.targetFormat = cfg.getChild("target-format").getValue();
}
} }


/** /**
/** /**
* @return the output format for the FOP renderer, i.e. a MIME type. * @return the output format for the FOP renderer, i.e. a MIME type.
*/ */
protected abstract String getTargetFormat();
protected String getTargetFormat() {
return this.targetFormat;
}


/** @see org.apache.fop.visual.BitmapProducer */
public BufferedImage produce(File src, ProducerContext context) {
/** {@inheritDoc} */
public BufferedImage produce(File src, int index, ProducerContext context) {
try { try {
FOUserAgent userAgent = fopFactory.newFOUserAgent(); FOUserAgent userAgent = fopFactory.newFOUserAgent();
userAgent.setTargetResolution(context.getTargetResolution()); userAgent.setTargetResolution(context.getTargetResolution());
userAgent.setBaseURL(src.getParentFile().toURL().toString()); userAgent.setBaseURL(src.getParentFile().toURL().toString());


File tempOut = new File(context.getTargetDir(), File tempOut = new File(context.getTargetDir(),
src.getName() + "." + getTargetExtension());
src.getName() + "." + index + "." + getTargetExtension());
File tempPNG = new File(context.getTargetDir(), File tempPNG = new File(context.getTargetDir(),
src.getName() + "." + getTargetExtension() + ".png");
src.getName() + "." + index + "." + getTargetExtension() + ".png");
try { try {
OutputStream out = new FileOutputStream(tempOut); OutputStream out = new FileOutputStream(tempOut);
out = new BufferedOutputStream(out); out = new BufferedOutputStream(out);

+ 1
- 1
test/java/org/apache/fop/visual/BatchDiffer.java 查看文件

final BufferedImage[] bitmaps = new BufferedImage[producers.length]; final BufferedImage[] bitmaps = new BufferedImage[producers.length];
for (int j = 0; j < producers.length; j++) { for (int j = 0; j < producers.length; j++) {
times[j] = System.currentTimeMillis(); times[j] = System.currentTimeMillis();
bitmaps[j] = producers[j].produce(f, context);
bitmaps[j] = producers[j].produce(f, j, context);
times[j] = System.currentTimeMillis() - times[j]; times[j] = System.currentTimeMillis() - times[j];
} }
if (log.isDebugEnabled()) { if (log.isDebugEnabled()) {

+ 2
- 1
test/java/org/apache/fop/visual/BitmapProducer.java 查看文件

* Produces a BufferedImage from the source file by invoking the FO processor and * Produces a BufferedImage from the source file by invoking the FO processor and
* converting the generated output file to a bitmap image if necessary. * converting the generated output file to a bitmap image if necessary.
* @param src the source FO or XML file * @param src the source FO or XML file
* @param index the index of the producer inside the test set
* @param context context information for the conversion * @param context context information for the conversion
* @return the generated BufferedImage * @return the generated BufferedImage
*/ */
BufferedImage produce(File src, ProducerContext context);
BufferedImage produce(File src, int index, ProducerContext context);


} }

+ 4
- 2
test/java/org/apache/fop/visual/BitmapProducerJava2D.java 查看文件

import org.apache.avalon.framework.configuration.Configuration; import org.apache.avalon.framework.configuration.Configuration;
import org.apache.avalon.framework.configuration.ConfigurationException; import org.apache.avalon.framework.configuration.ConfigurationException;
import org.apache.commons.io.IOUtils; import org.apache.commons.io.IOUtils;

import org.apache.fop.apps.FOUserAgent; import org.apache.fop.apps.FOUserAgent;
import org.apache.fop.apps.Fop; import org.apache.fop.apps.Fop;
import org.apache.fop.apps.FopFactory; import org.apache.fop.apps.FopFactory;
} }


/** @see org.apache.fop.visual.BitmapProducer */ /** @see org.apache.fop.visual.BitmapProducer */
public BufferedImage produce(File src, ProducerContext context) {
public BufferedImage produce(File src, int index, ProducerContext context) {
try { try {
FOUserAgent userAgent = fopFactory.newFOUserAgent(); FOUserAgent userAgent = fopFactory.newFOUserAgent();
userAgent.setTargetResolution(context.getTargetResolution()); userAgent.setTargetResolution(context.getTargetResolution());
userAgent.setBaseURL(src.getParentFile().toURL().toString()); userAgent.setBaseURL(src.getParentFile().toURL().toString());


File outputFile = new File(context.getTargetDir(), src.getName() + ".java2d.png");
File outputFile = new File(context.getTargetDir(),
src.getName() + "." + index + ".java2d.png");
OutputStream out = new FileOutputStream(outputFile); OutputStream out = new FileOutputStream(outputFile);
out = new BufferedOutputStream(out); out = new BufferedOutputStream(out);
try { try {

+ 8
- 6
test/java/org/apache/fop/visual/BitmapProducerPDF.java 查看文件

*/ */
public class BitmapProducerPDF extends AbstractPSPDFBitmapProducer { public class BitmapProducerPDF extends AbstractPSPDFBitmapProducer {


/** @see org.apache.fop.visual.AbstractPSPDFBitmapProducer#getTargetExtension() */
protected String getTargetExtension() {
return "pdf";
/**
* Default constructor.
*/
public BitmapProducerPDF() {
this.targetFormat = MimeConstants.MIME_PDF;
} }


/** @see org.apache.fop.visual.AbstractPSPDFBitmapProducer#getTargetFormat() */
protected String getTargetFormat() {
return MimeConstants.MIME_PDF;
/** {@inheritDoc} */
protected String getTargetExtension() {
return "pdf";
} }


} }

+ 8
- 7
test/java/org/apache/fop/visual/BitmapProducerPS.java 查看文件

*/ */
public class BitmapProducerPS extends AbstractPSPDFBitmapProducer { public class BitmapProducerPS extends AbstractPSPDFBitmapProducer {


/** @see org.apache.fop.visual.AbstractPSPDFBitmapProducer#getTargetExtension() */
protected String getTargetExtension() {
return "ps";
/**
* Default constructor.
*/
public BitmapProducerPS() {
this.targetFormat = MimeConstants.MIME_POSTSCRIPT;
} }


/** @see org.apache.fop.visual.AbstractPSPDFBitmapProducer#getTargetFormat() */
protected String getTargetFormat() {
return MimeConstants.MIME_POSTSCRIPT;
/** {@inheritDoc} */
protected String getTargetExtension() {
return "ps";
} }



} }

+ 1
- 1
test/java/org/apache/fop/visual/ReferenceBitmapLoader.java 查看文件

} }


/** @see org.apache.fop.visual.BitmapProducer */ /** @see org.apache.fop.visual.BitmapProducer */
public BufferedImage produce(File src, ProducerContext context) {
public BufferedImage produce(File src, int index, ProducerContext context) {
try { try {
File bitmap = new File(bitmapDirectory, src.getName() + ".png"); File bitmap = new File(bitmapDirectory, src.getName() + ".png");
if (bitmap.exists()) { if (bitmap.exists()) {

正在加载...
取消
保存