comparison nodejs/svg.js @ 717:b822b1912d67

Paint with black for unspecified, not "none", fill and stroke.
author Thinker K.F. Li <thinker@branda.to>
date Sat, 14 Aug 2010 23:52:43 +0800
parents f53e45d1fcd0
children 0cd59ce76e67
comparison
equal deleted inserted replaced
716:72abb4154936 717:b822b1912d67
125 var paint; 125 var paint;
126 var c; 126 var c;
127 127
128 if (color[0]=='#') { 128 if (color[0]=='#') {
129 var r,g,b; 129 var r,g,b;
130 r = parseInt(color.substring(1,3),16)/256; 130 r = parseInt(color.substring(1,3),16)/255;
131 g = parseInt(color.substring(3,5),16)/256; 131 g = parseInt(color.substring(3,5),16)/255;
132 b = parseInt(color.substring(5,7),16)/256; 132 b = parseInt(color.substring(5,7),16)/255;
133 paint = this.mb_rt.paint_color_new(r, g, b, alpha); 133 paint = this.mb_rt.paint_color_new(r, g, b, alpha);
134 } else if(_std_colors[color]) { 134 } else if(_std_colors[color]) {
135 c = _std_colors[color]; 135 c = _std_colors[color];
136 paint = this.mb_rt.paint_color_new(c[0], c[1], c[2], alpha); 136 paint = this.mb_rt.paint_color_new(c[0], c[1], c[2], alpha);
137 } else { 137 } else {
144 { 144 {
145 var d = n.attr('d').value(); 145 var d = n.attr('d').value();
146 var style = n.attr('style'); 146 var style = n.attr('style');
147 var path = this.mb_rt.path_new(d); 147 var path = this.mb_rt.path_new(d);
148 var paint; 148 var paint;
149 149 var fill_alpha = 1;
150 if (style==null) { 150 var stroke_alpha = 1;
151 paint = this.mb_rt.paint_color_new(0,0,0,1); 151 var fill_color;
152 paint.fill(path); 152 var stroke_color;
153 } else { 153 var black_paint;
154
155 if(style != null) {
154 var items = style.value().split(';'); 156 var items = style.value().split(';');
155 var fill_alpha = 1;
156 var stroke_alpha = 1;
157 var fill_color;
158 var stroke_color;
159 var alpha; 157 var alpha;
160 158
161 for(i in items) { 159 for(i in items) {
162 sys.puts(items[i]); 160 sys.puts(items[i]);
163 var f = items[i].split(':'); 161 var f = items[i].split(':');
164 if (f[0] == 'opacity') { 162 if (f[0] == 'opacity') {
165 alpha = f[1]; 163 alpha = f[1];
166 } else if (f[0] == 'fill') { 164 } else if (f[0] == 'fill') {
167 if(f[1] != "none") 165 fill_color = f[1];
168 fill_color = f[1];
169 } else if (f[0] == 'fill-opacity') { 166 } else if (f[0] == 'fill-opacity') {
170 fill_alpha = parseFloat(f[1]); 167 fill_alpha = parseFloat(f[1]);
171 } else if (f[0] == 'stroke') { 168 } else if (f[0] == 'stroke') {
172 if(f[1] != "none") 169 stroke_color = f[1];
173 stroke_color = f[1];
174 } else if (f[0] == 'stroke-width') { 170 } else if (f[0] == 'stroke-width') {
175 path.stroke_width = parseFloat(f[1]); 171 path.stroke_width = parseFloat(f[1]);
176 } else if (f[0] == 'stroke-opacity') { 172 } else if (f[0] == 'stroke-opacity') {
177 stroke_alpha = parseFloat(f[1]); 173 stroke_alpha = parseFloat(f[1]);
178 } 174 }
179 } 175 }
180 176
181 if(fill_color) { 177 }
178
179 if(!fill_color || !stroke_color)
180 black_paint = this.mb_rt.paint_color_new(0, 0, 0, 1);
181
182 if(fill_color) {
183 if(fill_color != "none") {
182 paint = this._prepare_paint_color(fill_color, fill_alpha); 184 paint = this._prepare_paint_color(fill_color, fill_alpha);
183 paint.fill(path); 185 paint.fill(path);
184 } 186 }
185 if(stroke_color) { 187 } else {
188 black_paint.fill(path);
189 }
190 if(stroke_color) {
191 if(stroke_color != "none") {
186 paint = this._prepare_paint_color(stroke_color, stroke_alpha); 192 paint = this._prepare_paint_color(stroke_color, stroke_alpha);
187 paint.stroke(path); 193 paint.stroke(path);
188 } 194 }
189 if(!stroke_color && !fill_color) { 195 } else {
190 paint = this.mb_rt.paint_color_new(0, 0, 0, 1); 196 black_paint.stroke(path);
191 paint.fill(path);
192 }
193
194 } 197 }
195 coord.add_shape(path); 198 coord.add_shape(path);
196 } 199 }
197 200
198 exports.parseText=function(coord,id, n) 201 exports.parseText=function(coord,id, n)