- Film Tool: fixed the export to PNG to be done at correct DPI
This commit is contained in:
@@ -13,6 +13,7 @@ CHANGELOG for FlatCAM Evo beta
|
|||||||
- the selection shapes are now moved from Move Plugin to AppMain
|
- the selection shapes are now moved from Move Plugin to AppMain
|
||||||
- Fiducials Plugin: fixed errors due of changes in the Shapely module
|
- Fiducials Plugin: fixed errors due of changes in the Shapely module
|
||||||
- Fiducials Plugin: fixed an error where in Basic mode the soldermask opening is added incorrectly
|
- Fiducials Plugin: fixed an error where in Basic mode the soldermask opening is added incorrectly
|
||||||
|
- Film Tool: fixed the export to PNG to be done at correct DPI
|
||||||
|
|
||||||
17.05.2023
|
17.05.2023
|
||||||
|
|
||||||
|
|||||||
@@ -655,7 +655,8 @@ class Film(AppTool):
|
|||||||
color = obj.obj_options['tools_film_color']
|
color = obj.obj_options['tools_film_color']
|
||||||
transparency_level = opacity_val
|
transparency_level = opacity_val
|
||||||
|
|
||||||
def make_negative_film(color, transparency_level, scale_factor_x, scale_factor_y, use_convex_hull, rounded_box):
|
def make_negative_film(color, transparency_level, scale_factor_x, scale_factor_y, use_convex_hull,
|
||||||
|
rounded_box, scale_type):
|
||||||
self.app.log.debug("FilmTool.export_negative_handler().make_negative_film()")
|
self.app.log.debug("FilmTool.export_negative_handler().make_negative_film()")
|
||||||
|
|
||||||
self.screen_dpi = self.app.qapp.screens()[0].logicalDotsPerInch()
|
self.screen_dpi = self.app.qapp.screens()[0].logicalDotsPerInch()
|
||||||
@@ -664,8 +665,13 @@ class Film(AppTool):
|
|||||||
dpi_rate = new_png_dpi / self.screen_dpi
|
dpi_rate = new_png_dpi / self.screen_dpi
|
||||||
|
|
||||||
if dpi_rate != 1 and ftype == 'png':
|
if dpi_rate != 1 and ftype == 'png':
|
||||||
scale_factor_x += dpi_rate
|
if scale_factor_x is None:
|
||||||
scale_factor_y += dpi_rate
|
scale_factor_x = 1
|
||||||
|
if scale_factor_y is None:
|
||||||
|
scale_factor_y = 1
|
||||||
|
scale_factor_x *= dpi_rate
|
||||||
|
scale_factor_y *= dpi_rate
|
||||||
|
scale_type = 1
|
||||||
|
|
||||||
transformed_box_geo = self.transform_geometry(box_obj, scale_factor_x=scale_factor_x,
|
transformed_box_geo = self.transform_geometry(box_obj, scale_factor_x=scale_factor_x,
|
||||||
scale_factor_y=scale_factor_y,
|
scale_factor_y=scale_factor_y,
|
||||||
@@ -689,10 +695,12 @@ class Film(AppTool):
|
|||||||
doc_final = self.create_negative_svg(svg_geo=exported_svg, box_bounds=bounds, r_box=rounded_box,
|
doc_final = self.create_negative_svg(svg_geo=exported_svg, box_bounds=bounds, r_box=rounded_box,
|
||||||
box_geo=transformed_box_geo, c_hull=use_convex_hull, margin=boundary,
|
box_geo=transformed_box_geo, c_hull=use_convex_hull, margin=boundary,
|
||||||
color=color, opacity=transparency_level, svg_units=svg_units)
|
color=color, opacity=transparency_level, svg_units=svg_units)
|
||||||
|
# with open("d://a.svg", 'w') as f:
|
||||||
|
# f.write(doc_final)
|
||||||
obj_bounds = obj.bounds()
|
obj_bounds = obj.bounds()
|
||||||
ret = self.write_output_file(content2save=doc_final, filename=filename, file_type=ftype, p_size=p_size,
|
ret = self.write_output_file(content2save=doc_final, filename=filename, file_type=ftype, p_size=p_size,
|
||||||
orientation=orientation, source_bounds=obj_bounds, box_bounds=bounds)
|
orientation=orientation, source_bounds=obj_bounds, box_bounds=bounds,
|
||||||
|
dpi=self.screen_dpi)
|
||||||
|
|
||||||
if ret == 'fail':
|
if ret == 'fail':
|
||||||
return 'fail'
|
return 'fail'
|
||||||
@@ -708,7 +716,8 @@ class Film(AppTool):
|
|||||||
try:
|
try:
|
||||||
make_negative_film(color=color, transparency_level=transparency_level,
|
make_negative_film(color=color, transparency_level=transparency_level,
|
||||||
scale_factor_x=scale_factor_x, scale_factor_y=scale_factor_y,
|
scale_factor_x=scale_factor_x, scale_factor_y=scale_factor_y,
|
||||||
use_convex_hull=use_convex_hull, rounded_box=rounded_box)
|
use_convex_hull=use_convex_hull, rounded_box=rounded_box,
|
||||||
|
scale_type=scale_type)
|
||||||
except Exception as e:
|
except Exception as e:
|
||||||
self.app.log.error("export_negative_handler() process -> %s" % str(e))
|
self.app.log.error("export_negative_handler() process -> %s" % str(e))
|
||||||
return
|
return
|
||||||
@@ -716,7 +725,7 @@ class Film(AppTool):
|
|||||||
self.app.worker_task.emit({'fcn': job_thread_film, 'params': []})
|
self.app.worker_task.emit({'fcn': job_thread_film, 'params': []})
|
||||||
else:
|
else:
|
||||||
make_negative_film(scale_factor_x=scale_factor_x, scale_factor_y=scale_factor_y,
|
make_negative_film(scale_factor_x=scale_factor_x, scale_factor_y=scale_factor_y,
|
||||||
use_convex_hull=use_convex_hull, rounded_box=rounded_box)
|
use_convex_hull=use_convex_hull, rounded_box=rounded_box, scale_type=scale_type)
|
||||||
|
|
||||||
def create_negative_svg(self, svg_geo, box_bounds, r_box, box_geo, c_hull, margin, color, opacity, svg_units):
|
def create_negative_svg(self, svg_geo, box_bounds, r_box, box_geo, c_hull, margin, color, opacity, svg_units):
|
||||||
# Change the attributes of the exported SVG
|
# Change the attributes of the exported SVG
|
||||||
@@ -882,7 +891,7 @@ class Film(AppTool):
|
|||||||
color = obj.obj_options['tools_film_color']
|
color = obj.obj_options['tools_film_color']
|
||||||
transparency_level = opacity_val
|
transparency_level = opacity_val
|
||||||
|
|
||||||
def make_positive_film(color, transparency_level, scale_factor_x, scale_factor_y):
|
def make_positive_film(color, transparency_level, scale_factor_x, scale_factor_y, scale_type):
|
||||||
self.app.log.debug("FilmTool.export_positive_handler().make_positive_film()")
|
self.app.log.debug("FilmTool.export_positive_handler().make_positive_film()")
|
||||||
|
|
||||||
self.screen_dpi = self.app.qapp.screens()[0].logicalDotsPerInch()
|
self.screen_dpi = self.app.qapp.screens()[0].logicalDotsPerInch()
|
||||||
@@ -891,8 +900,13 @@ class Film(AppTool):
|
|||||||
dpi_rate = new_png_dpi / self.screen_dpi
|
dpi_rate = new_png_dpi / self.screen_dpi
|
||||||
|
|
||||||
if dpi_rate != 1 and ftype == 'png':
|
if dpi_rate != 1 and ftype == 'png':
|
||||||
scale_factor_x += dpi_rate
|
if scale_factor_x is None:
|
||||||
scale_factor_y += dpi_rate
|
scale_factor_x = 1
|
||||||
|
if scale_factor_y is None:
|
||||||
|
scale_factor_y = 1
|
||||||
|
scale_factor_x *= dpi_rate
|
||||||
|
scale_factor_y *= dpi_rate
|
||||||
|
scale_type = 1
|
||||||
|
|
||||||
transformed_box_geo = self.transform_geometry(box_obj, scale_factor_x=scale_factor_x,
|
transformed_box_geo = self.transform_geometry(box_obj, scale_factor_x=scale_factor_x,
|
||||||
scale_factor_y=scale_factor_y,
|
scale_factor_y=scale_factor_y,
|
||||||
@@ -920,7 +934,8 @@ class Film(AppTool):
|
|||||||
|
|
||||||
obj_bounds = obj.bounds()
|
obj_bounds = obj.bounds()
|
||||||
ret = self.write_output_file(content2save=doc_final, filename=filename, file_type=ftype, p_size=p_size,
|
ret = self.write_output_file(content2save=doc_final, filename=filename, file_type=ftype, p_size=p_size,
|
||||||
orientation=orientation, source_bounds=obj_bounds, box_bounds=bounds)
|
orientation=orientation, source_bounds=obj_bounds, box_bounds=bounds,
|
||||||
|
dpi=self.screen_dpi)
|
||||||
|
|
||||||
if ret == 'fail':
|
if ret == 'fail':
|
||||||
return 'fail'
|
return 'fail'
|
||||||
@@ -935,7 +950,8 @@ class Film(AppTool):
|
|||||||
with self.app.proc_container.new(_("Working...")):
|
with self.app.proc_container.new(_("Working...")):
|
||||||
try:
|
try:
|
||||||
make_positive_film(color=color, transparency_level=transparency_level,
|
make_positive_film(color=color, transparency_level=transparency_level,
|
||||||
scale_factor_x=scale_factor_x, scale_factor_y=scale_factor_y)
|
scale_factor_x=scale_factor_x, scale_factor_y=scale_factor_y,
|
||||||
|
scale_type=scale_type)
|
||||||
except Exception as e:
|
except Exception as e:
|
||||||
self.app.log.error("export_positive_handler() process -> %s" % str(e))
|
self.app.log.error("export_positive_handler() process -> %s" % str(e))
|
||||||
return
|
return
|
||||||
@@ -943,7 +959,7 @@ class Film(AppTool):
|
|||||||
self.app.worker_task.emit({'fcn': job_thread_film, 'params': []})
|
self.app.worker_task.emit({'fcn': job_thread_film, 'params': []})
|
||||||
else:
|
else:
|
||||||
make_positive_film(color=color, transparency_level=transparency_level,
|
make_positive_film(color=color, transparency_level=transparency_level,
|
||||||
scale_factor_x=scale_factor_x, scale_factor_y=scale_factor_y)
|
scale_factor_x=scale_factor_x, scale_factor_y=scale_factor_y, scale_type=scale_type)
|
||||||
|
|
||||||
def create_positive_svg(self, svg_geo, box_bounds, margin, color, opacity, svg_units):
|
def create_positive_svg(self, svg_geo, box_bounds, margin, color, opacity, svg_units):
|
||||||
# Change the attributes of the exported SVG
|
# Change the attributes of the exported SVG
|
||||||
@@ -993,7 +1009,8 @@ class Film(AppTool):
|
|||||||
doc = parse_xml_string(svg_elem)
|
doc = parse_xml_string(svg_elem)
|
||||||
return doc.toprettyxml()
|
return doc.toprettyxml()
|
||||||
|
|
||||||
def write_output_file(self, content2save, filename, file_type, p_size, orientation, source_bounds, box_bounds):
|
def write_output_file(self, content2save, filename, file_type, p_size, orientation, source_bounds, box_bounds,
|
||||||
|
dpi=72):
|
||||||
p_msg = '[ERROR_NOTCL] %s' % _("Permission denied, saving not possible.\n"
|
p_msg = '[ERROR_NOTCL] %s' % _("Permission denied, saving not possible.\n"
|
||||||
"Most likely another app is holding the file open and not accessible.")
|
"Most likely another app is holding the file open and not accessible.")
|
||||||
if file_type == 'svg':
|
if file_type == 'svg':
|
||||||
@@ -1007,7 +1024,7 @@ class Film(AppTool):
|
|||||||
try:
|
try:
|
||||||
doc_final = StringIO(content2save)
|
doc_final = StringIO(content2save)
|
||||||
drawing = svg2rlg(doc_final)
|
drawing = svg2rlg(doc_final)
|
||||||
renderPM.drawToFile(drawing, filename, 'PNG')
|
renderPM.drawToFile(drawing, fn=filename, fmt='PNG', dpi=dpi)
|
||||||
except PermissionError:
|
except PermissionError:
|
||||||
self.app.inform.emit(p_msg)
|
self.app.inform.emit(p_msg)
|
||||||
return 'fail'
|
return 'fail'
|
||||||
|
|||||||
Reference in New Issue
Block a user