summaryrefslogtreecommitdiffstats
path: root/share
diff options
context:
space:
mode:
Diffstat (limited to 'share')
-rwxr-xr-xshare/extensions/inkex.py62
-rw-r--r--share/symbols/MapSymbolsNPS.svg5
2 files changed, 60 insertions, 7 deletions
diff --git a/share/extensions/inkex.py b/share/extensions/inkex.py
index 0f880005d..a564b5c8d 100755
--- a/share/extensions/inkex.py
+++ b/share/extensions/inkex.py
@@ -101,6 +101,13 @@ def errormsg(msg):
else:
sys.stderr.write((unicode(msg, "utf-8", errors='replace') + "\n").encode("UTF-8"))
+def are_near_relative(a, b, eps):
+ if (a-b <= a*eps) and (a-b >= -a*eps):
+ return True
+ else:
+ return False
+
+
# third party library
try:
from lxml import etree
@@ -277,16 +284,57 @@ class Effect:
retval = None
return retval
- def getDocumentUnit(self):
- docunit = self.document.xpath('//sodipodi:namedview/@inkscape:document-units', namespaces=NSS)
- if docunit:
- return docunit[0]
- else:
- return 'px'
-
#a dictionary of unit to user unit conversion factors
__uuconv = {'in':96.0, 'pt':1.33333333333, 'px':1.0, 'mm':3.77952755913, 'cm':37.7952755913,
'm':3779.52755913, 'km':3779527.55913, 'pc':16.0, 'yd':3456.0 , 'ft':1152.0}
+
+ # Function returns the unit used for the values in SVG.
+ # For lack of an attribute in SVG that explicitly defines what units are used for SVG coordinates,
+ # try to calculate the unit from the SVG width and SVG viewbox.
+ # Defaults to 'px' units.
+ def getDocumentUnit(self):
+ svgunit = 'px' #default to pixels
+
+ svgwidth = self.document.getroot().get('width')
+ viewboxstr = self.document.getroot().get('viewBox')
+ if viewboxstr:
+ unitmatch = re.compile('(%s)$' % '|'.join(self.__uuconv.keys()))
+ param = re.compile(r'(([-+]?[0-9]+(\.[0-9]*)?|[-+]?\.[0-9]+)([eE][-+]?[0-9]+)?)')
+
+ p = param.match(svgwidth)
+ u = unitmatch.search(svgwidth)
+
+ width = 100 #default
+ viewboxwidth = 100 #default
+ svgwidthunit = 'px' #default assume 'px' unit
+ if p:
+ width = float(p.string[p.start():p.end()])
+ else:
+ errormsg(_("SVG Width not set correctly! Assuming width = 100"))
+ if u:
+ svgwidthunit = u.string[u.start():u.end()]
+
+ viewboxnumbers = []
+ for t in viewboxstr.split():
+ try:
+ viewboxnumbers.append(float(t))
+ except ValueError:
+ pass
+ if len(viewboxnumbers) == 4: #check for correct number of numbers
+ viewboxwidth = viewboxnumbers[2] - viewboxnumbers[0]
+
+ svgunitfactor = self.__uuconv[svgwidthunit] * width / viewboxwidth
+
+ # try to find the svgunitfactor in the list of units known. If we don't find something, ...
+ eps = 0.01 #allow 1% error in factor
+ for key in self.__uuconv:
+ if are_near_relative(self.__uuconv[key], svgunitfactor, eps):
+ #found match!
+ svgunit = key;
+
+ return svgunit
+
+
def unittouu(self, string):
'''Returns userunits given a string representation of units in another system'''
unit = re.compile('(%s)$' % '|'.join(self.__uuconv.keys()))
diff --git a/share/symbols/MapSymbolsNPS.svg b/share/symbols/MapSymbolsNPS.svg
index 81b24adde..aa558c9b2 100644
--- a/share/symbols/MapSymbolsNPS.svg
+++ b/share/symbols/MapSymbolsNPS.svg
@@ -469,6 +469,7 @@
</symbol>
<symbol id="MotorBikeTrail">
+ <title>Motorbike Trail</title>
<g style="stroke:none">
<path d="m 36.625,26.25 6.125,0 a 1.75,1.75 0 0 1 0,3.5 l -7.25,0 c -0.75,0 -1.625,-0.25 -2.25,-1.25 l -2.75,-4.25 -5.25,8 7.25,3.75 c 2,1 2,2.5 2,3.5 l 0,13.5 a 2.75,2.75 0 0 1 -5.5,0 l 0,-11 -11.5,-6.25 c -2,-1.25 -2.25,-3.75 -1.25,-5.25 l 8.5,-13 c 1.25,-1.875 4.5,-2.25 6,-0.25 z"/>
<path d="m 26.5,43.75 0,2.5 -13.5,-7.5 c -2.5,-1.25 -5,-1 -7,0 -0.5,0.25 -1.25,-0.5 -0.5,-1.25 2.5,-2.125 6.5,-2 9,-0.5 z"/>
@@ -484,6 +485,7 @@
</symbol>
<symbol id="MotorBikeTrail_Inv">
+ <title>Motorbike Trail</title>
<rect x="0.5" y="0.5" width="71" height="71" ry="6" style="stroke:white"/>
<g style="fill:white;stroke:none">
<path d="m 36.625,26.25 6.125,0 a 1.75,1.75 0 0 1 0,3.5 l -7.25,0 c -0.75,0 -1.625,-0.25 -2.25,-1.25 l -2.75,-4.25 -5.25,8 7.25,3.75 c 2,1 2,2.5 2,3.5 l 0,13.5 a 2.75,2.75 0 0 1 -5.5,0 l 0,-11 -11.5,-6.25 c -2,-1.25 -2.25,-3.75 -1.25,-5.25 l 8.5,-13 c 1.25,-1.875 4.5,-2.25 6,-0.25 z"/>
@@ -501,6 +503,7 @@
<symbol id="RadiatorWater">
+ <title>Radiator Water</title>
<g style="stroke:none">
<path d="m 17.75,48 c 0.5,-4 2,-6 3.25,-6.5 6.5,-1.5 18.25,-2.25 23,-2.5 l -11.75,-19.625 3.5,0 11.5,19.125 7.25,-12 c 1,-1.5 2.25,-2 4.5,-2 l 7,0 0,3 -7,0 c -1.5,0 -2,1 -2.5,1.75 l -5.75,9.5 15.25,0 0,15.75 -20.5,0 a 11.03,11.03 0 0 0 -22,0 l -4,0 c -1,0 -2.25,-0.5 -2.25,-2 z"/>
<path d="m 20,33.5 c 0,-2 4,-11 4,-11 0,0 4,9 4,11 a 4,4 0 0 1 -8,0 z"/>
@@ -511,6 +514,7 @@
<symbol id="RadiatorWater_Inv">
+ <title>Radiator Water</title>
<rect x="0.5" y="0.5" width="71" height="71" ry="6" style="stroke:white"/>
<g style="fill:white;stroke:none">
<path d="m 17.75,48 c 0.5,-4 2,-6 3.25,-6.5 6.5,-1.5 18.25,-2.25 23,-2.5 l -11.75,-19.625 3.5,0 11.5,19.125 7.25,-12 c 1,-1.5 2.25,-2 4.5,-2 l 7,0 0,3 -7,0 c -1.5,0 -2,1 -2.5,1.75 l -5.75,9.5 15.25,0 0,15.75 -20.5,0 a 11.03,11.03 0 0 0 -22,0 l -4,0 c -1,0 -2.25,-0.5 -2.25,-2 z"/>
@@ -1040,6 +1044,7 @@
</symbol>
<symbol id="blank">
+ <title>Blank</title>
<rect x="1" y="1" width="70" height="70" rx="6" style="fill:none;stroke:black;stroke-width:2"/>
</symbol>
</defs>