lewisje / svgweb

Automatically exported from code.google.com/p/svgweb
Other
0 stars 0 forks source link

SVGTextNode.onDrawGlyph not removing glyph clones #494

Closed GoogleCodeExporter closed 8 years ago

GoogleCodeExporter commented 8 years ago
While testing some animations I noticed that animated (scale) SVG fonts left a 
trail of images for 
the animation.  The file can be found in svggen/animate-elem-03-t.svg.

I tracked the problem to onDrawGlyph() which loops through the children of the 
text node and 
removes old glyphs and makes new glyphs visible.

                for (var i:uint=0; i < this.svgChildren.length; i++) {
                    if (this.svgChildren[i] is SVGGlyphNode
                        && newGlyphs.indexOf(this.svgChildren[i]) == -1) {
                        removeSVGChild(this.svgChildren[i]);
                        i--;
                    }
                    else {
                        this.svgChildren[i].topSprite.visible=true;
                    }
                }

The first glyph in any text node is an SVGDOMTextNode which means the "else" in 
the loop is 
executed on the first iteration.  SVGDOMTextNodes don't have a topSprite so an 
exception is 
thrown and the loop is not completed.

I fixed the "if" so that only SVGGlyphNodes are affected

                    if (this.svgChildren[i] is SVGGlyphNode) {
                        if (newGlyphs.indexOf(this.svgChildren[i]) == -1) {
                            removeSVGChild(this.svgChildren[i]);
                            i--;
                        }
                        else {
                            this.svgChildren[i].topSprite.visible=true;
                        }
                    }

That fixed the glyph removal problem... but introduced another.  Calling 
removeSVGChild() 
results in a call to invalidateDisplay() which forces another draw cycle which 
eventually calls 
onDrawGlyph which does a removeSVGChild ...

Anyway, I replaced removeSVGChild with a cut down version - removeGlyphClone - 
which doesn't 
invalidate the display.  I'm not sure I got the cutting down correct but it 
seems to work.

Attached is a patch.

Original issue reported on code.google.com by k...@svgmaker.com on 27 May 2010 at 4:56

Attachments:

GoogleCodeExporter commented 8 years ago
Thanks a lot for the patch. That bug looks like one of those unforeseeable
interactions between multiple developers working on the same code that occurs 
once in
a while. That code precedes the existence of SVGDOMTextNode

Patch applied in r1138

Original comment by grick23@gmail.com on 28 May 2010 at 3:58