From: aurium Date: Mon, 23 Mar 2009 21:33:17 +0000 (+0000) Subject: adding extension: Interpolate Attribute in a Group X-Git-Url: https://git.tokkee.org/?a=commitdiff_plain;h=aa6fe48a5f4e584b028c1f3fd9153a2d8c78efbf;p=inkscape.git adding extension: Interpolate Attribute in a Group --- diff --git a/mkinstalldirs b/mkinstalldirs index ef7e16fda..d2d5f21b6 100755 --- a/mkinstalldirs +++ b/mkinstalldirs @@ -1,36 +1,21 @@ #! /bin/sh # mkinstalldirs --- make directory hierarchy - -scriptversion=2006-05-11.19 - -# Original author: Noah Friedman +# Author: Noah Friedman # Created: 1993-05-16 -# Public domain. -# -# This file is maintained in Automake, please report -# bugs to or send patches to -# . +# Public domain -nl=' -' -IFS=" "" $nl" errstatus=0 -dirmode= +dirmode="" usage="\ -Usage: mkinstalldirs [-h] [--help] [--version] [-m MODE] DIR ... - -Create each directory DIR (with mode MODE, if specified), including all -leading file name components. - -Report bugs to ." +Usage: mkinstalldirs [-h] [--help] [-m mode] dir ..." # process command line arguments while test $# -gt 0 ; do case $1 in -h | --help | --h*) # -h for help - echo "$usage" - exit $? + echo "$usage" 1>&2 + exit 0 ;; -m) # -m PERM arg shift @@ -38,10 +23,6 @@ while test $# -gt 0 ; do dirmode=$1 shift ;; - --version) - echo "$0 $scriptversion" - exit $? - ;; --) # stop option processing shift break @@ -69,58 +50,30 @@ case $# in 0) exit 0 ;; esac -# Solaris 8's mkdir -p isn't thread-safe. If you mkdir -p a/b and -# mkdir -p a/c at the same time, both will detect that a is missing, -# one will create a, then the other will try to create a and die with -# a "File exists" error. This is a problem when calling mkinstalldirs -# from a parallel make. We use --version in the probe to restrict -# ourselves to GNU mkdir, which is thread-safe. case $dirmode in '') - if mkdir -p --version . >/dev/null 2>&1 && test ! -d ./--version; then + if mkdir -p -- . 2>/dev/null; then echo "mkdir -p -- $*" exec mkdir -p -- "$@" - else - # On NextStep and OpenStep, the `mkdir' command does not - # recognize any option. It will interpret all options as - # directories to create, and then abort because `.' already - # exists. - test -d ./-p && rmdir ./-p - test -d ./--version && rmdir ./--version fi ;; *) - if mkdir -m "$dirmode" -p --version . >/dev/null 2>&1 && - test ! -d ./--version; then + if mkdir -m "$dirmode" -p -- . 2>/dev/null; then echo "mkdir -m $dirmode -p -- $*" exec mkdir -m "$dirmode" -p -- "$@" - else - # Clean up after NextStep and OpenStep mkdir. - for d in ./-m ./-p ./--version "./$dirmode"; - do - test -d $d && rmdir $d - done fi ;; esac for file do - case $file in - /*) pathcomp=/ ;; - *) pathcomp= ;; - esac - oIFS=$IFS - IFS=/ - set fnord $file + set fnord `echo ":$file" | sed -ne 's/^:\//#/;s/^://;s/\// /g;s/^#/\//;p'` shift - IFS=$oIFS + pathcomp= for d do - test "x$d" = x && continue - - pathcomp=$pathcomp$d + pathcomp="$pathcomp$d" case $pathcomp in -*) pathcomp=./$pathcomp ;; esac @@ -131,21 +84,21 @@ do mkdir "$pathcomp" || lasterr=$? if test ! -d "$pathcomp"; then - errstatus=$lasterr + errstatus=$lasterr else - if test ! -z "$dirmode"; then + if test ! -z "$dirmode"; then echo "chmod $dirmode $pathcomp" - lasterr= - chmod "$dirmode" "$pathcomp" || lasterr=$? + lasterr="" + chmod "$dirmode" "$pathcomp" || lasterr=$? - if test ! -z "$lasterr"; then - errstatus=$lasterr - fi - fi + if test ! -z "$lasterr"; then + errstatus=$lasterr + fi + fi fi fi - pathcomp=$pathcomp/ + pathcomp="$pathcomp/" done done @@ -154,8 +107,5 @@ exit $errstatus # Local Variables: # mode: shell-script # sh-indentation: 2 -# eval: (add-hook 'write-file-hooks 'time-stamp) -# time-stamp-start: "scriptversion=" -# time-stamp-format: "%:y-%02m-%02d.%02H" -# time-stamp-end: "$" # End: +# mkinstalldirs ends here diff --git a/share/extensions/interp-att-g.inx b/share/extensions/interp-att-g.inx new file mode 100644 index 000000000..5ed2d1bc0 --- /dev/null +++ b/share/extensions/interp-att-g.inx @@ -0,0 +1,51 @@ + + + <_name>Interpolate Attribute in a group + org.ekips.filter.interp-att-g + interp-att-g.py + inkex.py + <_param name="intro" type="description">This effect applays a value for any interpolable attribute for all elements inside the selected group or for all elements in a multiple selection + + <_item value="width">Width + <_item value="height">Height + <_item value="scale">Scale + <_item value="trans-x">Translate X + <_item value="trans-y">Translate Y + <_item value="fill">Fill + <_item value="opacity">Opacity + <_item value="other">Other + + <_param name="other-info" type="description">If you select "Other", you must know the SVG atributes to identify here this "other": + + + <_item value="color">Color + <_item value="int">Interger Number + <_item value="float">Float Number + + + <_item value="tag">Tag + <_item value="style">Style + <_item value="transform">Transformation + + <_param name="val-info" type="description">•••••••••••••••••••••••••••••••••••••••••••••••• + + + + <_item value="none">No Unit + <_item value="color">Color + px + pt + in + cm + mm + + + all + + + + + + diff --git a/share/extensions/interp-att-g.py b/share/extensions/interp-att-g.py new file mode 100755 index 000000000..c8794f9ad --- /dev/null +++ b/share/extensions/interp-att-g.py @@ -0,0 +1,199 @@ +#!/usr/bin/env python +''' +Copyright (C) 2005 Aaron Spike, aaron@ekips.org + +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 inkex, simplestyle, math, re, string + +class InterpAttG(inkex.Effect): + + def __init__(self): + inkex.Effect.__init__(self) + self.OptionParser.add_option("-a", "--att", + action="store", type="string", + dest="att", default="fill", + help="Attribute to be interpolated.") + self.OptionParser.add_option("-o", "--att-other", + action="store", type="string", + dest="att_other", + help="Other atribute (for a limited UI).") + self.OptionParser.add_option("-t", "--att-other-type", + action="store", type="string", + dest="att_other_type", + help="The other attribute type.") + self.OptionParser.add_option("-w", "--att-other-where", + action="store", type="string", + dest="att_other_where", + help="That is a tag attribute or a style attribute?") + self.OptionParser.add_option("-s", "--start-val", + action="store", type="string", + dest="start_val", default="#F00", + help="Initial interpolation value.") + self.OptionParser.add_option("-e", "--end-val", + action="store", type="string", + dest="end_val", default="#00F", + help="End interpolation value.") + self.OptionParser.add_option("-u", "--unit", + action="store", type="string", + dest="unit", default="color", + help="Values unit.") + + def getColorValues(self): + sv = string.replace( self.options.start_val, '#', '' ) + ev = string.replace( self.options.end_val, '#', '' ) + if re.search('\s|,', sv): + # There are separators. That must be a integer RGB color definition. + sv = re.split( '[\s,]+', sv ) + ev = re.split( '[\s,]+', ev ) + self.R_ini = int( sv[0] ) + self.G_ini = int( sv[1] ) + self.B_ini = int( sv[2] ) + self.R_end = int( ev[0] ) + self.G_end = int( ev[1] ) + self.B_end = int( ev[2] ) + else: + # There is no separator. That must be a Hex RGB color definition. + if len(sv) == 3: + self.R_ini = int( sv[0] + sv[0], 16 ) + self.G_ini = int( sv[1] + sv[1], 16 ) + self.B_ini = int( sv[2] + sv[2], 16 ) + self.R_end = int( ev[0] + ev[0], 16 ) + self.G_end = int( ev[1] + ev[1], 16 ) + self.B_end = int( ev[2] + ev[2], 16 ) + else: #the len must be 6 + self.R_ini = int( sv[0] + sv[1], 16 ) + self.G_ini = int( sv[2] + sv[3], 16 ) + self.B_ini = int( sv[4] + sv[5], 16 ) + self.R_end = int( ev[0] + ev[1], 16 ) + self.G_end = int( ev[2] + ev[3], 16 ) + self.B_end = int( ev[4] + ev[5], 16 ) + self.R_inc = ( self.R_end - self.R_ini ) / float( self.tot_el - 1 ) + self.G_inc = ( self.G_end - self.G_ini ) / float( self.tot_el - 1 ) + self.B_inc = ( self.B_end - self.B_ini ) / float( self.tot_el - 1 ) + self.R_cur = self.R_ini + self.G_cur = self.G_ini + self.B_cur = self.B_ini + + def getNumberValues(self): + sv = self.options.start_val + ev = self.options.end_val + if self.inte_att_type and self.inte_att_type != 'none': + sv = inkex.unittouu( sv + self.inte_att_type ) + ev = inkex.unittouu( ev + self.inte_att_type ) + self.val_cur = self.val_ini = sv + self.val_end = ev + self.val_inc = ( ev - sv ) / float( self.tot_el - 1 ) + + def getTotElements(self): + self.tot_el = 0 + if len( self.selected ) > 1: + # multiple selection + self.collection = self.options.ids + for i in self.options.ids: + path = '//*[@id="%s"]' % i + self.collection[self.tot_el] = self.document.xpath(path, namespaces=inkex.NSS)[0] + self.tot_el += 1 + else: + # must be a group + self.collection = self.selected[ self.options.ids[0] ] + for i in self.collection: + self.tot_el += 1 + + def effect(self): + if self.options.att == 'other': + self.inte_att = self.options.att_other + self.inte_att_type = self.options.att_other_type + self.where = self.options.att_other_where + else: + self.inte_att = self.options.att + if self.inte_att == 'width': + self.inte_att_type = 'float' + self.where = 'tag' + elif self.inte_att == 'height': + self.inte_att_type = 'float' + self.where = 'tag' + elif self.inte_att == 'scale': + self.inte_att_type = 'float' + self.where = 'transform' + elif self.inte_att == 'trans-x': + self.inte_att_type = 'float' + self.where = 'transform' + elif self.inte_att == 'trans-y': + self.inte_att_type = 'float' + self.where = 'transform' + elif self.inte_att == 'fill': + self.inte_att_type = 'color' + self.where = 'style' + elif self.inte_att == 'opacity': + self.inte_att_type = 'float' + self.where = 'style' + + self.getTotElements() + + if self.inte_att_type == 'color': + self.getColorValues() + else: + self.getNumberValues() + + #inkex.errormsg( 'R+: '+ str( self.R_inc ) ) + #inkex.errormsg( 'G+: '+ str( self.G_inc ) ) + #inkex.errormsg( 'B+: '+ str( self.B_inc ) ) + + for node in self.collection: + if self.inte_att_type == 'color': + val = 'rgb('+ \ + str(int(round(self.R_cur))) +','+ \ + str(int(round(self.G_cur))) +','+ \ + str(int(round(self.B_cur))) +')' + else: + if self.inte_att_type == 'float': + val = self.val_cur + else: # inte_att_type == 'int' + val = round(self.val_cur) + + if self.where == 'style': + s = node.get('style') + re_find = '(^|;)'+ self.inte_att +':[^;]*(;|$)' + if re.search( re_find, s ): + s = re.sub( re_find, '\\1'+ self.inte_att +':'+ str(val) +'\\2', s ) + else: + s += ';'+ self.inte_att +':'+ str(val) + node.set( 'style', s ) + elif self.where == 'transform': + t = node.get('transform') + if t == None: t = "" + if self.inte_att == 'trans-x': + val = "translate("+ str(val) +",0)" + elif self.inte_att == 'trans-y': + val = "translate(0,"+ str(val) +")" + else: + val = self.inte_att + "("+ str(val) +")" + node.set( 'transform', t +" "+ val ) + else: # self.where == 'tag': + node.set( self.inte_att, str(val) ) + + if self.inte_att_type == 'color': + self.R_cur += self.R_inc + self.G_cur += self.G_inc + self.B_cur += self.B_inc + else: + self.val_cur += self.val_inc + +if __name__ == '__main__': + e = InterpAttG() + e.affect() + +# vim: expandtab shiftwidth=4 tabstop=8 softtabstop=4 encoding=utf-8 textwidth=99