Code

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