Mercurial > MadButterfly
annotate tools/svg2code.py @ 842:76fe4afce640
The inkscape:bbox is defined as the global coordinate system. However, the center.x and center.y must be the coordiante system of the parent group of the SVG entity. Therefore, we need to do coordinate transformation from the global coordination system to the local coordination system.
author | wycc |
---|---|
date | Sat, 18 Sep 2010 21:23:51 +0800 |
parents | 586e50f82c1f |
children |
rev | line source |
---|---|
62
7d976d925431
Generate C header files for SVG files.
Thinker K.F. Li <thinker@branda.to>
parents:
diff
changeset
|
1 #! /usr/bin/env python |
822
586e50f82c1f
Unify coding style tag for emacs and vim.
Shih-Yuan Lee (FourDollars) <fourdollars@gmail.com>
parents:
458
diff
changeset
|
2 # -*- indent-tabs-mode: t; tab-width: 8; c-basic-offset: 4; -*- |
586e50f82c1f
Unify coding style tag for emacs and vim.
Shih-Yuan Lee (FourDollars) <fourdollars@gmail.com>
parents:
458
diff
changeset
|
3 # vim: sw=4:ts=8:sts=4 |
62
7d976d925431
Generate C header files for SVG files.
Thinker K.F. Li <thinker@branda.to>
parents:
diff
changeset
|
4 from xml.dom.minidom import parse |
7d976d925431
Generate C header files for SVG files.
Thinker K.F. Li <thinker@branda.to>
parents:
diff
changeset
|
5 import sys |
84
42698de1f653
Support translate() function for transform attribute of 'g' tag.
Thinker K.F. Li <thinker@branda.to>
parents:
83
diff
changeset
|
6 import re |
62
7d976d925431
Generate C header files for SVG files.
Thinker K.F. Li <thinker@branda.to>
parents:
diff
changeset
|
7 |
7d976d925431
Generate C header files for SVG files.
Thinker K.F. Li <thinker@branda.to>
parents:
diff
changeset
|
8 svgns='http://www.w3.org/2000/svg' |
7d976d925431
Generate C header files for SVG files.
Thinker K.F. Li <thinker@branda.to>
parents:
diff
changeset
|
9 xlinkns='http://www.w3.org/1999/xlink' |
7d976d925431
Generate C header files for SVG files.
Thinker K.F. Li <thinker@branda.to>
parents:
diff
changeset
|
10 |
85
9b4a02bcaeb1
matrix() function in transform attribute of group and shapes
Thinker K.F. Li <thinker@branda.to>
parents:
84
diff
changeset
|
11 re_rgb = re.compile('rgb\\( *([0-9]+(\\.[0-9]+)?) *, *([0-9]+(\\.[0-9]+)?) *, *([0-9]+(\\.[0-9]+)?) *\\)') |
62
7d976d925431
Generate C header files for SVG files.
Thinker K.F. Li <thinker@branda.to>
parents:
diff
changeset
|
12 def translate_stops(parent, codefo, parent_id): |
64 | 13 stops = [] |
62
7d976d925431
Generate C header files for SVG files.
Thinker K.F. Li <thinker@branda.to>
parents:
diff
changeset
|
14 for node in parent.childNodes: |
7d976d925431
Generate C header files for SVG files.
Thinker K.F. Li <thinker@branda.to>
parents:
diff
changeset
|
15 if node.localName == 'stop' and node.namespaceURI == svgns: |
7d976d925431
Generate C header files for SVG files.
Thinker K.F. Li <thinker@branda.to>
parents:
diff
changeset
|
16 style = node.getAttribute('style') |
7d976d925431
Generate C header files for SVG files.
Thinker K.F. Li <thinker@branda.to>
parents:
diff
changeset
|
17 style_props = [prop.strip() for prop in style.split(';') |
7d976d925431
Generate C header files for SVG files.
Thinker K.F. Li <thinker@branda.to>
parents:
diff
changeset
|
18 if prop.strip()] |
7d976d925431
Generate C header files for SVG files.
Thinker K.F. Li <thinker@branda.to>
parents:
diff
changeset
|
19 style_kvpairs = [prop.split(':') for prop in style_props] |
7d976d925431
Generate C header files for SVG files.
Thinker K.F. Li <thinker@branda.to>
parents:
diff
changeset
|
20 style_kvpairs = [(prop[0].strip(), prop[1].strip()) |
7d976d925431
Generate C header files for SVG files.
Thinker K.F. Li <thinker@branda.to>
parents:
diff
changeset
|
21 for prop in style_kvpairs] |
7d976d925431
Generate C header files for SVG files.
Thinker K.F. Li <thinker@branda.to>
parents:
diff
changeset
|
22 style_map = dict(style_kvpairs) |
7d976d925431
Generate C header files for SVG files.
Thinker K.F. Li <thinker@branda.to>
parents:
diff
changeset
|
23 |
7d976d925431
Generate C header files for SVG files.
Thinker K.F. Li <thinker@branda.to>
parents:
diff
changeset
|
24 color = style_map['stop-color'].strip() |
7d976d925431
Generate C header files for SVG files.
Thinker K.F. Li <thinker@branda.to>
parents:
diff
changeset
|
25 if len(color) == 7 and color[0] == '#': |
7d976d925431
Generate C header files for SVG files.
Thinker K.F. Li <thinker@branda.to>
parents:
diff
changeset
|
26 r = float(int(color[1:3], 16)) / 255.0 |
7d976d925431
Generate C header files for SVG files.
Thinker K.F. Li <thinker@branda.to>
parents:
diff
changeset
|
27 g = float(int(color[3:5], 16)) / 255.0 |
7d976d925431
Generate C header files for SVG files.
Thinker K.F. Li <thinker@branda.to>
parents:
diff
changeset
|
28 b = float(int(color[5:7], 16)) / 255.0 |
86
7d0580f89468
Fix bug of dealing matrix().
Thinker K.F. Li <thinker@branda.to>
parents:
85
diff
changeset
|
29 elif color.lower() == 'white': |
7d0580f89468
Fix bug of dealing matrix().
Thinker K.F. Li <thinker@branda.to>
parents:
85
diff
changeset
|
30 r, g, b = 1, 1, 1 |
7d0580f89468
Fix bug of dealing matrix().
Thinker K.F. Li <thinker@branda.to>
parents:
85
diff
changeset
|
31 elif color.lower() == 'black': |
7d0580f89468
Fix bug of dealing matrix().
Thinker K.F. Li <thinker@branda.to>
parents:
85
diff
changeset
|
32 r, g, b = 0, 0, 0 |
62
7d976d925431
Generate C header files for SVG files.
Thinker K.F. Li <thinker@branda.to>
parents:
diff
changeset
|
33 else: |
85
9b4a02bcaeb1
matrix() function in transform attribute of group and shapes
Thinker K.F. Li <thinker@branda.to>
parents:
84
diff
changeset
|
34 mo = re_rgb.match(color) |
9b4a02bcaeb1
matrix() function in transform attribute of group and shapes
Thinker K.F. Li <thinker@branda.to>
parents:
84
diff
changeset
|
35 if mo: |
9b4a02bcaeb1
matrix() function in transform attribute of group and shapes
Thinker K.F. Li <thinker@branda.to>
parents:
84
diff
changeset
|
36 r = float(mo.group(1)) |
9b4a02bcaeb1
matrix() function in transform attribute of group and shapes
Thinker K.F. Li <thinker@branda.to>
parents:
84
diff
changeset
|
37 g = float(mo.group(3)) |
9b4a02bcaeb1
matrix() function in transform attribute of group and shapes
Thinker K.F. Li <thinker@branda.to>
parents:
84
diff
changeset
|
38 b = float(mo.group(5)) |
9b4a02bcaeb1
matrix() function in transform attribute of group and shapes
Thinker K.F. Li <thinker@branda.to>
parents:
84
diff
changeset
|
39 else: |
9b4a02bcaeb1
matrix() function in transform attribute of group and shapes
Thinker K.F. Li <thinker@branda.to>
parents:
84
diff
changeset
|
40 raise ValueError, '\'%s\' is invalid color value.' % (color) |
9b4a02bcaeb1
matrix() function in transform attribute of group and shapes
Thinker K.F. Li <thinker@branda.to>
parents:
84
diff
changeset
|
41 pass |
62
7d976d925431
Generate C header files for SVG files.
Thinker K.F. Li <thinker@branda.to>
parents:
diff
changeset
|
42 |
86
7d0580f89468
Fix bug of dealing matrix().
Thinker K.F. Li <thinker@branda.to>
parents:
85
diff
changeset
|
43 try: |
7d0580f89468
Fix bug of dealing matrix().
Thinker K.F. Li <thinker@branda.to>
parents:
85
diff
changeset
|
44 opacity = style_map['stop-opacity'] |
7d0580f89468
Fix bug of dealing matrix().
Thinker K.F. Li <thinker@branda.to>
parents:
85
diff
changeset
|
45 except: |
7d0580f89468
Fix bug of dealing matrix().
Thinker K.F. Li <thinker@branda.to>
parents:
85
diff
changeset
|
46 opacity = 1 |
7d0580f89468
Fix bug of dealing matrix().
Thinker K.F. Li <thinker@branda.to>
parents:
85
diff
changeset
|
47 pass |
62
7d976d925431
Generate C header files for SVG files.
Thinker K.F. Li <thinker@branda.to>
parents:
diff
changeset
|
48 offset = node.getAttribute('offset') |
64 | 49 stops.append('[COLOR_STOP([%s], %f, %f, %f, %f, %f)]' % ( |
50 parent_id, r, g, b, float(opacity), float(offset))) | |
62
7d976d925431
Generate C header files for SVG files.
Thinker K.F. Li <thinker@branda.to>
parents:
diff
changeset
|
51 pass |
7d976d925431
Generate C header files for SVG files.
Thinker K.F. Li <thinker@branda.to>
parents:
diff
changeset
|
52 pass |
64 | 53 print >> codefo, '%sdnl' % (', '.join(stops)) |
62
7d976d925431
Generate C header files for SVG files.
Thinker K.F. Li <thinker@branda.to>
parents:
diff
changeset
|
54 pass |
7d976d925431
Generate C header files for SVG files.
Thinker K.F. Li <thinker@branda.to>
parents:
diff
changeset
|
55 |
7d976d925431
Generate C header files for SVG files.
Thinker K.F. Li <thinker@branda.to>
parents:
diff
changeset
|
56 def translate_linearGradient(linear, codefo, doc): |
210
3fadd2f2742e
M4 macros to generate code for dynamic loading.
Thinker K.F. Li <thinker@branda.to>
parents:
197
diff
changeset
|
57 linear_id = _get_id(linear) |
62
7d976d925431
Generate C header files for SVG files.
Thinker K.F. Li <thinker@branda.to>
parents:
diff
changeset
|
58 if linear.hasAttribute('x1'): |
7d976d925431
Generate C header files for SVG files.
Thinker K.F. Li <thinker@branda.to>
parents:
diff
changeset
|
59 x1 = float(linear.getAttribute('x1')) |
7d976d925431
Generate C header files for SVG files.
Thinker K.F. Li <thinker@branda.to>
parents:
diff
changeset
|
60 y1 = float(linear.getAttribute('y1')) |
7d976d925431
Generate C header files for SVG files.
Thinker K.F. Li <thinker@branda.to>
parents:
diff
changeset
|
61 x2 = float(linear.getAttribute('x2')) |
7d976d925431
Generate C header files for SVG files.
Thinker K.F. Li <thinker@branda.to>
parents:
diff
changeset
|
62 y2 = float(linear.getAttribute('y2')) |
7d976d925431
Generate C header files for SVG files.
Thinker K.F. Li <thinker@branda.to>
parents:
diff
changeset
|
63 else: |
7d976d925431
Generate C header files for SVG files.
Thinker K.F. Li <thinker@branda.to>
parents:
diff
changeset
|
64 x1 = y1 = x2 = y2 = 0 |
7d976d925431
Generate C header files for SVG files.
Thinker K.F. Li <thinker@branda.to>
parents:
diff
changeset
|
65 pass |
63 | 66 print >> codefo, 'ADD_LINEAR_PAINT([%s], %f, %f, %f, %f, [' % ( |
62
7d976d925431
Generate C header files for SVG files.
Thinker K.F. Li <thinker@branda.to>
parents:
diff
changeset
|
67 linear_id, x1, y1, x2, y2) |
7d976d925431
Generate C header files for SVG files.
Thinker K.F. Li <thinker@branda.to>
parents:
diff
changeset
|
68 translate_stops(linear, codefo, linear_id) |
63 | 69 print >> codefo, '])dnl' |
62
7d976d925431
Generate C header files for SVG files.
Thinker K.F. Li <thinker@branda.to>
parents:
diff
changeset
|
70 |
7d976d925431
Generate C header files for SVG files.
Thinker K.F. Li <thinker@branda.to>
parents:
diff
changeset
|
71 href = linear.getAttributeNS(xlinkns, 'href').strip() |
7d976d925431
Generate C header files for SVG files.
Thinker K.F. Li <thinker@branda.to>
parents:
diff
changeset
|
72 if href and href[0] == '#': |
78 | 73 print >> codefo, 'REF_STOPS_LINEAR([%s], [%s])dnl' % ( |
74 linear_id, href[1:]) | |
62
7d976d925431
Generate C header files for SVG files.
Thinker K.F. Li <thinker@branda.to>
parents:
diff
changeset
|
75 pass |
7d976d925431
Generate C header files for SVG files.
Thinker K.F. Li <thinker@branda.to>
parents:
diff
changeset
|
76 pass |
7d976d925431
Generate C header files for SVG files.
Thinker K.F. Li <thinker@branda.to>
parents:
diff
changeset
|
77 |
7d976d925431
Generate C header files for SVG files.
Thinker K.F. Li <thinker@branda.to>
parents:
diff
changeset
|
78 def translate_radialGradient(radial, codefo, doc): |
210
3fadd2f2742e
M4 macros to generate code for dynamic loading.
Thinker K.F. Li <thinker@branda.to>
parents:
197
diff
changeset
|
79 radial_id = _get_id(radial) |
62
7d976d925431
Generate C header files for SVG files.
Thinker K.F. Li <thinker@branda.to>
parents:
diff
changeset
|
80 try: |
7d976d925431
Generate C header files for SVG files.
Thinker K.F. Li <thinker@branda.to>
parents:
diff
changeset
|
81 cx = float(radial.getAttribute('cx')) |
7d976d925431
Generate C header files for SVG files.
Thinker K.F. Li <thinker@branda.to>
parents:
diff
changeset
|
82 cy = float(radial.getAttribute('cy')) |
7d976d925431
Generate C header files for SVG files.
Thinker K.F. Li <thinker@branda.to>
parents:
diff
changeset
|
83 except: |
7d976d925431
Generate C header files for SVG files.
Thinker K.F. Li <thinker@branda.to>
parents:
diff
changeset
|
84 cx = cy = 0 |
7d976d925431
Generate C header files for SVG files.
Thinker K.F. Li <thinker@branda.to>
parents:
diff
changeset
|
85 pass |
7d976d925431
Generate C header files for SVG files.
Thinker K.F. Li <thinker@branda.to>
parents:
diff
changeset
|
86 try: |
7d976d925431
Generate C header files for SVG files.
Thinker K.F. Li <thinker@branda.to>
parents:
diff
changeset
|
87 r = float(radial.getAttribute('r')) |
7d976d925431
Generate C header files for SVG files.
Thinker K.F. Li <thinker@branda.to>
parents:
diff
changeset
|
88 except: |
7d976d925431
Generate C header files for SVG files.
Thinker K.F. Li <thinker@branda.to>
parents:
diff
changeset
|
89 r = 0.5 |
7d976d925431
Generate C header files for SVG files.
Thinker K.F. Li <thinker@branda.to>
parents:
diff
changeset
|
90 pass |
63 | 91 print >> codefo, 'ADD_RADIAL_PAINT([%s], %f, %f, %f, [' % ( |
62
7d976d925431
Generate C header files for SVG files.
Thinker K.F. Li <thinker@branda.to>
parents:
diff
changeset
|
92 radial_id, cx, cy, r) |
7d976d925431
Generate C header files for SVG files.
Thinker K.F. Li <thinker@branda.to>
parents:
diff
changeset
|
93 translate_stops(radial, codefo, radial_id) |
63 | 94 print >>codefo, '])dnl' |
62
7d976d925431
Generate C header files for SVG files.
Thinker K.F. Li <thinker@branda.to>
parents:
diff
changeset
|
95 |
7d976d925431
Generate C header files for SVG files.
Thinker K.F. Li <thinker@branda.to>
parents:
diff
changeset
|
96 href = radial.getAttributeNS(xlinkns, 'href').strip() |
7d976d925431
Generate C header files for SVG files.
Thinker K.F. Li <thinker@branda.to>
parents:
diff
changeset
|
97 if href[0] == '#': |
78 | 98 print >> codefo, 'REF_STOPS_RADIAL([%s], [%s])dnl' % ( |
99 radial_id, href[1:]) | |
62
7d976d925431
Generate C header files for SVG files.
Thinker K.F. Li <thinker@branda.to>
parents:
diff
changeset
|
100 pass |
7d976d925431
Generate C header files for SVG files.
Thinker K.F. Li <thinker@branda.to>
parents:
diff
changeset
|
101 pass |
7d976d925431
Generate C header files for SVG files.
Thinker K.F. Li <thinker@branda.to>
parents:
diff
changeset
|
102 |
7d976d925431
Generate C header files for SVG files.
Thinker K.F. Li <thinker@branda.to>
parents:
diff
changeset
|
103 def translate_defs(defs, codefo, doc): |
7d976d925431
Generate C header files for SVG files.
Thinker K.F. Li <thinker@branda.to>
parents:
diff
changeset
|
104 for node in defs.childNodes: |
7d976d925431
Generate C header files for SVG files.
Thinker K.F. Li <thinker@branda.to>
parents:
diff
changeset
|
105 if node.namespaceURI != svgns: |
7d976d925431
Generate C header files for SVG files.
Thinker K.F. Li <thinker@branda.to>
parents:
diff
changeset
|
106 continue |
7d976d925431
Generate C header files for SVG files.
Thinker K.F. Li <thinker@branda.to>
parents:
diff
changeset
|
107 if node.localName == 'linearGradient': |
7d976d925431
Generate C header files for SVG files.
Thinker K.F. Li <thinker@branda.to>
parents:
diff
changeset
|
108 translate_linearGradient(node, codefo, doc) |
7d976d925431
Generate C header files for SVG files.
Thinker K.F. Li <thinker@branda.to>
parents:
diff
changeset
|
109 pass |
7d976d925431
Generate C header files for SVG files.
Thinker K.F. Li <thinker@branda.to>
parents:
diff
changeset
|
110 elif node.localName == 'radialGradient': |
7d976d925431
Generate C header files for SVG files.
Thinker K.F. Li <thinker@branda.to>
parents:
diff
changeset
|
111 translate_radialGradient(node, codefo, doc) |
7d976d925431
Generate C header files for SVG files.
Thinker K.F. Li <thinker@branda.to>
parents:
diff
changeset
|
112 pass |
7d976d925431
Generate C header files for SVG files.
Thinker K.F. Li <thinker@branda.to>
parents:
diff
changeset
|
113 pass |
7d976d925431
Generate C header files for SVG files.
Thinker K.F. Li <thinker@branda.to>
parents:
diff
changeset
|
114 pass |
7d976d925431
Generate C header files for SVG files.
Thinker K.F. Li <thinker@branda.to>
parents:
diff
changeset
|
115 |
7d976d925431
Generate C header files for SVG files.
Thinker K.F. Li <thinker@branda.to>
parents:
diff
changeset
|
116 def trans_color(code): |
7d976d925431
Generate C header files for SVG files.
Thinker K.F. Li <thinker@branda.to>
parents:
diff
changeset
|
117 return int(code[1:3], 16) / 255.0, \ |
7d976d925431
Generate C header files for SVG files.
Thinker K.F. Li <thinker@branda.to>
parents:
diff
changeset
|
118 int(code[3:5], 16) / 255.0, \ |
7d976d925431
Generate C header files for SVG files.
Thinker K.F. Li <thinker@branda.to>
parents:
diff
changeset
|
119 int(code[5:7], 16) / 255.0 |
7d976d925431
Generate C header files for SVG files.
Thinker K.F. Li <thinker@branda.to>
parents:
diff
changeset
|
120 |
83 | 121 def get_style_map(style_str): |
62
7d976d925431
Generate C header files for SVG files.
Thinker K.F. Li <thinker@branda.to>
parents:
diff
changeset
|
122 prop_strs = [s.strip() for s in style_str.split(';')] |
7d976d925431
Generate C header files for SVG files.
Thinker K.F. Li <thinker@branda.to>
parents:
diff
changeset
|
123 prop_kvs = [s.split(':') for s in prop_strs if s] |
7d976d925431
Generate C header files for SVG files.
Thinker K.F. Li <thinker@branda.to>
parents:
diff
changeset
|
124 prop_kvs = [(k.strip(), v.strip()) for k, v in prop_kvs] |
7d976d925431
Generate C header files for SVG files.
Thinker K.F. Li <thinker@branda.to>
parents:
diff
changeset
|
125 prop_map = dict(prop_kvs) |
83 | 126 return prop_map |
127 | |
128 def translate_style(node, coord_id, codefo, doc, prefix): | |
129 node_id = node.getAttribute('id') | |
279
86a5ae82ccf2
* Modify svg2code_ex to use differnt font size at two test items to illustrate the function of the new text parser
wycc
parents:
278
diff
changeset
|
130 try: |
86a5ae82ccf2
* Modify svg2code_ex to use differnt font size at two test items to illustrate the function of the new text parser
wycc
parents:
278
diff
changeset
|
131 prop_map = node.style_map |
86a5ae82ccf2
* Modify svg2code_ex to use differnt font size at two test items to illustrate the function of the new text parser
wycc
parents:
278
diff
changeset
|
132 except: |
86a5ae82ccf2
* Modify svg2code_ex to use differnt font size at two test items to illustrate the function of the new text parser
wycc
parents:
278
diff
changeset
|
133 style_str = node.getAttribute('style') |
86a5ae82ccf2
* Modify svg2code_ex to use differnt font size at two test items to illustrate the function of the new text parser
wycc
parents:
278
diff
changeset
|
134 prop_map = get_style_map(style_str) |
313
5737548e922f
Fix bug that svg2code.py handle fill & stroke opacity in a wrong way.
Thinker K.F. Li <thinker@branda.to>
parents:
310
diff
changeset
|
135 pass |
822
586e50f82c1f
Unify coding style tag for emacs and vim.
Shih-Yuan Lee (FourDollars) <fourdollars@gmail.com>
parents:
458
diff
changeset
|
136 |
313
5737548e922f
Fix bug that svg2code.py handle fill & stroke opacity in a wrong way.
Thinker K.F. Li <thinker@branda.to>
parents:
310
diff
changeset
|
137 if node.hasAttribute('fill-opacity'): |
5737548e922f
Fix bug that svg2code.py handle fill & stroke opacity in a wrong way.
Thinker K.F. Li <thinker@branda.to>
parents:
310
diff
changeset
|
138 opacity = float(node.getAttribute('fill-opacity')) |
5737548e922f
Fix bug that svg2code.py handle fill & stroke opacity in a wrong way.
Thinker K.F. Li <thinker@branda.to>
parents:
310
diff
changeset
|
139 elif node.hasAttribute('opacity'): |
62
7d976d925431
Generate C header files for SVG files.
Thinker K.F. Li <thinker@branda.to>
parents:
diff
changeset
|
140 opacity = float(node.getAttribute('opacity')) |
313
5737548e922f
Fix bug that svg2code.py handle fill & stroke opacity in a wrong way.
Thinker K.F. Li <thinker@branda.to>
parents:
310
diff
changeset
|
141 else: |
5737548e922f
Fix bug that svg2code.py handle fill & stroke opacity in a wrong way.
Thinker K.F. Li <thinker@branda.to>
parents:
310
diff
changeset
|
142 opacity = 1 |
62
7d976d925431
Generate C header files for SVG files.
Thinker K.F. Li <thinker@branda.to>
parents:
diff
changeset
|
143 pass |
7d976d925431
Generate C header files for SVG files.
Thinker K.F. Li <thinker@branda.to>
parents:
diff
changeset
|
144 |
300
1b69da2494e9
Use the opacity of the style to overwrite the default opacity property of the node itself.
wycc
parents:
296
diff
changeset
|
145 try: |
1b69da2494e9
Use the opacity of the style to overwrite the default opacity property of the node itself.
wycc
parents:
296
diff
changeset
|
146 opacity = float(prop_map['opacity']) |
1b69da2494e9
Use the opacity of the style to overwrite the default opacity property of the node itself.
wycc
parents:
296
diff
changeset
|
147 except: |
1b69da2494e9
Use the opacity of the style to overwrite the default opacity property of the node itself.
wycc
parents:
296
diff
changeset
|
148 pass |
1b69da2494e9
Use the opacity of the style to overwrite the default opacity property of the node itself.
wycc
parents:
296
diff
changeset
|
149 |
62
7d976d925431
Generate C header files for SVG files.
Thinker K.F. Li <thinker@branda.to>
parents:
diff
changeset
|
150 if prop_map.has_key('fill'): |
7d976d925431
Generate C header files for SVG files.
Thinker K.F. Li <thinker@branda.to>
parents:
diff
changeset
|
151 fill = prop_map['fill'].strip() |
7d976d925431
Generate C header files for SVG files.
Thinker K.F. Li <thinker@branda.to>
parents:
diff
changeset
|
152 if fill.startswith('#') and len(fill) == 7: |
7d976d925431
Generate C header files for SVG files.
Thinker K.F. Li <thinker@branda.to>
parents:
diff
changeset
|
153 r, g, b = trans_color(fill) |
7d976d925431
Generate C header files for SVG files.
Thinker K.F. Li <thinker@branda.to>
parents:
diff
changeset
|
154 print >> codefo, 'FILL_SHAPE([%s], %f, %f, %f, %f)dnl' % ( |
7d976d925431
Generate C header files for SVG files.
Thinker K.F. Li <thinker@branda.to>
parents:
diff
changeset
|
155 node_id, r, g, b, opacity) |
7d976d925431
Generate C header files for SVG files.
Thinker K.F. Li <thinker@branda.to>
parents:
diff
changeset
|
156 elif fill.startswith('url(') and fill.endswith(')'): |
7d976d925431
Generate C header files for SVG files.
Thinker K.F. Li <thinker@branda.to>
parents:
diff
changeset
|
157 paint_id = fill[5:-1] |
7d976d925431
Generate C header files for SVG files.
Thinker K.F. Li <thinker@branda.to>
parents:
diff
changeset
|
158 print >> codefo, 'FILL_SHAPE_WITH_PAINT([%s], [%s])dnl' % ( |
7d976d925431
Generate C header files for SVG files.
Thinker K.F. Li <thinker@branda.to>
parents:
diff
changeset
|
159 node_id, paint_id) |
86
7d0580f89468
Fix bug of dealing matrix().
Thinker K.F. Li <thinker@branda.to>
parents:
85
diff
changeset
|
160 elif fill.lower() == 'none': |
7d0580f89468
Fix bug of dealing matrix().
Thinker K.F. Li <thinker@branda.to>
parents:
85
diff
changeset
|
161 pass |
62
7d976d925431
Generate C header files for SVG files.
Thinker K.F. Li <thinker@branda.to>
parents:
diff
changeset
|
162 else: |
7d976d925431
Generate C header files for SVG files.
Thinker K.F. Li <thinker@branda.to>
parents:
diff
changeset
|
163 raise ValueError, '\'%s\' is an invalid value for fill.' % (fill) |
7d976d925431
Generate C header files for SVG files.
Thinker K.F. Li <thinker@branda.to>
parents:
diff
changeset
|
164 pass |
7d976d925431
Generate C header files for SVG files.
Thinker K.F. Li <thinker@branda.to>
parents:
diff
changeset
|
165 |
313
5737548e922f
Fix bug that svg2code.py handle fill & stroke opacity in a wrong way.
Thinker K.F. Li <thinker@branda.to>
parents:
310
diff
changeset
|
166 if node.hasAttribute('stroke-opacity'): |
62
7d976d925431
Generate C header files for SVG files.
Thinker K.F. Li <thinker@branda.to>
parents:
diff
changeset
|
167 stroke_opacity = float(node.getAttribute('stroke-opacity')) |
313
5737548e922f
Fix bug that svg2code.py handle fill & stroke opacity in a wrong way.
Thinker K.F. Li <thinker@branda.to>
parents:
310
diff
changeset
|
168 elif node.hasAttribute('opacity'): |
5737548e922f
Fix bug that svg2code.py handle fill & stroke opacity in a wrong way.
Thinker K.F. Li <thinker@branda.to>
parents:
310
diff
changeset
|
169 stroke_opacity = float(node.getAttribute('opacity')) |
5737548e922f
Fix bug that svg2code.py handle fill & stroke opacity in a wrong way.
Thinker K.F. Li <thinker@branda.to>
parents:
310
diff
changeset
|
170 else: |
62
7d976d925431
Generate C header files for SVG files.
Thinker K.F. Li <thinker@branda.to>
parents:
diff
changeset
|
171 stroke_opacity = 1.0 |
7d976d925431
Generate C header files for SVG files.
Thinker K.F. Li <thinker@branda.to>
parents:
diff
changeset
|
172 pass |
7d976d925431
Generate C header files for SVG files.
Thinker K.F. Li <thinker@branda.to>
parents:
diff
changeset
|
173 |
7d976d925431
Generate C header files for SVG files.
Thinker K.F. Li <thinker@branda.to>
parents:
diff
changeset
|
174 if prop_map.has_key('stroke'): |
7d976d925431
Generate C header files for SVG files.
Thinker K.F. Li <thinker@branda.to>
parents:
diff
changeset
|
175 stroke = prop_map['stroke'].strip() |
7d976d925431
Generate C header files for SVG files.
Thinker K.F. Li <thinker@branda.to>
parents:
diff
changeset
|
176 if stroke.startswith('#') and len(stroke) == 7: |
7d976d925431
Generate C header files for SVG files.
Thinker K.F. Li <thinker@branda.to>
parents:
diff
changeset
|
177 r, g, b = trans_color(stroke) |
7d976d925431
Generate C header files for SVG files.
Thinker K.F. Li <thinker@branda.to>
parents:
diff
changeset
|
178 print >> codefo, 'STROKE_SHAPE([%s], %f, %f, %f, %f)dnl' % ( |
7d976d925431
Generate C header files for SVG files.
Thinker K.F. Li <thinker@branda.to>
parents:
diff
changeset
|
179 node_id, r, g, b, stroke_opacity) |
7d976d925431
Generate C header files for SVG files.
Thinker K.F. Li <thinker@branda.to>
parents:
diff
changeset
|
180 elif stroke.startswith('url(') and stroke.endswith(')'): |
7d976d925431
Generate C header files for SVG files.
Thinker K.F. Li <thinker@branda.to>
parents:
diff
changeset
|
181 paint_id = stroke[5:-1] |
7d976d925431
Generate C header files for SVG files.
Thinker K.F. Li <thinker@branda.to>
parents:
diff
changeset
|
182 print >> codefo, 'STROKE_SHAPE_WITH_PAINT([%s], [%s])dnl' % ( |
7d976d925431
Generate C header files for SVG files.
Thinker K.F. Li <thinker@branda.to>
parents:
diff
changeset
|
183 node_id, paint_id) |
83 | 184 elif stroke.lower() == 'none': |
185 pass | |
62
7d976d925431
Generate C header files for SVG files.
Thinker K.F. Li <thinker@branda.to>
parents:
diff
changeset
|
186 else: |
7d976d925431
Generate C header files for SVG files.
Thinker K.F. Li <thinker@branda.to>
parents:
diff
changeset
|
187 raise ValueError, '\'%s\' is an invalid value for stroke.' \ |
7d976d925431
Generate C header files for SVG files.
Thinker K.F. Li <thinker@branda.to>
parents:
diff
changeset
|
188 % (stroke) |
7d976d925431
Generate C header files for SVG files.
Thinker K.F. Li <thinker@branda.to>
parents:
diff
changeset
|
189 pass |
80
e548221c04eb
svg2code.py support stroke
Thinker K.F. Li <thinker@branda.to>
parents:
78
diff
changeset
|
190 |
e548221c04eb
svg2code.py support stroke
Thinker K.F. Li <thinker@branda.to>
parents:
78
diff
changeset
|
191 if prop_map.has_key('stroke-width'): |
83 | 192 if prop_map['stroke-width'].endswith('px'): |
372
2212f515584c
Adjust stroke width to more close to rendering result of Inkscape
Thinker K.F. Li <thinker@branda.to>
parents:
333
diff
changeset
|
193 stroke_width = float(prop_map['stroke-width'][:-2]) / 2 |
83 | 194 else: |
372
2212f515584c
Adjust stroke width to more close to rendering result of Inkscape
Thinker K.F. Li <thinker@branda.to>
parents:
333
diff
changeset
|
195 stroke_width = float(prop_map['stroke-width']) / 2 |
83 | 196 pass |
80
e548221c04eb
svg2code.py support stroke
Thinker K.F. Li <thinker@branda.to>
parents:
78
diff
changeset
|
197 print >> codefo, 'STROKE_WIDTH([%s], %f)dnl' % ( |
e548221c04eb
svg2code.py support stroke
Thinker K.F. Li <thinker@branda.to>
parents:
78
diff
changeset
|
198 node_id, stroke_width) |
e548221c04eb
svg2code.py support stroke
Thinker K.F. Li <thinker@branda.to>
parents:
78
diff
changeset
|
199 pass |
373
07ca7681f43b
Avoid set stroke width on shape with stroke=none
Thinker K.F. Li <thinker@branda.to>
parents:
372
diff
changeset
|
200 elif prop_map.has_key('stroke') and prop_map['stroke'] != 'none': |
372
2212f515584c
Adjust stroke width to more close to rendering result of Inkscape
Thinker K.F. Li <thinker@branda.to>
parents:
333
diff
changeset
|
201 print >> codefo, 'STROKE_WIDTH([%s], %f)dnl' % ( |
2212f515584c
Adjust stroke width to more close to rendering result of Inkscape
Thinker K.F. Li <thinker@branda.to>
parents:
333
diff
changeset
|
202 node_id, 0.5) |
2212f515584c
Adjust stroke width to more close to rendering result of Inkscape
Thinker K.F. Li <thinker@branda.to>
parents:
333
diff
changeset
|
203 pass |
81 | 204 |
205 if prop_map.has_key('display'): | |
206 display = prop_map['display'].strip().lower() | |
207 if display == 'none': | |
208 print >> codefo, '%sHIDE([%s])dnl' % (prefix, node_id) | |
209 pass | |
210 pass | |
62
7d976d925431
Generate C header files for SVG files.
Thinker K.F. Li <thinker@branda.to>
parents:
diff
changeset
|
211 pass |
7d976d925431
Generate C header files for SVG files.
Thinker K.F. Li <thinker@branda.to>
parents:
diff
changeset
|
212 |
85
9b4a02bcaeb1
matrix() function in transform attribute of group and shapes
Thinker K.F. Li <thinker@branda.to>
parents:
84
diff
changeset
|
213 def translate_shape_transform(shape, coord_id, codefo): |
9b4a02bcaeb1
matrix() function in transform attribute of group and shapes
Thinker K.F. Li <thinker@branda.to>
parents:
84
diff
changeset
|
214 shape_id = shape.getAttribute('id') |
9b4a02bcaeb1
matrix() function in transform attribute of group and shapes
Thinker K.F. Li <thinker@branda.to>
parents:
84
diff
changeset
|
215 |
9b4a02bcaeb1
matrix() function in transform attribute of group and shapes
Thinker K.F. Li <thinker@branda.to>
parents:
84
diff
changeset
|
216 if shape.hasAttribute('transform'): |
9b4a02bcaeb1
matrix() function in transform attribute of group and shapes
Thinker K.F. Li <thinker@branda.to>
parents:
84
diff
changeset
|
217 shape_coord_id = shape_id + '_coord' |
101 | 218 ## \page shape_coord Coordinate Transformation for Shapes. |
219 # | |
220 # svg2code.py add a coord_t for a shape if transform attribute | |
221 # of it's tag is setted. The name of coord_t object is | |
222 # <shape_id> + "_coord". | |
85
9b4a02bcaeb1
matrix() function in transform attribute of group and shapes
Thinker K.F. Li <thinker@branda.to>
parents:
84
diff
changeset
|
223 print >> codefo, 'dnl' |
9b4a02bcaeb1
matrix() function in transform attribute of group and shapes
Thinker K.F. Li <thinker@branda.to>
parents:
84
diff
changeset
|
224 print >> codefo, 'ADD_COORD([%s], [%s])dnl' % ( |
9b4a02bcaeb1
matrix() function in transform attribute of group and shapes
Thinker K.F. Li <thinker@branda.to>
parents:
84
diff
changeset
|
225 shape_coord_id, coord_id) |
9b4a02bcaeb1
matrix() function in transform attribute of group and shapes
Thinker K.F. Li <thinker@branda.to>
parents:
84
diff
changeset
|
226 transform = shape.getAttribute('transform') |
9b4a02bcaeb1
matrix() function in transform attribute of group and shapes
Thinker K.F. Li <thinker@branda.to>
parents:
84
diff
changeset
|
227 translate_transform(shape_coord_id, transform, codefo, 'SHAPE_') |
9b4a02bcaeb1
matrix() function in transform attribute of group and shapes
Thinker K.F. Li <thinker@branda.to>
parents:
84
diff
changeset
|
228 coord_id = shape_coord_id |
9b4a02bcaeb1
matrix() function in transform attribute of group and shapes
Thinker K.F. Li <thinker@branda.to>
parents:
84
diff
changeset
|
229 pass |
9b4a02bcaeb1
matrix() function in transform attribute of group and shapes
Thinker K.F. Li <thinker@branda.to>
parents:
84
diff
changeset
|
230 return coord_id |
9b4a02bcaeb1
matrix() function in transform attribute of group and shapes
Thinker K.F. Li <thinker@branda.to>
parents:
84
diff
changeset
|
231 |
269
c96f38ad4bb6
Fix mis-behavior of translate_path_data() on arc.
Thinker K.F. Li <thinker@branda.to>
parents:
260
diff
changeset
|
232 ## \brief Calculate geometry of ellipse where the arc is on. |
c96f38ad4bb6
Fix mis-behavior of translate_path_data() on arc.
Thinker K.F. Li <thinker@branda.to>
parents:
260
diff
changeset
|
233 # |
c96f38ad4bb6
Fix mis-behavior of translate_path_data() on arc.
Thinker K.F. Li <thinker@branda.to>
parents:
260
diff
changeset
|
234 # This function calculate the ellipse with information from SVG path data. |
c96f38ad4bb6
Fix mis-behavior of translate_path_data() on arc.
Thinker K.F. Li <thinker@branda.to>
parents:
260
diff
changeset
|
235 # |
c96f38ad4bb6
Fix mis-behavior of translate_path_data() on arc.
Thinker K.F. Li <thinker@branda.to>
parents:
260
diff
changeset
|
236 # \see calc_center_and_x_aix() |
c96f38ad4bb6
Fix mis-behavior of translate_path_data() on arc.
Thinker K.F. Li <thinker@branda.to>
parents:
260
diff
changeset
|
237 def _calc_ellipse_of_arc(x0, y0, rx, ry, x_rotate, large, sweep, x, y): |
c96f38ad4bb6
Fix mis-behavior of translate_path_data() on arc.
Thinker K.F. Li <thinker@branda.to>
parents:
260
diff
changeset
|
238 import math |
822
586e50f82c1f
Unify coding style tag for emacs and vim.
Shih-Yuan Lee (FourDollars) <fourdollars@gmail.com>
parents:
458
diff
changeset
|
239 |
269
c96f38ad4bb6
Fix mis-behavior of translate_path_data() on arc.
Thinker K.F. Li <thinker@branda.to>
parents:
260
diff
changeset
|
240 _sin = math.sin(x_rotate) |
c96f38ad4bb6
Fix mis-behavior of translate_path_data() on arc.
Thinker K.F. Li <thinker@branda.to>
parents:
260
diff
changeset
|
241 _cos = math.cos(x_rotate) |
822
586e50f82c1f
Unify coding style tag for emacs and vim.
Shih-Yuan Lee (FourDollars) <fourdollars@gmail.com>
parents:
458
diff
changeset
|
242 |
458
bb4f651090bf
Use cairo to transform and draw arc.
Thinker K.F. Li <thinker@branda.to>
parents:
434
diff
changeset
|
243 nrx = x * _cos + y * _sin # Not Rotated X |
269
c96f38ad4bb6
Fix mis-behavior of translate_path_data() on arc.
Thinker K.F. Li <thinker@branda.to>
parents:
260
diff
changeset
|
244 nry = x * -_sin + y * _cos |
c96f38ad4bb6
Fix mis-behavior of translate_path_data() on arc.
Thinker K.F. Li <thinker@branda.to>
parents:
260
diff
changeset
|
245 nrx0 = x0 * _cos + y0 * _sin |
c96f38ad4bb6
Fix mis-behavior of translate_path_data() on arc.
Thinker K.F. Li <thinker@branda.to>
parents:
260
diff
changeset
|
246 nry0 = x0 * -_sin + y0 * _cos |
822
586e50f82c1f
Unify coding style tag for emacs and vim.
Shih-Yuan Lee (FourDollars) <fourdollars@gmail.com>
parents:
458
diff
changeset
|
247 |
269
c96f38ad4bb6
Fix mis-behavior of translate_path_data() on arc.
Thinker K.F. Li <thinker@branda.to>
parents:
260
diff
changeset
|
248 udx = (nrx - nrx0) / 2 / rx # ux - umx |
c96f38ad4bb6
Fix mis-behavior of translate_path_data() on arc.
Thinker K.F. Li <thinker@branda.to>
parents:
260
diff
changeset
|
249 udy = (nry - nry0) / 2 / ry # uy - umy |
c96f38ad4bb6
Fix mis-behavior of translate_path_data() on arc.
Thinker K.F. Li <thinker@branda.to>
parents:
260
diff
changeset
|
250 umx = (nrx + nrx0) / 2 / rx |
c96f38ad4bb6
Fix mis-behavior of translate_path_data() on arc.
Thinker K.F. Li <thinker@branda.to>
parents:
260
diff
changeset
|
251 umy = (nry + nry0) / 2 / ry |
c96f38ad4bb6
Fix mis-behavior of translate_path_data() on arc.
Thinker K.F. Li <thinker@branda.to>
parents:
260
diff
changeset
|
252 |
c96f38ad4bb6
Fix mis-behavior of translate_path_data() on arc.
Thinker K.F. Li <thinker@branda.to>
parents:
260
diff
changeset
|
253 udx2 = udx * udx |
c96f38ad4bb6
Fix mis-behavior of translate_path_data() on arc.
Thinker K.F. Li <thinker@branda.to>
parents:
260
diff
changeset
|
254 udy2 = udy * udy |
c96f38ad4bb6
Fix mis-behavior of translate_path_data() on arc.
Thinker K.F. Li <thinker@branda.to>
parents:
260
diff
changeset
|
255 udl2 = udx2 + udy2 |
458
bb4f651090bf
Use cairo to transform and draw arc.
Thinker K.F. Li <thinker@branda.to>
parents:
434
diff
changeset
|
256 if udl2 > 1: # make sure never > 1 |
bb4f651090bf
Use cairo to transform and draw arc.
Thinker K.F. Li <thinker@branda.to>
parents:
434
diff
changeset
|
257 udl2 = 1 |
bb4f651090bf
Use cairo to transform and draw arc.
Thinker K.F. Li <thinker@branda.to>
parents:
434
diff
changeset
|
258 pass |
269
c96f38ad4bb6
Fix mis-behavior of translate_path_data() on arc.
Thinker K.F. Li <thinker@branda.to>
parents:
260
diff
changeset
|
259 |
c96f38ad4bb6
Fix mis-behavior of translate_path_data() on arc.
Thinker K.F. Li <thinker@branda.to>
parents:
260
diff
changeset
|
260 if udy != 0: |
c96f38ad4bb6
Fix mis-behavior of translate_path_data() on arc.
Thinker K.F. Li <thinker@branda.to>
parents:
260
diff
changeset
|
261 # center is at left-side of arc |
c96f38ad4bb6
Fix mis-behavior of translate_path_data() on arc.
Thinker K.F. Li <thinker@branda.to>
parents:
260
diff
changeset
|
262 udcx = -math.sqrt((1 - udl2) * udl2) / (udy + udx2 / udy) |
c96f38ad4bb6
Fix mis-behavior of translate_path_data() on arc.
Thinker K.F. Li <thinker@branda.to>
parents:
260
diff
changeset
|
263 udcy = -udcx * udx / udy |
c96f38ad4bb6
Fix mis-behavior of translate_path_data() on arc.
Thinker K.F. Li <thinker@branda.to>
parents:
260
diff
changeset
|
264 else: |
c96f38ad4bb6
Fix mis-behavior of translate_path_data() on arc.
Thinker K.F. Li <thinker@branda.to>
parents:
260
diff
changeset
|
265 # center is at down-side of arc |
c96f38ad4bb6
Fix mis-behavior of translate_path_data() on arc.
Thinker K.F. Li <thinker@branda.to>
parents:
260
diff
changeset
|
266 udcx = 0 |
c96f38ad4bb6
Fix mis-behavior of translate_path_data() on arc.
Thinker K.F. Li <thinker@branda.to>
parents:
260
diff
changeset
|
267 udcy = math.sqrt((1 - udl2) * udl2) / udx |
c96f38ad4bb6
Fix mis-behavior of translate_path_data() on arc.
Thinker K.F. Li <thinker@branda.to>
parents:
260
diff
changeset
|
268 pass |
c96f38ad4bb6
Fix mis-behavior of translate_path_data() on arc.
Thinker K.F. Li <thinker@branda.to>
parents:
260
diff
changeset
|
269 |
c96f38ad4bb6
Fix mis-behavior of translate_path_data() on arc.
Thinker K.F. Li <thinker@branda.to>
parents:
260
diff
changeset
|
270 reflect = 0 |
c96f38ad4bb6
Fix mis-behavior of translate_path_data() on arc.
Thinker K.F. Li <thinker@branda.to>
parents:
260
diff
changeset
|
271 if large: |
c96f38ad4bb6
Fix mis-behavior of translate_path_data() on arc.
Thinker K.F. Li <thinker@branda.to>
parents:
260
diff
changeset
|
272 reflect ^= 1 |
c96f38ad4bb6
Fix mis-behavior of translate_path_data() on arc.
Thinker K.F. Li <thinker@branda.to>
parents:
260
diff
changeset
|
273 pass |
c96f38ad4bb6
Fix mis-behavior of translate_path_data() on arc.
Thinker K.F. Li <thinker@branda.to>
parents:
260
diff
changeset
|
274 if sweep != 1: |
c96f38ad4bb6
Fix mis-behavior of translate_path_data() on arc.
Thinker K.F. Li <thinker@branda.to>
parents:
260
diff
changeset
|
275 reflect ^= 1 |
c96f38ad4bb6
Fix mis-behavior of translate_path_data() on arc.
Thinker K.F. Li <thinker@branda.to>
parents:
260
diff
changeset
|
276 pass |
c96f38ad4bb6
Fix mis-behavior of translate_path_data() on arc.
Thinker K.F. Li <thinker@branda.to>
parents:
260
diff
changeset
|
277 if reflect: |
c96f38ad4bb6
Fix mis-behavior of translate_path_data() on arc.
Thinker K.F. Li <thinker@branda.to>
parents:
260
diff
changeset
|
278 udcx = -udcx |
c96f38ad4bb6
Fix mis-behavior of translate_path_data() on arc.
Thinker K.F. Li <thinker@branda.to>
parents:
260
diff
changeset
|
279 udcy = -udcy |
c96f38ad4bb6
Fix mis-behavior of translate_path_data() on arc.
Thinker K.F. Li <thinker@branda.to>
parents:
260
diff
changeset
|
280 pass |
c96f38ad4bb6
Fix mis-behavior of translate_path_data() on arc.
Thinker K.F. Li <thinker@branda.to>
parents:
260
diff
changeset
|
281 |
c96f38ad4bb6
Fix mis-behavior of translate_path_data() on arc.
Thinker K.F. Li <thinker@branda.to>
parents:
260
diff
changeset
|
282 nrcx = rx * (udcx + umx) |
c96f38ad4bb6
Fix mis-behavior of translate_path_data() on arc.
Thinker K.F. Li <thinker@branda.to>
parents:
260
diff
changeset
|
283 nrcy = ry * (udcy + umy) |
822
586e50f82c1f
Unify coding style tag for emacs and vim.
Shih-Yuan Lee (FourDollars) <fourdollars@gmail.com>
parents:
458
diff
changeset
|
284 |
269
c96f38ad4bb6
Fix mis-behavior of translate_path_data() on arc.
Thinker K.F. Li <thinker@branda.to>
parents:
260
diff
changeset
|
285 cx = nrcx * _cos - nrcy * _sin |
c96f38ad4bb6
Fix mis-behavior of translate_path_data() on arc.
Thinker K.F. Li <thinker@branda.to>
parents:
260
diff
changeset
|
286 cy = nrcx * _sin + nrcy * _cos |
822
586e50f82c1f
Unify coding style tag for emacs and vim.
Shih-Yuan Lee (FourDollars) <fourdollars@gmail.com>
parents:
458
diff
changeset
|
287 |
458
bb4f651090bf
Use cairo to transform and draw arc.
Thinker K.F. Li <thinker@branda.to>
parents:
434
diff
changeset
|
288 return cx, cy |
269
c96f38ad4bb6
Fix mis-behavior of translate_path_data() on arc.
Thinker K.F. Li <thinker@branda.to>
parents:
260
diff
changeset
|
289 |
197
bcad1ccdf45c
Translate the path string into binary array to save the parsing in the runtime. It can reduce the size as well.
wycc@wycc-desktop
parents:
101
diff
changeset
|
290 # M x y : Move to (x,y) |
bcad1ccdf45c
Translate the path string into binary array to save the parsing in the runtime. It can reduce the size as well.
wycc@wycc-desktop
parents:
101
diff
changeset
|
291 # Z : close path |
bcad1ccdf45c
Translate the path string into binary array to save the parsing in the runtime. It can reduce the size as well.
wycc@wycc-desktop
parents:
101
diff
changeset
|
292 # L x y : lineto (x,y) |
bcad1ccdf45c
Translate the path string into binary array to save the parsing in the runtime. It can reduce the size as well.
wycc@wycc-desktop
parents:
101
diff
changeset
|
293 # H x : horizontal line to x |
bcad1ccdf45c
Translate the path string into binary array to save the parsing in the runtime. It can reduce the size as well.
wycc@wycc-desktop
parents:
101
diff
changeset
|
294 # V y : Vertical line to y |
bcad1ccdf45c
Translate the path string into binary array to save the parsing in the runtime. It can reduce the size as well.
wycc@wycc-desktop
parents:
101
diff
changeset
|
295 # C x1 y1 x2 y2 x y : Draw a segment of bezier curve |
241
104d83378582
Add scene support in svg2code.py.
Thinker K.F. Li <thinker@branda.to>
parents:
210
diff
changeset
|
296 # S x2 y2 x t : Draw a segment of bezier curve from the last |
104d83378582
Add scene support in svg2code.py.
Thinker K.F. Li <thinker@branda.to>
parents:
210
diff
changeset
|
297 # control point |
197
bcad1ccdf45c
Translate the path string into binary array to save the parsing in the runtime. It can reduce the size as well.
wycc@wycc-desktop
parents:
101
diff
changeset
|
298 # Q x1 y1 x y : Draw a segment of quadratic curve |
241
104d83378582
Add scene support in svg2code.py.
Thinker K.F. Li <thinker@branda.to>
parents:
210
diff
changeset
|
299 # T x y : Draw a segment of quadratic curve from the last |
104d83378582
Add scene support in svg2code.py.
Thinker K.F. Li <thinker@branda.to>
parents:
210
diff
changeset
|
300 # control pint |
197
bcad1ccdf45c
Translate the path string into binary array to save the parsing in the runtime. It can reduce the size as well.
wycc@wycc-desktop
parents:
101
diff
changeset
|
301 # A x y r f s x y : Draw an arc |
241
104d83378582
Add scene support in svg2code.py.
Thinker K.F. Li <thinker@branda.to>
parents:
210
diff
changeset
|
302 # translate the path data into two arrays. The first is an integer whose |
104d83378582
Add scene support in svg2code.py.
Thinker K.F. Li <thinker@branda.to>
parents:
210
diff
changeset
|
303 # upper 8 bits are the command type The second array hold all arguments. |
197
bcad1ccdf45c
Translate the path string into binary array to save the parsing in the runtime. It can reduce the size as well.
wycc@wycc-desktop
parents:
101
diff
changeset
|
304 |
bcad1ccdf45c
Translate the path string into binary array to save the parsing in the runtime. It can reduce the size as well.
wycc@wycc-desktop
parents:
101
diff
changeset
|
305 command_length={'M': 2, 'm':2, |
bcad1ccdf45c
Translate the path string into binary array to save the parsing in the runtime. It can reduce the size as well.
wycc@wycc-desktop
parents:
101
diff
changeset
|
306 'Z': 0, 'z':0, |
bcad1ccdf45c
Translate the path string into binary array to save the parsing in the runtime. It can reduce the size as well.
wycc@wycc-desktop
parents:
101
diff
changeset
|
307 'L': 2, 'l':2, |
bcad1ccdf45c
Translate the path string into binary array to save the parsing in the runtime. It can reduce the size as well.
wycc@wycc-desktop
parents:
101
diff
changeset
|
308 'H': 1, 'h':1, |
bcad1ccdf45c
Translate the path string into binary array to save the parsing in the runtime. It can reduce the size as well.
wycc@wycc-desktop
parents:
101
diff
changeset
|
309 'V': 1, 'v':1, |
bcad1ccdf45c
Translate the path string into binary array to save the parsing in the runtime. It can reduce the size as well.
wycc@wycc-desktop
parents:
101
diff
changeset
|
310 'C': 6, 'c':6, |
bcad1ccdf45c
Translate the path string into binary array to save the parsing in the runtime. It can reduce the size as well.
wycc@wycc-desktop
parents:
101
diff
changeset
|
311 'S': 4, 's':4, |
bcad1ccdf45c
Translate the path string into binary array to save the parsing in the runtime. It can reduce the size as well.
wycc@wycc-desktop
parents:
101
diff
changeset
|
312 'Q': 4, 'q':4, |
269
c96f38ad4bb6
Fix mis-behavior of translate_path_data() on arc.
Thinker K.F. Li <thinker@branda.to>
parents:
260
diff
changeset
|
313 'T': 2, 't':2, |
c96f38ad4bb6
Fix mis-behavior of translate_path_data() on arc.
Thinker K.F. Li <thinker@branda.to>
parents:
260
diff
changeset
|
314 'A': 7, 'a':7} |
197
bcad1ccdf45c
Translate the path string into binary array to save the parsing in the runtime. It can reduce the size as well.
wycc@wycc-desktop
parents:
101
diff
changeset
|
315 |
458
bb4f651090bf
Use cairo to transform and draw arc.
Thinker K.F. Li <thinker@branda.to>
parents:
434
diff
changeset
|
316 def _angle_rotated_ellipse(x, y, rx, ry, x_rotate): |
bb4f651090bf
Use cairo to transform and draw arc.
Thinker K.F. Li <thinker@branda.to>
parents:
434
diff
changeset
|
317 import math |
822
586e50f82c1f
Unify coding style tag for emacs and vim.
Shih-Yuan Lee (FourDollars) <fourdollars@gmail.com>
parents:
458
diff
changeset
|
318 |
458
bb4f651090bf
Use cairo to transform and draw arc.
Thinker K.F. Li <thinker@branda.to>
parents:
434
diff
changeset
|
319 _cos = math.cos(x_rotate) |
bb4f651090bf
Use cairo to transform and draw arc.
Thinker K.F. Li <thinker@branda.to>
parents:
434
diff
changeset
|
320 _sin = math.sin(x_rotate) |
bb4f651090bf
Use cairo to transform and draw arc.
Thinker K.F. Li <thinker@branda.to>
parents:
434
diff
changeset
|
321 |
bb4f651090bf
Use cairo to transform and draw arc.
Thinker K.F. Li <thinker@branda.to>
parents:
434
diff
changeset
|
322 nrx = (x * _cos + y * _sin) / rx |
bb4f651090bf
Use cairo to transform and draw arc.
Thinker K.F. Li <thinker@branda.to>
parents:
434
diff
changeset
|
323 nry = (-x * _sin + y * _cos) / ry |
822
586e50f82c1f
Unify coding style tag for emacs and vim.
Shih-Yuan Lee (FourDollars) <fourdollars@gmail.com>
parents:
458
diff
changeset
|
324 |
458
bb4f651090bf
Use cairo to transform and draw arc.
Thinker K.F. Li <thinker@branda.to>
parents:
434
diff
changeset
|
325 xy_tan = nry / nrx |
bb4f651090bf
Use cairo to transform and draw arc.
Thinker K.F. Li <thinker@branda.to>
parents:
434
diff
changeset
|
326 xy_angle = math.atan(xy_tan) |
bb4f651090bf
Use cairo to transform and draw arc.
Thinker K.F. Li <thinker@branda.to>
parents:
434
diff
changeset
|
327 |
bb4f651090bf
Use cairo to transform and draw arc.
Thinker K.F. Li <thinker@branda.to>
parents:
434
diff
changeset
|
328 if nrx < 0: |
bb4f651090bf
Use cairo to transform and draw arc.
Thinker K.F. Li <thinker@branda.to>
parents:
434
diff
changeset
|
329 xy_angle = math.pi + xy_angle |
bb4f651090bf
Use cairo to transform and draw arc.
Thinker K.F. Li <thinker@branda.to>
parents:
434
diff
changeset
|
330 pass |
822
586e50f82c1f
Unify coding style tag for emacs and vim.
Shih-Yuan Lee (FourDollars) <fourdollars@gmail.com>
parents:
458
diff
changeset
|
331 |
458
bb4f651090bf
Use cairo to transform and draw arc.
Thinker K.F. Li <thinker@branda.to>
parents:
434
diff
changeset
|
332 return xy_angle |
bb4f651090bf
Use cairo to transform and draw arc.
Thinker K.F. Li <thinker@branda.to>
parents:
434
diff
changeset
|
333 |
bb4f651090bf
Use cairo to transform and draw arc.
Thinker K.F. Li <thinker@branda.to>
parents:
434
diff
changeset
|
334 def rotate(x, y, angle): |
bb4f651090bf
Use cairo to transform and draw arc.
Thinker K.F. Li <thinker@branda.to>
parents:
434
diff
changeset
|
335 import math |
bb4f651090bf
Use cairo to transform and draw arc.
Thinker K.F. Li <thinker@branda.to>
parents:
434
diff
changeset
|
336 _cos = math.cos(angle) |
bb4f651090bf
Use cairo to transform and draw arc.
Thinker K.F. Li <thinker@branda.to>
parents:
434
diff
changeset
|
337 _sin = math.sin(angle) |
bb4f651090bf
Use cairo to transform and draw arc.
Thinker K.F. Li <thinker@branda.to>
parents:
434
diff
changeset
|
338 nx = x * _cos - y * _sin |
bb4f651090bf
Use cairo to transform and draw arc.
Thinker K.F. Li <thinker@branda.to>
parents:
434
diff
changeset
|
339 ny = x * _sin + y * _cos |
bb4f651090bf
Use cairo to transform and draw arc.
Thinker K.F. Li <thinker@branda.to>
parents:
434
diff
changeset
|
340 return nx, ny |
bb4f651090bf
Use cairo to transform and draw arc.
Thinker K.F. Li <thinker@branda.to>
parents:
434
diff
changeset
|
341 |
bb4f651090bf
Use cairo to transform and draw arc.
Thinker K.F. Li <thinker@branda.to>
parents:
434
diff
changeset
|
342 def translate_path_data(data, codefo): |
bb4f651090bf
Use cairo to transform and draw arc.
Thinker K.F. Li <thinker@branda.to>
parents:
434
diff
changeset
|
343 import string |
bb4f651090bf
Use cairo to transform and draw arc.
Thinker K.F. Li <thinker@branda.to>
parents:
434
diff
changeset
|
344 import math |
822
586e50f82c1f
Unify coding style tag for emacs and vim.
Shih-Yuan Lee (FourDollars) <fourdollars@gmail.com>
parents:
458
diff
changeset
|
345 |
197
bcad1ccdf45c
Translate the path string into binary array to save the parsing in the runtime. It can reduce the size as well.
wycc@wycc-desktop
parents:
101
diff
changeset
|
346 temp = data.split() |
bcad1ccdf45c
Translate the path string into binary array to save the parsing in the runtime. It can reduce the size as well.
wycc@wycc-desktop
parents:
101
diff
changeset
|
347 fields=[] |
bcad1ccdf45c
Translate the path string into binary array to save the parsing in the runtime. It can reduce the size as well.
wycc@wycc-desktop
parents:
101
diff
changeset
|
348 for f in temp: |
bcad1ccdf45c
Translate the path string into binary array to save the parsing in the runtime. It can reduce the size as well.
wycc@wycc-desktop
parents:
101
diff
changeset
|
349 for s in f.split(','): |
bcad1ccdf45c
Translate the path string into binary array to save the parsing in the runtime. It can reduce the size as well.
wycc@wycc-desktop
parents:
101
diff
changeset
|
350 if s != '': |
bcad1ccdf45c
Translate the path string into binary array to save the parsing in the runtime. It can reduce the size as well.
wycc@wycc-desktop
parents:
101
diff
changeset
|
351 fields.append(s) |
bcad1ccdf45c
Translate the path string into binary array to save the parsing in the runtime. It can reduce the size as well.
wycc@wycc-desktop
parents:
101
diff
changeset
|
352 cmd = '' |
280 | 353 cmd_args=0 |
197
bcad1ccdf45c
Translate the path string into binary array to save the parsing in the runtime. It can reduce the size as well.
wycc@wycc-desktop
parents:
101
diff
changeset
|
354 commands='' |
458
bb4f651090bf
Use cairo to transform and draw arc.
Thinker K.F. Li <thinker@branda.to>
parents:
434
diff
changeset
|
355 pnts=[] |
bb4f651090bf
Use cairo to transform and draw arc.
Thinker K.F. Li <thinker@branda.to>
parents:
434
diff
changeset
|
356 float_args=[] |
197
bcad1ccdf45c
Translate the path string into binary array to save the parsing in the runtime. It can reduce the size as well.
wycc@wycc-desktop
parents:
101
diff
changeset
|
357 for f in fields: |
269
c96f38ad4bb6
Fix mis-behavior of translate_path_data() on arc.
Thinker K.F. Li <thinker@branda.to>
parents:
260
diff
changeset
|
358 if f in command_length: |
c96f38ad4bb6
Fix mis-behavior of translate_path_data() on arc.
Thinker K.F. Li <thinker@branda.to>
parents:
260
diff
changeset
|
359 if cmd_args != 0 and (narg % cmd_args) != 0: |
c96f38ad4bb6
Fix mis-behavior of translate_path_data() on arc.
Thinker K.F. Li <thinker@branda.to>
parents:
260
diff
changeset
|
360 raise ValueError, 'invalid path data %s' % (repr(fields)) |
c96f38ad4bb6
Fix mis-behavior of translate_path_data() on arc.
Thinker K.F. Li <thinker@branda.to>
parents:
260
diff
changeset
|
361 cmd = f |
c96f38ad4bb6
Fix mis-behavior of translate_path_data() on arc.
Thinker K.F. Li <thinker@branda.to>
parents:
260
diff
changeset
|
362 cmd_args = command_length[f] |
c96f38ad4bb6
Fix mis-behavior of translate_path_data() on arc.
Thinker K.F. Li <thinker@branda.to>
parents:
260
diff
changeset
|
363 narg = 0 |
c96f38ad4bb6
Fix mis-behavior of translate_path_data() on arc.
Thinker K.F. Li <thinker@branda.to>
parents:
260
diff
changeset
|
364 continue |
c96f38ad4bb6
Fix mis-behavior of translate_path_data() on arc.
Thinker K.F. Li <thinker@branda.to>
parents:
260
diff
changeset
|
365 |
c96f38ad4bb6
Fix mis-behavior of translate_path_data() on arc.
Thinker K.F. Li <thinker@branda.to>
parents:
260
diff
changeset
|
366 if (narg % cmd_args) == 0: |
c96f38ad4bb6
Fix mis-behavior of translate_path_data() on arc.
Thinker K.F. Li <thinker@branda.to>
parents:
260
diff
changeset
|
367 commands = commands + cmd |
c96f38ad4bb6
Fix mis-behavior of translate_path_data() on arc.
Thinker K.F. Li <thinker@branda.to>
parents:
260
diff
changeset
|
368 pass |
458
bb4f651090bf
Use cairo to transform and draw arc.
Thinker K.F. Li <thinker@branda.to>
parents:
434
diff
changeset
|
369 |
bb4f651090bf
Use cairo to transform and draw arc.
Thinker K.F. Li <thinker@branda.to>
parents:
434
diff
changeset
|
370 if cmd == 'H': |
bb4f651090bf
Use cairo to transform and draw arc.
Thinker K.F. Li <thinker@branda.to>
parents:
434
diff
changeset
|
371 arg = float(f) |
bb4f651090bf
Use cairo to transform and draw arc.
Thinker K.F. Li <thinker@branda.to>
parents:
434
diff
changeset
|
372 pnts.append(arg) |
bb4f651090bf
Use cairo to transform and draw arc.
Thinker K.F. Li <thinker@branda.to>
parents:
434
diff
changeset
|
373 pnts.append(pnts[-2]) |
bb4f651090bf
Use cairo to transform and draw arc.
Thinker K.F. Li <thinker@branda.to>
parents:
434
diff
changeset
|
374 continue |
bb4f651090bf
Use cairo to transform and draw arc.
Thinker K.F. Li <thinker@branda.to>
parents:
434
diff
changeset
|
375 if cmd == 'h': |
bb4f651090bf
Use cairo to transform and draw arc.
Thinker K.F. Li <thinker@branda.to>
parents:
434
diff
changeset
|
376 arg = float(f) |
bb4f651090bf
Use cairo to transform and draw arc.
Thinker K.F. Li <thinker@branda.to>
parents:
434
diff
changeset
|
377 pnts.append(arg + pnts[-2]) |
bb4f651090bf
Use cairo to transform and draw arc.
Thinker K.F. Li <thinker@branda.to>
parents:
434
diff
changeset
|
378 pnts.append(pnts[-2]) |
bb4f651090bf
Use cairo to transform and draw arc.
Thinker K.F. Li <thinker@branda.to>
parents:
434
diff
changeset
|
379 continue |
bb4f651090bf
Use cairo to transform and draw arc.
Thinker K.F. Li <thinker@branda.to>
parents:
434
diff
changeset
|
380 if cmd == 'V': |
bb4f651090bf
Use cairo to transform and draw arc.
Thinker K.F. Li <thinker@branda.to>
parents:
434
diff
changeset
|
381 arg = float(f) |
bb4f651090bf
Use cairo to transform and draw arc.
Thinker K.F. Li <thinker@branda.to>
parents:
434
diff
changeset
|
382 pnts.append(pnts[-2]) |
bb4f651090bf
Use cairo to transform and draw arc.
Thinker K.F. Li <thinker@branda.to>
parents:
434
diff
changeset
|
383 pnts.append(arg) |
bb4f651090bf
Use cairo to transform and draw arc.
Thinker K.F. Li <thinker@branda.to>
parents:
434
diff
changeset
|
384 continue |
bb4f651090bf
Use cairo to transform and draw arc.
Thinker K.F. Li <thinker@branda.to>
parents:
434
diff
changeset
|
385 if cmd == 'v': |
bb4f651090bf
Use cairo to transform and draw arc.
Thinker K.F. Li <thinker@branda.to>
parents:
434
diff
changeset
|
386 arg = float(f) |
bb4f651090bf
Use cairo to transform and draw arc.
Thinker K.F. Li <thinker@branda.to>
parents:
434
diff
changeset
|
387 pnts.append(pnts[-2]) |
bb4f651090bf
Use cairo to transform and draw arc.
Thinker K.F. Li <thinker@branda.to>
parents:
434
diff
changeset
|
388 pnts.append(arg + pnts[-2]) |
bb4f651090bf
Use cairo to transform and draw arc.
Thinker K.F. Li <thinker@branda.to>
parents:
434
diff
changeset
|
389 continue |
822
586e50f82c1f
Unify coding style tag for emacs and vim.
Shih-Yuan Lee (FourDollars) <fourdollars@gmail.com>
parents:
458
diff
changeset
|
390 |
269
c96f38ad4bb6
Fix mis-behavior of translate_path_data() on arc.
Thinker K.F. Li <thinker@branda.to>
parents:
260
diff
changeset
|
391 arg = float(f) |
458
bb4f651090bf
Use cairo to transform and draw arc.
Thinker K.F. Li <thinker@branda.to>
parents:
434
diff
changeset
|
392 if (cmd not in 'am') and (cmd in string.lowercase): |
bb4f651090bf
Use cairo to transform and draw arc.
Thinker K.F. Li <thinker@branda.to>
parents:
434
diff
changeset
|
393 # relative and not arc or moveto |
bb4f651090bf
Use cairo to transform and draw arc.
Thinker K.F. Li <thinker@branda.to>
parents:
434
diff
changeset
|
394 arg = arg + pnts[-2] |
bb4f651090bf
Use cairo to transform and draw arc.
Thinker K.F. Li <thinker@branda.to>
parents:
434
diff
changeset
|
395 pass |
bb4f651090bf
Use cairo to transform and draw arc.
Thinker K.F. Li <thinker@branda.to>
parents:
434
diff
changeset
|
396 pnts.append(arg) |
269
c96f38ad4bb6
Fix mis-behavior of translate_path_data() on arc.
Thinker K.F. Li <thinker@branda.to>
parents:
260
diff
changeset
|
397 narg = narg + 1 |
458
bb4f651090bf
Use cairo to transform and draw arc.
Thinker K.F. Li <thinker@branda.to>
parents:
434
diff
changeset
|
398 |
bb4f651090bf
Use cairo to transform and draw arc.
Thinker K.F. Li <thinker@branda.to>
parents:
434
diff
changeset
|
399 # For arc curve |
269
c96f38ad4bb6
Fix mis-behavior of translate_path_data() on arc.
Thinker K.F. Li <thinker@branda.to>
parents:
260
diff
changeset
|
400 if (narg % cmd_args) == 0 and (cmd in 'Aa'): |
c96f38ad4bb6
Fix mis-behavior of translate_path_data() on arc.
Thinker K.F. Li <thinker@branda.to>
parents:
260
diff
changeset
|
401 x0, y0, rx, ry, x_rotate, large, sweep, x, y = \ |
458
bb4f651090bf
Use cairo to transform and draw arc.
Thinker K.F. Li <thinker@branda.to>
parents:
434
diff
changeset
|
402 tuple(pnts[-9:]) |
bb4f651090bf
Use cairo to transform and draw arc.
Thinker K.F. Li <thinker@branda.to>
parents:
434
diff
changeset
|
403 if cmd == 'a': |
bb4f651090bf
Use cairo to transform and draw arc.
Thinker K.F. Li <thinker@branda.to>
parents:
434
diff
changeset
|
404 # relative position |
bb4f651090bf
Use cairo to transform and draw arc.
Thinker K.F. Li <thinker@branda.to>
parents:
434
diff
changeset
|
405 abs_x = x + x0 |
bb4f651090bf
Use cairo to transform and draw arc.
Thinker K.F. Li <thinker@branda.to>
parents:
434
diff
changeset
|
406 abs_y = y + y0 |
bb4f651090bf
Use cairo to transform and draw arc.
Thinker K.F. Li <thinker@branda.to>
parents:
434
diff
changeset
|
407 else: |
bb4f651090bf
Use cairo to transform and draw arc.
Thinker K.F. Li <thinker@branda.to>
parents:
434
diff
changeset
|
408 abs_x = x |
bb4f651090bf
Use cairo to transform and draw arc.
Thinker K.F. Li <thinker@branda.to>
parents:
434
diff
changeset
|
409 abs_y = y |
bb4f651090bf
Use cairo to transform and draw arc.
Thinker K.F. Li <thinker@branda.to>
parents:
434
diff
changeset
|
410 pass |
269
c96f38ad4bb6
Fix mis-behavior of translate_path_data() on arc.
Thinker K.F. Li <thinker@branda.to>
parents:
260
diff
changeset
|
411 x_rotate = int(x_rotate) |
c96f38ad4bb6
Fix mis-behavior of translate_path_data() on arc.
Thinker K.F. Li <thinker@branda.to>
parents:
260
diff
changeset
|
412 large = int(large) |
c96f38ad4bb6
Fix mis-behavior of translate_path_data() on arc.
Thinker K.F. Li <thinker@branda.to>
parents:
260
diff
changeset
|
413 sweep = int(sweep) |
458
bb4f651090bf
Use cairo to transform and draw arc.
Thinker K.F. Li <thinker@branda.to>
parents:
434
diff
changeset
|
414 cx, cy = _calc_ellipse_of_arc(x0, y0, rx, ry, |
bb4f651090bf
Use cairo to transform and draw arc.
Thinker K.F. Li <thinker@branda.to>
parents:
434
diff
changeset
|
415 x_rotate, large, |
bb4f651090bf
Use cairo to transform and draw arc.
Thinker K.F. Li <thinker@branda.to>
parents:
434
diff
changeset
|
416 sweep, abs_x, abs_y) |
bb4f651090bf
Use cairo to transform and draw arc.
Thinker K.F. Li <thinker@branda.to>
parents:
434
diff
changeset
|
417 # Corners |
bb4f651090bf
Use cairo to transform and draw arc.
Thinker K.F. Li <thinker@branda.to>
parents:
434
diff
changeset
|
418 c0x, c0y = rotate(-rx, -ry, x_rotate) |
bb4f651090bf
Use cairo to transform and draw arc.
Thinker K.F. Li <thinker@branda.to>
parents:
434
diff
changeset
|
419 c0x, c0y = c0x + cx, c0y + cy |
bb4f651090bf
Use cairo to transform and draw arc.
Thinker K.F. Li <thinker@branda.to>
parents:
434
diff
changeset
|
420 |
bb4f651090bf
Use cairo to transform and draw arc.
Thinker K.F. Li <thinker@branda.to>
parents:
434
diff
changeset
|
421 c1x, c1y = rotate(rx, -ry, x_rotate) |
bb4f651090bf
Use cairo to transform and draw arc.
Thinker K.F. Li <thinker@branda.to>
parents:
434
diff
changeset
|
422 c1x, c1y = c1x + cx, c1y + cy |
bb4f651090bf
Use cairo to transform and draw arc.
Thinker K.F. Li <thinker@branda.to>
parents:
434
diff
changeset
|
423 |
bb4f651090bf
Use cairo to transform and draw arc.
Thinker K.F. Li <thinker@branda.to>
parents:
434
diff
changeset
|
424 c2x, c2y = rotate(rx, ry, x_rotate) |
bb4f651090bf
Use cairo to transform and draw arc.
Thinker K.F. Li <thinker@branda.to>
parents:
434
diff
changeset
|
425 c2x, c2y = c2x + cx, c2y + cy |
bb4f651090bf
Use cairo to transform and draw arc.
Thinker K.F. Li <thinker@branda.to>
parents:
434
diff
changeset
|
426 |
bb4f651090bf
Use cairo to transform and draw arc.
Thinker K.F. Li <thinker@branda.to>
parents:
434
diff
changeset
|
427 c3x, c3y = rotate(-rx, ry, x_rotate) |
bb4f651090bf
Use cairo to transform and draw arc.
Thinker K.F. Li <thinker@branda.to>
parents:
434
diff
changeset
|
428 c3x, c3y = c3x + cx, c3y + cy |
822
586e50f82c1f
Unify coding style tag for emacs and vim.
Shih-Yuan Lee (FourDollars) <fourdollars@gmail.com>
parents:
458
diff
changeset
|
429 |
458
bb4f651090bf
Use cairo to transform and draw arc.
Thinker K.F. Li <thinker@branda.to>
parents:
434
diff
changeset
|
430 pnts[-7:] = [c0x, c0y, c1x, c1y, c2x, c2y, c3x, c3y, abs_x, abs_y] |
822
586e50f82c1f
Unify coding style tag for emacs and vim.
Shih-Yuan Lee (FourDollars) <fourdollars@gmail.com>
parents:
458
diff
changeset
|
431 |
458
bb4f651090bf
Use cairo to transform and draw arc.
Thinker K.F. Li <thinker@branda.to>
parents:
434
diff
changeset
|
432 start_angle = _angle_rotated_ellipse(x0 - cx, y0 - cy, |
bb4f651090bf
Use cairo to transform and draw arc.
Thinker K.F. Li <thinker@branda.to>
parents:
434
diff
changeset
|
433 rx, ry, x_rotate) |
bb4f651090bf
Use cairo to transform and draw arc.
Thinker K.F. Li <thinker@branda.to>
parents:
434
diff
changeset
|
434 stop_angle = _angle_rotated_ellipse(x - cx, y - cy, |
bb4f651090bf
Use cairo to transform and draw arc.
Thinker K.F. Li <thinker@branda.to>
parents:
434
diff
changeset
|
435 rx, ry, x_rotate) |
822
586e50f82c1f
Unify coding style tag for emacs and vim.
Shih-Yuan Lee (FourDollars) <fourdollars@gmail.com>
parents:
458
diff
changeset
|
436 |
458
bb4f651090bf
Use cairo to transform and draw arc.
Thinker K.F. Li <thinker@branda.to>
parents:
434
diff
changeset
|
437 # sweep == 1 for positive-angle direction |
bb4f651090bf
Use cairo to transform and draw arc.
Thinker K.F. Li <thinker@branda.to>
parents:
434
diff
changeset
|
438 # sweep == 0 for negative-angle direction |
bb4f651090bf
Use cairo to transform and draw arc.
Thinker K.F. Li <thinker@branda.to>
parents:
434
diff
changeset
|
439 if start_angle > stop_angle and sweep: |
bb4f651090bf
Use cairo to transform and draw arc.
Thinker K.F. Li <thinker@branda.to>
parents:
434
diff
changeset
|
440 stop_angle = math.pi * 2 + stop_angle |
bb4f651090bf
Use cairo to transform and draw arc.
Thinker K.F. Li <thinker@branda.to>
parents:
434
diff
changeset
|
441 elif start_angle < stop_angle and not sweep: |
bb4f651090bf
Use cairo to transform and draw arc.
Thinker K.F. Li <thinker@branda.to>
parents:
434
diff
changeset
|
442 start_angle = math.pi * 2 + start_angle |
bb4f651090bf
Use cairo to transform and draw arc.
Thinker K.F. Li <thinker@branda.to>
parents:
434
diff
changeset
|
443 pass |
822
586e50f82c1f
Unify coding style tag for emacs and vim.
Shih-Yuan Lee (FourDollars) <fourdollars@gmail.com>
parents:
458
diff
changeset
|
444 |
458
bb4f651090bf
Use cairo to transform and draw arc.
Thinker K.F. Li <thinker@branda.to>
parents:
434
diff
changeset
|
445 float_args.extend([cx, cy, rx, ry, |
bb4f651090bf
Use cairo to transform and draw arc.
Thinker K.F. Li <thinker@branda.to>
parents:
434
diff
changeset
|
446 start_angle, stop_angle, x_rotate]) |
269
c96f38ad4bb6
Fix mis-behavior of translate_path_data() on arc.
Thinker K.F. Li <thinker@branda.to>
parents:
260
diff
changeset
|
447 pass |
c96f38ad4bb6
Fix mis-behavior of translate_path_data() on arc.
Thinker K.F. Li <thinker@branda.to>
parents:
260
diff
changeset
|
448 pass |
458
bb4f651090bf
Use cairo to transform and draw arc.
Thinker K.F. Li <thinker@branda.to>
parents:
434
diff
changeset
|
449 return commands, pnts, float_args |
197
bcad1ccdf45c
Translate the path string into binary array to save the parsing in the runtime. It can reduce the size as well.
wycc@wycc-desktop
parents:
101
diff
changeset
|
450 |
210
3fadd2f2742e
M4 macros to generate code for dynamic loading.
Thinker K.F. Li <thinker@branda.to>
parents:
197
diff
changeset
|
451 _id_sn = 0 |
3fadd2f2742e
M4 macros to generate code for dynamic loading.
Thinker K.F. Li <thinker@branda.to>
parents:
197
diff
changeset
|
452 |
3fadd2f2742e
M4 macros to generate code for dynamic loading.
Thinker K.F. Li <thinker@branda.to>
parents:
197
diff
changeset
|
453 def _get_id(obj): |
3fadd2f2742e
M4 macros to generate code for dynamic loading.
Thinker K.F. Li <thinker@branda.to>
parents:
197
diff
changeset
|
454 global _id_sn |
3fadd2f2742e
M4 macros to generate code for dynamic loading.
Thinker K.F. Li <thinker@branda.to>
parents:
197
diff
changeset
|
455 |
3fadd2f2742e
M4 macros to generate code for dynamic loading.
Thinker K.F. Li <thinker@branda.to>
parents:
197
diff
changeset
|
456 if obj.hasAttribute('id'): |
3fadd2f2742e
M4 macros to generate code for dynamic loading.
Thinker K.F. Li <thinker@branda.to>
parents:
197
diff
changeset
|
457 oid = obj.getAttribute('id') |
3fadd2f2742e
M4 macros to generate code for dynamic loading.
Thinker K.F. Li <thinker@branda.to>
parents:
197
diff
changeset
|
458 else: |
3fadd2f2742e
M4 macros to generate code for dynamic loading.
Thinker K.F. Li <thinker@branda.to>
parents:
197
diff
changeset
|
459 oid = '_MB_RAND_%s_' % (_id_sn) |
3fadd2f2742e
M4 macros to generate code for dynamic loading.
Thinker K.F. Li <thinker@branda.to>
parents:
197
diff
changeset
|
460 obj.setAttribute('id', oid) |
3fadd2f2742e
M4 macros to generate code for dynamic loading.
Thinker K.F. Li <thinker@branda.to>
parents:
197
diff
changeset
|
461 _id_sn = _id_sn + 1 |
3fadd2f2742e
M4 macros to generate code for dynamic loading.
Thinker K.F. Li <thinker@branda.to>
parents:
197
diff
changeset
|
462 pass |
3fadd2f2742e
M4 macros to generate code for dynamic loading.
Thinker K.F. Li <thinker@branda.to>
parents:
197
diff
changeset
|
463 return oid |
3fadd2f2742e
M4 macros to generate code for dynamic loading.
Thinker K.F. Li <thinker@branda.to>
parents:
197
diff
changeset
|
464 |
3fadd2f2742e
M4 macros to generate code for dynamic loading.
Thinker K.F. Li <thinker@branda.to>
parents:
197
diff
changeset
|
465 ## |
3fadd2f2742e
M4 macros to generate code for dynamic loading.
Thinker K.F. Li <thinker@branda.to>
parents:
197
diff
changeset
|
466 # Decorator that check if objects have attribute 'mbname'. |
3fadd2f2742e
M4 macros to generate code for dynamic loading.
Thinker K.F. Li <thinker@branda.to>
parents:
197
diff
changeset
|
467 # |
3fadd2f2742e
M4 macros to generate code for dynamic loading.
Thinker K.F. Li <thinker@branda.to>
parents:
197
diff
changeset
|
468 def check_mbname(func): |
3fadd2f2742e
M4 macros to generate code for dynamic loading.
Thinker K.F. Li <thinker@branda.to>
parents:
197
diff
changeset
|
469 def deco(obj, coord_id, codefo, doc): |
428
c3faebaec0c4
Reformat svg2code.py to make more compatible witth our convention
Thinker K.F. Li <thinker@branda.to>
parents:
373
diff
changeset
|
470 if obj.hasAttribute('mbname') and obj.getAttribute('mbname'): |
210
3fadd2f2742e
M4 macros to generate code for dynamic loading.
Thinker K.F. Li <thinker@branda.to>
parents:
197
diff
changeset
|
471 ## \note mbname declare that this node should be in the |
3fadd2f2742e
M4 macros to generate code for dynamic loading.
Thinker K.F. Li <thinker@branda.to>
parents:
197
diff
changeset
|
472 # symbol table. |
3fadd2f2742e
M4 macros to generate code for dynamic loading.
Thinker K.F. Li <thinker@branda.to>
parents:
197
diff
changeset
|
473 mbname = obj.getAttribute('mbname') |
296
2e97e8082d83
* Fix the symbol definition code which does not assume the id is the same as the mbname.
wycc
parents:
287
diff
changeset
|
474 id = obj.getAttribute('id') |
2e97e8082d83
* Fix the symbol definition code which does not assume the id is the same as the mbname.
wycc
parents:
287
diff
changeset
|
475 print >> codefo, 'ADD_SYMBOL([%s],[%s])dnl' % (id,mbname) |
210
3fadd2f2742e
M4 macros to generate code for dynamic loading.
Thinker K.F. Li <thinker@branda.to>
parents:
197
diff
changeset
|
476 pass |
3fadd2f2742e
M4 macros to generate code for dynamic loading.
Thinker K.F. Li <thinker@branda.to>
parents:
197
diff
changeset
|
477 func(obj, coord_id, codefo, doc) |
3fadd2f2742e
M4 macros to generate code for dynamic loading.
Thinker K.F. Li <thinker@branda.to>
parents:
197
diff
changeset
|
478 pass |
3fadd2f2742e
M4 macros to generate code for dynamic loading.
Thinker K.F. Li <thinker@branda.to>
parents:
197
diff
changeset
|
479 return deco |
3fadd2f2742e
M4 macros to generate code for dynamic loading.
Thinker K.F. Li <thinker@branda.to>
parents:
197
diff
changeset
|
480 |
3fadd2f2742e
M4 macros to generate code for dynamic loading.
Thinker K.F. Li <thinker@branda.to>
parents:
197
diff
changeset
|
481 @check_mbname |
62
7d976d925431
Generate C header files for SVG files.
Thinker K.F. Li <thinker@branda.to>
parents:
diff
changeset
|
482 def translate_path(path, coord_id, codefo, doc): |
85
9b4a02bcaeb1
matrix() function in transform attribute of group and shapes
Thinker K.F. Li <thinker@branda.to>
parents:
84
diff
changeset
|
483 coord_id = translate_shape_transform(path, coord_id, codefo) |
9b4a02bcaeb1
matrix() function in transform attribute of group and shapes
Thinker K.F. Li <thinker@branda.to>
parents:
84
diff
changeset
|
484 |
62
7d976d925431
Generate C header files for SVG files.
Thinker K.F. Li <thinker@branda.to>
parents:
diff
changeset
|
485 path_id = path.getAttribute('id') |
7d976d925431
Generate C header files for SVG files.
Thinker K.F. Li <thinker@branda.to>
parents:
diff
changeset
|
486 d = path.getAttribute('d') |
458
bb4f651090bf
Use cairo to transform and draw arc.
Thinker K.F. Li <thinker@branda.to>
parents:
434
diff
changeset
|
487 (commands, pnts, float_args) = translate_path_data(d, codefo) |
62
7d976d925431
Generate C header files for SVG files.
Thinker K.F. Li <thinker@branda.to>
parents:
diff
changeset
|
488 print >> codefo, 'dnl' |
197
bcad1ccdf45c
Translate the path string into binary array to save the parsing in the runtime. It can reduce the size as well.
wycc@wycc-desktop
parents:
101
diff
changeset
|
489 #print >> codefo, 'ADD_PATH([%s], [%s], [%s])dnl' % (path_id, d, coord_id) |
458
bb4f651090bf
Use cairo to transform and draw arc.
Thinker K.F. Li <thinker@branda.to>
parents:
434
diff
changeset
|
490 spnts='' |
bb4f651090bf
Use cairo to transform and draw arc.
Thinker K.F. Li <thinker@branda.to>
parents:
434
diff
changeset
|
491 for c in pnts: |
bb4f651090bf
Use cairo to transform and draw arc.
Thinker K.F. Li <thinker@branda.to>
parents:
434
diff
changeset
|
492 spnts = spnts + "%f," % c |
bb4f651090bf
Use cairo to transform and draw arc.
Thinker K.F. Li <thinker@branda.to>
parents:
434
diff
changeset
|
493 s_float_arg='' |
bb4f651090bf
Use cairo to transform and draw arc.
Thinker K.F. Li <thinker@branda.to>
parents:
434
diff
changeset
|
494 for c in float_args: |
bb4f651090bf
Use cairo to transform and draw arc.
Thinker K.F. Li <thinker@branda.to>
parents:
434
diff
changeset
|
495 s_float_arg = s_float_arg + ("%f," % c) |
197
bcad1ccdf45c
Translate the path string into binary array to save the parsing in the runtime. It can reduce the size as well.
wycc@wycc-desktop
parents:
101
diff
changeset
|
496 |
458
bb4f651090bf
Use cairo to transform and draw arc.
Thinker K.F. Li <thinker@branda.to>
parents:
434
diff
changeset
|
497 print >> codefo, 'ADD_PATH([%s], [%s], [%s], [%s], [%d], [%s], [%d])dnl' % ( |
bb4f651090bf
Use cairo to transform and draw arc.
Thinker K.F. Li <thinker@branda.to>
parents:
434
diff
changeset
|
498 path_id, coord_id, commands, spnts, len(pnts), |
bb4f651090bf
Use cairo to transform and draw arc.
Thinker K.F. Li <thinker@branda.to>
parents:
434
diff
changeset
|
499 s_float_arg, len(float_args)) |
85
9b4a02bcaeb1
matrix() function in transform attribute of group and shapes
Thinker K.F. Li <thinker@branda.to>
parents:
84
diff
changeset
|
500 |
81 | 501 translate_style(path, coord_id, codefo, doc, 'PATH_') |
62
7d976d925431
Generate C header files for SVG files.
Thinker K.F. Li <thinker@branda.to>
parents:
diff
changeset
|
502 pass |
7d976d925431
Generate C header files for SVG files.
Thinker K.F. Li <thinker@branda.to>
parents:
diff
changeset
|
503 |
210
3fadd2f2742e
M4 macros to generate code for dynamic loading.
Thinker K.F. Li <thinker@branda.to>
parents:
197
diff
changeset
|
504 @check_mbname |
62
7d976d925431
Generate C header files for SVG files.
Thinker K.F. Li <thinker@branda.to>
parents:
diff
changeset
|
505 def translate_rect(rect, coord_id, codefo, doc): |
85
9b4a02bcaeb1
matrix() function in transform attribute of group and shapes
Thinker K.F. Li <thinker@branda.to>
parents:
84
diff
changeset
|
506 coord_id = translate_shape_transform(rect, coord_id, codefo) |
9b4a02bcaeb1
matrix() function in transform attribute of group and shapes
Thinker K.F. Li <thinker@branda.to>
parents:
84
diff
changeset
|
507 |
210
3fadd2f2742e
M4 macros to generate code for dynamic loading.
Thinker K.F. Li <thinker@branda.to>
parents:
197
diff
changeset
|
508 rect_id = _get_id(rect) |
62
7d976d925431
Generate C header files for SVG files.
Thinker K.F. Li <thinker@branda.to>
parents:
diff
changeset
|
509 x = float(rect.getAttribute('x')) |
7d976d925431
Generate C header files for SVG files.
Thinker K.F. Li <thinker@branda.to>
parents:
diff
changeset
|
510 y = float(rect.getAttribute('y')) |
80
e548221c04eb
svg2code.py support stroke
Thinker K.F. Li <thinker@branda.to>
parents:
78
diff
changeset
|
511 rx = 0.0 |
e548221c04eb
svg2code.py support stroke
Thinker K.F. Li <thinker@branda.to>
parents:
78
diff
changeset
|
512 if rect.hasAttribute('rx'): |
e548221c04eb
svg2code.py support stroke
Thinker K.F. Li <thinker@branda.to>
parents:
78
diff
changeset
|
513 rx = float(rect.getAttribute('rx')) |
e548221c04eb
svg2code.py support stroke
Thinker K.F. Li <thinker@branda.to>
parents:
78
diff
changeset
|
514 pass |
e548221c04eb
svg2code.py support stroke
Thinker K.F. Li <thinker@branda.to>
parents:
78
diff
changeset
|
515 ry = 0.0 |
e548221c04eb
svg2code.py support stroke
Thinker K.F. Li <thinker@branda.to>
parents:
78
diff
changeset
|
516 if rect.hasAttribute('ry'): |
e548221c04eb
svg2code.py support stroke
Thinker K.F. Li <thinker@branda.to>
parents:
78
diff
changeset
|
517 ry = float(rect.getAttribute('ry')) |
e548221c04eb
svg2code.py support stroke
Thinker K.F. Li <thinker@branda.to>
parents:
78
diff
changeset
|
518 pass |
62
7d976d925431
Generate C header files for SVG files.
Thinker K.F. Li <thinker@branda.to>
parents:
diff
changeset
|
519 width = float(rect.getAttribute('width')) |
7d976d925431
Generate C header files for SVG files.
Thinker K.F. Li <thinker@branda.to>
parents:
diff
changeset
|
520 height = float(rect.getAttribute('height')) |
7d976d925431
Generate C header files for SVG files.
Thinker K.F. Li <thinker@branda.to>
parents:
diff
changeset
|
521 print >> codefo, 'dnl' |
80
e548221c04eb
svg2code.py support stroke
Thinker K.F. Li <thinker@branda.to>
parents:
78
diff
changeset
|
522 print >> codefo, 'ADD_RECT([%s], %f, %f, %f, %f, %f, %f, [%s])dnl' % ( |
e548221c04eb
svg2code.py support stroke
Thinker K.F. Li <thinker@branda.to>
parents:
78
diff
changeset
|
523 rect_id, x, y, width, height, rx, ry, coord_id) |
81 | 524 translate_style(rect, coord_id, codefo, doc, 'RECT_') |
62
7d976d925431
Generate C header files for SVG files.
Thinker K.F. Li <thinker@branda.to>
parents:
diff
changeset
|
525 pass |
7d976d925431
Generate C header files for SVG files.
Thinker K.F. Li <thinker@branda.to>
parents:
diff
changeset
|
526 |
83 | 527 def translate_font_style(text, codefo): |
210
3fadd2f2742e
M4 macros to generate code for dynamic loading.
Thinker K.F. Li <thinker@branda.to>
parents:
197
diff
changeset
|
528 text_id = _get_id(text) |
83 | 529 style_str = text.getAttribute('style') |
530 style_map = get_style_map(style_str) | |
531 | |
278
a90fd749af82
Implement the whole tspan attribute. Currently, we can accept font family/font style/font weight and font size.
wycc
parents:
241
diff
changeset
|
532 return style_map |
a90fd749af82
Implement the whole tspan attribute. Currently, we can accept font family/font style/font weight and font size.
wycc
parents:
241
diff
changeset
|
533 |
428
c3faebaec0c4
Reformat svg2code.py to make more compatible witth our convention
Thinker K.F. Li <thinker@branda.to>
parents:
373
diff
changeset
|
534 def merge_style(tspan, text): |
279
86a5ae82ccf2
* Modify svg2code_ex to use differnt font size at two test items to illustrate the function of the new text parser
wycc
parents:
278
diff
changeset
|
535 newmap = tspan.style_map |
86a5ae82ccf2
* Modify svg2code_ex to use differnt font size at two test items to illustrate the function of the new text parser
wycc
parents:
278
diff
changeset
|
536 map = text.style_map |
86a5ae82ccf2
* Modify svg2code_ex to use differnt font size at two test items to illustrate the function of the new text parser
wycc
parents:
278
diff
changeset
|
537 for k,v in text.style_map.items(): |
428
c3faebaec0c4
Reformat svg2code.py to make more compatible witth our convention
Thinker K.F. Li <thinker@branda.to>
parents:
373
diff
changeset
|
538 if not newmap.has_key(k): |
c3faebaec0c4
Reformat svg2code.py to make more compatible witth our convention
Thinker K.F. Li <thinker@branda.to>
parents:
373
diff
changeset
|
539 newmap[k] = v |
c3faebaec0c4
Reformat svg2code.py to make more compatible witth our convention
Thinker K.F. Li <thinker@branda.to>
parents:
373
diff
changeset
|
540 pass |
c3faebaec0c4
Reformat svg2code.py to make more compatible witth our convention
Thinker K.F. Li <thinker@branda.to>
parents:
373
diff
changeset
|
541 pass |
c3faebaec0c4
Reformat svg2code.py to make more compatible witth our convention
Thinker K.F. Li <thinker@branda.to>
parents:
373
diff
changeset
|
542 pass |
c3faebaec0c4
Reformat svg2code.py to make more compatible witth our convention
Thinker K.F. Li <thinker@branda.to>
parents:
373
diff
changeset
|
543 |
c3faebaec0c4
Reformat svg2code.py to make more compatible witth our convention
Thinker K.F. Li <thinker@branda.to>
parents:
373
diff
changeset
|
544 def translate_tspan(tspan, text, coord_id, codefo, doc, txt_strs, attrs): |
279
86a5ae82ccf2
* Modify svg2code_ex to use differnt font size at two test items to illustrate the function of the new text parser
wycc
parents:
278
diff
changeset
|
545 try: |
86a5ae82ccf2
* Modify svg2code_ex to use differnt font size at two test items to illustrate the function of the new text parser
wycc
parents:
278
diff
changeset
|
546 map = tspan.style_map |
86a5ae82ccf2
* Modify svg2code_ex to use differnt font size at two test items to illustrate the function of the new text parser
wycc
parents:
278
diff
changeset
|
547 except: |
86a5ae82ccf2
* Modify svg2code_ex to use differnt font size at two test items to illustrate the function of the new text parser
wycc
parents:
278
diff
changeset
|
548 map = translate_font_style(tspan, codefo) |
86a5ae82ccf2
* Modify svg2code_ex to use differnt font size at two test items to illustrate the function of the new text parser
wycc
parents:
278
diff
changeset
|
549 tspan.style_map = map |
428
c3faebaec0c4
Reformat svg2code.py to make more compatible witth our convention
Thinker K.F. Li <thinker@branda.to>
parents:
373
diff
changeset
|
550 pass |
279
86a5ae82ccf2
* Modify svg2code_ex to use differnt font size at two test items to illustrate the function of the new text parser
wycc
parents:
278
diff
changeset
|
551 if tspan.hasAttribute('x'): |
428
c3faebaec0c4
Reformat svg2code.py to make more compatible witth our convention
Thinker K.F. Li <thinker@branda.to>
parents:
373
diff
changeset
|
552 # Render the tspan as an independent text if the x |
822
586e50f82c1f
Unify coding style tag for emacs and vim.
Shih-Yuan Lee (FourDollars) <fourdollars@gmail.com>
parents:
458
diff
changeset
|
553 # attribute is defined. All elements inside |
428
c3faebaec0c4
Reformat svg2code.py to make more compatible witth our convention
Thinker K.F. Li <thinker@branda.to>
parents:
373
diff
changeset
|
554 # the tspan will be ignore by the outter text or tspan elements. |
c3faebaec0c4
Reformat svg2code.py to make more compatible witth our convention
Thinker K.F. Li <thinker@branda.to>
parents:
373
diff
changeset
|
555 # FIXME: We need to apply the style map recursively. |
c3faebaec0c4
Reformat svg2code.py to make more compatible witth our convention
Thinker K.F. Li <thinker@branda.to>
parents:
373
diff
changeset
|
556 merge_style(tspan, text) |
c3faebaec0c4
Reformat svg2code.py to make more compatible witth our convention
Thinker K.F. Li <thinker@branda.to>
parents:
373
diff
changeset
|
557 translate_text(tspan, coord_id, codefo, doc) |
c3faebaec0c4
Reformat svg2code.py to make more compatible witth our convention
Thinker K.F. Li <thinker@branda.to>
parents:
373
diff
changeset
|
558 return '' |
c3faebaec0c4
Reformat svg2code.py to make more compatible witth our convention
Thinker K.F. Li <thinker@branda.to>
parents:
373
diff
changeset
|
559 attr = [len(txt_strs.encode('utf8')) - 1, 0, tspan] |
278
a90fd749af82
Implement the whole tspan attribute. Currently, we can accept font family/font style/font weight and font size.
wycc
parents:
241
diff
changeset
|
560 attrs.append(attr) |
a90fd749af82
Implement the whole tspan attribute. Currently, we can accept font family/font style/font weight and font size.
wycc
parents:
241
diff
changeset
|
561 for node in tspan.childNodes: |
a90fd749af82
Implement the whole tspan attribute. Currently, we can accept font family/font style/font weight and font size.
wycc
parents:
241
diff
changeset
|
562 if node.localName == None: |
a90fd749af82
Implement the whole tspan attribute. Currently, we can accept font family/font style/font weight and font size.
wycc
parents:
241
diff
changeset
|
563 txt_strs = txt_strs + node.data |
a90fd749af82
Implement the whole tspan attribute. Currently, we can accept font family/font style/font weight and font size.
wycc
parents:
241
diff
changeset
|
564 elif node.localName == 'tspan': |
428
c3faebaec0c4
Reformat svg2code.py to make more compatible witth our convention
Thinker K.F. Li <thinker@branda.to>
parents:
373
diff
changeset
|
565 txt_strs = translate_tspan(node, tspan, coord_id, codefo, |
c3faebaec0c4
Reformat svg2code.py to make more compatible witth our convention
Thinker K.F. Li <thinker@branda.to>
parents:
373
diff
changeset
|
566 doc, txt_strs, attrs) |
83 | 567 pass |
568 pass | |
279
86a5ae82ccf2
* Modify svg2code_ex to use differnt font size at two test items to illustrate the function of the new text parser
wycc
parents:
278
diff
changeset
|
569 attr[1] = len(txt_strs.encode('utf8')) |
278
a90fd749af82
Implement the whole tspan attribute. Currently, we can accept font family/font style/font weight and font size.
wycc
parents:
241
diff
changeset
|
570 return txt_strs |
83 | 571 |
428
c3faebaec0c4
Reformat svg2code.py to make more compatible witth our convention
Thinker K.F. Li <thinker@branda.to>
parents:
373
diff
changeset
|
572 def pango_generate_font_attributes(attrs,coord_id, codefo,doc): |
278
a90fd749af82
Implement the whole tspan attribute. Currently, we can accept font family/font style/font weight and font size.
wycc
parents:
241
diff
changeset
|
573 for a in attrs: |
a90fd749af82
Implement the whole tspan attribute. Currently, we can accept font family/font style/font weight and font size.
wycc
parents:
241
diff
changeset
|
574 start = a[0] |
a90fd749af82
Implement the whole tspan attribute. Currently, we can accept font family/font style/font weight and font size.
wycc
parents:
241
diff
changeset
|
575 end = a[1] |
a90fd749af82
Implement the whole tspan attribute. Currently, we can accept font family/font style/font weight and font size.
wycc
parents:
241
diff
changeset
|
576 node = a[2] |
a90fd749af82
Implement the whole tspan attribute. Currently, we can accept font family/font style/font weight and font size.
wycc
parents:
241
diff
changeset
|
577 #print "generate attributes from %d to %d" %(start,end) |
a90fd749af82
Implement the whole tspan attribute. Currently, we can accept font family/font style/font weight and font size.
wycc
parents:
241
diff
changeset
|
578 style_map = node.style_map |
a90fd749af82
Implement the whole tspan attribute. Currently, we can accept font family/font style/font weight and font size.
wycc
parents:
241
diff
changeset
|
579 #print [style_map] |
a90fd749af82
Implement the whole tspan attribute. Currently, we can accept font family/font style/font weight and font size.
wycc
parents:
241
diff
changeset
|
580 if style_map.has_key('font-size'): |
a90fd749af82
Implement the whole tspan attribute. Currently, we can accept font family/font style/font weight and font size.
wycc
parents:
241
diff
changeset
|
581 # FIXME: Implement all units here |
a90fd749af82
Implement the whole tspan attribute. Currently, we can accept font family/font style/font weight and font size.
wycc
parents:
241
diff
changeset
|
582 if style_map['font-size'].endswith('px'): |
a90fd749af82
Implement the whole tspan attribute. Currently, we can accept font family/font style/font weight and font size.
wycc
parents:
241
diff
changeset
|
583 font_sz = float(style_map['font-size'][:-2]) |
333
bdf36a26e420
Make generated code clean.
Thinker K.F. Li <thinker@branda.to>
parents:
313
diff
changeset
|
584 print >> codefo, 'PANGO_SIZE(%d,%d,%d)dnl' % (font_sz*1024,start,end) |
278
a90fd749af82
Implement the whole tspan attribute. Currently, we can accept font family/font style/font weight and font size.
wycc
parents:
241
diff
changeset
|
585 else: |
a90fd749af82
Implement the whole tspan attribute. Currently, we can accept font family/font style/font weight and font size.
wycc
parents:
241
diff
changeset
|
586 font_sz = float(style_map['font-size']) |
333
bdf36a26e420
Make generated code clean.
Thinker K.F. Li <thinker@branda.to>
parents:
313
diff
changeset
|
587 print >> codefo, 'PANGO_SIZE(%d,%d,%d)dnl' % (font_sz*1024,start,end) |
428
c3faebaec0c4
Reformat svg2code.py to make more compatible witth our convention
Thinker K.F. Li <thinker@branda.to>
parents:
373
diff
changeset
|
588 pass |
278
a90fd749af82
Implement the whole tspan attribute. Currently, we can accept font family/font style/font weight and font size.
wycc
parents:
241
diff
changeset
|
589 pass |
822
586e50f82c1f
Unify coding style tag for emacs and vim.
Shih-Yuan Lee (FourDollars) <fourdollars@gmail.com>
parents:
458
diff
changeset
|
590 |
278
a90fd749af82
Implement the whole tspan attribute. Currently, we can accept font family/font style/font weight and font size.
wycc
parents:
241
diff
changeset
|
591 if style_map.has_key('font-style'): |
a90fd749af82
Implement the whole tspan attribute. Currently, we can accept font family/font style/font weight and font size.
wycc
parents:
241
diff
changeset
|
592 font_style = style_map['font-style'].lower() |
a90fd749af82
Implement the whole tspan attribute. Currently, we can accept font family/font style/font weight and font size.
wycc
parents:
241
diff
changeset
|
593 if font_style == 'normal': |
333
bdf36a26e420
Make generated code clean.
Thinker K.F. Li <thinker@branda.to>
parents:
313
diff
changeset
|
594 print >> codefo, 'PANGO_STYLE(PANGO_STYLE_NORMAL,%d,%d)dnl' % (start,end) |
278
a90fd749af82
Implement the whole tspan attribute. Currently, we can accept font family/font style/font weight and font size.
wycc
parents:
241
diff
changeset
|
595 elif font_style == 'italic': |
333
bdf36a26e420
Make generated code clean.
Thinker K.F. Li <thinker@branda.to>
parents:
313
diff
changeset
|
596 print >> codefo, 'PANGO_STYLE(PANGO_STYLE_ITALIC,%d,%d)dnl' % (start,end) |
278
a90fd749af82
Implement the whole tspan attribute. Currently, we can accept font family/font style/font weight and font size.
wycc
parents:
241
diff
changeset
|
597 elif font_style == 'oblique': |
333
bdf36a26e420
Make generated code clean.
Thinker K.F. Li <thinker@branda.to>
parents:
313
diff
changeset
|
598 print >> codefo, 'PANGO_STYLE(PANGO_STYLE_OBLIQUE,%d,%d)dnl' % (start,end) |
428
c3faebaec0c4
Reformat svg2code.py to make more compatible witth our convention
Thinker K.F. Li <thinker@branda.to>
parents:
373
diff
changeset
|
599 pass |
c3faebaec0c4
Reformat svg2code.py to make more compatible witth our convention
Thinker K.F. Li <thinker@branda.to>
parents:
373
diff
changeset
|
600 pass |
83 | 601 |
278
a90fd749af82
Implement the whole tspan attribute. Currently, we can accept font family/font style/font weight and font size.
wycc
parents:
241
diff
changeset
|
602 if style_map.has_key('font-family'): |
306 | 603 font_family = style_map['font-family'] |
333
bdf36a26e420
Make generated code clean.
Thinker K.F. Li <thinker@branda.to>
parents:
313
diff
changeset
|
604 print >> codefo, 'PANGO_FAMILY(%s,%d,%d)dnl' % (font_family,start,end) |
428
c3faebaec0c4
Reformat svg2code.py to make more compatible witth our convention
Thinker K.F. Li <thinker@branda.to>
parents:
373
diff
changeset
|
605 pass |
278
a90fd749af82
Implement the whole tspan attribute. Currently, we can accept font family/font style/font weight and font size.
wycc
parents:
241
diff
changeset
|
606 if style_map.has_key('text-anchor'): |
a90fd749af82
Implement the whole tspan attribute. Currently, we can accept font family/font style/font weight and font size.
wycc
parents:
241
diff
changeset
|
607 text_anchor = style_map['text-anchor'].lower() |
a90fd749af82
Implement the whole tspan attribute. Currently, we can accept font family/font style/font weight and font size.
wycc
parents:
241
diff
changeset
|
608 # FIXME: We need to implement a mb_text_set_aligment to implement SVG-styled alignment. |
a90fd749af82
Implement the whole tspan attribute. Currently, we can accept font family/font style/font weight and font size.
wycc
parents:
241
diff
changeset
|
609 print "The text-anchor is not implemented yet" |
428
c3faebaec0c4
Reformat svg2code.py to make more compatible witth our convention
Thinker K.F. Li <thinker@branda.to>
parents:
373
diff
changeset
|
610 pass |
278
a90fd749af82
Implement the whole tspan attribute. Currently, we can accept font family/font style/font weight and font size.
wycc
parents:
241
diff
changeset
|
611 if style_map.has_key('font-variant'): |
a90fd749af82
Implement the whole tspan attribute. Currently, we can accept font family/font style/font weight and font size.
wycc
parents:
241
diff
changeset
|
612 font_variant = style_map['font-variant'].lower() |
a90fd749af82
Implement the whole tspan attribute. Currently, we can accept font family/font style/font weight and font size.
wycc
parents:
241
diff
changeset
|
613 print "The font-variant is not implemented yet" |
428
c3faebaec0c4
Reformat svg2code.py to make more compatible witth our convention
Thinker K.F. Li <thinker@branda.to>
parents:
373
diff
changeset
|
614 pass |
278
a90fd749af82
Implement the whole tspan attribute. Currently, we can accept font family/font style/font weight and font size.
wycc
parents:
241
diff
changeset
|
615 if style_map.has_key('font-weight'): |
a90fd749af82
Implement the whole tspan attribute. Currently, we can accept font family/font style/font weight and font size.
wycc
parents:
241
diff
changeset
|
616 font_weight = style_map['font-weight'].lower() |
a90fd749af82
Implement the whole tspan attribute. Currently, we can accept font family/font style/font weight and font size.
wycc
parents:
241
diff
changeset
|
617 if font_weight == 'normal': |
333
bdf36a26e420
Make generated code clean.
Thinker K.F. Li <thinker@branda.to>
parents:
313
diff
changeset
|
618 print >> codefo, 'PANGO_STYLE(PANGO_WEIGHT_NORMAL,%d,%d)dnl' % (start,end) |
278
a90fd749af82
Implement the whole tspan attribute. Currently, we can accept font family/font style/font weight and font size.
wycc
parents:
241
diff
changeset
|
619 elif font_weight == 'bold': |
333
bdf36a26e420
Make generated code clean.
Thinker K.F. Li <thinker@branda.to>
parents:
313
diff
changeset
|
620 print >> codefo, 'PANGO_STYLE(PANGO_WEIGHT_BOLD,%d,%d)dnl' % (start,end) |
278
a90fd749af82
Implement the whole tspan attribute. Currently, we can accept font family/font style/font weight and font size.
wycc
parents:
241
diff
changeset
|
621 elif font_weight == 'bolder': |
333
bdf36a26e420
Make generated code clean.
Thinker K.F. Li <thinker@branda.to>
parents:
313
diff
changeset
|
622 print >> codefo, 'PANGO_STYLE(PANGO_WEIGHT_HEAVY,%d,%d)dnl' % (start,end) |
278
a90fd749af82
Implement the whole tspan attribute. Currently, we can accept font family/font style/font weight and font size.
wycc
parents:
241
diff
changeset
|
623 elif font_weight == 'lighter': |
333
bdf36a26e420
Make generated code clean.
Thinker K.F. Li <thinker@branda.to>
parents:
313
diff
changeset
|
624 print >> codefo, 'PANGO_STYLE(PANGO_WEIGHT_ULTRALIGHT,%d,%d)dnl' % (start,end) |
278
a90fd749af82
Implement the whole tspan attribute. Currently, we can accept font family/font style/font weight and font size.
wycc
parents:
241
diff
changeset
|
625 elif font_weight == '100': |
333
bdf36a26e420
Make generated code clean.
Thinker K.F. Li <thinker@branda.to>
parents:
313
diff
changeset
|
626 print >> codefo, 'PANGO_STYLE(PANGO_WEIGHT_ULTRALIGHT,%d,%d)dnl' % (start,end) |
278
a90fd749af82
Implement the whole tspan attribute. Currently, we can accept font family/font style/font weight and font size.
wycc
parents:
241
diff
changeset
|
627 elif font_weight == '200': |
333
bdf36a26e420
Make generated code clean.
Thinker K.F. Li <thinker@branda.to>
parents:
313
diff
changeset
|
628 print >> codefo, 'PANGO_STYLE(PANGO_WEIGHT_ULTRALIGHT,%d,%d)dnl' % (start,end) |
278
a90fd749af82
Implement the whole tspan attribute. Currently, we can accept font family/font style/font weight and font size.
wycc
parents:
241
diff
changeset
|
629 elif font_weight == '300': |
333
bdf36a26e420
Make generated code clean.
Thinker K.F. Li <thinker@branda.to>
parents:
313
diff
changeset
|
630 print >> codefo, 'PANGO_STYLE(PANGO_WEIGHT_LIGHT,%d,%d)dnl' % (start,end) |
278
a90fd749af82
Implement the whole tspan attribute. Currently, we can accept font family/font style/font weight and font size.
wycc
parents:
241
diff
changeset
|
631 elif font_weight == '400': |
333
bdf36a26e420
Make generated code clean.
Thinker K.F. Li <thinker@branda.to>
parents:
313
diff
changeset
|
632 print >> codefo, 'PANGO_STYLE(PANGO_WEIGHT_NORMAL,%d,%d)dnl' % (start,end) |
278
a90fd749af82
Implement the whole tspan attribute. Currently, we can accept font family/font style/font weight and font size.
wycc
parents:
241
diff
changeset
|
633 elif font_weight == '500': |
333
bdf36a26e420
Make generated code clean.
Thinker K.F. Li <thinker@branda.to>
parents:
313
diff
changeset
|
634 print >> codefo, 'PANGO_STYLE(PANGO_WEIGHT_NORMAL,%d,%d)dnl' % (start,end) |
278
a90fd749af82
Implement the whole tspan attribute. Currently, we can accept font family/font style/font weight and font size.
wycc
parents:
241
diff
changeset
|
635 elif font_weight == '600': |
333
bdf36a26e420
Make generated code clean.
Thinker K.F. Li <thinker@branda.to>
parents:
313
diff
changeset
|
636 print >> codefo, 'PANGO_STYLE(PANGO_WEIGHT_SEMIBOLD,%d,%d)dnl' % (start,end) |
278
a90fd749af82
Implement the whole tspan attribute. Currently, we can accept font family/font style/font weight and font size.
wycc
parents:
241
diff
changeset
|
637 elif font_weight == '700': |
333
bdf36a26e420
Make generated code clean.
Thinker K.F. Li <thinker@branda.to>
parents:
313
diff
changeset
|
638 print >> codefo, 'PANGO_STYLE(PANGO_WEIGHT_BOLD,%d,%d)dnl' % (start,end) |
278
a90fd749af82
Implement the whole tspan attribute. Currently, we can accept font family/font style/font weight and font size.
wycc
parents:
241
diff
changeset
|
639 elif font_weight == '800': |
333
bdf36a26e420
Make generated code clean.
Thinker K.F. Li <thinker@branda.to>
parents:
313
diff
changeset
|
640 print >> codefo, 'PANGO_STYLE(PANGO_WEIGHT_ULTRABOLD,%d,%d)dnl' % (start,end) |
278
a90fd749af82
Implement the whole tspan attribute. Currently, we can accept font family/font style/font weight and font size.
wycc
parents:
241
diff
changeset
|
641 elif font_weight == '900': |
333
bdf36a26e420
Make generated code clean.
Thinker K.F. Li <thinker@branda.to>
parents:
313
diff
changeset
|
642 print >> codefo, 'PANGO_STYLE(PANGO_WEIGHT_HEAVY,%d,%d)dnl' % (start,end) |
278
a90fd749af82
Implement the whole tspan attribute. Currently, we can accept font family/font style/font weight and font size.
wycc
parents:
241
diff
changeset
|
643 else: |
a90fd749af82
Implement the whole tspan attribute. Currently, we can accept font family/font style/font weight and font size.
wycc
parents:
241
diff
changeset
|
644 print "The font-weight %s is not supported" % font_weight |
428
c3faebaec0c4
Reformat svg2code.py to make more compatible witth our convention
Thinker K.F. Li <thinker@branda.to>
parents:
373
diff
changeset
|
645 pass |
c3faebaec0c4
Reformat svg2code.py to make more compatible witth our convention
Thinker K.F. Li <thinker@branda.to>
parents:
373
diff
changeset
|
646 pass |
278
a90fd749af82
Implement the whole tspan attribute. Currently, we can accept font family/font style/font weight and font size.
wycc
parents:
241
diff
changeset
|
647 if style_map.has_key('direction'): |
a90fd749af82
Implement the whole tspan attribute. Currently, we can accept font family/font style/font weight and font size.
wycc
parents:
241
diff
changeset
|
648 direction = style_map['direction'].lower() |
a90fd749af82
Implement the whole tspan attribute. Currently, we can accept font family/font style/font weight and font size.
wycc
parents:
241
diff
changeset
|
649 print "The direction is not implemented yet" |
428
c3faebaec0c4
Reformat svg2code.py to make more compatible witth our convention
Thinker K.F. Li <thinker@branda.to>
parents:
373
diff
changeset
|
650 pass |
278
a90fd749af82
Implement the whole tspan attribute. Currently, we can accept font family/font style/font weight and font size.
wycc
parents:
241
diff
changeset
|
651 if style_map.has_key('unicode-bidi'): |
a90fd749af82
Implement the whole tspan attribute. Currently, we can accept font family/font style/font weight and font size.
wycc
parents:
241
diff
changeset
|
652 bidi = style_map['unicode-bidi'].lower() |
a90fd749af82
Implement the whole tspan attribute. Currently, we can accept font family/font style/font weight and font size.
wycc
parents:
241
diff
changeset
|
653 print "The bidi is not implemented yet" |
428
c3faebaec0c4
Reformat svg2code.py to make more compatible witth our convention
Thinker K.F. Li <thinker@branda.to>
parents:
373
diff
changeset
|
654 pass |
83 | 655 pass |
656 pass | |
657 | |
428
c3faebaec0c4
Reformat svg2code.py to make more compatible witth our convention
Thinker K.F. Li <thinker@branda.to>
parents:
373
diff
changeset
|
658 def pango_gen_text(text, coord_id, codefo, doc, txt_strs, attrs): |
83 | 659 if txt_strs: |
210
3fadd2f2742e
M4 macros to generate code for dynamic loading.
Thinker K.F. Li <thinker@branda.to>
parents:
197
diff
changeset
|
660 text_id = _get_id(text) |
83 | 661 x = float(text.getAttribute('x')) |
662 y = float(text.getAttribute('y')) | |
663 print >> codefo, 'dnl' | |
664 print >> codefo, \ | |
278
a90fd749af82
Implement the whole tspan attribute. Currently, we can accept font family/font style/font weight and font size.
wycc
parents:
241
diff
changeset
|
665 'PANGO_BEGIN_TEXT([%s], [%s], %f, %f, 16, [%s])dnl' % ( |
83 | 666 text_id.encode('utf8'), u''.join(txt_strs).encode('utf8'), |
667 x, y, coord_id.encode('utf8')) | |
428
c3faebaec0c4
Reformat svg2code.py to make more compatible witth our convention
Thinker K.F. Li <thinker@branda.to>
parents:
373
diff
changeset
|
668 pango_generate_font_attributes(attrs, coord_id, codefo, doc) |
278
a90fd749af82
Implement the whole tspan attribute. Currently, we can accept font family/font style/font weight and font size.
wycc
parents:
241
diff
changeset
|
669 print >> codefo, \ |
a90fd749af82
Implement the whole tspan attribute. Currently, we can accept font family/font style/font weight and font size.
wycc
parents:
241
diff
changeset
|
670 'PANGO_END_TEXT([%s], [%s], %f, %f, 16, [%s])dnl' % ( |
a90fd749af82
Implement the whole tspan attribute. Currently, we can accept font family/font style/font weight and font size.
wycc
parents:
241
diff
changeset
|
671 text_id.encode('utf8'), u''.join(txt_strs).encode('utf8'), |
a90fd749af82
Implement the whole tspan attribute. Currently, we can accept font family/font style/font weight and font size.
wycc
parents:
241
diff
changeset
|
672 x, y, coord_id.encode('utf8')) |
a90fd749af82
Implement the whole tspan attribute. Currently, we can accept font family/font style/font weight and font size.
wycc
parents:
241
diff
changeset
|
673 translate_style(text, coord_id, codefo, doc, 'TEXT_') |
431
bf1addb037b7
Add -s option to svg2code.py.
Thinker K.F. Li <thinker@branda.to>
parents:
428
diff
changeset
|
674 pass |
bf1addb037b7
Add -s option to svg2code.py.
Thinker K.F. Li <thinker@branda.to>
parents:
428
diff
changeset
|
675 pass |
bf1addb037b7
Add -s option to svg2code.py.
Thinker K.F. Li <thinker@branda.to>
parents:
428
diff
changeset
|
676 |
bf1addb037b7
Add -s option to svg2code.py.
Thinker K.F. Li <thinker@branda.to>
parents:
428
diff
changeset
|
677 def stext_generate_font_attributes(text, attrs, coord_id, codefo, doc): |
bf1addb037b7
Add -s option to svg2code.py.
Thinker K.F. Li <thinker@branda.to>
parents:
428
diff
changeset
|
678 text_id = _get_id(text) |
822
586e50f82c1f
Unify coding style tag for emacs and vim.
Shih-Yuan Lee (FourDollars) <fourdollars@gmail.com>
parents:
458
diff
changeset
|
679 |
431
bf1addb037b7
Add -s option to svg2code.py.
Thinker K.F. Li <thinker@branda.to>
parents:
428
diff
changeset
|
680 for start, end, node in attrs: |
bf1addb037b7
Add -s option to svg2code.py.
Thinker K.F. Li <thinker@branda.to>
parents:
428
diff
changeset
|
681 style_map = node.style_map |
822
586e50f82c1f
Unify coding style tag for emacs and vim.
Shih-Yuan Lee (FourDollars) <fourdollars@gmail.com>
parents:
458
diff
changeset
|
682 |
431
bf1addb037b7
Add -s option to svg2code.py.
Thinker K.F. Li <thinker@branda.to>
parents:
428
diff
changeset
|
683 font_sz = 10 |
bf1addb037b7
Add -s option to svg2code.py.
Thinker K.F. Li <thinker@branda.to>
parents:
428
diff
changeset
|
684 if style_map.has_key('font-size'): |
bf1addb037b7
Add -s option to svg2code.py.
Thinker K.F. Li <thinker@branda.to>
parents:
428
diff
changeset
|
685 fsz = style_map['font-size'] |
bf1addb037b7
Add -s option to svg2code.py.
Thinker K.F. Li <thinker@branda.to>
parents:
428
diff
changeset
|
686 if fsz.endswith('px'): |
bf1addb037b7
Add -s option to svg2code.py.
Thinker K.F. Li <thinker@branda.to>
parents:
428
diff
changeset
|
687 font_sz = float(fsz[:-2]) |
bf1addb037b7
Add -s option to svg2code.py.
Thinker K.F. Li <thinker@branda.to>
parents:
428
diff
changeset
|
688 else: |
bf1addb037b7
Add -s option to svg2code.py.
Thinker K.F. Li <thinker@branda.to>
parents:
428
diff
changeset
|
689 font_sz = float(fsz) |
bf1addb037b7
Add -s option to svg2code.py.
Thinker K.F. Li <thinker@branda.to>
parents:
428
diff
changeset
|
690 pass |
bf1addb037b7
Add -s option to svg2code.py.
Thinker K.F. Li <thinker@branda.to>
parents:
428
diff
changeset
|
691 pass |
822
586e50f82c1f
Unify coding style tag for emacs and vim.
Shih-Yuan Lee (FourDollars) <fourdollars@gmail.com>
parents:
458
diff
changeset
|
692 |
431
bf1addb037b7
Add -s option to svg2code.py.
Thinker K.F. Li <thinker@branda.to>
parents:
428
diff
changeset
|
693 if style_map.has_key('font-family'): |
bf1addb037b7
Add -s option to svg2code.py.
Thinker K.F. Li <thinker@branda.to>
parents:
428
diff
changeset
|
694 font_family = style_map['font-family'] |
bf1addb037b7
Add -s option to svg2code.py.
Thinker K.F. Li <thinker@branda.to>
parents:
428
diff
changeset
|
695 else: |
bf1addb037b7
Add -s option to svg2code.py.
Thinker K.F. Li <thinker@branda.to>
parents:
428
diff
changeset
|
696 font_family = 'serif' |
bf1addb037b7
Add -s option to svg2code.py.
Thinker K.F. Li <thinker@branda.to>
parents:
428
diff
changeset
|
697 pass |
822
586e50f82c1f
Unify coding style tag for emacs and vim.
Shih-Yuan Lee (FourDollars) <fourdollars@gmail.com>
parents:
458
diff
changeset
|
698 |
431
bf1addb037b7
Add -s option to svg2code.py.
Thinker K.F. Li <thinker@branda.to>
parents:
428
diff
changeset
|
699 font_slant = 0 |
bf1addb037b7
Add -s option to svg2code.py.
Thinker K.F. Li <thinker@branda.to>
parents:
428
diff
changeset
|
700 if style_map.has_key('font-style'): |
bf1addb037b7
Add -s option to svg2code.py.
Thinker K.F. Li <thinker@branda.to>
parents:
428
diff
changeset
|
701 fn_style = style_map['font-style'] |
bf1addb037b7
Add -s option to svg2code.py.
Thinker K.F. Li <thinker@branda.to>
parents:
428
diff
changeset
|
702 if fn_style == 'normal': |
bf1addb037b7
Add -s option to svg2code.py.
Thinker K.F. Li <thinker@branda.to>
parents:
428
diff
changeset
|
703 font_slant = 0 |
bf1addb037b7
Add -s option to svg2code.py.
Thinker K.F. Li <thinker@branda.to>
parents:
428
diff
changeset
|
704 elif fn_style == 'italic': |
bf1addb037b7
Add -s option to svg2code.py.
Thinker K.F. Li <thinker@branda.to>
parents:
428
diff
changeset
|
705 font_slant = 100 |
bf1addb037b7
Add -s option to svg2code.py.
Thinker K.F. Li <thinker@branda.to>
parents:
428
diff
changeset
|
706 elif fn_style == 'oblique': |
bf1addb037b7
Add -s option to svg2code.py.
Thinker K.F. Li <thinker@branda.to>
parents:
428
diff
changeset
|
707 font_slant = 110 |
bf1addb037b7
Add -s option to svg2code.py.
Thinker K.F. Li <thinker@branda.to>
parents:
428
diff
changeset
|
708 else: |
bf1addb037b7
Add -s option to svg2code.py.
Thinker K.F. Li <thinker@branda.to>
parents:
428
diff
changeset
|
709 raise ValueError, '%s is not a valid font-style' % (fn_style) |
bf1addb037b7
Add -s option to svg2code.py.
Thinker K.F. Li <thinker@branda.to>
parents:
428
diff
changeset
|
710 pass |
822
586e50f82c1f
Unify coding style tag for emacs and vim.
Shih-Yuan Lee (FourDollars) <fourdollars@gmail.com>
parents:
458
diff
changeset
|
711 |
431
bf1addb037b7
Add -s option to svg2code.py.
Thinker K.F. Li <thinker@branda.to>
parents:
428
diff
changeset
|
712 font_weight = 80 |
bf1addb037b7
Add -s option to svg2code.py.
Thinker K.F. Li <thinker@branda.to>
parents:
428
diff
changeset
|
713 if style_map.has_key('font-weight'): |
bf1addb037b7
Add -s option to svg2code.py.
Thinker K.F. Li <thinker@branda.to>
parents:
428
diff
changeset
|
714 fn_weight = style_map['font-weight'] |
bf1addb037b7
Add -s option to svg2code.py.
Thinker K.F. Li <thinker@branda.to>
parents:
428
diff
changeset
|
715 if fn_weight == 'normal': |
bf1addb037b7
Add -s option to svg2code.py.
Thinker K.F. Li <thinker@branda.to>
parents:
428
diff
changeset
|
716 font_weight = 80 |
bf1addb037b7
Add -s option to svg2code.py.
Thinker K.F. Li <thinker@branda.to>
parents:
428
diff
changeset
|
717 elif fn_weight == 'medium': |
bf1addb037b7
Add -s option to svg2code.py.
Thinker K.F. Li <thinker@branda.to>
parents:
428
diff
changeset
|
718 font_weight = 100 |
bf1addb037b7
Add -s option to svg2code.py.
Thinker K.F. Li <thinker@branda.to>
parents:
428
diff
changeset
|
719 elif fn_weight == 'bold': |
bf1addb037b7
Add -s option to svg2code.py.
Thinker K.F. Li <thinker@branda.to>
parents:
428
diff
changeset
|
720 font_weight = 200 |
bf1addb037b7
Add -s option to svg2code.py.
Thinker K.F. Li <thinker@branda.to>
parents:
428
diff
changeset
|
721 elif fn_weight == 'bolder': |
bf1addb037b7
Add -s option to svg2code.py.
Thinker K.F. Li <thinker@branda.to>
parents:
428
diff
changeset
|
722 font_weight = 150 |
bf1addb037b7
Add -s option to svg2code.py.
Thinker K.F. Li <thinker@branda.to>
parents:
428
diff
changeset
|
723 elif fn_weight == 'light': |
bf1addb037b7
Add -s option to svg2code.py.
Thinker K.F. Li <thinker@branda.to>
parents:
428
diff
changeset
|
724 font_weight = 50 |
bf1addb037b7
Add -s option to svg2code.py.
Thinker K.F. Li <thinker@branda.to>
parents:
428
diff
changeset
|
725 elif fn_weight == 'lighter': |
bf1addb037b7
Add -s option to svg2code.py.
Thinker K.F. Li <thinker@branda.to>
parents:
428
diff
changeset
|
726 font_weight = 70 |
bf1addb037b7
Add -s option to svg2code.py.
Thinker K.F. Li <thinker@branda.to>
parents:
428
diff
changeset
|
727 else: |
bf1addb037b7
Add -s option to svg2code.py.
Thinker K.F. Li <thinker@branda.to>
parents:
428
diff
changeset
|
728 font_weight = int(fn_weight) |
bf1addb037b7
Add -s option to svg2code.py.
Thinker K.F. Li <thinker@branda.to>
parents:
428
diff
changeset
|
729 pass |
bf1addb037b7
Add -s option to svg2code.py.
Thinker K.F. Li <thinker@branda.to>
parents:
428
diff
changeset
|
730 pass |
822
586e50f82c1f
Unify coding style tag for emacs and vim.
Shih-Yuan Lee (FourDollars) <fourdollars@gmail.com>
parents:
458
diff
changeset
|
731 |
431
bf1addb037b7
Add -s option to svg2code.py.
Thinker K.F. Li <thinker@branda.to>
parents:
428
diff
changeset
|
732 print >> codefo, 'STYLE_BLOCK([%s], %d, [%s], %f, %d, %d)dnl' % ( |
bf1addb037b7
Add -s option to svg2code.py.
Thinker K.F. Li <thinker@branda.to>
parents:
428
diff
changeset
|
733 text_id, end - start, font_family, font_sz, |
bf1addb037b7
Add -s option to svg2code.py.
Thinker K.F. Li <thinker@branda.to>
parents:
428
diff
changeset
|
734 font_slant, font_weight) |
257
50d253d0fcba
Simple image loader and image shape.
Thinker K.F. Li <thinker@branda.to>
parents:
241
diff
changeset
|
735 pass |
50d253d0fcba
Simple image loader and image shape.
Thinker K.F. Li <thinker@branda.to>
parents:
241
diff
changeset
|
736 pass |
50d253d0fcba
Simple image loader and image shape.
Thinker K.F. Li <thinker@branda.to>
parents:
241
diff
changeset
|
737 |
428
c3faebaec0c4
Reformat svg2code.py to make more compatible witth our convention
Thinker K.F. Li <thinker@branda.to>
parents:
373
diff
changeset
|
738 def stext_gen_text(text, coord_id, codefo, doc, txt_strs, attrs): |
431
bf1addb037b7
Add -s option to svg2code.py.
Thinker K.F. Li <thinker@branda.to>
parents:
428
diff
changeset
|
739 if not txt_strs: |
bf1addb037b7
Add -s option to svg2code.py.
Thinker K.F. Li <thinker@branda.to>
parents:
428
diff
changeset
|
740 return |
822
586e50f82c1f
Unify coding style tag for emacs and vim.
Shih-Yuan Lee (FourDollars) <fourdollars@gmail.com>
parents:
458
diff
changeset
|
741 |
431
bf1addb037b7
Add -s option to svg2code.py.
Thinker K.F. Li <thinker@branda.to>
parents:
428
diff
changeset
|
742 text_id = _get_id(text) |
bf1addb037b7
Add -s option to svg2code.py.
Thinker K.F. Li <thinker@branda.to>
parents:
428
diff
changeset
|
743 x = float(text.getAttribute('x')) |
bf1addb037b7
Add -s option to svg2code.py.
Thinker K.F. Li <thinker@branda.to>
parents:
428
diff
changeset
|
744 y = float(text.getAttribute('y')) |
bf1addb037b7
Add -s option to svg2code.py.
Thinker K.F. Li <thinker@branda.to>
parents:
428
diff
changeset
|
745 print >> codefo, 'dnl' |
bf1addb037b7
Add -s option to svg2code.py.
Thinker K.F. Li <thinker@branda.to>
parents:
428
diff
changeset
|
746 print >> codefo, \ |
bf1addb037b7
Add -s option to svg2code.py.
Thinker K.F. Li <thinker@branda.to>
parents:
428
diff
changeset
|
747 'ADD_STEXT([%s], [%s], %f, %f, [%s])dnl' % \ |
bf1addb037b7
Add -s option to svg2code.py.
Thinker K.F. Li <thinker@branda.to>
parents:
428
diff
changeset
|
748 (text_id, txt_strs.encode('utf8'), x, y, coord_id) |
bf1addb037b7
Add -s option to svg2code.py.
Thinker K.F. Li <thinker@branda.to>
parents:
428
diff
changeset
|
749 translate_style(text, coord_id, codefo, doc, 'STEXT_') |
bf1addb037b7
Add -s option to svg2code.py.
Thinker K.F. Li <thinker@branda.to>
parents:
428
diff
changeset
|
750 stext_generate_font_attributes(text, attrs, coord_id, codefo, doc) |
428
c3faebaec0c4
Reformat svg2code.py to make more compatible witth our convention
Thinker K.F. Li <thinker@branda.to>
parents:
373
diff
changeset
|
751 pass |
c3faebaec0c4
Reformat svg2code.py to make more compatible witth our convention
Thinker K.F. Li <thinker@branda.to>
parents:
373
diff
changeset
|
752 |
c3faebaec0c4
Reformat svg2code.py to make more compatible witth our convention
Thinker K.F. Li <thinker@branda.to>
parents:
373
diff
changeset
|
753 def gen_text(text, coord_id, codefo, doc, txt_strs, attrs): |
c3faebaec0c4
Reformat svg2code.py to make more compatible witth our convention
Thinker K.F. Li <thinker@branda.to>
parents:
373
diff
changeset
|
754 raise NotImplementedError, \ |
c3faebaec0c4
Reformat svg2code.py to make more compatible witth our convention
Thinker K.F. Li <thinker@branda.to>
parents:
373
diff
changeset
|
755 'gen_text should be assigned to an implementation' |
c3faebaec0c4
Reformat svg2code.py to make more compatible witth our convention
Thinker K.F. Li <thinker@branda.to>
parents:
373
diff
changeset
|
756 |
c3faebaec0c4
Reformat svg2code.py to make more compatible witth our convention
Thinker K.F. Li <thinker@branda.to>
parents:
373
diff
changeset
|
757 @check_mbname |
c3faebaec0c4
Reformat svg2code.py to make more compatible witth our convention
Thinker K.F. Li <thinker@branda.to>
parents:
373
diff
changeset
|
758 def translate_text(text, coord_id, codefo, doc): |
434 | 759 coord_id = translate_shape_transform(text, coord_id, codefo) |
428
c3faebaec0c4
Reformat svg2code.py to make more compatible witth our convention
Thinker K.F. Li <thinker@branda.to>
parents:
373
diff
changeset
|
760 try: |
c3faebaec0c4
Reformat svg2code.py to make more compatible witth our convention
Thinker K.F. Li <thinker@branda.to>
parents:
373
diff
changeset
|
761 map = text.style_map |
822
586e50f82c1f
Unify coding style tag for emacs and vim.
Shih-Yuan Lee (FourDollars) <fourdollars@gmail.com>
parents:
458
diff
changeset
|
762 except: |
428
c3faebaec0c4
Reformat svg2code.py to make more compatible witth our convention
Thinker K.F. Li <thinker@branda.to>
parents:
373
diff
changeset
|
763 map = translate_font_style(text, codefo) |
c3faebaec0c4
Reformat svg2code.py to make more compatible witth our convention
Thinker K.F. Li <thinker@branda.to>
parents:
373
diff
changeset
|
764 text.style_map = map |
c3faebaec0c4
Reformat svg2code.py to make more compatible witth our convention
Thinker K.F. Li <thinker@branda.to>
parents:
373
diff
changeset
|
765 pass |
c3faebaec0c4
Reformat svg2code.py to make more compatible witth our convention
Thinker K.F. Li <thinker@branda.to>
parents:
373
diff
changeset
|
766 attrs = [] |
c3faebaec0c4
Reformat svg2code.py to make more compatible witth our convention
Thinker K.F. Li <thinker@branda.to>
parents:
373
diff
changeset
|
767 attr = [0, 0, text] |
c3faebaec0c4
Reformat svg2code.py to make more compatible witth our convention
Thinker K.F. Li <thinker@branda.to>
parents:
373
diff
changeset
|
768 attrs.append(attr) |
c3faebaec0c4
Reformat svg2code.py to make more compatible witth our convention
Thinker K.F. Li <thinker@branda.to>
parents:
373
diff
changeset
|
769 |
c3faebaec0c4
Reformat svg2code.py to make more compatible witth our convention
Thinker K.F. Li <thinker@branda.to>
parents:
373
diff
changeset
|
770 txt_strs = '' |
c3faebaec0c4
Reformat svg2code.py to make more compatible witth our convention
Thinker K.F. Li <thinker@branda.to>
parents:
373
diff
changeset
|
771 for node in text.childNodes: |
c3faebaec0c4
Reformat svg2code.py to make more compatible witth our convention
Thinker K.F. Li <thinker@branda.to>
parents:
373
diff
changeset
|
772 if node.localName == None: |
c3faebaec0c4
Reformat svg2code.py to make more compatible witth our convention
Thinker K.F. Li <thinker@branda.to>
parents:
373
diff
changeset
|
773 txt_strs = txt_strs + node.data |
c3faebaec0c4
Reformat svg2code.py to make more compatible witth our convention
Thinker K.F. Li <thinker@branda.to>
parents:
373
diff
changeset
|
774 elif node.localName == 'tspan': |
431
bf1addb037b7
Add -s option to svg2code.py.
Thinker K.F. Li <thinker@branda.to>
parents:
428
diff
changeset
|
775 txt_strs = translate_tspan(node, text, coord_id, codefo, |
428
c3faebaec0c4
Reformat svg2code.py to make more compatible witth our convention
Thinker K.F. Li <thinker@branda.to>
parents:
373
diff
changeset
|
776 doc,txt_strs, attrs) |
c3faebaec0c4
Reformat svg2code.py to make more compatible witth our convention
Thinker K.F. Li <thinker@branda.to>
parents:
373
diff
changeset
|
777 pass |
c3faebaec0c4
Reformat svg2code.py to make more compatible witth our convention
Thinker K.F. Li <thinker@branda.to>
parents:
373
diff
changeset
|
778 pass |
c3faebaec0c4
Reformat svg2code.py to make more compatible witth our convention
Thinker K.F. Li <thinker@branda.to>
parents:
373
diff
changeset
|
779 attr[1] = len(txt_strs.encode('utf8')) |
c3faebaec0c4
Reformat svg2code.py to make more compatible witth our convention
Thinker K.F. Li <thinker@branda.to>
parents:
373
diff
changeset
|
780 gen_text(text, coord_id, codefo, doc, txt_strs, attrs) |
c3faebaec0c4
Reformat svg2code.py to make more compatible witth our convention
Thinker K.F. Li <thinker@branda.to>
parents:
373
diff
changeset
|
781 pass |
c3faebaec0c4
Reformat svg2code.py to make more compatible witth our convention
Thinker K.F. Li <thinker@branda.to>
parents:
373
diff
changeset
|
782 |
310 | 783 @check_mbname |
784 def translate_image(image, coord_id, codefo, doc): | |
785 coord_id = translate_shape_transform(image, coord_id, codefo) | |
822
586e50f82c1f
Unify coding style tag for emacs and vim.
Shih-Yuan Lee (FourDollars) <fourdollars@gmail.com>
parents:
458
diff
changeset
|
786 |
310 | 787 image_id = _get_id(image) |
788 if not image.hasAttributeNS(xlinkns, 'href'): | |
789 raise ValueError, 'image %s must has a href attribute.' % (image_id) | |
790 href = image.getAttributeNS(xlinkns, 'href') | |
791 if image.hasAttribute('x'): | |
792 x_str = image.getAttribute('x') | |
793 x = float(x_str) | |
794 else: | |
795 x = 0 | |
796 pass | |
797 if image.hasAttribute('y'): | |
798 y_str = image.getAttribute('y') | |
799 y = float(y_str) | |
800 else: | |
801 y = 0 | |
802 pass | |
803 if image.hasAttribute('width'): | |
804 width_str = image.getAttribute('width') | |
805 width = float(width_str) | |
806 else: | |
807 width = -1 | |
808 pass | |
809 if image.hasAttribute('height'): | |
810 height_str = image.getAttribute('height') | |
811 height = float(height_str) | |
812 else: | |
813 height = -1 | |
814 pass | |
815 print >> codefo, 'dnl' | |
816 print >> codefo, \ | |
817 'ADD_IMAGE([%s], [%s], %f, %f, %f, %f, [%s])dnl' % ( | |
818 image_id, href, x, y, width, height, coord_id) | |
819 pass | |
822
586e50f82c1f
Unify coding style tag for emacs and vim.
Shih-Yuan Lee (FourDollars) <fourdollars@gmail.com>
parents:
458
diff
changeset
|
820 |
310 | 821 |
85
9b4a02bcaeb1
matrix() function in transform attribute of group and shapes
Thinker K.F. Li <thinker@branda.to>
parents:
84
diff
changeset
|
822 reo_func = re.compile('([a-zA-Z]+)\\([^\\)]*\\)') |
9b4a02bcaeb1
matrix() function in transform attribute of group and shapes
Thinker K.F. Li <thinker@branda.to>
parents:
84
diff
changeset
|
823 reo_translate = re.compile('translate\\(([-+]?[0-9]+(\\.[0-9]+)?),([-+]?[0-9]+(\\.[0-9]+)?)\\)') |
9b4a02bcaeb1
matrix() function in transform attribute of group and shapes
Thinker K.F. Li <thinker@branda.to>
parents:
84
diff
changeset
|
824 reo_matrix = re.compile('matrix\\(([-+]?[0-9]+(\\.[0-9]+)?),([-+]?[0-9]+(\\.[0-9]+)?),([-+]?[0-9]+(\\.[0-9]+)?),([-+]?[0-9]+(\\.[0-9]+)?),([-+]?[0-9]+(\\.[0-9]+)?),([-+]?[0-9]+(\\.[0-9]+)?)\\)') |
9b4a02bcaeb1
matrix() function in transform attribute of group and shapes
Thinker K.F. Li <thinker@branda.to>
parents:
84
diff
changeset
|
825 def translate_transform(coord_id, transform, codefo, prefix): |
84
42698de1f653
Support translate() function for transform attribute of 'g' tag.
Thinker K.F. Li <thinker@branda.to>
parents:
83
diff
changeset
|
826 transform = transform.strip() |
85
9b4a02bcaeb1
matrix() function in transform attribute of group and shapes
Thinker K.F. Li <thinker@branda.to>
parents:
84
diff
changeset
|
827 mo = reo_func.match(transform) |
9b4a02bcaeb1
matrix() function in transform attribute of group and shapes
Thinker K.F. Li <thinker@branda.to>
parents:
84
diff
changeset
|
828 if not mo: |
9b4a02bcaeb1
matrix() function in transform attribute of group and shapes
Thinker K.F. Li <thinker@branda.to>
parents:
84
diff
changeset
|
829 return |
9b4a02bcaeb1
matrix() function in transform attribute of group and shapes
Thinker K.F. Li <thinker@branda.to>
parents:
84
diff
changeset
|
830 name = mo.group(1) |
9b4a02bcaeb1
matrix() function in transform attribute of group and shapes
Thinker K.F. Li <thinker@branda.to>
parents:
84
diff
changeset
|
831 if name == 'translate': |
9b4a02bcaeb1
matrix() function in transform attribute of group and shapes
Thinker K.F. Li <thinker@branda.to>
parents:
84
diff
changeset
|
832 mo = reo_translate.match(transform) |
9b4a02bcaeb1
matrix() function in transform attribute of group and shapes
Thinker K.F. Li <thinker@branda.to>
parents:
84
diff
changeset
|
833 if mo: |
9b4a02bcaeb1
matrix() function in transform attribute of group and shapes
Thinker K.F. Li <thinker@branda.to>
parents:
84
diff
changeset
|
834 x = float(mo.group(1)) |
9b4a02bcaeb1
matrix() function in transform attribute of group and shapes
Thinker K.F. Li <thinker@branda.to>
parents:
84
diff
changeset
|
835 y = float(mo.group(3)) |
9b4a02bcaeb1
matrix() function in transform attribute of group and shapes
Thinker K.F. Li <thinker@branda.to>
parents:
84
diff
changeset
|
836 print >> codefo, '%sTRANSLATE([%s], %f, %f)dnl' % ( |
9b4a02bcaeb1
matrix() function in transform attribute of group and shapes
Thinker K.F. Li <thinker@branda.to>
parents:
84
diff
changeset
|
837 prefix, coord_id, x, y) |
9b4a02bcaeb1
matrix() function in transform attribute of group and shapes
Thinker K.F. Li <thinker@branda.to>
parents:
84
diff
changeset
|
838 pass |
9b4a02bcaeb1
matrix() function in transform attribute of group and shapes
Thinker K.F. Li <thinker@branda.to>
parents:
84
diff
changeset
|
839 elif name == 'matrix': |
9b4a02bcaeb1
matrix() function in transform attribute of group and shapes
Thinker K.F. Li <thinker@branda.to>
parents:
84
diff
changeset
|
840 mo = reo_matrix.match(transform) |
9b4a02bcaeb1
matrix() function in transform attribute of group and shapes
Thinker K.F. Li <thinker@branda.to>
parents:
84
diff
changeset
|
841 if mo: |
9b4a02bcaeb1
matrix() function in transform attribute of group and shapes
Thinker K.F. Li <thinker@branda.to>
parents:
84
diff
changeset
|
842 r10, r11, r12 = \ |
9b4a02bcaeb1
matrix() function in transform attribute of group and shapes
Thinker K.F. Li <thinker@branda.to>
parents:
84
diff
changeset
|
843 float(mo.group(1)), float(mo.group(3)), float(mo.group(5)) |
9b4a02bcaeb1
matrix() function in transform attribute of group and shapes
Thinker K.F. Li <thinker@branda.to>
parents:
84
diff
changeset
|
844 r20, r21, r22 = \ |
9b4a02bcaeb1
matrix() function in transform attribute of group and shapes
Thinker K.F. Li <thinker@branda.to>
parents:
84
diff
changeset
|
845 float(mo.group(7)), float(mo.group(9)), float(mo.group(11)) |
9b4a02bcaeb1
matrix() function in transform attribute of group and shapes
Thinker K.F. Li <thinker@branda.to>
parents:
84
diff
changeset
|
846 print >> codefo, \ |
9b4a02bcaeb1
matrix() function in transform attribute of group and shapes
Thinker K.F. Li <thinker@branda.to>
parents:
84
diff
changeset
|
847 '%sMATRIX([%s], %f, %f, %f, %f, %f, %f)dnl' % ( |
9b4a02bcaeb1
matrix() function in transform attribute of group and shapes
Thinker K.F. Li <thinker@branda.to>
parents:
84
diff
changeset
|
848 prefix, coord_id, r10, r11, r12, r20, r21, r22) |
9b4a02bcaeb1
matrix() function in transform attribute of group and shapes
Thinker K.F. Li <thinker@branda.to>
parents:
84
diff
changeset
|
849 pass |
84
42698de1f653
Support translate() function for transform attribute of 'g' tag.
Thinker K.F. Li <thinker@branda.to>
parents:
83
diff
changeset
|
850 pass |
42698de1f653
Support translate() function for transform attribute of 'g' tag.
Thinker K.F. Li <thinker@branda.to>
parents:
83
diff
changeset
|
851 pass |
42698de1f653
Support translate() function for transform attribute of 'g' tag.
Thinker K.F. Li <thinker@branda.to>
parents:
83
diff
changeset
|
852 |
210
3fadd2f2742e
M4 macros to generate code for dynamic loading.
Thinker K.F. Li <thinker@branda.to>
parents:
197
diff
changeset
|
853 @check_mbname |
62
7d976d925431
Generate C header files for SVG files.
Thinker K.F. Li <thinker@branda.to>
parents:
diff
changeset
|
854 def translate_group(group, parent_id, codefo, doc): |
210
3fadd2f2742e
M4 macros to generate code for dynamic loading.
Thinker K.F. Li <thinker@branda.to>
parents:
197
diff
changeset
|
855 group_id = _get_id(group) |
62
7d976d925431
Generate C header files for SVG files.
Thinker K.F. Li <thinker@branda.to>
parents:
diff
changeset
|
856 print >> codefo, 'dnl' |
7d976d925431
Generate C header files for SVG files.
Thinker K.F. Li <thinker@branda.to>
parents:
diff
changeset
|
857 print >> codefo, 'ADD_COORD([%s], [%s])dnl' % (group_id, parent_id) |
84
42698de1f653
Support translate() function for transform attribute of 'g' tag.
Thinker K.F. Li <thinker@branda.to>
parents:
83
diff
changeset
|
858 |
42698de1f653
Support translate() function for transform attribute of 'g' tag.
Thinker K.F. Li <thinker@branda.to>
parents:
83
diff
changeset
|
859 if group.hasAttribute('transform'): |
42698de1f653
Support translate() function for transform attribute of 'g' tag.
Thinker K.F. Li <thinker@branda.to>
parents:
83
diff
changeset
|
860 transform = group.getAttribute('transform') |
85
9b4a02bcaeb1
matrix() function in transform attribute of group and shapes
Thinker K.F. Li <thinker@branda.to>
parents:
84
diff
changeset
|
861 translate_transform(group_id, transform, codefo, 'COORD_') |
84
42698de1f653
Support translate() function for transform attribute of 'g' tag.
Thinker K.F. Li <thinker@branda.to>
parents:
83
diff
changeset
|
862 pass |
42698de1f653
Support translate() function for transform attribute of 'g' tag.
Thinker K.F. Li <thinker@branda.to>
parents:
83
diff
changeset
|
863 |
434 | 864 mock_sn = 0 |
81 | 865 translate_style(group, group_id, codefo, doc, 'GROUP_') |
62
7d976d925431
Generate C header files for SVG files.
Thinker K.F. Li <thinker@branda.to>
parents:
diff
changeset
|
866 for node in group.childNodes: |
7d976d925431
Generate C header files for SVG files.
Thinker K.F. Li <thinker@branda.to>
parents:
diff
changeset
|
867 if node.namespaceURI != svgns: |
7d976d925431
Generate C header files for SVG files.
Thinker K.F. Li <thinker@branda.to>
parents:
diff
changeset
|
868 continue |
7d976d925431
Generate C header files for SVG files.
Thinker K.F. Li <thinker@branda.to>
parents:
diff
changeset
|
869 if node.localName == 'g': |
7d976d925431
Generate C header files for SVG files.
Thinker K.F. Li <thinker@branda.to>
parents:
diff
changeset
|
870 translate_group(node, group_id, codefo, doc) |
7d976d925431
Generate C header files for SVG files.
Thinker K.F. Li <thinker@branda.to>
parents:
diff
changeset
|
871 elif node.localName == 'path': |
7d976d925431
Generate C header files for SVG files.
Thinker K.F. Li <thinker@branda.to>
parents:
diff
changeset
|
872 translate_path(node, group_id, codefo, doc) |
7d976d925431
Generate C header files for SVG files.
Thinker K.F. Li <thinker@branda.to>
parents:
diff
changeset
|
873 elif node.localName == 'rect': |
7d976d925431
Generate C header files for SVG files.
Thinker K.F. Li <thinker@branda.to>
parents:
diff
changeset
|
874 translate_rect(node, group_id, codefo, doc) |
83 | 875 elif node.localName == 'text': |
876 translate_text(node, group_id, codefo, doc) | |
310 | 877 elif node.localName == 'image': |
878 translate_image(node, group_id, codefo, doc) | |
278
a90fd749af82
Implement the whole tspan attribute. Currently, we can accept font family/font style/font weight and font size.
wycc
parents:
241
diff
changeset
|
879 elif node.localName == 'textarea': |
a90fd749af82
Implement the whole tspan attribute. Currently, we can accept font family/font style/font weight and font size.
wycc
parents:
241
diff
changeset
|
880 translate_textarea(node, group_id, codefo, doc) |
62
7d976d925431
Generate C header files for SVG files.
Thinker K.F. Li <thinker@branda.to>
parents:
diff
changeset
|
881 pass |
7d976d925431
Generate C header files for SVG files.
Thinker K.F. Li <thinker@branda.to>
parents:
diff
changeset
|
882 pass |
7d976d925431
Generate C header files for SVG files.
Thinker K.F. Li <thinker@branda.to>
parents:
diff
changeset
|
883 pass |
7d976d925431
Generate C header files for SVG files.
Thinker K.F. Li <thinker@branda.to>
parents:
diff
changeset
|
884 |
241
104d83378582
Add scene support in svg2code.py.
Thinker K.F. Li <thinker@branda.to>
parents:
210
diff
changeset
|
885 ## \brief Translate "scenes" tag in "metadata" tag. |
104d83378582
Add scene support in svg2code.py.
Thinker K.F. Li <thinker@branda.to>
parents:
210
diff
changeset
|
886 # |
104d83378582
Add scene support in svg2code.py.
Thinker K.F. Li <thinker@branda.to>
parents:
210
diff
changeset
|
887 def translate_scenes(scenes_node, codefo, doc): |
104d83378582
Add scene support in svg2code.py.
Thinker K.F. Li <thinker@branda.to>
parents:
210
diff
changeset
|
888 scenes = [] |
104d83378582
Add scene support in svg2code.py.
Thinker K.F. Li <thinker@branda.to>
parents:
210
diff
changeset
|
889 for scene in scenes_node.childNodes: |
104d83378582
Add scene support in svg2code.py.
Thinker K.F. Li <thinker@branda.to>
parents:
210
diff
changeset
|
890 if scene.localName != 'scene' or \ |
104d83378582
Add scene support in svg2code.py.
Thinker K.F. Li <thinker@branda.to>
parents:
210
diff
changeset
|
891 not scene.hasAttribute('ref') or \ |
104d83378582
Add scene support in svg2code.py.
Thinker K.F. Li <thinker@branda.to>
parents:
210
diff
changeset
|
892 not scene.hasAttribute('start'): |
104d83378582
Add scene support in svg2code.py.
Thinker K.F. Li <thinker@branda.to>
parents:
210
diff
changeset
|
893 continue |
822
586e50f82c1f
Unify coding style tag for emacs and vim.
Shih-Yuan Lee (FourDollars) <fourdollars@gmail.com>
parents:
458
diff
changeset
|
894 |
241
104d83378582
Add scene support in svg2code.py.
Thinker K.F. Li <thinker@branda.to>
parents:
210
diff
changeset
|
895 start_str = scene.getAttribute('start') |
104d83378582
Add scene support in svg2code.py.
Thinker K.F. Li <thinker@branda.to>
parents:
210
diff
changeset
|
896 start = end = int(start_str) |
104d83378582
Add scene support in svg2code.py.
Thinker K.F. Li <thinker@branda.to>
parents:
210
diff
changeset
|
897 if scene.hasAttribute('end'): |
104d83378582
Add scene support in svg2code.py.
Thinker K.F. Li <thinker@branda.to>
parents:
210
diff
changeset
|
898 end_str = scene.getAttribute('end') |
104d83378582
Add scene support in svg2code.py.
Thinker K.F. Li <thinker@branda.to>
parents:
210
diff
changeset
|
899 end = int(end_str) |
104d83378582
Add scene support in svg2code.py.
Thinker K.F. Li <thinker@branda.to>
parents:
210
diff
changeset
|
900 pass |
104d83378582
Add scene support in svg2code.py.
Thinker K.F. Li <thinker@branda.to>
parents:
210
diff
changeset
|
901 ref = scene.getAttribute('ref') |
822
586e50f82c1f
Unify coding style tag for emacs and vim.
Shih-Yuan Lee (FourDollars) <fourdollars@gmail.com>
parents:
458
diff
changeset
|
902 |
241
104d83378582
Add scene support in svg2code.py.
Thinker K.F. Li <thinker@branda.to>
parents:
210
diff
changeset
|
903 while len(scenes) <= end: |
104d83378582
Add scene support in svg2code.py.
Thinker K.F. Li <thinker@branda.to>
parents:
210
diff
changeset
|
904 scenes.append([]) |
104d83378582
Add scene support in svg2code.py.
Thinker K.F. Li <thinker@branda.to>
parents:
210
diff
changeset
|
905 pass |
822
586e50f82c1f
Unify coding style tag for emacs and vim.
Shih-Yuan Lee (FourDollars) <fourdollars@gmail.com>
parents:
458
diff
changeset
|
906 |
241
104d83378582
Add scene support in svg2code.py.
Thinker K.F. Li <thinker@branda.to>
parents:
210
diff
changeset
|
907 for i in range(start, end + 1): |
104d83378582
Add scene support in svg2code.py.
Thinker K.F. Li <thinker@branda.to>
parents:
210
diff
changeset
|
908 scenes[i].append(ref) |
104d83378582
Add scene support in svg2code.py.
Thinker K.F. Li <thinker@branda.to>
parents:
210
diff
changeset
|
909 pass |
104d83378582
Add scene support in svg2code.py.
Thinker K.F. Li <thinker@branda.to>
parents:
210
diff
changeset
|
910 pass |
104d83378582
Add scene support in svg2code.py.
Thinker K.F. Li <thinker@branda.to>
parents:
210
diff
changeset
|
911 |
104d83378582
Add scene support in svg2code.py.
Thinker K.F. Li <thinker@branda.to>
parents:
210
diff
changeset
|
912 for scene_idx, groups_in_scene in enumerate(scenes): |
104d83378582
Add scene support in svg2code.py.
Thinker K.F. Li <thinker@branda.to>
parents:
210
diff
changeset
|
913 if groups_in_scene: |
104d83378582
Add scene support in svg2code.py.
Thinker K.F. Li <thinker@branda.to>
parents:
210
diff
changeset
|
914 groups_str = '[' + '],['.join(groups_in_scene) + ']' |
104d83378582
Add scene support in svg2code.py.
Thinker K.F. Li <thinker@branda.to>
parents:
210
diff
changeset
|
915 else: |
104d83378582
Add scene support in svg2code.py.
Thinker K.F. Li <thinker@branda.to>
parents:
210
diff
changeset
|
916 groups_str = '' |
104d83378582
Add scene support in svg2code.py.
Thinker K.F. Li <thinker@branda.to>
parents:
210
diff
changeset
|
917 pass |
104d83378582
Add scene support in svg2code.py.
Thinker K.F. Li <thinker@branda.to>
parents:
210
diff
changeset
|
918 print >> codefo, \ |
104d83378582
Add scene support in svg2code.py.
Thinker K.F. Li <thinker@branda.to>
parents:
210
diff
changeset
|
919 'SCENE(%d, [%s])dnl' % (scene_idx, groups_str) |
104d83378582
Add scene support in svg2code.py.
Thinker K.F. Li <thinker@branda.to>
parents:
210
diff
changeset
|
920 pass |
104d83378582
Add scene support in svg2code.py.
Thinker K.F. Li <thinker@branda.to>
parents:
210
diff
changeset
|
921 pass |
104d83378582
Add scene support in svg2code.py.
Thinker K.F. Li <thinker@branda.to>
parents:
210
diff
changeset
|
922 |
62
7d976d925431
Generate C header files for SVG files.
Thinker K.F. Li <thinker@branda.to>
parents:
diff
changeset
|
923 def svg_2_code(dom, codefo): |
7d976d925431
Generate C header files for SVG files.
Thinker K.F. Li <thinker@branda.to>
parents:
diff
changeset
|
924 for node in dom.childNodes: |
7d976d925431
Generate C header files for SVG files.
Thinker K.F. Li <thinker@branda.to>
parents:
diff
changeset
|
925 if node.localName == 'svg' and node.namespaceURI == svgns: |
7d976d925431
Generate C header files for SVG files.
Thinker K.F. Li <thinker@branda.to>
parents:
diff
changeset
|
926 break; |
7d976d925431
Generate C header files for SVG files.
Thinker K.F. Li <thinker@branda.to>
parents:
diff
changeset
|
927 pass |
7d976d925431
Generate C header files for SVG files.
Thinker K.F. Li <thinker@branda.to>
parents:
diff
changeset
|
928 else: |
7d976d925431
Generate C header files for SVG files.
Thinker K.F. Li <thinker@branda.to>
parents:
diff
changeset
|
929 raise ValueErr, 'no any svg tag node.' |
822
586e50f82c1f
Unify coding style tag for emacs and vim.
Shih-Yuan Lee (FourDollars) <fourdollars@gmail.com>
parents:
458
diff
changeset
|
930 |
62
7d976d925431
Generate C header files for SVG files.
Thinker K.F. Li <thinker@branda.to>
parents:
diff
changeset
|
931 svg = node |
7d976d925431
Generate C header files for SVG files.
Thinker K.F. Li <thinker@branda.to>
parents:
diff
changeset
|
932 for node in svg.childNodes: |
7d976d925431
Generate C header files for SVG files.
Thinker K.F. Li <thinker@branda.to>
parents:
diff
changeset
|
933 if node.localName == 'defs' and node.namespaceURI == svgns: |
7d976d925431
Generate C header files for SVG files.
Thinker K.F. Li <thinker@branda.to>
parents:
diff
changeset
|
934 translate_defs(node, codefo, dom) |
241
104d83378582
Add scene support in svg2code.py.
Thinker K.F. Li <thinker@branda.to>
parents:
210
diff
changeset
|
935 elif node.localName == 'metadata' and node.namespaceURI == svgns: |
104d83378582
Add scene support in svg2code.py.
Thinker K.F. Li <thinker@branda.to>
parents:
210
diff
changeset
|
936 for meta_node in node.childNodes: |
104d83378582
Add scene support in svg2code.py.
Thinker K.F. Li <thinker@branda.to>
parents:
210
diff
changeset
|
937 if meta_node.localName == 'scenes': |
104d83378582
Add scene support in svg2code.py.
Thinker K.F. Li <thinker@branda.to>
parents:
210
diff
changeset
|
938 translate_scenes(meta_node, codefo, dom) |
104d83378582
Add scene support in svg2code.py.
Thinker K.F. Li <thinker@branda.to>
parents:
210
diff
changeset
|
939 pass |
104d83378582
Add scene support in svg2code.py.
Thinker K.F. Li <thinker@branda.to>
parents:
210
diff
changeset
|
940 pass |
62
7d976d925431
Generate C header files for SVG files.
Thinker K.F. Li <thinker@branda.to>
parents:
diff
changeset
|
941 pass |
7d976d925431
Generate C header files for SVG files.
Thinker K.F. Li <thinker@branda.to>
parents:
diff
changeset
|
942 elif node.localName == 'g' and node.namespaceURI == svgns: |
7d976d925431
Generate C header files for SVG files.
Thinker K.F. Li <thinker@branda.to>
parents:
diff
changeset
|
943 translate_group(node, 'root_coord', codefo, dom) |
7d976d925431
Generate C header files for SVG files.
Thinker K.F. Li <thinker@branda.to>
parents:
diff
changeset
|
944 pass |
7d976d925431
Generate C header files for SVG files.
Thinker K.F. Li <thinker@branda.to>
parents:
diff
changeset
|
945 pass |
7d976d925431
Generate C header files for SVG files.
Thinker K.F. Li <thinker@branda.to>
parents:
diff
changeset
|
946 pass |
7d976d925431
Generate C header files for SVG files.
Thinker K.F. Li <thinker@branda.to>
parents:
diff
changeset
|
947 |
7d976d925431
Generate C header files for SVG files.
Thinker K.F. Li <thinker@branda.to>
parents:
diff
changeset
|
948 if __name__ == '__main__': |
7d976d925431
Generate C header files for SVG files.
Thinker K.F. Li <thinker@branda.to>
parents:
diff
changeset
|
949 from os import path |
428
c3faebaec0c4
Reformat svg2code.py to make more compatible witth our convention
Thinker K.F. Li <thinker@branda.to>
parents:
373
diff
changeset
|
950 import optparse |
822
586e50f82c1f
Unify coding style tag for emacs and vim.
Shih-Yuan Lee (FourDollars) <fourdollars@gmail.com>
parents:
458
diff
changeset
|
951 |
428
c3faebaec0c4
Reformat svg2code.py to make more compatible witth our convention
Thinker K.F. Li <thinker@branda.to>
parents:
373
diff
changeset
|
952 usage='usage: %prog [options] <SVG file> [<output>]' |
c3faebaec0c4
Reformat svg2code.py to make more compatible witth our convention
Thinker K.F. Li <thinker@branda.to>
parents:
373
diff
changeset
|
953 parser = optparse.OptionParser(usage=usage) |
c3faebaec0c4
Reformat svg2code.py to make more compatible witth our convention
Thinker K.F. Li <thinker@branda.to>
parents:
373
diff
changeset
|
954 parser.add_option('-s', '--stext', dest='stext', |
c3faebaec0c4
Reformat svg2code.py to make more compatible witth our convention
Thinker K.F. Li <thinker@branda.to>
parents:
373
diff
changeset
|
955 action='store_true', default=False, |
c3faebaec0c4
Reformat svg2code.py to make more compatible witth our convention
Thinker K.F. Li <thinker@branda.to>
parents:
373
diff
changeset
|
956 help='Use sh_stext instead of sh_text'); |
c3faebaec0c4
Reformat svg2code.py to make more compatible witth our convention
Thinker K.F. Li <thinker@branda.to>
parents:
373
diff
changeset
|
957 options, args = parser.parse_args() |
822
586e50f82c1f
Unify coding style tag for emacs and vim.
Shih-Yuan Lee (FourDollars) <fourdollars@gmail.com>
parents:
458
diff
changeset
|
958 |
428
c3faebaec0c4
Reformat svg2code.py to make more compatible witth our convention
Thinker K.F. Li <thinker@branda.to>
parents:
373
diff
changeset
|
959 if len(args) == 2: |
c3faebaec0c4
Reformat svg2code.py to make more compatible witth our convention
Thinker K.F. Li <thinker@branda.to>
parents:
373
diff
changeset
|
960 svgfn = args[0] |
c3faebaec0c4
Reformat svg2code.py to make more compatible witth our convention
Thinker K.F. Li <thinker@branda.to>
parents:
373
diff
changeset
|
961 codefn = args[1] |
c3faebaec0c4
Reformat svg2code.py to make more compatible witth our convention
Thinker K.F. Li <thinker@branda.to>
parents:
373
diff
changeset
|
962 elif len(args) == 1: |
c3faebaec0c4
Reformat svg2code.py to make more compatible witth our convention
Thinker K.F. Li <thinker@branda.to>
parents:
373
diff
changeset
|
963 svgfn = args[0] |
62
7d976d925431
Generate C header files for SVG files.
Thinker K.F. Li <thinker@branda.to>
parents:
diff
changeset
|
964 codefn = 'out.mb' |
7d976d925431
Generate C header files for SVG files.
Thinker K.F. Li <thinker@branda.to>
parents:
diff
changeset
|
965 else: |
428
c3faebaec0c4
Reformat svg2code.py to make more compatible witth our convention
Thinker K.F. Li <thinker@branda.to>
parents:
373
diff
changeset
|
966 parser.print_help() |
241
104d83378582
Add scene support in svg2code.py.
Thinker K.F. Li <thinker@branda.to>
parents:
210
diff
changeset
|
967 sys.exit(1) |
62
7d976d925431
Generate C header files for SVG files.
Thinker K.F. Li <thinker@branda.to>
parents:
diff
changeset
|
968 pass |
822
586e50f82c1f
Unify coding style tag for emacs and vim.
Shih-Yuan Lee (FourDollars) <fourdollars@gmail.com>
parents:
458
diff
changeset
|
969 |
65
35c2b7ba140b
Use file name of generated M4 script as name of header
Thinker K.F. Li <thinker@branda.to>
parents:
64
diff
changeset
|
970 struct_name = path.basename(codefn).split('.')[0] |
62
7d976d925431
Generate C header files for SVG files.
Thinker K.F. Li <thinker@branda.to>
parents:
diff
changeset
|
971 |
428
c3faebaec0c4
Reformat svg2code.py to make more compatible witth our convention
Thinker K.F. Li <thinker@branda.to>
parents:
373
diff
changeset
|
972 if options.stext: |
c3faebaec0c4
Reformat svg2code.py to make more compatible witth our convention
Thinker K.F. Li <thinker@branda.to>
parents:
373
diff
changeset
|
973 gen_text = stext_gen_text |
c3faebaec0c4
Reformat svg2code.py to make more compatible witth our convention
Thinker K.F. Li <thinker@branda.to>
parents:
373
diff
changeset
|
974 else: |
c3faebaec0c4
Reformat svg2code.py to make more compatible witth our convention
Thinker K.F. Li <thinker@branda.to>
parents:
373
diff
changeset
|
975 gen_text = pango_gen_text |
c3faebaec0c4
Reformat svg2code.py to make more compatible witth our convention
Thinker K.F. Li <thinker@branda.to>
parents:
373
diff
changeset
|
976 pass |
c3faebaec0c4
Reformat svg2code.py to make more compatible witth our convention
Thinker K.F. Li <thinker@branda.to>
parents:
373
diff
changeset
|
977 |
62
7d976d925431
Generate C header files for SVG files.
Thinker K.F. Li <thinker@branda.to>
parents:
diff
changeset
|
978 dom = parse(svgfn) |
7d976d925431
Generate C header files for SVG files.
Thinker K.F. Li <thinker@branda.to>
parents:
diff
changeset
|
979 codefo = file(codefn, 'w+') |
7d976d925431
Generate C header files for SVG files.
Thinker K.F. Li <thinker@branda.to>
parents:
diff
changeset
|
980 print >> codefo, 'MADBUTTERFLY([%s],[dnl' % (struct_name) |
7d976d925431
Generate C header files for SVG files.
Thinker K.F. Li <thinker@branda.to>
parents:
diff
changeset
|
981 svg_2_code(dom, codefo) |
7d976d925431
Generate C header files for SVG files.
Thinker K.F. Li <thinker@branda.to>
parents:
diff
changeset
|
982 print >> codefo, '])dnl' |
7d976d925431
Generate C header files for SVG files.
Thinker K.F. Li <thinker@branda.to>
parents:
diff
changeset
|
983 pass |
7d976d925431
Generate C header files for SVG files.
Thinker K.F. Li <thinker@branda.to>
parents:
diff
changeset
|
984 |