Преглед изворни кода

made it easier to add xml handlers


git-svn-id: https://svn.apache.org/repos/asf/xmlgraphics/fop/trunk@194708 13f79535-47bb-0310-9956-ffa450edef68
pull/30/head
Keiron Liddle пре 22 година
родитељ
комит
e337eacb74

+ 8
- 3
src/org/apache/fop/apps/Driver.java Прегледај датотеку

@@ -173,6 +173,7 @@ public class Driver {
* the system resources that FOP will use
*/
private Logger log;
private FOUserAgent userAgent = null;

public static final String getParserClassName() {
String parserClassName = null;
@@ -192,6 +193,7 @@ public class Driver {
public Driver() {
_stream = null;
_treeBuilder = new FOTreeBuilder();
_treeBuilder.setUserAgent(getUserAgent());
setupDefaultMappings();
}

@@ -202,12 +204,15 @@ public class Driver {
}

public void setUserAgent(FOUserAgent agent) {
userAgent = agent;
}

private FOUserAgent getUserAgent() {
FOUserAgent ua = new FOUserAgent();
ua.setLogger(log);
return ua;
if(userAgent == null) {
userAgent = new FOUserAgent();
userAgent.setLogger(log);
}
return userAgent;
}

public void setLogger(Logger logger) {

+ 5
- 0
src/org/apache/fop/fo/FOTreeBuilder.java Прегледај датотеку

@@ -83,6 +83,11 @@ public class FOTreeBuilder extends DefaultHandler {
userAgent = ua;
}

public FOUserAgent getUserAgent() {
return userAgent;
}


public void setStreamRenderer(StreamRenderer streamRenderer) {
this.streamRenderer = streamRenderer;
}

+ 18
- 10
src/org/apache/fop/render/pdf/PDFXMLHandler.java Прегледај датотеку

@@ -59,7 +59,17 @@ public static final String PDF_YPOS = "ypos";

public void handleXML(RendererContext context, Document doc,
String ns) throws Exception {
PDFDocument pdfDoc = (PDFDocument) context.getProperty(PDF_DOCUMENT);
PDFInfo pdfi = getPDFInfo(context);

String svg = "http://www.w3.org/2000/svg";
if (svg.equals(ns)) {
SVGHandler svghandler = new SVGHandler();
svghandler.renderSVGDocument(context, doc, pdfi);
} else {
}
}

public static PDFInfo getPDFInfo(RendererContext context) {
PDFInfo pdfi = new PDFInfo();
pdfi.pdfDoc = (PDFDocument)context.getProperty(PDF_DOCUMENT);
pdfi.currentStream = (PDFStream)context.getProperty(PDF_STREAM);
@@ -70,18 +80,12 @@ public static final String PDF_YPOS = "ypos";
pdfi.currentFontSize = ((Integer)context.getProperty(PDF_FONT_SIZE)).intValue();
pdfi.currentXPosition = ((Integer)context.getProperty(PDF_XPOS)).intValue();
pdfi.currentYPosition = ((Integer)context.getProperty(PDF_YPOS)).intValue();

String svg = "http://www.w3.org/2000/svg";
if (svg.equals(ns)) {
SVGHandler svghandler = new SVGHandler();
svghandler.renderSVGDocument(context, doc, pdfi);
} else {
}
return pdfi;
}

class PDFInfo {
public static class PDFInfo {
PDFDocument pdfDoc;
PDFStream currentStream;
public PDFStream currentStream;
int x;
int y;
FontState fs;
@@ -91,6 +95,10 @@ public static final String PDF_YPOS = "ypos";
int currentYPosition;
}

/**
* This method is placed in an inner class so that we don't get class
* loading errors if batik is not present.
*/
protected class SVGHandler {
protected void renderSVGDocument(RendererContext context, Document doc, PDFInfo pdfInfo) {
float sx = 1, sy = 1;

Loading…
Откажи
Сачувај