From 7ed371cd50c39eeb6ce12fcdaf969d3ebfff5544 Mon Sep 17 00:00:00 2001 From: "Salvador E. Tropea" Date: Fri, 23 Sep 2022 12:34:54 -0300 Subject: [PATCH] [Pcb_Print] RSVG 2.54 seems to solve scale issues - So now we adjust the scale according to the resulting size, instead of assuming RSVG will do it always wrong. --- kibot/create_pdf.py | 10 ++++++++-- kibot/out_pcb_print.py | 5 +++-- 2 files changed, 11 insertions(+), 4 deletions(-) diff --git a/kibot/create_pdf.py b/kibot/create_pdf.py index 3bcafa14..fa269a7e 100644 --- a/kibot/create_pdf.py +++ b/kibot/create_pdf.py @@ -6,9 +6,12 @@ # Project: KiBot (formerly KiPlot) # Base idea: https://gitlab.com/dennevi/Board2Pdf/ (Released as Public Domain) from . import PyPDF2 +from . import log + +logger = log.get_logger() -def create_pdf_from_pages(input_files, output_fn, scale=1.0): +def create_pdf_from_pages(input_files, output_fn, forced_width=None): output = PyPDF2.PdfFileWriter() # Collect all pages open_files = [] @@ -17,7 +20,10 @@ def create_pdf_from_pages(input_files, output_fn, scale=1.0): open_files.append(file) pdf_reader = PyPDF2.PdfFileReader(file) page_obj = pdf_reader.getPage(0) - if scale != 1.0: + if forced_width is not None: + width = page_obj.mediaBox.getWidth()*25.4/72 + scale = forced_width/width + logger.debugl(1, 'PDF scale {} ({} -> {})'.format(scale, width, forced_width)) page_obj.scaleBy(scale) page_obj.compressContentStreams() output.addPage(page_obj) diff --git a/kibot/out_pcb_print.py b/kibot/out_pcb_print.py index 68f7baab..f14a90e0 100644 --- a/kibot/out_pcb_print.py +++ b/kibot/out_pcb_print.py @@ -867,6 +867,7 @@ class PCB_PrintOptions(VariantOptions): def svg_to_pdf(self, input_folder, svg_file, pdf_file): # Note: rsvg-convert uses 90 dpi but KiCad (and the docs I found) says SVG pt is 72 dpi # We use a 5x scale and then reduce it to maintain the page size + # Note: rsvg 2.50.3 has this problem 2.54.5 doesn't, so we ensure the size is correct, not a fixed scale dpi = str(self.dpi) cmd = [self.rsvg_command, '-d', dpi, '-p', dpi, '-f', 'pdf', '-o', os.path.join(input_folder, pdf_file), os.path.join(input_folder, svg_file)] @@ -917,8 +918,8 @@ class PCB_PrintOptions(VariantOptions): logger.debug('- Creating {} from {}'.format(pdf_file, svg_file)) self.svg_to_pdf(input_folder, svg_file, pdf_file) svg_files.append(os.path.join(input_folder, pdf_file)) - logger.debug('- Joining {} into {}'.format(svg_files, output_fn)) - create_pdf_from_pages(svg_files, output_fn, scale=72.0/self.dpi) + logger.debug('- Joining {} into {} ({}x{})'.format(svg_files, output_fn, self.paper_w, self.paper_h)) + create_pdf_from_pages(svg_files, output_fn, forced_width=self.paper_w) def check_tools(self): if self.format != 'SVG':