Code

add text case effects
authorbuliabyak <buliabyak@users.sourceforge.net>
Tue, 10 Jul 2007 06:19:01 +0000 (06:19 +0000)
committerbuliabyak <buliabyak@users.sourceforge.net>
Tue, 10 Jul 2007 06:19:01 +0000 (06:19 +0000)
14 files changed:
share/extensions/Makefile.am
share/extensions/chardataeffect.py [new file with mode: 0644]
share/extensions/text_flipcase.inx [new file with mode: 0644]
share/extensions/text_flipcase.py [new file with mode: 0644]
share/extensions/text_lowercase.inx [new file with mode: 0644]
share/extensions/text_lowercase.py [new file with mode: 0644]
share/extensions/text_randomcase.inx [new file with mode: 0644]
share/extensions/text_randomcase.py [new file with mode: 0644]
share/extensions/text_sentencecase.inx [new file with mode: 0644]
share/extensions/text_sentencecase.py [new file with mode: 0644]
share/extensions/text_titlecase.inx [new file with mode: 0644]
share/extensions/text_titlecase.py [new file with mode: 0644]
share/extensions/text_uppercase.inx [new file with mode: 0644]
share/extensions/text_uppercase.py [new file with mode: 0644]

index f405ffb67346b5b2ffd6c37ec3d71f3e118ad720..7d3a00bb2710074276b9625e6c91d059a2bdf993 100644 (file)
@@ -12,6 +12,7 @@ moduledir = $(datadir)/inkscape/extensions
 extensions = \
        addnodes.py \
        bezmisc.py \
+       chardataeffect.py\
        color_brighter.py\
        color_custom.py\
        color_darker.py\
@@ -80,6 +81,12 @@ extensions = \
        straightseg.py \
        summersnight.py \
        svg_and_media_zip_output.py \
+       text_uppercase.py \
+       text_lowercase.py \
+       text_sentencecase.py \
+       text_titlecase.py \
+       text_flipcase.py \
+       text_randomcase.py \
        txt2svg.pl \
        webbrowser_commandline.py \
        webbrowser_faq.py\
@@ -160,6 +167,12 @@ modules = \
        svg_and_media_zip_output.inx \
        svgz_input.inx \
        svgz_output.inx \
+       text_uppercase.inx\
+       text_lowercase.inx \
+       text_sentencecase.inx \
+       text_titlecase.inx \
+       text_flipcase.inx \
+       text_randomcase.inx \
        txt2svg.inx \
        whirl.inx \
        wmf_input.inx
