Skip to content

Commit cdac06d

Browse files
author
Juergen Weigert
committed
fixes #19
1 parent 085def8 commit cdac06d

File tree

1 file changed

+20
-0
lines changed

1 file changed

+20
-0
lines changed

sendto_silhouette.py

Lines changed: 20 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -77,6 +77,7 @@
7777
# 2016-05-21 jw, v1.18 -- warn about python-usb < 1.0 and give instructions.
7878
# Limit pressure to 18. 19 or 20 make the machine
7979
# scroll forward backward for several minutes.
80+
# Support document unit inches. https://github.com/fablabnbg/inkscape-silhouette/issues/19
8081

8182
__version__ = '1.18' # Keep in sync with sendto_silhouette.inx ca line 79
8283
__author__ = 'Juergen Weigert <[email protected]> and contributors'
@@ -131,6 +132,7 @@ def px2mm(px):
131132
return px*25.4/90
132133

133134
# Lifted with impunity from eggbot.py
135+
# Added all known inkscape units. https://github.com/fablabnbg/inkscape-silhouette/issues/19
134136
def parseLengthWithUnits( str ):
135137

136138
'''
@@ -148,12 +150,25 @@ def parseLengthWithUnits( str ):
148150
elif s[-2:] == 'mm':
149151
u = 'mm'
150152
s = s[:-2]
153+
elif s[-2:] == 'pt':
154+
u = 'pt'
155+
s = s[:-2]
156+
elif s[-2:] == 'pc':
157+
u = 'pc'
158+
s = s[:-2]
159+
elif s[-2:] == 'cm':
160+
u = 'cm'
161+
s = s[:-2]
162+
elif s[-2:] == 'in':
163+
u = 'in'
164+
s = s[:-2]
151165
elif s[-1:] == '%':
152166
u = '%'
153167
s = s[:-1]
154168
try:
155169
v = float( s )
156170
except:
171+
print >>sys.stderr, "parseLengthWithUnits: unknown unit ", s
157172
return None, None
158173

159174
return v, u
@@ -861,10 +876,15 @@ def getLength( self, name, default ):
861876
return v
862877
elif u == 'mm':
863878
return v*90./25.4 # inverse of px2mm
879+
elif u == 'in':
880+
return v*90.
881+
elif u == 'cm':
882+
return v*90./2.54 # inverse of 10*px2mm
864883
elif u == '%':
865884
return float( default ) * v / 100.0
866885
else:
867886
print >>sys.stderr, "unknown unit ", u
887+
print >>self.tty, "unknown unit ", u
868888
return None
869889
else:
870890
# No width specified; assume the default value

0 commit comments

Comments
 (0)