vhardy      01/10/11 02:46:19

  Modified:    sources/org/apache/batik/svggen SVGGeneratorContext.java
                        SVGGraphics2D.java
  Log:
  Addition of defaults for initial graphic context attributes.
  
  Revision  Changes    Path
  1.13      +105 -1    
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.12
  retrieving revision 1.13
  diff -u -r1.12 -r1.13
  --- SVGGeneratorContext.java  2001/09/13 08:42:50     1.12
  +++ SVGGeneratorContext.java  2001/10/11 09:46:19     1.13
  @@ -10,6 +10,14 @@
   
   import org.w3c.dom.Document;
   
  +import java.awt.Paint;
  +import java.awt.Stroke;
  +import java.awt.Composite;
  +import java.awt.Shape;
  +import java.awt.RenderingHints;
  +import java.awt.Font;
  +import java.awt.Color;
  +
   /**
    * This class contains all non graphical contextual information that
    * are needed by the {@link org.apache.batik.svggen.SVGGraphics2D} to
  @@ -18,7 +26,7 @@
    *
    * @see 
org.apache.batik.svggen.SVGGraphics2D#SVGGraphics2D(SVGGeneratorContext,boolean)
    * @author <a href="mailto:[EMAIL PROTECTED]>Christophe Jolif</a>
  - * @version $Id: SVGGeneratorContext.java,v 1.12 2001/09/13 08:42:50 tkormann Exp $
  + * @version $Id: SVGGeneratorContext.java,v 1.13 2001/10/11 09:46:19 vhardy Exp $
    */
   public class SVGGeneratorContext implements ErrorConstants {
       // this fields are package access for read-only purpose
  @@ -71,6 +79,85 @@
       boolean svgFont = false;
   
       /**
  +     * GraphicContextDefaults
  +     */
  +    GraphicContextDefaults gcDefaults;
  +
  +    /**
  +     * Class to describe the GraphicContext defaults to
  +     * be used. Note that this class does *not* contain
  +     * a default for the initial transform, as this 
  +     * transform *has to be identity* for the SVGGraphics2D
  +     * to operate (the TransformStacks operation is based
  +     * on that assumption. See the DOMTreeManager class).
  +     */
  +    public static class GraphicContextDefaults {
  +        protected Paint paint;
  +        protected Stroke stroke;
  +        protected Composite composite;
  +        protected Shape clip;
  +        protected RenderingHints hints;
  +        protected Font font;
  +        protected Color background; 
  +
  +        public void setStroke(Stroke stroke){
  +            this.stroke = stroke;
  +        }
  +
  +        public Stroke getStroke(){
  +            return stroke;
  +        }
  +
  +        public void setComposite(Composite composite){
  +            this.composite = composite;
  +        }
  +
  +        public Composite getComposite(){
  +            return composite;
  +        }
  +
  +        public void setClip(Shape clip){
  +            this.clip = clip;
  +        }
  +
  +        public Shape getClip(){
  +            return clip;
  +        }
  +
  +        public void setRenderingHints(RenderingHints hints){
  +            this.hints = hints;
  +        }
  +
  +        public RenderingHints getRenderingHints(){
  +            return hints;
  +        }
  +
  +        public void setFont(Font font){
  +            this.font = font;
  +        }
  +
  +        public Font getFont(){
  +            return font;
  +        }
  +
  +        public void setBackground(Color background){
  +            this.background = background;
  +        }
  +
  +        public Color getBackground(){
  +            return background;
  +        }
  +
  +        public void setPaint(Paint paint){
  +            this.paint = paint;
  +        }
  +
  +        public Paint getPaint(){
  +            return paint;
  +        }
  +    }
  +
  +    /**
        * Builds an instance of <code>SVGGeneratorContext</code> with the given
        * <code>domFactory</code> but let the user set later the other contextual
        * information. Please note that none of the parameter below should be
  @@ -104,6 +191,23 @@
           ctx.setComment("Generated by the Batik Graphics2D SVG Generator");
           ctx.setErrorHandler(new DefaultErrorHandler());
           return ctx;
  +    }
  +
  +    /**
  +     * Returns the set of defaults which should be used for the 
  +     * GraphicContext.
  +     */
  +    final public GraphicContextDefaults getGraphicContextDefaults(){
  +        return gcDefaults;
  +    }
  +
  +    /**
  +     * Sets the default to be used for the graphic context.
  +     * Note that gcDefaults may be null and that any of its attributes
  +     * may be null.
  +     */
  +    final public void setGraphicContextDefaults(GraphicContextDefaults gcDefaults){
  +        this.gcDefaults = gcDefaults;
       }
   
       /**
  
  
  
  1.24      +44 -3     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.23
  retrieving revision 1.24
  diff -u -r1.23 -r1.24
  --- SVGGraphics2D.java        2001/09/19 13:21:55     1.23
  +++ SVGGraphics2D.java        2001/10/11 09:46:19     1.24
  @@ -45,7 +45,7 @@
    *
    *
    * @author <a href="mailto:[EMAIL PROTECTED]";>Vincent Hardy</a>
  - * @version $Id: SVGGraphics2D.java,v 1.23 2001/09/19 13:21:55 vhardy Exp $
  + * @version $Id: SVGGraphics2D.java,v 1.24 2001/10/11 09:46:19 vhardy Exp $
    * @see                org.apache.batik.ext.awt.g2d.GraphicContext
    * @see                org.apache.batik.svggen.DOMTreeManager
    * @see                org.apache.batik.svggen.DOMGroupManager
  @@ -200,7 +200,20 @@
                            ImageHandler imageHandler,
                            ExtensionHandler extensionHandler,
                            boolean textAsShapes) {
  -        super(textAsShapes);
  +        this(buildSVGGeneratorContext(domFactory,
  +                                      imageHandler,
  +                                      extensionHandler),
  +             textAsShapes);
  +    }
  +
  +    /**
  +     * Helper method to create an <tt>SVGGeneratorContext</tt> from the 
  +     * constructor parameters.
  +     */
  +    public static SVGGeneratorContext 
  +        buildSVGGeneratorContext(Document domFactory,
  +                                 ImageHandler imageHandler,
  +                                 ExtensionHandler extensionHandler){
   
           SVGGeneratorContext generatorCtx = new SVGGeneratorContext(domFactory);
           generatorCtx.setIDGenerator(new SVGIDGenerator());
  @@ -210,7 +223,7 @@
           generatorCtx.setComment("Generated by the Batik Graphics2D SVG Generator");
           generatorCtx.setErrorHandler(new DefaultErrorHandler());
   
  -        setGeneratorContext(generatorCtx);
  +        return generatorCtx;
       }
   
       /**
  @@ -239,6 +252,34 @@
           this.generatorCtx = generatorCtx;
   
           this.gc = new GraphicContext(new AffineTransform());
  +
  +        SVGGeneratorContext.GraphicContextDefaults gcDefaults =
  +            generatorCtx.getGraphicContextDefaults();
  +
  +        if(gcDefaults != null){
  +            if(gcDefaults.getPaint() != null){
  +                gc.setPaint(gcDefaults.getPaint());
  +            }
  +            if(gcDefaults.getStroke() != null){
  +                gc.setStroke(gcDefaults.getStroke());
  +            }
  +            if(gcDefaults.getComposite() != null){
  +                gc.setComposite(gcDefaults.getComposite());
  +            }
  +            if(gcDefaults.getClip() != null){
  +                gc.setClip(gcDefaults.getClip());
  +            }
  +            if(gcDefaults.getRenderingHints() != null){
  +                gc.setRenderingHints(gcDefaults.getRenderingHints());
  +            }
  +            if(gcDefaults.getFont() != null){
  +                gc.setFont(gcDefaults.getFont());
  +            }
  +            if(gcDefaults.getBackground() != null){
  +                gc.setBackground(gcDefaults.getBackground());
  +            }
  +        }
  +
           this.shapeConverter = new SVGShape(generatorCtx);
           this.domTreeManager = new DOMTreeManager(gc,
                                                    generatorCtx,
  
  
  

---------------------------------------------------------------------
To unsubscribe, e-mail: [EMAIL PROTECTED]
For additional commands, e-mail: [EMAIL PROTECTED]

Reply via email to