diff options
author | Keiron Liddle <keiron@apache.org> | 2001-11-15 08:12:37 +0000 |
---|---|---|
committer | Keiron Liddle <keiron@apache.org> | 2001-11-15 08:12:37 +0000 |
commit | a0f30b3d13ee1a3aaf521eed1c0665f1d8fd03b1 (patch) | |
tree | 90c8515260d302868de9644ec45d8bd7ba443621 | |
parent | 777dbd0139d29b074adc4ddd05e64b66b0cd5d48 (diff) | |
download | xmlgraphics-fop-a0f30b3d13ee1a3aaf521eed1c0665f1d8fd03b1.tar.gz xmlgraphics-fop-a0f30b3d13ee1a3aaf521eed1c0665f1d8fd03b1.zip |
made the batik pdf transcoder work again
some improvements to svg handling
Submitted by: Thomas E Deweese <thomas.deweese@kodak.com>
git-svn-id: https://svn.apache.org/repos/asf/xmlgraphics/fop/trunk@194567 13f79535-47bb-0310-9956-ffa450edef68
-rw-r--r-- | src/org/apache/fop/fo/XMLObj.java | 57 | ||||
-rw-r--r-- | src/org/apache/fop/image/analyser/SVGReader.java | 2 | ||||
-rw-r--r-- | src/org/apache/fop/layout/FontInfo.java | 7 | ||||
-rw-r--r-- | src/org/apache/fop/pdf/PDFDocument.java | 2 | ||||
-rw-r--r-- | src/org/apache/fop/svg/PDFDocumentGraphics2D.java | 12 | ||||
-rw-r--r-- | src/org/apache/fop/svg/PDFTranscoder.java | 2 | ||||
-rw-r--r-- | src/org/apache/fop/svg/SVGElement.java | 124 | ||||
-rw-r--r-- | src/org/apache/fop/svg/SVGUserAgent.java | 2 | ||||
-rw-r--r-- | src/org/apache/fop/svg/SVGUtilities.java | 2 |
9 files changed, 143 insertions, 67 deletions
diff --git a/src/org/apache/fop/fo/XMLObj.java b/src/org/apache/fop/fo/XMLObj.java index db4dd3962..c52006d8a 100644 --- a/src/org/apache/fop/fo/XMLObj.java +++ b/src/org/apache/fop/fo/XMLObj.java @@ -53,51 +53,52 @@ public abstract class XMLObj extends FONode { 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() { diff --git a/src/org/apache/fop/image/analyser/SVGReader.java b/src/org/apache/fop/image/analyser/SVGReader.java index 2f60b62ea..a27080380 100644 --- a/src/org/apache/fop/image/analyser/SVGReader.java +++ b/src/org/apache/fop/image/analyser/SVGReader.java @@ -157,7 +157,7 @@ public class SVGReader extends AbstractImageReader { } public String getMedia() { - return ""; + return "print"; } /** diff --git a/src/org/apache/fop/layout/FontInfo.java b/src/org/apache/fop/layout/FontInfo.java index 4f145e3ea..edfefc1eb 100644 --- a/src/org/apache/fop/layout/FontInfo.java +++ b/src/org/apache/fop/layout/FontInfo.java @@ -8,7 +8,6 @@ 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; @@ -58,10 +57,10 @@ public class FontInfo { 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)); diff --git a/src/org/apache/fop/pdf/PDFDocument.java b/src/org/apache/fop/pdf/PDFDocument.java index 06bf33b54..b21fc706f 100644 --- a/src/org/apache/fop/pdf/PDFDocument.java +++ b/src/org/apache/fop/pdf/PDFDocument.java @@ -946,7 +946,7 @@ public class PDFDocument { /* add it to the list of objects */ this.objects.add(page); - + pages.addPage(page); return page; } diff --git a/src/org/apache/fop/svg/PDFDocumentGraphics2D.java b/src/org/apache/fop/svg/PDFDocumentGraphics2D.java index a97763353..3ddbba1df 100644 --- a/src/org/apache/fop/svg/PDFDocumentGraphics2D.java +++ b/src/org/apache/fop/svg/PDFDocumentGraphics2D.java @@ -78,16 +78,16 @@ public class PDFDocumentGraphics2D extends PDFGraphics2D { 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"); } @@ -167,10 +167,6 @@ public class PDFDocumentGraphics2D extends PDFGraphics2D { pdfDoc.outputTrailer(stream); } - public void setGraphicContext(GraphicContext c) { - gc = c; - } - /** * This constructor supports the create method */ diff --git a/src/org/apache/fop/svg/PDFTranscoder.java b/src/org/apache/fop/svg/PDFTranscoder.java index 9d5ab9ff8..dea3df6d2 100644 --- a/src/org/apache/fop/svg/PDFTranscoder.java +++ b/src/org/apache/fop/svg/PDFTranscoder.java @@ -382,7 +382,7 @@ public class PDFTranscoder extends XMLAbstractTranscoder { } public String getMedia() { - return ""; + return "print"; } /** diff --git a/src/org/apache/fop/svg/SVGElement.java b/src/org/apache/fop/svg/SVGElement.java index cf4fd9c63..c30177de8 100644 --- a/src/org/apache/fop/svg/SVGElement.java +++ b/src/org/apache/fop/svg/SVGElement.java @@ -29,8 +29,14 @@ import org.apache.batik.gvt.*; 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; @@ -38,6 +44,7 @@ import java.net.URL; 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. @@ -127,29 +134,10 @@ public class SVGElement extends SVGObj { 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(); @@ -186,4 +174,96 @@ public class SVGElement extends SVGObj { 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; + } + } } diff --git a/src/org/apache/fop/svg/SVGUserAgent.java b/src/org/apache/fop/svg/SVGUserAgent.java index 9c3808568..dc4c8a247 100644 --- a/src/org/apache/fop/svg/SVGUserAgent.java +++ b/src/org/apache/fop/svg/SVGUserAgent.java @@ -85,7 +85,7 @@ public class SVGUserAgent implements UserAgent { } public String getMedia() { - return ""; + return "print"; } /** diff --git a/src/org/apache/fop/svg/SVGUtilities.java b/src/org/apache/fop/svg/SVGUtilities.java index fe854d271..6ff4e404f 100644 --- a/src/org/apache/fop/svg/SVGUtilities.java +++ b/src/org/apache/fop/svg/SVGUtilities.java @@ -161,7 +161,7 @@ public class SVGUtilities { 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); |