1 #!/usr/bin/env python
2 '''
3 Copyright (C) 2006 Jos Hirth, kaioa.com
4 Copyright (C) 2007 bulia byak
5 Copyright (C) 2007 Aaron C. Spike
7 This program is free software; you can redistribute it and/or modify
8 it under the terms of the GNU General Public License as published by
9 the Free Software Foundation; either version 2 of the License, or
10 (at your option) any later version.
12 This program is distributed in the hope that it will be useful,
13 but WITHOUT ANY WARRANTY; without even the implied warranty of
14 MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
15 GNU General Public License for more details.
17 You should have received a copy of the GNU General Public License
18 along with this program; if not, write to the Free Software
19 Foundation, Inc., 59 Temple Place, Suite 330, Boston, MA 02111-1307 USA
20 '''
21 import sys, optparse, inkex
23 class CharDataEffect(inkex.Effect):
24 def __init__(self):
25 inkex.Effect.__init__(self)
26 self.visited = []
28 newline = True
29 newpar = True
31 def effect(self):
32 if len(self.selected)==0:
33 self.recurse(self.document.getroot())
34 else:
35 for id,node in self.selected.iteritems():
36 self.recurse(node)
38 def recurse(self,node):
39 istext = (node.tag == '{http://www.w3.org/2000/svg}flowPara' or node.tag == '{http://www.w3.org/2000/svg}flowDiv' or node.tag == '{http://www.w3.org/2000/svg}text')
40 if node.get('{http://sodipodi.sourceforge.net/DTD/sodipodi-0.dtd}role') == 'line':
41 self.newline = True
42 elif istext:
43 self.newline = True
44 self.newpar = True
46 if node.text != None:
47 node.text = self.process_chardata(node.text, self.newline, self.newpar)
48 self.newline = False
49 self.newpar = False
51 for child in node:
52 self.recurse(child)
54 if node.tail != None:
55 node.tail = self.process_chardata(node.tail, self.newline, self.newpar)
57 def process_chardata(self,text, line, par):
58 pass