From: Steve Coffman Date: Fri, 11 May 2001 20:25:52 +0000 (+0000) Subject: PR: X-Git-Url: https://source.dussan.org/?a=commitdiff_plain;h=5b68906b40ded9fd2c1d6ce0ce1e8406dcf118d0;p=xmlgraphics-fop.git PR: Obtained from: Keiron Liddle Submitted by: Steve Coffman Reviewed by: Steve Coffman This updates Keiron's branch that uses Batik for SVG. Adds a few files missing. git-svn-id: https://svn.apache.org/repos/asf/xmlgraphics/fop/branches/fop-0_17_0_batikSVG@194240 13f79535-47bb-0310-9956-ffa450edef68 --- diff --git a/build.sh b/build.sh index 3f6df1c06..26cb67755 100755 --- a/build.sh +++ b/build.sh @@ -12,9 +12,9 @@ if [ "$JAVA_HOME" = "" ] ; then echo "location of the Java Virtual Machine you want to use." exit 1 fi - -LOCALCLASSPATH=$JAVA_HOME/lib/tools.jar:$JAVA_HOME/lib/classes.zip:./lib/ant.jar:./lib/buildtools.jar:./lib/batik.jar -ANT_HOME=./lib +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.2.3.jar:$LIBDIR/xalan-2.0.0.jar:$LIBDIR/xalanj1compat.jar:$LIBDIR/bsf.jar:$LIBDIR/jimi-1.0.jar +ANT_HOME=$LIBDIR echo Building with classpath $CLASSPATH:$LOCALCLASSPATH echo diff --git a/docs/examples/svg/makedoc.sh b/docs/examples/svg/makedoc.sh index d7b1d51d3..8ec376513 100755 --- a/docs/examples/svg/makedoc.sh +++ b/docs/examples/svg/makedoc.sh @@ -13,7 +13,7 @@ if [ "$JAVA_HOME" = "" ] ; then exit 1 fi -LOCALCLASSPATH=$JAVA_HOME/lib/tools.jar:$JAVA_HOME/lib/classes.zip:../../../lib/ant.jar:../../../lib/w3c.jar:../../../lib/buildtools.jar:../../../build/fop.jar:../../../lib/batik.jar +LOCALCLASSPATH=$JAVA_HOME/lib/tools.jar:$JAVA_HOME/lib/classes.zip:../../../lib/ant.jar:../../../lib/xerces-1.2.3.jar:../../../lib/buildtools.jar:../../../build/fop.jar:../../../lib/batik.jar:../../../lib/xalan-2.0.0.jar ANT_HOME=../../../lib echo Building with classpath $CLASSPATH:$LOCALCLASSPATH diff --git a/fop.sh b/fop.sh index d91034f75..1bc911954 100755 --- a/fop.sh +++ b/fop.sh @@ -1,3 +1,3 @@ #!/bin/sh -java -cp fop.jar:lib/w3c.jar:lib/xalan-2.0.0.jar:lib/xerces-1.2.3.jar:lib/jimi-1.0.jar org.apache.fop.apps.Fop "$@" +java -cp build/fop.jar:lib/w3c.jar:lib/xalan-2.0.0.jar:lib/xerces-1.2.3.jar:lib/jimi-1.0.jar org.apache.fop.apps.Fop "$@" diff --git a/lib/batik.jar b/lib/batik.jar index d05c85bbd..5c1486efe 100644 Binary files a/lib/batik.jar and b/lib/batik.jar differ diff --git a/src/codegen/svgelements.xml b/src/codegen/svgelements.xml index d27d11fa2..ddc384112 100644 --- a/src/codegen/svgelements.xml +++ b/src/codegen/svgelements.xml @@ -1,4 +1,13 @@ + id @@ -12,6 +21,40 @@ requiredFeatures requiredExtensions systemLanguage + + + xmlns:xlink + xlink:type + xlink:role + xlink:arcrole + xlink:title + xlink:show + xlink:actuate + + + onfocusin + onfocusout + onactivate + onclick + onmousedown + onmouseup + onmouseover + onmousemove + onmouseout + onload + + + onunload + onabort + onerror + onresize + onscroll + onzoom + + + onbegin + onend + onrepeat @@ -109,16 +152,76 @@ clip overflow + + x + y + width + height + result + + + + in + + + type + tableValues + slope + intercept + amplitude + exponent + offset + + + + xlink:href + + + attributeName + attributeType + + + + xlink:href + attributeName + attributeType + + + begin + dur + end + min + max + restart + repeatCount + repeatDur + fill + + + calcMode + values + keyTimes + keySplines + from + to + by + + + additive + accumulate + a - xlnk:href + xmlns:xlink + xlink:type xlink:role xlink:arcrole xlink:title xlink:show xlink:actuate + xlink:href externalResourcesRequired @@ -126,7 +229,7 @@ style transform - + target @@ -136,13 +239,13 @@ - externalResourceRequired + externalResourcesRequired class style transform - + cx cy r @@ -150,6 +253,37 @@ altGlyph + + + + + + xlink:href + glyphRef + format + externalResourcesRequired + class + style + + + + + + x + y + dx + dy + rotate + + + + altGlyphDef + + + + + + altGlyphItem @@ -158,50 +292,131 @@ animate + + externalResourcesRequired + + + + + + animateColor + + externalResourcesRequired + + + + + + animateMotion + + externalResourcesRequired + + + + calcMode + values + keyTimes + keySplines + from + to + by + + path + keyPoints + rotate + origin animateTransform + + externalResourcesRequired + + + + + + + type clipPath - id + + + externalResourcesRequired + class style + + + + + + transform clipPathUnits + + color-profile + + + + xlink:href + local + name + rendering-intent + + cursor + + xlink:href + + externalResourcesRequired + x + y defs + + + + + externalResourcesRequired + class + style + transform desc + + + + class + style @@ -210,37 +425,396 @@ - externalResourceRequired + externalResourcesRequired class style transform - + cx cy rx ry + + feBlend + + + + in2 + mode + + + + feColorMatrix + + + + type + values + + + + feComponentTransfer + + + + + + + feComposite + + + + in2 + operator + k1 + k2 + k3 + k4 + + + + feConvolveMatrix + + + order + kernelMatrix + divisor + bias + targetX + targetY + edgeMode + kernelUnitLength + preserveAlpha + + + + feDistantLight + + + azimuth + elevation + + + + feDiffuseLighting + + + class + style + + + surfaceScale + diffuseConstant + + + + feDisplacementMap + + + + in2 + scale + xChannelSelector + yChannelSelector + + + + feFlood + + + + class + style + + + + + feFuncR + + + + + + + feFuncG + + + + + + + feFuncB + + + + + + + feFuncA + + + + + + + feGaussianBlur + + + + stdDeviation + + + + feOffset + + + + + + fePointLight + + + x + y + z + + + + feImage + + + + xlink:href + + externalResourcesRequired + class + style + + transform + + + + + feMerge + + + + + + + feMergeNode + + + in + + + + feMorphology + + + + operator + radius + + + + feOffset + + + + dx + dy + + + + feSpecularLighting + + + class + style + + + surfaceScale + specularConstant + specularExponent + + + + feSpotLight + + + x + y + z + pointsAtX + pointsAtY + pointsAtZ + specularExponent + limitingConeAngle + + + + feTile + + + + + + + feTurbulence + + + + baseFrequency + numOctaves + seed + stitchTiles + type + + filter + + xlink:href + + externalResourcesRequired + class + style + + filterUnits + primitiveUnits + x + y + width + height + filterRes font + externalResourcesRequired + class + style + + horiz-origin-x + horiz-origin-y + horiz-adv-x + vert-origin-x + vert-origin-y + vert-adv-y + + + + font-face + + + font-family + font-style + font-variant + font-weight + font-stretch + font-size + unicode-range + units-per-em + panose-1 + stemv + stemh + slope + cap-height + x-height + accent-height + ascent + descent + widths + bbox + ideographic + alphabetic + mathematical + hanging + v-ideographic + v-alphabetic + v-mathematical + v-hanging + underline-position + underline-thickness + strikethrough-position + strikethrough-thickness + overline-position + overline-thickness + + + + font-face-src + + + + + + font-face-uri + + + + xlink:href + + + + font-face-format + + + string + + + + font-face-name + + + name + + + + foreignObject + + + + + externalResourcesRequired + class + style + + transform + + x + y + width + height + + + + + definition-src + + + + xlink:href g + + - id + + externalResourcesRequired style transform class @@ -250,22 +824,65 @@ glyph + class + style + + unicode + glyph-name + d + orientation + arabic-form + lang + horiz-adv-x + vert-origin-x + vert-origin-y + vert-adv-y + + + + glyphRef + + + + xlink:href + class + style + + glyphRef + format + x + y + dx + dy hkern + u1 + g1 + u2 + g2 + k image - id + + + + + + + + externalResourcesRequired + class style transform - class + preserveAspectRatio xlink:href x y @@ -279,14 +896,14 @@ - externalResourceRequired + externalResourcesRequired class style transform - + x1 x2 y1 @@ -297,65 +914,128 @@ linearGradient - id + + xlink:href + externalResourcesRequired + class style - transform + + gradientUnits + gradientTransform class - xlink:href x1 y1 x2 y2 - gradientTransform spreadMethod - gradientUnits marker + + externalResourcesRequired + class + style + + viewBox + preserveAspectRatio + refX + refY + markerUnits + markerWidth + markerHeight + orient mask - id + + + externalResourcesRequired + class style + + transform + maskUnits + maskContentUnits + x + y + width + height + + + + metadata + + missing-glyph + class + style + + d + horiz-adv-x + vert-origin-x + vert-origin-y + vert-adv-y + + + + mpath + + + + xlink:href + externalResourcesRequired path - id + + + + + + + externalResourcesRequired style transform class d + pathLength pattern - id - style - transform + + + + externalResourcesRequired class + style + + viewBox + preserveAspectRatio xlink:href width height x y patternUnits + patternContentUnits + patternTransform @@ -371,7 +1051,7 @@ transform - + points @@ -388,7 +1068,7 @@ transform - + points @@ -396,10 +1076,11 @@ radialGradient - id + + externalResourcesRequired style - transform class + gradientTransform xlink:href cx @@ -408,6 +1089,7 @@ fx fy gradientUnits + spreadMethod @@ -416,13 +1098,13 @@ - externalResourceRequired + externalResourcesRequired class style transform - + x y width @@ -435,14 +1117,32 @@ set + + externalResourcesRequired + + + + + to + + + + script + + + + xlink:href + externalResourcesRequired + type stop - id + class style + offset @@ -450,25 +1150,61 @@ style + xml:space + type + media + title + + + + svg + + + + + + + + externalResourcesRequired + class + style + viewBox + preserveAspectRatio + zoomAndPan + x + y + width + height + contentScriptType + contentStyleType switch - id - requiredFeatures - requiredExtensions - systemLanguage + + + + + externalResourcesRequired + class + style + transform symbol - id + + externalResourcesRequired + + + class style viewBox + preserveAspectRatio @@ -479,14 +1215,14 @@ xlink:href - externalResourceRequired + externalResourcesRequired class style - + x y dx @@ -502,14 +1238,14 @@ - externalResourceRequired + externalResourcesRequired class style - + x y dx @@ -525,7 +1261,7 @@ - externalResourceRequired + externalResourcesRequired class style @@ -534,7 +1270,7 @@ transform - + x y textLength @@ -549,14 +1285,14 @@ xlink:href - externalResourceRequired + externalResourcesRequired class style - + startOffset textLength lengthAdjust @@ -568,13 +1304,23 @@ title + + + class + style use - id + + + + + + externalResourcesRequired + class style transform xlink:href @@ -588,6 +1334,22 @@ vkern + u1 + g1 + u2 + g2 + k + + + + view + + + externalResourcesRequired + viewBox + preserveAspectRatio + zoomAndPan + viewTarget diff --git a/src/org/apache/fop/apps/AWTStarter.java b/src/org/apache/fop/apps/AWTStarter.java index 061c391ba..c0eb930f6 100644 --- a/src/org/apache/fop/apps/AWTStarter.java +++ b/src/org/apache/fop/apps/AWTStarter.java @@ -84,7 +84,7 @@ public class AWTStarter extends CommandLineStarter { frame = createPreviewDialog(renderer, resource); renderer.setProgressListener(frame); renderer.setComponent(frame); - MessageHandler.setOutputMethod(MessageHandler.EVENT); + MessageHandler.setOutputMethod(MessageHandler.NONE); MessageHandler.addListener(frame); } diff --git a/src/org/apache/fop/apps/CommandLineStarter.java b/src/org/apache/fop/apps/CommandLineStarter.java index fe8cddec6..b39a741c3 100644 --- a/src/org/apache/fop/apps/CommandLineStarter.java +++ b/src/org/apache/fop/apps/CommandLineStarter.java @@ -60,7 +60,7 @@ public class CommandLineStarter extends Starter { if (errorDump) { e.printStackTrace(); } - System.exit(1); + System.exit(0); } } diff --git a/src/org/apache/fop/datatypes/KeepValue.java b/src/org/apache/fop/datatypes/KeepValue.java index 3f1e06d7d..e8bb43452 100644 --- a/src/org/apache/fop/datatypes/KeepValue.java +++ b/src/org/apache/fop/datatypes/KeepValue.java @@ -75,4 +75,9 @@ public class KeepValue { { return type; } + + public String toString() + { + return type; + } } diff --git a/src/org/apache/fop/pdf/PDFDocument.java b/src/org/apache/fop/pdf/PDFDocument.java index 7d2c7ec2e..b07216642 100644 --- a/src/org/apache/fop/pdf/PDFDocument.java +++ b/src/org/apache/fop/pdf/PDFDocument.java @@ -915,11 +915,13 @@ public class PDFDocument { contents, pagewidth, pageheight); + if(currentPage != null) { Enumeration enum=currentPage.getIDList().elements(); while ( enum.hasMoreElements() ) { String id=enum.nextElement().toString(); idReferences.setInternalGoToPageReference(id,page.referencePDF()); } + } /* add it to the list of objects */ this.objects.addElement(page); diff --git a/src/org/apache/fop/render/awt/AWTRenderer.java b/src/org/apache/fop/render/awt/AWTRenderer.java index aec6c7cff..0905eae98 100644 --- a/src/org/apache/fop/render/awt/AWTRenderer.java +++ b/src/org/apache/fop/render/awt/AWTRenderer.java @@ -27,6 +27,7 @@ import org.apache.batik.swing.gvt.*; import org.apache.batik.gvt.*; import org.apache.batik.gvt.renderer.*; import org.apache.batik.gvt.filter.*; +import org.apache.batik.gvt.event.*; import java.awt.*; import java.awt.Image; @@ -690,6 +691,7 @@ public class AWTRenderer implements Renderer, Printable, Pageable { BridgeContext ctx = new BridgeContext(userAgent, rc); GraphicsNode root; graphics.translate(x / 1000f, pageHeight - y / 1000f); + graphics.setRenderingHints(rc.getRenderingHints()); try { root = builder.build(ctx, doc); root.paint(graphics, rc); @@ -927,5 +929,20 @@ public class AWTRenderer implements Renderer, Printable, Pageable { { return new Dimension(100, 100); } + + public EventDispatcher getEventDispatcher() + { + return null; + } + + public boolean supportExtension(String str) + { + return false; + } + + public boolean hasFeature(String str) + { + return false; + } } } diff --git a/src/org/apache/fop/render/pdf/PDFRenderer.java b/src/org/apache/fop/render/pdf/PDFRenderer.java index d034cc075..62f04f5a8 100644 --- a/src/org/apache/fop/render/pdf/PDFRenderer.java +++ b/src/org/apache/fop/render/pdf/PDFRenderer.java @@ -75,6 +75,7 @@ import org.apache.batik.swing.gvt.*; 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.w3c.dom.*; import org.w3c.dom.svg.*; @@ -574,6 +575,7 @@ public class PDFRenderer implements Renderer { case Overflow.HIDDEN: break; } + area.getObject().render(this); currentStream.add("Q\n"); currentStream.add("BT\n"); @@ -628,10 +630,12 @@ public class PDFRenderer implements Renderer { GraphicsNodeRenderContext rc = getRenderContext(); BridgeContext ctx = new BridgeContext(userAgent, rc); GraphicsNode root; + //System.out.println("creating PDFGraphics2D"); PDFGraphics2D graphics = new PDFGraphics2D(true, area.getFontState(), pdfDoc, currentFontName, currentFontSize, currentXPosition, currentYPosition); graphics.setGraphicContext(new org.apache.batik.ext.awt.g2d.GraphicContext()); + graphics.setRenderingHints(rc.getRenderingHints()); try { root = builder.build(ctx, doc); root.paint(graphics, rc); @@ -1277,5 +1281,20 @@ public class PDFRenderer implements Renderer { { return new Dimension(100, 100); } + + public EventDispatcher getEventDispatcher() + { + return null; + } + + public boolean supportExtension(String str) + { + return false; + } + + public boolean hasFeature(String str) + { + return false; + } } } diff --git a/src/org/apache/fop/svg/PDFDocumentGraphics2D.java b/src/org/apache/fop/svg/PDFDocumentGraphics2D.java new file mode 100644 index 000000000..37bc930fd --- /dev/null +++ b/src/org/apache/fop/svg/PDFDocumentGraphics2D.java @@ -0,0 +1,120 @@ +/***************************************************************************** + * Copyright (C) The Apache Software Foundation. All rights reserved. * + * ------------------------------------------------------------------------- * + * This software is published under the terms of the Apache Software License * + * version 1.1, a copy of which has been included with this distribution in * + * the LICENSE file. * + *****************************************************************************/ + +package org.apache.fop.svg; + +import org.apache.fop.pdf.*; +import org.apache.fop.layout.*; +import org.apache.fop.fonts.*; +import org.apache.fop.render.pdf.*; +import org.apache.fop.image.*; +import org.apache.fop.datatypes.ColorSpace; + +import org.apache.batik.ext.awt.g2d.*; + +import java.text.AttributedCharacterIterator; +import java.awt.*; +import java.awt.Font; +import java.awt.Image; +import java.awt.image.*; +import java.awt.font.*; +import java.awt.geom.*; +import java.awt.image.renderable.*; +import java.io.*; + +import java.util.Map; + +/** + * This concrete implementation of AbstractGraphics2D is a + * simple help to programmers to get started with their own + * implementation of Graphics2D. + * DefaultGraphics2D implements all the abstract methods + * is AbstractGraphics2D and makes it easy to start + * implementing a Graphic2D piece-meal. + * + * @author Vincent Hardy + * @version $Id$ + * @see org.apache.batik.ext.awt.g2d.AbstractGraphics2D + */ +public class PDFDocumentGraphics2D extends PDFGraphics2D { + OutputStream stream; + + PDFStream pdfStream; + int width; + int height; + + /** + * Create a new PDFGraphics2D with the given pdf document info. + * This is used to create a Graphics object for use inside an already + * existing document. + * Maybe this could be handled as a subclass (PDFDocumentGraphics2d) + */ + public PDFDocumentGraphics2D(boolean textAsShapes, OutputStream stream, int width, int height) + { + super(textAsShapes); + standalone = true; + this.stream = stream; + this.pdfDoc = new PDFDocument(); + this.pdfDoc.setProducer("FOP SVG Renderer"); + pdfStream = this.pdfDoc.makeStream(); + this.width = width; + this.height = height; + + currentFontName = ""; + currentFontSize = 0; + currentYPosition = 0; + currentXPosition = 0; +// fontState = fs; + + currentStream.write("1 0 0 -1 0 " + height + " cm\n"); + + // end part + /* + FontSetup.addToResources(this.pdfDoc, fontInfo); + */ + + } + + public void finish() throws IOException + { + pdfStream.add(getString()); + PDFResources pdfResources = this.pdfDoc.getResources(); + PDFPage currentPage = this.pdfDoc.makePage(pdfResources, pdfStream, + width, + height, null); + this.pdfDoc.output(stream); + + } + + public String getString() { + return currentStream.toString(); + } + + public void setGraphicContext(GraphicContext c) + { + gc = c; + } + + /** + * This constructor supports the create method + */ + public PDFDocumentGraphics2D(PDFDocumentGraphics2D g){ + super(g); + } + + /** + * Creates a new Graphics object that is + * a copy of this Graphics object. + * @return a new graphics context that is a copy of + * this graphics context. + */ + public Graphics create(){ + return new PDFDocumentGraphics2D(this); + } + +} diff --git a/src/org/apache/fop/svg/PDFGraphics2D.java b/src/org/apache/fop/svg/PDFGraphics2D.java index a376dbee0..e13a3f897 100644 --- a/src/org/apache/fop/svg/PDFGraphics2D.java +++ b/src/org/apache/fop/svg/PDFGraphics2D.java @@ -12,6 +12,8 @@ import org.apache.fop.pdf.*; import org.apache.fop.layout.*; import org.apache.fop.fonts.*; import org.apache.fop.render.pdf.*; +import org.apache.fop.image.*; +import org.apache.fop.datatypes.ColorSpace; import org.apache.batik.ext.awt.g2d.*; @@ -40,18 +42,20 @@ import java.util.Map; * @see org.apache.batik.ext.awt.g2d.AbstractGraphics2D */ public class PDFGraphics2D extends AbstractGraphics2D { + protected PDFDocument pdfDoc; + + protected FontState fontState; + boolean standalone = false; /** the PDF Document being created */ - protected PDFDocument pdfDoc; + //protected PDFDocument pdfDoc; - protected FontState fontState; + //protected FontState fontState; /** the current stream to add PDF commands to */ StringWriter currentStream = new StringWriter(); - PDFStream pdfStream; - /** the current (internal) font name */ protected String currentFontName; @@ -65,9 +69,9 @@ public class PDFGraphics2D extends AbstractGraphics2D { protected int currentXPosition = 0; /** the current colour for use in svg */ - private PDFColor currentColour = new PDFColor(0, 0, 0); + PDFColor currentColour = new PDFColor(0, 0, 0); - private FontInfo fontInfo; + FontInfo fontInfo; /** * Create a new PDFGraphics2D with the given pdf document info. @@ -85,38 +89,10 @@ public class PDFGraphics2D extends AbstractGraphics2D { fontState = fs; } - /** - * Create a new PDFGraphics2D with the given pdf document info. - * This is used to create a Graphics object for use inside an already - * existing document. - * Maybe this could be handled as a subclass (PDFDocumentGraphics2d) - */ - public PDFGraphics2D(boolean textAsShapes, OutputStream stream) + public PDFGraphics2D(boolean textAsShapes) { super(textAsShapes); - standalone = true; - this.pdfDoc = new PDFDocument(); - this.pdfDoc.setProducer("FOP SVG Renderer"); - pdfStream = this.pdfDoc.makeStream(); - - currentFontName = ""; - currentFontSize = 0; - currentYPosition = 0; - currentXPosition = 0; -// fontState = fs; - - // end part - /* - FontSetup.addToResources(this.pdfDoc, fontInfo); - pdfStream.write(getString()) - this.pdfResources = this.pdfDoc.getResources(); - currentPage = this.pdfDoc.makePage(this.pdfResources, currentStream, - page.getWidth() / 1000, - page.getHeight() / 1000, page); - this.pdfDoc.output(stream); - */ - - } + } public String getString() { return currentStream.toString(); @@ -144,13 +120,6 @@ public class PDFGraphics2D extends AbstractGraphics2D { return new PDFGraphics2D(this); } - public void setColor(Color c){ - super.setColor(c); - currentColour = new PDFColor(c.getRed(), c.getGreen(), c.getBlue()); - currentStream.write(currentColour.getColorSpaceOut(false)); - currentStream.write(currentColour.getColorSpaceOut(true)); - } - /** * Draws as much of the specified image as is currently available. * The image is drawn with its top-left corner at @@ -176,20 +145,161 @@ public class PDFGraphics2D extends AbstractGraphics2D { * @see java.awt.image.ImageObserver#imageUpdate(java.awt.Image, int, int, int, int, int) */ public boolean drawImage(Image img, int x, int y, ImageObserver observer){ - System.err.println("drawImage"); -/* int width = img.getWidth(observer); - int height = img.getHeight(observer); - FopImage fopimg = new FopImage() { - }; + System.err.println("drawImage:x, y"); + + final int width = img.getWidth(observer); + final int height = img.getHeight(observer); + if(width == -1 || height == -1) { + return false; + } + + Dimension size = new Dimension(width, height); + BufferedImage buf = buildBufferedImage(size); + + java.awt.Graphics2D g = buf.createGraphics(); + g.setComposite(AlphaComposite.SrcOver); + g.setBackground(new Color(1, 1, 1, 0)); + g.setPaint(new Color(1, 1, 1, 0)); + g.fillRect(0, 0, width, height); + g.clip(new Rectangle(0, 0, buf.getWidth(), buf.getHeight())); + + if(!g.drawImage(img, 0, 0, observer)) { + return false; + } + g.dispose(); + + final byte[] result = new byte[buf.getWidth() * buf.getHeight() * 3]; + + Raster raster = buf.getData(); + DataBuffer bd = raster.getDataBuffer(); + + int count = 0; + switch(bd.getDataType()) { + case DataBuffer.TYPE_INT: + int[][] idata = ((DataBufferInt)bd).getBankData(); + for(int i = 0; i < idata.length; i++) { + for(int j = 0; j < idata[i].length; j++) { + //System.out.println("data:" + ((idata[i][j] >> 24) & 0xFF)); + if(((idata[i][j] >> 24) & 0xFF) != 255) { +System.out.println("data:" + ((idata[i][j] >> 24) & 0xFF)); + result[count++] = (byte)0xFF; + result[count++] = (byte)0xFF; + result[count++] = (byte)0xFF; + } else { + result[count++] = (byte)((idata[i][j] >> 16) & 0xFF); + result[count++] = (byte)((idata[i][j] >> 8) & 0xFF); + result[count++] = (byte)((idata[i][j]) & 0xFF); + } + } + } + break; + default: + // error + break; + } + + try { + FopImage fopimg = new TempImage(width, height, result); int xObjectNum = this.pdfDoc.addImage(fopimg); - currentStream.add("q\n" + (((float) w) / 1000f) + - " 0 0 " + (((float) h) / 1000f) + " " + + /*currentStream.write("q\n" + (((float) width)) + + " 0 0 " + (((float) height)) + " " + x + " " + - ((float)(y - h)) + " cm\n" + "/Im" + + ((float)(y - height)) + " cm\n" + "/Im" + xObjectNum + " Do\nQ\n");*/ + AffineTransform at = getTransform(); + double[] matrix = new double[6]; + at.getMatrix(matrix); + currentStream.write("q\n" + matrix[0] + + " " + matrix[1] + " " + matrix[2] + " " + matrix[3] + " " + + matrix[4] + " " + + matrix[5] + " cm\n"); + currentStream.write("" + width + + " 0 0 " + (-height) + " " + + x + " " + + (y + height) + " cm\n" + "/Im" + + xObjectNum + " Do\nQ\n"); + } catch(Exception e) { + e.printStackTrace(); + } return true; } + public BufferedImage buildBufferedImage(Dimension size) { + return new BufferedImage(size.width, size.height, + BufferedImage.TYPE_INT_ARGB); + } + + class TempImage implements FopImage { + int m_height; + int m_width; + int m_bitsPerPixel; + ColorSpace m_colorSpace; + int m_bitmapSiye; + byte[] m_bitmaps; + PDFColor transparent = new PDFColor(255, 255, 255); + + TempImage(int width, int height, byte[] result) throws FopImageException + { + this.m_height = height; + this.m_width = width; + this.m_bitsPerPixel = 8; + this.m_colorSpace = new ColorSpace(ColorSpace.DEVICE_RGB); + //this.m_isTransparent = false; + //this.m_bitmapsSize = this.m_width * this.m_height * 3; + this.m_bitmaps = result; + } + + public String getURL() {return "" + m_bitmaps;} + + // image size + public int getWidth() throws FopImageException + { + return m_width; + } + + public int getHeight() throws FopImageException + {return m_height;} + + // DeviceGray, DeviceRGB, or DeviceCMYK + public ColorSpace getColorSpace() throws FopImageException + {return m_colorSpace;} + + // bits per pixel + public int getBitsPerPixel() throws FopImageException + {return m_bitsPerPixel;} + + // For transparent images + public boolean isTransparent() throws FopImageException + {return transparent != null;} + public PDFColor getTransparentColor() throws FopImageException + {return transparent;} + + // get the image bytes, and bytes properties + + // get uncompressed image bytes + public byte[] getBitmaps() throws FopImageException + {return m_bitmaps;} +// width * (bitsPerPixel / 8) * height, no ? + public int getBitmapsSize() throws FopImageException + {return m_width * m_height * 3;} + + // get compressed image bytes + // I don't know if we really need it, nor if it + // should be changed... + public byte[] getRessourceBytes() throws FopImageException + {return null;} + public int getRessourceBytesSize() throws FopImageException + {return 0;} + // return null if no corresponding PDFFilter + public PDFFilter getPDFFilter() throws FopImageException + {return null;} + + // release memory + public void close() {} + + } + + /** * Draws as much of the specified image as has already been scaled * to fit inside the specified rectangle. @@ -278,10 +388,17 @@ public class PDFGraphics2D extends AbstractGraphics2D { * @see #setComposite */ public void draw(Shape s){ - System.out.println("draw(Shape)"); + //System.out.println("draw(Shape)"); + Color c = getColor(); + currentColour = new PDFColor(c.getRed(), c.getGreen(), c.getBlue()); + currentStream.write(currentColour.getColorSpaceOut(true)); + c = getBackground(); + PDFColor col = new PDFColor(c.getRed(), c.getGreen(), c.getBlue()); + currentStream.write(col.getColorSpaceOut(false)); + PDFNumber pdfNumber = new PDFNumber(); - PathIterator iter = s.getPathIterator(new AffineTransform()); + PathIterator iter = s.getPathIterator(getTransform()); while(!iter.isDone()) { double vals[] = new double[6]; int type = iter.currentSegment(vals); @@ -427,8 +544,6 @@ public class PDFGraphics2D extends AbstractGraphics2D { System.err.println("drawString(AttributedCharacterIterator)"); } - - /** * Fills the interior of a Shape using the settings of the * Graphics2D context. The rendering attributes applied @@ -444,10 +559,17 @@ public class PDFGraphics2D extends AbstractGraphics2D { * @see #setClip */ public void fill(Shape s){ - System.err.println("fill"); + //System.err.println("fill"); + Color c = getColor(); + currentColour = new PDFColor(c.getRed(), c.getGreen(), c.getBlue()); + currentStream.write(currentColour.getColorSpaceOut(true)); + c = getBackground(); + PDFColor col = new PDFColor(c.getRed(), c.getGreen(), c.getBlue()); + currentStream.write(col.getColorSpaceOut(false)); + PDFNumber pdfNumber = new PDFNumber(); - PathIterator iter = s.getPathIterator(new AffineTransform()); + PathIterator iter = s.getPathIterator(getTransform()); while(!iter.isDone()) { double vals[] = new double[6]; int type = iter.currentSegment(vals); @@ -503,7 +625,7 @@ public class PDFGraphics2D extends AbstractGraphics2D { */ public GraphicsConfiguration getDeviceConfiguration(){ System.out.println("getDeviceConviguration"); - return null; + return GraphicsEnvironment.getLocalGraphicsEnvironment().getDefaultScreenDevice().getDefaultConfiguration(); } /** diff --git a/src/org/apache/fop/svg/PDFTranscoder.java b/src/org/apache/fop/svg/PDFTranscoder.java new file mode 100644 index 000000000..3bb8d226c --- /dev/null +++ b/src/org/apache/fop/svg/PDFTranscoder.java @@ -0,0 +1,655 @@ +/***************************************************************************** + * Copyright (C) The Apache Software Foundation. All rights reserved. * + * ------------------------------------------------------------------------- * + * This software is published under the terms of the Apache Software License * + * version 1.1, a copy of which has been included with this distribution in * + * the LICENSE file. * + *****************************************************************************/ + +package org.apache.fop.svg; + +import java.awt.AlphaComposite; +import java.awt.Cursor; +import java.awt.Dimension; +import java.awt.Graphics2D; +import java.awt.Paint; +import java.awt.Point; +import java.awt.Rectangle; +import java.awt.Shape; + +import java.awt.geom.AffineTransform; +import java.awt.geom.Dimension2D; +import java.awt.geom.Rectangle2D; +import java.awt.image.BufferedImage; + +import java.awt.*; +import java.awt.event.*; +import java.awt.geom.*; +import java.awt.font.*; + +import java.net.MalformedURLException; +import java.net.URL; + +import java.util.HashSet; +import java.util.Set; + +import org.apache.batik.transcoder.*; + +import org.apache.batik.bridge.BridgeContext; +import org.apache.batik.bridge.BridgeException; +import org.apache.batik.bridge.GVTBuilder; +import org.apache.batik.bridge.UserAgent; +import org.apache.batik.bridge.ViewBox; + +import org.apache.batik.dom.svg.DefaultSVGContext; +import org.apache.batik.dom.svg.SAXSVGDocumentFactory; +import org.apache.batik.dom.svg.SVGDOMImplementation; +import org.apache.batik.dom.svg.SVGOMDocument; +import org.apache.batik.dom.util.DocumentFactory; + +import org.apache.batik.ext.awt.image.GraphicsUtil; + +import org.apache.batik.gvt.GraphicsNode; +import org.apache.batik.gvt.GraphicsNodeRenderContext; +import org.apache.batik.gvt.event.EventDispatcher; +import org.apache.batik.gvt.renderer.ImageRenderer; +import org.apache.batik.gvt.renderer.ImageRendererFactory; + +import org.apache.batik.transcoder.TranscoderException; +import org.apache.batik.transcoder.TranscoderOutput; +import org.apache.batik.transcoder.TranscodingHints; +import org.apache.batik.transcoder.XMLAbstractTranscoder; +import org.apache.batik.transcoder.image.resources.Messages; + +import org.apache.batik.transcoder.keys.BooleanKey; +import org.apache.batik.transcoder.keys.FloatKey; +import org.apache.batik.transcoder.keys.LengthKey; +import org.apache.batik.transcoder.keys.PaintKey; +import org.apache.batik.transcoder.keys.PaintKey; +import org.apache.batik.transcoder.keys.Rectangle2DKey; +import org.apache.batik.transcoder.keys.StringKey; +import org.apache.batik.transcoder.*; + +import org.apache.batik.util.SVGConstants; + +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 org.apache.batik.gvt.event.*; + +import org.w3c.dom.*; +import org.w3c.dom.svg.*; +import org.w3c.dom.css.*; +import org.w3c.dom.svg.SVGLength; + +import org.apache.fop.svg.*; + +import org.w3c.dom.DOMException; +import org.w3c.dom.DOMImplementation; +import org.w3c.dom.Document; +import org.w3c.dom.svg.SVGAElement; +import org.w3c.dom.svg.SVGDocument; +import org.w3c.dom.svg.SVGSVGElement; + +// FIXME : Those import clauses will change with new design +import org.apache.batik.gvt.renderer.StaticRendererFactory; + +/** + * This class enables to transcode an input to an image of any format. + * + *

