pcb_print: fixed frame page orientation in GUI mode.

This commit is contained in:
Salvador E. Tropea 2022-06-12 15:37:00 -03:00
parent 72a2c71ddb
commit 06bb47ea05
5 changed files with 12 additions and 6 deletions

View File

@ -23,6 +23,7 @@ and this project adheres to [Semantic Versioning](https://semver.org/spec/v2.0.0
- Problems expanding multiple KiCad variables in the same value.
- XML BoM: Fixed problems with fields containing / (#206)
- pcb_print: vias processing was disabled.
- pcb_print: frame orientation in GUI mode.
### Changed
- KiCad environment variables: more variables detected, native KiCad 6 names,

View File

@ -13,15 +13,17 @@ from .. import log
logger = log.get_logger()
def patch_svg_file(file, remove_bkg=False):
def patch_svg_file(file, remove_bkg=False, is_portrait=False):
""" KiCad always prints in portrait """
logger.debug('Patching SVG file `{}`'.format(file))
with open(file, 'rt') as f:
text = f.read()
text = re.sub(r'<svg (.*) width="(.*)" height="(.*)" viewBox="(\S+) (\S+) (\S+) (\S+)"',
r'<svg \1 width="\3" height="\2" viewBox="\4 \5 \7 \6"', text)
if not is_portrait:
text = re.sub(r'<svg (.*) width="(.*)" height="(.*)" viewBox="(\S+) (\S+) (\S+) (\S+)"',
r'<svg \1 width="\3" height="\2" viewBox="\4 \5 \7 \6"', text)
if remove_bkg:
text = re.sub(r'<rect.*>', '', text)
else:
elif not is_portrait:
text = re.sub(r'<rect x="(\S+)" y="(\S+)" width="(\S+)" height="(\S+)"',
r'<rect x="\1" y="\2" width="\4" height="\3"', text)
with open(file, 'wt') as f:

View File

@ -476,7 +476,8 @@ class PCB_PrintOptions(VariantOptions):
video_name = os.path.join(self.expand_filename_pcb(GS.out_dir), 'pcbnew_export_screencast.ogv')
if os.path.isfile(video_name):
os.remove(video_name)
patch_svg_file(output, remove_bkg=True)
# Rotate the paper size if needed and remove the background (or it will be over the drawings)
patch_svg_file(output, remove_bkg=True, is_portrait=self.paper_portrait)
def plot_pads(self, la, pc, p, filelist):
id = la._id
@ -742,6 +743,7 @@ class PCB_PrintOptions(VariantOptions):
pcb = PCB.load(GS.pcb_file)
self.paper_w = pcb.paper_w
self.paper_h = pcb.paper_h
self.paper_portrait = pcb.paper_portrait
self.paper = pcb.paper
def plot_extra_cu(self, id, la, pc, p, filelist):

View File

@ -116,5 +116,5 @@ def test_pcb_print_simple_2(test_dir):
if context.ki6():
assert abs(w-431.8) < 0.1 and abs(h-279.4) < 0.1
else:
assert abs(w-297.0) < 0.1 and abs(h-210.0) < 0.1
assert abs(w-210.0) < 0.1 and abs(h-297.0) < 0.1
ctx.clean_up()

View File

@ -10,6 +10,7 @@ outputs:
plot_sheet_reference: true
format: 'PDF'
frame_plot_mechanism: gui
keep_temporal_files: true
pages:
- layers:
- layer: F.Cu