Tue, 26 Sep 2017 19:08:02 +0200
SVG options: offset, original scale
SVG Bugfix: "scale" does now really fit to dimensions
printrun-src/printrun/laser.py | file | annotate | diff | comparison | revisions | |
printrun-src/printrun/pronterface.py | file | annotate | diff | comparison | revisions |
--- a/printrun-src/printrun/laser.py Sat Sep 23 13:07:51 2017 +0200 +++ b/printrun-src/printrun/laser.py Tue Sep 26 19:08:02 2017 +0200 @@ -302,8 +302,8 @@ from svg2gcode.shapes import point_generator from svg2gcode import simplepath, cspsubdiv, cubicsuperpath, simpletransform - bed_max_x = self.settings.lc_svg_width - bed_max_y = self.settings.lc_svg_height + bed_max_x = float(self.settings.lc_svg_width) + bed_max_y = float(self.settings.lc_svg_height) self.log("Generating paths from SVG (outlines only)...") svg_shapes = set(['rect', 'circle', 'ellipse', 'line', 'polyline', 'polygon', 'path']) @@ -368,14 +368,16 @@ max_x = x if y > max_y: max_y = y - #ofs_x = 0 - #ofs_y = 0 - - ofs_x *= -1 - ofs_y *= -1 - max_x += ofs_x - max_y += ofs_y - self.log("Calculated Offset to 0,0 is %f,%f" % (ofs_x, ofs_y)) + + if self.settings.lc_svg_offset: + ofs_x *= -1 + ofs_y *= -1 + max_x += ofs_x + max_y += ofs_y + self.log("Calculated Offset to 0,0 is %f,%f" % (ofs_x, ofs_y)) + else: + ofs_x = 0 + ofs_y = 0 """ self.log("Calculated Dimension is %f,%f" % (max_x, max_y)) @@ -383,8 +385,21 @@ height = max_y """ - if self.settings.lc_svg_scalemode == "scale": - scale_x = scale_y = min(bed_max_x, bed_max_y) / max(width, height) + if self.settings.lc_svg_scalemode == "original": + scale_x = 1.0 + scale_y = 1.0 + elif self.settings.lc_svg_scalemode == "scale": + scale_x = bed_max_x / width + scale_y = bed_max_y / height + if (scale_x * height) > bed_max_y: + # use y scale + scale_x = scale_y + elif (scale_y * width) > bed_max_x: + # use x scale + scale_y = scale_x + # double-check + if (scale_x * width > bed_max_x) or (scale_y * height > bed_max_y): + scale_x = scale_y = min(bed_max_x, bed_max_y) / max(width, height) else: scale_x = bed_max_x / width scale_y = bed_max_y / height
--- a/printrun-src/printrun/pronterface.py Sat Sep 23 13:07:51 2017 +0200 +++ b/printrun-src/printrun/pronterface.py Tue Sep 26 19:08:02 2017 +0200 @@ -338,7 +338,8 @@ self.settings._add(FloatSpinSetting("lc_svg_smoothness", 0.2, 0.1, 10.0, "Smoothness", "Smoothness of curves (smaller value = smoother curve)", "Laser"), self.update_lc_settings) self.settings._add(SpinSetting("lc_svg_width", 50, 1, 250, "Width (mm)", "Image width", "Laser"), self.update_lc_settings) self.settings._add(SpinSetting("lc_svg_height", 50, 1, 250, "Height (mm)", "Image height", "Laser"), self.update_lc_settings) - self.settings._add(ComboSetting("lc_svg_scalemode", "scale", ["scale", "stretch"], "Scaling mode", "scale to dimensions / stretch to dimensions", "Laser"), self.update_lc_settings) + self.settings._add(ComboSetting("lc_svg_scalemode", "original", ["original", "scale", "stretch"], "Scaling mode", "scale/stretch to above dimensions", "Laser"), self.update_lc_settings) + self.settings._add(BooleanSetting("lc_svg_offset", True, "Calculate offset to X=0, Y=0", "If enabled, move image to origin position", "Laser"), self.update_lc_settings) # -------------------------------------------------------------- # Main interface handling