Two transcoding hints (KEY_WIDTH and + * KEY_HEIGHT) can be used to respectively specify the image + * width and the image height. If only one of these keys is specified, + * the transcoder preserves the aspect ratio of the original image. + * + *

The KEY_BACKGROUND_COLOR defines the background color + * to use for opaque image formats, or the background color that may + * be used for image formats that support alpha channel. + * + *

The KEY_AOI represents the area of interest to paint + * in device space. + * + *

Three additional transcoding hints that act on the SVG + * processor can be specified: + * + *

KEY_LANGUAGE to set the default language to use (may be + * used by a <switch> SVG element for example), + * KEY_USER_STYLESHEET_URI to fix the URI of a user + * stylesheet, and KEY_PIXEL_TO_MM to specify the pixel to + * millimeter conversion factor. + * + * @author Thierry Kormann + * @version $Id$ + */ +public class PDFTranscoder extends XMLAbstractTranscoder { + + /** The user agent dedicated to an ImageTranscoder. */ + protected UserAgent userAgent = new ImageTranscoderUserAgent(); + + /** + * Constructs a new ImageTranscoder. + */ + public PDFTranscoder() { + hints.put(KEY_DOCUMENT_ELEMENT_NAMESPACE_URI, + SVGConstants.SVG_NAMESPACE_URI); + hints.put(KEY_DOCUMENT_ELEMENT, + SVGConstants.SVG_SVG_TAG); + hints.put(KEY_DOM_IMPLEMENTATION, + SVGDOMImplementation.getDOMImplementation()); + } + + /** + * Transcodes the specified Document as an image in the specified output. + * + * @param document the document to transcode + * @param uri the uri of the document or null if any + * @param output the ouput where to transcode + * @exception TranscoderException if an error occured while transcoding + */ + protected void transcode(Document document, + String uri, + TranscoderOutput output) + throws TranscoderException { + + if (!(document instanceof SVGOMDocument)) { + throw new TranscoderException( + Messages.formatMessage("notsvg", null)); + } + SVGDocument svgDoc = (SVGDocument)document; + SVGSVGElement root = svgDoc.getRootElement(); + // initialize the SVG document with the appropriate context + String parserClassname = (String)hints.get(KEY_XML_PARSER_CLASSNAME); + DefaultSVGContext svgCtx = new DefaultSVGContext(); + svgCtx.setPixelToMM(userAgent.getPixelToMM()); + ((SVGOMDocument)document).setSVGContext(svgCtx); + + // build the GVT tree + GVTBuilder builder = new GVTBuilder(); + ImageRendererFactory rendFactory = new StaticRendererFactory(); + GraphicsNodeRenderContext rc = getRenderContext(); + BridgeContext ctx = new BridgeContext(userAgent, rc); + GraphicsNode gvtRoot; + try { + gvtRoot = builder.build(ctx, svgDoc); + } catch (BridgeException ex) { + throw new TranscoderException(ex); + } + // get the 'width' and 'height' attributes of the SVG document + float docWidth = (float)ctx.getDocumentSize().getWidth(); + float docHeight = (float)ctx.getDocumentSize().getHeight(); + ctx = null; + builder = null; + + // compute the image's width and height according the hints + float imgWidth = -1; + if (hints.containsKey(KEY_WIDTH)) { + imgWidth = ((Float)hints.get(KEY_WIDTH)).floatValue(); + } + float imgHeight = -1; + if (hints.containsKey(KEY_HEIGHT)) { + imgHeight = ((Float)hints.get(KEY_HEIGHT)).floatValue(); + } + float width, height; + if (imgWidth > 0 && imgHeight > 0) { + width = imgWidth; + height = imgHeight; + } else if (imgHeight > 0) { + width = (docWidth * imgHeight) / docHeight; + height = imgHeight; + } else if (imgWidth > 0) { + width = imgWidth; + height = (docHeight * imgWidth) / docWidth; + } else { + width = docWidth; + height = docHeight; + } + // compute the preserveAspectRatio matrix + AffineTransform Px; + String ref = null; + try { + ref = new URL(uri).getRef(); + } catch (MalformedURLException ex) { + // nothing to do, catched previously + } + + try { + Px = ViewBox.getViewTransform(ref, root, width, height); + } catch (BridgeException ex) { + throw new TranscoderException(ex); + } + + if (Px.isIdentity() && (width != docWidth || height != docHeight)) { + // The document has no viewBox, we need to resize it by hand. + // we want to keep the document size ratio + float d = Math.max(docWidth, docHeight); + float dd = Math.max(width, height); + float scale = dd/d; + Px = AffineTransform.getScaleInstance(scale, scale); + } + // take the AOI into account if any + if (hints.containsKey(KEY_AOI)) { + Rectangle2D aoi = (Rectangle2D)hints.get(KEY_AOI); + // transform the AOI into the image's coordinate system + aoi = Px.createTransformedShape(aoi).getBounds2D(); + AffineTransform Mx = new AffineTransform(); + double sx = width / aoi.getWidth(); + double sy = height / aoi.getHeight(); + Mx.scale(sx, sy); + double tx = -aoi.getX(); + double ty = -aoi.getY(); + Mx.translate(tx, ty); + // take the AOI transformation matrix into account + // we apply first the preserveAspectRatio matrix + Px.preConcatenate(Mx); + } + // prepare the image to be painted + int w = (int)width; + int h = (int)height; + + PDFDocumentGraphics2D graphics = new PDFDocumentGraphics2D(true, output.getOutputStream(), w, h); + // GraphicsNodeRenderContext rc = getRenderContext(); + graphics.setGraphicContext(new org.apache.batik.ext.awt.g2d.GraphicContext()); + graphics.setRenderingHints(rc.getRenderingHints()); + + gvtRoot.paint(graphics, rc); + + try { + graphics.finish(); + } catch (Exception ex) { + ex.printStackTrace(); + throw new TranscoderException(ex); + } + /* + // paint the SVG document using the bridge package + // create the appropriate renderer + ImageRenderer renderer = rendFactory.createImageRenderer(); + renderer.updateOffScreen(w, h); + renderer.setTransform(Px); + renderer.setTree(gvtRoot); + gvtRoot = null; // We're done with it... + + try { + // now we are sure that the aoi is the image size + Shape raoi = new Rectangle2D.Float(0, 0, width, height); + // Warning: the renderer's AOI must be in user space + renderer.repaint(Px.createInverse().createTransformedShape(raoi)); + BufferedImage rend = renderer.getOffScreen(); + renderer = null; // We're done with it... + + // BufferedImage dest = createImage(w, h); + + //Graphics2D g2d = GraphicsUtil.createGraphics(dest); + + //g2d.drawRenderedImage(rend, new AffineTransform()); + } catch (Exception ex) { + throw new TranscoderException(ex); + } + */ + } + + 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); + nodeRenderContext.setTextPainter(textPainter); + } + + return nodeRenderContext; + } + + /** + * Creates a DocumentFactory that is used to create an SVG DOM + * tree. The specified DOM Implementation is ignored and the Batik + * SVG DOM Implementation is automatically used. + * + * @param domImpl the DOM Implementation (not used) + * @param parserClassname the XML parser classname + */ + protected DocumentFactory createDocumentFactory(DOMImplementation domImpl, + String parserClassname) { + return new SAXSVGDocumentFactory(parserClassname); + } + + // -------------------------------------------------------------------- + // UserAgent implementation + // -------------------------------------------------------------------- + + /** + * A user agent implementation for ImageTranscoder. + */ + protected class ImageTranscoderUserAgent implements UserAgent { + + /** + * Returns the default size of this user agent (400x400). + */ + public Dimension2D getViewportSize() { + return new Dimension(400, 400); + } + + /** + * Displays the specified error message using the ErrorHandler. + */ + public void displayError(String message) { + try { + getErrorHandler().error(new TranscoderException(message)); + } catch (TranscoderException ex) { + throw new RuntimeException(); + } + } + + /** + * Displays the specified error using the ErrorHandler. + */ + public void displayError(Exception e) { + try { + getErrorHandler().error(new TranscoderException(e)); + } catch (TranscoderException ex) { + throw new RuntimeException(); + } + } + + /** + * Displays the specified message using the ErrorHandler. + */ + public void displayMessage(String message) { + try { + getErrorHandler().warning(new TranscoderException(message)); + } catch (TranscoderException ex) { + throw new RuntimeException(); + } + } + + /** + * Returns the pixel to millimeter conversion factor specified in the + * TranscodingHints or 0.3528 if any. + */ + public float getPixelToMM() { + if (getTranscodingHints().containsKey(KEY_PIXEL_TO_MM)) { + return ((Float)getTranscodingHints().get(KEY_PIXEL_TO_MM)).floatValue(); + } else { + // return 0.3528f; // 72 dpi + return 0.26458333333333333333333333333333f; // 96dpi + } + } + + /** + * Returns the user language specified in the + * TranscodingHints or "en" (english) if any. + */ + public String getLanguages() { + if (getTranscodingHints().containsKey(KEY_LANGUAGE)) { + return (String)getTranscodingHints().get(KEY_LANGUAGE); + } else { + return "en"; + } + } + + /** + * Returns the user stylesheet specified in the + * TranscodingHints or null if any. + */ + public String getUserStyleSheetURI() { + return (String)getTranscodingHints().get(KEY_USER_STYLESHEET_URI); + } + + /** + * Returns the XML parser to use from the TranscodingHints. + */ + public String getXMLParserClassName() { + return (String)getTranscodingHints().get(KEY_XML_PARSER_CLASSNAME); + } + + /** + * Unsupported operation. + */ + public EventDispatcher getEventDispatcher() { + return null; + } + + /** + * Unsupported operation. + */ + public void openLink(SVGAElement elt) { } + + /** + * Unsupported operation. + */ + public void setSVGCursor(Cursor cursor) { } + + /** + * Unsupported operation. + */ + public void runThread(Thread t) { } + + /** + * Unsupported operation. + */ + public AffineTransform getTransform() { + return null; + } + + /** + * Unsupported operation. + */ + public Point getClientAreaLocationOnScreen() { + return new Point(); + } + + /** + * Tells whether the given feature is supported by this + * user agent. + */ + public boolean hasFeature(String s) { + return FEATURES.contains(s); + } + + /** + * Tells whether the given extension is supported by this + * user agent. + */ + public boolean supportExtension(String s) { + return false; + } + } + + protected final static Set FEATURES = new HashSet(); + static { + FEATURES.add(SVGConstants.SVG_ORG_W3C_SVG_FEATURE); + FEATURES.add(SVGConstants.SVG_ORG_W3C_SVG_LANG_FEATURE); + FEATURES.add(SVGConstants.SVG_ORG_W3C_SVG_STATIC_FEATURE); + } + + // -------------------------------------------------------------------- + // Keys definition + // -------------------------------------------------------------------- + + /** + * The image width key. + * + * + * + * + * + * + * + * + * + * + * + * + * + * + * + * + *

Key:

KEY_WIDTH

Value:

Float

Default:

The width of the top most svg element

Required:

No

Description:

Specify the width of the image to create.
*/ + public static final TranscodingHints.Key KEY_WIDTH + = new LengthKey(); + + /** + * The image height key. + * + * + * + * + * + * + * + * + * + * + * + * + * + * + * + * + *

Key:

KEY_HEIGHT

Value:

Float

Default:

The height of the top most svg element

Required:

No

Description:

Specify the height of the image to create.
*/ + public static final TranscodingHints.Key KEY_HEIGHT + = new LengthKey(); + + /** + * The area of interest key. + * + * + * + * + * + * + * + * + * + * + * + * + * + * + * + * + *

Key:

KEY_AOI

Value:

Rectangle2D

Default:

The document's size

Required:

No

Description:

Specify the area of interest to render. The + * rectangle coordinates must be specified in pixels and in the + * document coordinates system.
+ */ + public static final TranscodingHints.Key KEY_AOI + = new Rectangle2DKey(); + + /** + * The language key. + * + * + * + * + * + * + * + * + * + * + * + * + * + * + * + * + *

Key:

KEY_LANGUAGE

Value:

String

Default:

"en"

Required:

No

Description:

Specify the preferred language of the document. + *
+ */ + public static final TranscodingHints.Key KEY_LANGUAGE + = new StringKey(); + + /** + * The user stylesheet URI key. + * + * + * + * + * + * + * + * + * + * + * + * + * + * + * + * + *

Key:

KEY_USER_STYLESHEET_URI

Value:

String

Default:

null

Required:

No

Description:

Specify the user style sheet.
+ */ + public static final TranscodingHints.Key KEY_USER_STYLESHEET_URI + = new StringKey(); + + /** + * The pixel to millimeter conversion factor key. + * + * + * + * + * + * + * + * + * + * + * + * + * + * + * + * + *

Key:

KEY_PIXEL_TO_MM

Value:

Float

Default:

0.33

Required:

No

Description:

Specify the pixel to millimeter conversion factor. + *
+ */ + public static final TranscodingHints.Key KEY_PIXEL_TO_MM + = new FloatKey(); + + /** + * The image background paint key. + * + * + * + * + * + * + * + * + * + * + * + * + * + * + * + * + *

Key:

KEY_BACKGROUND_COLOR

Value:

Paint

Default:

null

Required:

No

Description:

Specify the background color to use. + * The color is required by opaque image formats and is used by + * image formats that support alpha channel.
+ */ + public static final TranscodingHints.Key KEY_BACKGROUND_COLOR + = new PaintKey(); + +} diff --git a/src/org/apache/fop/svg/SVG.java b/src/org/apache/fop/svg/SVG.java index 92e7cffad..3b9b18c02 100644 --- a/src/org/apache/fop/svg/SVG.java +++ b/src/org/apache/fop/svg/SVG.java @@ -64,6 +64,8 @@ import org.w3c.dom.*; import org.w3c.dom.svg.*; import org.w3c.dom.svg.SVGLength; +import java.io.File; + /** * class representing svg:svg pseudo flow object. */ @@ -329,6 +331,10 @@ public class SVG extends SVGObj implements GraphicsCreator { /* create an SVG area */ /* if width and height are zero, may want to get the bounds of the content. */ SVGOMDocument doc = new SVGOMDocument(null, SVGDOMImplementation.getDOMImplementation()); + try { + doc.setURLObject(new File(".").toURL()); + } catch(Exception e) { + } DefaultSVGContext dc = new DefaultSVGContext() { public float getPixelToMM() { diff --git a/src/org/apache/fop/svg/SVGElementMapping.java b/src/org/apache/fop/svg/SVGElementMapping.java index bb217acf5..cb7305750 100644 --- a/src/org/apache/fop/svg/SVGElementMapping.java +++ b/src/org/apache/fop/svg/SVGElementMapping.java @@ -106,5 +106,11 @@ public class SVGElementMapping implements ElementMapping { builder.addMapping(uri, "animateTransform", AnimateTransform.maker()); builder.addMapping(uri, "cursor", Cursor.maker()); builder.addMapping(uri, "filter", Filter.maker()); + + builder.addMapping(uri, "feFlood", FeFlood.maker()); + builder.addMapping(uri, "feGaussianBlur", FeGaussianBlur.maker()); + builder.addMapping(uri, "feOffset", FeOffset.maker()); + builder.addMapping(uri, "feMerge", FeMerge.maker()); + builder.addMapping(uri, "feMergeNode", FeMergeNode.maker()); } } diff --git a/src/org/apache/fop/svg/SVGObj.java b/src/org/apache/fop/svg/SVGObj.java index cd81d7bb3..c5d53ad6f 100644 --- a/src/org/apache/fop/svg/SVGObj.java +++ b/src/org/apache/fop/svg/SVGObj.java @@ -62,6 +62,8 @@ import org.apache.batik.dom.svg.*; import org.w3c.dom.svg.*; import org.w3c.dom.*; +import java.util.*; + /** * Since SVG objects are not layed out then this class checks * that this element is not being layed out inside some incorrect @@ -80,14 +82,28 @@ public abstract class SVGObj extends FObj implements GraphicsCreator { super(parent, propertyList); } + protected static Hashtable ns = new Hashtable(); + public void addGraphic(Document doc, Element parent) { Element element = doc.createElementNS("http://www.w3.org/2000/svg", tagName); // Element element = doc.createElement(tagName); for(int count = 0; count < props.length; count++) { if(this.properties.get(props[count]) != null) { String rf = this.properties.get(props[count]).getString(); - if(rf != null) - element.setAttribute(props[count], rf); + if(rf != null) { + if(props[count].indexOf(":") == -1) { + element.setAttribute(props[count], rf); + } else { + String pref = props[count].substring(0, props[count].indexOf(":")); +System.out.println(pref); + if(pref.equals("xmlns")) { + ns.put(props[count].substring(props[count].indexOf(":") + 1), rf); +System.out.println(ns); + } + ns.put("xlink", "http://www.w3.org/1999/xlink"); + element.setAttributeNS((String)ns.get(pref), props[count], rf); + } + } } } parent.appendChild(element);