From 4a8a980cde39e1c9ec18390baece54bc3d60c1af Mon Sep 17 00:00:00 2001 From: Marius Stanciu Date: Tue, 17 Dec 2019 14:47:44 +0200 Subject: [PATCH] - added ability to save the Source File as PDF - fixed page size and added line breaks --- README.md | 1 + flatcamEditors/FlatCAMTextEditor.py | 34 +++++++++++++++-------------- 2 files changed, 19 insertions(+), 16 deletions(-) diff --git a/README.md b/README.md index c9ba45f4..bbfbbd1e 100644 --- a/README.md +++ b/README.md @@ -18,6 +18,7 @@ CAD program, and create G-Code for Isolation routing. - made sure that if in Gerber UI the isolation is made with a V-Shape tool then the tool type is automatically updated on the generated Geometry Object - added ability to save the Source File as PDF (still have to adjust the page size) - fixed the generate_from_geometry_2() method to use the default values in case the parameters are None +- added ability to save the Source File as PDF - fixed page size and added line breaks 16.12.2019 diff --git a/flatcamEditors/FlatCAMTextEditor.py b/flatcamEditors/FlatCAMTextEditor.py index 02c6ec19..d850729a 100644 --- a/flatcamEditors/FlatCAMTextEditor.py +++ b/flatcamEditors/FlatCAMTextEditor.py @@ -8,6 +8,12 @@ from flatcamGUI.GUIElements import * from PyQt5 import QtPrintSupport +from reportlab.platypus import SimpleDocTemplate, Paragraph +from reportlab.lib.styles import getSampleStyleSheet +from reportlab.lib.units import inch, mm + +from io import StringIO + import gettext import FlatCAMTranslation as fcTranslate import builtins @@ -218,17 +224,13 @@ class TextEditor(QtWidgets.QWidget): try: my_gcode = self.code_editor.toPlainText() if filename.rpartition('.')[2].lower() == 'pdf': - from reportlab.platypus import SimpleDocTemplate, Paragraph - from reportlab.lib.styles import getSampleStyleSheet - from reportlab.lib.units import inch + page_size = ( + self.app.plotcanvas.pagesize_dict[self.app.defaults['global_workspaceT']][0] * mm, + self.app.plotcanvas.pagesize_dict[self.app.defaults['global_workspaceT']][1] * mm + ) - if self.app.defaults['units'].upper() == 'MM': - dims = self.app.plotcanvas.pagesize_dict[self.app.defaults['global_workspaceT']] - else: - dims = ( - self.app.plotcanvas.pagesize_dict[self.app.defaults['global_workspaceT']][0] / 25.4, - self.app.plotcanvas.pagesize_dict[self.app.defaults['global_workspaceT']][1] / 25.4 - ) + # add new line after each line + lined_gcode = my_gcode.replace("\n", "
") styles = getSampleStyleSheet() styleN = styles['Normal'] @@ -237,13 +239,13 @@ class TextEditor(QtWidgets.QWidget): doc = SimpleDocTemplate( filename, - pagesize=dims, - bottomMargin=0.4 * 72, - topMargin=0.6 * 72, - rightMargin=0.8 * 72, - leftMargin=0.8 * 72) + pagesize=page_size, + bottomMargin=0.4 * inch, + topMargin=0.6 * inch, + rightMargin=0.8 * inch, + leftMargin=0.8 * inch) - P = Paragraph(my_gcode, styleN) + P = Paragraph(lined_gcode, styleN) story.append(P) doc.build(