cvs commit: xml-fop/src/org/apache/fop/image/analyser SVGReader.java

2002-11-14 Thread keiron
keiron  2002/11/14 07:19:42

  Modified:src/org/apache/fop/image AbstractFopImage.java BmpImage.java
EPSImage.java FopImage.java FopImageConsumer.java
GifImage.java ImageCache.java ImageFactory.java
JAIImage.java JimiImage.java JpegImage.java
   src/org/apache/fop/image/analyser SVGReader.java
  Log:
  some cleanup of comments and code
  
  Revision  ChangesPath
  1.15  +77 -34xml-fop/src/org/apache/fop/image/AbstractFopImage.java
  
  Index: AbstractFopImage.java
  ===
  RCS file: /home/cvs/xml-fop/src/org/apache/fop/image/AbstractFopImage.java,v
  retrieving revision 1.14
  retrieving revision 1.15
  diff -u -r1.14 -r1.15
  --- AbstractFopImage.java 8 Nov 2002 10:47:58 -   1.14
  +++ AbstractFopImage.java 14 Nov 2002 15:19:41 -  1.15
  @@ -1,6 +1,6 @@
   /*
* $Id$
  - * Copyright (C) 2001 The Apache Software Foundation. All rights reserved.
  + * Copyright (C) 2001-2002 The Apache Software Foundation. All rights reserved.
* For details on use and redistribution please refer to the
* LICENSE file included with these sources.
*/
  @@ -8,15 +8,12 @@
   package org.apache.fop.image;
   
   // Java
  -import java.net.URL;
   import java.awt.color.ColorSpace;
   import java.awt.color.ICC_Profile;
   import java.io.InputStream;
   
   // FOP
   import org.apache.fop.pdf.PDFColor;
  -import org.apache.fop.image.analyser.ImageReaderFactory;
  -import org.apache.fop.image.analyser.ImageReader;
   import org.apache.fop.fo.FOUserAgent;
   
   /**
  @@ -26,17 +23,20 @@
* @see FopImage
*/
   public abstract class AbstractFopImage implements FopImage {
  +/**
  + * Keeps track of what has been loaded.
  + */
   protected int loaded = 0;
   
   /**
* Image width (in pixel).
*/
  -protected int m_width = 0;
  +protected int width = 0;
   
   /**
* Image height (in pixel).
*/
  -protected int m_height = 0;
  +protected int height = 0;
   
   /**
* Image input stream.
  @@ -51,32 +51,32 @@
   /**
* Image color space (java.awt.color.ColorSpace).
*/
  -protected ColorSpace m_colorSpace = null;
  +protected ColorSpace colorSpace = null;
   
   /**
* Bits per pixel.
*/
  -protected int m_bitsPerPixel = 0;
  +protected int bitsPerPixel = 0;
   
   /**
* Image data (uncompressed).
*/
  -protected byte[] m_bitmaps = null;
  +protected byte[] bitmaps = null;
   
   /**
* Image data size.
*/
  -protected int m_bitmapsSize = 0;
  +protected int bitmapsSize = 0;
   
   /**
* Image transparency.
*/
  -protected boolean m_isTransparent = false;
  +protected boolean isTransparent = false;
   
   /**
* Transparent color (org.apache.fop.pdf.PDFColor).
*/
  -protected PDFColor m_transparentColor = null;
  +protected PDFColor transparentColor = null;
   
   /**
* Constructor.
  @@ -86,63 +86,94 @@
* LIimage height
* /UL
* The image data isn't kept in memory.
  - * @param input input stream
  - * imgReader ImageReader object
  - * @return a new FopImage object
  + * @param info image information
*/
   public AbstractFopImage(FopImage.ImageInfo info) {
   this.inputStream = info.inputStream;
   this.imageInfo = info;
  -if(this.imageInfo.width != -1) {
  -m_width = imageInfo.width;
  -m_height = imageInfo.height;
  +if (this.imageInfo.width != -1) {
  +width = imageInfo.width;
  +height = imageInfo.height;
   loaded = loaded | DIMENSIONS;
   }
   }
   
  +/**
  + * Get the mime type for this image.
  + *
  + * @return the mime type for the image
  + */
   public String getMimeType() {
   return imageInfo.mimeType;
   }
   
   /**
* Load image data and initialize its properties.
  + *
  + * @param type the type of loading to do
  + * @param ua the user agent for handling logging etc.
  + * @return true if the loading was successful
*/
   public synchronized boolean load(int type, FOUserAgent ua) {
  -if((loaded  type) != 0) {
  +if ((loaded  type) != 0) {
   return true;
   }
   boolean success = true;
  -if(((type  DIMENSIONS) != 0)  ((loaded  DIMENSIONS) == 0)) {
  +if (((type  DIMENSIONS) != 0)  ((loaded  DIMENSIONS) == 0)) {
   success = success  loadDimensions(ua);
   
  -if(!success) {
  +if (!success) {
   return false;
   }
   loaded = loaded | DIMENSIONS;
   }
  -if(((type  BITMAP) != 

cvs commit: xml-fop/src/org/apache/fop/image/analyser SVGReader.java

2002-11-13 Thread jeremias
jeremias2002/11/13 02:33:08

  Modified:src/org/apache/fop/image/analyser Tag: fop-0_20_2-maintain
SVGReader.java
  Log:
  Adjust for Batik 1.5b4
  
  Revision  ChangesPath
  No   revision
  
  
  No   revision
  
  
  1.12.2.4  +44 -40xml-fop/src/org/apache/fop/image/analyser/SVGReader.java
  
  Index: SVGReader.java
  ===
  RCS file: /home/cvs/xml-fop/src/org/apache/fop/image/analyser/SVGReader.java,v
  retrieving revision 1.12.2.3
  retrieving revision 1.12.2.4
  diff -u -r1.12.2.3 -r1.12.2.4
  --- SVGReader.java6 Jun 2002 07:57:02 -   1.12.2.3
  +++ SVGReader.java13 Nov 2002 10:33:08 -  1.12.2.4
  @@ -1,6 +1,6 @@
   /*
* $Id$
  - * Copyright (C) 2001 The Apache Software Foundation. All rights reserved.
  + * Copyright (C) 2001-2002 The Apache Software Foundation. All rights reserved.
* For details on use and redistribution please refer to the
* LICENSE file included with these sources.
*/
  @@ -8,49 +8,52 @@
   package org.apache.fop.image.analyser;
   
   // Java
  +import java.net.URL;
  +import java.util.List;
  +import java.io.File;
   import java.io.BufferedInputStream;
   import java.io.IOException;
   
  -import org.w3c.dom.svg.SVGDocument;
  -import org.w3c.dom.svg.SVGSVGElement;
  -
  -// FOP
  -import org.apache.fop.messaging.*;
  -import org.apache.fop.image.SVGImage;
  +import java.awt.geom.AffineTransform;
  +import java.awt.Point;
  +import java.awt.geom.Dimension2D;
  +import java.awt.Dimension;
   
   import org.xml.sax.InputSource;
   import org.xml.sax.XMLReader;
   
  -import org.apache.batik.dom.svg.SAXSVGDocumentFactory;
  -
  -import org.apache.batik.dom.svg.*;
  -import org.w3c.dom.*;
  -import org.w3c.dom.svg.*;
  +import org.w3c.dom.Element;
  +import org.w3c.dom.DOMImplementation;
  +import org.w3c.dom.svg.SVGDocument;
   import org.w3c.dom.svg.SVGLength;
  -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.svg.SVGSVGElement;
   
  -import org.w3c.dom.DOMImplementation;
  +// FOP
  +import org.apache.fop.messaging.MessageHandler;
  +import org.apache.fop.image.SVGImage;
  +
  +//Batik
   import org.apache.batik.dom.svg.SVGDOMImplementation;
  +import org.apache.batik.dom.svg.SVGOMDocument;
  +import org.apache.batik.dom.svg.SAXSVGDocumentFactory;
  +//import org.apache.batik.dom.svg.*;
  +import org.apache.batik.bridge.UserAgentAdapter;
  +import org.apache.batik.bridge.UserAgent;
  +import org.apache.batik.bridge.BridgeContext;
  +import org.apache.batik.bridge.UnitProcessor;
  +//import org.apache.batik.swing.svg.*;
  +//import org.apache.batik.swing.gvt.*;
  +//import org.apache.batik.gvt.U*;
  +//import org.apache.batik.gvt.renderer.*;
  +//import org.apache.batik.gvt.filter.*;
  +//import org.apache.batik.gvt.event.*;
   
  -import java.io.File;
  -import java.net.URL;
  -import java.util.List;
  -import java.util.ArrayList;
  -import java.awt.geom.AffineTransform;
  -import java.awt.Point;
  -import java.awt.geom.Dimension2D;
  -import java.awt.Dimension;
   
   /**
* ImageReader object for SVG document image type.
*/
   public class SVGReader extends AbstractImageReader {
  +
   public boolean verifySignature(String uri,
  BufferedInputStream fis) throws IOException {
   this.imageStream = fis;
  @@ -70,14 +73,15 @@
   try {
   SAXSVGDocumentFactory factory =
 new SAXSVGDocumentFactory(SVGImage.getParserName());
  -SVGDocument doc = factory.createDocument(uri, imageStream);
  +SVGDocument doc = (SVGDocument)factory.createDocument(uri, imageStream);
   
  -Element e = ((SVGDocument)doc).getRootElement();
  -String s;
   UserAgent userAgent = new MUserAgent(new AffineTransform());
   BridgeContext ctx = new BridgeContext(userAgent);
  +
  +Element e = ((SVGDocument)doc).getRootElement();
   UnitProcessor.Context uctx = UnitProcessor.createContext(ctx, e);
   
  +String s;
   // 'width' attribute - default is 100%
   s = e.getAttributeNS(null, SVGOMDocument.SVG_WIDTH_ATTRIBUTE);
   if (s.length() == 0) {
  @@ -98,8 +102,7 @@
   } catch (NoClassDefFoundError ncdfe) {
   MessageHandler.errorln(Batik not in class path);
   return false;
  -}
  -catch (Exception e) {
  +} catch (Exception e) {
   MessageHandler.errorln(Could not load external SVG:  +
  e.getMessage());
   // assuming any exception means this document 

cvs commit: xml-fop/src/org/apache/fop/image/analyser SVGReader.java

2002-02-22 Thread keiron

keiron  02/02/22 01:09:35

  Modified:src/org/apache/fop/image SVGImage.java
   src/org/apache/fop/image/analyser SVGReader.java
  Log:
  fix for no class def found error if no batik
  
  Revision  ChangesPath
  1.10  +2 -2  xml-fop/src/org/apache/fop/image/SVGImage.java
  
  Index: SVGImage.java
  ===
  RCS file: /home/cvs/xml-fop/src/org/apache/fop/image/SVGImage.java,v
  retrieving revision 1.9
  retrieving revision 1.10
  diff -u -r1.9 -r1.10
  --- SVGImage.java 21 Feb 2002 09:54:27 -  1.9
  +++ SVGImage.java 22 Feb 2002 09:09:35 -  1.10
  @@ -1,5 +1,5 @@
   /*
  - * $Id: SVGImage.java,v 1.9 2002/02/21 09:54:27 keiron Exp $
  + * $Id: SVGImage.java,v 1.10 2002/02/22 09:09:35 keiron Exp $
* Copyright (C) 2001 The Apache Software Foundation. All rights reserved.
* For details on use and redistribution please refer to the
* LICENSE file included with these sources.
  @@ -29,7 +29,7 @@
   public SVGImage(URL href, ImageReader imgReader) {
   super(href, imgReader);
   if(imgReader instanceof SVGReader) {
  -doc = ((SVGReader)imgReader).getDocument();
  +doc = (SVGDocument)((SVGReader)imgReader).getDocument();
   }
   }
   
  
  
  
  1.18  +72 -46xml-fop/src/org/apache/fop/image/analyser/SVGReader.java
  
  Index: SVGReader.java
  ===
  RCS file: /home/cvs/xml-fop/src/org/apache/fop/image/analyser/SVGReader.java,v
  retrieving revision 1.17
  retrieving revision 1.18
  diff -u -r1.17 -r1.18
  --- SVGReader.java21 Feb 2002 09:54:27 -  1.17
  +++ SVGReader.java22 Feb 2002 09:09:35 -  1.18
  @@ -1,5 +1,5 @@
   /*
  - * $Id: SVGReader.java,v 1.17 2002/02/21 09:54:27 keiron Exp $
  + * $Id: SVGReader.java,v 1.18 2002/02/22 09:09:35 keiron Exp $
* Copyright (C) 2001 The Apache Software Foundation. All rights reserved.
* For details on use and redistribution please refer to the
* LICENSE file included with these sources.
  @@ -55,7 +55,10 @@
   public class SVGReader extends AbstractImageReader {
   public static final String SVG_MIME_TYPE = image/svg+xml;
   FOUserAgent userAgent;
  -SVGDocument doc;
  +Document doc;
  +
  +public SVGReader() {
  +}
   
   public boolean verifySignature(String uri, BufferedInputStream fis,
  FOUserAgent ua) throws IOException {
  @@ -68,7 +71,7 @@
   return SVG_MIME_TYPE;
   }
   
  -public SVGDocument getDocument() {
  +public Document getDocument() {
   return doc;
   }
   
  @@ -77,53 +80,76 @@
* Possibly need a slightly different design for the image stuff.
*/
   protected boolean loadImage(String uri) {
  -// parse document and get the size attributes of the svg element
   try {
  -int length = imageStream.available();
  -imageStream.mark(length);
  -SAXSVGDocumentFactory factory =
  -  new SAXSVGDocumentFactory(SVGImage.getParserName());
  -doc = factory.createDocument(uri, imageStream);
  -
  -Element e = ((SVGDocument) doc).getRootElement();
  -String s;
  -SVGUserAgent userAg = new SVGUserAgent(new AffineTransform());
  -userAg.setLogger(userAgent.getLogger());
  -BridgeContext ctx = new BridgeContext(userAg);
  -UnitProcessor.Context uctx =
  -  UnitProcessor.createContext(ctx, e);
  -
  -// 'width' attribute - default is 100%
  -s = e.getAttributeNS(null, SVGOMDocument.SVG_WIDTH_ATTRIBUTE);
  -if (s.length() == 0) {
  -s = SVGOMDocument.SVG_SVG_WIDTH_DEFAULT_VALUE;
  -}
  -width = (int) 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;
  -}
  -height = (int) UnitProcessor.svgVerticalLengthToUserSpace (
  -   s, SVGOMDocument.SVG_HEIGHT_ATTRIBUTE, uctx);
  -
  -return true;
  -} catch (NoClassDefFoundError ncdfe) {
  -//userAgent.getLogger().error(Batik not in class path, ncdfe);
  +Loader loader = new Loader();
  +return loader.getImage(uri);
  +} catch (NoClassDefFoundError e) {
  +//userAgent.getLogger().error(Batik not in class path, e);
   return false;
   }
  -catch (Exception e) {
  -//userAgent.getLogger().error(Could not load external SVG:  +
  -//   

cvs commit: xml-fop/src/org/apache/fop/image/analyser SVGReader.java

2002-02-22 Thread keiron

keiron  02/02/22 01:18:47

  Modified:src/org/apache/fop/fo FOUserAgent.java
   src/org/apache/fop/image ImageFactory.java ImageLoader.java
   src/org/apache/fop/image/analyser SVGReader.java
  Log:
  improved cache
  gets base dir from user agent
  
  Revision  ChangesPath
  1.6   +10 -1 xml-fop/src/org/apache/fop/fo/FOUserAgent.java
  
  Index: FOUserAgent.java
  ===
  RCS file: /home/cvs/xml-fop/src/org/apache/fop/fo/FOUserAgent.java,v
  retrieving revision 1.5
  retrieving revision 1.6
  diff -u -r1.5 -r1.6
  --- FOUserAgent.java  21 Feb 2002 09:54:26 -  1.5
  +++ FOUserAgent.java  22 Feb 2002 09:18:47 -  1.6
  @@ -1,5 +1,5 @@
   /*
  - * $Id: FOUserAgent.java,v 1.5 2002/02/21 09:54:26 keiron Exp $
  + * $Id: FOUserAgent.java,v 1.6 2002/02/22 09:18:47 keiron Exp $
* Copyright (C) 2001 The Apache Software Foundation. All rights reserved.
* For details on use and redistribution please refer to the
* LICENSE file included with these sources.
  @@ -34,6 +34,7 @@
   HashMap defaults = new HashMap();
   HashMap handlers = new HashMap();
   Logger log;
  +String base;
   
   public void setLogger(Logger logger) {
   log = logger;
  @@ -41,6 +42,14 @@
   
   public Logger getLogger() {
   return log;
  +}
  +
  +public void setBaseDirectory(String b) {
  +base = b;
  +}
  +
  +public String getBaseDirectory() {
  +return base;
   }
   
   /**
  
  
  
  1.2   +69 -18xml-fop/src/org/apache/fop/image/ImageFactory.java
  
  Index: ImageFactory.java
  ===
  RCS file: /home/cvs/xml-fop/src/org/apache/fop/image/ImageFactory.java,v
  retrieving revision 1.1
  retrieving revision 1.2
  diff -u -r1.1 -r1.2
  --- ImageFactory.java 21 Feb 2002 09:54:27 -  1.1
  +++ ImageFactory.java 22 Feb 2002 09:18:47 -  1.2
  @@ -1,5 +1,5 @@
   /*
  - * $Id: ImageFactory.java,v 1.1 2002/02/21 09:54:27 keiron Exp $
  + * $Id: ImageFactory.java,v 1.2 2002/02/22 09:18:47 keiron Exp $
* Copyright (C) 2001 The Apache Software Foundation. All rights reserved.
* For details on use and redistribution please refer to the
* LICENSE file included with these sources.
  @@ -20,6 +20,7 @@
   import java.util.HashSet;
   import java.util.Set;
   import java.util.Collections;
  +import java.util.Iterator;
   
   // FOP
   import org.apache.fop.image.analyser.ImageReaderFactory;
  @@ -39,7 +40,7 @@
*/
   public class ImageFactory {
   private static ImageFactory factory = new ImageFactory();
  -ImageCache cache = new ContextImageCache();
  +ImageCache cache = new ContextImageCache(true);
   
   private ImageFactory() {}
   
  @@ -277,26 +278,58 @@
* weak hashmap so they may be garbage collected.
*/
   class ContextImageCache implements ImageCache {
  -Set invalid = Collections.synchronizedSet(new HashSet());
  +// if this cache is collective then images can be shared
  +// among contexts, this implies that the base directory
  +// is either the same or does not effect the images being
  +// loaded
  +boolean collective;
   Map contextStore = Collections.synchronizedMap(new HashMap());
  -Map weakStore = Collections.synchronizedMap(new WeakHashMap());
  +Set invalid = null;
  +Map weakStore = null;
  +
  +public ContextImageCache(boolean col) {
  +collective = col;
  +if(collective) {
  +weakStore = Collections.synchronizedMap(new WeakHashMap());
  +invalid = Collections.synchronizedSet(new HashSet());
  +}
  +}
   
   // sync around lookups and puts
   // another sync around load for a particular image
   public FopImage getImage(String url, FOUserAgent context) {
  -ImageLoader im;
  +ImageLoader im = null;
   // this protects the finding or creating of a new
   // ImageLoader for multi threads
   synchronized (this) {
  -if (invalid.contains(url)) {
  +if (collective  invalid.contains(url)) {
   return null;
   }
   Context con = (Context) contextStore.get(context);
   if (con == null) {
  -con = new Context(context);
  +con = new Context(context, collective);
   contextStore.put(context, con);
  +} else {
  +if(con.invalid(url)) {
  +return null;
  +}
  +im = con.getImage(url);
   }
  -im = (ImageLoader) weakStore.get(url);
  +if(im == null  collective) {
  +for(Iterator iter = contextStore.values().iterator(); 
iter.hasNext(); ) {
  +Context c = (Context)iter.next();
  +

cvs commit: xml-fop/src/org/apache/fop/image/analyser SVGReader.java

2001-09-25 Thread keiron

keiron  01/09/25 05:32:36

  Modified:src/org/apache/fop/svg SVGElement.java
   src/org/apache/fop/image/analyser SVGReader.java
  Log:
  gets the width and height in a better way
  
  Revision  ChangesPath
  1.13  +20 -11xml-fop/src/org/apache/fop/svg/SVGElement.java
  
  Index: SVGElement.java
  ===
  RCS file: /home/cvs/xml-fop/src/org/apache/fop/svg/SVGElement.java,v
  retrieving revision 1.12
  retrieving revision 1.13
  diff -u -r1.12 -r1.13
  --- SVGElement.java   2001/09/24 07:31:52 1.12
  +++ SVGElement.java   2001/09/25 12:32:36 1.13
  @@ -1,5 +1,5 @@
   /*
  - * $Id: SVGElement.java,v 1.12 2001/09/24 07:31:52 keiron Exp $
  + * $Id: SVGElement.java,v 1.13 2001/09/25 12:32:36 keiron Exp $
* Copyright (C) 2001 The Apache Software Foundation. All rights reserved.
* For details on use and redistribution please refer to the
* LICENSE file included with these sources.
  @@ -138,19 +138,28 @@
   };
   ((SVGOMDocument)doc).setSVGContext(dc);
   
  -// this is ugly preprocessing to get the width and height
  +Element e = ((SVGDocument)doc).getRootElement();
  +String s;
   SVGUserAgent userAgent = new SVGUserAgent(new AffineTransform());
   userAgent.setLogger(log);
  -GVTBuilder builder = new GVTBuilder();
   BridgeContext ctx = new BridgeContext(userAgent);
  -GraphicsNode root;
  -root = builder.build(ctx, doc);
  -// get the 'width' and 'height' attributes of the SVG document
  -float width = (float)ctx.getDocumentSize().getWidth();
  -float height = (float)ctx.getDocumentSize().getHeight();
  -ctx = null;
  -builder = null;
  -///
  +UnitProcessor.Context uctx = UnitProcessor.createContext(ctx, e);
  +
  +// '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);
   svg.setSVGDocument(doc);
  
  
  
  1.11  +20 -11xml-fop/src/org/apache/fop/image/analyser/SVGReader.java
  
  Index: SVGReader.java
  ===
  RCS file: /home/cvs/xml-fop/src/org/apache/fop/image/analyser/SVGReader.java,v
  retrieving revision 1.10
  retrieving revision 1.11
  diff -u -r1.10 -r1.11
  --- SVGReader.java2001/09/24 07:31:52 1.10
  +++ SVGReader.java2001/09/25 12:32:36 1.11
  @@ -1,5 +1,5 @@
   /*
  - * $Id: SVGReader.java,v 1.10 2001/09/24 07:31:52 keiron Exp $
  + * $Id: SVGReader.java,v 1.11 2001/09/25 12:32:36 keiron Exp $
* Copyright (C) 2001 The Apache Software Foundation. All rights reserved.
* For details on use and redistribution please refer to the
* LICENSE file included with these sources.
  @@ -72,18 +72,27 @@
 new SAXSVGDocumentFactory(SVGImage.getParserName());
   SVGDocument doc = factory.createDocument(uri, imageStream);
   
  -// this is ugly preprocessing to get the width and height
  +Element e = ((SVGDocument)doc).getRootElement();
  +String s;
   UserAgent userAgent = new MUserAgent(new AffineTransform());
  -GVTBuilder builder = new GVTBuilder();
   BridgeContext ctx = new BridgeContext(userAgent);
  -GraphicsNode root;
  -root = builder.build(ctx, doc);
  -// get the 'width' and 'height' attributes of the SVG document
  -width = (int) ctx.getDocumentSize().getWidth();
  -height = (int) ctx.getDocumentSize().getHeight();
  -ctx = null;
  -builder = null;
  -///
  +UnitProcessor.Context uctx = UnitProcessor.createContext(ctx, e);
  +
  +// 'width' attribute - default is 100%
  +s = e.getAttributeNS(null, SVGOMDocument.SVG_WIDTH_ATTRIBUTE);
  +if (s.length() == 0) {
  +s = SVGOMDocument.SVG_SVG_WIDTH_DEFAULT_VALUE;
  +}
  +width = (int)UnitProcessor.svgHorizontalLengthToUserSpace
  + (s, SVGOMDocument.SVG_WIDTH_ATTRIBUTE, uctx);
  +
  +// 'height' attribute - default is 100%
  +