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

This commit is contained in:
Marius Stanciu 2019-12-17 14:47:44 +02:00
parent 82f0c40ff8
commit 4a8a980cde
2 changed files with 19 additions and 16 deletions

View File

@ -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

View File

@ -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", "<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(