From 9ef8a5b537ef61ea51769ecd8d4399d5fff80879 Mon Sep 17 00:00:00 2001 From: buliabyak Date: Tue, 10 Jul 2007 06:19:01 +0000 Subject: [PATCH] add text case effects --- share/extensions/Makefile.am | 13 ++++++ share/extensions/chardataeffect.py | 59 ++++++++++++++++++++++++++ share/extensions/text_flipcase.inx | 15 +++++++ share/extensions/text_flipcase.py | 19 +++++++++ share/extensions/text_lowercase.inx | 15 +++++++ share/extensions/text_lowercase.py | 8 ++++ share/extensions/text_randomcase.inx | 15 +++++++ share/extensions/text_randomcase.py | 27 ++++++++++++ share/extensions/text_sentencecase.inx | 15 +++++++ share/extensions/text_sentencecase.py | 37 ++++++++++++++++ share/extensions/text_titlecase.inx | 15 +++++++ share/extensions/text_titlecase.py | 28 ++++++++++++ share/extensions/text_uppercase.inx | 15 +++++++ share/extensions/text_uppercase.py | 8 ++++ 14 files changed, 289 insertions(+) create mode 100644 share/extensions/chardataeffect.py create mode 100644 share/extensions/text_flipcase.inx create mode 100644 share/extensions/text_flipcase.py create mode 100644 share/extensions/text_lowercase.inx create mode 100644 share/extensions/text_lowercase.py create mode 100644 share/extensions/text_randomcase.inx create mode 100644 share/extensions/text_randomcase.py create mode 100644 share/extensions/text_sentencecase.inx create mode 100644 share/extensions/text_sentencecase.py create mode 100644 share/extensions/text_titlecase.inx create mode 100644 share/extensions/text_titlecase.py create mode 100644 share/extensions/text_uppercase.inx create mode 100644 share/extensions/text_uppercase.py diff --git a/share/extensions/Makefile.am b/share/extensions/Makefile.am index f405ffb67..7d3a00bb2 100644 --- a/share/extensions/Makefile.am +++ b/share/extensions/Makefile.am @@ -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 index 000000000..5b72030b6 --- /dev/null +++ b/share/extensions/chardataeffect.py @@ -0,0 +1,59 @@ +#!/usr/bin/env python +''' +Copyright (C) 2006 Jos Hirth, kaioa.com +Copyright (C) 2007 bulia byak +Copyright (C) 2007 Aaron C. Spike + +This program is free software; you can redistribute it and/or modify +it under the terms of the GNU General Public License as published by +the Free Software Foundation; either version 2 of the License, or +(at your option) any later version. + +This program is distributed in the hope that it will be useful, +but WITHOUT ANY WARRANTY; without even the implied warranty of +MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the +GNU General Public License for more details. + +You should have received a copy of the GNU General Public License +along with this program; if not, write to the Free Software +Foundation, Inc., 59 Temple Place, Suite 330, Boston, MA 02111-1307 USA +''' +import sys, optparse, inkex + +class CharDataEffect(inkex.Effect): + def __init__(self): + inkex.Effect.__init__(self) + self.visited = [] + + newline = True + newpar = True + + def effect(self): + if len(self.selected)==0: + self.recurse(self.document.getroot()) + else: + for id,node in self.selected.iteritems(): + self.recurse(node) + + def recurse(self,node): + 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': + self.newline = True + elif istext: + self.newline = True + self.newpar = True + + if node.text != None: + node.text = self.process_chardata(node.text, self.newline, self.newpar) + self.newline = False + self.newpar = False + + for child in node: + self.recurse(child) + + if node.tail != None: + node.tail = self.process_chardata(node.tail, self.newline, self.newpar) + + def process_chardata(self,text, line, par): + pass + diff --git a/share/extensions/text_flipcase.inx b/share/extensions/text_flipcase.inx new file mode 100644 index 000000000..398a8e819 --- /dev/null +++ b/share/extensions/text_flipcase.inx @@ -0,0 +1,15 @@ + + <_name>fLIP cASE + org.inkscape.text.flipcase + chardataeffect.py + text_flipcase.py + + all + + + + + + diff --git a/share/extensions/text_flipcase.py b/share/extensions/text_flipcase.py new file mode 100644 index 000000000..4909b4f4a --- /dev/null +++ b/share/extensions/text_flipcase.py @@ -0,0 +1,19 @@ +import chardataeffect, inkex, string + +class C(chardataeffect.CharDataEffect): + + def process_chardata(self,text, line, par): + r = "" + for i in range(len(text)): + c = text[i] + if c.islower(): + r = r + c.upper() + elif c.isupper(): + r = r + c.lower() + else: + r = r + c + + return r + +c = C() +c.affect() diff --git a/share/extensions/text_lowercase.inx b/share/extensions/text_lowercase.inx new file mode 100644 index 000000000..083e58418 --- /dev/null +++ b/share/extensions/text_lowercase.inx @@ -0,0 +1,15 @@ + + <_name>lowercase + org.inkscape.text.lowercase + chardataeffect.py + text_lowercase.py + + all + + + + + + diff --git a/share/extensions/text_lowercase.py b/share/extensions/text_lowercase.py new file mode 100644 index 000000000..7dd04a208 --- /dev/null +++ b/share/extensions/text_lowercase.py @@ -0,0 +1,8 @@ +import chardataeffect, inkex, string + +class C(chardataeffect.CharDataEffect): + def process_chardata(self,text, line=False, par=False): + return text.lower() + +c = C() +c.affect() diff --git a/share/extensions/text_randomcase.inx b/share/extensions/text_randomcase.inx new file mode 100644 index 000000000..09604c14b --- /dev/null +++ b/share/extensions/text_randomcase.inx @@ -0,0 +1,15 @@ + + <_name>rANdOm CasE + org.inkscape.text.randomcase + chardataeffect.py + text_randomcase.py + + all + + + + + + diff --git a/share/extensions/text_randomcase.py b/share/extensions/text_randomcase.py new file mode 100644 index 000000000..0961c594b --- /dev/null +++ b/share/extensions/text_randomcase.py @@ -0,0 +1,27 @@ +import chardataeffect, inkex, string + +import random + +class C(chardataeffect.CharDataEffect): + + def process_chardata(self,text, line, par): + r = "" + a = 1 + for i in range(len(text)): + c = text[i] + # bias the randomness towards inversion of the previous case: + if a > 0: + a = random.choice([-2,-1,1]) + else: + a = random.choice([-1,1,2]) + if a > 0 and c.isalpha(): + r = r + c.upper() + elif a < 0 and c.isalpha(): + r = r + c.lower() + else: + r = r + c + + return r + +c = C() +c.affect() diff --git a/share/extensions/text_sentencecase.inx b/share/extensions/text_sentencecase.inx new file mode 100644 index 000000000..da3b292ae --- /dev/null +++ b/share/extensions/text_sentencecase.inx @@ -0,0 +1,15 @@ + + <_name>Sentence case + org.inkscape.text.sentencecase + chardataeffect.py + text_sentencecase.py + + all + + + + + + diff --git a/share/extensions/text_sentencecase.py b/share/extensions/text_sentencecase.py new file mode 100644 index 000000000..9b29f7f84 --- /dev/null +++ b/share/extensions/text_sentencecase.py @@ -0,0 +1,37 @@ +import chardataeffect, inkex, string + +class C(chardataeffect.CharDataEffect): + + sentence_start = True + was_punctuation = False + + def process_chardata(self,text, line, par): + r = "" + #inkex.debug(text+str(line)+str(par)) + for c in text: + if c == '.' or c == '!' or c == '?': + self.was_punctuation = True + elif ((c.isspace() or line == True) and self.was_punctuation) or par == True: + self.sentence_start = True + self.was_punctuation = False + elif c == '"' or c == ')': + pass + else: + self.was_punctuation = False + + if not c.isspace(): + line = False + par = False + + if self.sentence_start and c.isalpha(): + r = r + c.upper() + self.sentence_start = False + elif not self.sentence_start and c.isalpha(): + r = r + c.lower() + else: + r = r + c + + return r + +c = C() +c.affect() diff --git a/share/extensions/text_titlecase.inx b/share/extensions/text_titlecase.inx new file mode 100644 index 000000000..a18a30d49 --- /dev/null +++ b/share/extensions/text_titlecase.inx @@ -0,0 +1,15 @@ + + <_name>Title Case + org.inkscape.text.titlecase + chardataeffect.py + text_titlecase.py + + all + + + + + + diff --git a/share/extensions/text_titlecase.py b/share/extensions/text_titlecase.py new file mode 100644 index 000000000..b6548b62b --- /dev/null +++ b/share/extensions/text_titlecase.py @@ -0,0 +1,28 @@ +import chardataeffect, inkex, string + +class C(chardataeffect.CharDataEffect): + + word_ended = True + + def process_chardata(self,text, line, par): + r = "" + for i in range(len(text)): + c = text[i] + if c.isspace() or line == True or par == True: + self.word_ended = True + if not c.isspace(): + line = False + par = False + + if self.word_ended and c.isalpha(): + r = r + c.upper() + self.word_ended = False + elif c.isalpha(): + r = r + c.lower() + else: + r = r + c + + return r + +c = C() +c.affect() diff --git a/share/extensions/text_uppercase.inx b/share/extensions/text_uppercase.inx new file mode 100644 index 000000000..cf9d8e5df --- /dev/null +++ b/share/extensions/text_uppercase.inx @@ -0,0 +1,15 @@ + + <_name>UPPERCASE + org.inkscape.text.uppercase + chardataeffect.py + text_uppercase.py + + all + + + + + + diff --git a/share/extensions/text_uppercase.py b/share/extensions/text_uppercase.py new file mode 100644 index 000000000..8e894ed81 --- /dev/null +++ b/share/extensions/text_uppercase.py @@ -0,0 +1,8 @@ +import chardataeffect, inkex, string + +class C(chardataeffect.CharDataEffect): + def process_chardata(self,text, line=False, par=False): + return text.upper() + +c = C() +c.affect() -- 2.30.2