Просмотр исходного кода

- added ability to save the Source File as PDF - fixed page size and added line breaks

Marius Stanciu 6 лет назад
Родитель
Сommit
4a8a980cde
2 измененных файлов с 20 добавлено и 17 удалено
  1. 1 0
      README.md
  2. 19 17
      flatcamEditors/FlatCAMTextEditor.py

+ 1 - 0
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
 

+ 19 - 17
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
-
-                    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
-                        )
+                    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
+                    )
+
+                    # add new line after each line
+                    lined_gcode = my_gcode.replace("\n", "<br />")
 
                     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(