You are viewing a plain text version of this content. The canonical link for it is here.
Posted to batik-dev@xmlgraphics.apache.org by cj...@apache.org on 2001/05/02 10:48:44 UTC
cvs commit: xml-batik/test-sources/org/apache/batik/svggen GeneratorContext.java SVGAccuracyTest.java
cjolif 01/05/02 01:48:44
Modified: test-sources/org/apache/batik/svggen GeneratorContext.java
SVGAccuracyTest.java
Log:
add a test for SVG Generator extensibility
Revision Changes Path
1.2 +68 -3 xml-batik/test-sources/org/apache/batik/svggen/GeneratorContext.java
Index: GeneratorContext.java
===================================================================
RCS file: /home/cvs/xml-batik/test-sources/org/apache/batik/svggen/GeneratorContext.java,v
retrieving revision 1.1
retrieving revision 1.2
diff -u -r1.1 -r1.2
--- GeneratorContext.java 2001/04/25 16:31:30 1.1
+++ GeneratorContext.java 2001/05/02 08:48:43 1.2
@@ -10,15 +10,80 @@
import java.awt.*;
import java.awt.geom.*;
+import org.w3c.dom.*;
+import java.util.*;
+import java.net.URL;
+import org.apache.batik.dom.svg.SVGDOMImplementation;
+import org.apache.batik.util.SVGConstants;
/**
* Testing customization of the SVGGeneratorContext
*
* @author <a href="mailto:cjolif@ilog.fr">Christophe Jolif</a>
- * @version $Id: GeneratorContext.java,v 1.1 2001/04/25 16:31:30 cjolif Exp $
+ * @version $Id: GeneratorContext.java,v 1.2 2001/05/02 08:48:43 cjolif Exp $
*/
-public class GeneratorContext implements Painter {
- public void paint(Graphics2D g) {
+public class GeneratorContext extends SVGAccuracyTest implements SVGConstants {
+ public static class TestIDGenerator extends SVGIDGenerator {
+ public String generateID(String prefix) {
+ return "test"+super.generateID(prefix);
+ }
+ }
+ public static class TestStyleHandler extends DefaultStyleHandler {
+ private CDATASection styleSheet;
+ public TestStyleHandler(CDATASection styleSheet) {
+ this.styleSheet = styleSheet;
+ }
+ public void setStyle(Element element, Map styleMap,
+ SVGGeneratorContext generatorContext) {
+ Iterator iter = styleMap.keySet().iterator();
+ // create a new class id in the style sheet
+ String id = generatorContext.getIDGenerator().generateID("C");
+ styleSheet.appendData("."+id+" {");
+ // append each key/value pairs
+ while (iter.hasNext()) {
+ String key = (String)iter.next();
+ String value = (String)styleMap.get(key);
+ styleSheet.appendData(key+":"+value+";");
+ }
+ styleSheet.appendData("}\n");
+ // reference the class id of the style sheet on the element to be styled
+ element.setAttribute("class", id);
+ }
}
+
+ private Element topLevelGroup = null;
+
+ public GeneratorContext(Painter painter,
+ URL refURL) {
+ super(painter, refURL);
+ }
+
+ protected SVGGraphics2D buildSVGGraphics2D() {
+ DOMImplementation impl = SVGDOMImplementation.getDOMImplementation();
+ String namespaceURI = SVGDOMImplementation.SVG_NAMESPACE_URI;
+ Document domFactory = impl.createDocument(namespaceURI, SVG_SVG_TAG, null);
+ SVGGeneratorContext ctx = SVGGeneratorContext.createDefault(domFactory);
+ CDATASection styleSheet = domFactory.createCDATASection("");
+ ctx.setIDGenerator(new TestIDGenerator());
+ // Extension Handler to be done
+ // Image Handler to be done
+ ctx.setStyleHandler(new TestStyleHandler(styleSheet));
+ // with a accent to test encoding
+ ctx.setComment("Generated by the Batik Test Framework. Test:\u00e9j");
+ // error handler ?
+ SVGGraphics2D g2d = new SVGGraphics2D(ctx, false);
+ topLevelGroup = g2d.getTopLevelGroup();
+ Element style = domFactory.createElementNS(SVG_NAMESPACE_URI, SVG_STYLE_TAG);
+ style.setAttributeNS(null, SVG_TYPE_ATTRIBUTE, "text/css");
+ style.appendChild(styleSheet);
+ topLevelGroup.appendChild(style);
+ return g2d;
+ }
+
+ protected void configureSVGGraphics2D(SVGGraphics2D g2d) {
+ topLevelGroup.appendChild(g2d.getTopLevelGroup());
+ g2d.setTopLevelGroup(topLevelGroup);
+ }
}
+
1.5 +10 -2 xml-batik/test-sources/org/apache/batik/svggen/SVGAccuracyTest.java
Index: SVGAccuracyTest.java
===================================================================
RCS file: /home/cvs/xml-batik/test-sources/org/apache/batik/svggen/SVGAccuracyTest.java,v
retrieving revision 1.4
retrieving revision 1.5
diff -u -r1.4 -r1.5
--- SVGAccuracyTest.java 2001/04/24 16:15:41 1.4
+++ SVGAccuracyTest.java 2001/05/02 08:48:43 1.5
@@ -40,7 +40,7 @@
* SVG reference.
*
* @author <a href="mailto:vhardy@apache.org">Vincent Hardy</a>
- * @version $Id: SVGAccuracyTest.java,v 1.4 2001/04/24 16:15:41 cjolif Exp $
+ * @version $Id: SVGAccuracyTest.java,v 1.5 2001/05/02 08:48:43 cjolif Exp $
*/
public class SVGAccuracyTest extends AbstractTest
implements SVGConstants{
@@ -143,6 +143,7 @@
OutputStreamWriter osw = new OutputStreamWriter(bos, "UTF-8");
try{
painter.paint(g2d);
+ configureSVGGraphics2D(g2d);
g2d.stream(osw);
osw.flush();
bos.flush();
@@ -254,11 +255,18 @@
* Builds an <tt>SVGGraphics2D</tt> with a default
* configuration.
*/
- protected SVGGraphics2D buildSVGGraphics2D(){
+ protected SVGGraphics2D buildSVGGraphics2D() {
// CSSDocumentHandler.setParserClassName(CSS_PARSER_CLASS_NAME);
DOMImplementation impl = SVGDOMImplementation.getDOMImplementation();
String namespaceURI = SVGDOMImplementation.SVG_NAMESPACE_URI;
Document domFactory = impl.createDocument(namespaceURI, SVG_SVG_TAG, null);
return new SVGGraphics2D(domFactory);
}
+
+
+ /**
+ * Eventually configure the <tt>SVGGraphics2D</tt> after dumping in it and just
+ * before serializing the DOM Tree.
+ */
+ protected void configureSVGGraphics2D(SVGGraphics2D g2d) {}
}
---------------------------------------------------------------------
To unsubscribe, e-mail: batik-dev-unsubscribe@xml.apache.org
For additional commands, e-mail: batik-dev-help@xml.apache.org