From 8c3e5b982b29448e24912093daf9a9b7f9289478 Mon Sep 17 00:00:00 2001 From: "Salvador E. Tropea" Date: Fri, 16 Dec 2022 13:44:12 -0300 Subject: [PATCH] [PCB_Print][Fixed] Images not showing in custom frames. Closes #352 --- CHANGELOG.md | 3 +++ kibot/kicad/worksheet.py | 12 +++++++++--- kibot/out_pcb_print.py | 2 +- 3 files changed, 13 insertions(+), 4 deletions(-) diff --git a/CHANGELOG.md b/CHANGELOG.md index bfcd9c55..3e6a0cfe 100644 --- a/CHANGELOG.md +++ b/CHANGELOG.md @@ -5,6 +5,9 @@ The format is based on [Keep a Changelog](https://keepachangelog.com/en/1.0.0/), and this project adheres to [Semantic Versioning](https://semver.org/spec/v2.0.0.html). ## [1.5.2] - Unreleased +### Fixed +- PCB_Print: + - Images not showing in custom frames. (#352) ## [1.5.1] - 2022-12-16 ### Fixed diff --git a/kibot/kicad/worksheet.py b/kibot/kicad/worksheet.py index 24160e1e..2d6b90c6 100644 --- a/kibot/kicad/worksheet.py +++ b/kibot/kicad/worksheet.py @@ -403,7 +403,7 @@ class WksBitmap(WksDrawing): # Make a list to be added to the SVG output p.images.append(e) - def add_to_svg(e, svg, p): + def add_to_svg(e, svg, p, svg_precision): s = e.data w, h = unpack('>LL', s[16:24]) # For KiCad 300 dpi is 1:1 scale @@ -413,6 +413,10 @@ class WksBitmap(WksDrawing): h = FromMM(h/dpi*25.4) # KiCad informs the position for the center of the image pos, posi = p.solve_ref(e.pos, e.incrx, e.incry, e.pos_ref) + # KiCad 6 can adjust the precision + # The default is 6 and makes 1 KiCad unit == 1 SVG unit + # But this isn't supported by browsers (Chrome and Firefox) + scale = 10.0 ** (svg_precision - 6) for _ in range(e.repeat): img = ImageElement(io.BytesIO(s), w, h) x = pos.x-round(w/2) @@ -421,6 +425,8 @@ class WksBitmap(WksDrawing): if GS.ki5: # KiCad 5 uses Inches and with less resolution img.scale(KICAD5_SVG_SCALE) + elif svg_precision != 6: + img.scale(scale) # Put the image in a group g = GroupElement([img]) # Add the group to the SVG @@ -527,9 +533,9 @@ class Worksheet(object): continue e.draw(self) - def add_images_to_svg(self, svg): + def add_images_to_svg(self, svg, svg_precision): for e in self.images: - e.add_to_svg(svg, self) + e.add_to_svg(svg, self, svg_precision) def out_of_margin(self, p): """ Used to check if the repeat went outside the page usable area """ diff --git a/kibot/out_pcb_print.py b/kibot/out_pcb_print.py index a524a4b0..674cf9d7 100644 --- a/kibot/out_pcb_print.py +++ b/kibot/out_pcb_print.py @@ -669,7 +669,7 @@ class PCB_PrintOptions(VariantOptions): img.data = f.read() os.remove(fname) os.remove(dest) - self.last_worksheet.add_images_to_svg(svg) + self.last_worksheet.add_images_to_svg(svg, self.svg_precision) def fill_polygons(self, svg, color): """ I don't know how to generate filled polygons on KiCad 5.