Skip to content

Commit 0a137fe

Browse files
committed
Fix detecting drawing box
1 parent 1bb0d7b commit 0a137fe

File tree

1 file changed

+13
-1
lines changed

1 file changed

+13
-1
lines changed

pcbdraw/plot.py

+13-1
Original file line numberDiff line numberDiff line change
@@ -1272,7 +1272,19 @@ def _shrink_svg(self, svg: etree.ElementTree, margin: int) -> None:
12721272
from xml.etree.ElementTree import fromstring as xmlParse
12731273

12741274
from lxml.etree import tostring as serializeXml # type: ignore
1275-
paths = svgpathtools.document.flattened_paths(xmlParse(serializeXml(svg)))
1275+
tree = xmlParse(serializeXml(svg))
1276+
1277+
# As we cannot interpret mask cropping, we cannot simply take all paths
1278+
# from source document (as e.g., silkscreen outside PCB) would enlarge
1279+
# the canvas. Instead, we take bounding box of the substrate and
1280+
# components separately
1281+
paths = []
1282+
components = tree.find(".//*[@id='componentContainer']")
1283+
if components is not None:
1284+
paths += svgpathtools.document.flattened_paths(components)
1285+
substrate = tree.find(".//*[@id='cut-off']")
1286+
if substrate is not None:
1287+
paths += svgpathtools.document.flattened_paths(substrate)
12761288

12771289
if len(paths) == 0:
12781290
return

0 commit comments

Comments
 (0)