Mercurial > MadButterfly
comparison nodejs/svg.js @ 878:818e5bed913d abs_n_rel_center
Handle stroke-width and gradientTransform
author | Thinker K.F. Li <thinker@codemud.net> |
---|---|
date | Sat, 25 Sep 2010 16:17:49 +0800 |
parents | deadcca6e213 |
children | 44f46d6873be |
comparison
equal
deleted
inserted
replaced
877:deadcca6e213 | 878:818e5bed913d |
---|---|
225 } else if(_std_colors[color]) { | 225 } else if(_std_colors[color]) { |
226 c = _std_colors[color]; | 226 c = _std_colors[color]; |
227 paint = this.mb_rt.paint_color_new(c[0], c[1], c[2], alpha); | 227 paint = this.mb_rt.paint_color_new(c[0], c[1], c[2], alpha); |
228 } else if (color.substring(0,3) == 'url') { | 228 } else if (color.substring(0,3) == 'url') { |
229 var id = color.substring(5, color.length-1); | 229 var id = color.substring(5, color.length-1); |
230 var gr = this.gradients[id]; | 230 sys.puts(id); |
231 if(gr) { | 231 if(id in this.gradients) { |
232 var gr = this.gradients[id]; | |
233 sys.puts(gr); | |
232 paint = this.mb_rt.paint_linear_new(gr[0],gr[1],gr[2],gr[3]); | 234 paint = this.mb_rt.paint_linear_new(gr[0],gr[1],gr[2],gr[3]); |
233 } else { | 235 } else { |
234 var radial = this.radials[id]; | 236 var radial = this.radials[id]; |
235 paint = this.mb_rt.paint_radial_new(radial[0], | 237 paint = this.mb_rt.paint_radial_new(radial[0], |
236 radial[1], | 238 radial[1], |
237 radial[2]); | 239 radial[2]); |
238 } | 240 } |
239 paint.set_stops(this.stop_ref[id]); | 241 paint.set_stops(this.stop_ref[id]); |
242 sys.puts(this.stop_ref[id]); | |
240 } else { | 243 } else { |
241 paint = this.mb_rt.paint_color_new(0,0,0,1); | 244 paint = this.mb_rt.paint_color_new(0,0,0,1); |
242 } | 245 } |
243 return paint; | 246 return paint; |
244 }; | 247 }; |
633 var fill_alpha = 1; | 636 var fill_alpha = 1; |
634 var stroke_alpha = 1; | 637 var stroke_alpha = 1; |
635 var alpha = 1; | 638 var alpha = 1; |
636 var fill_color; | 639 var fill_color; |
637 var stroke_color; | 640 var stroke_color; |
641 var stroke_width = 1; | |
638 var black_paint; | 642 var black_paint; |
639 var i; | 643 var i; |
640 | 644 |
641 style = parse_style(node); | 645 style = parse_style(node); |
642 if(style) { | 646 if(style) { |
673 paint.stroke(tgt); | 677 paint.stroke(tgt); |
674 } | 678 } |
675 } else { | 679 } else { |
676 black_paint.stroke(tgt); | 680 black_paint.stroke(tgt); |
677 } | 681 } |
682 | |
683 tgt.stroke_width = stroke_width; | |
678 }; | 684 }; |
679 | 685 |
680 loadSVG.prototype.parsePath=function(accu, coord,id, n) | 686 loadSVG.prototype.parsePath=function(accu, coord,id, n) |
681 { | 687 { |
682 var d = n.attr('d').value(); | 688 var d = n.attr('d').value(); |
991 loadSVG.prototype._MB_parseLinearGradient=function(root,n) | 997 loadSVG.prototype._MB_parseLinearGradient=function(root,n) |
992 { | 998 { |
993 var id = n.attr('id'); | 999 var id = n.attr('id'); |
994 var k; | 1000 var k; |
995 var nodes = n.childNodes(); | 1001 var nodes = n.childNodes(); |
1002 var mtx = [1, 0, 0, 0, 1, 0]; | |
996 | 1003 |
997 if (id == null) return; | 1004 if (id == null) return; |
998 id = id.value(); | 1005 id = id.value(); |
999 | 1006 |
1000 var x1 = n.attr("x1"); | 1007 var x1 = n.attr("x1"); |
1001 var y1 = n.attr("y1"); | 1008 var y1 = n.attr("y1"); |
1002 var x2 = n.attr("x2"); | 1009 var x2 = n.attr("x2"); |
1003 var y2 = n.attr("y2"); | 1010 var y2 = n.attr("y2"); |
1011 var xy; | |
1004 var gr; | 1012 var gr; |
1005 var color, opacity; | 1013 var color, opacity; |
1006 var stops; | 1014 var stops; |
1007 var r,g,b; | 1015 var r,g,b; |
1008 | 1016 |
1032 if(typeof x2 == "undefined") | 1040 if(typeof x2 == "undefined") |
1033 x2 = hrefgr[2]; | 1041 x2 = hrefgr[2]; |
1034 if(typeof y2 == "undefined") | 1042 if(typeof y2 == "undefined") |
1035 y2 = hrefgr[3]; | 1043 y2 = hrefgr[3]; |
1036 } | 1044 } |
1045 | |
1046 if(n.attr('gradientTransform')) { | |
1047 parseTransform(mtx, n.attr('gradientTransform').value()); | |
1048 xy = _pnt_transform(x1, y1, mtx); | |
1049 x1 = xy[0]; | |
1050 y1 = xy[1]; | |
1051 xy = _pnt_transform(x2, y2, mtx); | |
1052 x2 = xy[0]; | |
1053 y2 = xy[1]; | |
1054 } | |
1055 | |
1037 this.stop_ref[id] = stops; | 1056 this.stop_ref[id] = stops; |
1038 this.gradients[id] = [x1,y1,x2,y2]; | 1057 this.gradients[id] = [x1,y1,x2,y2]; |
1039 }; | 1058 }; |
1040 | 1059 |
1041 loadSVG.prototype._MB_parseRadialGradient = function(root,n) { | 1060 loadSVG.prototype._MB_parseRadialGradient = function(root,n) { |
1042 var stops; | 1061 var stops; |
1043 var cx, cy; | 1062 var cx, cy; |
1063 var xy; | |
1064 var mtx = [1, 0, 0, 0, 1, 0]; | |
1044 var id; | 1065 var id; |
1045 var href; | 1066 var href; |
1046 var r; | 1067 var r; |
1047 | 1068 |
1048 id = n.attr("id"); | 1069 id = n.attr("id"); |
1070 if(href) { | 1091 if(href) { |
1071 href = href.value().substring(1); | 1092 href = href.value().substring(1); |
1072 stops = this.stop_ref[href]; | 1093 stops = this.stop_ref[href]; |
1073 } | 1094 } |
1074 | 1095 |
1096 if(n.attr('gradientTransform')) { | |
1097 parseTransform(mtx, n.attr('gradientTransform').value()); | |
1098 xy = _pnt_transform(cx, cy, mtx); | |
1099 cx = xy[0]; | |
1100 cy = xy[1]; | |
1101 } | |
1102 | |
1075 this.radials[id] = [cx, cy, r]; | 1103 this.radials[id] = [cx, cy, r]; |
1076 this.stop_ref[id] = stops; | 1104 this.stop_ref[id] = stops; |
1077 } | 1105 } |
1078 | 1106 |
1079 loadSVG.prototype.parseDefs=function(root,n) | 1107 loadSVG.prototype.parseDefs=function(root,n) |