@@ -133,8 +133,8 @@ def getSVG(shape, opts=None):
133133 :type Shape: Vertex, Edge, Wire, Face, Shell, Solid, or Compound.
134134 :param opts: An options dictionary that influences the SVG that is output.
135135 :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) .
138138 marginLeft: Inset margin from the left side of the document.
139139 marginTop: Inset margin from the top side of the document.
140140 projectionDir: Direction the camera will view the shape from.
@@ -180,7 +180,6 @@ def getSVG(shape, opts=None):
180180 hiddenColor = tuple (d ["hiddenColor" ])
181181 showHidden = bool (d ["showHidden" ])
182182 focus = float (d ["focus" ]) if d .get ("focus" ) else None
183- fitView = bool (d ["fitView" ]) if d .get ("fitView" ) else None
184183
185184 hlr = HLRBRep_Algo ()
186185 hlr .Add (shape .wrapped )
@@ -237,24 +236,21 @@ def getSVG(shape, opts=None):
237236 bb = Compound .makeCompound (hidden + visible ).BoundingBox ()
238237
239238 # 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
247245 else :
248- width = height * (bb .xlen / bb .ylen )
246+ height = ( width - 2.0 * marginLeft ) * (bb .ylen / bb .xlen ) + 2.0 * marginTop
249247
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
252250 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 )
258254
259255 # compute amount to translate-- move the top left into view
260256 (xTranslate , yTranslate ) = (
@@ -296,8 +292,8 @@ def getSVG(shape, opts=None):
296292 "visibleContent" : visibleContent ,
297293 "xTranslate" : str (xTranslate ),
298294 "yTranslate" : str (yTranslate ),
299- "width" : str (image_width ),
300- "height" : str (image_height ),
295+ "width" : str (width ),
296+ "height" : str (height ),
301297 "textboxY" : str (height - 30 ),
302298 "uom" : str (uom ),
303299 "axesIndicator" : axesIndicator ,
0 commit comments