@@ -133,8 +133,8 @@ def getSVG(shape, opts=None):
133
133
:type Shape: Vertex, Edge, Wire, Face, Shell, Solid, or Compound.
134
134
:param opts: An options dictionary that influences the SVG that is output.
135
135
:type opts: Dictionary, keys are as follows:
136
- width: Document width of the resulting image.
137
- height: Document height of the resulting image.
136
+ width: Width of the resulting image (-1 to fit based on height) .
137
+ height: Height of the resulting image (-1 to fit based on width) .
138
138
marginLeft: Inset margin from the left side of the document.
139
139
marginTop: Inset margin from the top side of the document.
140
140
projectionDir: Direction the camera will view the shape from.
@@ -180,7 +180,6 @@ def getSVG(shape, opts=None):
180
180
hiddenColor = tuple (d ["hiddenColor" ])
181
181
showHidden = bool (d ["showHidden" ])
182
182
focus = float (d ["focus" ]) if d .get ("focus" ) else None
183
- fitView = bool (d ["fitView" ]) if d .get ("fitView" ) else None
184
183
185
184
hlr = HLRBRep_Algo ()
186
185
hlr .Add (shape .wrapped )
@@ -237,24 +236,21 @@ def getSVG(shape, opts=None):
237
236
bb = Compound .makeCompound (hidden + visible ).BoundingBox ()
238
237
239
238
# Determine whether the user wants to fit the drawing to the bounding box
240
- bb_scale = 0.75
241
- if fitView :
242
- bb_scale = 1.0
243
-
244
- # Figure out which dimension to base the adjusted image size on
245
- if width / bb .xlen < height / bb .ylen :
246
- height = width * (bb .ylen / bb .xlen )
239
+ if width <= 0 or height <= 0 :
240
+ # Fit image to specified width (or height)
241
+ if width <= 0 :
242
+ width = (height - (2.0 * marginTop )) * (
243
+ bb .xlen / bb .ylen
244
+ ) + 2.0 * marginLeft
247
245
else :
248
- width = height * (bb .xlen / bb .ylen )
246
+ height = ( width - 2.0 * marginLeft ) * (bb .ylen / bb .xlen ) + 2.0 * marginTop
249
247
250
- image_width = width + ( marginLeft * 2.0 )
251
- image_height = height + ( marginTop * 2.0 )
248
+ # width pixels for x, height pixels for y
249
+ unitScale = ( width - 2.0 * marginLeft ) / bb . xlen
252
250
else :
253
- image_width = width
254
- image_height = height
255
-
256
- # width pixels for x, height pixels for y
257
- unitScale = min (width / bb .xlen * bb_scale , height / bb .ylen * bb_scale )
251
+ bb_scale = 0.75
252
+ # width pixels for x, height pixels for y
253
+ unitScale = min (width / bb .xlen * bb_scale , height / bb .ylen * bb_scale )
258
254
259
255
# compute amount to translate-- move the top left into view
260
256
(xTranslate , yTranslate ) = (
@@ -296,8 +292,8 @@ def getSVG(shape, opts=None):
296
292
"visibleContent" : visibleContent ,
297
293
"xTranslate" : str (xTranslate ),
298
294
"yTranslate" : str (yTranslate ),
299
- "width" : str (image_width ),
300
- "height" : str (image_height ),
295
+ "width" : str (width ),
296
+ "height" : str (height ),
301
297
"textboxY" : str (height - 30 ),
302
298
"uom" : str (uom ),
303
299
"axesIndicator" : axesIndicator ,
0 commit comments