QScintilla/Exporters/ExporterPDF.py

changeset 12
1d8dd9706f46
parent 6
52e8c820d0dd
child 13
1af94a91f439
equal deleted inserted replaced
11:b0996e4a289e 12:1d8dd9706f46
13 13
14 from PyQt4.QtCore import * 14 from PyQt4.QtCore import *
15 from PyQt4.QtGui import * 15 from PyQt4.QtGui import *
16 from PyQt4.Qsci import QsciScintilla 16 from PyQt4.Qsci import QsciScintilla
17 17
18 from ExporterBase import ExporterBase 18 from .ExporterBase import ExporterBase
19 19
20 import Preferences 20 import Preferences
21 21
22 PDF_FONT_DEFAULT = 1 # Helvetica 22 PDF_FONT_DEFAULT = 1 # Helvetica
23 PDF_FONTSIZE_DEFAULT = 10 23 PDF_FONTSIZE_DEFAULT = 10
71 """ 71 """
72 Public method to write the data to the file. 72 Public method to write the data to the file.
73 73
74 @param objectData data to be written (integer or string) 74 @param objectData data to be written (integer or string)
75 """ 75 """
76 if type(objectData) == type(1): 76 if isinstance(objectData, int):
77 self.file.write("%d" % objectData) 77 self.file.write("%d" % objectData)
78 else: 78 else:
79 self.file.write(objectData) 79 self.file.write(objectData)
80 80
81 def add(self, objectData): 81 def add(self, objectData):
357 return 357 return
358 358
359 if self.firstLine: 359 if self.firstLine:
360 # avoid breakage due to locale setting 360 # avoid breakage due to locale setting
361 f = int(self.leading * 10 + 0.5) 361 f = int(self.leading * 10 + 0.5)
362 buffer = "0 -%d.%d TD\n" % (f / 10, f % 10) 362 buffer = "0 -%d.%d TD\n" % (f // 10, f % 10)
363 self.firstLine = False 363 self.firstLine = False
364 else: 364 else:
365 buffer = "T*\n" 365 buffer = "T*\n"
366 self.pageData += buffer 366 self.pageData += buffer
367 367
385 @param color color object to convert (QColor) 385 @param color color object to convert (QColor)
386 @return PDF color description (string) 386 @return PDF color description (string)
387 """ 387 """
388 pdfColor = "" 388 pdfColor = ""
389 for component in [color.red(), color.green(), color.blue()]: 389 for component in [color.red(), color.green(), color.blue()]:
390 c = (component * 1000 + 127) / 255 390 c = (component * 1000 + 127) // 255
391 if c == 0 or c == 1000: 391 if c == 0 or c == 1000:
392 pdfColor += "%d " % (c / 1000) 392 pdfColor += "%d " % (c // 1000)
393 else: 393 else:
394 pdfColor += "0.%03d " % c 394 pdfColor += "0.%03d " % c
395 return pdfColor 395 return pdfColor
396 396
397 def exportSource(self): 397 def exportSource(self):
509 self.pr.fontSize += fontSize 509 self.pr.fontSize += fontSize
510 else: 510 else:
511 self.pr.fontSize = PDF_FONTSIZE_DEFAULT 511 self.pr.fontSize = PDF_FONTSIZE_DEFAULT
512 512
513 try: 513 try:
514 f = open(filename, "wb") 514 f = open(filename, "w")
515 515
516 # initialise PDF rendering 516 # initialise PDF rendering
517 ot = PDFObjectTracker(f) 517 ot = PDFObjectTracker(f)
518 self.pr.oT = ot 518 self.pr.oT = ot
519 self.pr.startPDF() 519 self.pr.startPDF()
573 pos += 1 573 pos += 1
574 574
575 # write required stuff and close the PDF file 575 # write required stuff and close the PDF file
576 self.pr.endPDF() 576 self.pr.endPDF()
577 f.close() 577 f.close()
578 except IOError, err: 578 except IOError as err:
579 QApplication.restoreOverrideCursor() 579 QApplication.restoreOverrideCursor()
580 QMessageBox.critical(self.editor, 580 QMessageBox.critical(self.editor,
581 self.trUtf8("Export source"), 581 self.trUtf8("Export source"),
582 self.trUtf8( 582 self.trUtf8(
583 """<p>The source could not be exported to <b>{0}</b>.</p>""" 583 """<p>The source could not be exported to <b>{0}</b>.</p>"""
584 """<p>Reason: {1}</p>""")\ 584 """<p>Reason: {1}</p>""")\
585 .format(filename, unicode(err)), 585 .format(filename, str(err)),
586 QMessageBox.StandardButtons(\ 586 QMessageBox.StandardButtons(\
587 QMessageBox.Ok)) 587 QMessageBox.Ok))
588 finally: 588 finally:
589 QApplication.restoreOverrideCursor() 589 QApplication.restoreOverrideCursor()

eric ide

mercurial