Browse Source

added external image handler


git-svn-id: https://svn.apache.org/repos/asf/xmlgraphics/fop/trunk@194695 13f79535-47bb-0310-9956-ffa450edef68
tags/fop-0_20_4-doc
Keiron Liddle 22 years ago
parent
commit
8f766d59eb

+ 1
- 1
contrib/plan/build.sh View File

@@ -12,7 +12,7 @@ if [ "$JAVA_HOME" = "" ] ; then
exit 1
fi
LIBDIR=../../lib
LOCALCLASSPATH=$JAVA_HOME/lib/tools.jar:$JAVA_HOME/lib/classes.zip:$LIBDIR/ant.jar:$LIBDIR/batik.jar:$LIBDIR/buildtools.jar:$LIBDIR/xerces-1.4.3.jar:$LIBDIR/xalan-2.2D11.jar:../../build/fop.jar
LOCALCLASSPATH=$JAVA_HOME/lib/tools.jar:$JAVA_HOME/lib/classes.zip:$LIBDIR/ant.jar:$LIBDIR/batik.jar:$LIBDIR/buildtools.jar:$LIBDIR/xerces-1.4.3.jar:$LIBDIR/xalan-2.2D11.jar:../../build/fop.jar:$LIBDIR/logkit-1.0.jar
ANT_HOME=$LIBDIR

echo

+ 1
- 1
contrib/plan/build.xml View File

@@ -15,7 +15,7 @@
<property name="name" value="plan"/>
<property name="version" value="0.1-CVS"/>
<filter token="version" value="${version}"/>
<property name="year" value="2001"/>
<property name="year" value="2002"/>

<echo message="------------------- ${Name} ${version} [${year}] ----------------"/>


+ 7
- 0
contrib/plan/docs/plan.fo View File

@@ -101,6 +101,13 @@ All other options are set in the style attribute.

</fo:block>

<fo:block>
A plan as an external graphic.
</fo:block>

<fo:block>
<fo:external-graphic src="june.xml"/>
</fo:block>
</fo:flow>
</fo:page-sequence>
</fo:root>

+ 2
- 5
contrib/plan/src/org/apache/fop/plan/Main.java View File

@@ -48,15 +48,12 @@ public class Main {
public Document createSVGDocument(InputStream is) {
Document doc = null;

Element svgRoot = null;
Element root = null;
try {
// DOMImplementation impl = javax.xml.parsers.DocumentBuilderFactory.newInstance().newDocumentBuilder().getDOMImplementation();
// String ns = GraphElementMapping.URI;
// doc = impl.createDocument(ns, "graph", null);
doc = javax.xml.parsers.DocumentBuilderFactory.newInstance().
newDocumentBuilder().parse(is);

svgRoot = doc.getDocumentElement();
root = doc.getDocumentElement();

} catch (Exception e) {
e.printStackTrace();

+ 12
- 1
contrib/plan/src/org/apache/fop/plan/PlanElement.java View File

@@ -23,6 +23,7 @@ public class PlanElement extends PlanObj {
Document svgDoc = null;
float width;
float height;
boolean converted;

public PlanElement(FONode parent) {
super(parent);
@@ -34,7 +35,9 @@ public class PlanElement extends PlanObj {
}

public void convertToSVG() {
if(svgDoc == null && doc != null) {
try {
if(!converted) {
converted = true;
PlanRenderer pr = new PlanRenderer();
pr.setFontInfo("Helvetica", 12);
svgDoc = pr.createSVGDocument(doc);
@@ -43,6 +46,11 @@ public class PlanElement extends PlanObj {

doc = svgDoc;
}
} catch(Throwable t) {
log.error("Could not convert Plan to SVG", t);
width = 0;
height = 0;
}

}

@@ -52,6 +60,9 @@ public class PlanElement extends PlanObj {
}

public String getDocumentNamespace() {
if(svgDoc == null) {
return PlanElementMapping.URI;
}
return "http://www.w3.org/2000/svg";
}


+ 25
- 0
contrib/plan/src/org/apache/fop/plan/PlanElementMapping.java View File

@@ -7,6 +7,9 @@
package org.apache.fop.plan;

import org.apache.fop.fo.*;
import org.apache.fop.image.analyser.XMLReader;
import org.apache.fop.image.FopImage;
import org.w3c.dom.Document;

import java.util.HashMap;

@@ -21,6 +24,8 @@ public class PlanElementMapping implements ElementMapping {
foObjs = new HashMap();
foObjs.put("plan", new PE());
foObjs.put(DEFAULT, new PlanMaker());

XMLReader.setConverter(URI, new PlanConverter());
}
}

@@ -41,4 +46,24 @@ public class PlanElementMapping implements ElementMapping {
}
}

static class PlanConverter implements XMLReader.Converter {
public FopImage.ImageInfo convert(Document doc) {
try {
PlanRenderer pr = new PlanRenderer();
pr.setFontInfo("Helvetica", 12);
FopImage.ImageInfo info = new FopImage.ImageInfo();
info.data = pr.createSVGDocument(doc);
info.width = (int)pr.getWidth();
info.height = (int)pr.getHeight();
info.mimeType = "image/svg+xml";
info.str = "http://www.w3.org/2000/svg";

return info;
} catch(Throwable t) {
}
return null;

}
}

}

Loading…
Cancel
Save