xmlgraphics-batik-dev mailing list archives

Site index · List index
Message view « Date » · « Thread »
Top « Date » · « Thread »
From dewe...@apache.org
Subject cvs commit: xml-batik/sources/org/apache/batik/util SoftReferenceCache.java
Date Sun, 06 Feb 2005 00:58:48 GMT
deweese     2005/02/05 16:58:48

  Modified:    .        build.xml
               sources/org/apache/batik/bridge SVGTextElementBridge.java
                        SVGUtilities.java ScriptingEnvironment.java
               sources/org/apache/batik/dom/events EventListenerList.java
               sources/org/apache/batik/dom/svg
                        SVGOMAnimatedPreserveAspectRatio.java
               sources/org/apache/batik/gvt CompositeGraphicsNode.java
               sources/org/apache/batik/gvt/text GlyphLayout.java
               sources/org/apache/batik/util SoftReferenceCache.java
  Log:
  1) textPath no longer supports 'position attributes' on it's self
  2) textPath now supports progression position attributes provided
     by parent/child tspan/text nodes.
  3) systemLanguage, requiredFeatures, requiredExtensions now all fail
     to match when given an empty string (as specified by the SVG
     specification). Bug #33242 (thanks Rick Graham).
  4) Fixed potential synchronization issues in JavaScript intervals.
  5) Small optimization in Event dispatch.
  6) Removed debug print from SVGOMAnimatedPreserveAspectRatio.java
  7) Potentially large optimization in BBox generation
  8) Synchronization fix in SoftReferenceCache.
  
  PR: 33242
  
  Revision  Changes    Path
  1.155     +5 -3      xml-batik/build.xml
  
  Index: build.xml
  ===================================================================
  RCS file: /home/cvs/xml-batik/build.xml,v
  retrieving revision 1.154
  retrieving revision 1.155
  diff -u -r1.154 -r1.155
  --- build.xml	18 Nov 2004 01:46:49 -0000	1.154
  +++ build.xml	6 Feb 2005 00:58:47 -0000	1.155
  @@ -953,8 +953,10 @@
     <!-- Applications ....................................................... -->
     <target name="squiggle" depends="compile"
             description="Runs Squiggle - the SVG browser">
  -    <java fork="yes"
  -          classname="${class-prefix}.apps.svgbrowser.Main">
  +    <java fork="yes" 
  +          classname="${class-prefix}.apps.svgbrowser.Main"
  +<!--      jvm="C:\Documents and Settings\<user>\.netbeans\4.0\modules\profiler-ea-vm\jre\bin\java"
 -->
  +          >
         <classpath>
           <pathelement location="${dest}" />
           <path refid="libs-classpath"/>
  
  
  
  1.103     +7 -1      xml-batik/sources/org/apache/batik/bridge/SVGTextElementBridge.java
  
  Index: SVGTextElementBridge.java
  ===================================================================
  RCS file: /home/cvs/xml-batik/sources/org/apache/batik/bridge/SVGTextElementBridge.java,v
  retrieving revision 1.102
  retrieving revision 1.103
  diff -u -r1.102 -r1.103
  --- SVGTextElementBridge.java	3 Jan 2005 10:48:05 -0000	1.102
  +++ SVGTextElementBridge.java	6 Feb 2005 00:58:47 -0000	1.103
  @@ -1154,6 +1154,12 @@
               (!CSSUtilities.convertDisplay(element))) {
               return;
           }
  +        if (element.getLocalName().equals(SVG_TEXT_PATH_TAG)) {
  +            // 'textPath' doesn't support position attributes.
  +            addChildGlyphPositionAttributes(as, element, ctx);
  +            return;
  +        }
  +
           AttributedCharacterIterator aci = as.getIterator();
   
           // calculate which chars in the string belong to this element
  
  
  
  1.31      +11 -5     xml-batik/sources/org/apache/batik/bridge/SVGUtilities.java
  
  Index: SVGUtilities.java
  ===================================================================
  RCS file: /home/cvs/xml-batik/sources/org/apache/batik/bridge/SVGUtilities.java,v
  retrieving revision 1.30
  retrieving revision 1.31
  diff -u -r1.30 -r1.31
  --- SVGUtilities.java	18 Nov 2004 01:46:54 -0000	1.30
  +++ SVGUtilities.java	6 Feb 2005 00:58:47 -0000	1.31
  @@ -168,6 +168,8 @@
               // Tests the system languages.
               String sl = elt.getAttributeNS(null,
                                              SVG_SYSTEM_LANGUAGE_ATTRIBUTE);
  +            if (sl.length() == 0) // SVG spec says empty returns false
  +                return false;
               StringTokenizer st = new StringTokenizer(sl, ", ");
               while (st.hasMoreTokens()) {
                   String s = st.nextToken();
  @@ -179,9 +181,11 @@
           }
           if (elt.hasAttributeNS(null, SVG_REQUIRED_FEATURES_ATTRIBUTE)) {
               // Tests the system features.
  -            String sf = elt.getAttributeNS(null,
  +            String rf = elt.getAttributeNS(null,
                                              SVG_REQUIRED_FEATURES_ATTRIBUTE);
  -            StringTokenizer st = new StringTokenizer(sf, " ");
  +            if (rf.length() == 0)  // SVG spec says empty returns false
  +                return false;
  +            StringTokenizer st = new StringTokenizer(rf, " ");
               while (st.hasMoreTokens()) {
                   String s = st.nextToken();
                   if (!ua.hasFeature(s)) {
  @@ -191,9 +195,11 @@
           }
           if (elt.hasAttributeNS(null, SVG_REQUIRED_EXTENSIONS_ATTRIBUTE)) {
               // Tests the system features.
  -            String sf = elt.getAttributeNS(null,
  +            String re = elt.getAttributeNS(null,
                                              SVG_REQUIRED_EXTENSIONS_ATTRIBUTE);
  -            StringTokenizer st = new StringTokenizer(sf, " ");
  +            if (re.length() == 0)  // SVG spec says empty returns false
  +                return false;
  +            StringTokenizer st = new StringTokenizer(re, " ");
               while (st.hasMoreTokens()) {
                   String s = st.nextToken();
                   if (!ua.supportExtension(s)) {
  
  
  
  1.47      +36 -20    xml-batik/sources/org/apache/batik/bridge/ScriptingEnvironment.java
  
  Index: ScriptingEnvironment.java
  ===================================================================
  RCS file: /home/cvs/xml-batik/sources/org/apache/batik/bridge/ScriptingEnvironment.java,v
  retrieving revision 1.46
  retrieving revision 1.47
  diff -u -r1.46 -r1.47
  --- ScriptingEnvironment.java	18 Nov 2004 01:46:54 -0000	1.46
  +++ ScriptingEnvironment.java	6 Feb 2005 00:58:47 -0000	1.47
  @@ -634,20 +634,27 @@
               script = s;
           }
           public void run() {
  -            if (error) {
  -                return;
  +            synchronized (this) {
  +                if (error)
  +                    return;
  +                count--;
               }
  -            count--;
               try {
                   interpreter.evaluate(script);
               } catch (InterpreterException ie) {
                   handleInterpreterException(ie);
  -                error = true;
  +                synchronized (this) {
  +                    error = true;
  +                }
               } catch (Exception e) {
                   if (userAgent != null) {
                       userAgent.displayError(e);
  +                } else {
  +                    e.printStackTrace(); // No UA so just output...
  +                }
  +                synchronized (this) {
  +                    error = true;
                   }
  -                error = true;
               }
           }
       }
  @@ -668,17 +675,22 @@
               runnable = r;
           }
           public void run() {
  -            if (error) {
  -                return;
  +            synchronized (this) {
  +                if (error)
  +                    return;
  +                count--;
               }
  -            count--;
               try {
                   runnable.run();
               } catch (Exception e) {
                   if (userAgent != null) {
                       userAgent.displayError(e);
  +                } else {
  +                    e.printStackTrace(); // No UA so just output...
  +                }
  +                synchronized (this) { 
  +                    error = true;
                   }
  -                error = true;
               }
           }
       }
  @@ -715,10 +727,11 @@
                       EvaluateIntervalRunnable eir =
                           new EvaluateIntervalRunnable(script, interpreter);
                       public void run() {
  -                        if (eir.count > 1) {
  -                            return;
  +                        synchronized (eir) {
  +                            if (eir.count > 1)
  +                                return;
  +                            eir.count++;
                           }
  -                        eir.count++;
                           synchronized (updateRunnableQueue.getIteratorLock()) {
                               if (updateRunnableQueue.getThread() == null) {
                                   cancel();
  @@ -726,8 +739,9 @@
                               }
                               updateRunnableQueue.invokeLater(eir);
                           }
  -                        if (eir.error) {
  -                            cancel();
  +                        synchronized (eir) {
  +                            if (eir.error)
  +                                cancel();
                           }
                       }
                   };
  @@ -745,13 +759,15 @@
                       EvaluateRunnableRunnable eihr =
                           new EvaluateRunnableRunnable(r);
                       public void run() {
  -                        if (eihr.count > 1) {
  -                            return;
  +                        synchronized (eihr) {
  +                            if (eihr.count > 1)
  +                                return;
  +                            eihr.count++;
                           }
  -                        eihr.count++;
                           updateRunnableQueue.invokeLater(eihr);
  -                        if (eihr.error) {
  -                            cancel();
  +                        synchronized (eihr) {
  +                            if (eihr.error)
  +                                cancel();
                           }
                       }
                   };
  
  
  
  1.6       +35 -18    xml-batik/sources/org/apache/batik/dom/events/EventListenerList.java
  
  Index: EventListenerList.java
  ===================================================================
  RCS file: /home/cvs/xml-batik/sources/org/apache/batik/dom/events/EventListenerList.java,v
  retrieving revision 1.5
  retrieving revision 1.6
  diff -u -r1.5 -r1.6
  --- EventListenerList.java	18 Aug 2004 07:13:12 -0000	1.5
  +++ EventListenerList.java	6 Feb 2005 00:58:48 -0000	1.6
  @@ -27,17 +27,30 @@
    */
   public class EventListenerList {
   
  -    private Entry first;
  -    private int n = 0;
  +    /**
  +     * Current number of entries in list.
  +     */
  +    protected int              n         = 0;
  +    /**
  +     * Simple Linked list of listeners.
  +     */
  +    protected Entry            first     = null;
  +    /**
  +     * Array of listeners retained between calls to getEventListeners if the
  +     * list of listeners doesn't change.  This needs to be a copy so if the
  +     * list of listeners changes during event dispatch it doesn't effect
  +     * the inprogress dispatch.
  +     */
  +    protected EventListener [] listeners = null;
   
       /**
        * Returns an array of the event listeners of this list, or null if any.
        */
       public EventListener [] getEventListeners() {
  -	if (first == null) {
  -	    return null;
  -	}
  -	EventListener [] listeners = new EventListener[n];
  +	if (first == null)     return null;
  +        if (listeners != null) return listeners;
  +
  +	listeners = new EventListener[n];
   	Entry current = first;
   	for (int i=0; i < n; ++i, current = current.next) {
   	    listeners[i] = current.listener;
  @@ -51,6 +64,7 @@
        */
       public void add(EventListener listener) {
   	first = new Entry(listener, first);
  +        listeners = null; // Clear current listener list.
   	n++;
       }
   
  @@ -59,22 +73,26 @@
        * @param listener the event listener to remove
        */
       public void remove(EventListener listener) {
  -	if (first == null) {
  -	    return;
  -	} else if (first.listener == listener) {
  +	if (first == null) return;
  +
  +
  +        if (first.listener == listener) {
   	    first = first.next;
  +            listeners = null; // Clear current listener list.
   	    --n;
   	} else {
   	    Entry prev = first;
   	    Entry e = first.next;
  -	    while (e != null && e.listener != listener) {
  +	    while (e != null) {
  +                if (e.listener == listener) {
  +                    prev.next = e.next;
  +                    listeners = null; // Clear current listener list.
  +                    --n;
  +                    break;
  +                }
   		prev = e;
   		e = e.next;
   	    }
  -	    if (e != null) {
  -		prev.next = e.next;
  -		--n;
  -	    }
   	}
       }
   
  @@ -85,9 +103,8 @@
        */
       public boolean contains(EventListener listener) {
   	for (Entry e=first; e != null; e = e.next) {
  -	    if (listener == e.listener) {
  +	    if (listener == e.listener)
   		return true;
  -	    }
   	}
   	return false;
       }
  @@ -100,9 +117,9 @@
       }
   
       // simple entry for the list
  -    private static class Entry {
  +    protected static class Entry {
   	EventListener listener;
  -	Entry next;
  +	Entry         next;
   
   	public Entry(EventListener listener, Entry next) {
   	    this.listener = listener;
  
  
  
  1.2       +1 -1      xml-batik/sources/org/apache/batik/dom/svg/SVGOMAnimatedPreserveAspectRatio.java
  
  Index: SVGOMAnimatedPreserveAspectRatio.java
  ===================================================================
  RCS file: /home/cvs/xml-batik/sources/org/apache/batik/dom/svg/SVGOMAnimatedPreserveAspectRatio.java,v
  retrieving revision 1.1
  retrieving revision 1.2
  diff -u -r1.1 -r1.2
  --- SVGOMAnimatedPreserveAspectRatio.java	1 Sep 2004 09:35:22 -0000	1.1
  +++ SVGOMAnimatedPreserveAspectRatio.java	6 Feb 2005 00:58:48 -0000	1.2
  @@ -63,7 +63,7 @@
       public void attrAdded(Attr node, String newv) {
           if (!changing) {
               preserveAspectRatio.setValueAsString(newv);
  -            System.out.println("attr added: " + newv);
  +            // System.out.println("attr added: " + newv);
           }
       }
       
  
  
  
  1.41      +47 -1     xml-batik/sources/org/apache/batik/gvt/CompositeGraphicsNode.java
  
  Index: CompositeGraphicsNode.java
  ===================================================================
  RCS file: /home/cvs/xml-batik/sources/org/apache/batik/gvt/CompositeGraphicsNode.java,v
  retrieving revision 1.40
  retrieving revision 1.41
  diff -u -r1.40 -r1.41
  --- CompositeGraphicsNode.java	30 Nov 2004 03:23:58 -0000	1.40
  +++ CompositeGraphicsNode.java	6 Feb 2005 00:58:48 -0000	1.41
  @@ -221,6 +221,36 @@
       }
   
       /**
  +     * Transforms a Rectangle 2D by an affine transform.  It assumes the transform
  +     * is only scale/translate so there is no loss of precision over transforming
  +     * the source geometry.
  +     */
  +    public static Rectangle2D  getTransformedBBox(Rectangle2D r2d, AffineTransform t) {
  +        if ((t  == null) || (r2d == null)) return r2d;
  +
  +        double x  = r2d.getX();
  +        double w  = r2d.getWidth();
  +        double y  = r2d.getY();
  +        double h  = r2d.getHeight();
  +
  +        double sx = t.getScaleX();
  +        double sy = t.getScaleY();
  +        if (sx < 0) {
  +            x = -(x + w);
  +            sx = -sx;
  +        }
  +        if (sy < 0) {
  +            y = -(y + h);
  +            sy = -sy;
  +        }
  +
  +        return new Rectangle2D.Float
  +            ((float)(x*sx+t.getTranslateX()), 
  +             (float)(y*sy+t.getTranslateY()),
  +             (float)(w*sx), (float)(h*sy));
  +    }
  +
  +    /**
        * Returns the bounds of this node's primitivePaint after applying
        * the input transform (if any), concatenated with this node's
        * transform (if any).
  @@ -233,6 +263,12 @@
               t = new AffineTransform(txf);
               t.concatenate(transform);
           }
  +
  +        if ((t == null) || ((t.getShearX() == 0) && (t.getShearY() == 0))) {
  +            // No rotation it's safe to simply transform our bounding box.
  +            return getTransformedBBox(getPrimitiveBounds(), t);
  +        }
  +	
           int i = 0;
           Rectangle2D tpb = null;
           while (tpb == null && i < count) {
  @@ -299,6 +335,11 @@
               t = new AffineTransform(txf);
               t.concatenate(transform);
           }
  +
  +        if ((t == null) || ((t.getShearX() == 0) && (t.getShearY() == 0))) {
  +            // No rotation it's safe to simply transform our bounding box.
  +            return getTransformedBBox(getGeometryBounds(), t);
  +        }
   	
           Rectangle2D gb = null;
           int i=0;
  @@ -366,6 +407,11 @@
               t.concatenate(transform);
           }
   	
  +        if ((t == null) || ((t.getShearX() == 0) && (t.getShearY() == 0))) {
  +            // No rotation it's safe to simply transform our bounding box.
  +            return getTransformedBBox(getSensitiveBounds(), t);
  +        }
  +	
           Rectangle2D sb = null;
           int i=0;
           while (sb == null && i < count) {
  
  
  
  1.62      +52 -37    xml-batik/sources/org/apache/batik/gvt/text/GlyphLayout.java
  
  Index: GlyphLayout.java
  ===================================================================
  RCS file: /home/cvs/xml-batik/sources/org/apache/batik/gvt/text/GlyphLayout.java,v
  retrieving revision 1.61
  retrieving revision 1.62
  diff -u -r1.61 -r1.62
  --- GlyphLayout.java	18 Nov 2004 01:47:00 -0000	1.61
  +++ GlyphLayout.java	6 Feb 2005 00:58:48 -0000	1.62
  @@ -1133,44 +1133,47 @@
   
               GVTGlyphMetrics gm = gv.getGlyphMetrics(i);
   
  -            if (i==0) {
  -                if (isVertical()) {
  -                    if (glyphOrientationAuto) {
  -                        if (isLatinChar(ch)) {
  -                            // it will be rotated 90
  -                            verticalFirstOffset = 0f;
  +            if (textPath == null) {
  +                // Don't adjust the location of the first
  +                // glyph when doing layout on a text path.
  +                if (i==0) {
  +                    if (isVertical()) {
  +                        if (glyphOrientationAuto) {
  +                            if (isLatinChar(ch)) {
  +                                // it will be rotated 90
  +                                verticalFirstOffset = 0f;
  +                            } else {
  +                                // it won't be rotated
  +                                verticalFirstOffset = 
  +                                    (float)gm.getBounds2D().getHeight();
  +                            }
                           } else {
  -                            // it won't be rotated
  -                            verticalFirstOffset = 
  -                                (float)gm.getBounds2D().getHeight();
  +                            if (glyphOrientationAngle == 0) {
  +                                verticalFirstOffset = 
  +                                    (float)gm.getBounds2D().getHeight();
  +                            } else {
  +                                // 90, 180, 270
  +                                verticalFirstOffset = 0f;
  +                            }
                           }
                       } else {
  -                        if (glyphOrientationAngle == 0) {
  -                            verticalFirstOffset = 
  +                        if ((glyphOrientationAngle == 270)) {
  +                            horizontalFirstOffset = 
                                   (float)gm.getBounds2D().getHeight();
                           } else {
  -                            // 90, 180, 270
  -                            verticalFirstOffset = 0f;
  +                            // 0, 90, 180
  +                            horizontalFirstOffset = 0;
                           }
                       }
                   } else {
  -                    if ((glyphOrientationAngle == 270)) {
  -                        horizontalFirstOffset = 
  +                    if (glyphOrientationAuto && 
  +                        (verticalFirstOffset == 0f)
  +                        && !isLatinChar(ch)) {
  +                        verticalFirstOffset = 
                               (float)gm.getBounds2D().getHeight();
  -                    } else {
  -                        // 0, 90, 180
  -                        horizontalFirstOffset = 0;
                       }
                   }
  -            } else {
  -                if (glyphOrientationAuto && 
  -                    (verticalFirstOffset == 0f)
  -                    && !isLatinChar(ch)) {
  -
  -                    verticalFirstOffset = (float)gm.getBounds2D().getHeight();
  -                }
               }
  -
               // ox and oy are origin adjustments for each glyph,
               // computed on the basis of baseline-shifts, etc.
               float ox = 0f;
  @@ -1795,22 +1798,18 @@
           }
   
           // the current start point of the character on the path
  -        float currentPosition;
  -        if (horizontal) {
  -            currentPosition = (float)offset.getX() + startOffset;
  -        } else {
  -            currentPosition = (float)offset.getY() + startOffset;
  -        }
  -
           // calculate the offset of the first glyph the offset will be
           // 0 if the glyph is on the path (ie. not adjusted by a dy or
           // dx)
           Point2D firstGlyphPosition = gv.getGlyphPosition(0);
           float glyphOffset = 0;   // offset perpendicular to path
  +        float currentPosition;
           if (horizontal) {
  -            glyphOffset = (float)(firstGlyphPosition.getY());
  +            glyphOffset     = (float)(firstGlyphPosition.getY());
  +            currentPosition = (float)(firstGlyphPosition.getX() + startOffset);
           } else {
  -            glyphOffset = (float)(firstGlyphPosition.getX());
  +            glyphOffset     = (float)(firstGlyphPosition.getX());
  +            currentPosition = (float)(firstGlyphPosition.getY() + startOffset);
           }
   
           char ch = aci.first();
  @@ -1844,7 +1843,7 @@
                   }
               } else {
                   // last glyph, use the glyph metrics
  -                GVTGlyphMetrics gm = gv.getGlyphMetrics(i);
  +                GVTGlyphMetrics gm           = gv.getGlyphMetrics(i);
                   if (horizontal) {
                       if ((glyphOrientationAngle == 0) ||
                           (glyphOrientationAngle == 180)) {
  @@ -1880,6 +1879,22 @@
                   charMidPos = currentPosition + glyphWidth / 2f;
               } else {
                   charMidPos = currentPosition + glyphHeight / 2f;
  +                /*
  +                if (glyphOrientationAuto) {
  +                    if (isLatinChar(ch)) {
  +                        charMidPos = currentPosition + glyphWidth / 2f;
  +                    } else {
  +                        charMidPos = currentPosition + glyphHeight / 2f;
  +                    }
  +                } else {
  +                    if ((glyphOrientationAngle ==   0) ||
  +                        (glyphOrientationAngle == 180)) {
  +                        charMidPos = currentPosition + glyphHeight / 2f;
  +                    } else  {
  +                        charMidPos = currentPosition + glyphWidth / 2f;
  +                    }
  +                }
  +                */
               }
   
               // Calculate the actual point to place the glyph around
  
  
  
  1.9       +7 -1      xml-batik/sources/org/apache/batik/util/SoftReferenceCache.java
  
  Index: SoftReferenceCache.java
  ===================================================================
  RCS file: /home/cvs/xml-batik/sources/org/apache/batik/util/SoftReferenceCache.java,v
  retrieving revision 1.8
  retrieving revision 1.9
  diff -u -r1.8 -r1.9
  --- SoftReferenceCache.java	18 Aug 2004 07:15:50 -0000	1.8
  +++ SoftReferenceCache.java	6 Feb 2005 00:58:48 -0000	1.9
  @@ -174,10 +174,16 @@
               if (cache == null) return; // Can't really happen.
               synchronized (cache) {
                   Object o = cache.map.remove(key);
  -                if (this != o)
  +                if (this == o) {
  +                    // Notify other threads that they may have
  +                    // to provide this resource now.
  +                    cache.notifyAll(); 
  +                } else {
                       // Must not have been ours put it back...
                       // Can happen if a clear is done.
                       cache.map.put(key, o);
  +                }
  + 
               }
           }
       }
  
  
  

---------------------------------------------------------------------
To unsubscribe, e-mail: batik-dev-unsubscribe@xml.apache.org
For additional commands, e-mail: batik-dev-help@xml.apache.org


Mime
View raw message