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

« back to all changes in this revision

Viewing changes to share/extensions/eqtexsvg.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:
49
49
    doc_sizeW = max(doc_width,doc_height)
50
50
 
51
51
    def clone_and_rewrite(self, node_in):
52
 
        if node_in.tag != 'svg':
53
 
            node_out = inkex.etree.Element(inkex.addNS(node_in.tag,'svg'))
 
52
        in_tag = node_in.tag.rsplit('}',1)[-1]
 
53
        if in_tag != 'svg':
 
54
            node_out = inkex.etree.Element(inkex.addNS(in_tag,'svg'))
54
55
            for name in node_in.attrib:
55
56
                node_out.set(name, node_in.attrib[name])
56
57
        else:
57
58
            node_out = inkex.etree.Element(inkex.addNS('g','svg'))
58
59
        for c in node_in.iterchildren():
59
 
            if c.tag in ('g', 'path', 'polyline', 'polygon'):
 
60
            c_tag = c.tag.rsplit('}',1)[-1]
 
61
            if c_tag in ('g', 'path', 'polyline', 'polygon'):
60
62
                child = clone_and_rewrite(self, c)
61
 
                if c.tag == 'g':
 
63
                if c_tag == 'g':
62
64
                    child.set('transform','matrix('+str(doc_sizeH/700.)+',0,0,'+str(-doc_sizeH/700.)+','+str(-doc_sizeH*0.25)+','+str(doc_sizeW*0.75)+')')
63
65
                node_out.append(child)
64
66
 
86
88
        dvi_file = os.path.join(base_dir, "eq.dvi")
87
89
        svg_file = os.path.join(base_dir, "eq.svg")
88
90
        out_file = os.path.join(base_dir, "eq.out")
 
91
        err_file = os.path.join(base_dir, "eq.err")
89
92
 
90
93
        def clean():
91
94
            os.remove(latex_file)
95
98
            os.remove(dvi_file)
96
99
            os.remove(svg_file)
97
100
            os.remove(out_file)
 
101
            if os.path.exists(err_file):
 
102
                os.remove(err_file)
98
103
            os.rmdir(base_dir)
99
104
 
100
105
        create_equation_tex(latex_file, self.options.formula)
101
 
        #os.system('cd ' + base_dir)
102
 
        os.system('latex -output-directory=' + base_dir + ' -halt-on-error ' + latex_file + ' > ' + out_file)
103
 
        try:
104
 
            os.stat(dvi_file)
105
 
        except OSError:
106
 
            print >>sys.stderr, "invalid LaTeX input:"
 
106
        os.system('latex "-output-directory=%s" -halt-on-error "%s" > "%s"' \
 
107
                  % (base_dir, latex_file, out_file))
 
108
        try:
 
109
            os.stat(dvi_file)
 
110
        except OSError:
 
111
            print >>sys.stderr, "invalid LaTeX input:"
107
112
            print >>sys.stderr, self.options.formula
108
113
            print >>sys.stderr, "temporary files were left in:", base_dir
109
114
            sys.exit(1)
110
115
 
111
 
        os.system('dvips -q -f -E -D 600 -y 5000 -o ' + ps_file + ' ' + dvi_file)
112
 
        #os.system('cd ' + base_dir)
113
 
        os.system('pstoedit -f plot-svg -dt -ssp ' + ps_file + ' ' + svg_file + '> ' + out_file)
 
116
        os.system('dvips -q -f -E -D 600 -y 5000 -o "%s" "%s"' % (ps_file, dvi_file))
 
117
        # cd to base_dir is necessary, because pstoedit writes
 
118
        # temporary files to cwd and needs write permissions
 
119
        separator = ';'
 
120
        if os.name == 'nt':
 
121
            separator = '&&'
 
122
        os.system('cd "%s" %s pstoedit -f plot-svg -dt -ssp "%s" "%s" > "%s" 2> "%s"' \
 
123
                  % (base_dir, separator, ps_file, svg_file, out_file, err_file))
 
124
 
 
125
        # forward errors to stderr but skip pstoedit header
 
126
        if os.path.exists(err_file):
 
127
            err_stream = open(err_file, 'r')
 
128
            for line in err_stream:
 
129
                if not line.startswith('pstoedit: version'):
 
130
                    sys.stderr.write(line + '\n')
 
131
            err_stream.close()
 
132
 
114
133
        svg_open(self, svg_file)
115
134
 
116
135
        clean()
117
136
 
118
 
e = EQTEXSVG()
119
 
e.affect()
 
137
if __name__ == '__main__':
 
138
    e = EQTEXSVG()
 
139
    e.affect()
 
140
 
 
141
 
 
142
# vim: expandtab shiftwidth=4 tabstop=8 softtabstop=4 encoding=utf-8 textwidth=99