~valavanisalex/ubuntu/precise/inkscape/fix-943984

« back to all changes in this revision

Viewing changes to share/extensions/hpgl_output.py

  • Committer: Bazaar Package Importer
  • Author(s): Bryce Harrington
  • Date: 2009-07-02 17:09:45 UTC
  • mfrom: (1.1.9 upstream)
  • Revision ID: james.westby@ubuntu.com-20090702170945-nn6d6zswovbwju1t
Tags: 0.47~pre1-0ubuntu1
* New upstream release.
  - Don't constrain maximization on small resolution devices (pre0)
    (LP: #348842)
  - Fixes segfault on startup (pre0)
    (LP: #391149)

Show diffs side-by-side

added added

removed removed

Lines of Context:
16
16
along with this program; if not, write to the Free Software
17
17
Foundation, Inc., 59 Temple Place, Suite 330, Boston, MA  02111-1307  USA
18
18
'''
19
 
import inkex, cubicsuperpath, simplepath, cspsubdiv
 
19
import inkex, cubicsuperpath, simplepath, simplestyle, cspsubdiv
20
20
 
21
21
class MyEffect(inkex.Effect):
22
22
    def __init__(self):
23
23
        inkex.Effect.__init__(self)
24
24
        self.OptionParser.add_option("-f", "--flatness",
25
25
                        action="store", type="float", 
26
 
                        dest="flat", default=10.0,
 
26
                        dest="flat", default=0.2,
27
27
                        help="Minimum flatness of the subdivided curves")
 
28
        self.OptionParser.add_option("-m", "--mirror",
 
29
                        action="store", type="inkbool", 
 
30
                        dest="mirror", default="FALSE",
 
31
                        help="Mirror Y-Axis")
 
32
        self.OptionParser.add_option("-x", "--xOrigin",
 
33
                        action="store", type="float", 
 
34
                        dest="xOrigin", default=0.0,
 
35
                        help="X Origin (pixels)")
 
36
        self.OptionParser.add_option("-y", "--yOrigin",
 
37
                        action="store", type="float", 
 
38
                        dest="yOrigin", default=0.0,
 
39
                        help="Y Origin (pixels)")
 
40
        self.OptionParser.add_option("-p", "--plotInvisibleLayers",
 
41
                        action="store", type="inkbool", 
 
42
                        dest="plotInvisibleLayers", default="FALSE",
 
43
                        help="Plot invisible layers")
 
44
 
28
45
        self.hpgl = ['IN;SP1;']
29
46
    def output(self):
30
47
        print ''.join(self.hpgl)
31
48
    def effect(self):
32
 
        path = '//svg:path'
33
 
        for node in self.document.getroot().xpath(path, namespaces=inkex.NSS):
34
 
            d = node.get('d')
35
 
            if len(simplepath.parsePath(d)):
36
 
                p = cubicsuperpath.parsePath(d)
37
 
                cspsubdiv.cspsubdiv(p, self.options.flat)
38
 
                for sp in p:
39
 
                    first = True
40
 
                    for csp in sp:
41
 
                        cmd = 'PD'
42
 
                        if first:
43
 
                            cmd = 'PU'
44
 
                        first = False
45
 
                        self.hpgl.append('%s%s,%s;' % (cmd,csp[1][0],csp[1][1]))
 
49
        mirror = 1.0
 
50
        if self.options.mirror:
 
51
            mirror = -1.0
 
52
        x0 = self.options.xOrigin
 
53
        y0 = self.options.yOrigin
 
54
        scale = 1016.0/90
 
55
        i = 0
 
56
        layerPath = '//svg:g[@inkscape:groupmode="layer"]'
 
57
        for layer in self.document.getroot().xpath(layerPath, namespaces=inkex.NSS):
 
58
            i += 1
 
59
            style = layer.get('style')
 
60
            if style:
 
61
                style = simplestyle.parseStyle(style)
 
62
                if style['display']=='none':
 
63
                    if not self.options.plotInvisibleLayers:
 
64
                        continue
 
65
            nodePath = ('//svg:g[@inkscape:groupmode="layer"][%d]/descendant::svg:path') % i
 
66
            for node in self.document.getroot().xpath(nodePath, namespaces=inkex.NSS):
 
67
                d = node.get('d')
 
68
                if len(simplepath.parsePath(d)):
 
69
                    p = cubicsuperpath.parsePath(d)
 
70
                    cspsubdiv.cspsubdiv(p, self.options.flat)
 
71
                    for sp in p:
 
72
                        first = True
 
73
                        for csp in sp:
 
74
                            cmd = 'PD'
 
75
                            if first:
 
76
                                cmd = 'PU'
 
77
                            first = False
 
78
                            self.hpgl.append('%s%d,%d;' % (cmd,(csp[1][0] - x0)*scale,(csp[1][1] - y0)*scale*mirror))
46
79
 
47
80
if __name__ == '__main__':   #pragma: no cover
48
81
    e = MyEffect()
49
82
    e.affect()
 
83
 
 
84
# vim: expandtab shiftwidth=4 tabstop=8 softtabstop=4 encoding=utf-8 textwidth=99