diff --git a/share/extensions/chardataeffect.py b/share/extensions/chardataeffect.py
new file mode 100644 (file)
index 0000000..5b72030
--- /dev/null
@@ -0,0 +1,59 @@
+#!/usr/bin/env python \r
+'''\r
+Copyright (C) 2006 Jos Hirth, kaioa.com\r
+Copyright (C) 2007 bulia byak\r
+Copyright (C) 2007 Aaron C. Spike\r
+\r
+This program is free software; you can redistribute it and/or modify\r
+it under the terms of the GNU General Public License as published by\r
+the Free Software Foundation; either version 2 of the License, or\r
+(at your option) any later version.\r
+\r
+This program is distributed in the hope that it will be useful,\r
+but WITHOUT ANY WARRANTY; without even the implied warranty of\r
+MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE.  See the\r
+GNU General Public License for more details.\r
+\r
+You should have received a copy of the GNU General Public License\r
+along with this program; if not, write to the Free Software\r
+Foundation, Inc., 59 Temple Place, Suite 330, Boston, MA  02111-1307  USA\r
+'''\r
+import sys, optparse, inkex\r
+\r
+class CharDataEffect(inkex.Effect):\r
+  def __init__(self):\r
+    inkex.Effect.__init__(self)\r
+    self.visited = []\r
+\r
+  newline = True\r
+  newpar = True\r
+\r
+  def effect(self):\r
+    if len(self.selected)==0:\r
+      self.recurse(self.document.getroot())\r
+    else:\r
+      for id,node in self.selected.iteritems():\r
+        self.recurse(node)\r
+\r
+  def recurse(self,node):\r
+    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')
+    if node.get('{http://sodipodi.sourceforge.net/DTD/sodipodi-0.dtd}role') == 'line':\r
+      self.newline = True\r
+    elif istext:\r
+      self.newline = True\r
+      self.newpar = True\r
+
+    if node.text != None:\r
+      node.text = self.process_chardata(node.text, self.newline, self.newpar)\r
+      self.newline = False\r
+      self.newpar = False\r
+
+    for child in node:\r
+      self.recurse(child)\r
+
+    if node.tail != None:\r
+      node.tail = self.process_chardata(node.tail, self.newline, self.newpar)\r
+\r
+  def process_chardata(self,text, line, par):\r
+    pass\r
+\r
diff --git a/share/extensions/text_flipcase.inx b/share/extensions/text_flipcase.inx
new file mode 100644 (file)
index 0000000..398a8e8
--- /dev/null
@@ -0,0 +1,15 @@
+<inkscape-extension>\r
+       <_name>fLIP cASE</_name>\r
+       <id>org.inkscape.text.flipcase</id>\r
+       <dependency type="executable" location="extensions">chardataeffect.py</dependency>\r
+       <dependency type="executable" location="extensions">text_flipcase.py</dependency>\r
+       <effect>\r
+               <object-type>all</object-type>\r
+               <effects-menu>\r
+                       <submenu _name="Text"/>\r
+               </effects-menu>\r
+       </effect>\r
+       <script>\r
+               <command reldir="extensions" interpreter="python">text_flipcase.py</command>\r
+       </script>\r
+</inkscape-extension>\r
diff --git a/share/extensions/text_flipcase.py b/share/extensions/text_flipcase.py
new file mode 100644 (file)
index 0000000..4909b4f
--- /dev/null
@@ -0,0 +1,19 @@
+import chardataeffect, inkex, string\r
+\r
+class C(chardataeffect.CharDataEffect):\r
+\r
+  def process_chardata(self,text, line, par):\r
+    r = ""\r
+    for i in range(len(text)):\r
+      c = text[i]
+      if c.islower():\r
+        r = r + c.upper()\r
+      elif c.isupper():\r
+        r = r + c.lower()\r
+      else:\r
+        r = r + c\r
+\r
+    return r\r
+\r
+c = C()\r
+c.affect()\r
diff --git a/share/extensions/text_lowercase.inx b/share/extensions/text_lowercase.inx
new file mode 100644 (file)
index 0000000..083e584
--- /dev/null
@@ -0,0 +1,15 @@
+<inkscape-extension>\r
+       <_name>lowercase</_name>\r
+       <id>org.inkscape.text.lowercase</id>\r
+       <dependency type="executable" location="extensions">chardataeffect.py</dependency>\r
+       <dependency type="executable" location="extensions">text_lowercase.py</dependency>\r
+       <effect>\r
+               <object-type>all</object-type>\r
+               <effects-menu>\r
+                       <submenu _name="Text"/>\r
+               </effects-menu>\r
+       </effect>\r
+       <script>\r
+               <command reldir="extensions" interpreter="python">text_lowercase.py</command>\r
+       </script>\r
+</inkscape-extension>\r
diff --git a/share/extensions/text_lowercase.py b/share/extensions/text_lowercase.py
new file mode 100644 (file)
index 0000000..7dd04a2
--- /dev/null
@@ -0,0 +1,8 @@
+import chardataeffect, inkex, string\r
+\r
+class C(chardataeffect.CharDataEffect):\r
+  def process_chardata(self,text, line=False, par=False):\r
+    return text.lower()\r
+\r
+c = C()\r
+c.affect()\r
diff --git a/share/extensions/text_randomcase.inx b/share/extensions/text_randomcase.inx
new file mode 100644 (file)
index 0000000..09604c1
--- /dev/null
@@ -0,0 +1,15 @@
+<inkscape-extension>\r
+       <_name>rANdOm CasE</_name>\r
+       <id>org.inkscape.text.randomcase</id>\r
+       <dependency type="executable" location="extensions">chardataeffect.py</dependency>\r
+       <dependency type="executable" location="extensions">text_randomcase.py</dependency>\r
+       <effect>\r
+               <object-type>all</object-type>\r
+               <effects-menu>\r
+                       <submenu _name="Text"/>\r
+               </effects-menu>\r
+       </effect>\r
+       <script>\r
+               <command reldir="extensions" interpreter="python">text_randomcase.py</command>\r
+       </script>\r
+</inkscape-extension>\r
diff --git a/share/extensions/text_randomcase.py b/share/extensions/text_randomcase.py
new file mode 100644 (file)
index 0000000..0961c59
--- /dev/null
@@ -0,0 +1,27 @@
+import chardataeffect, inkex, string\r
+\r
+import random\r
+\r
+class C(chardataeffect.CharDataEffect):\r
+\r
+  def process_chardata(self,text, line, par):\r
+    r = ""\r
+    a = 1\r
+    for i in range(len(text)):\r
+      c = text[i]\r
+      # bias the randomness towards inversion of the previous case:
+      if a > 0:
+        a = random.choice([-2,-1,1])\r
+      else:
+        a = random.choice([-1,1,2])\r      
+      if a > 0 and c.isalpha():\r
+        r = r + c.upper()\r
+      elif a < 0 and c.isalpha():\r\r
+        r = r + c.lower()\r
+      else:\r
+        r = r + c\r
+\r
+    return r\r
+\r
+c = C()\r
+c.affect()\r
diff --git a/share/extensions/text_sentencecase.inx b/share/extensions/text_sentencecase.inx
new file mode 100644 (file)
index 0000000..da3b292
--- /dev/null
@@ -0,0 +1,15 @@
+<inkscape-extension>\r
+       <_name>Sentence case</_name>\r
+       <id>org.inkscape.text.sentencecase</id>\r
+       <dependency type="executable" location="extensions">chardataeffect.py</dependency>\r
+       <dependency type="executable" location="extensions">text_sentencecase.py</dependency>\r
+       <effect>\r
+               <object-type>all</object-type>\r
+               <effects-menu>\r
+                       <submenu _name="Text"/>\r
+               </effects-menu>\r
+       </effect>\r
+       <script>\r
+               <command reldir="extensions" interpreter="python">text_sentencecase.py</command>\r
+       </script>\r
+</inkscape-extension>\r
diff --git a/share/extensions/text_sentencecase.py b/share/extensions/text_sentencecase.py
new file mode 100644 (file)
index 0000000..9b29f7f
--- /dev/null
@@ -0,0 +1,37 @@
+import chardataeffect, inkex, string\r
+\r
+class C(chardataeffect.CharDataEffect):\r
+\r
+  sentence_start = True\r
+  was_punctuation = False\r
+\r
+  def process_chardata(self,text, line, par):\r
+    r = ""\r
+    #inkex.debug(text+str(line)+str(par))
+    for c in text:\r
+      if c == '.' or c == '!' or c == '?':\r
+        self.was_punctuation = True\r
+      elif ((c.isspace() or line == True) and self.was_punctuation) or par == True:\r
+        self.sentence_start = True\r
+        self.was_punctuation = False\r
+      elif c == '"' or c == ')':\r
+        pass\r
+      else:\r
+        self.was_punctuation = False\r
+
+      if not c.isspace():\r
+        line = False\r
+        par = False\r
+\r
+      if self.sentence_start and c.isalpha():\r
+        r = r + c.upper()\r
+        self.sentence_start = False\r
+      elif not self.sentence_start and c.isalpha():\r
+        r = r + c.lower()\r
+      else:\r
+        r = r + c\r
+\r
+    return r\r
+\r
+c = C()\r
+c.affect()\r
diff --git a/share/extensions/text_titlecase.inx b/share/extensions/text_titlecase.inx
new file mode 100644 (file)
index 0000000..a18a30d
--- /dev/null
@@ -0,0 +1,15 @@
+<inkscape-extension>\r
+       <_name>Title Case</_name>\r
+       <id>org.inkscape.text.titlecase</id>\r
+       <dependency type="executable" location="extensions">chardataeffect.py</dependency>\r
+       <dependency type="executable" location="extensions">text_titlecase.py</dependency>\r
+       <effect>\r
+               <object-type>all</object-type>\r
+               <effects-menu>\r
+                       <submenu _name="Text"/>\r
+               </effects-menu>\r
+       </effect>\r
+       <script>\r
+               <command reldir="extensions" interpreter="python">text_titlecase.py</command>\r
+       </script>\r
+</inkscape-extension>\r
diff --git a/share/extensions/text_titlecase.py b/share/extensions/text_titlecase.py
new file mode 100644 (file)
index 0000000..b6548b6
--- /dev/null
@@ -0,0 +1,28 @@
+import chardataeffect, inkex, string\r
+\r
+class C(chardataeffect.CharDataEffect):\r
+\r
+  word_ended = True\r
+\r
+  def process_chardata(self,text, line, par):\r
+    r = ""\r
+    for i in range(len(text)):\r
+      c = text[i]\r
+      if c.isspace() or line == True or par == True:\r
+        self.word_ended = True\r
+      if not c.isspace():\r
+        line = False\r
+        par = False\r
+\r
+      if self.word_ended and c.isalpha():\r
+        r = r + c.upper()\r
+        self.word_ended = False\r
+      elif c.isalpha():\r
+        r = r + c.lower()\r
+      else:\r
+        r = r + c\r
+\r
+    return r\r
+\r
+c = C()\r
+c.affect()\r
diff --git a/share/extensions/text_uppercase.inx b/share/extensions/text_uppercase.inx
new file mode 100644 (file)
index 0000000..cf9d8e5
--- /dev/null
@@ -0,0 +1,15 @@
+<inkscape-extension>\r
+       <_name>UPPERCASE</_name>\r
+       <id>org.inkscape.text.uppercase</id>\r
+       <dependency type="executable" location="extensions">chardataeffect.py</dependency>\r
+       <dependency type="executable" location="extensions">text_uppercase.py</dependency>\r
+       <effect>\r
+               <object-type>all</object-type>\r
+               <effects-menu>\r
+                       <submenu _name="Text"/>\r
+               </effects-menu>\r
+       </effect>\r
+       <script>\r
+               <command reldir="extensions" interpreter="python">text_uppercase.py</command>\r
+       </script>\r
+</inkscape-extension>\r
diff --git a/share/extensions/text_uppercase.py b/share/extensions/text_uppercase.py
new file mode 100644 (file)
index 0000000..8e894ed
--- /dev/null
@@ -0,0 +1,8 @@
+import chardataeffect, inkex, string\r
+\r
+class C(chardataeffect.CharDataEffect):\r
+  def process_chardata(self,text, line=False, par=False):\r
+    return text.upper()\r
+\r
+c = C()\r
+c.affect()\r