Skip to content

Commit

Permalink
Draft: Added a pref option to disable SVG page scaling on import - fixes
Browse files Browse the repository at this point in the history
  • Loading branch information
yorikvanhavre committed Sep 6, 2015
1 parent 4da63d1 commit 3665b77
Show file tree
Hide file tree
Showing 2 changed files with 54 additions and 29 deletions.
23 changes: 23 additions & 0 deletions src/Mod/Draft/Resources/ui/preferences-svg.ui
Expand Up @@ -74,6 +74,29 @@
</item>
</layout>
</item>
<item>
<layout class="QHBoxLayout" name="horizontalLayout">
<item>
<widget class="Gui::PrefCheckBox" name="checkBox">
<property name="toolTip">
<string>If this is checked, no units conversion will occur. One unit in the SVG file will translate as one millimeter.</string>
</property>
<property name="text">
<string>Disable units scaling</string>
</property>
<property name="checked">
<bool>false</bool>
</property>
<property name="prefEntry" stdset="0">
<cstring>svgDisableUnitScaling</cstring>
</property>
<property name="prefPath" stdset="0">
<cstring>Mod/Draft</cstring>
</property>
</widget>
</item>
</layout>
</item>
</layout>
</widget>
</item>
Expand Down
60 changes: 31 additions & 29 deletions src/Mod/Draft/importSVG.py
Expand Up @@ -386,6 +386,7 @@ def __init__(self):
"retrieving Draft parameters"
params = FreeCAD.ParamGet("User parameter:BaseApp/Preferences/Mod/Draft")
self.style = params.GetInt("svgstyle")
self.disableUnitScaling = params.GetBool("svgDisableUnitScaling",False)
self.count = 0
self.transform = None
self.grouptransform = []
Expand Down Expand Up @@ -467,36 +468,37 @@ def startElement(self, name, attrs):

if name == 'svg':
m=FreeCAD.Matrix()
if 'width' in data and 'height' in data and \
'viewBox' in data:
vbw=float(data['viewBox'][2])
vbh=float(data['viewBox'][3])
w=attrs.getValue('width')
h=attrs.getValue('height')
self.viewbox=(vbw,vbh)
if len(self.grouptransform)==0:
unitmode='mm'
else: #nested svg element
unitmode='css'
abw = getsize(w,unitmode)
abh = getsize(h,unitmode)
sx=abw/vbw
sy=abh/vbh
preservearstr=' '.join(data.get('preserveAspectRatio',[])).lower()
uniformscaling = round(sx/sy,5) == 1
if uniformscaling:
m.scale(Vector(sx,sy,1))
else:
FreeCAD.Console.PrintWarning('Scaling Factors do not match!!!\n')
if preservearstr.startswith('none'):
if not self.disableUnitScaling:
if 'width' in data and 'height' in data and \
'viewBox' in data:
vbw=float(data['viewBox'][2])
vbh=float(data['viewBox'][3])
w=attrs.getValue('width')
h=attrs.getValue('height')
self.viewbox=(vbw,vbh)
if len(self.grouptransform)==0:
unitmode='mm'
else: #nested svg element
unitmode='css'
abw = getsize(w,unitmode)
abh = getsize(h,unitmode)
sx=abw/vbw
sy=abh/vbh
preservearstr=' '.join(data.get('preserveAspectRatio',[])).lower()
uniformscaling = round(sx/sy,5) == 1
if uniformscaling:
m.scale(Vector(sx,sy,1))
else: #preserve the aspect ratio
if preservearstr.endswith('slice'):
sxy=max(sx,sy)
else:
sxy=min(sx,sy)
m.scale(Vector(sxy,sxy,1))
elif len(self.grouptransform)==0:
else:
FreeCAD.Console.PrintWarning('Scaling Factors do not match!!!\n')
if preservearstr.startswith('none'):
m.scale(Vector(sx,sy,1))
else: #preserve the aspect ratio
if preservearstr.endswith('slice'):
sxy=max(sx,sy)
else:
sxy=min(sx,sy)
m.scale(Vector(sxy,sxy,1))
elif len(self.grouptransform)==0:
#fallback to 90 dpi
m.scale(Vector(25.4/90.0,25.4/90.0,1))
self.grouptransform.append(m)
Expand Down

0 comments on commit 3665b77

Please sign in to comment.