From: Keiron Liddle Date: Tue, 13 Mar 2001 05:28:27 +0000 (+0000) Subject: renders svg to the awt viewer using batik X-Git-Url: https://source.dussan.org/?a=commitdiff_plain;h=33818208867e4d24c6093eab4f8e0bc517fe4253;p=xmlgraphics-fop.git renders svg to the awt viewer using batik doesn't handle all svg due to lack of property handling git-svn-id: https://svn.apache.org/repos/asf/xmlgraphics/fop/branches/fop-0_17_0_batikSVG@194156 13f79535-47bb-0310-9956-ffa450edef68 --- diff --git a/lib/batik.jar b/lib/batik.jar index 169b4c636..d05c85bbd 100644 Binary files a/lib/batik.jar and b/lib/batik.jar differ diff --git a/src/codegen/elements.dtd b/src/codegen/elements.dtd index 427bce70f..2ae37e2eb 100644 --- a/src/codegen/elements.dtd +++ b/src/codegen/elements.dtd @@ -4,11 +4,17 @@ DTD for svgelements.xml --> + - + + + + + diff --git a/src/codegen/elements.xsl b/src/codegen/elements.xsl index b8bcbafa5..9c0e3cdd7 100644 --- a/src/codegen/elements.xsl +++ b/src/codegen/elements.xsl @@ -33,6 +33,23 @@ + + + + + + + + + + + + + + + +"", + @@ -77,17 +94,17 @@ import org.w3c.dom.Element; public class extends SVGObj { /** - * inner class for making A objects. + * inner class for making objects. */ public static class Maker extends FObj.Maker { /** - * make a A object. + * make a object. * * @param parent the parent formatting object * @param propertyList the explicit properties of this object * - * @return the A object + * @return the object */ public FObj make(FObj parent, PropertyList propertyList) throws FOPException { @@ -98,14 +115,14 @@ public class extends SVGObj { /** * returns the maker for this object. * - * @return the maker for A objects + * @return the maker for objects */ public static FObj.Maker maker() { return new .Maker(); } /** - * constructs a A object (called by Maker). + * constructs a object (called by Maker). * * @param parent the parent formatting object * @param propertyList the explicit properties of this object @@ -114,11 +131,7 @@ public class extends SVGObj { super(parent, propertyList); this.name = ":"; tagName = ""; - props = new String[] { - - "", - - }; + props = new String[] {}; } diff --git a/src/codegen/svgelements.xml b/src/codegen/svgelements.xml index 2f9936d94..a279114c6 100644 --- a/src/codegen/svgelements.xml +++ b/src/codegen/svgelements.xml @@ -1,5 +1,114 @@ - + + + id + class + + + xml:lang + xml:space + + + requiredFeatures + requiredExtensions + systemLanguage + + + + + + + + + + + + + + + + + enable-background + + + flood-color + flood-opacity + + + fill + fill-opacity + fill-rule + stroke + stroke-dasharray + stroke-dashoffset + stroke-linecap + stroke-linejoin + stroke-miterlimit + stroke-opacity + stroke-width + + + font-family + font-size + font-size-adjust + font-stretch + font-style + font-variant + font-weight + + + stop-color + stop-opacity + + + clip-path + clip-rule + color + color-interpolation + color-rendering + cursor + display + filter + image-rendering + mask + opacity + pointer-events + space-rendering + text-rendering + visibility + + + color-profile + + + lighting-color + + + marker-start + marker-mid + marker-end + + + alignment-baseline + baseline-shift + direction + glyph-orientation-horizontal + glyph-orientation-vertical + kerning + letter-spacing + text-decoration + unicode-bidi + word-spacing + + + writing-mode + text-anchor + dominant-baseline + + + clip + overflow + a @@ -9,6 +118,9 @@ circle + + + id style transform @@ -20,31 +132,37 @@ altGlyph + animate + animateColor + animateMotion + animateTransform + clipPath + id style clipPathUnits @@ -53,11 +171,13 @@ cursor + defs + @@ -68,6 +188,7 @@ ellipse + id style transform @@ -80,16 +201,19 @@ filter + font + g + id style transform @@ -99,16 +223,19 @@ glyph + hkern + image + id style transform @@ -123,6 +250,7 @@ line + id style transform @@ -136,6 +264,7 @@ linearGradient + id style transform @@ -153,11 +282,13 @@ marker + mask + id style @@ -165,11 +296,13 @@ missing-glyph + path + id style transform @@ -180,6 +313,7 @@ pattern + id style transform @@ -195,6 +329,7 @@ polygon + id style transform @@ -205,6 +340,7 @@ polyline + id style transform @@ -215,6 +351,7 @@ radialGradient + id style transform @@ -232,6 +369,9 @@ rect + + + id style transform @@ -247,11 +387,13 @@ set + stop + id style offset @@ -260,11 +402,13 @@ style + switch + id requiredFeatures requiredExtensions @@ -274,6 +418,7 @@ symbol + id style viewBox @@ -282,6 +427,7 @@ tref + id style xlink:href @@ -294,6 +440,7 @@ tspan + id style x @@ -305,6 +452,7 @@ text + id style transform @@ -317,6 +465,7 @@ textPath + id style xlink:href @@ -325,11 +474,13 @@ title + use + id style transform @@ -343,6 +494,7 @@ vkern + diff --git a/src/codegen/svgproperties.xml b/src/codegen/svgproperties.xml index 11f4397e1..a242b0d0b 100644 --- a/src/codegen/svgproperties.xml +++ b/src/codegen/svgproperties.xml @@ -90,7 +90,6 @@ offset SVGStringProperty - style SVGStringProperty @@ -111,6 +110,110 @@ points SVGStringProperty + + fill + SVGStringProperty + + + fill-opacity + SVGStringProperty + + + fill-rule + SVGStringProperty + + + stroke + SVGStringProperty + + + stroke-dasharray + SVGStringProperty + + + stroke-dashoffset + SVGStringProperty + + + stroke-linecap + SVGStringProperty + + + stroke-linejoin + SVGStringProperty + + + stroke-miterlimit + SVGStringProperty + + + stroke-opacity + SVGStringProperty + + + stroke-width + SVGStringProperty + + + clip-path + SVGStringProperty + + + clip-rule + SVGStringProperty + + + color + SVGStringProperty + + + color-interpolation + SVGStringProperty + + + color-rendering + SVGStringProperty + + + cursor + SVGStringProperty + + + display + SVGStringProperty + + + filter + SVGStringProperty + + + image-rendering + SVGStringProperty + + + opacity + SVGStringProperty + + + mask + SVGStringProperty + + + space-rendering + SVGStringProperty + + + text-rendering + SVGStringProperty + + + pointer-events + SVGStringProperty + + + visibility + SVGStringProperty + font-family diff --git a/src/org/apache/fop/render/awt/AWTRenderer.java b/src/org/apache/fop/render/awt/AWTRenderer.java index 0f3c7e1a1..e2ff10226 100644 --- a/src/org/apache/fop/render/awt/AWTRenderer.java +++ b/src/org/apache/fop/render/awt/AWTRenderer.java @@ -21,6 +21,13 @@ import org.apache.fop.apps.*; import org.w3c.dom.svg.*; +import org.apache.batik.bridge.*; +import org.apache.batik.swing.svg.*; +import org.apache.batik.swing.gvt.*; +import org.apache.batik.gvt.*; +import org.apache.batik.gvt.renderer.*; +import org.apache.batik.gvt.filter.*; + import java.awt.*; import java.awt.Image; import java.awt.image.*; @@ -627,8 +634,13 @@ public class AWTRenderer implements Renderer, Printable, Pageable { Enumeration e = area.getChildren().elements(); while (e.hasMoreElements()) { - org.apache.fop.layout.Box b = - (org.apache.fop.layout.Box) e.nextElement(); + org.apache.fop.layout.Box b = (org.apache.fop.layout.Box) e.nextElement(); + if(b instanceof InlineArea) { + InlineArea ia = (InlineArea)b; + this.currentYPosition = ry - ia.getYOffset(); + } else { + this.currentYPosition = ry - area.getPlacementOffset(); + } b.render(this); } @@ -660,18 +672,99 @@ public class AWTRenderer implements Renderer, Printable, Pageable { this.currentXPosition += area.getContentWidth(); } - public void renderSVGArea(SVGArea area) { - int x = this.currentAreaContainerXPosition; + int x = this.currentXPosition; int y = this.currentYPosition; int w = area.getContentWidth(); int h = area.getHeight(); - this.currentYPosition -= h; +// this.currentYPosition -= h; + + SVGDocument doc = area.getSVGDocument(); + + UserAgent userAgent = new MUserAgent(new AffineTransform()); + GVTBuilder builder = new GVTBuilder(); + GraphicsNodeRenderContext rc = getRenderContext(); + BridgeContext ctx = new BridgeContext(userAgent, rc); + GraphicsNode root; + try { + root = builder.build(ctx, doc); + //rc.setTransform(new AffineTransform(1, 0, x, 0, 1, y)); + graphics.translate(x / 1000f, pageHeight - y / 1000f); + root.paint(graphics, rc); + graphics.translate(-x / 1000f, y / 1000f - pageHeight); + } catch(Exception e) { + e.printStackTrace(); + } + this.currentXPosition += area.getContentWidth(); + +/* final JSVGComponent svgComponent = new JSVGComponent(userAgent, true, true); +// JFrame frame = new JFrame(); +// frame.setSize(300, 300); +// frame.getContentPane().add(svgComponent); +// frame.setVisible(true); + svgComponent.setSVGDocument(doc); + + svgComponent.addGVTTreeRendererListener(new GVTTreeRendererListener() { + public void gvtRenderingPrepare(GVTTreeRendererEvent e) + { + System.out.println("rendering prepare:" + e); + } + + public void gvtRenderingStarted(GVTTreeRendererEvent e) + { + System.out.println("rendering started:" + e); + } + + public void gvtRenderingCancelled(GVTTreeRendererEvent e) + { + } + + public void gvtRenderingFailed(GVTTreeRendererEvent e) + { + } + + public void gvtRenderingCompleted(GVTTreeRendererEvent e) + { + System.out.println("rendering complete:" + e); + Object src = e.getSource(); + Image im = e.getImage(); + svgComponent.paint(graphics); + } + });*/ } + public GraphicsNodeRenderContext getRenderContext() { + GraphicsNodeRenderContext nodeRenderContext = null; + if (nodeRenderContext == null) { + RenderingHints hints = new RenderingHints(null); + hints.put(RenderingHints.KEY_ANTIALIASING, + RenderingHints.VALUE_ANTIALIAS_ON); + + hints.put(RenderingHints.KEY_INTERPOLATION, + RenderingHints.VALUE_INTERPOLATION_BILINEAR); + + FontRenderContext fontRenderContext = + new FontRenderContext(new AffineTransform(), true, true); + + TextPainter textPainter = new StrokingTextPainter(); + + GraphicsNodeRableFactory gnrFactory = + new ConcreteGraphicsNodeRableFactory(); + + nodeRenderContext = + new GraphicsNodeRenderContext(new AffineTransform(), + null, + hints, + fontRenderContext, + textPainter, + gnrFactory); + } + + return nodeRenderContext; + } public void setProducer(String producer) { @@ -776,7 +869,98 @@ public class AWTRenderer implements Renderer, Printable, Pageable { area.getObject().render(this); } -} + protected class MUserAgent implements UserAgent { + AffineTransform currentTransform = null; + /** + * Creates a new SVGUserAgent. + */ + protected MUserAgent(AffineTransform at) { + currentTransform = at; + } + + /** + * Displays an error message. + */ + public void displayError(String message) { + System.err.println(message); + } + + /** + * Displays an error resulting from the specified Exception. + */ + public void displayError(Exception ex) { + ex.printStackTrace(System.err); + } + + /** + * Displays a message in the User Agent interface. + * The given message is typically displayed in a status bar. + */ + public void displayMessage(String message) { + System.out.println(message); + } + + /** + * Returns a customized the pixel to mm factor. + */ + public float getPixelToMM() { + return 0.264583333333333333333f; // 72 dpi + } + + /** + * Returns the language settings. + */ + public String getLanguages() { + return "en";//userLanguages; + } + + /** + * Returns the user stylesheet uri. + * @return null if no user style sheet was specified. + */ + public String getUserStyleSheetURI() { + return null;//userStyleSheetURI; + } + /** + * Returns the class name of the XML parser. + */ + public String getXMLParserClassName() { + String parserClassName = + System.getProperty("org.xml.sax.parser"); + if (parserClassName == null) { + parserClassName = "org.apache.xerces.parsers.SAXParser"; + } + return parserClassName;//application.getXMLParserClassName(); + } + /** + * Opens a link in a new component. + * @param doc The current document. + * @param uri The document URI. + */ + public void openLink(SVGAElement elt) + { + //application.openLink(uri); + } + public Point getClientAreaLocationOnScreen() + { + return new Point(0, 0); + } + + public void setSVGCursor(java.awt.Cursor cursor) + { + } + + public AffineTransform getTransform() + { + return currentTransform; + } + + public Dimension2D getViewportSize() + { + return new Dimension(100, 100); + } + } +} diff --git a/src/org/apache/fop/svg/SVG.java b/src/org/apache/fop/svg/SVG.java index 8b7a3b3f4..9db5ea1c2 100644 --- a/src/org/apache/fop/svg/SVG.java +++ b/src/org/apache/fop/svg/SVG.java @@ -236,7 +236,7 @@ public class SVG extends SVGObj implements GraphicsCreator { DefaultSVGContext dc = new DefaultSVGContext() { public float getPixelToMM() { - return 12; + return 0.264583333333333333333f; // 72 dpi } public float getViewportWidth() { return 100; @@ -247,7 +247,7 @@ public class SVG extends SVGObj implements GraphicsCreator { }; doc.setSVGContext(dc); - System.out.println("tag:" + tagName); + //System.out.println("tag:" + tagName); Element topLevel = doc.createElementNS("http://www.w3.org/2000/svg", tagName); for(int count = 0; count < props.length; count++) { String rf = this.properties.get(props[count]).getString(); diff --git a/src/org/apache/fop/svg/SVGObj.java b/src/org/apache/fop/svg/SVGObj.java index adbd9c9ad..07a55d9b5 100644 --- a/src/org/apache/fop/svg/SVGObj.java +++ b/src/org/apache/fop/svg/SVGObj.java @@ -84,8 +84,10 @@ public abstract class SVGObj extends FObj implements GraphicsCreator { Element element = doc.createElementNS("http://www.w3.org/2000/svg", tagName); // Element element = doc.createElement(tagName); for(int count = 0; count < props.length; count++) { - String rf = this.properties.get(props[count]).getString(); - element.setAttribute(props[count], rf); + if(this.properties.get(props[count]) != null) { + String rf = this.properties.get(props[count]).getString(); + element.setAttribute(props[count], rf); + } } parent.appendChild(element); int numChildren = this.children.size();