deweese 2003/02/13 05:11:37
Modified: . build.xml
sources/org/apache/batik/bridge SVGFilterElementBridge.java
sources/org/apache/batik/ext/awt/image/renderable
DeferRable.java
sources/org/apache/batik/ext/awt/image/spi
JDKRegistryEntry.java
Log:
1) JDK Registry Entry no longer uses media tracker and components.
So with JDK 1.4.x you can use '-Djava.awt.headless=true' to rasterize
SVG content without an X display on UNIX systems.
2) Improved DeferRable so you can defer more (the JDK entry takes advantage
of this).
3) The build.xml now has a '-Djava.awt.headless=true' jvm arg
commented out for svgrasterizer so people can more easily use the
rasterizer w/o a display.
Revision Changes Path
1.122 +2 -1 xml-batik/build.xml
Index: build.xml
===================================================================
RCS file: /home/cvs/xml-batik/build.xml,v
retrieving revision 1.121
retrieving revision 1.122
diff -u -r1.121 -r1.122
--- build.xml 9 Dec 2002 16:26:28 -0000 1.121
+++ build.xml 13 Feb 2003 13:11:37 -0000 1.122
@@ -866,6 +866,7 @@
<path refid="libs-classpath"/>
<pathelement location="resources" />
</classpath>
+<!-- <jvmarg value="-Djava.awt.headless=true"/> -->
<arg line="${args}"/>
</java>
</target>
1.15 +3 -2
xml-batik/sources/org/apache/batik/bridge/SVGFilterElementBridge.java
Index: SVGFilterElementBridge.java
===================================================================
RCS file:
/home/cvs/xml-batik/sources/org/apache/batik/bridge/SVGFilterElementBridge.java,v
retrieving revision 1.14
retrieving revision 1.15
diff -u -r1.14 -r1.15
--- SVGFilterElementBridge.java 19 Mar 2002 15:19:25 -0000 1.14
+++ SVGFilterElementBridge.java 13 Feb 2003 13:11:37 -0000 1.15
@@ -84,7 +84,8 @@
filterChain.setFilterResolutionX((int)filterRes[0]);
filterChain.setFilterResolutionY((int)filterRes[1]);
- // create a map for filter nodes to advertise themselves as named source
+ // Create a map for filter nodes to advertise themselves as
+ // named source
Map filterNodeMap = new HashMap(11);
filterNodeMap.put(SVG_SOURCE_GRAPHIC_VALUE, sourceGraphic);
1.4 +56 -6
xml-batik/sources/org/apache/batik/ext/awt/image/renderable/DeferRable.java
Index: DeferRable.java
===================================================================
RCS file:
/home/cvs/xml-batik/sources/org/apache/batik/ext/awt/image/renderable/DeferRable.java,v
retrieving revision 1.3
retrieving revision 1.4
diff -u -r1.3 -r1.4
--- DeferRable.java 3 Aug 2001 17:37:28 -0000 1.3
+++ DeferRable.java 13 Feb 2003 13:11:37 -0000 1.4
@@ -14,6 +14,7 @@
import java.awt.image.RenderedImage;
import java.awt.image.renderable.RenderContext;
import java.util.Vector;
+import java.util.Map;
/**
* This class allows for the return of a proxy object quickly, while a
@@ -27,8 +28,9 @@
*/
public class DeferRable implements Filter {
- Filter src;
-
+ Filter src;
+ Rectangle2D bounds;
+ Map props;
/**
* Constructor takes nothing
*/
@@ -63,7 +65,19 @@
public synchronized void setSource(Filter src) {
// Only let them set Source once.
if (this.src != null) return;
- this.src = src;
+ this.src = src;
+ this.bounds = src.getBounds2D();
+ notifyAll();
+ }
+
+ public synchronized void setBounds(Rectangle2D bounds) {
+ if (this.bounds != null) return;
+ this.bounds = bounds;
+ notifyAll();
+ }
+
+ public synchronized void setProperties(Map props) {
+ this.props = props;
notifyAll();
}
@@ -87,7 +101,20 @@
* it will block until we have a real source.
*/
public Rectangle2D getBounds2D() {
- return getSource().getBounds2D();
+ synchronized(this) {
+ while ((src == null) && (bounds == null)) {
+ try {
+ // Wait for someone to set bounds.
+ wait();
+ }
+ catch(InterruptedException ie) {
+ // Loop around again see if src is set now...
+ }
+ }
+ }
+ if (src != null)
+ return src.getBounds2D();
+ return bounds;
}
public float getMinX() {
@@ -107,14 +134,37 @@
* Forward the call (blocking until source is set if need be).
*/
public Object getProperty(String name) {
- return getSource().getProperty(name);
+ synchronized (this) {
+ while ((src == null) && (props == null)) {
+ try {
+ // Wait for someone to set src | props
+ wait();
+ } catch(InterruptedException ie) { }
+ }
+ }
+ if (src != null)
+ return src.getProperty(name);
+ return props.get(name);
}
/**
* Forward the call (blocking until source is set if need be).
*/
public String [] getPropertyNames() {
- return getSource().getPropertyNames();
+ synchronized (this) {
+ while ((src == null) && (props == null)) {
+ try {
+ // Wait for someone to set src | props
+ wait();
+ } catch(InterruptedException ie) { }
+ }
+ }
+ if (src != null)
+ return src.getPropertyNames();
+
+ String [] ret = new String[props.size()];
+ props.keySet().toArray(ret);
+ return ret;
}
/**
1.6 +168 -57
xml-batik/sources/org/apache/batik/ext/awt/image/spi/JDKRegistryEntry.java
Index: JDKRegistryEntry.java
===================================================================
RCS file:
/home/cvs/xml-batik/sources/org/apache/batik/ext/awt/image/spi/JDKRegistryEntry.java,v
retrieving revision 1.5
retrieving revision 1.6
diff -u -r1.5 -r1.6
--- JDKRegistryEntry.java 7 Aug 2001 17:28:22 -0000 1.5
+++ JDKRegistryEntry.java 13 Feb 2003 13:11:37 -0000 1.6
@@ -8,25 +8,25 @@
package org.apache.batik.ext.awt.image.spi;
+import java.awt.Toolkit;
+import java.awt.Graphics2D;
+import java.awt.Image;
+import java.awt.geom.Rectangle2D;
+import java.awt.image.ImageObserver;
+import java.awt.image.RenderedImage;
+import java.awt.image.BufferedImage;
+
import java.net.URL;
import java.net.MalformedURLException;
+import java.util.HashMap;
+
import org.apache.batik.ext.awt.image.renderable.Filter;
import org.apache.batik.ext.awt.image.renderable.RedRable;
import org.apache.batik.ext.awt.image.renderable.DeferRable;
import org.apache.batik.ext.awt.image.GraphicsUtil;
import org.apache.batik.util.ParsedURL;
-import java.awt.Toolkit;
-import java.awt.MediaTracker;
-import java.awt.Label;
-import java.awt.Component;
-import java.awt.Graphics2D;
-import java.awt.Image;
-import java.awt.image.RenderedImage;
-import java.awt.image.BufferedImage;
-
-
/**
* This Image tag registy entry is setup to wrap the core JDK
* Image stream tools.
@@ -79,74 +79,185 @@
*/
public Filter handleURL(ParsedURL purl, boolean needRawData) {
- URL url;
+ final URL url;
try {
url = new URL(purl.toString());
} catch (MalformedURLException mue) {
return null;
}
- Toolkit tk = Toolkit.getDefaultToolkit();
- final Image img = tk.createImage(url);
- if (img == null)
- return null;
-
- RenderedImage ri = loadImage(img);
- if (ri == null)
- return null;
+ final DeferRable dr = new DeferRable();
+ final String errCode;
+ final Object [] errParam;
+ if (purl != null) {
+ errCode = ERR_URL_FORMAT_UNREADABLE;
+ errParam = new Object[] {"JDK", url};
+ } else {
+ errCode = ERR_STREAM_FORMAT_UNREADABLE;
+ errParam = new Object[] {"JDK"};
+ }
- return new RedRable(GraphicsUtil.wrap(ri));
+ Thread t = new Thread() {
+ public void run() {
+ Filter filt = null;
+
+ Toolkit tk = Toolkit.getDefaultToolkit();
+ Image img = tk.createImage(url);
+
+ if (img != null) {
+ RenderedImage ri = loadImage(img, dr);
+ if (ri != null) {
+ filt = new RedRable(GraphicsUtil.wrap(ri));
+ }
+ }
+
+ if (filt == null)
+ filt = ImageTagRegistry.getBrokenLinkImage
+ (this, errCode, errParam);
+
+ dr.setSource(filt);
+ }
+ };
+ t.start();
+ return dr;
}
// Stuff for Image Loading.
- static Component mediaComponent = new Label();
- static MediaTracker mediaTracker = new MediaTracker(mediaComponent);
- static int id = 0;
-
- public RenderedImage loadImage(Image img) {
+ public RenderedImage loadImage(Image img, final DeferRable dr) {
// In some cases the image will be a
// BufferedImage (subclass of RenderedImage).
if (img instanceof RenderedImage)
return (RenderedImage)img;
- // Setup the mediaTracker.
- int myID;
- synchronized (mediaTracker) {
- myID = id++;
- }
+ MyImgObs observer = new MyImgObs();
+ Toolkit.getDefaultToolkit().prepareImage(img, -1, -1, observer);
+ observer.waitTilWidthHeightDone();
+ int width = observer.width;
+ int height = observer.height;
+ dr.setBounds(new Rectangle2D.Double(0, 0, width, height));
+
+ // Build the image to draw into.
+ BufferedImage bi = new BufferedImage
+ (width, height, BufferedImage.TYPE_INT_ARGB);
+ Graphics2D g2d = bi.createGraphics();
+
+ // Wait till the image is fully loaded.
+ observer.waitTilImageDone();
+ if (observer.imageError)
+ return null;
+ dr.setProperties(new HashMap());
+
+ g2d.drawImage(img, 0, 0, null);
+ g2d.dispose();
+
+ return bi;
+ }
- // Add our image to the media tracker and wait....
- mediaTracker.addImage(img, myID);
- while (true) {
- try {
- mediaTracker.waitForID(myID);
- }
- catch(InterruptedException ie) {
- // Something woke us up but the image
- // isn't done yet, so try again.
- continue;
- };
- // All done!
- break;
+ public class MyImgObs implements ImageObserver {
+ boolean widthDone = false;
+ boolean heightDone = false;
+ boolean imageDone = false;
+ int width = -1;
+ int height = -1;
+ boolean imageError = false;
+
+ int IMG_BITS = ALLBITS|ERROR|ABORT;
+
+ public void clear() {
+ width=-1;
+ height=-1;
+ widthDone = false;
+ heightDone = false;
+ imageDone = false;
}
- // Clean up our registraction
- mediaTracker.removeImage(img, myID);
+ public boolean imageUpdate(Image img, int infoflags,
+ int x, int y, int width, int height) {
+ synchronized (this) {
+ boolean notify = false;
+
+ if ((infoflags & WIDTH) != 0) this.width = width;
+ if ((infoflags & HEIGHT) != 0) this.height = height;
+
+ if ((infoflags & ALLBITS) != 0) {
+ this.width = width;
+ this.height = height;
+ }
+
+ if ((infoflags & IMG_BITS) != 0) {
+ if ((!widthDone) || (!heightDone) || (!imageDone)) {
+ widthDone = true;
+ heightDone = true;
+ imageDone = true;
+ notify = true;
+ }
+ if ((infoflags & ERROR) != 0) {
+ imageError = true;
+ }
+ }
+
+
+ if ((!widthDone) && (this.width != -1)) {
+ notify = true;
+ widthDone = true;
+ }
+ if ((!heightDone) && (this.height != -1)) {
+ notify = true;
+ heightDone = true;
+ }
- if ((img.getWidth(null) == -1)||
- (img.getHeight(null) == -1))
- return null;
+ if (notify)
+ notifyAll();
+ }
+ return true;
+ }
- // Build the image to .
- BufferedImage bi = null;
- bi = new BufferedImage(img.getWidth(null),
- img.getHeight(null),
- BufferedImage.TYPE_INT_ARGB);
- Graphics2D g2d = bi.createGraphics();
+ public synchronized void waitTilWidthHeightDone() {
+ while ((!widthDone) || (!heightDone)) {
+ try {
+ // Wait for someone to set xxxDone
+ wait();
+ }
+ catch(InterruptedException ie) {
+ // Loop around again see if src is set now...
+ }
+ }
+ }
+ public synchronized void waitTilWidthDone() {
+ while (!widthDone) {
+ try {
+ // Wait for someone to set xxxDone
+ wait();
+ }
+ catch(InterruptedException ie) {
+ // Loop around again see if src is set now...
+ }
+ }
+ }
+ public synchronized void waitTilHeightDone() {
+ while (!heightDone) {
+ try {
+ // Wait for someone to set xxxDone
+ wait();
+ }
+ catch(InterruptedException ie) {
+ // Loop around again see if src is set now...
+ }
+ }
+ }
- g2d.drawImage(img, 0, 0, null);
- g2d.dispose();
- return bi;
+ public synchronized void waitTilImageDone() {
+ while (!imageDone) {
+ try {
+ // Wait for someone to set xxxDone
+ wait();
+ }
+ catch(InterruptedException ie) {
+ // Loop around again see if src is set now...
+ }
+ }
+ }
}
+
}
---------------------------------------------------------------------
To unsubscribe, e-mail: [EMAIL PROTECTED]
For additional commands, e-mail: [EMAIL PROTECTED]