Skip to content

Commit

Permalink
Merge pull request #7 from wanglongqi/why_xpath_not_working
Browse files Browse the repository at this point in the history
Clean up old codes. The functionality should be all right.
  • Loading branch information
wanglongqi authored Nov 15, 2017
2 parents e3f62eb + 4e486e8 commit a220fd2
Showing 1 changed file with 13 additions and 24 deletions.
37 changes: 13 additions & 24 deletions writetex.py
Original file line number Diff line number Diff line change
Expand Up @@ -5,8 +5,8 @@
An Latex equation editor for Inkscape.
:Author: WANG Longqi <[email protected]>
:Date: 2017-08-12
:Version: v1.6.1
:Date: 2017-11-04
:Version: v1.6.2
This file is a part of WriteTeX extension for Inkscape. For more information,
please refer to http://wanglongqi.github.io/WriteTeX.
Expand Down Expand Up @@ -71,17 +71,6 @@ def __init__(self):
help="Write output directly to a new node in svg file")

def effect(self):
self.zoom = float(self.document.xpath(
'//sodipodi:namedview/@inkscape:zoom', namespaces=inkex.NSS)[0])
self.width = 1/self.zoom * \
float(self.document.xpath(
'//sodipodi:namedview/@inkscape:window-width', namespaces=inkex.NSS)[0])
self.height = 1/self.zoom * \
float(self.document.xpath(
'//sodipodi:namedview/@inkscape:window-height', namespaces=inkex.NSS)[0])
self.width = self.unittouu(str(self.width)+'px')
self.height = self.unittouu(str(self.height)+'px')

self.options.scale = float(self.options.scale)
action = self.options.action.strip("\"")
if action == "viewold":
Expand All @@ -93,8 +82,8 @@ def effect(self):
if self.options.tosvg == "true":
doc = inkex.etree.fromstring(
'<text x="%g" y="%g">%s</text>' % (
self.view_center[0]-self.width/6,
self.view_center[1]-self.height/6,
self.view_center[0],
self.view_center[1],
node.attrib.get(
'{%s}text' % WriteTexNS, '').decode('string-escape')))
p = node.getparent()
Expand Down Expand Up @@ -233,16 +222,16 @@ def svg_to_group(self, svgin):
if self.options.rescale == 'true':
newnode.attrib['transform'] = 'matrix(%f,0,0,%f,%f,%f)' % (
800*self.options.scale, 800*self.options.scale,
self.view_center[0]-self.width/6,
self.view_center[1]-self.height/6)
self.view_center[0],
self.view_center[1])
else:
if 'transform' in node.attrib:
newnode.attrib['transform'] = node.attrib['transform']
else:
newnode.attrib['transform'] = 'matrix(%f,0,0,%f,%f,%f)' % (
800*self.options.scale, 800*self.options.scale,
self.view_center[0]-self.width/6,
self.view_center[1]-self.height/6)
self.view_center[0],
self.view_center[1])
newnode.attrib['style'] = node.attrib['style']
except:
pass
Expand All @@ -252,8 +241,8 @@ def svg_to_group(self, svgin):
else:
newnode.attrib['transform'] = 'matrix(%f,0,0,%f,%f,%f)' % (
800*self.options.scale, 800*self.options.scale,
self.view_center[0]-self.width/6,
self.view_center[1]-self.height/6)
self.view_center[0],
self.view_center[1])
self.current_layer.append(newnode)

def merge_pdf2svg_svg(self, svg_file):
Expand Down Expand Up @@ -311,8 +300,8 @@ def svg_to_group(self, svgin):
if self.options.rescale == 'true':
newnode.attrib['transform'] = 'matrix(%f,0,0,%f,%f,%f)' % (
self.options.scale, self.options.scale,
self.view_center[0]-self.width/6,
self.view_center[1]-self.height/6)
self.view_center[0],
self.view_center[1])
else:
if 'transform' in node.attrib:
newnode.attrib['transform'] = node.attrib['transform']
Expand Down Expand Up @@ -355,4 +344,4 @@ def parse_transform(transf):

if __name__ == '__main__':
e = WriteTex()
e.affect()
e.affect()

0 comments on commit a220fd2

Please sign in to comment.