comparison nodejs/svg.js @ 879:44f46d6873be abs_n_rel_center

Set paint for tspan correctly
author Thinker K.F. Li <thinker@codemud.net>
date Sat, 25 Sep 2010 17:43:39 +0800
parents 818e5bed913d
children ac3e8492ad74
comparison
equal deleted inserted replaced
878:818e5bed913d 879:44f46d6873be
184 function tspan_set_text(text) 184 function tspan_set_text(text)
185 { 185 {
186 this.text.set_text(text); 186 this.text.set_text(text);
187 } 187 }
188 188
189 loadSVG.prototype.parseTSpan = function(coord, n,style) { 189 function _parse_font_size(fn_sz_str) {
190 var pos;
191
192 pos = fn_sz_str.search("px");
193 if(pos >= 0)
194 fn_sz_str = fn_sz_str.substring(0, pos);
195 pos = fn_sz_str.search("pt");
196 if(pos >= 0)
197 fn_sz_str = fn_sz_str.substring(0, pos);
198
199 return parseFloat(fn_sz_str);
200 }
201
202 loadSVG.prototype.parseTSpan = function(coord, n, pstyle) {
190 var x = getInteger(n,'x'); 203 var x = getInteger(n,'x');
191 var y = getInteger(n,'y'); 204 var y = getInteger(n,'y');
192 var tcoord = this.mb_rt.coord_new(coord); 205 var tcoord = this.mb_rt.coord_new(coord);
193 var nodes = n.childNodes(); 206 var style;
207 var family = "Courier";
208 var sz = 10;
209 var face;
194 var k; 210 var k;
195
196 var obj = this.mb_rt.stext_new(n.text(),x,y); 211 var obj = this.mb_rt.stext_new(n.text(),x,y);
197 parseTextStyle(style,n); 212
198 style.paint = this.mb_rt.paint_color_new(1,1,1,1); 213 style = parse_style(n);
199 style.face=this.mb_rt.font_face_query(style.family, 2, 100); 214 for(k in pstyle) {
200 obj.set_style([[20,style.face,style.fs]]); 215 if(k in style)
201 style.paint.fill(obj); 216 continue;
217 style[k] = pstyle[k];
218 }
219
220 if("font-family" in style)
221 family = style["font-family"];
222 if("font-size" in style)
223 sz = _parse_font_size(style["font-size"]);
224
225 face = this.mb_rt.font_face_query(family, 100, 210);
226 obj.set_style([[20, face, sz]]);
227
202 tcoord.add_shape(obj); 228 tcoord.add_shape(obj);
203 for(k in nodes) { 229 tcoord.set_text = tspan_set_text;
204 var name = nodes[k].name();
205 if (name == "tspan") {
206 this.parseTSpan(tcoord,nodes[k]);
207 } else {
208 }
209 }
210 tcoord.set_text=tspan_set_text;
211 tcoord.text = obj; 230 tcoord.text = obj;
231
232 this._set_paint(n, obj);
233 this._set_bbox(n, obj);
234
212 make_mbnames(this.mb_rt, n, tcoord); 235 make_mbnames(this.mb_rt, n, tcoord);
213 }; 236 };
214 237
215 loadSVG.prototype._prepare_paint_color = function(color, alpha) { 238 loadSVG.prototype._prepare_paint_color = function(color, alpha) {
216 var paint; 239 var paint;
225 } else if(_std_colors[color]) { 248 } else if(_std_colors[color]) {
226 c = _std_colors[color]; 249 c = _std_colors[color];
227 paint = this.mb_rt.paint_color_new(c[0], c[1], c[2], alpha); 250 paint = this.mb_rt.paint_color_new(c[0], c[1], c[2], alpha);
228 } else if (color.substring(0,3) == 'url') { 251 } else if (color.substring(0,3) == 'url') {
229 var id = color.substring(5, color.length-1); 252 var id = color.substring(5, color.length-1);
230 sys.puts(id);
231 if(id in this.gradients) { 253 if(id in this.gradients) {
232 var gr = this.gradients[id]; 254 var gr = this.gradients[id];
233 sys.puts(gr);
234 paint = this.mb_rt.paint_linear_new(gr[0],gr[1],gr[2],gr[3]); 255 paint = this.mb_rt.paint_linear_new(gr[0],gr[1],gr[2],gr[3]);
235 } else { 256 } else {
236 var radial = this.radials[id]; 257 var radial = this.radials[id];
237 paint = this.mb_rt.paint_radial_new(radial[0], 258 paint = this.mb_rt.paint_radial_new(radial[0],
238 radial[1], 259 radial[1],
239 radial[2]); 260 radial[2]);
240 } 261 }
241 paint.set_stops(this.stop_ref[id]); 262 paint.set_stops(this.stop_ref[id]);
242 sys.puts(this.stop_ref[id]);
243 } else { 263 } else {
244 paint = this.mb_rt.paint_color_new(0,0,0,1); 264 paint = this.mb_rt.paint_color_new(0,0,0,1);
245 } 265 }
246 return paint; 266 return paint;
247 }; 267 };
700 loadSVG.prototype.parseText=function(accu,coord,id, n) 720 loadSVG.prototype.parseText=function(accu,coord,id, n)
701 { 721 {
702 var x = getInteger(n,'x'); 722 var x = getInteger(n,'x');
703 var y = getInteger(n,'y'); 723 var y = getInteger(n,'y');
704 var tcoord = this.mb_rt.coord_new(coord); 724 var tcoord = this.mb_rt.coord_new(coord);
705 var style = new Object(); 725 var style;
706 726
707 if (n.attr('x')) { 727 if (n.attr('x')) {
708 var nx = coord[0]*x+coord[1]*y+coord[2]; 728 var nx = coord[0]*x+coord[1]*y+coord[2];
709 if (coord.center.x > nx) 729 if (coord.center.x > nx)
710 coord.center.x = nx; 730 coord.center.x = nx;
712 if (n.attr('y')) { 732 if (n.attr('y')) {
713 var ny = coord[3]*x+coord[4]*y+coord[5]; 733 var ny = coord[3]*x+coord[4]*y+coord[5];
714 if (coord.center.y > ny) 734 if (coord.center.y > ny)
715 coord.center.y = ny; 735 coord.center.y = ny;
716 } 736 }
717 style.fs = 20; 737 style = parse_style(n);
718 style.family = 'courier';
719 parseTextStyle(style,n);
720 var nodes = n.childNodes(); 738 var nodes = n.childNodes();
721 var k; 739 var k;
722 for(k in nodes) { 740 for(k in nodes) {
723 var c= nodes[k].name(); 741 var c= nodes[k].name();
724 if (c == "tspan") { 742 if (c == "tspan") {