Mercurial > MadButterfly
comparison nodejs/svg.js @ 880:ac3e8492ad74 abs_n_rel_center
Formalize path data for MadButterfly.
Inkscape and other editors would omit 'l' or 'L' after 'm' or 'M'.
MadButterfly can not handle it, now. So, we work around it at SVG
parser.
author | Thinker K.F. Li <thinker@codemud.net> |
---|---|
date | Sat, 25 Sep 2010 18:46:37 +0800 |
parents | 44f46d6873be |
children | a17c4e231e54 |
comparison
equal
deleted
inserted
replaced
879:44f46d6873be | 880:ac3e8492ad74 |
---|---|
701 } | 701 } |
702 | 702 |
703 tgt.stroke_width = stroke_width; | 703 tgt.stroke_width = stroke_width; |
704 }; | 704 }; |
705 | 705 |
706 function formalize_path_data(d) { | |
707 var posM, posm; | |
708 var pos; | |
709 var nums = "0123456789+-."; | |
710 var rel = false; | |
711 var cmd; | |
712 | |
713 posM = d.search("M"); | |
714 posm = d.search("m"); | |
715 pos = posm < posM? posm: posM; | |
716 if(pos == -1) | |
717 pos = posM == -1? posm: posM; | |
718 if(pos == -1) | |
719 return d; | |
720 | |
721 if(posm == pos) | |
722 rel = true; | |
723 | |
724 pos = pos + 1; | |
725 while(pos < d.length && " ,".search(d[pos]) >= 0) | |
726 pos++; | |
727 while(pos < d.length && nums.search(d[pos]) >= 0) | |
728 pos++; | |
729 while(pos < d.length && " ,".search(d[pos]) >= 0) | |
730 pos++; | |
731 while(pos < d.length && nums.search(d[pos]) >= 0) | |
732 pos++; | |
733 while(pos < d.length && " ,".search(d[pos]) >= 0) | |
734 pos++; | |
735 if(nums.search(d[pos]) >= 0) { | |
736 if(rel) | |
737 cmd = "l"; | |
738 else | |
739 cmd = "L"; | |
740 d = d.substring(0, pos) + cmd + formalize_path_data(d.substring(pos)); | |
741 } | |
742 return d; | |
743 } | |
744 | |
706 loadSVG.prototype.parsePath=function(accu, coord,id, n) | 745 loadSVG.prototype.parsePath=function(accu, coord,id, n) |
707 { | 746 { |
708 var d = n.attr('d').value(); | 747 var d = formalize_path_data(n.attr('d').value()); |
709 var style = n.attr('style'); | 748 var style = n.attr('style'); |
710 var path = this.mb_rt.path_new(d); | 749 var path = this.mb_rt.path_new(d); |
711 | 750 |
712 guessPathBoundingBox(coord,d); | 751 guessPathBoundingBox(coord,d); |
713 coord.add_shape(path); | 752 coord.add_shape(path); |
714 this._set_paint(n, path); | 753 this._set_paint(n, path); |
715 this._set_bbox(n, path); | 754 this._set_bbox(n, path); |
716 | 755 |