Mercurial > MadButterfly
comparison nodejs/svg.js @ 625:9f2080b68f8e
Add the text style parser. This can not handle the recursive tspan yet.
author | wycc |
---|---|
date | Fri, 16 Jul 2010 04:04:53 +0800 |
parents | d45c928f6523 |
children | 01e960bfc9ff |
comparison
equal
deleted
inserted
replaced
624:d45c928f6523 | 625:9f2080b68f8e |
---|---|
25 var a = n.attr(name); | 25 var a = n.attr(name); |
26 if (a==null) return 0; | 26 if (a==null) return 0; |
27 return parseInt(a.value()); | 27 return parseInt(a.value()); |
28 } | 28 } |
29 | 29 |
30 function parseStyle(n) | 30 function parseTextStyle(obj,n) |
31 { | 31 { |
32 var attr; | |
33 if (n) { | |
34 attr = n.attr('style'); | |
35 } else { | |
36 attr = null; | |
37 } | |
38 var fs = 20; | |
39 var family="ciurier"; | |
40 if (attr == null) { | |
41 var paint = mb_rt.paint_color_new(1,1,1,1); | |
42 var face=mb_rt.font_face_query(family, 2, 100); | |
43 obj.set_style([[20,face,fs]]); | |
44 return paint; | |
45 } | |
46 var f = attr.value().split(';'); | |
47 | |
48 for(i in f) { | |
49 var kv = f[i].split(':'); | |
50 if (kv[0] == 'font-size') { | |
51 fs = parsePointSize(kv[1]); | |
52 } else if (kv[0] == "font-style") { | |
53 } else if (kv[0] == "font-weight") { | |
54 } else if (kv[0] == "fill") { | |
55 } else if (kv[0] == "fill-opacity") { | |
56 } else if (kv[0] == "stroke") { | |
57 } else if (kv[0] == "stroke-width") { | |
58 } else if (kv[0] == "stroke-linecap") { | |
59 } else if (kv[0] == "stroke-linejoin") { | |
60 } else if (kv[0] == "stroke-lineopacity") { | |
61 } else if (kv[0] == "font-family") { | |
62 } else if (kv[0] == "font-stretch") { | |
63 } else if (kv[0] == "font-variant") { | |
64 } else if (kv[0] == "text-anchor") { | |
65 } else if (kv[0] == "text-align") { | |
66 } else if (kv[0] == "writing-mode") { | |
67 } else if (kv[0] == "line-height") { | |
68 sys.puts("Unknown style: "+kv[0]); | |
69 } | |
70 } | |
71 var paint = mb_rt.paint_color_new(1,1,1,1); | |
72 var face=mb_rt.font_face_query(family, 2, 100); | |
73 obj.set_style([[20,face,fs]]); | |
74 return paint; | |
32 } | 75 } |
33 | 76 |
34 function _MB_parseTSpan(coord, n) | 77 function _MB_parseTSpan(coord, n) |
35 { | 78 { |
36 var x = getInteger(n,'x'); | 79 var x = getInteger(n,'x'); |
37 var y = getInteger(n,'y'); | 80 var y = getInteger(n,'y'); |
38 var tcoord = mb_rt.coord_new(coord); | 81 var tcoord = mb_rt.coord_new(coord); |
39 var paint = parseStyle(n); | |
40 var nodes = n.childNodes(); | 82 var nodes = n.childNodes(); |
41 var k; | 83 var k; |
42 | 84 |
43 sys.puts(n.text()); | 85 sys.puts(n.text()); |
44 var obj = mb_rt.stext_new(n.text(),x,y); | 86 var obj = mb_rt.stext_new(n.text(),x,y); |
45 var paint = mb_rt.paint_color_new(1,1,1,1); | 87 var paint = parseTextStyle(obj,n); |
46 var face=mb_rt.font_face_query("courier", 2, 100); | |
47 obj.set_style([[5,face,20]]); | |
48 paint.fill(obj); | 88 paint.fill(obj); |
49 tcoord.add_shape(obj); | 89 tcoord.add_shape(obj); |
50 for(k in nodes) { | 90 for(k in nodes) { |
51 var name = nodes[k].name(); | 91 var name = nodes[k].name(); |
52 if (name == "tspan") { | 92 if (name == "tspan") { |
59 function _MB_parseText(coord,id, n) | 99 function _MB_parseText(coord,id, n) |
60 { | 100 { |
61 var x = getInteger(n,'x'); | 101 var x = getInteger(n,'x'); |
62 var y = getInteger(n,'y'); | 102 var y = getInteger(n,'y'); |
63 var tcoord = mb_rt.coord_new(coord); | 103 var tcoord = mb_rt.coord_new(coord); |
64 var paint = parseStyle(n); | 104 //var paint = parseTextStyle(n); |
65 var nodes = n.childNodes(); | 105 var nodes = n.childNodes(); |
66 var k; | 106 var k; |
67 for(k in nodes) { | 107 for(k in nodes) { |
68 var n = nodes[k].name(); | 108 var n = nodes[k].name(); |
69 if (n == "tspan") { | 109 if (n == "tspan") { |