protected int width;
protected int height;
+
+ protected float viewportWidth;
+ protected float viewportHeight;
protected int pagecount;
protected boolean pagePending;
* @throws IOException in case of an I/O problem
*/
public void setSVGDimension(float w, float h) throws IOException {
+ this.viewportWidth = w;
+ this.viewportHeight = h;
+ /*
if (w != this.width || h != this.height) {
gen.concatMatrix(width / w, 0, 0, height / h, 0, 0);
- }
+ }*/
}
/**
writePageHeader();
gen.writeln("0.001 0.001 scale");
- gen.concatMatrix(1, 0, 0, -1, 0, this.height * 1000);
+ if ((this.viewportWidth != this.width
+ || this.viewportHeight != this.height)
+ && (this.viewportWidth > 0) && (this.viewportHeight > 0)){
+ gen.concatMatrix(this.width / this.viewportWidth, 0,
+ 0, -1 * (this.height / this.viewportHeight),
+ 0, this.height * 1000);
+ } else {
+ gen.concatMatrix(1, 0, 0, -1, 0, this.height * 1000);
+ }
gen.writeDSCComment(DSCConstants.END_PAGE_SETUP);
this.pagePending = true;
}
import org.apache.avalon.framework.configuration.Configuration;
import org.apache.avalon.framework.container.ContainerUtil;
import org.apache.batik.bridge.BridgeContext;
+import org.apache.batik.bridge.UnitProcessor;
import org.apache.batik.transcoder.TranscoderException;
import org.apache.batik.transcoder.TranscoderOutput;
import org.apache.fop.svg.AbstractFOPTranscoder;
import org.w3c.dom.Document;
+import org.w3c.dom.svg.SVGLength;
/**
* This class enables to transcode an input to a PostScript document.
protected abstract AbstractPSDocumentGraphics2D createDocumentGraphics2D();
- protected BridgeContext createBridgeContext() {
- /*boolean stroke = true;
- if (hints.containsKey(KEY_STROKE_TEXT)) {
- stroke = ((Boolean)hints.get(KEY_STROKE_TEXT)).booleanValue();
- }*/
-
- BridgeContext ctx = new BridgeContext(userAgent);
- PSTextPainter textPainter = new PSTextPainter(graphics.getFontInfo());
- ctx.setTextPainter(textPainter);
- ctx.putBridge(new PSTextElementBridge(textPainter));
-
- //ctx.putBridge(new PSImageElementBridge());
- return ctx;
- }
-
/**
* Transcodes the specified Document as an image in the specified output.
*
super.transcode(document, uri, output);
+ getLogger().trace("document size: " + width + " x " + height);
+
// prepare the image to be painted
- int w = (int)(width + 0.5);
- int h = (int)(height + 0.5);
+ UnitProcessor.Context uctx = UnitProcessor.createContext(ctx,
+ document.getDocumentElement());
+ float widthInPt = UnitProcessor.userSpaceToSVG(width, SVGLength.SVG_LENGTHTYPE_PT,
+ UnitProcessor.HORIZONTAL_LENGTH, uctx);
+ int w = (int)(widthInPt + 0.5);
+ float heightInPt = UnitProcessor.userSpaceToSVG(height, SVGLength.SVG_LENGTHTYPE_PT,
+ UnitProcessor.HORIZONTAL_LENGTH, uctx);
+ int h = (int)(heightInPt + 0.5);
+ getLogger().trace("document size: " + w + "pt x " + h + "pt");
+
try {
graphics.setupDocument(output.getOutputStream(), w, h);
}
}
+ protected BridgeContext createBridgeContext() {
+ /*boolean stroke = true;
+ if (hints.containsKey(KEY_STROKE_TEXT)) {
+ stroke = ((Boolean)hints.get(KEY_STROKE_TEXT)).booleanValue();
+ }*/
+
+ BridgeContext ctx = new BridgeContext(userAgent);
+ PSTextPainter textPainter = new PSTextPainter(graphics.getFontInfo());
+ ctx.setTextPainter(textPainter);
+ ctx.putBridge(new PSTextElementBridge(textPainter));
+
+ //ctx.putBridge(new PSImageElementBridge());
+ return ctx;
+ }
+
}
private PDFPage currentPage;
private PDFStream pdfStream;
+
private int width;
private int height;
+
private List fontList;
private Log logger;
import org.apache.avalon.framework.configuration.ConfigurationException;
import org.apache.avalon.framework.container.ContainerUtil;
import org.apache.batik.bridge.BridgeContext;
+import org.apache.batik.bridge.UnitProcessor;
import org.apache.batik.bridge.UserAgent;
import org.apache.batik.gvt.TextPainter;
import org.apache.batik.gvt.renderer.StrokingTextPainter;
import org.apache.batik.transcoder.TranscoderOutput;
import org.apache.batik.transcoder.image.ImageTranscoder;
import org.w3c.dom.Document;
+import org.w3c.dom.svg.SVGLength;
/**
* This class enables to transcode an input to a pdf document.
return new AbstractFOPTranscoder.FOPTranscoderUserAgent() {
// The PDF stuff wants everything at 72dpi
public float getPixelUnitToMillimeter() {
- //return super.getPixelUnitToMillimeter();
- return 25.4f / 72; //72dpi = 0.352778f;
+ return super.getPixelUnitToMillimeter();
+ //return 25.4f / 72; //72dpi = 0.352778f;
}
};
}
getLogger().trace("document size: " + width + " x " + height);
// prepare the image to be painted
- int w = (int)(width + 0.5);
- int h = (int)(height + 0.5);
+ UnitProcessor.Context uctx = UnitProcessor.createContext(ctx,
+ document.getDocumentElement());
+ float widthInPt = UnitProcessor.userSpaceToSVG(width, SVGLength.SVG_LENGTHTYPE_PT,
+ UnitProcessor.HORIZONTAL_LENGTH, uctx);
+ int w = (int)(widthInPt + 0.5);
+ float heightInPt = UnitProcessor.userSpaceToSVG(height, SVGLength.SVG_LENGTHTYPE_PT,
+ UnitProcessor.HORIZONTAL_LENGTH, uctx);
+ int h = (int)(heightInPt + 0.5);
+ getLogger().trace("document size: " + w + "pt x " + h + "pt");
+
+ // prepare the image to be painted
+ //int w = (int)(width + 0.5);
+ //int h = (int)(height + 0.5);
try {
graphics.setupDocument(output.getOutputStream(), w, h);
- graphics.setSVGDimension(w, h);
+ graphics.setSVGDimension(width, height);
if (hints.containsKey(ImageTranscoder.KEY_BACKGROUND_COLOR)) {
graphics.setBackgroundColor