~valavanisalex/ubuntu/oneiric/inkscape/inkscape_0.48.1-2ubuntu4

« back to all changes in this revision

Viewing changes to share/extensions/addnodes.py

  • Committer: Bazaar Package Importer
  • Author(s): Kees Cook, Ted Gould, Kees Cook
  • Date: 2009-06-24 14:00:43 UTC
  • mfrom: (1.1.8 upstream)
  • Revision ID: james.westby@ubuntu.com-20090624140043-07stp20mry48hqup
Tags: 0.47~pre0-0ubuntu1
* New upstream release

[ Ted Gould ]
* debian/control: Adding libgsl0 and removing version specifics on boost

[ Kees Cook ]
* debian/watch: updated to run uupdate and mangle pre-release versions.
* Dropped patches that have been taken upstream:
  - 01_mips
  - 02-poppler-0.8.3
  - 03-chinese-inkscape
  - 05_fix_latex_patch
  - 06_gcc-4.4
  - 07_cdr2svg
  - 08_skip-bad-utf-on-pdf-import
  - 09_gtk-clist
  - 10_belarussian
  - 11_libpng
  - 12_desktop
  - 13_slider
  - 100_svg_import_improvements
  - 102_sp_pattern_painter_free
  - 103_bitmap_type_print

Show diffs side-by-side

added added

removed removed

Lines of Context:
1
1
#!/usr/bin/env python 
2
2
'''
 
3
This extension either adds nodes to a path so that
 
4
    a) no segment is longer than a maximum value 
 
5
    or
 
6
    b) so that each segment is divided into a given number of equal segments
 
7
 
3
8
Copyright (C) 2005,2007 Aaron Spike, aaron@ekips.org
4
9
 
5
10
This program is free software; you can redistribute it and/or modify
16
21
along with this program; if not, write to the Free Software
17
22
Foundation, Inc., 59 Temple Place, Suite 330, Boston, MA  02111-1307  USA
18
23
'''
19
 
import inkex, cubicsuperpath, simplestyle, copy, math, re, bezmisc
 
24
 
 
25
import inkex
 
26
import cubicsuperpath, simplestyle, copy, math, re, bezmisc
20
27
 
21
28
def numsegs(csp):
22
29
    return sum([len(p)-1 for p in csp])
58
65
class SplitIt(inkex.Effect):
59
66
    def __init__(self):
60
67
        inkex.Effect.__init__(self)
61
 
        self.OptionParser.add_option("-m", "--max",
 
68
        self.OptionParser.add_option("--segments",
 
69
                        action="store", type="int", 
 
70
                        dest="segments", default=2,
 
71
                        help="Number of segments to divide the path into")
 
72
        self.OptionParser.add_option("--max",
62
73
                        action="store", type="float", 
63
 
                        dest="max", default=0.0,
64
 
                        help="maximum segment length")
 
74
                        dest="max", default=2,
 
75
                        help="Number of segments to divide the path into")
 
76
        self.OptionParser.add_option("--method",
 
77
                        action="store", type="string", 
 
78
                        dest="method", default='',
 
79
                        help="The kind of division to perform")
 
80
 
65
81
    def effect(self):
 
82
 
66
83
        for id, node in self.selected.iteritems():
67
84
            if node.tag == inkex.addNS('path','svg'):
68
85
                p = cubicsuperpath.parsePath(node.get('d'))
77
94
                    i = 1
78
95
                    while i <= len(sub)-1:
79
96
                        length = cspseglength(new[-1][-1], sub[i])
80
 
                        if length > self.options.max:
 
97
                        
 
98
                        if self.options.method == 'bynum':
 
99
                            splits = self.options.segments
 
100
                        else:
81
101
                            splits = math.ceil(length/self.options.max)
82
 
                            for s in xrange(int(splits),1,-1):
83
 
                                new[-1][-1], next, sub[i] = cspbezsplitatlength(new[-1][-1], sub[i], 1.0/s)
84
 
                                new[-1].append(next[:])
 
102
 
 
103
                        for s in xrange(int(splits),1,-1):
 
104
                            new[-1][-1], next, sub[i] = cspbezsplitatlength(new[-1][-1], sub[i], 1.0/s)
 
105
                            new[-1].append(next[:])
85
106
                        new[-1].append(sub[i])
86
107
                        i+=1
87
108
                    
88
109
                node.set('d',cubicsuperpath.formatPath(new))
89
110
 
90
 
e = SplitIt()
91
 
e.affect()
 
111
if __name__ == '__main__':
 
112
    e = SplitIt()
 
113
    e.affect()
 
114
 
 
115
 
 
116
# vim: expandtab shiftwidth=4 tabstop=8 softtabstop=4 encoding=utf-8 textwidth=99