deweese 01/11/08 15:02:44 Modified: sources/org/apache/batik/bridge SVGGlyphElementBridge.java SVGPathElementBridge.java SVGPolygonElementBridge.java SVGPolylineElementBridge.java SVGTextPathElementBridge.java SVGUtilities.java UnitProcessor.java ViewBox.java sources/org/apache/batik/css/parser Parser.java Scanner.java sources/org/apache/batik/ext/awt/image/rendered PadRed.java sources/org/apache/batik/parser AWTTransformProducer.java AbstractParser.java AngleParser.java FragmentIdentifierParser.java LengthListParser.java LengthParser.java Parser.java PathParser.java PointsParser.java PreserveAspectRatioParser.java TransformListParser.java sources/org/apache/batik/util ParsedURLDefaultProtocolHandler.java test-resources/org/apache/batik/test regard.xml samplesRendering.xml test-sources/org/apache/batik/test/svg SVGReferenceRenderingAccuracyTest.java SVGRenderingAccuracyTest.java xdocs extendingBatik.xml Log: 1) Modified ...css.parser.Scanner.nextChar and ...parser.AbstractParser.read to be faster and more amenable to inlining where appropriate. 2) Added a parse method on AbstractParser that takes a String in addtion to the one that takes a reader, the bridges now use the string version, this avoids the numerous allocation of 8K read buffers. 3) PadRed is now better about sharing a scratch buffer. 4) SVGReferenceRenderingAccuracyTest now properly handles id's that have fragements. 5) Fixed some comments in regard.xml 6) Fixed alias for a test in samplesRendering.xml 7) Updated extension Documentation to reference new Extension classes. Revision Changes Path 1.6 +2 -2 xml-batik/sources/org/apache/batik/bridge/SVGGlyphElementBridge.java Index: SVGGlyphElementBridge.java =================================================================== RCS file: /home/cvs/xml-batik/sources/org/apache/batik/bridge/SVGGlyphElementBridge.java,v retrieving revision 1.5 retrieving revision 1.6 diff -u -r1.5 -r1.6 --- SVGGlyphElementBridge.java 2001/08/02 07:49:35 1.5 +++ SVGGlyphElementBridge.java 2001/11/08 23:02:42 1.6 @@ -43,7 +43,7 @@ * Bridge class for the <glyph> element. * * @author <a href="mailto:[EMAIL PROTECTED]">Bella Robinson</a> - * @version $Id: SVGGlyphElementBridge.java,v 1.5 2001/08/02 07:49:35 bella Exp $ + * @version $Id: SVGGlyphElementBridge.java,v 1.6 2001/11/08 23:02:42 deweese Exp $ */ public class SVGGlyphElementBridge extends AbstractSVGBridge implements ErrorConstants { @@ -99,7 +99,7 @@ try { PathParser pathParser = new PathParser(); pathParser.setPathHandler(app); - pathParser.parse(new StringReader(d)); + pathParser.parse(d); } catch (ParseException ex) { throw new BridgeException(glyphElement, ERR_ATTRIBUTE_VALUE_MALFORMED, 1.7 +2 -2 xml-batik/sources/org/apache/batik/bridge/SVGPathElementBridge.java Index: SVGPathElementBridge.java =================================================================== RCS file: /home/cvs/xml-batik/sources/org/apache/batik/bridge/SVGPathElementBridge.java,v retrieving revision 1.6 retrieving revision 1.7 diff -u -r1.6 -r1.7 --- SVGPathElementBridge.java 2001/05/02 14:34:09 1.6 +++ SVGPathElementBridge.java 2001/11/08 23:02:43 1.7 @@ -22,7 +22,7 @@ * Bridge class for the <path> element. * * @author <a href="mailto:[EMAIL PROTECTED]">Thierry Kormann</a> - * @version $Id: SVGPathElementBridge.java,v 1.6 2001/05/02 14:34:09 tkormann Exp $ + * @version $Id: SVGPathElementBridge.java,v 1.7 2001/11/08 23:02:43 deweese Exp $ */ public class SVGPathElementBridge extends SVGDecoratedShapeElementBridge { @@ -57,7 +57,7 @@ try { PathParser pathParser = new PathParser(); pathParser.setPathHandler(app); - pathParser.parse(new StringReader(s)); + pathParser.parse(s); } catch (ParseException ex) { BridgeException bex = new BridgeException(e, ERR_ATTRIBUTE_VALUE_MALFORMED, 1.8 +2 -2 xml-batik/sources/org/apache/batik/bridge/SVGPolygonElementBridge.java Index: SVGPolygonElementBridge.java =================================================================== RCS file: /home/cvs/xml-batik/sources/org/apache/batik/bridge/SVGPolygonElementBridge.java,v retrieving revision 1.7 retrieving revision 1.8 diff -u -r1.7 -r1.8 --- SVGPolygonElementBridge.java 2001/05/02 14:34:11 1.7 +++ SVGPolygonElementBridge.java 2001/11/08 23:02:43 1.8 @@ -22,7 +22,7 @@ * Bridge class for the <polygon> element. * * @author <a href="mailto:[EMAIL PROTECTED]">Thierry Kormann</a> - * @version $Id: SVGPolygonElementBridge.java,v 1.7 2001/05/02 14:34:11 tkormann Exp $ + * @version $Id: SVGPolygonElementBridge.java,v 1.8 2001/11/08 23:02:43 deweese Exp $ */ public class SVGPolygonElementBridge extends SVGDecoratedShapeElementBridge { @@ -56,7 +56,7 @@ try { PointsParser pp = new PointsParser(); pp.setPointsHandler(app); - pp.parse(new StringReader(s)); + pp.parse(s); } catch (ParseException ex) { BridgeException bex = new BridgeException(e, ERR_ATTRIBUTE_VALUE_MALFORMED, 1.7 +2 -2 xml-batik/sources/org/apache/batik/bridge/SVGPolylineElementBridge.java Index: SVGPolylineElementBridge.java =================================================================== RCS file: /home/cvs/xml-batik/sources/org/apache/batik/bridge/SVGPolylineElementBridge.java,v retrieving revision 1.6 retrieving revision 1.7 diff -u -r1.6 -r1.7 --- SVGPolylineElementBridge.java 2001/05/02 14:34:11 1.6 +++ SVGPolylineElementBridge.java 2001/11/08 23:02:43 1.7 @@ -22,7 +22,7 @@ * Bridge class for the <polyline> element. * * @author <a href="mailto:[EMAIL PROTECTED]">Thierry Kormann</a> - * @version $Id: SVGPolylineElementBridge.java,v 1.6 2001/05/02 14:34:11 tkormann Exp $ + * @version $Id: SVGPolylineElementBridge.java,v 1.7 2001/11/08 23:02:43 deweese Exp $ */ public class SVGPolylineElementBridge extends SVGDecoratedShapeElementBridge { @@ -56,7 +56,7 @@ try { PointsParser pp = new PointsParser(); pp.setPointsHandler(app); - pp.parse(new StringReader(s)); + pp.parse(s); } catch (ParseException ex) { BridgeException bex = new BridgeException(e, ERR_ATTRIBUTE_VALUE_MALFORMED, 1.4 +2 -2 xml-batik/sources/org/apache/batik/bridge/SVGTextPathElementBridge.java Index: SVGTextPathElementBridge.java =================================================================== RCS file: /home/cvs/xml-batik/sources/org/apache/batik/bridge/SVGTextPathElementBridge.java,v retrieving revision 1.3 retrieving revision 1.4 diff -u -r1.3 -r1.4 --- SVGTextPathElementBridge.java 2001/07/05 06:56:09 1.3 +++ SVGTextPathElementBridge.java 2001/11/08 23:02:43 1.4 @@ -23,7 +23,7 @@ * Bridge class for the <textPath> element. * * @author <a href="mailto:[EMAIL PROTECTED]">Bella Robinson</a> - * @version $Id: SVGTextPathElementBridge.java,v 1.3 2001/07/05 06:56:09 bella Exp $ + * @version $Id: SVGTextPathElementBridge.java,v 1.4 2001/11/08 23:02:43 deweese Exp $ */ public class SVGTextPathElementBridge extends AbstractSVGBridge implements ErrorConstants { @@ -71,7 +71,7 @@ try { PathParser pathParser = new PathParser(); pathParser.setPathHandler(app); - pathParser.parse(new StringReader(s)); + pathParser.parse(s); } catch (ParseException ex) { throw new BridgeException(pathElement, ERR_ATTRIBUTE_VALUE_MALFORMED, new Object[] {SVG_D_ATTRIBUTE}); 1.17 +2 -3 xml-batik/sources/org/apache/batik/bridge/SVGUtilities.java Index: SVGUtilities.java =================================================================== RCS file: /home/cvs/xml-batik/sources/org/apache/batik/bridge/SVGUtilities.java,v retrieving revision 1.16 retrieving revision 1.17 diff -u -r1.16 -r1.17 --- SVGUtilities.java 2001/10/09 22:17:10 1.16 +++ SVGUtilities.java 2001/11/08 23:02:43 1.17 @@ -50,7 +50,7 @@ * * @author <a href="mailto:[EMAIL PROTECTED]">Thierry Kormann</a> * @author <a href="mailto:[EMAIL PROTECTED]">Stephane Hillion</a> - * @version $Id: SVGUtilities.java,v 1.16 2001/10/09 22:17:10 deweese Exp $ + * @version $Id: SVGUtilities.java,v 1.17 2001/11/08 23:02:43 deweese Exp $ */ public abstract class SVGUtilities implements SVGConstants, ErrorConstants { @@ -818,8 +818,7 @@ String attr, String transform) { try { - StringReader r = new StringReader(transform); - return AWTTransformProducer.createAffineTransform(r); + return AWTTransformProducer.createAffineTransform(transform); } catch (ParseException ex) { throw new BridgeException(e, ERR_ATTRIBUTE_VALUE_MALFORMED, new Object[] {attr, transform, ex}); 1.6 +3 -3 xml-batik/sources/org/apache/batik/bridge/UnitProcessor.java Index: UnitProcessor.java =================================================================== RCS file: /home/cvs/xml-batik/sources/org/apache/batik/bridge/UnitProcessor.java,v retrieving revision 1.5 retrieving revision 1.6 diff -u -r1.5 -r1.6 --- UnitProcessor.java 2001/10/19 07:44:08 1.5 +++ UnitProcessor.java 2001/11/08 23:02:43 1.6 @@ -28,7 +28,7 @@ * * @author <a href="mailto:[EMAIL PROTECTED]">Stephane Hillion</a> * @author <a href="mailto:[EMAIL PROTECTED]">Thierry Kormann</a> - * @version $Id: UnitProcessor.java,v 1.5 2001/10/19 07:44:08 tkormann Exp $ + * @version $Id: UnitProcessor.java,v 1.6 2001/11/08 23:02:43 deweese Exp $ */ public abstract class UnitProcessor { @@ -196,7 +196,7 @@ LengthParser lengthParser = new LengthParser(); UnitResolver ur = new UnitResolver(); lengthParser.setLengthHandler(ur); - lengthParser.parse(new StringReader(s)); + lengthParser.parse(s); return svgToObjectBoundingBox(ur.value, ur.unit, d, ctx); } catch (ParseException ex) { throw new BridgeException(ctx.getElement(), @@ -368,7 +368,7 @@ LengthParser lengthParser = new LengthParser(); UnitResolver ur = new UnitResolver(); lengthParser.setLengthHandler(ur); - lengthParser.parse(new StringReader(s)); + lengthParser.parse(s); return svgToUserSpace(ur.value, ur.unit, d, ctx); } catch (ParseException ex) { throw new BridgeException(ctx.getElement(), 1.7 +5 -5 xml-batik/sources/org/apache/batik/bridge/ViewBox.java Index: ViewBox.java =================================================================== RCS file: /home/cvs/xml-batik/sources/org/apache/batik/bridge/ViewBox.java,v retrieving revision 1.6 retrieving revision 1.7 diff -u -r1.6 -r1.7 --- ViewBox.java 2001/08/22 12:17:26 1.6 +++ ViewBox.java 2001/11/08 23:02:43 1.7 @@ -29,7 +29,7 @@ * This class provides convenient methods to handle viewport. * * @author <a href="mailto:[EMAIL PROTECTED]">Thierry Kormann</a> - * @version $Id: ViewBox.java,v 1.6 2001/08/22 12:17:26 tkormann Exp $ + * @version $Id: ViewBox.java,v 1.7 2001/11/08 23:02:43 deweese Exp $ */ public abstract class ViewBox implements SVGConstants, ErrorConstants { @@ -63,7 +63,7 @@ ViewHandler vh = new ViewHandler(); FragmentIdentifierParser p = new FragmentIdentifierParser(); p.setFragmentIdentifierHandler(vh); - p.parse(new StringReader(ref)); + p.parse(ref); Element attrDefElement = e; // the element that defines the attributes if (vh.hasId) { @@ -104,7 +104,7 @@ ViewHandler ph = new ViewHandler(); pp.setPreserveAspectRatioHandler(ph); try { - pp.parse(new StringReader(aspectRatio)); + pp.parse(aspectRatio); } catch (ParseException ex) { throw new BridgeException (attrDefElement, ERR_ATTRIBUTE_VALUE_MALFORMED, @@ -189,7 +189,7 @@ ViewHandler ph = new ViewHandler(); p.setPreserveAspectRatioHandler(ph); try { - p.parse(new StringReader(aspectRatio)); + p.parse(aspectRatio); } catch (ParseException ex) { throw new BridgeException (e, ERR_ATTRIBUTE_VALUE_MALFORMED, @@ -223,7 +223,7 @@ ViewHandler ph = new ViewHandler(); p.setPreserveAspectRatioHandler(ph); try { - p.parse(new StringReader(aspectRatio)); + p.parse(aspectRatio); } catch (ParseException ex) { throw new BridgeException (e, ERR_ATTRIBUTE_VALUE_MALFORMED, 1.15 +13 -3 xml-batik/sources/org/apache/batik/css/parser/Parser.java Index: Parser.java =================================================================== RCS file: /home/cvs/xml-batik/sources/org/apache/batik/css/parser/Parser.java,v retrieving revision 1.14 retrieving revision 1.15 diff -u -r1.14 -r1.15 --- Parser.java 2001/11/02 15:31:10 1.14 +++ Parser.java 2001/11/08 23:02:43 1.15 @@ -43,7 +43,7 @@ * This class implements the {@link org.w3c.css.sac.Parser} interface. * * @author <a href="mailto:[EMAIL PROTECTED]">Stephane Hillion</a> - * @version $Id: Parser.java,v 1.14 2001/11/02 15:31:10 hillion Exp $ + * @version $Id: Parser.java,v 1.15 2001/11/08 23:02:43 deweese Exp $ */ public class Parser implements org.w3c.css.sac.Parser, @@ -282,6 +282,7 @@ } } finally { documentHandler.endDocument(source); + scanner = null; } } @@ -305,6 +306,8 @@ parseStyleDeclaration(false); } catch (CSSParseException e) { reportError(e); + } finally { + scanner = null; } } @@ -315,6 +318,7 @@ scanner = new Scanner(characterStream(source, null)); nextIgnoreSpaces(); parseRule(); + scanner = null; } /** @@ -324,8 +328,9 @@ throws CSSException, IOException { scanner = new Scanner(characterStream(source, null)); nextIgnoreSpaces(); - - return parseSelectorList(); + SelectorList ret = parseSelectorList(); + scanner = null; + return ret; } /** @@ -346,6 +351,8 @@ throw e; } + scanner = null; + if (current != LexicalUnits.EOF) { errorHandler.fatalError(createCSSParseException("eof.expected")); } @@ -360,6 +367,9 @@ throws CSSException, IOException { scanner = new Scanner(characterStream(source, null)); nextIgnoreSpaces(); + + scanner = null; + switch (current) { case LexicalUnits.EOF: return false; 1.7 +108 -49 xml-batik/sources/org/apache/batik/css/parser/Scanner.java Index: Scanner.java =================================================================== RCS file: /home/cvs/xml-batik/sources/org/apache/batik/css/parser/Scanner.java,v retrieving revision 1.6 retrieving revision 1.7 diff -u -r1.6 -r1.7 --- Scanner.java 2001/08/21 15:25:59 1.6 +++ Scanner.java 2001/11/08 23:02:43 1.7 @@ -16,7 +16,7 @@ * units. * * @author <a href="mailto:[EMAIL PROTECTED]">Stephane Hillion</a> - * @version $Id: Scanner.java,v 1.6 2001/08/21 15:25:59 hillion Exp $ + * @version $Id: Scanner.java,v 1.7 2001/11/08 23:02:43 deweese Exp $ */ public class Scanner { @@ -36,11 +36,6 @@ protected int column = 1; /** - * The previous char. - */ - protected int previous; - - /** * The current char. */ protected int current; @@ -48,7 +43,7 @@ /** * The reading buffer. */ - protected char[] readBuffer = new char[4096]; + protected char[] readBuffer; /** * The current position in the read buffer. @@ -63,7 +58,7 @@ /** * The recording buffer. */ - protected char[] buffer = new char[4096]; + protected char[] buffer = new char[128]; /** * The current position in the buffer. @@ -98,6 +93,7 @@ public Scanner(Reader r) throws ParseException { try { reader = r; + readBuffer = new char[4096]; current = nextChar(); } catch (IOException e) { throw new ParseException(e); @@ -105,6 +101,27 @@ } /** + * Creates a new Scanner object. + * @param r The reader to scan. + */ + public Scanner(String s) throws ParseException { + try { + reader = null; + readBuffer = s.toCharArray(); + readPosition = 0; + readCount = readBuffer.length; + collapseCRNL(0); + if (readCount == 0) { + current = -1; + } else { + current = nextChar(); + } + } catch (IOException e) { + throw new ParseException(e); + } + } + + /** * Returns the current line. */ public int getLine() { @@ -143,8 +160,12 @@ * Clears the buffer. */ public void clearBuffer() { - position = 1; - buffer[0] = (char)previous; + if (position <= 0) { + position = 0; + } else { + buffer[0] = buffer[position-1]; + position = 1; + } } /** @@ -1186,57 +1207,95 @@ * end of stream has been reached. */ protected int nextChar() throws IOException { - int c = readChar(); + if ((readPosition == readCount) && (!fillReadBuffer())) { + return (char)(current = -1); + } - // Line break normalization. - switch (c) { - case -1: - return current = previous = -1; - - case 10: - if (previous == 13) { - previous = 10; - return current = nextChar(); - } - line++; - column = 1; - previous = c; - break; + current = readBuffer[readPosition++]; - case 13: - previous = c; - c = 10; + if (current != 10) { + column++; + } else { line++; column = 1; - break; - - default: - previous = c; - column++; } + if (position == buffer.length) { char[] t = new char[position * 3 / 2]; - for (int i = position - 1; i >= 0; --i) { - t[i] = buffer[i]; - } + // System.out.println("Resizing Buffer: " + t.length); + System.arraycopy(buffer, 0, t, 0, position); buffer = t; } - buffer[position++] = (char)c; - return current = c; + + return buffer[position++] = (char)current; } - /** - * Reads a single char from the reader. - */ - protected int readChar() throws IOException { - if (readPosition == readCount) { - readPosition = 0; - readCount = reader.read(readBuffer, 0, readBuffer.length); - if (readCount == -1) { - readCount = 0; - return -1; + protected final boolean fillReadBuffer() throws IOException { + if (readCount != 0) { + if (readPosition == readCount) { + readBuffer[0] = readBuffer[readCount-1]; + readCount=readPosition=1; + } else { + // we keep the last char in our readBuffer. + System.arraycopy(readBuffer, readPosition-1, readBuffer, 0, + readCount-readPosition+1); + readCount = (readCount-readPosition)+1; + readPosition = 1; + } + } + + // No reader so can't extend... + if (reader == null) + return (readCount != readPosition); + + // remember where the fill starts... + int src=readCount-1; + if (src < 0) src = 0; + + // Refill the readBuffer... + int read = reader.read(readBuffer, readCount, + readBuffer.length-readCount); + if (read == -1) + return (readCount != readPosition); + + readCount+=read; // add in chars read. + + + collapseCRNL(src); // Now collapse cr/nl... + + return (readCount != readPosition); + } + + protected final void collapseCRNL(int src) { + // Now collapse cr/nl... + while (src<readCount) { + if (readBuffer[src] != 13) { + src++; + } else { + readBuffer[src] = 10; + src++; + if (src>=readCount) break; + if (readBuffer[src] == 10) { + // We now need to collapse some of the chars to + // eliminate cr/nl pairs. This is where we do it... + int dst = src; // start writing where this 10 is + src++; // skip reading this 10. + while (src<readCount) { + if (readBuffer[src] == 13) { + readBuffer[dst++] = 10; + src++; + if (src>=readCount) break; + if (readBuffer[src] == 10) { + src++; + } + continue; + } + readBuffer[dst++] = readBuffer[src++]; + } + readCount = dst; + break; + } } } - return readBuffer[readPosition++]; } } 1.9 +7 -2 xml-batik/sources/org/apache/batik/ext/awt/image/rendered/PadRed.java Index: PadRed.java =================================================================== RCS file: /home/cvs/xml-batik/sources/org/apache/batik/ext/awt/image/rendered/PadRed.java,v retrieving revision 1.8 retrieving revision 1.9 diff -u -r1.8 -r1.9 --- PadRed.java 2001/04/30 22:01:05 1.8 +++ PadRed.java 2001/11/08 23:02:43 1.9 @@ -32,7 +32,7 @@ * This is an implementation of a Pad operation as a RenderedImage. * * @author <a href="mailto:[EMAIL PROTECTED]">Thomas DeWeese</a> - * @version $Id: PadRed.java,v 1.8 2001/04/30 22:01:05 deweese Exp $ */ + * @version $Id: PadRed.java,v 1.9 2001/11/08 23:02:43 deweese Exp $ */ public class PadRed extends AbstractRed { static final boolean DEBUG=false; @@ -101,12 +101,17 @@ protected static class ZeroRecter { WritableRaster wr; int bands; + static int [] zeros=null; public ZeroRecter(WritableRaster wr) { this.wr = wr; this.bands = wr.getSampleModel().getNumBands(); } public void zeroRect(Rectangle r) { - int [] zeros = new int[r.width*bands]; + synchronized (this) { + if ((zeros == null) || (zeros.length <r.width*bands)) + zeros = new int[r.width*bands]; + } + for (int y=0; y<r.height; y++) { wr.setPixels(r.x, r.y+y, r.width, 1, zeros); } 1.4 +16 -1 xml-batik/sources/org/apache/batik/parser/AWTTransformProducer.java Index: AWTTransformProducer.java =================================================================== RCS file: /home/cvs/xml-batik/sources/org/apache/batik/parser/AWTTransformProducer.java,v retrieving revision 1.3 retrieving revision 1.4 diff -u -r1.3 -r1.4 --- AWTTransformProducer.java 2001/02/01 13:45:50 1.3 +++ AWTTransformProducer.java 2001/11/08 23:02:43 1.4 @@ -17,7 +17,7 @@ * an AffineTransform from the value of a 'transform' attribute. * * @author <a href="mailto:[EMAIL PROTECTED]">Stephane Hillion</a> - * @version $Id: AWTTransformProducer.java,v 1.3 2001/02/01 13:45:50 tkormann Exp $ + * @version $Id: AWTTransformProducer.java,v 1.4 2001/11/08 23:02:43 deweese Exp $ */ public class AWTTransformProducer implements TransformListHandler { /** @@ -36,6 +36,21 @@ p.setTransformListHandler(th); p.parse(r); + + return th.getAffineTransform(); + } + + /** + * Utility method for creating an AffineTransform. + * @param r The reader used to read the transform specification. + */ + public static AffineTransform createAffineTransform(String s) + throws ParseException { + TransformListParser p = new TransformListParser(); + AWTTransformProducer th = new AWTTransformProducer(); + + p.setTransformListHandler(th); + p.parse(s); return th.getAffineTransform(); } 1.4 +176 -84 xml-batik/sources/org/apache/batik/parser/AbstractParser.java Index: AbstractParser.java =================================================================== RCS file: /home/cvs/xml-batik/sources/org/apache/batik/parser/AbstractParser.java,v retrieving revision 1.3 retrieving revision 1.4 diff -u -r1.3 -r1.4 --- AbstractParser.java 2001/08/21 15:26:00 1.3 +++ AbstractParser.java 2001/11/08 23:02:43 1.4 @@ -24,7 +24,7 @@ * and error handling methods. * * @author <a href="mailto:[EMAIL PROTECTED]">Stephane Hillion</a> - * @version $Id: AbstractParser.java,v 1.3 2001/08/21 15:26:00 hillion Exp $ + * @version $Id: AbstractParser.java,v 1.4 2001/11/08 23:02:43 deweese Exp $ */ public abstract class AbstractParser implements Parser { @@ -63,7 +63,7 @@ /** * The buffer. */ - protected char[] buffer = new char[4096]; + protected char[] buffer; /** * The current position in the buffer. @@ -80,10 +80,6 @@ */ protected int current; - /** - * The previous char. - */ - protected int previous; /** * Returns the current character value. @@ -132,63 +128,124 @@ } /** - * Initializes the parser. + * Parses the given reader */ - protected void initialize(Reader r) { + public void parse(Reader r) throws ParseException { reader = r; + buffer = new char[4096]; + + doParse(); } /** - * Reads one character from the given reader and sets 'current' to this - * value. + * Parses the given string. */ - protected void read() { - try { - if (position == count) { - position = 0; - count = reader.read(buffer, 0, buffer.length); - if (count == -1) { - count = 0; - current = -1; - return; + public void parse(String s) throws ParseException { + reader = null; + buffer = s.toCharArray(); + position=0; + count=buffer.length; + collapseCRNL(0, count); + + doParse(); + } + + /** + * Method resposible for actually parsing data after AbstractParser + * has initialized it's self. + */ + protected abstract void doParse() throws ParseException ; + + protected final void collapseCRNL(int src, int end) { + // Now collapse cr/nl... + while(src<end) { + if (buffer[src] != 13) { + src++; + } else { + buffer[src] = 10; + src++; + if (src>=end) break; + if (buffer[src] == 10) { + // We now need to collapse some of the chars to + // eliminate cr/nl pairs. This is where we do it... + int dst = src; // start writing where this 10 is + src++; // skip reading this 10. + while (src<end) { + if (buffer[src] == 13) { + buffer[dst++] = 10; + src++; + if (src>=end) break; + if (buffer[src] == 10) { + src++; + } + continue; + } + buffer[dst++] = buffer[src++]; + } + end = dst; + break; } } - int c = buffer[position++]; - - switch (c) { - case -1: - current = previous = -1; - return; + } + } - case 10: - if (previous == 13) { - previous = 10; - read(); - return; + protected final boolean fillBuffer() { + try { + if (count != 0) { + if (position == count) { + buffer[0] = buffer[count-1]; + count=position=1; + } else { + // we keep the last char in our buffer. + System.arraycopy(buffer, position-1, buffer, 0, + count-position+1); + count = (count-position)+1; + position = 1; } - line++; - column = 1; - previous = c; - break; - - case 13: - previous = c; - c = 10; - line++; - column = 1; - break; - - default: - previous = c; - column++; + } + + if (reader == null) + return (count != position); + + // remember where the fill starts... + int src=count-1; + if (src < 0) src = 0; + + // Refill the buffer... + int read = reader.read(buffer, count, buffer.length-count); + if (read == -1) { + return (count != position); } - current = c; + + count+=read; // add in chars read. + collapseCRNL(src, count); } catch (IOException e) { errorHandler.error (new ParseException (createErrorMessage("io.exception", null), e)); } + return (count != position); + } + + /** + * Reads one character from the given reader and sets 'current' to this + * value. + */ + protected void read() { + if ((position == count) && (!fillBuffer())) { + current = -1; + return; + } + + current = buffer[position++]; + + if (current == 10) { + line++; + column = 1; + } else { + column++; + } } /** @@ -198,8 +255,8 @@ */ protected void reportError(String key, Object[] args) throws ParseException { - errorHandler.error(new ParseException(createErrorMessage(key, args), - line, + errorHandler.error(new ParseException(createErrorMessage(key, args), + line, column)); } @@ -209,7 +266,7 @@ * @param args The message arguments. */ protected String createErrorMessage(String key, Object[] args) { - try { + try { return formatMessage(key, args); } catch (MissingResourceException e) { return key; @@ -221,53 +278,88 @@ * @return BUNDLE_CLASSNAME. */ protected String getBundleClassName() { - return BUNDLE_CLASSNAME; + return BUNDLE_CLASSNAME; } /** * Skips the whitespaces in the current reader. */ protected void skipSpaces() { + switch (current) { + default: + return; + case 0x20: + case 0x9: + case 0xD: + case 0xA: + } for (;;) { - switch (current) { - default: - return; - case 0x20: - case 0x9: - case 0xD: - case 0xA: - } - read(); - } + if ((position == count) && (!fillBuffer())) { + current = -1; + return; + } + current = buffer[position++]; + + switch (current) { + default: return; + case 0x20: case 0x09: column++; break; + case 0x0D: case 0x0A: line++; column=0; break; + } + } } /** * Skips the whitespaces and an optional comma. */ protected void skipCommaSpaces() { - wsp1: for (;;) { - switch (current) { - default: - break wsp1; - case 0x20: - case 0x9: - case 0xD: - case 0xA: - } - read(); - } - if (current == ',') { - wsp2: for (;;) { - read(); - switch (current) { - default: - break wsp2; - case 0x20: - case 0x9: - case 0xD: - case 0xA: - } - } - } + // Check current char... + switch (current) { + default: return; + case 0x20: case 0x09: case 0x0D: case 0x0A: break; // nl/cr, spc, tab + case ',': + // for a comma just eat rest of ws. + for(;;) { + if ((position == count) && (!fillBuffer())) { + current = -1; + return; + } + current = buffer[position++]; + switch (current) { + default: return; + case 0x20: case 0x09: column++; break; // space/tab + case 0x0D: case 0x0A: line++; column=0; break; // nl/cr + } + } + } + + for(;;) { + // After current char we need to take care to increment line + // and column... + if ((position == count) && (!fillBuffer())) { + current = -1; + return; + } + current = buffer[position++]; + + switch (current) { + default: return; + case 0x20: case 0x09: column++; break; // space tab + case 0x0D: case 0x0A: line++; column=0; break; // nl cr + case ',': + // for a comma just eat rest of ws. + for(;;) { + if ((position == count) && (!fillBuffer())) { + current = -1; + return; + } + current = buffer[position++]; + switch (current) { + default: return; + case 0x20: case 0x09: column++; break; + case 0x0D: case 0x0A: line++; column=0; break; + } + } + } + } } } 1.3 +2 -4 xml-batik/sources/org/apache/batik/parser/AngleParser.java Index: AngleParser.java =================================================================== RCS file: /home/cvs/xml-batik/sources/org/apache/batik/parser/AngleParser.java,v retrieving revision 1.2 retrieving revision 1.3 diff -u -r1.2 -r1.3 --- AngleParser.java 2001/01/03 14:17:39 1.2 +++ AngleParser.java 2001/11/08 23:02:43 1.3 @@ -15,7 +15,7 @@ * values. * * @author <a href="mailto:[EMAIL PROTECTED]">Stephane Hillion</a> - * @version $Id: AngleParser.java,v 1.2 2001/01/03 14:17:39 hillion Exp $ + * @version $Id: AngleParser.java,v 1.3 2001/11/08 23:02:43 deweese Exp $ */ public class AngleParser extends NumberParser { @@ -50,9 +50,7 @@ /** * Parses the given reader representing an angle. */ - public void parse(Reader r) throws ParseException { - initialize(r); - + protected void doParse() throws ParseException { angleHandler.startAngle(); read(); 1.8 +3 -4 xml-batik/sources/org/apache/batik/parser/FragmentIdentifierParser.java Index: FragmentIdentifierParser.java =================================================================== RCS file: /home/cvs/xml-batik/sources/org/apache/batik/parser/FragmentIdentifierParser.java,v retrieving revision 1.7 retrieving revision 1.8 diff -u -r1.7 -r1.8 --- FragmentIdentifierParser.java 2001/08/21 15:26:00 1.7 +++ FragmentIdentifierParser.java 2001/11/08 23:02:43 1.8 @@ -17,7 +17,7 @@ * fragment identifiers. * * @author <a href="mailto:[EMAIL PROTECTED]">Stephane Hillion</a> - * @version $Id: FragmentIdentifierParser.java,v 1.7 2001/08/21 15:26:00 hillion Exp $ + * @version $Id: FragmentIdentifierParser.java,v 1.8 2001/11/08 23:02:43 deweese Exp $ */ public class FragmentIdentifierParser extends AbstractParser { @@ -69,11 +69,10 @@ /** * Parses the given reader. */ - public void parse(Reader r) throws ParseException { - initialize(r); + protected void doParse() throws ParseException { bufferSize = 0; - read(); + read(); fragmentIdentifierHandler.startFragmentIdentifier(); 1.3 +2 -4 xml-batik/sources/org/apache/batik/parser/LengthListParser.java Index: LengthListParser.java =================================================================== RCS file: /home/cvs/xml-batik/sources/org/apache/batik/parser/LengthListParser.java,v retrieving revision 1.2 retrieving revision 1.3 diff -u -r1.2 -r1.3 --- LengthListParser.java 2001/01/03 14:17:39 1.2 +++ LengthListParser.java 2001/11/08 23:02:43 1.3 @@ -16,7 +16,7 @@ * list values. * * @author <a href="mailto:[EMAIL PROTECTED]">Stephane Hillion</a> - * @version $Id: LengthListParser.java,v 1.2 2001/01/03 14:17:39 hillion Exp $ + * @version $Id: LengthListParser.java,v 1.3 2001/11/08 23:02:43 deweese Exp $ */ public class LengthListParser extends LengthParser { @@ -52,9 +52,7 @@ /** * Parses the given reader. */ - public void parse(Reader r) throws ParseException { - initialize(r); - + protected void doParse() throws ParseException { ((LengthListHandler)lengthHandler).startLengthList(); read(); 1.3 +2 -7 xml-batik/sources/org/apache/batik/parser/LengthParser.java Index: LengthParser.java =================================================================== RCS file: /home/cvs/xml-batik/sources/org/apache/batik/parser/LengthParser.java,v retrieving revision 1.2 retrieving revision 1.3 diff -u -r1.2 -r1.3 --- LengthParser.java 2001/01/03 14:17:39 1.2 +++ LengthParser.java 2001/11/08 23:02:43 1.3 @@ -15,7 +15,7 @@ * values. * * @author <a href="mailto:[EMAIL PROTECTED]">Stephane Hillion</a> - * @version $Id: LengthParser.java,v 1.2 2001/01/03 14:17:39 hillion Exp $ + * @version $Id: LengthParser.java,v 1.3 2001/11/08 23:02:43 deweese Exp $ */ public class LengthParser extends NumberParser { @@ -58,12 +58,7 @@ return lengthHandler; } - /** - * Parses the given reader. - */ - public void parse(Reader r) throws ParseException { - initialize(r); - + protected void doParse() throws ParseException { lengthHandler.startLength(); read(); 1.2 +8 -3 xml-batik/sources/org/apache/batik/parser/Parser.java Index: Parser.java =================================================================== RCS file: /home/cvs/xml-batik/sources/org/apache/batik/parser/Parser.java,v retrieving revision 1.1 retrieving revision 1.2 diff -u -r1.1 -r1.2 --- Parser.java 2000/10/10 18:40:27 1.1 +++ Parser.java 2001/11/08 23:02:43 1.2 @@ -17,13 +17,18 @@ * This interface represents a parser. * * @author <a href="mailto:[EMAIL PROTECTED]">Stephane Hillion</a> - * @version $Id: Parser.java,v 1.1 2000/10/10 18:40:27 hillion Exp $ + * @version $Id: Parser.java,v 1.2 2001/11/08 23:02:43 deweese Exp $ */ public interface Parser extends Localizable { /** - * Parses the given reader representing an angle. + * Parses the given reader */ - void parse(Reader r) throws ParseException; + public void parse(Reader r) throws ParseException; + + /** + * Parses the given string + */ + public void parse(String s) throws ParseException; /** * Allows an application to register an error event handler. 1.7 +2 -7 xml-batik/sources/org/apache/batik/parser/PathParser.java Index: PathParser.java =================================================================== RCS file: /home/cvs/xml-batik/sources/org/apache/batik/parser/PathParser.java,v retrieving revision 1.6 retrieving revision 1.7 diff -u -r1.6 -r1.7 --- PathParser.java 2001/11/06 16:33:49 1.6 +++ PathParser.java 2001/11/08 23:02:43 1.7 @@ -15,7 +15,7 @@ * attribute values. * * @author <a href="mailto:[EMAIL PROTECTED]">Stephane Hillion</a> - * @version $Id: PathParser.java,v 1.6 2001/11/06 16:33:49 hillion Exp $ + * @version $Id: PathParser.java,v 1.7 2001/11/08 23:02:43 deweese Exp $ */ public class PathParser extends NumberParser { @@ -53,12 +53,7 @@ return pathHandler; } - /** - * Parses the given reader. - */ - public void parse(Reader r) throws ParseException { - initialize(r); - + protected void doParse() throws ParseException { pathHandler.startPath(); read(); 1.3 +2 -4 xml-batik/sources/org/apache/batik/parser/PointsParser.java Index: PointsParser.java =================================================================== RCS file: /home/cvs/xml-batik/sources/org/apache/batik/parser/PointsParser.java,v retrieving revision 1.2 retrieving revision 1.3 diff -u -r1.2 -r1.3 --- PointsParser.java 2001/01/03 14:17:39 1.2 +++ PointsParser.java 2001/11/08 23:02:43 1.3 @@ -15,7 +15,7 @@ * attribute values (used with polyline and polygon elements). * * @author <a href="mailto:[EMAIL PROTECTED]">Stephane Hillion</a> - * @version $Id: PointsParser.java,v 1.2 2001/01/03 14:17:39 hillion Exp $ + * @version $Id: PointsParser.java,v 1.3 2001/11/08 23:02:43 deweese Exp $ */ public class PointsParser extends NumberParser { @@ -61,9 +61,7 @@ /** * Parses the given reader. */ - public void parse(Reader r) throws ParseException { - initialize(r); - + protected void doParse() throws ParseException { pointsHandler.startPoints(); read(); 1.5 +2 -4 xml-batik/sources/org/apache/batik/parser/PreserveAspectRatioParser.java Index: PreserveAspectRatioParser.java =================================================================== RCS file: /home/cvs/xml-batik/sources/org/apache/batik/parser/PreserveAspectRatioParser.java,v retrieving revision 1.4 retrieving revision 1.5 diff -u -r1.4 -r1.5 --- PreserveAspectRatioParser.java 2001/02/05 07:48:40 1.4 +++ PreserveAspectRatioParser.java 2001/11/08 23:02:43 1.5 @@ -15,7 +15,7 @@ * attribute values. * * @author <a href="mailto:[EMAIL PROTECTED]">Stephane Hillion</a> - * @version $Id: PreserveAspectRatioParser.java,v 1.4 2001/02/05 07:48:40 hillion Exp $ + * @version $Id: PreserveAspectRatioParser.java,v 1.5 2001/11/08 23:02:43 deweese Exp $ */ public class PreserveAspectRatioParser extends AbstractParser { @@ -57,9 +57,7 @@ /** * Parses the given reader. */ - public void parse(Reader r) throws ParseException { - initialize(r); - + protected void doParse() throws ParseException { read(); skipSpaces(); 1.4 +2 -4 xml-batik/sources/org/apache/batik/parser/TransformListParser.java Index: TransformListParser.java =================================================================== RCS file: /home/cvs/xml-batik/sources/org/apache/batik/parser/TransformListParser.java,v retrieving revision 1.3 retrieving revision 1.4 diff -u -r1.3 -r1.4 --- TransformListParser.java 2001/03/28 09:24:13 1.3 +++ TransformListParser.java 2001/11/08 23:02:43 1.4 @@ -15,7 +15,7 @@ * attribute values. * * @author <a href="mailto:[EMAIL PROTECTED]">Stephane Hillion</a> - * @version $Id: TransformListParser.java,v 1.3 2001/03/28 09:24:13 hillion Exp $ + * @version $Id: TransformListParser.java,v 1.4 2001/11/08 23:02:43 deweese Exp $ */ public class TransformListParser extends NumberParser { @@ -56,9 +56,7 @@ /** * Parses the given reader. */ - public void parse(Reader r) throws ParseException { - initialize(r); - + protected void doParse() throws ParseException { transformListHandler.startTransformList(); loop: for (;;) { 1.7 +45 -5 xml-batik/sources/org/apache/batik/util/ParsedURLDefaultProtocolHandler.java Index: ParsedURLDefaultProtocolHandler.java =================================================================== RCS file: /home/cvs/xml-batik/sources/org/apache/batik/util/ParsedURLDefaultProtocolHandler.java,v retrieving revision 1.6 retrieving revision 1.7 diff -u -r1.6 -r1.7 --- ParsedURLDefaultProtocolHandler.java 2001/10/09 22:17:11 1.6 +++ ParsedURLDefaultProtocolHandler.java 2001/11/08 23:02:44 1.7 @@ -22,7 +22,7 @@ * 'normal' URL formats, so in many cases * * @author <a href="mailto:[EMAIL PROTECTED]">Thomas DeWeese</a> - * @version $Id: ParsedURLDefaultProtocolHandler.java,v 1.6 2001/10/09 22:17:11 deweese Exp $ + * @version $Id: ParsedURLDefaultProtocolHandler.java,v 1.7 2001/11/08 23:02:44 deweese Exp $ */ public class ParsedURLDefaultProtocolHandler extends AbstractParsedURLProtocolHandler { @@ -121,6 +121,8 @@ // Path spec follows... hostPort = urlStr.substring(pidx, idx); + hostPort = hostPort; + pidx = idx; // Remember location of '/' // pull apart host and port number... @@ -134,10 +136,8 @@ ret.host = hostPort; } else { // Host and port - if (idx == 0) - ret.host = null; - else - ret.host = hostPort.substring(0,idx); + if (idx == 0) ret.host = null; + else ret.host = hostPort.substring(0,idx); if (idx+1 < hostPort.length()) { String portStr = hostPort.substring(idx+1); @@ -153,6 +153,8 @@ if ((pidx == -1) || (pidx >= len)) return ret; // Nothing follows String pathRef = urlStr.substring(pidx); + pathRef = pathRef; + idx = pathRef.indexOf('#'); ret.ref = null; if (idx == -1) { @@ -164,6 +166,44 @@ ret.ref = pathRef.substring(idx+1); } return ret; + } + + public static String unescapeStr(String str) { + int idx = str.indexOf('%'); + if (idx == -1) return str; // quick out.. + + int prev=0; + StringBuffer ret = new StringBuffer(); + while (idx != -1) { + if (idx != prev) + ret.append(str.substring(prev, idx)); + + if (idx+2 >= str.length()) break; + prev = idx+3; + idx = str.indexOf('%', prev); + + int ch1 = charToHex(str.charAt(idx+1)); + int ch2 = charToHex(str.charAt(idx+1)); + if ((ch1 == -1) || (ch2==-1)) continue; + ret.append((char)(ch1<<4 | ch2)); + } + + return ret.toString(); + } + + public static int charToHex(int ch) { + switch(ch) { + case '0': case '1': case '2': case '3': case '4': + case '5': case '6': case '7': case '8': case '9': + return ch-'0'; + case 'a': case 'A': return 10; + case 'b': case 'B': return 11; + case 'c': case 'C': return 12; + case 'd': case 'D': return 13; + case 'e': case 'E': return 14; + case 'f': case 'F': return 15; + default: return -1; + } } /** 1.18 +6 -6 xml-batik/test-resources/org/apache/batik/test/regard.xml Index: regard.xml =================================================================== RCS file: /home/cvs/xml-batik/test-resources/org/apache/batik/test/regard.xml,v retrieving revision 1.17 retrieving revision 1.18 diff -u -r1.17 -r1.18 --- regard.xml 2001/11/08 15:05:20 1.17 +++ regard.xml 2001/11/08 23:02:44 1.18 @@ -11,7 +11,7 @@ <!-- regression testing. --> <!-- --> <!-- @author [EMAIL PROTECTED] --> -<!-- @version $Id: regard.xml,v 1.17 2001/11/08 15:05:20 hillion Exp $ --> +<!-- @version $Id: regard.xml,v 1.18 2001/11/08 23:02:44 deweese Exp $ --> <!-- ========================================================================= --> <testRun id="regard" name="Batik Standard Regression Test Run"> <testReportProcessor class="org.apache.batik.test.xml.XMLTestReportProcessor" > @@ -29,14 +29,14 @@ <!-- Rendering Accuracy Tests --> <!-- ====================================================================== --> - <!-- SVG Working Group --> - <!-- Basic Effectivity --> - <!-- Test Suite --> + <!-- Batik --> + <!-- Samples --> <testSuite href="file:test-resources/org/apache/batik/test/samplesRendering.xml" /> - <!-- Batik --> - <!-- Samples --> + <!-- SVG Working Group --> + <!-- Basic Effectivity --> + <!-- Test Suite --> <testSuite href="file:test-resources/org/apache/batik/test/beSuite.xml" /> 1.45 +2 -2 xml-batik/test-resources/org/apache/batik/test/samplesRendering.xml Index: samplesRendering.xml =================================================================== RCS file: /home/cvs/xml-batik/test-resources/org/apache/batik/test/samplesRendering.xml,v retrieving revision 1.44 retrieving revision 1.45 diff -u -r1.44 -r1.45 --- samplesRendering.xml 2001/10/22 10:37:00 1.44 +++ samplesRendering.xml 2001/11/08 23:02:44 1.45 @@ -8,7 +8,7 @@ <!-- ========================================================================= --> <!-- @author [EMAIL PROTECTED] --> -<!-- @version $Id: samplesRendering.xml,v 1.44 2001/10/22 10:37:00 vhardy Exp $ --> +<!-- @version $Id: samplesRendering.xml,v 1.45 2001/11/08 23:02:44 deweese Exp $ --> <!-- ========================================================================= --> <testSuite id="samplesRendering" name="samples and samples/test Rendering" class="org.apache.batik.test.svg.SamplesRenderingTest"> @@ -107,7 +107,7 @@ <test id="samples/anne.svg#svgView(viewBox(100,50,100,200))-ViewBox2" /> <test id="samples/anne.svg#svgView(transform(translate(-100,-50)))-Transform1" /> <test id="samples/anne.svg#svgView(transform(translate(225,250)rotate(45)translate(-225,-250)))-Transform2" /> - <test id="samples/anne.svg#svgView(transform(rotate(45,225,250)))-Transform2" /> + <test id="samples/anne.svg#svgView(transform(rotate(45,225,250)))-Transform3" /> </testGroup> </testGroup> 1.2 +47 -1 xml-batik/test-sources/org/apache/batik/test/svg/SVGReferenceRenderingAccuracyTest.java Index: SVGReferenceRenderingAccuracyTest.java =================================================================== RCS file: /home/cvs/xml-batik/test-sources/org/apache/batik/test/svg/SVGReferenceRenderingAccuracyTest.java,v retrieving revision 1.1 retrieving revision 1.2 diff -u -r1.1 -r1.2 --- SVGReferenceRenderingAccuracyTest.java 2001/10/16 10:38:10 1.1 +++ SVGReferenceRenderingAccuracyTest.java 2001/11/08 23:02:44 1.2 @@ -9,6 +9,8 @@ package org.apache.batik.test.svg; import java.io.File; +import java.net.URL; +import java.net.MalformedURLException; import org.apache.batik.dom.svg.SVGOMDocument; @@ -21,7 +23,7 @@ * to the SVG file. * * @author <a href="mailto:[EMAIL PROTECTED]">Vincent Hardy</a> - * @version $Id: SVGReferenceRenderingAccuracyTest.java,v 1.1 2001/10/16 10:38:10 vhardy Exp $ + * @version $Id: SVGReferenceRenderingAccuracyTest.java,v 1.2 2001/11/08 23:02:44 deweese Exp $ */ public class SVGReferenceRenderingAccuracyTest extends ParametrizedRenderingAccuracyTest { @@ -62,6 +64,50 @@ setVariationURL(buildVariationURL(dirNfile[0], dirNfile[1])); setSaveVariation(new File(buildSaveVariationFile(dirNfile[0], dirNfile[1]))); + } + + /** + * Resolves the input string as follows. + * + * + First, the string is interpreted as a file description minus + * any url fragment it may have (stuff after a '#'). If the + * file's parent directory exists, then the file name is turned + * into a URL and the fragment if any is appended. + * + Otherwise, the string is supposed to be a URL. If it + * is an invalid URL, an IllegalArgumentException is thrown. + */ + protected URL resolveURL(String url){ + // We must strip the # off if there is one otherwise File thinks + // we want to reference a file that has a '#' in it's name... + String fragment = null; + String file = url; + int n = file.lastIndexOf('#'); + if (n != -1) { + fragment = file.substring(n); // include the #. + file = file.substring(0,n); + } + + // Is url a file? + File f = (new File(file)).getAbsoluteFile(); + if(f.getParentFile().exists()){ + try{ + if (fragment == null) { + return f.toURL(); // No fragment. + } else { + // Construct URL that includes fragment... + return new URL(f.toURL(), fragment); + } + }catch(MalformedURLException e){ + throw new IllegalArgumentException(); + } + } + + // url is not a file. It must be a regular URL... + try{ + return new URL(url); + }catch(MalformedURLException e){ + throw new IllegalArgumentException(url); + } } /** 1.22 +3 -3 xml-batik/test-sources/org/apache/batik/test/svg/SVGRenderingAccuracyTest.java Index: SVGRenderingAccuracyTest.java =================================================================== RCS file: /home/cvs/xml-batik/test-sources/org/apache/batik/test/svg/SVGRenderingAccuracyTest.java,v retrieving revision 1.21 retrieving revision 1.22 diff -u -r1.21 -r1.22 --- SVGRenderingAccuracyTest.java 2001/11/06 15:04:51 1.21 +++ SVGRenderingAccuracyTest.java 2001/11/08 23:02:44 1.22 @@ -64,7 +64,7 @@ * all pixel values are the same). * * @author <a href="mailto:[EMAIL PROTECTED]">Vincent Hardy</a> - * @version $Id: SVGRenderingAccuracyTest.java,v 1.21 2001/11/06 15:04:51 hillion Exp $ + * @version $Id: SVGRenderingAccuracyTest.java,v 1.22 2001/11/08 23:02:44 deweese Exp $ */ public class SVGRenderingAccuracyTest extends AbstractTest { /** @@ -881,8 +881,8 @@ new Boolean(false)); t.addTranscodingHint(PNGTranscoder.KEY_BACKGROUND_COLOR, new Color(0,0,0,0)); - t.addTranscodingHint(PNGTranscoder.KEY_XML_PARSER_VALIDATING, - new Boolean(true)); + // t.addTranscodingHint(PNGTranscoder.KEY_XML_PARSER_VALIDATING, + // new Boolean(true)); return t; } 1.9 +128 -93 xml-batik/xdocs/extendingBatik.xml Index: extendingBatik.xml =================================================================== RCS file: /home/cvs/xml-batik/xdocs/extendingBatik.xml,v retrieving revision 1.8 retrieving revision 1.9 diff -u -r1.8 -r1.9 --- extendingBatik.xml 2001/08/21 15:26:01 1.8 +++ extendingBatik.xml 2001/11/08 23:02:44 1.9 @@ -11,7 +11,7 @@ <!-- ====================================================================== --> <!-- author [EMAIL PROTECTED] --> -<!-- version $Id: extendingBatik.xml,v 1.8 2001/08/21 15:26:01 hillion Exp $ --> +<!-- version $Id: extendingBatik.xml,v 1.9 2001/11/08 23:02:44 deweese Exp $ --> <!-- ====================================================================== --> <document> @@ -165,71 +165,91 @@ <code>org.apache.batik.extension.PrefixableStylableExtensionElement</code>. If you derive off this class you are only required to implement three methods: <code>getLocalName</code>, - <code>getNamespaceURI</code>, and <code>newNode</code> (plus constructors). If - all you want is proper style support then you are - done implementing your elements at this point. + <code>getNamespaceURI</code>, and <code>newNode</code> + (plus constructors). If all you want is proper style + support (commonly the case) then you are done implementing + your elements at this point. </p> <p> - The distribution comes with two examples - <code>org.apache.batik.extension.svg.BatikStarElement</code>, - and - <code>org.apache.batik.extension.svg.BatikRegularPolygonElement</code>. - These examples also include the required <code>DomExtension</code> instance to - register the elements with the <code>ExtensibleSVGDOMImplementation</code>. + The distribution comes with a number of examples + <ul> + <li><code>org.apache.batik.extension.svg.BatikStarElement</code></li> + <li><code>org.apache.batik.extension.svg.BatikRegularPolygonElement</code></li> + <li><code>org.apache.batik.extension.svg.BatikHistogramNormalizationElement</code></li> + <li><code>org.apache.batik.extension.svg.SolidColorElement</code></li> + <li><code>org.apache.batik.extension.svg.ColorSwitchElement</code></li> + </ul> + Included with these examples is + <code>org.apache.batik.extension.svg.BatikDomExtension</code> + which is the required instance of <code>DomExtension</code> + used to register the elements with the + <code>ExtensibleSVGDOMImplementation</code>. </p> + + <p> + When your new element requires new 'presentation attributes' + (XML attributes that can be modified through CSS or depending + on your view point the other way round, CSS properties that + can be specified using XML attributes), you may also need to + extend the CSS engine. This can be done by registering a + custom CSS value factory. Both of the color examples do + this (see <code>BatikDomExtension</code>). + </p> </s2> <anchor id="bridgeExtension"/> <s2 title="Writing a Batik Bridge Extension"> <p> Before you write a bridge extension it may be useful - to understand what the role of the bridge package is + to understand what the role the bridge package plays in Batik. The bridge package is responsible for creating and maintaining elements in the Graphics - Vector Toolkit (GVT) tree from the corresponding + Vector Toolkit (GVT) tree based on the corresponding element in the SVG DOM. This is done because for a variety of reasons the SVG DOM is not well suited for - rendering directly off of. The GVT tree is used for - all rendering and transcoding operations. + rendering, thus GVT tree is used for all rendering and + transcoding operations. </p> <p> The key class for managing this link is the - <code>BridgeContext</code> class. This class maintains an + <code>BridgeContext</code>. This class maintains an association between a tag name with namespace and a particular bridge instance that will handle it. The - work of constructing the proper entities in the GVT - tree is then deferred to the registered instance of the - bridge class. + work of constructing the proper entity or entities in the + GVT tree is then deferred to the Bridge registered for + a particular tag. If no bridge is regiestered nothing is + done. </p> <p> - New associations can be added by subclasses of the - <code>BridgeExtension</code> Service Provider Interface. This - interface has a number of methods that provide + New associations can be added by implementors of the + <code>BridgeExtension</code> Service Provider Interface. + This interface has a number of methods that provide information about the particular extension being registered (including contact information, and the list of implemented extensions). It also has a 'registerTags' method which is responsible for - registering the bridge instances with a <code>BridgeContext</code>. - The built in bridges are bundled with a - BridgeExtension as well as the two example extension - tags (in <code>org.apache.batik.extension.svg</code>), + registering the bridge instances with a + <code>BridgeContext</code>. All the built in bridges are + bundled with a BridgeExtension (in + <code>org.apache.batik.bridge</code>), + as are the example extensions (in + <code>org.apache.batik.extension.svg</code>), so these are both good places to start. </p> <p> - The <code>Bridge</code> interface itself is very simple. It only - includes methods to get the namespace and local name - of the tag the bridge is responsible for. This + The <code>Bridge</code> interface itself is very simple. + It only includes methods to get the namespace and local + name of the tag the bridge is responsible for. This interface is then extended for each of the major concepts present in SVG: </p> <dl> <dt><link href="#graphicsNodeBridge"> GraphicsNodeBridge</link></dt> - <dd> These are probably the most common SVG elements they represent graphic elements in what I'll call @@ -237,7 +257,8 @@ most other bridges modify in some way (by clipping, masking, filtering, etc). <br/> - <em>Example tags:</em> svg, g, path, rect. + <em>Example tags:</em> svg, g, path, rect.<br/> + <em>Example Extensions:</em> BatikRegularPolygonElementBridge, BatikStarElementBridge. </dd> <dt>FilterBridge</dt> @@ -259,7 +280,8 @@ Constructs an element in the filter chain applied to a SVG graphics node. <br/> - <em>Example tags:</em> feBlend, feCompose, ... + <em>Example tags:</em> feBlend, feCompose, ...<br/> + <em>Example Extensions:</em> BatikHistogramNormalizationElementBridge </dd> <dt><link href="#paintBridge">PaintBridge</link></dt> @@ -267,7 +289,8 @@ Constructs a java Paint object to be used in filling or stroking graphic elements. <br/> - <em>Example tags:</em> gradient, pattern. + <em>Example tags:</em> gradient, pattern.<br/> + <em>Example Extensions:</em> SolidColorBridge, ColorSwitchBridge </dd> <dt>ClipBridge</dt> @@ -302,7 +325,9 @@ Extension writers are free to work with any of the above bridges, however the three most common are likely to be the <code>GraphicsNodeBridge</code>, the - <code>FilterPrimitiveBridge</code>, and the <code>PaintBridge</code>. + <code>FilterPrimitiveBridge</code>, and the + <code>PaintBridge</code> (each of which have example + extensions available for inspection). Each of these interfaces has several extremely useful subclasses that handle much of the common behavior among elements. @@ -321,12 +346,12 @@ <s3 title="GraphicsNodeBridge"> <p> The graphics node bridge is oriented around - constructing a new <code>GraphicsNode</code> in the GVT tree. - The <code>GraphicsNode</code> is the basic element that makes - up the GVT tree. Each <code>GraphicsNode</code> has a <code>paint</code> - method that is responsible for painting the object - (including considering clipping, masking, - filtering, and opacity for the node). + constructing a new <code>GraphicsNode</code> in the GVT + tree. The <code>GraphicsNode</code> is the basic element + that makes up the GVT tree. Each <code>GraphicsNode</code> + has a <code>paint</code> method that is responsible for + painting the object (including considering clipping, + masking, filtering, and opacity for the node). </p> <p> @@ -335,9 +360,9 @@ directly or subclass <code>bridge.AbstractGraphicsNodeBridge</code>. This gives you the most flexibility since you can - construct a new subclass of - <code>gvt.GraphicsNode</code> and implement the - paint method to do essentially anything you want, + construct your new subclass of + <code>gvt.GraphicsNode</code> where you can implement + the paint method to do essentially anything you want, this is also a lot of work (and I'm not going to try and explain everything needed to pull this off). @@ -370,6 +395,16 @@ end of each segment of the path. </dd> </dl> + <p> + If you decide that you need to implement a new subclass + of <code>GraphicsNode</code> I strongly suggest that + you derive off of <code>AbstractGraphicsNode</code> + as this class does much of the work to behave like + a drawn element in SVG (like clipping, filtering, + masking). In this case you implement + the <code>primitivePaint</code> method + instead of the <code>paint</code> method. + </p> </s3> <anchor id="filterPrimitiveBridge"/> @@ -395,18 +430,18 @@ <p> The majority of classes for part of Batik are present - in the <code>batik.ext.awt.image.*</code> package hierarchy which - contains a set of generally useful extensions to the - core JDK classes and methods. + in the <code>batik.ext.awt.image.*</code> package hierarchy + which contains a large set of generally useful extensions to + the core JDK classes and methods. </p> <p> - Note that the <code>FilterPrimitiveBridge</code> is invoked once - for each reference to the <code><filter></code> tag that the filter - primitive is part of. So if a filter effect is used a - half dozen times the <code>createFilter</code> method will be - called a half dozen times, even though the tag may - only appear once in the file. This means that it is + Note that the <code>FilterPrimitiveBridge</code> is invoked + once for each reference to the <code><filter></code> + tag that the filter primitive is part of. So if a filter + effect is used a half dozen times the <code>createFilter</code> + method will be called a half dozen times, even though the + tag may only appear once in the file. This means that it is safe for the Filters returned to be 'fixed' for a particular <code>GraphicsNode</code> being filtered. </p> @@ -420,10 +455,11 @@ <code>java.ext.awt.image.renderable.Filter</code> and <code>java.ext.awt.image.rendered.CacheableRed</code>. Batik contains simple wrapper classes that can take - the default JDK <code>Renderable</code> and <code>Rendered</code> Image - interfaces. Within the code base the convention 'Red' - for classes implementing <code>RenderedImage</code>, and 'Rable' - for classes implementing <code>RenderableImage</code> is commonly + the default JDK <code>Renderable</code> and + <code>Rendered</code> Image interfaces. Within the code + base the convention 'Red' for classes implementing + <code>RenderedImage</code>, and 'Rable' for classes + implementing <code>RenderableImage</code> is commonly used ('Red' is to be pronounced like the color, and 'Rable' is to be pronounced like 'horrible' with a silent 'h'). @@ -431,10 +467,10 @@ <p> The <code>FilterPrimitiveBridge</code> really has only - one method right now: <code>createFilter</code> that must construct - an instance of <code>Filter</code> to perform the required - operation. This is still a fairly complex task given - the general need to support accessing the various + one method right now: <code>createFilter</code> that must + construct an instance of <code>Filter</code> to perform + the required operation. This is still a fairly complex task + given the general need to support accessing the various standard sources of image data. To this end there is a provided subclass, <code>AbstractSVGFilterPrimitiveElementBridge</code> @@ -453,7 +489,7 @@ <code>ext.awt.image.rendered.AbstractTiledRed</code>. <code>TiledRed</code> ties into the Batik tile cache (use this with caution as it is a complex area of - the Batik code and that code may be inadvertently broken). + the Batik code). </p> <p> @@ -474,8 +510,8 @@ </p> <p> - Like the filter primitive bridge the <code>PaintBridge</code> is - invoked for each reference to the paint. This makes + Like the filter primitive bridge the <code>PaintBridge</code> + is invoked for each reference to the paint. This makes it possible to customize the Paint returned for the particular element to be painted. </p> @@ -488,12 +524,12 @@ <p> For paints you are mostly on your own, because unlike - the cases there aren't any really generally useful + the other cases there aren't any really generally useful base classes to derive off, the closest is the <code>AbstractSVGGradientElementBridge</code> which is used to handle most of the radial and linear gradient attributes. - </p> + </p> <p> The existing gradient paint implementations are in @@ -501,7 +537,6 @@ <code>gvt</code> since it requires access to gvt internals. </p> - </s3> </s2> </s1> @@ -512,16 +547,16 @@ When Batik encounters an 'image' element and it determines the element does not reference an SVG file. It defers the loading of the referenced image to - <code>org.apache.batik.ext.awt.image.spi.ImageTagRegistry</code>. This - class maintains a list of <code>RegistryEntries</code>, generally one - for each format. + <code>org.apache.batik.ext.awt.image.spi.ImageTagRegistry</code>. + This class maintains a list of <code>RegistryEntries</code>, + generally one for each format. </p> <p> Since the formats supported natively by Batik are also - implemented through this mechanism. The <code>JPEGRegistryEntry</code> - and <code>PNGRegistryEntry</code> should be used as good references for - extensions. + implemented through this mechanism. The + <code>JPEGRegistryEntry</code> and <code>PNGRegistryEntry</code> + should be used as good references for extensions. </p> <s2 title="RegistryEntry"> <p> @@ -531,18 +566,18 @@ <dl> <dt>URLRegistryEntry</dt> <dd> - These take a <code>ParsedURL</code> and try to decide if the URL - is intended for them. This group is mostly - intended to handle alternate network protocols. It + These take a <code>ParsedURL</code> and try to decide if + the URL is intended for them. This group of entries is + mostly intended to handle alternate network protocols. It can also be useful for interfacing with libraries that want a URL instead of a stream. </dd> <dt>StreamRegistryEntry</dt> <dd> - These work with a markable <code>InputStream</code>. This is the - preferred form of registry entry as it generally - avoids opening a potentially expensive connection + These work with a markable <code>InputStream</code>. + This is the preferred form of registry entry as it + generally avoids opening a potentially expensive connection multiple times, instead it opens the stream once and relies on mark and reset to allow entries to check the stream. @@ -562,10 +597,10 @@ <dt>MagicNumberRegistryEntry</dt> <dd> An abstract class that can handle the - <code>isCompatibleStream</code> method for formats that make use - of "magic numbers". Magic numbers are a well known - sequence of bytes at a well known offset in the - file. + <code>isCompatibleStream</code> method for formats that + make use of "magic numbers". Magic numbers are a well + known sequence of bytes at a well known offset in the + file, that are commonly used to identify image file formats. </dd> <dt>RedRable</dt> @@ -582,7 +617,7 @@ thread, rather than hold up the construction of the GVT tree while reading the image (useful since reading the image is generally I/O bound, so it - makes a good background task). This is used by all + makes a good background task). This is used by most of the current Image readers. </dd> @@ -613,13 +648,13 @@ </p> <p> - <code>ParsedURL</code> offers a few advantages over the JDK's URL class. - First, it is designed to make minimal use of exceptions, so it - is possible to use it to parse a malformed URL and get "the - good parts". Second, it is extensible, so support for new - protocols can be added, even protocols that change the normal - parsing rules for URLs (such as our friend the 'data' - protocol). Third it can automatically check a stream when + <code>ParsedURL</code> offers a few advantages over the JDK's + URL class. First, it is designed to make minimal use of + exceptions, so it is possible to use it to parse a malformed + URL and get "the good parts". Second, it is extensible, so + support for new protocols can be added, even protocols that + change the normal parsing rules for URLs (such as our friend the + 'data' protocol). Third it can automatically check a stream when opened for common compression types and decode them for you (this behavior can also be bypassed if needed). </p> @@ -635,10 +670,10 @@ </p> <p> - The <code>ParsedURLData</code> class holds all the data and implements the - all the stream handling commands for the ParsedURL class. - This allows ProtocolHandlers to return custom subclasses for - particular protocols. + The <code>ParsedURLData</code> class holds all the data and + implements the all the stream handling commands for the + ParsedURL class. This allows ProtocolHandlers to return custom + subclasses for particular protocols. </p> </s1> </body>
--------------------------------------------------------------------- To unsubscribe, e-mail: [EMAIL PROTECTED] For additional commands, e-mail: [EMAIL PROTECTED]