public abstract String getNameSpace();
protected static HashMap ns = new HashMap();
+ static {
+ ns.put("xlink", "http://www.w3.org/1999/xlink");
+ }
public void addElement(Document doc, Element parent) {
this.doc = doc;
element = doc.createElementNS(getNameSpace(), name);
- for (int count = 0; count < attr.getLength(); count++) {
- String rf = attr.getValue(count);
- String qname = attr.getQName(count);
- if (qname.indexOf(":") == -1) {
- element.setAttribute(qname, rf);
+ for (int count = 0; count < attr.getLength(); count++) {
+ String rf = attr.getValue(count);
+ String qname = attr.getQName(count);
+ int idx = qname.indexOf(":");
+ if (idx == -1) {
+ element.setAttribute(qname, rf);
+ } else {
+ String pref = qname.substring(0, idx);
+ String tail = qname.substring(idx + 1);
+ if (pref.equals("xmlns")) {
+ ns.put(tail, rf);
} else {
- String pref =
- qname.substring(0, qname.indexOf(":"));
- if (pref.equals("xmlns")) {
- ns.put(qname.substring(qname.indexOf(":")
- + 1), rf);
- }
- ns.put("xlink", "http://www.w3.org/1999/xlink");
- element.setAttributeNS((String)ns.get(pref),
- qname, rf);
+ element.setAttributeNS((String)ns.get(pref), tail, rf);
}
}
+ }
attr = null;
parent.appendChild(element);
}
public void buildTopLevel(Document doc, Element svgRoot) {
// build up the info for the top level element
- for (int count = 0; count < attr.getLength(); count++) {
- String rf = attr.getValue(count);
- String qname = attr.getQName(count);
- if (qname.indexOf(":") == -1) {
- element.setAttribute(qname, rf);
+ for (int count = 0; count < attr.getLength(); count++) {
+ String rf = attr.getValue(count);
+ String qname = attr.getQName(count);
+ int idx = qname.indexOf(":");
+ if (idx == -1) {
+ element.setAttribute(qname, rf);
+ } else {
+ String pref = qname.substring(0, idx);
+ String tail = qname.substring(idx + 1);
+ if (pref.equals("xmlns")) {
+ ns.put(tail, rf);
} else {
- String pref =
- qname.substring(0, qname.indexOf(":"));
- if (pref.equals("xmlns")) {
- ns.put(qname.substring(qname.indexOf(":")
- + 1), rf);
- }
- ns.put("xlink", "http://www.w3.org/1999/xlink");
- element.setAttributeNS((String)ns.get(pref),
- qname, rf);
+ element.setAttributeNS((String)ns.get(pref), tail, rf);
}
}
+ }
}
public Document createBasicDocument() {
}
public String getMedia() {
- return "";
+ return "print";
}
/**
package org.apache.fop.layout;
import java.util.HashMap;
-import org.apache.fop.messaging.MessageHandler;
import java.util.Enumeration;
import org.apache.fop.apps.FOPException;
if (f == null) {
throw new FOPException("no default font defined by OutputConverter");
}
- MessageHandler.errorln("defaulted font to any,normal,normal");
+ //MessageHandler.errorln("defaulted font to any,normal,normal");
}
- MessageHandler.errorln("unknown font " + key
- + " so defaulted font to any");
+ //MessageHandler.errorln("unknown font " + key
+ // + " so defaulted font to any");
}
usedFonts.put(f, fonts.get(f));
/* add it to the list of objects */
this.objects.add(page);
-
+ pages.addPage(page);
return page;
}
currentFontSize = 0;
currentYPosition = 0;
currentXPosition = 0;
-
- PDFResources pdfResources = this.pdfDoc.getResources();
- currentPage = this.pdfDoc.makePage(pdfResources,
- width, height);
}
void setupDocument(OutputStream stream, int width, int height) {
this.width = width;
this.height = height;
this.stream = stream;
+
+ PDFResources pdfResources = this.pdfDoc.getResources();
+ currentPage = this.pdfDoc.makePage(pdfResources,
+ width, height);
currentStream.write("1 0 0 -1 0 " + height + " cm\n");
}
pdfDoc.outputTrailer(stream);
}
- public void setGraphicContext(GraphicContext c) {
- gc = c;
- }
-
/**
* This constructor supports the create method
*/
}
public String getMedia() {
- return "";
+ return "print";
}
/**
import org.apache.batik.gvt.renderer.*;
import org.apache.batik.gvt.filter.*;
import org.apache.batik.gvt.event.*;
+import org.apache.batik.bridge.UnitProcessor;
+import org.apache.batik.css.value.ImmutableFloat;
+import org.apache.batik.css.CSSOMReadOnlyValue;
+import org.apache.batik.util.SVGConstants;
import org.w3c.dom.DOMImplementation;
+import org.w3c.dom.css.CSSPrimitiveValue;
+
import org.apache.batik.dom.svg.SVGDOMImplementation;
import java.io.File;
import java.util.List;
import java.util.ArrayList;
import java.awt.geom.AffineTransform;
+import java.awt.geom.Point2D;
/**
* class representing svg:svg pseudo flow object.
e.setAttributeNS(XMLSupport.XMLNS_NAMESPACE_URI, "xmlns", SVGDOMImplementation.SVG_NAMESPACE_URI);
//}
- String s;
- SVGUserAgent userAgent = new SVGUserAgent(new AffineTransform());
- userAgent.setLogger(log);
- BridgeContext ctx = new BridgeContext(userAgent);
- UnitProcessor.Context uctx = UnitProcessor.createContext(ctx, e);
+ Point2D p2d = getSize(this.fs, svgRoot);
- // 'width' attribute - default is 100%
- s = e.getAttributeNS(null, SVGOMDocument.SVG_WIDTH_ATTRIBUTE);
- if (s.length() == 0) {
- s = SVGOMDocument.SVG_SVG_WIDTH_DEFAULT_VALUE;
- }
- float width = UnitProcessor.svgHorizontalLengthToUserSpace
- (s, SVGOMDocument.SVG_WIDTH_ATTRIBUTE, uctx);
-
- // 'height' attribute - default is 100%
- s = e.getAttributeNS(null, SVGOMDocument.SVG_HEIGHT_ATTRIBUTE);
- if (s.length() == 0) {
- s = SVGOMDocument.SVG_SVG_HEIGHT_DEFAULT_VALUE;
- }
- float height = UnitProcessor.svgVerticalLengthToUserSpace
- (s, SVGOMDocument.SVG_HEIGHT_ATTRIBUTE, uctx);
-
- SVGArea svg = new SVGArea(fs, width, height);
+ SVGArea svg = new SVGArea(fs, (float)p2d.getX(),
+ (float)p2d.getY());
svg.setSVGDocument(doc);
svg.start();
FONT_FAMILY.add("serif");
}
+ public static Point2D getSize(FontState fs, Element svgRoot) {
+ String str;
+ UnitProcessor.Context ctx;
+ ctx = new PDFUnitContext(fs, svgRoot);
+ str = svgRoot.getAttributeNS(null, SVGConstants.SVG_WIDTH_ATTRIBUTE);
+ if (str.length() == 0) str = "100%";
+ float width = UnitProcessor.svgHorizontalLengthToUserSpace
+ (str, SVGConstants.SVG_WIDTH_ATTRIBUTE, ctx);
+
+ str = svgRoot.getAttributeNS(null, SVGConstants.SVG_HEIGHT_ATTRIBUTE);
+ if (str.length() == 0) str = "100%";
+ float height = UnitProcessor.svgVerticalLengthToUserSpace
+ (str, SVGConstants.SVG_HEIGHT_ATTRIBUTE, ctx);
+ return new Point2D.Float(width, height);
+ }
+ /**
+ * This class is the default context for a particular
+ * element. Informations not available on the element are get from
+ * the bridge context (such as the viewport or the pixel to
+ * millimeter factor.
+ */
+ public static class PDFUnitContext implements UnitProcessor.Context {
+
+ /** The element. */
+ protected Element e;
+ protected FontState fs;
+ public PDFUnitContext(FontState fs, Element e) {
+ this.e = e;
+ this.fs = fs;
+ }
+
+ /**
+ * Returns the element.
+ */
+ public Element getElement() {
+ return e;
+ }
+
+ /**
+ * Returns the context of the parent element of this context.
+ * Since this is always for the root SVG element there never
+ * should be one...
+ */
+ public UnitProcessor.Context getParentElementContext() {
+ return null;
+ }
+
+ /**
+ * Returns the pixel to mm factor.
+ */
+ public float getPixelToMM() {
+ return 0.264583333333333333333f;
+ // 72 dpi
+ }
+
+ /**
+ * Returns the font-size medium value in pt.
+ */
+ public float getMediumFontSize() {
+ return 9f;
+ }
+
+ /**
+ * Returns the font-size value.
+ */
+ public CSSPrimitiveValue getFontSize() {
+ return new CSSOMReadOnlyValue
+ (new ImmutableFloat(CSSPrimitiveValue.CSS_PT,
+ fs.getFontSize()));
+ }
+
+ /**
+ * Returns the x-height value.
+ */
+ public float getXHeight() {
+ return 0.5f;
+ }
+
+ /**
+ * Returns the viewport width used to compute units.
+ */
+ public float getViewportWidth() {
+ return 100;
+ }
+
+ /**
+ * Returns the viewport height used to compute units.
+ */
+ public float getViewportHeight() {
+ return 100;
+ }
+ }
}
}
public String getMedia() {
- return "";
+ return "print";
}
/**
public static final Element createImage(Document doc, String ref,
float width, float height) {
Element border = doc.createElementNS(svgNS, "image");
- border.setAttributeNS("http://www.w3.org/1999/xlink", "xlink:href",
+ border.setAttributeNS("http://www.w3.org/1999/xlink", "href",
ref);
border.setAttributeNS(null, "width", "" + width);
border.setAttributeNS(null, "height", "" + height);