tkormann    02/03/21 01:39:17

  Modified:    sources/org/apache/batik/bridge BridgeContext.java
                        SVGFontUtilities.java
  Log:
  polish code
  
  Revision  Changes    Path
  1.43      +153 -124  xml-batik/sources/org/apache/batik/bridge/BridgeContext.java
  
  Index: BridgeContext.java
  ===================================================================
  RCS file: /home/cvs/xml-batik/sources/org/apache/batik/bridge/BridgeContext.java,v
  retrieving revision 1.42
  retrieving revision 1.43
  diff -u -r1.42 -r1.43
  --- BridgeContext.java        20 Mar 2002 16:34:43 -0000      1.42
  +++ BridgeContext.java        21 Mar 2002 09:39:17 -0000      1.43
  @@ -40,8 +40,8 @@
   import org.apache.batik.gvt.TextPainter;
   import org.apache.batik.script.Interpreter;
   import org.apache.batik.script.InterpreterPool;
  -import org.apache.batik.util.Service;
   import org.apache.batik.util.SVGConstants;
  +import org.apache.batik.util.Service;
   
   import org.w3c.dom.Document;
   import org.w3c.dom.Element;
  @@ -66,7 +66,7 @@
    * a SVG DOM tree such as the current viewport or the user agent.
    *
    * @author <a href="mailto:[EMAIL PROTECTED]";>Thierry Kormann</a>
  - * @version $Id: BridgeContext.java,v 1.42 2002/03/20 16:34:43 tkormann Exp $
  + * @version $Id: BridgeContext.java,v 1.43 2002/03/21 09:39:17 tkormann Exp $
    */
   public class BridgeContext implements ErrorConstants, CSSContext {
   
  @@ -88,11 +88,11 @@
       protected Map interpreterMap = new HashMap(7);
   
       /**
  -     * A hash map of all the font families already matched. This is
  +     * A Map of all the font families already matched. This is
        * to reduce the number of instances of GVTFontFamilies and to
        * hopefully reduce the time taken to search for a matching SVG font.
        */
  -    private HashMap fontFamilyMap;
  +    private Map fontFamilyMap;
   
       /**
        * The viewports.
  @@ -232,7 +232,33 @@
       // end debug leak
       */
   
  -    // properties ////////////////////////////////////
  +    /**
  +     * Initializes the given document.
  +     */
  +    protected void initializeDocument(Document document) {
  +        SVGOMDocument doc = (SVGOMDocument)document;
  +        CSSEngine eng = doc.getCSSEngine();
  +        if (eng == null) {
  +            SVGDOMImplementation impl;
  +            impl = (SVGDOMImplementation)doc.getImplementation();
  +            eng = impl.createCSSEngine(doc, this);
  +            doc.setCSSEngine(eng);
  +            eng.setMedia(userAgent.getMedia());
  +            String uri = userAgent.getUserStyleSheetURI();
  +            if (uri != null) {
  +                try {
  +                    URL url = new URL(uri);
  +                    eng.setUserAgentStyleSheet
  +                        (eng.parseStyleSheet(url, "all"));
  +                } catch (MalformedURLException e) {
  +                    userAgent.displayError(e);
  +                }
  +            }
  +            eng.setAlternateStyleSheet(userAgent.getAlternateStyleSheet());
  +        }
  +    }
  +
  +    // properties ////////////////////////////////////////////////////////////
   
       /**
        * Sets the text painter that will be used by text nodes. This attributes
  @@ -246,24 +272,6 @@
       }
   
       /**
  -     * Returns the document this bridge context is dedicated to.
  -     */
  -    public Document getDocument() {
  -        return document;
  -    }
  -
  -    /**
  -     * Returns the map of font families
  -     */
  -    public HashMap getFontFamilyMap(){
  -        if (fontFamilyMap == null){
  -            fontFamilyMap = new HashMap();
  -        }
  -
  -        return fontFamilyMap;
  -    }
  -
  -    /**
        * Returns the text painter that will be used be text nodes.
        */
       public TextPainter getTextPainter() {
  @@ -271,10 +279,10 @@
       }
   
       /**
  -     * Returns the user agent of this bridge context.
  +     * Returns the document this bridge context is dedicated to.
        */
  -    public UserAgent getUserAgent() {
  -        return userAgent;
  +    public Document getDocument() {
  +        return document;
       }
   
       /**
  @@ -290,29 +298,29 @@
       }
   
       /**
  -     * Initializes the given document.
  +     * Returns the map of font families
        */
  -    protected void initializeDocument(Document document) {
  -        SVGOMDocument doc = (SVGOMDocument)document;
  -        CSSEngine eng = doc.getCSSEngine();
  -        if (eng == null) {
  -            SVGDOMImplementation impl;
  -            impl = (SVGDOMImplementation)doc.getImplementation();
  -            eng = impl.createCSSEngine(doc, this);
  -            doc.setCSSEngine(eng);
  -            eng.setMedia(userAgent.getMedia());
  -            String uri = userAgent.getUserStyleSheetURI();
  -            if (uri != null) {
  -                try {
  -                    URL url = new URL(uri);
  -                    eng.setUserAgentStyleSheet
  -                        (eng.parseStyleSheet(url, "all"));
  -                } catch (MalformedURLException e) {
  -                    userAgent.displayError(e);
  -                }
  -            }
  -            eng.setAlternateStyleSheet(userAgent.getAlternateStyleSheet());
  +    public Map getFontFamilyMap(){
  +        if (fontFamilyMap == null){
  +            fontFamilyMap = new HashMap();
           }
  +        return fontFamilyMap;
  +    }
  +
  +    /**
  +     * Sets the map of font families to the specified value.
  +     *
  +     *@param fontFamilyMap the map of font families
  +     */
  +    protected void setFontFamilyMap(Map fontFamilyMap) {
  +        this.fontFamilyMap = fontFamilyMap;
  +    }
  +
  +    /**
  +     * Returns the user agent of this bridge context.
  +     */
  +    public UserAgent getUserAgent() {
  +        return userAgent;
       }
   
       /**
  @@ -324,17 +332,17 @@
       }
   
       /**
  -     * Sets the GVT builder that uses this context.
  +     * Returns the GVT builder that is currently used to build the GVT tree.
        */
  -    protected void setGVTBuilder(GVTBuilder gvtBuilder) {
  -        this.gvtBuilder = gvtBuilder;
  +    public GVTBuilder getGVTBuilder() {
  +        return gvtBuilder;
       }
   
       /**
  -     * Returns the GVT builder that is currently used to build the GVT tree.
  +     * Sets the GVT builder that uses this context.
        */
  -    public GVTBuilder getGVTBuilder() {
  -        return gvtBuilder;
  +    protected void setGVTBuilder(GVTBuilder gvtBuilder) {
  +        this.gvtBuilder = gvtBuilder;
       }
   
       /**
  @@ -345,6 +353,15 @@
       }
   
       /**
  +     * Sets the interpreter pool used to handle scripts to the
  +     * specified interpreter pool.
  +     * @param interpreterPool the interpreter pool
  +     */
  +    protected void setInterpreterPool(InterpreterPool interpreterPool) {
  +        this.interpreterPool = interpreterPool;
  +    }
  +
  +    /**
        * Returns a Interpreter for the specified language.
        *
        * @param language the scripting language
  @@ -362,15 +379,6 @@
       }
   
       /**
  -     * Sets the interpreter pool used to handle scripts to the
  -     * specified interpreter pool.
  -     * @param interpreterPool the interpreter pool
  -     */
  -    protected void setInterpreterPool(InterpreterPool interpreterPool) {
  -        this.interpreterPool = interpreterPool;
  -    }
  -
  -    /**
        * Returns the document loader used to load external documents.
        */
       public DocumentLoader getDocumentLoader() {
  @@ -385,7 +393,56 @@
           this.documentLoader = newDocumentLoader;
       }
   
  -    // convenient methods
  +    /**
  +     * Returns the actual size of the document or null if the document
  +     * has not been built yet.
  +     */
  +    public Dimension2D getDocumentSize() {
  +        return documentSize;
  +    }
  +
  +    /**
  +     * Sets the size of the document to the specified dimension.
  +     *
  +     * @param d the actual size of the SVG document
  +     */
  +    protected void setDocumentSize(Dimension2D d) {
  +        this.documentSize = d;
  +    }
  +
  +    /**
  +     * Returns true if the document is dynamic, false otherwise.
  +     */
  +    public boolean isDynamic() {
  +        return dynamic;
  +    }
  +
  +    /**
  +     * Sets the document as a dynamic document. Call this method
  +     * before the build phase (ie. before <tt>gvtBuilder.build(...)</tt>)
  +     * otherwise, that will have no effect.
  +     *
  +     *@param b the document state
  +     */
  +    public void setDynamic(boolean b) {
  +        dynamic = b;
  +    }
  +
  +    /**
  +     * Returns the update manager, if the bridge supports dynamic features.
  +     */
  +    public UpdateManager getUpdateManager() {
  +        return updateManager;
  +    }
  +
  +    /**
  +     * Sets the update manager.
  +     */
  +    protected void setUpdateManager(UpdateManager um) {
  +        updateManager = um;
  +    }
  +
  +    // reference management //////////////////////////////////////////////////
   
       /**
        * Returns the element referenced by the specified element by the
  @@ -419,27 +476,11 @@
           }
       }
   
  -    // methods to access to the current state of the bridge context
  -
  -    /**
  -     * Returns the actual size of the document or null if the document
  -     * has not been built yet.
  -     */
  -    public Dimension2D getDocumentSize() {
  -        return documentSize;
  -    }
  -
  -    /**
  -     * Sets the size of the document to the specified dimension.
  -     *
  -     * @param d the actual size of the SVG document
  -     */
  -    protected void setDocumentSize(Dimension2D d) {
  -        this.documentSize = d;
  -    }
  +    // Viewport //////////////////////////////////////////////////////////////
   
       /**
        * Returns the viewport of the specified element.
  +     *
        * @param e the element interested in its viewport
        */
       public Viewport getViewport(Element e) {
  @@ -468,7 +509,8 @@
   
       /**
        * Starts a new viewport from the specified element.
  -     * @param e the element that starts the viewport
  +     *
  +     * @param e the element that defines a new viewport
        * @param viewport the viewport of the element
        */
       public void openViewport(Element e, Viewport viewport) {
  @@ -491,41 +533,13 @@
           }
       }
   
  -    /**
  -     * Returns true if the bridge should support dynamic SVG content,
  -     * false otherwise.
  -     */
  -    public boolean isDynamic() {
  -        return dynamic;
  -    }
  -
  -    /**
  -     * Sets the dynamic mode.
  -     */
  -    public void setDynamic(boolean b) {
  -        dynamic = b;
  -    }
  -
  -    /**
  -     * Returns the update manager, if the bridge supports dynamic features.
  -     */
  -    public UpdateManager getUpdateManager() {
  -        return updateManager;
  -    }
  -
  -    /**
  -     * Sets the update manager.
  -     */
  -    protected void setUpdateManager(UpdateManager um) {
  -        updateManager = um;
  -    }
  -
  -    // binding methods
  +    // Bindings //////////////////////////////////////////////////////////////
   
       /**
        * Binds the specified GraphicsNode to the specified Element. This method
        * automatically bind the graphics node to the element and the element to
        * the graphics node.
  +     *
        * @param element the element to bind to the specified graphics node
        * @param node the graphics node to bind to the specified element
        */
  @@ -540,6 +554,7 @@
   
       /**
        * Removes the binding of the specified Element.
  +     *
        * @param element the element to unbind
        */
       public void unbind(Element element) {
  @@ -579,7 +594,7 @@
           }
       }
   
  -    // bridge support
  +    // Bridge management /////////////////////////////////////////////////////
    
       /**
        * Returns the bridge associated with the specified element.
  @@ -653,7 +668,7 @@
        * @param bridge the bridge that manages the element
        */
       public void putBridge(String namespaceURI, String localName, Bridge bridge) {
  -        // debug
  +        // start assert
           if (!(namespaceURI.equals(bridge.getNamespaceURI())
                 && localName.equals(bridge.getLocalName()))) {
               throw new Error("Invalid Bridge: "+
  @@ -661,7 +676,7 @@
                               localName+"/"+bridge.getLocalName()+" "+
                               bridge.getClass());
           }
  -
  +        // end assert
           if (namespaceURIMap == null) {
               namespaceURIMap = new HashMap();
           }
  @@ -708,11 +723,26 @@
           }
       }
   
  -    // dynamic support /////////////////////////////////////////////////////////
  +    // dynamic support ////////////////////////////////////////////////////////
   
  +    /**
  +     * The DOM EventListener to receive 'DOMAttrModified' event.
  +     */
       protected EventListener domAttrModifiedEventListener;
  +
  +    /**
  +     * The DOM EventListener to receive 'DOMNodeInserted' event.
  +     */
       protected EventListener domNodeInsertedEventListener;
  +
  +    /**
  +     * The DOM EventListener to receive 'DOMNodeRemoved' event.
  +     */
       protected EventListener domNodeRemovedEventListener;
  +
  +    /**
  +     * The CSSEngine listener to receive CSSEngineEvent.
  +     */
       protected CSSEngineListener cssPropertiesChangedListener;
   
       /**
  @@ -861,7 +891,7 @@
        * Returns a lighter font-weight.
        */
       public float getLighterFontWeight(float f) {
  -        // !!! TODO: delegates to the UserAgent.
  +        // <!> FIXME: delegates to the UserAgent.
           switch ((int)f) {
           case 100: return 100;
           case 200: return 100;
  @@ -881,7 +911,7 @@
        * Returns a bolder font-weight.
        */
       public float getBolderFontWeight(float f) {
  -        // !!! TODO: delegates to the UserAgent.
  +        // <!> FIXME: delegates to the UserAgent.
           switch ((int)f) {
           case 100: return 600;
           case 200: return 600;
  @@ -908,7 +938,7 @@
        * Returns the medium font size.
        */
       public float getMediumFontSize() {
  -        // !!! TODO: delegates to the UserAgent.
  +        // <!> FIXME: delegates to the UserAgent.
           return 9f * 25.4f / (72f * getPixelToMillimeters());
       }
   
  @@ -928,9 +958,11 @@
           return getViewport(elt).getHeight();
       }
   
  -    // bridge extensions support
  +    // bridge extensions support //////////////////////////////////////////////
  +
  +    protected static List extensions = null;
   
  -   /**
  +    /**
        * Registers the bridges to handle SVG 1.0 elements.
        *
        * @param ctx the bridge context to initialize
  @@ -938,15 +970,12 @@
       public static void registerSVGBridges(BridgeContext ctx) {
           UserAgent ua = ctx.getUserAgent();
           Iterator iter = getBridgeExtensions().iterator();
  -
           while(iter.hasNext()) {
               BridgeExtension be = (BridgeExtension)iter.next();
               be.registerTags(ctx);
               ua.registerExtension(be);
           }
       }
  -
  -    static List extensions = null;
   
       /**
        * Returns the extensions supported by this bridge context.
  
  
  
  1.12      +13 -9     xml-batik/sources/org/apache/batik/bridge/SVGFontUtilities.java
  
  Index: SVGFontUtilities.java
  ===================================================================
  RCS file: /home/cvs/xml-batik/sources/org/apache/batik/bridge/SVGFontUtilities.java,v
  retrieving revision 1.11
  retrieving revision 1.12
  diff -u -r1.11 -r1.12
  --- SVGFontUtilities.java     18 Mar 2002 10:28:19 -0000      1.11
  +++ SVGFontUtilities.java     21 Mar 2002 09:39:17 -0000      1.12
  @@ -8,28 +8,32 @@
   
   package org.apache.batik.bridge;
   
  -import org.apache.batik.util.SVGConstants;
  +import java.util.Map;
  +import java.util.StringTokenizer;
  +import java.util.Vector;
   
  -import org.apache.batik.gvt.font.GVTFontFamily;
  -import org.apache.batik.gvt.font.UnresolvedFontFamily;
  -import org.apache.batik.dom.util.XLinkSupport;
   import org.apache.batik.dom.svg.SVGOMDocument;
   import org.apache.batik.dom.svg.XMLBaseSupport;
   
  +import org.apache.batik.dom.util.XLinkSupport;
  +
  +import org.apache.batik.gvt.font.GVTFontFamily;
  +import org.apache.batik.gvt.font.UnresolvedFontFamily;
  +
  +import org.apache.batik.util.SVGConstants;
  +
   import org.w3c.dom.Document;
   import org.w3c.dom.Element;
   import org.w3c.dom.Node;
   import org.w3c.dom.NodeList;
  +
   import org.w3c.dom.svg.SVGDocument;
  -import java.util.HashMap;
  -import java.util.Vector;
  -import java.util.StringTokenizer;
   
   /**
    * Utility class for SVG fonts.
    *
    * @author <a href="mailto:[EMAIL PROTECTED]";>Bella Robinson</a>
  - * @version $Id: SVGFontUtilities.java,v 1.11 2002/03/18 10:28:19 hillion Exp $
  + * @version $Id: SVGFontUtilities.java,v 1.12 2002/03/21 09:39:17 tkormann Exp $
    */
   public abstract class SVGFontUtilities implements SVGConstants {
   
  @@ -64,7 +68,7 @@
   
           // check fontFamilyMap to see if we have already created an
           // FontFamily that matches
  -        HashMap fontFamilyMap = ctx.getFontFamilyMap();
  +        Map fontFamilyMap = ctx.getFontFamilyMap();
           GVTFontFamily fontFamily =
               (GVTFontFamily)fontFamilyMap.get(fontKeyName);
           if (fontFamily != null) {
  
  
  

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

Reply via email to