cjolif 01/07/03 02:51:44 Modified: sources/org/apache/batik/svggen SVGClip.java SVGPath.java SVGRenderingHints.java Log: - prevent SVGClip.java from throwing an NPE when the Shape converted by SVGShape.java returns null. - when a null value is used for KEY_RENDERING is should produce the same SVG file as for the default value. - SVGShape was wrapping the shape in parameter into a GeneralPath instance. It is not necessary => remove it to speed a little bit the generator. Revision Changes Path 1.9 +21 -12 xml-batik/sources/org/apache/batik/svggen/SVGClip.java Index: SVGClip.java =================================================================== RCS file: /home/cvs/xml-batik/sources/org/apache/batik/svggen/SVGClip.java,v retrieving revision 1.8 retrieving revision 1.9 diff -u -r1.8 -r1.9 --- SVGClip.java 2001/04/26 14:17:08 1.8 +++ SVGClip.java 2001/07/03 09:51:36 1.9 @@ -20,7 +20,7 @@ * Utility class that converts a Path object into an SVG clip * * @author <a href="mailto:[EMAIL PROTECTED]">Vincent Hardy</a> - * @version $Id: SVGClip.java,v 1.8 2001/04/26 14:17:08 cjolif Exp $ + * @version $Id: SVGClip.java,v 1.9 2001/07/03 09:51:36 cjolif Exp $ */ public class SVGClip extends AbstractSVGConverter { /** @@ -77,15 +77,19 @@ if (clipDesc == null) { Element clipDef = clipToSVG(clip); - clipPathAttrBuf.append(SIGN_POUND); - clipPathAttrBuf.append(clipDef.getAttributeNS(null, ATTR_ID)); - clipPathAttrBuf.append(URL_SUFFIX); - - clipDesc = new SVGClipDescriptor(clipPathAttrBuf.toString(), - clipDef); - - descMap.put(clipKey, clipDesc); - defSet.add(clipDef); + if (clipDef == null) + clipDesc = NO_CLIP; + else { + clipPathAttrBuf.append(SIGN_POUND); + clipPathAttrBuf.append(clipDef.getAttributeNS(null, ATTR_ID)); + clipPathAttrBuf.append(URL_SUFFIX); + + clipDesc = new SVGClipDescriptor(clipPathAttrBuf.toString(), + clipDef); + + descMap.put(clipKey, clipDesc); + defSet.add(clipDef); + } } } else clipDesc = NO_CLIP; @@ -112,8 +116,13 @@ idGenerator.generateID(ID_PREFIX_CLIP_PATH)); Element clipPath = shapeConverter.toSVG(clip); - clipDef.appendChild(clipPath); - return clipDef; + // unfortunately it may be null because of SVGPath that may produce null + // SVG elements. + if (clipPath != null) { + clipDef.appendChild(clipPath); + return clipDef; + } else + return null; // what means the shape return null ? } } 1.9 +7 -14 xml-batik/sources/org/apache/batik/svggen/SVGPath.java Index: SVGPath.java =================================================================== RCS file: /home/cvs/xml-batik/sources/org/apache/batik/svggen/SVGPath.java,v retrieving revision 1.8 retrieving revision 1.9 diff -u -r1.8 -r1.9 --- SVGPath.java 2001/04/27 23:23:24 1.8 +++ SVGPath.java 2001/07/03 09:51:38 1.9 @@ -30,8 +30,9 @@ * than the default. Otherwise, the attribute would have * to be specified in the majority of path elements. * + * @author <a href="mailto:[EMAIL PROTECTED]">Christophe Jolif</a> * @author <a href="mailto:[EMAIL PROTECTED]">Vincent Hardy</a> - * @version $Id: SVGPath.java,v 1.8 2001/04/27 23:23:24 vhardy Exp $ + * @version $Id: SVGPath.java,v 1.9 2001/07/03 09:51:38 cjolif Exp $ */ public class SVGPath extends SVGGraphicObjectConverter { /** @@ -47,17 +48,10 @@ * @return a path Element. */ public Element toSVG(Shape path) { - // Convert input path to GeneralPath if necessary - GeneralPath shape = null; - if (path instanceof GeneralPath) - shape = (GeneralPath)path; - else - shape = new GeneralPath(path); - // Create the path element and process its // d attribute. - String dAttr = toSVGPathData(shape); - if (dAttr==null || dAttr.trim().length() == 0){ + String dAttr = toSVGPathData(path); + if (dAttr==null || dAttr.length() == 0){ // be careful not to append null to the DOM tree // because it will crash return null; @@ -69,18 +63,17 @@ svgPath.setAttributeNS(null, SVG_D_ATTRIBUTE, dAttr); // Set winding rule if different than SVG's default - if(shape.getWindingRule() == GeneralPath.WIND_EVEN_ODD) + if (path.getPathIterator(null).getWindingRule() == GeneralPath.WIND_EVEN_ODD) svgPath.setAttributeNS(null, SVG_FILL_RULE_ATTRIBUTE, SVG_EVEN_ODD_VALUE); return svgPath; - } /** * @param path the GeneralPath to convert * @return the value of the corresponding d attribute */ - static String toSVGPathData(GeneralPath path) { + static String toSVGPathData(Shape path) { StringBuffer d = new StringBuffer(""); PathIterator pi = path.getPathIterator(null); float seg[] = new float[6]; @@ -125,7 +118,7 @@ /** * Appends a coordinate to the path data */ - private static void appendPoint(StringBuffer d, float x, float y){ + private static void appendPoint(StringBuffer d, float x, float y) { d.append(doubleString(x)); d.append(SPACE); d.append(doubleString(y)); 1.10 +3 -2 xml-batik/sources/org/apache/batik/svggen/SVGRenderingHints.java Index: SVGRenderingHints.java =================================================================== RCS file: /home/cvs/xml-batik/sources/org/apache/batik/svggen/SVGRenderingHints.java,v retrieving revision 1.9 retrieving revision 1.10 diff -u -r1.9 -r1.10 --- SVGRenderingHints.java 2001/04/27 18:34:14 1.9 +++ SVGRenderingHints.java 2001/07/03 09:51:39 1.10 @@ -32,7 +32,7 @@ * + TEXT_ANTIALIASING -> text-rendering * * @author <a href="mailto:[EMAIL PROTECTED]">Vincent Hardy</a> - * @version $Id: SVGRenderingHints.java,v 1.9 2001/04/27 18:34:14 vhardy Exp $ + * @version $Id: SVGRenderingHints.java,v 1.10 2001/07/03 09:51:39 cjolif Exp $ */ public class SVGRenderingHints extends AbstractSVGConverter{ /** @@ -55,7 +55,8 @@ * @return map Map of attribute values that describe the hints */ public static SVGHintsDescriptor toSVG(RenderingHints hints){ - String colorInterpolation = SVG_SRGB_VALUE; + // no hints should mean default + String colorInterpolation = SVG_AUTO_VALUE; String colorRendering = SVG_AUTO_VALUE; String textRendering = SVG_AUTO_VALUE; String shapeRendering = SVG_AUTO_VALUE; --------------------------------------------------------------------- To unsubscribe, e-mail: [EMAIL PROTECTED] For additional commands, e-mail: [EMAIL PROTECTED]