src/eric7/QScintilla/Exporters/ExporterPDF.py

branch
eric7
changeset 10431
64157aeb0312
parent 9653
e67609152c5e
child 10439
21c28b0f9e41
equal deleted inserted replaced
10430:e440aaf179ce 10431:64157aeb0312
72 72
73 def __init__(self, file): 73 def __init__(self, file):
74 """ 74 """
75 Constructor 75 Constructor
76 76
77 @param file file object open for writing (file) 77 @param file file object open for writing
78 @type file
78 """ 79 """
79 self.file = file 80 self.file = file
80 self.offsetList = [] 81 self.offsetList = []
81 self.index = 1 82 self.index = 1
82 83
83 def write(self, objectData): 84 def write(self, objectData):
84 """ 85 """
85 Public method to write the data to the file. 86 Public method to write the data to the file.
86 87
87 @param objectData data to be written (integer or string) 88 @param objectData data to be written
89 @type int or str
88 """ 90 """
89 if isinstance(objectData, int): 91 if isinstance(objectData, int):
90 self.file.write("{0:d}".format(objectData)) 92 self.file.write("{0:d}".format(objectData))
91 else: 93 else:
92 self.file.write(objectData) 94 self.file.write(objectData)
93 95
94 def add(self, objectData): 96 def add(self, objectData):
95 """ 97 """
96 Public method to add a new object. 98 Public method to add a new object.
97 99
98 @param objectData data to be added (integer or string) 100 @param objectData data to be added
99 @return object number assigned to the supplied data (integer) 101 @type int or str
102 @return object number assigned to the supplied data
103 @rtype int
100 """ 104 """
101 self.offsetList.append(self.file.tell()) 105 self.offsetList.append(self.file.tell())
102 self.write(self.index) 106 self.write(self.index)
103 self.write(" 0 obj\n") 107 self.write(" 0 obj\n")
104 self.write(objectData) 108 self.write(objectData)
109 113
110 def xref(self): 114 def xref(self):
111 """ 115 """
112 Public method to build the xref table. 116 Public method to build the xref table.
113 117
114 @return file offset of the xref table (integer) 118 @return file offset of the xref table
119 @rtype int
115 """ 120 """
116 xrefStart = self.file.tell() 121 xrefStart = self.file.tell()
117 self.write("xref\n0 ") 122 self.write("xref\n0 ")
118 self.write(self.index) 123 self.write(self.index)
119 # a xref entry *must* be 20 bytes long (PDF1.4Ref(p64)) 124 # a xref entry *must* be 20 bytes long (PDF1.4Ref(p64))
164 169
165 def fontToPoints(self, thousandths): 170 def fontToPoints(self, thousandths):
166 """ 171 """
167 Public method to convert the font size to points. 172 Public method to convert the font size to points.
168 173
169 @param thousandths font size (integer) 174 @param thousandths font size
170 @return point size of the font (integer) 175 @type int
176 @return point size of the font
177 @rtype int
171 """ 178 """
172 return self.fontSize * thousandths / 1000.0 179 return self.fontSize * thousandths / 1000.0
173 180
174 def setStyle(self, style_): 181 def setStyle(self, style_):
175 """ 182 """
176 Public method to set a style. 183 Public method to set a style.
177 184
178 @param style_ style to be set (integer) 185 @param style_ style to be set
179 @return the PDF string to set the given style (string) 186 @type int
187 @return the PDF string to set the given style
188 @rtype str
180 """ 189 """
181 styleNext = style_ 190 styleNext = style_
182 if style_ == -1: 191 if style_ == -1:
183 styleNext = self.styleCurrent 192 styleNext = self.styleCurrent
184 193
290 299
291 def add(self, ch, style_): 300 def add(self, ch, style_):
292 """ 301 """
293 Public method to add a character to the page. 302 Public method to add a character to the page.
294 303
295 @param ch character to add (string) 304 @param ch character to add
296 @param style_ number of the style of the character (integer) 305 @type str
306 @param style_ number of the style of the character
307 @type int
297 """ 308 """
298 if not self.pageStarted: 309 if not self.pageStarted:
299 self.startPage() 310 self.startPage()
300 311
301 # get glyph width (TODO future non-monospace handling) 312 # get glyph width (TODO future non-monospace handling)
408 419
409 def __init__(self, editor, parent=None): 420 def __init__(self, editor, parent=None):
410 """ 421 """
411 Constructor 422 Constructor
412 423
413 @param editor reference to the editor object (QScintilla.Editor.Editor) 424 @param editor reference to the editor object
414 @param parent parent object of the exporter (QObject) 425 @type QScintilla.Editor.Editor
426 @param parent parent object of the exporter
427 @type QObject
415 """ 428 """
416 ExporterBase.__init__(self, editor, parent) 429 ExporterBase.__init__(self, editor, parent)
417 430
418 def __getPDFRGB(self, color): 431 def __getPDFRGB(self, color):
419 """ 432 """
420 Private method to convert a color object to the correct PDF color. 433 Private method to convert a color object to the correct PDF color.
421 434
422 @param color color object to convert (QColor) 435 @param color color object to convert
423 @return PDF color description (string) 436 @type QColor
437 @return PDF color description
438 @rtype str
424 """ 439 """
425 pdfColor = "" 440 pdfColor = ""
426 for component in [color.red(), color.green(), color.blue()]: 441 for component in [color.red(), color.green(), color.blue()]:
427 c = (component * 1000 + 127) // 255 442 c = (component * 1000 + 127) // 255
428 if c in (0, 1000): 443 if c in (0, 1000):

eric ide

mercurial