vhardy 2003/07/02 06:51:46
Modified: test-resources/org/apache/batik/svggen regsvggen.xml
sources/org/apache/batik/svggen DefaultStyleHandler.java
SVGRenderingHints.java
Added: test-sources/org/apache/batik/svggen Bug17965.java
Log:
Fixed bug 17965. Modified text hint mapping.
Revision Changes Path
1.1 xml-batik/test-sources/org/apache/batik/svggen/Bug17965.java
Index: Bug17965.java
===================================================================
/*****************************************************************************
* Copyright (C) The Apache Software Foundation. All rights reserved. *
* ------------------------------------------------------------------------- *
* This software is published under the terms of the Apache Software License *
* version 1.1, a copy of which has been included with this distribution in *
* the LICENSE file. *
*****************************************************************************/
package org.apache.batik.svggen;
import java.awt.*;
import java.awt.geom.*;
import java.awt.image.*;
import javax.swing.ImageIcon;
/**
* This test validates fix to Bug #17965 and checks that
* attributes which do not apply to given element (eg., font-family
* does not apply to <rect>) are not written out.
*
* @author <a href="mailto:[EMAIL PROTECTED]">Vincent Hardy</a>
* @version $Id: Bug17965.java,v 1.1 2003/07/02 13:51:43 vhardy Exp $
*/
public class Bug17965 implements Painter {
public void paint(Graphics2D g) {
g.setRenderingHint(java.awt.RenderingHints.KEY_ANTIALIASING,
java.awt.RenderingHints.VALUE_ANTIALIAS_ON);
Font font = new Font("Arial", Font.PLAIN, 30);
g.setFont(font);
g.setPaint(Color.blue);
g.fillRect(0, 0, 50, 50);
font = new Font("Helvetica", Font.PLAIN, 20);
g.setFont(font);
g.fillRect( 50, 50, 50, 50);
}
}
1.18 +2 -1 xml-batik/test-resources/org/apache/batik/svggen/regsvggen.xml
Index: regsvggen.xml
===================================================================
RCS file: /home/cvs/xml-batik/test-resources/org/apache/batik/svggen/regsvggen.xml,v
retrieving revision 1.17
retrieving revision 1.18
diff -u -r1.17 -r1.18
--- regsvggen.xml 8 Jul 2002 11:54:02 -0000 1.17
+++ regsvggen.xml 2 Jul 2003 13:51:43 -0000 1.18
@@ -19,6 +19,7 @@
<test id="Bug4389" />
<test id="Bug4945" />
<test id="Bug6535" />
+ <test id="Bug17965" />
<test id="Clip" />
<test id="Color1" />
<test id="Color2" />
1.3 +47 -5
xml-batik/sources/org/apache/batik/svggen/DefaultStyleHandler.java
Index: DefaultStyleHandler.java
===================================================================
RCS file:
/home/cvs/xml-batik/sources/org/apache/batik/svggen/DefaultStyleHandler.java,v
retrieving revision 1.2
retrieving revision 1.3
diff -u -r1.2 -r1.3
--- DefaultStyleHandler.java 11 Apr 2003 13:59:02 -0000 1.2
+++ DefaultStyleHandler.java 2 Jul 2003 13:51:44 -0000 1.3
@@ -8,8 +8,12 @@
package org.apache.batik.svggen;
+import org.apache.batik.util.SVGConstants;
+
import java.util.Iterator;
import java.util.Map;
+import java.util.HashMap;
+import java.util.Vector;
import org.w3c.dom.Element;
@@ -20,7 +24,29 @@
* @author <a href="mailto:[EMAIL PROTECTED]">Christophe Jolif</a>
* @version $Id$
*/
-public class DefaultStyleHandler implements StyleHandler {
+public class DefaultStyleHandler implements StyleHandler, SVGConstants {
+ /**
+ * Static initializer for which attributes should be ignored on
+ * some elements.
+ */
+ static HashMap ignoreAttributes = new HashMap();
+
+ static {
+ Vector textAttributes = new Vector();
+ textAttributes.addElement(SVG_FONT_SIZE_ATTRIBUTE);
+ textAttributes.addElement(SVG_FONT_FAMILY_ATTRIBUTE);
+ textAttributes.addElement(SVG_FONT_STYLE_ATTRIBUTE);
+ textAttributes.addElement(SVG_FONT_WEIGHT_ATTRIBUTE);
+
+ ignoreAttributes.put(SVG_RECT_TAG, textAttributes);
+ ignoreAttributes.put(SVG_CIRCLE_TAG, textAttributes);
+ ignoreAttributes.put(SVG_ELLIPSE_TAG, textAttributes);
+ ignoreAttributes.put(SVG_POLYGON_TAG, textAttributes);
+ ignoreAttributes.put(SVG_POLYGON_TAG, textAttributes);
+ ignoreAttributes.put(SVG_LINE_TAG, textAttributes);
+ ignoreAttributes.put(SVG_PATH_TAG, textAttributes);
+ }
+
/**
* Sets the style described by <code>styleMap</code> on the given
* <code>element</code>. That is sets the xml attributes with their
@@ -36,9 +62,25 @@
String styleName = null;
while (iter.hasNext()) {
styleName = (String)iter.next();
- if (element.getAttributeNS(null, styleName).length() == 0)
- element.setAttributeNS(null, styleName,
- (String)styleMap.get(styleName));
+ if (element.getAttributeNS(null, styleName).length() == 0){
+ if (appliesTo(styleName, tagName)) {
+ element.setAttributeNS(null, styleName,
+ (String)styleMap.get(styleName));
+ }
+ }
+ }
+ }
+
+ /**
+ * Controls whether or not a given attribute applies to a particular
+ * element.
+ */
+ protected boolean appliesTo(String styleName, String tagName) {
+ Vector v = (Vector)ignoreAttributes.get(tagName);
+ if (v == null) {
+ return true;
+ } else {
+ return !v.contains(styleName);
}
}
}
1.12 +2 -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.11
retrieving revision 1.12
diff -u -r1.11 -r1.12
--- SVGRenderingHints.java 11 Apr 2003 13:59:06 -0000 1.11
+++ SVGRenderingHints.java 2 Jul 2003 13:51:44 -0000 1.12
@@ -126,7 +126,7 @@
if(textAntialiasing == hints.VALUE_TEXT_ANTIALIAS_ON)
textRendering = SVG_OPTIMIZE_LEGIBILITY_VALUE;
else if(textAntialiasing == hints.VALUE_TEXT_ANTIALIAS_OFF)
- textRendering = SVG_GEOMETRIC_PRECISION_VALUE;
+ textRendering = SVG_OPTIMIZE_SPEED_VALUE;
else if(textAntialiasing == hints.VALUE_TEXT_ANTIALIAS_DEFAULT)
textRendering = SVG_AUTO_VALUE;
---------------------------------------------------------------------
To unsubscribe, e-mail: [EMAIL PROTECTED]
For additional commands, e-mail: [EMAIL PROTECTED]