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/03/27 16:46:09 UTC
cvs commit: xml-batik/sources/org/apache/batik/svggen DefaultStyleHandler.java StyleHandler.java DOMGroupManager.java DOMTreeManager.java ExtensionHandler.java SVGGeneratorContext.java SVGGraphicContext.java SVGGraphicContextConverter.java SVGGraphics2D.java
cjolif 01/03/27 06:46:09
Modified: sources/org/apache/batik/svggen DOMGroupManager.java
DOMTreeManager.java ExtensionHandler.java
SVGGeneratorContext.java SVGGraphicContext.java
SVGGraphicContextConverter.java SVGGraphics2D.java
Added: sources/org/apache/batik/svggen DefaultStyleHandler.java
StyleHandler.java
Log:
Add a style handler to be able to totally change from the outside
how the style is managed on the document being build.
Revision Changes Path
1.8 +86 -52 xml-batik/sources/org/apache/batik/svggen/DOMGroupManager.java
Index: DOMGroupManager.java
===================================================================
RCS file: /home/cvs/xml-batik/sources/org/apache/batik/svggen/DOMGroupManager.java,v
retrieving revision 1.7
retrieving revision 1.8
diff -u -r1.7 -r1.8
--- DOMGroupManager.java 2001/03/26 09:45:12 1.7
+++ DOMGroupManager.java 2001/03/27 14:46:08 1.8
@@ -46,14 +46,18 @@
* is added to the current group. This is needed to let the
* DOMTreeManager handle group managers that would be used concurrently.
*
+ * @author <a href="mailto:cjolif@ilog.fr">Christophe Jolif</a>
* @author <a href="mailto:vincent.hardy@eng.sun.com">Vincent Hardy</a>
- * @version $Id: DOMGroupManager.java,v 1.7 2001/03/26 09:45:12 tkormann Exp $
+ * @version $Id: DOMGroupManager.java,v 1.8 2001/03/27 14:46:08 cjolif Exp $
*/
public class DOMGroupManager implements SVGSyntax {
private static final String ERROR_GC_NULL = "gc should not be null";
private static final String ERROR_DOMTREEMANAGER_NULL =
"domTreeManager should not be null";
+ public final static short DRAW = 0x01;
+ public final static short FILL = 0x10;
+
/**
* Reference to the GraphicContext this manager will use to
* reflect style attributes in the tree nodes.
@@ -82,11 +86,11 @@
* @param domTreeManager DOMTreeManager instance this group manager
* cooperates with.
*/
- public DOMGroupManager(GraphicContext gc, DOMTreeManager domTreeManager){
- if(gc == null)
+ public DOMGroupManager(GraphicContext gc, DOMTreeManager domTreeManager) {
+ if (gc == null)
throw new IllegalArgumentException(ERROR_GC_NULL);
- if(domTreeManager == null)
+ if (domTreeManager == null)
throw new IllegalArgumentException(ERROR_DOMTREEMANAGER_NULL);
this.gc = gc;
@@ -102,28 +106,51 @@
/**
* Reset the state of this object to handle a new currentGroup
*/
- void recycleCurrentGroup(){
+ void recycleCurrentGroup() {
// Create new initial current group node
- currentGroup = domTreeManager.getDOMFactory().createElementNS(SVG_NAMESPACE_URI, SVG_G_TAG);
+ currentGroup = domTreeManager.getDOMFactory().
+ createElementNS(SVG_NAMESPACE_URI, SVG_G_TAG);
}
/**
- * Add a node to the current group, if possible
+ * Adds a node to the current group, if possible
* @param element child Element to add to the group
*/
public void addElement(Element element) {
+ addElement(element, (short)(DRAW|FILL));
+
+}
+ /**
+ * Adds a node to the current group, if possible
+ * @param element child Element to add to the group
+ */
+ public void addElement(Element element, short method) {
//
// If this is the first child to be added to the
// currentGroup, 'freeze' the style attributes.
//
- if(!currentGroup.hasChildNodes()){
+ if (!currentGroup.hasChildNodes()) {
currentGroup.appendChild(element);
groupGC = domTreeManager.gcConverter.toSVG(gc);
SVGGraphicContext deltaGC = processDeltaGC(groupGC,
domTreeManager.defaultGC);
- setAttributes(currentGroup, deltaGC.getGroupContext());
- setAttributes(element, deltaGC.getGraphicElementContext());
+ domTreeManager.getStyleHandler().
+ setStyle(currentGroup, deltaGC.getGroupContext(),
+ domTreeManager.getGeneratorContext());
+ if ((method & DRAW) == 0) {
+ // force stroke:none
+ deltaGC.getGraphicElementContext().put(SVG_STROKE_ATTRIBUTE,
+ SVG_NONE_VALUE);
+ }
+ if ((method & FILL) == 0) {
+ // force fill:none
+ deltaGC.getGraphicElementContext().put(SVG_FILL_ATTRIBUTE,
+ SVG_NONE_VALUE);
+ }
+ domTreeManager.getStyleHandler().
+ setStyle(element, deltaGC.getGraphicElementContext(),
+ domTreeManager.getGeneratorContext());
setTransform(currentGroup, deltaGC.getTransformStack());
domTreeManager.appendGroup(currentGroup, this);
} else {
@@ -133,17 +160,31 @@
// out delta between current gc and group
// context
//
- SVGGraphicContext elementGC = domTreeManager.gcConverter.toSVG(gc);
+ SVGGraphicContext elementGC =
+ domTreeManager.gcConverter.toSVG(gc);
SVGGraphicContext deltaGC = processDeltaGC(elementGC, groupGC);
// If there are less than the maximum number
// of differences, then add the node to the current
// group and set its attributes
trimContextForElement(deltaGC, element);
- if(countOverrides(deltaGC) <= domTreeManager.maxGCOverrides) {
+ if (countOverrides(deltaGC) <= domTreeManager.maxGCOverrides) {
currentGroup.appendChild(element);
- setAttributes(element, deltaGC.getGroupContext());
- setAttributes(element, deltaGC.getGraphicElementContext());
+ // as there already are children we put all
+ // attributes (group + element) on the element itself.
+ if ((method & DRAW) == 0) {
+ // force stroke:none
+ deltaGC.getContext().
+ put(SVG_STROKE_ATTRIBUTE, SVG_NONE_VALUE);
+ }
+ if ((method & FILL) == 0) {
+ // force fill:none
+ deltaGC.getContext().
+ put(SVG_FILL_ATTRIBUTE, SVG_NONE_VALUE);
+ }
+ domTreeManager.getStyleHandler().
+ setStyle(element, deltaGC.getContext(),
+ domTreeManager.getGeneratorContext());
setTransform(element, deltaGC.getTransformStack());
} else {
//
@@ -152,7 +193,7 @@
currentGroup =
domTreeManager.getDOMFactory().
createElementNS(SVG_NAMESPACE_URI, SVG_G_TAG);
- addElement(element);
+ addElement(element, method);
}
} else {
//
@@ -163,7 +204,7 @@
domTreeManager.getDOMFactory().
createElementNS(SVG_NAMESPACE_URI, SVG_G_TAG);
gc.validateTransformStack();
- addElement(element);
+ addElement(element, method);
}
}
}
@@ -173,17 +214,17 @@
* overrides. Only differences in the group context are considered
* overrides.
*/
- private int countOverrides(SVGGraphicContext deltaGC){
+ private int countOverrides(SVGGraphicContext deltaGC) {
return deltaGC.getGroupContext().size();
}
/**
* Removes properties that do not apply for a specific element
*/
- private void trimContextForElement(SVGGraphicContext svgGC, Element element){
+ private void trimContextForElement(SVGGraphicContext svgGC, Element element) {
String tag = element.getTagName();
Map groupAttrMap = svgGC.getGroupContext();
- if(tag != null){
+ if (tag != null) {
// For each attribute, check if there is an attribute
// descriptor. If there is, check if the attribute
// applies to the input element. If there is none,
@@ -202,28 +243,15 @@
* Processes the transform attribute value corresponding to a
* given transform stack
*/
- private void setTransform(Element element, TransformStackElement transformStack[]){
- String transform = domTreeManager.gcConverter.toSVG(transformStack).trim();
- if(transform.length() > 0)
+ private void setTransform(Element element,
+ TransformStackElement transformStack[]) {
+ String transform = domTreeManager.gcConverter.
+ toSVG(transformStack).trim();
+ if (transform.length() > 0)
element.setAttributeNS(null, SVG_TRANSFORM_ATTRIBUTE, transform);
}
/**
- * Implementation helper: sets attributes in input attrMap
- * into input element. If the element's attribute is already
- * specified, it is *not* overridden.
- */
- private void setAttributes(Element element, Map attrMap){
- String tagName = element.getTagName();
- Iterator iter = attrMap.keySet().iterator();
- while(iter.hasNext()){
- String attrName = (String)iter.next();
- if(element.getAttributeNS(null, attrName).length() == 0)
- element.setAttributeNS(null, attrName, (String)attrMap.get(attrName));
- }
- }
-
- /**
* Processes the difference between two graphic contexts. The values
* in gc that are different from the values in referenceGc will be
* present in the delta. Other values will no.
@@ -240,11 +268,18 @@
TransformStackElement deltaTransformStack[] =
new TransformStackElement[deltaStackLength];
- System.arraycopy(gcTransformStack, referenceStack.length, deltaTransformStack, 0, deltaStackLength);
+ System.arraycopy(gcTransformStack, referenceStack.length,
+ deltaTransformStack, 0, deltaStackLength);
- // System.err.println("gc transform stack length: " + gc.getTransformStack().length);
- // System.err.println("reference stack length : " + referenceGc.getTransformStack().length);
- // System.err.println("delta stack length : " + deltaTransformStack.length);
+ /**
+ System.err.println("gc transform stack length: " +
+ gc.getTransformStack().length);
+ System.err.println("reference stack length : " +
+ referenceGc.getTransformStack().length);
+ System.err.println("delta stack length : " +
+ deltaTransformStack.length);
+ */
+
/*
TransformStackElement gcStack[] = gc.getTransformStack();
for(int i=0; i<gcStack.length; i++)
@@ -255,15 +290,14 @@
System.err.println("refStack[" + i + "] = " + refStack[i].toString());
for(int i=0; i<deltaTransformStack.length; i++)
- System.err.println("deltaStack[" + i + "] = " + deltaTransformStack[i].toString());
+ System.err.println("deltaStack[" + i + "] = " +
+ deltaTransformStack[i].toString());
*/
- SVGGraphicContext deltaGC = new SVGGraphicContext(groupDelta, graphicElementDelta, deltaTransformStack);
- // System.out.println("===>>> Reference GC");
- // SVGGraphicContextConverter.traceSVGGC(referenceGc, domTreeManager.gcConverter);
+ SVGGraphicContext deltaGC = new SVGGraphicContext(groupDelta,
+ graphicElementDelta,
+ deltaTransformStack);
- // System.out.println("===>>> Delta GC");
- // SVGGraphicContextConverter.traceSVGGC(deltaGC, domTreeManager.gcConverter);
return deltaGC;
}
@@ -273,14 +307,15 @@
* are different from values in referenceMap are place in the
* returned delta Map.
*/
- private Map processDeltaMap(Map map, Map referenceMap){
- Map mapDelta = new Hashtable();
+ private Map processDeltaMap(Map map, Map referenceMap) {
+ // no need to be synch => HashMap
+ Map mapDelta = new HashMap();
Iterator iter = map.keySet().iterator();
- while(iter.hasNext()){
+ while (iter.hasNext()){
String key = (String)iter.next();
String value = (String)map.get(key);
String refValue = (String)referenceMap.get(key);
- if(!value.equals(refValue)) {
+ if (!value.equals(refValue)) {
/*if(key.equals(SVG_TRANSFORM_ATTRIBUTE)){
// Special handling for the transform attribute.
// At this point in the processing, the transform
@@ -291,7 +326,6 @@
mapDelta.put(key, value);
}
}
-
return mapDelta;
}
}
1.9 +9 -5 xml-batik/sources/org/apache/batik/svggen/DOMTreeManager.java
Index: DOMTreeManager.java
===================================================================
RCS file: /home/cvs/xml-batik/sources/org/apache/batik/svggen/DOMTreeManager.java,v
retrieving revision 1.8
retrieving revision 1.9
diff -u -r1.8 -r1.9
--- DOMTreeManager.java 2001/03/26 12:37:32 1.8
+++ DOMTreeManager.java 2001/03/27 14:46:08 1.9
@@ -45,7 +45,7 @@
*
* @author <a href="mailto:cjolif">Christophe Jolif</a>
* @author <a href="mailto:vincent.hardy@eng.sun.com">Vincent Hardy</a>
- * @version $Id: DOMTreeManager.java,v 1.8 2001/03/26 12:37:32 tkormann Exp $
+ * @version $Id: DOMTreeManager.java,v 1.9 2001/03/27 14:46:08 cjolif Exp $
*/
public class DOMTreeManager implements SVGSyntax {
/**
@@ -292,10 +292,6 @@
*/
void setExtensionHandler(ExtensionHandler extensionHandler) {
generatorContext.setExtensionHandler(extensionHandler);
- // we have change the context, this automatically change
- // handler for converters
- // gcConverter.setExtensionHandler(extensionHandler);
- // filterConverter.setExtensionHandler(extensionHandler);
}
/**
@@ -395,7 +391,15 @@
return gcConverter;
}
+ SVGGeneratorContext getGeneratorContext() {
+ return generatorContext;
+ }
+
Document getDOMFactory() {
return generatorContext.domFactory;
+ }
+
+ StyleHandler getStyleHandler() {
+ return generatorContext.styleHandler;
}
}
1.4 +2 -2 xml-batik/sources/org/apache/batik/svggen/ExtensionHandler.java
Index: ExtensionHandler.java
===================================================================
RCS file: /home/cvs/xml-batik/sources/org/apache/batik/svggen/ExtensionHandler.java,v
retrieving revision 1.3
retrieving revision 1.4
diff -u -r1.3 -r1.4
--- ExtensionHandler.java 2001/03/23 17:23:10 1.3
+++ ExtensionHandler.java 2001/03/27 14:46:08 1.4
@@ -24,7 +24,7 @@
* Paints, Composites or BufferedImageOp filters).
*
* @author <a href="mailto:vincent.hardy@eng.sun.com">Vincent Hardy</a>
- * @version $Id: ExtensionHandler.java,v 1.3 2001/03/23 17:23:10 cjolif Exp $
+ * @version $Id: ExtensionHandler.java,v 1.4 2001/03/27 14:46:08 cjolif Exp $
*/
public interface ExtensionHandler {
/**
@@ -33,7 +33,7 @@
* @return an SVGPaintDescriptor
*/
public SVGPaintDescriptor handlePaint(Paint paint,
- SVGGeneratorContext geneartorContext);
+ SVGGeneratorContext generatorContext);
/**
* @param composite Custom Composite to be converted to SVG.
1.4 +36 -10 xml-batik/sources/org/apache/batik/svggen/SVGGeneratorContext.java
Index: SVGGeneratorContext.java
===================================================================
RCS file: /home/cvs/xml-batik/sources/org/apache/batik/svggen/SVGGeneratorContext.java,v
retrieving revision 1.3
retrieving revision 1.4
diff -u -r1.3 -r1.4
--- SVGGeneratorContext.java 2001/03/23 17:23:13 1.3
+++ SVGGeneratorContext.java 2001/03/27 14:46:08 1.4
@@ -18,9 +18,9 @@
*
* @see org.apache.batik.svggen.SVGGraphics2D#SVGGraphics2D(SVGGeneratorContext,boolean)
* @author <a href="mailto:cjolif@ilog.fr>Christophe Jolif</a>
- * @version $Id: SVGGeneratorContext.java,v 1.3 2001/03/23 17:23:13 cjolif Exp $
+ * @version $Id: SVGGeneratorContext.java,v 1.4 2001/03/27 14:46:08 cjolif Exp $
*/
-final public class SVGGeneratorContext {
+public class SVGGeneratorContext {
/**
* Error messages.
*/
@@ -32,6 +32,8 @@
"extensionHandler should not be null";
private static final String ERROR_ID_GENERATOR_NULL =
"idGenerator should not be null";
+ private static final String ERROR_STYLE_HANDLER_NULL =
+ "styleHandler should not be null";
// this fields are package access for read-only purpose
@@ -63,6 +65,11 @@
SVGIDGenerator idGenerator;
/**
+ * To set style.
+ */
+ StyleHandler styleHandler;
+
+ /**
* Builds an instance of <code>SVGGeneratorContext</code> with the given
* <code>domFactory</code> but let the user set later the other contextual
* information.
@@ -87,6 +94,7 @@
ctx.setIDGenerator(new SVGIDGenerator());
ctx.setExtensionHandler(new DefaultExtensionHandler());
ctx.setImageHandler(new ImageHandlerBase64Encoder());
+ ctx.setStyleHandler(new DefaultStyleHandler());
return ctx;
}
@@ -94,7 +102,7 @@
* Returns the {@link org.apache.batik.svggen.SVGIDGenerator} that
* has been set.
*/
- public SVGIDGenerator getIDGenerator() {
+ final public SVGIDGenerator getIDGenerator() {
return idGenerator;
}
@@ -102,7 +110,7 @@
* Sets the {@link org.apache.batik.svggen.SVGIDGenerator}
* to be used. It should not be <code>null</code>.
*/
- protected void setIDGenerator(SVGIDGenerator idGenerator) {
+ final protected void setIDGenerator(SVGIDGenerator idGenerator) {
if (idGenerator == null)
throw new IllegalArgumentException(ERROR_ID_GENERATOR_NULL);
this.idGenerator = idGenerator;
@@ -112,7 +120,7 @@
* Returns the DOM Factory that
* has been set.
*/
- public Document getDOMFactory() {
+ final public Document getDOMFactory() {
return domFactory;
}
@@ -120,7 +128,7 @@
* Sets the DOM Factory
* to be used. It should not be <code>null</code>.
*/
- protected void setDOMFactory(Document domFactory) {
+ final protected void setDOMFactory(Document domFactory) {
if (domFactory == null)
throw new IllegalArgumentException(ERROR_DOM_FACTORY_NULL);
this.domFactory = domFactory;
@@ -130,7 +138,7 @@
* Returns the {@link org.apache.batik.svggen.ExtensionHandler} that
* has been set.
*/
- public ExtensionHandler getExtensionHandler() {
+ final public ExtensionHandler getExtensionHandler() {
return extensionHandler;
}
@@ -138,7 +146,7 @@
* Sets the {@link org.apache.batik.svggen.ExtensionHandler}
* to be used. It should not be <code>null</code>.
*/
- protected void setExtensionHandler(ExtensionHandler extensionHandler) {
+ final protected void setExtensionHandler(ExtensionHandler extensionHandler) {
if (extensionHandler == null)
throw new IllegalArgumentException(ERROR_EXTENSION_HANDLER_NULL);
this.extensionHandler = extensionHandler;
@@ -148,7 +156,7 @@
* Returns the {@link org.apache.batik.svggen.ImageHandler} that
* has been set.
*/
- public ImageHandler getImageHandler() {
+ final public ImageHandler getImageHandler() {
return imageHandler;
}
@@ -156,9 +164,27 @@
* Sets the {@link org.apache.batik.svggen.ImageHandler}
* to be used. It should not be <code>null</code>.
*/
- protected void setImageHandler(ImageHandler imageHandler) {
+ final protected void setImageHandler(ImageHandler imageHandler) {
if (imageHandler == null)
throw new IllegalArgumentException(ERROR_IMAGE_HANDLER_NULL);
this.imageHandler = imageHandler;
+ }
+
+ /**
+ * Returns the {@link org.apache.batik.svggen.StyleHandler} that
+ * has been set.
+ */
+ final public StyleHandler getStyleHandler() {
+ return styleHandler;
+ }
+
+ /**
+ * Sets the {@link org.apache.batik.svggen.Stylehandler}
+ * to be used. It should not be <code>null</code>.
+ */
+ final protected void setStyleHandler(StyleHandler styleHandler) {
+ if (styleHandler == null)
+ throw new IllegalArgumentException(ERROR_STYLE_HANDLER_NULL);
+ this.styleHandler = styleHandler;
}
}
1.3 +80 -10 xml-batik/sources/org/apache/batik/svggen/SVGGraphicContext.java
Index: SVGGraphicContext.java
===================================================================
RCS file: /home/cvs/xml-batik/sources/org/apache/batik/svggen/SVGGraphicContext.java,v
retrieving revision 1.2
retrieving revision 1.3
diff -u -r1.2 -r1.3
--- SVGGraphicContext.java 2001/03/14 01:36:47 1.2
+++ SVGGraphicContext.java 2001/03/27 14:46:08 1.3
@@ -9,9 +9,11 @@
package org.apache.batik.svggen;
import java.util.Map;
+import java.util.HashMap;
import org.w3c.dom.*;
+import org.apache.batik.util.SVGConstants;
import org.apache.batik.ext.awt.g2d.GraphicContext;
import org.apache.batik.ext.awt.g2d.TransformStackElement;
@@ -20,50 +22,118 @@
* context attribute.
*
* @author <a href="mailto:vincent.hardy@eng.sun.com">Vincent Hardy</a>
- * @version $Id: SVGGraphicContext.java,v 1.2 2001/03/14 01:36:47 vhardy Exp $
+ * @version $Id: SVGGraphicContext.java,v 1.3 2001/03/27 14:46:08 cjolif Exp $
*/
-public class SVGGraphicContext{
- public static final String ERROR_NULL_INPUT = "groupContext, graphicElementContext and transformStack should not be null";
+public class SVGGraphicContext implements SVGConstants {
+ private static final String ERROR_NULL_INPUT =
+ "arguments should not be null";
+
+ // this properties can only be set of leaf nodes =>
+ // if they have default values they can be ignored
+ private static final String leafOnlyAttributes[] = {
+ SVG_OPACITY_ATTRIBUTE,
+ SVG_FILTER_ATTRIBUTE,
+ SVG_CLIP_PATH_ATTRIBUTE
+ };
+
+ private static final String defaultValues[] = {
+ "1",
+ SVG_NONE_VALUE,
+ SVG_NONE_VALUE
+ };
+
+ private Map context;
private Map groupContext;
private Map graphicElementContext;
private TransformStackElement transformStack[];
/**
+ * @param context Set of style attributes in this context.
+ * @param transformStack Sequence of transforms that where
+ * applied to create the context's current transform.
+ */
+ public SVGGraphicContext(Map context,
+ TransformStackElement transformStack[]) {
+ if (context == null ||
+ transformStack == null)
+ throw new IllegalArgumentException(ERROR_NULL_INPUT);
+ this.context = context;
+ this.transformStack = transformStack;
+ computeGroupAndGraphicElementContext();
+ }
+
+ /**
* @param groupContext Set of attributes that apply to group
* @param graphicElementContext Set of attributes that apply to
* elements but not to groups (e.g., opacity, filter).
* @param transformStack Sequence of transforms that where
* applied to create the context's current transform.
*/
- public SVGGraphicContext(Map groupContext,
- Map graphicElementContext,
- TransformStackElement transformStack[]){
- if(groupContext == null || graphicElementContext == null)
+ public SVGGraphicContext(Map groupContext, Map graphicElementContext,
+ TransformStackElement transformStack[]) {
+ if (groupContext == null || graphicElementContext == null ||
+ transformStack == null)
throw new IllegalArgumentException(ERROR_NULL_INPUT);
this.groupContext = groupContext;
this.graphicElementContext = graphicElementContext;
this.transformStack = transformStack;
+ computeContext();
}
+
/**
+ * @return set of all attributes.
+ */
+ public Map getContext() {
+ return context;
+ }
+
+ /**
* @return set of attributes that can be set on a group
*/
- public Map getGroupContext(){
+ public Map getGroupContext() {
return groupContext;
}
/**
* @return set of attributes that can be set on leaf node
*/
- public Map getGraphicElementContext(){
+ public Map getGraphicElementContext() {
return graphicElementContext;
}
/**
* @return set of TransformStackElement for this context
*/
- public TransformStackElement[] getTransformStack(){
+ public TransformStackElement[] getTransformStack() {
return transformStack;
+ }
+
+ private void computeContext() {
+ if (context != null)
+ return;
+
+ context = new HashMap(groupContext);
+ context.putAll(graphicElementContext);
+ }
+
+ private void computeGroupAndGraphicElementContext() {
+ if (groupContext != null)
+ return;
+ //
+ // Now, move attributes that only apply to
+ // leaf elements to a separate map.
+ //
+ groupContext = new HashMap(context);
+ graphicElementContext = new HashMap();
+ for (int i=0; i< leafOnlyAttributes.length; i++) {
+ Object attrValue = groupContext.get(leafOnlyAttributes[i]);
+ if (attrValue != null){
+ if (!attrValue.equals(defaultValues[i]))
+ graphicElementContext.put(leafOnlyAttributes[i], attrValue);
+ groupContext.remove(leafOnlyAttributes[i]);
+ }
+ }
}
}
1.7 +11 -28 xml-batik/sources/org/apache/batik/svggen/SVGGraphicContextConverter.java
Index: SVGGraphicContextConverter.java
===================================================================
RCS file: /home/cvs/xml-batik/sources/org/apache/batik/svggen/SVGGraphicContextConverter.java,v
retrieving revision 1.6
retrieving revision 1.7
diff -u -r1.6 -r1.7
--- SVGGraphicContextConverter.java 2001/03/26 09:45:13 1.6
+++ SVGGraphicContextConverter.java 2001/03/27 14:46:08 1.7
@@ -25,20 +25,14 @@
* SVG attributes.
*
* @author <a href="mailto:vincent.hardy@eng.sun.com">Vincent Hardy</a>
- * @version $Id: SVGGraphicContextConverter.java,v 1.6 2001/03/26 09:45:13 tkormann Exp $
+ * @version $Id: SVGGraphicContextConverter.java,v 1.7 2001/03/27 14:46:08 cjolif Exp $
*/
-public class SVGGraphicContextConverter implements SVGSyntax {
+public class SVGGraphicContextConverter {
private static final String ERROR_CONTEXT_NULL =
"generatorContext should not be null";
private static final int GRAPHIC_CONTEXT_CONVERTER_COUNT = 6;
- private String leafOnlyAttributes[] = {
- SVG_OPACITY_ATTRIBUTE,
- SVG_FILTER_ATTRIBUTE,
- SVG_CLIP_PATH_ATTRIBUTE
- };
-
private SVGTransform transformConverter;
private SVGPaint paintConverter;
private SVGBasicStroke strokeConverter;
@@ -86,7 +80,7 @@
* @return a String containing the transform attribute value
* equivalent of the input transform stack.
*/
- public String toSVG(TransformStackElement transformStack[]){
+ public String toSVG(TransformStackElement transformStack[]) {
return transformConverter.toSVGTransform(transformStack);
}
@@ -94,29 +88,18 @@
* @return an object that describes the set of SVG attributes that
* represent the equivalent of the input GraphicContext state.
*/
- public SVGGraphicContext toSVG(GraphicContext gc){
- Map groupAttrMap = new Hashtable();
+ public SVGGraphicContext toSVG(GraphicContext gc) {
+ // no need for synchronized map => use HashMap
+ Map groupAttrMap = new HashMap();
- for(int i=0; i<converters.length; i++){
+ for (int i=0; i<converters.length; i++) {
SVGDescriptor desc = converters[i].toSVG(gc);
- if(desc != null)
+ if (desc != null)
desc.getAttributeMap(groupAttrMap);
}
-
- //
- // Now, move attributes that only apply to
- // leaf elements to a separate map.
- //
- Map graphicElementsMap = new Hashtable();
- for(int i=0; i<leafOnlyAttributes.length; i++){
- Object attrValue = groupAttrMap.get(leafOnlyAttributes[i]);
- if(attrValue != null){
- graphicElementsMap.put(leafOnlyAttributes[i], attrValue);
- groupAttrMap.remove(leafOnlyAttributes[i]);
- }
- }
- return new SVGGraphicContext(groupAttrMap, graphicElementsMap,
+ // the ctor will to the splitting (group/element) job
+ return new SVGGraphicContext(groupAttrMap,
gc.getTransformStack());
}
@@ -124,7 +107,7 @@
* @return a set of element containing definitions for the attribute
* values generated by this converter since its creation.
*/
- public Set getDefinitionSet(){
+ public Set getDefinitionSet() {
Set defSet = new HashSet();
for(int i=0; i<converters.length; i++)
defSet.addAll(converters[i].getDefinitionSet());
1.11 +10 -14 xml-batik/sources/org/apache/batik/svggen/SVGGraphics2D.java
Index: SVGGraphics2D.java
===================================================================
RCS file: /home/cvs/xml-batik/sources/org/apache/batik/svggen/SVGGraphics2D.java,v
retrieving revision 1.10
retrieving revision 1.11
diff -u -r1.10 -r1.11
--- SVGGraphics2D.java 2001/03/26 09:45:13 1.10
+++ SVGGraphics2D.java 2001/03/27 14:46:08 1.11
@@ -44,7 +44,7 @@
*
*
* @author <a href="mailto:vincent.hardy@eng.sun.com">Vincent Hardy</a>
- * @version $Id: SVGGraphics2D.java,v 1.10 2001/03/26 09:45:13 tkormann Exp $
+ * @version $Id: SVGGraphics2D.java,v 1.11 2001/03/27 14:46:08 cjolif Exp $
* @see org.apache.batik.ext.awt.g2d.GraphicContext
* @see org.apache.batik.svggen.DOMTreeManager
* @see org.apache.batik.svggen.DOMGroupManager
@@ -592,19 +592,17 @@
* @see #setClip
* @see #setComposite
*/
- public void draw(Shape s){
+ public void draw(Shape s) {
// Only BasicStroke can be converted to an SVG attribute equivalent.
// If the GraphicContext's Stroke is not an instance of BasicStroke,
// then the stroked outline is filled.
Stroke stroke = gc.getStroke();
- if(stroke instanceof BasicStroke){
+ if (stroke instanceof BasicStroke) {
Element svgShape = shapeConverter.toSVG(s);
- if(svgShape != null){
- svgShape.setAttributeNS(null, SVG_FILL_ATTRIBUTE, SVG_NONE_VALUE);
- domGroupManager.addElement(svgShape);
+ if (svgShape != null) {
+ domGroupManager.addElement(svgShape, DOMGroupManager.DRAW);
}
- }
- else{
+ } else {
Shape strokedShape = stroke.createStrokedShape(s);
fill(strokedShape);
}
@@ -939,9 +937,8 @@
AbstractSVGConverter.doubleString(x));
text.setAttributeNS(null, SVG_Y_ATTRIBUTE,
AbstractSVGConverter.doubleString(y));
- text.setAttributeNS(null, SVG_STROKE_ATTRIBUTE, SVG_NONE_VALUE);
text.appendChild(getDOMFactory().createTextNode(s));
- domGroupManager.addElement(text);
+ domGroupManager.addElement(text, DOMGroupManager.FILL);
} else {
GlyphVector gv = getFont().
createGlyphVector(getFontRenderContext(), s);
@@ -992,11 +989,10 @@
* @see #clip
* @see #setClip
*/
- public void fill(Shape s){
+ public void fill(Shape s) {
Element svgShape = shapeConverter.toSVG(s);
- if(svgShape != null){
- svgShape.setAttributeNS(null, SVG_STROKE_ATTRIBUTE, SVG_NONE_VALUE);
- domGroupManager.addElement(svgShape);
+ if (svgShape != null) {
+ domGroupManager.addElement(svgShape, DOMGroupManager.FILL);
}
}
1.1 xml-batik/sources/org/apache/batik/svggen/DefaultStyleHandler.java
Index: DefaultStyleHandler.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.util.Iterator;
import java.util.Map;
import org.w3c.dom.Element;
/**
* The <code>DefaultStyleHandler</code> class provides the default
* way to style an SVG <code>Element</code>.
*
* @author <a href="mailto:cjolif@ilog.fr">Christophe Jolif</a>
* @version $Id: DefaultStyleHandler.java,v 1.1 2001/03/27 14:46:08 cjolif Exp $
*/
public class DefaultStyleHandler implements StyleHandler {
/**
* Sets the style described by <code>styleMap</code> on the given
* <code>element</code>. That is sets the xml attributes with their
* styled value.
* @param element the SVG <code>Element</code> to be styled.
* @param styleMap the <code>Map</code> containing pairs of style
* property names, style values.
*/
public void setStyle(Element element, Map styleMap,
SVGGeneratorContext generatorContext) {
String tagName = element.getTagName();
Iterator iter = styleMap.keySet().iterator();
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));
}
}
}
1.1 xml-batik/sources/org/apache/batik/svggen/StyleHandler.java
Index: StyleHandler.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.util.Map;
import org.w3c.dom.Element;
/**
* The <code>StyleHandler</code> interface allows you to specialize
* how the style will be set on an SVG <code>Element</code>.
*
* @author <a href="mailto:cjolif@ilog.fr">Christophe Jolif</a>
* @version $Id: StyleHandler.java,v 1.1 2001/03/27 14:46:08 cjolif Exp $
*/
public interface StyleHandler {
/**
* Sets the style described by <code>styleMap</code> on the given
* <code>element</code>.
* @param element the SVG <code>Element</code> to be styled.
* @param styleMap the <code>Map</code> containing pairs of style
* property names, style values.
*/
public void setStyle(Element element, Map styleMap,
SVGGeneratorContext generatorContext);
}
---------------------------------------------------------------------
To unsubscribe, e-mail: batik-dev-unsubscribe@xml.apache.org
For additional commands, e-mail: batik-dev-help@xml.apache.org