@@ -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 (None to fit based on height) .
137
+ height: Height of the resulting image (None 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.
@@ -169,8 +169,13 @@ def getSVG(shape, opts=None):
169
169
# need to guess the scale and the coordinate center
170
170
uom = guessUnitOfMeasure (shape )
171
171
172
- width = float (d ["width" ])
173
- height = float (d ["height" ])
172
+ # Handle the case where the height or width are None
173
+ width = d ["width" ]
174
+ if width != None :
175
+ width = float (d ["width" ])
176
+ height = d ["height" ]
177
+ if d ["height" ] != None :
178
+ height = float (d ["height" ])
174
179
marginLeft = float (d ["marginLeft" ])
175
180
marginTop = float (d ["marginTop" ])
176
181
projectionDir = tuple (d ["projectionDir" ])
@@ -235,8 +240,22 @@ def getSVG(shape, opts=None):
235
240
# get bounding box -- these are all in 2D space
236
241
bb = Compound .makeCompound (hidden + visible ).BoundingBox ()
237
242
238
- # width pixels for x, height pixels for y
239
- unitScale = min (width / bb .xlen * 0.75 , height / bb .ylen * 0.75 )
243
+ # Determine whether the user wants to fit the drawing to the bounding box
244
+ if width == None or height == None :
245
+ # Fit image to specified width (or height)
246
+ if width == None :
247
+ width = (height - (2.0 * marginTop )) * (
248
+ bb .xlen / bb .ylen
249
+ ) + 2.0 * marginLeft
250
+ else :
251
+ height = (width - 2.0 * marginLeft ) * (bb .ylen / bb .xlen ) + 2.0 * marginTop
252
+
253
+ # width pixels for x, height pixels for y
254
+ unitScale = (width - 2.0 * marginLeft ) / bb .xlen
255
+ else :
256
+ bb_scale = 0.75
257
+ # width pixels for x, height pixels for y
258
+ unitScale = min (width / bb .xlen * bb_scale , height / bb .ylen * bb_scale )
240
259
241
260
# compute amount to translate-- move the top left into view
242
261
(xTranslate , yTranslate ) = (
0 commit comments