4xx / svg-edit

Automatically exported from code.google.com/p/svg-edit
MIT License
0 stars 0 forks source link

Add quadratic path segment handling, fix a null bug #1044

Open GoogleCodeExporter opened 9 years ago

GoogleCodeExporter commented 9 years ago
I like this project very much, but found some bugs, so post my solution.
Without these two patches, it may crash. 
Enjoy:

1.+++ svg-editor.js 
                    $('#stroke_style').val(selectedElement.getAttribute("stroke-dasharray")||"none");

                    var attr = selectedElement.getAttribute("stroke-linejoin") || 'miter';
+                                        if (attr == "null") {
+                                            attr = 'miter';
+                                        }

                    setStrokeOpt($('#linejoin_' + attr)[0]);

2.+++ svgcanvas.js

        8: ['x','y','x1','y1'],
        10: ['x','y','r1','r2','angle','largeArcFlag','sweepFlag'],
        12: ['x'],
-       14: ['y']
-   };
+       14: ['y'],
+       18: ['x','y']
+   }; //18 : T path. eg:  <path id="1" d="m283,347t-20,-3l0,9t0,0"

Original issue reported on code.google.com by askthe...@gmail.com on 5 Feb 2013 at 9:56

GoogleCodeExporter commented 9 years ago
Hi, may you tell us the problem that this patch solves?

Original comment by aldoluis...@gmail.com on 6 Feb 2013 at 5:24

GoogleCodeExporter commented 9 years ago
1 is just bug fix. In last version, var attr = 
selectedElement.getAttribute("stroke-linejoin") || 'miter'; means : if 
selectedElement.getAttribute returns null, attr should be assigned with 
'miter'. But when I run this js, I found selectedElement.getAttribute may 
return a string "null", and cause error. Maybe there are other bugs like this, 
I only tried some of this project.

2 is in svgcanvas.js:
// Group: Path edit functions
// Functions relating to editing path elements
var pathActions = this.pathActions = function() {

        var subpath = false;
        var pathData = {};
        var current_path;
        var path;
        var segData = {
                2: ['x','y'],
                4: ['x','y'],
                6: ['x','y','x1','y1','x2','y2'],
                8: ['x','y','x1','y1'],
                10: ['x','y','r1','r2','angle','largeArcFlag','sweepFlag'],
                12: ['x'],
                14: ['y'],
                18: ['x','y']

in last version without 18, if we load a svg file with <path id="1" 
d="m283,347t-20,-3l0,9t0,0" ..., and try to move this path by mouse, will cause 
error. Because there are "t"s in this path, which has 2 parameters.

Sorry for my poor English ..

Original comment by askthe...@gmail.com on 21 Feb 2013 at 9:38

GoogleCodeExporter commented 9 years ago
Hm, not sure why getAttribute() would return the string "null" that seems like 
a bug in some other part of our code.  But anyway, I think this patch looks 
good if someone cares to merge it...

Original comment by codedr...@gmail.com on 21 Feb 2013 at 6:53