- finished working in adding DPI settings for PNG export in Film Tool although there are some limitations due of Reportlab

This commit is contained in:
Marius Stanciu 2020-10-06 12:49:24 +03:00 committed by Marius
parent f99a5a8073
commit 8cb4b5abf8
3 changed files with 47 additions and 31 deletions

View File

@ -10,6 +10,7 @@ CHANGELOG for FlatCAM beta
5.10.2020 5.10.2020
- working on adding DPI setting for PNG export in the Film Tool - working on adding DPI setting for PNG export in the Film Tool
- finished working in adding DPI settings for PNG export in Film Tool although there are some limitations due of Reportlab
26.09.2020 26.09.2020

View File

@ -436,23 +436,31 @@ class Film(AppTool):
self.app.inform.emit('[WARNING_NOTCL] %s: %s' % (_("No object Box. Using instead"), obj)) self.app.inform.emit('[WARNING_NOTCL] %s: %s' % (_("No object Box. Using instead"), obj))
box = obj box = obj
new_png_dpi = self.ui.png_dpi_spinner.get_value() scale_factor_x = scale_factor_x
dpi_rate = new_png_dpi / 96 scale_factor_y = scale_factor_y
if dpi_rate != 1:
scale_factor_x += dpi_rate
scale_factor_y += dpi_rate
def make_negative_film(): def make_negative_film(scale_factor_x, scale_factor_y):
exported_svg = obj.export_svg(scale_stroke_factor=scale_stroke_factor, log.debug("FilmTool.export_negative().make_negative_film()")
scale_factor_x=scale_factor_x, scale_factor_y=scale_factor_y,
skew_factor_x=skew_factor_x, skew_factor_y=skew_factor_y,
mirror=mirror
)
scale_reference = 'center'
# Determine bounding area for svg export # Determine bounding area for svg export
bounds = box.bounds() bounds = box.bounds()
size = box.size() size = box.size()
default_dpi = 96
new_png_dpi = self.ui.png_dpi_spinner.get_value()
dpi_rate = new_png_dpi / default_dpi
if dpi_rate != 1:
scale_factor_x += dpi_rate
scale_factor_y += dpi_rate
scale_reference = (bounds[0], bounds[1])
exported_svg = obj.export_svg(scale_stroke_factor=scale_stroke_factor,
scale_factor_x=scale_factor_x, scale_factor_y=scale_factor_y,
skew_factor_x=skew_factor_x, skew_factor_y=skew_factor_y,
mirror=mirror, scale_reference=scale_reference
)
uom = obj.units.lower() uom = obj.units.lower()
# Convert everything to strings for use in the xml doc # Convert everything to strings for use in the xml doc
@ -521,7 +529,7 @@ class Film(AppTool):
try: try:
doc_final = StringIO(doc_final) doc_final = StringIO(doc_final)
drawing = svg2rlg(doc_final) drawing = svg2rlg(doc_final)
if new_png_dpi == 96: if new_png_dpi == default_dpi:
renderPM.drawToFile(drawing, filename, 'PNG') renderPM.drawToFile(drawing, filename, 'PNG')
else: else:
renderPM.drawToFile(drawing, filename, 'PNG', dpi=new_png_dpi) renderPM.drawToFile(drawing, filename, 'PNG', dpi=new_png_dpi)
@ -565,7 +573,7 @@ class Film(AppTool):
def job_thread_film(app_obj): def job_thread_film(app_obj):
try: try:
make_negative_film() make_negative_film(scale_factor_x=scale_factor_x, scale_factor_y=scale_factor_y)
except Exception: except Exception:
proc.done() proc.done()
return return
@ -626,24 +634,34 @@ class Film(AppTool):
self.inform.emit('[WARNING_NOTCL] %s: %s' % (_("No object Box. Using instead"), obj)) self.inform.emit('[WARNING_NOTCL] %s: %s' % (_("No object Box. Using instead"), obj))
box = obj box = obj
scale_factor_x = scale_factor_x
scale_factor_y = scale_factor_y
p_size = pagesize_val p_size = pagesize_val
orientation = orientation_val orientation = orientation_val
color = color_val color = color_val
transparency_level = opacity_val transparency_level = opacity_val
new_png_dpi = self.ui.png_dpi_spinner.get_value() def make_positive_film(p_size, orientation, color, transparency_level, scale_factor_x, scale_factor_y):
dpi_rate = new_png_dpi / 96
if dpi_rate != 1:
scale_factor_x += dpi_rate
scale_factor_y += dpi_rate
def make_positive_film(p_size, orientation, color, transparency_level):
log.debug("FilmTool.export_positive().make_positive_film()") log.debug("FilmTool.export_positive().make_positive_film()")
scale_reference = 'center'
# Determine bounding area for svg export
bounds = box.bounds()
size = box.size()
default_dpi = 96
new_png_dpi = self.ui.png_dpi_spinner.get_value()
dpi_rate = new_png_dpi / default_dpi
if dpi_rate != 1:
scale_factor_x += dpi_rate
scale_factor_y += dpi_rate
scale_reference = (bounds[0], bounds[1])
exported_svg = obj.export_svg(scale_stroke_factor=scale_stroke_factor, exported_svg = obj.export_svg(scale_stroke_factor=scale_stroke_factor,
scale_factor_x=scale_factor_x, scale_factor_y=scale_factor_y, scale_factor_x=scale_factor_x, scale_factor_y=scale_factor_y,
skew_factor_x=skew_factor_x, skew_factor_y=skew_factor_y, skew_factor_x=skew_factor_x, skew_factor_y=skew_factor_y,
mirror=mirror mirror=mirror, scale_reference=scale_reference
) )
# Change the attributes of the exported SVG # Change the attributes of the exported SVG
@ -658,10 +676,6 @@ class Film(AppTool):
exported_svg = ET.tostring(root) exported_svg = ET.tostring(root)
# Determine bounding area for svg export
bounds = box.bounds()
size = box.size()
# This contain the measure units # This contain the measure units
uom = obj.units.lower() uom = obj.units.lower()
@ -709,7 +723,7 @@ class Film(AppTool):
try: try:
doc_final = StringIO(doc_final) doc_final = StringIO(doc_final)
drawing = svg2rlg(doc_final) drawing = svg2rlg(doc_final)
if new_png_dpi == 96: if new_png_dpi == default_dpi:
renderPM.drawToFile(drawing, filename, 'PNG') renderPM.drawToFile(drawing, filename, 'PNG')
else: else:
renderPM.drawToFile(drawing, filename, 'PNG', dpi=new_png_dpi) renderPM.drawToFile(drawing, filename, 'PNG', dpi=new_png_dpi)
@ -753,7 +767,8 @@ class Film(AppTool):
def job_thread_film(): def job_thread_film():
try: try:
make_positive_film(p_size=p_size, orientation=orientation, color=color, make_positive_film(p_size=p_size, orientation=orientation, color=color,
transparency_level=transparency_level) transparency_level=transparency_level,
scale_factor_x=scale_factor_x, scale_factor_y=scale_factor_y)
except Exception: except Exception:
proc.done() proc.done()
return return

