[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.
This commit is contained in:
parent
20f324087f
commit
7ed371cd50
|
|
@ -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)
|
||||
|
|
|
|||
|
|
@ -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':
|
||||
|
|
|
|||
Loading…
Reference in New Issue