Skip to content

Commit 65de218

Browse files
committed
Trying to be smarter about using the desired image size
1 parent 176ff70 commit 65de218

File tree

2 files changed

+7
-3
lines changed

2 files changed

+7
-3
lines changed

cadquery/occ_impl/exporters/svg.py

Lines changed: 6 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -240,8 +240,12 @@ def getSVG(shape, opts=None):
240240
bb_scale = 0.75
241241
if fitView:
242242
bb_scale = 1.0
243-
width = bb.xlen
244-
height = bb.ylen
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)
247+
else:
248+
width = height * (bb.xlen / bb.ylen)
245249

246250
# width pixels for x, height pixels for y
247251
unitScale = min(width / bb.xlen * bb_scale, height / bb.ylen * bb_scale)

doc/importexport.rst

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -216,7 +216,7 @@ options are as follows.
216216
* *hiddenColor* - Color of the line that hidden edges are drawn with.
217217
* *showHidden* - Whether or not to show hidden lines.
218218
* *focus* - If specified, creates a perspective SVG with the projector at the distance specified.
219-
* *fitView* - If specified, will attempt to fit the height and width of the image to the contents. The ``marginLeft`` and ``marginTop`` options should be set to 0 or the object will fall outside the viewport. The ``width`` and ``height`` options that were specified will be overridden, which can cause unexpected final image sizes.
219+
* *fitView* - If specified, will attempt to fit the height and width of the image to the contents. The ``marginLeft`` and ``marginTop`` options should be set to 0 or the object will fall outside the viewport. The ``width`` or ``height`` options that were specified will be overridden, but the largest dimension should be preserved.
220220

221221
The options are passed to the exporter in a dictionary, and can be left out to force the SVG to be created with default options.
222222
Below are examples with and without options set.

0 commit comments

Comments
 (0)