View File

@ -2221,7 +2221,7 @@ class Geometry(object):
def export_svg(self, scale_stroke_factor=0.00, def export_svg(self, scale_stroke_factor=0.00,
scale_factor_x=None, scale_factor_y=None, scale_factor_x=None, scale_factor_y=None,
skew_factor_x=None, skew_factor_y=None, skew_factor_x=None, skew_factor_y=None,
skew_reference='center', skew_reference='center', scale_reference='center',
mirror=None): mirror=None):
""" """
Exports the Geometry Object as a SVG Element Exports the Geometry Object as a SVG Element
@ -2256,11 +2256,11 @@ class Geometry(object):
geom = geom_svg geom = geom_svg
if scale_factor_x and not scale_factor_y: if scale_factor_x and not scale_factor_y:
geom = affinity.scale(geom_svg, scale_factor_x, 1.0) geom = affinity.scale(geom_svg, scale_factor_x, 1.0, origin=scale_reference)
elif not scale_factor_x and scale_factor_y: elif not scale_factor_x and scale_factor_y:
geom = affinity.scale(geom_svg, 1.0, scale_factor_y) geom = affinity.scale(geom_svg, 1.0, scale_factor_y, origin=scale_reference)
elif scale_factor_x and scale_factor_y: elif scale_factor_x and scale_factor_y:
geom = affinity.scale(geom_svg, scale_factor_x, scale_factor_y) geom = affinity.scale(geom_svg, scale_factor_x, scale_factor_y, origin=scale_reference)
if skew_factor_x and not skew_factor_y: if skew_factor_x and not skew_factor_y:
geom = affinity.skew(geom_svg, skew_factor_x, 0.0, origin=skew_ref) geom = affinity.skew(geom_svg, skew_factor_x, 0.0, origin=skew_ref)