58 RTF_COLOR = "#000000" |
59 RTF_COLOR = "#000000" |
59 |
60 |
60 def __init__(self, editor, parent=None): |
61 def __init__(self, editor, parent=None): |
61 """ |
62 """ |
62 Constructor |
63 Constructor |
63 |
64 |
64 @param editor reference to the editor object (QScintilla.Editor.Editor) |
65 @param editor reference to the editor object (QScintilla.Editor.Editor) |
65 @param parent parent object of the exporter (QObject) |
66 @param parent parent object of the exporter (QObject) |
66 """ |
67 """ |
67 ExporterBase.__init__(self, editor, parent) |
68 ExporterBase.__init__(self, editor, parent) |
68 |
69 |
69 def __GetRTFNextControl(self, pos, style): |
70 def __GetRTFNextControl(self, pos, style): |
70 """ |
71 """ |
71 Private method to extract the next RTF control word from style. |
72 Private method to extract the next RTF control word from style. |
72 |
73 |
73 @param pos position to start search (integer) |
74 @param pos position to start search (integer) |
74 @param style style definition to search in (string) |
75 @param style style definition to search in (string) |
75 @return tuple of new start position and control word found |
76 @return tuple of new start position and control word found |
76 (integer, string) |
77 (integer, string) |
77 """ |
78 """ |
78 # \f0\fs20\cf0\highlight0\b0\i0 |
79 # \f0\fs20\cf0\highlight0\b0\i0 |
79 if pos >= len(style): |
80 if pos >= len(style): |
80 return pos, "" |
81 return pos, "" |
81 |
82 |
82 oldpos = pos |
83 oldpos = pos |
83 pos += 1 # implicit skip over leading '\' |
84 pos += 1 # implicit skip over leading '\' |
84 while pos < len(style) and style[pos] != '\\': |
85 while pos < len(style) and style[pos] != "\\": |
85 pos += 1 |
86 pos += 1 |
86 return pos, style[oldpos:pos] |
87 return pos, style[oldpos:pos] |
87 |
88 |
88 def __GetRTFStyleChange(self, last, current): |
89 def __GetRTFStyleChange(self, last, current): |
89 """ |
90 """ |
90 Private method to extract control words that are different between two |
91 Private method to extract control words that are different between two |
91 styles. |
92 styles. |
92 |
93 |
93 @param last least recently used style (string) |
94 @param last least recently used style (string) |
94 @param current current style (string) |
95 @param current current style (string) |
95 @return string containing the delta between these styles (string) |
96 @return string containing the delta between these styles (string) |
96 """ |
97 """ |
97 # \f0\fs20\cf0\highlight0\b0\i0 |
98 # \f0\fs20\cf0\highlight0\b0\i0 |
98 lastPos = 0 |
99 lastPos = 0 |
99 currentPos = 0 |
100 currentPos = 0 |
100 delta = '' |
101 delta = "" |
101 i = 0 |
102 i = 0 |
102 while i < 6: |
103 while i < 6: |
103 lastPos, lastControl = self.__GetRTFNextControl(lastPos, last) |
104 lastPos, lastControl = self.__GetRTFNextControl(lastPos, last) |
104 currentPos, currentControl = self.__GetRTFNextControl(currentPos, |
105 currentPos, currentControl = self.__GetRTFNextControl(currentPos, current) |
105 current) |
|
106 if lastControl != currentControl: |
106 if lastControl != currentControl: |
107 delta += currentControl |
107 delta += currentControl |
108 i += 1 |
108 i += 1 |
109 if delta != '': |
109 if delta != "": |
110 delta += ' ' |
110 delta += " " |
111 return delta |
111 return delta |
112 |
112 |
113 def exportSource(self): |
113 def exportSource(self): |
114 """ |
114 """ |
115 Public method performing the export. |
115 Public method performing the export. |
116 """ |
116 """ |
117 filename = self._getFileName(self.tr("RTF Files (*.rtf)")) |
117 filename = self._getFileName(self.tr("RTF Files (*.rtf)")) |
118 if not filename: |
118 if not filename: |
119 return |
119 return |
120 |
120 |
121 self.editor.recolor(0, -1) |
121 self.editor.recolor(0, -1) |
122 tabs = Preferences.getEditorExporter("RTF/UseTabs") |
122 tabs = Preferences.getEditorExporter("RTF/UseTabs") |
123 tabSize = self.editor.getEditorConfig("TabWidth") |
123 tabSize = self.editor.getEditorConfig("TabWidth") |
124 if tabSize == 0: |
124 if tabSize == 0: |
125 tabSize = 4 |
125 tabSize = 4 |
126 |
126 |
127 with EricOverrideCursor(), open(filename, "w", encoding="utf-8") as f: |
127 with EricOverrideCursor(), open(filename, "w", encoding="utf-8") as f: |
128 try: |
128 try: |
129 styles, fontsize = self.__prepareStyles(f) |
129 styles, fontsize = self.__prepareStyles(f) |
130 |
130 |
131 lastStyle = ( |
131 lastStyle = ( |
132 self.RTF_SETFONTFACE + "0" + |
132 self.RTF_SETFONTFACE |
133 self.RTF_SETFONTSIZE + "{0:d}".format(fontsize) + |
133 + "0" |
134 self.RTF_SETCOLOR + "0" + |
134 + self.RTF_SETFONTSIZE |
135 self.RTF_SETBACKGROUND + "1" + |
135 + "{0:d}".format(fontsize) |
136 self.RTF_BOLD_OFF + |
136 + self.RTF_SETCOLOR |
137 self.RTF_ITALIC_OFF |
137 + "0" |
|
138 + self.RTF_SETBACKGROUND |
|
139 + "1" |
|
140 + self.RTF_BOLD_OFF |
|
141 + self.RTF_ITALIC_OFF |
138 ) |
142 ) |
139 |
143 |
140 lengthDoc = self.editor.length() |
144 lengthDoc = self.editor.length() |
141 prevCR = False |
145 prevCR = False |
142 column = 0 |
146 column = 0 |
143 pos = 0 |
147 pos = 0 |
144 deltaStyle = "" |
148 deltaStyle = "" |
145 styleCurrent = -1 |
149 styleCurrent = -1 |
146 utf8 = self.editor.isUtf8() |
150 utf8 = self.editor.isUtf8() |
147 utf8Ch = b"" |
151 utf8Ch = b"" |
148 utf8Len = 0 |
152 utf8Len = 0 |
149 |
153 |
150 while pos < lengthDoc: |
154 while pos < lengthDoc: |
151 ch = self.editor.byteAt(pos) |
155 ch = self.editor.byteAt(pos) |
152 style = self.editor.styleAt(pos) |
156 style = self.editor.styleAt(pos) |
153 if style != styleCurrent: |
157 if style != styleCurrent: |
154 deltaStyle = self.__GetRTFStyleChange( |
158 deltaStyle = self.__GetRTFStyleChange(lastStyle, styles[style]) |
155 lastStyle, styles[style]) |
|
156 if deltaStyle: |
159 if deltaStyle: |
157 f.write(deltaStyle) |
160 f.write(deltaStyle) |
158 styleCurrent = style |
161 styleCurrent = style |
159 lastStyle = styles[style] |
162 lastStyle = styles[style] |
160 |
163 |
161 if ch == b'{': |
164 if ch == b"{": |
162 f.write('\\{') |
165 f.write("\\{") |
163 elif ch == b'}': |
166 elif ch == b"}": |
164 f.write('\\}') |
167 f.write("\\}") |
165 elif ch == b'\\': |
168 elif ch == b"\\": |
166 f.write('\\\\') |
169 f.write("\\\\") |
167 elif ch == b'\t': |
170 elif ch == b"\t": |
168 if tabs: |
171 if tabs: |
169 f.write(self.RTF_TAB) |
172 f.write(self.RTF_TAB) |
170 else: |
173 else: |
171 ts = tabSize - (column % tabSize) |
174 ts = tabSize - (column % tabSize) |
172 f.write(' ' * ts) |
175 f.write(" " * ts) |
173 column += ts - 1 |
176 column += ts - 1 |
174 elif ch == b'\n': |
177 elif ch == b"\n": |
175 if not prevCR: |
178 if not prevCR: |
176 f.write(self.RTF_EOLN) |
179 f.write(self.RTF_EOLN) |
177 column -= 1 |
180 column -= 1 |
178 elif ch == b'\r': |
181 elif ch == b"\r": |
179 f.write(self.RTF_EOLN) |
182 f.write(self.RTF_EOLN) |
180 column -= 1 |
183 column -= 1 |
181 else: |
184 else: |
182 if ord(ch) > 0x7F and utf8: |
185 if ord(ch) > 0x7F and utf8: |
183 utf8Ch += ch |
186 utf8Ch += ch |
189 elif (utf8Ch[0] & 0xC0) == 0xC0: |
192 elif (utf8Ch[0] & 0xC0) == 0xC0: |
190 utf8Len = 2 |
193 utf8Len = 2 |
191 column -= 1 |
194 column -= 1 |
192 # will be incremented again later |
195 # will be incremented again later |
193 elif len(utf8Ch) == utf8Len: |
196 elif len(utf8Ch) == utf8Len: |
194 ch = utf8Ch.decode('utf8') |
197 ch = utf8Ch.decode("utf8") |
195 if ord(ch) <= 0xff: |
198 if ord(ch) <= 0xFF: |
196 f.write("\\'{0:x}".format(ord(ch))) |
199 f.write("\\'{0:x}".format(ord(ch))) |
197 else: |
200 else: |
198 f.write("\\u{0:d}\\'{1:x}".format( |
201 f.write( |
199 ord(ch), ord(ch) & 0xFF)) |
202 "\\u{0:d}\\'{1:x}".format( |
|
203 ord(ch), ord(ch) & 0xFF |
|
204 ) |
|
205 ) |
200 utf8Ch = b"" |
206 utf8Ch = b"" |
201 utf8Len = 0 |
207 utf8Len = 0 |
202 else: |
208 else: |
203 column -= 1 |
209 column -= 1 |
204 # will be incremented again later |
210 # will be incremented again later |
205 else: |
211 else: |
206 f.write(ch.decode()) |
212 f.write(ch.decode()) |
207 |
213 |
208 column += 1 |
214 column += 1 |
209 prevCR = ch == b'\r' |
215 prevCR = ch == b"\r" |
210 pos += 1 |
216 pos += 1 |
211 |
217 |
212 f.write(self.RTF_BODYCLOSE) |
218 f.write(self.RTF_BODYCLOSE) |
213 except OSError as err: |
219 except OSError as err: |
214 EricMessageBox.critical( |
220 EricMessageBox.critical( |
215 self.editor, |
221 self.editor, |
216 self.tr("Export source"), |
222 self.tr("Export source"), |
217 self.tr( |
223 self.tr( |
218 """<p>The source could not be exported to""" |
224 """<p>The source could not be exported to""" |
219 """ <b>{0}</b>.</p><p>Reason: {1}</p>""") |
225 """ <b>{0}</b>.</p><p>Reason: {1}</p>""" |
220 .format(filename, str(err))) |
226 ).format(filename, str(err)), |
221 |
227 ) |
|
228 |
222 def __prepareStyles(self, f): |
229 def __prepareStyles(self, f): |
223 """ |
230 """ |
224 Private method to generate and store the different styles. |
231 Private method to generate and store the different styles. |
225 |
232 |
226 @param f filepointer to the open RTF |
233 @param f filepointer to the open RTF |
227 @type object |
234 @type object |
228 @return styles, fontsize |
235 @return styles, fontsize |
229 @rtype dict, int |
236 @rtype dict, int |
230 """ |
237 """ |
231 styles = {} |
238 styles = {} |
232 fonts = {} |
239 fonts = {} |
233 colors = {} |
240 colors = {} |
234 lastStyle = "" |
241 lastStyle = "" |
235 |
242 |
236 lex = self.editor.getLexer() |
243 lex = self.editor.getLexer() |
237 |
244 |
238 wysiwyg = Preferences.getEditorExporter("RTF/WYSIWYG") |
245 wysiwyg = Preferences.getEditorExporter("RTF/WYSIWYG") |
239 if wysiwyg: |
246 if wysiwyg: |
240 if lex: |
247 if lex: |
241 defaultFont = lex.font(QsciScintilla.STYLE_DEFAULT) |
248 defaultFont = lex.font(QsciScintilla.STYLE_DEFAULT) |
242 else: |
249 else: |
246 fontface = defaultFont.family() |
253 fontface = defaultFont.family() |
247 fontsize = QFontInfo(defaultFont).pointSize() << 1 |
254 fontsize = QFontInfo(defaultFont).pointSize() << 1 |
248 if fontsize == 0: |
255 if fontsize == 0: |
249 fontsize = 10 << 1 |
256 fontsize = 10 << 1 |
250 characterset = QsciScintilla.SC_CHARSET_DEFAULT |
257 characterset = QsciScintilla.SC_CHARSET_DEFAULT |
251 |
258 |
252 if lex: |
259 if lex: |
253 fgColour = lex.color(QsciScintilla.STYLE_DEFAULT) |
260 fgColour = lex.color(QsciScintilla.STYLE_DEFAULT) |
254 bgColour = lex.paper(QsciScintilla.STYLE_DEFAULT) |
261 bgColour = lex.paper(QsciScintilla.STYLE_DEFAULT) |
255 else: |
262 else: |
256 fgColour = self.editor.color() |
263 fgColour = self.editor.color() |
257 bgColour = self.editor.paper() |
264 bgColour = self.editor.paper() |
258 |
265 |
259 f.write(self.RTF_HEADEROPEN + self.RTF_FONTDEFOPEN) |
266 f.write(self.RTF_HEADEROPEN + self.RTF_FONTDEFOPEN) |
260 fonts[0] = fontface |
267 fonts[0] = fontface |
261 fontCount = 1 |
268 fontCount = 1 |
262 f.write(self.RTF_FONTDEF.format(0, characterset, fontface)) |
269 f.write(self.RTF_FONTDEF.format(0, characterset, fontface)) |
263 colors[0] = fgColour |
270 colors[0] = fgColour |
264 colors[1] = bgColour |
271 colors[1] = bgColour |
265 colorCount = 2 |
272 colorCount = 2 |
266 |
273 |
267 if lex: |
274 if lex: |
268 istyle = 0 |
275 istyle = 0 |
269 while istyle <= QsciScintilla.STYLE_MAX: |
276 while istyle <= QsciScintilla.STYLE_MAX: |
270 if ( |
277 if ( |
271 istyle < QsciScintilla.STYLE_DEFAULT or |
278 istyle < QsciScintilla.STYLE_DEFAULT |
272 istyle > QsciScintilla.STYLE_LASTPREDEFINED |
279 or istyle > QsciScintilla.STYLE_LASTPREDEFINED |
273 ): |
280 ): |
274 if lex.description(istyle): |
281 if lex.description(istyle): |
275 font = lex.font(istyle) |
282 font = lex.font(istyle) |
276 lastStyle = self.RTF_SETFONTFACE |
283 lastStyle = self.RTF_SETFONTFACE |
277 if wysiwyg: |
284 if wysiwyg: |
280 if value.lower() == font.family().lower(): |
287 if value.lower() == font.family().lower(): |
281 fontKey = key |
288 fontKey = key |
282 break |
289 break |
283 else: |
290 else: |
284 fonts[fontCount] = font.family() |
291 fonts[fontCount] = font.family() |
285 f.write(self.RTF_FONTDEF.format( |
292 f.write( |
286 fontCount, characterset, |
293 self.RTF_FONTDEF.format( |
287 font.family())) |
294 fontCount, characterset, font.family() |
|
295 ) |
|
296 ) |
288 fontKey = fontCount |
297 fontKey = fontCount |
289 fontCount += 1 |
298 fontCount += 1 |
290 |
299 |
291 lastStyle += "{0:d}".format(fontKey) |
300 lastStyle += "{0:d}".format(fontKey) |
292 else: |
301 else: |
293 lastStyle += "0" |
302 lastStyle += "0" |
294 |
303 |
295 lastStyle += self.RTF_SETFONTSIZE |
304 lastStyle += self.RTF_SETFONTSIZE |
296 if wysiwyg and QFontInfo(font).pointSize(): |
305 if wysiwyg and QFontInfo(font).pointSize(): |
297 lastStyle += ( |
306 lastStyle += "{0:d}".format( |
298 "{0:d}".format( |
307 QFontInfo(font).pointSize() << 1 |
299 QFontInfo(font).pointSize() << 1) |
|
300 ) |
308 ) |
301 else: |
309 else: |
302 lastStyle += "{0:d}".format(fontsize) |
310 lastStyle += "{0:d}".format(fontsize) |
303 |
311 |
304 sColour = lex.color(istyle) |
312 sColour = lex.color(istyle) |
305 sColourKey = None |
313 sColourKey = None |
306 for key, value in colors.items(): |
314 for key, value in colors.items(): |
307 if value == sColour: |
315 if value == sColour: |
308 sColourKey = key |
316 sColourKey = key |
309 break |
317 break |
310 else: |
318 else: |
311 colors[colorCount] = sColour |
319 colors[colorCount] = sColour |
312 sColourKey = colorCount |
320 sColourKey = colorCount |
313 colorCount += 1 |
321 colorCount += 1 |
314 lastStyle += ( |
322 lastStyle += self.RTF_SETCOLOR + "{0:d}".format(sColourKey) |
315 self.RTF_SETCOLOR + |
323 |
316 "{0:d}".format(sColourKey) |
|
317 ) |
|
318 |
|
319 sColour = lex.paper(istyle) |
324 sColour = lex.paper(istyle) |
320 sColourKey = None |
325 sColourKey = None |
321 for key, value in colors.items(): |
326 for key, value in colors.items(): |
322 if value == sColour: |
327 if value == sColour: |
323 sColourKey = key |
328 sColourKey = key |
324 break |
329 break |
325 else: |
330 else: |
326 colors[colorCount] = sColour |
331 colors[colorCount] = sColour |
327 sColourKey = colorCount |
332 sColourKey = colorCount |
328 colorCount += 1 |
333 colorCount += 1 |
329 |
334 |
330 lastStyle += ( |
335 lastStyle += self.RTF_SETBACKGROUND + "{0:d}".format(sColourKey) |
331 self.RTF_SETBACKGROUND + |
336 |
332 "{0:d}".format(sColourKey) |
|
333 ) |
|
334 |
|
335 if font.bold(): |
337 if font.bold(): |
336 lastStyle += self.RTF_BOLD_ON |
338 lastStyle += self.RTF_BOLD_ON |
337 else: |
339 else: |
338 lastStyle += self.RTF_BOLD_OFF |
340 lastStyle += self.RTF_BOLD_OFF |
339 if font.italic(): |
341 if font.italic(): |
340 lastStyle += self.RTF_ITALIC_ON |
342 lastStyle += self.RTF_ITALIC_ON |
341 else: |
343 else: |
342 lastStyle += self.RTF_ITALIC_OFF |
344 lastStyle += self.RTF_ITALIC_OFF |
343 styles[istyle] = lastStyle |
345 styles[istyle] = lastStyle |
344 |
346 |
345 # get substyles |
347 # get substyles |
346 subs_start, subs_count = self.editor.getSubStyleRange( |
348 subs_start, subs_count = self.editor.getSubStyleRange(istyle) |
347 istyle) |
|
348 for subs_idx in range(subs_count): |
349 for subs_idx in range(subs_count): |
349 font = lex.font(subs_start + subs_idx) |
350 font = lex.font(subs_start + subs_idx) |
350 lastStyle = self.RTF_SETFONTFACE |
351 lastStyle = self.RTF_SETFONTFACE |
351 if wysiwyg: |
352 if wysiwyg: |
352 fontKey = None |
353 fontKey = None |
354 if value.lower() == font.family().lower(): |
355 if value.lower() == font.family().lower(): |
355 fontKey = key |
356 fontKey = key |
356 break |
357 break |
357 else: |
358 else: |
358 fonts[fontCount] = font.family() |
359 fonts[fontCount] = font.family() |
359 f.write(self.RTF_FONTDEF.format( |
360 f.write( |
360 fontCount, characterset, |
361 self.RTF_FONTDEF.format( |
361 font.family())) |
362 fontCount, characterset, font.family() |
|
363 ) |
|
364 ) |
362 fontKey = fontCount |
365 fontKey = fontCount |
363 fontCount += 1 |
366 fontCount += 1 |
364 |
367 |
365 lastStyle += "{0:d}".format(fontKey) |
368 lastStyle += "{0:d}".format(fontKey) |
366 else: |
369 else: |
367 lastStyle += "0" |
370 lastStyle += "0" |
368 |
371 |
369 lastStyle += self.RTF_SETFONTSIZE |
372 lastStyle += self.RTF_SETFONTSIZE |
370 if wysiwyg and QFontInfo(font).pointSize(): |
373 if wysiwyg and QFontInfo(font).pointSize(): |
371 lastStyle += ( |
374 lastStyle += "{0:d}".format( |
372 "{0:d}".format( |
375 QFontInfo(font).pointSize() << 1 |
373 QFontInfo(font).pointSize() << 1) |
|
374 ) |
376 ) |
375 else: |
377 else: |
376 lastStyle += "{0:d}".format(fontsize) |
378 lastStyle += "{0:d}".format(fontsize) |
377 |
379 |
378 sColour = lex.color(subs_start + subs_idx) |
380 sColour = lex.color(subs_start + subs_idx) |
379 sColourKey = None |
381 sColourKey = None |
380 for key, value in colors.items(): |
382 for key, value in colors.items(): |
381 if value == sColour: |
383 if value == sColour: |
382 sColourKey = key |
384 sColourKey = key |
383 break |
385 break |
384 else: |
386 else: |
385 colors[colorCount] = sColour |
387 colors[colorCount] = sColour |
386 sColourKey = colorCount |
388 sColourKey = colorCount |
387 colorCount += 1 |
389 colorCount += 1 |
388 lastStyle += ( |
390 lastStyle += self.RTF_SETCOLOR + "{0:d}".format(sColourKey) |
389 self.RTF_SETCOLOR + |
391 |
390 "{0:d}".format(sColourKey) |
|
391 ) |
|
392 |
|
393 sColour = lex.paper(subs_start + subs_idx) |
392 sColour = lex.paper(subs_start + subs_idx) |
394 sColourKey = None |
393 sColourKey = None |
395 for key, value in colors.items(): |
394 for key, value in colors.items(): |
396 if value == sColour: |
395 if value == sColour: |
397 sColourKey = key |
396 sColourKey = key |
398 break |
397 break |
399 else: |
398 else: |
400 colors[colorCount] = sColour |
399 colors[colorCount] = sColour |
401 sColourKey = colorCount |
400 sColourKey = colorCount |
402 colorCount += 1 |
401 colorCount += 1 |
403 |
402 |
404 lastStyle += ( |
403 lastStyle += self.RTF_SETBACKGROUND + "{0:d}".format( |
405 self.RTF_SETBACKGROUND + |
404 sColourKey |
406 "{0:d}".format(sColourKey) |
|
407 ) |
405 ) |
408 |
406 |
409 if font.bold(): |
407 if font.bold(): |
410 lastStyle += self.RTF_BOLD_ON |
408 lastStyle += self.RTF_BOLD_ON |
411 else: |
409 else: |
412 lastStyle += self.RTF_BOLD_OFF |
410 lastStyle += self.RTF_BOLD_OFF |
413 if font.italic(): |
411 if font.italic(): |
414 lastStyle += self.RTF_ITALIC_ON |
412 lastStyle += self.RTF_ITALIC_ON |
415 else: |
413 else: |
416 lastStyle += self.RTF_ITALIC_OFF |
414 lastStyle += self.RTF_ITALIC_OFF |
417 styles[subs_idx - subs_start] = lastStyle |
415 styles[subs_idx - subs_start] = lastStyle |
418 |
416 |
419 else: |
417 else: |
420 styles[istyle] = ( |
418 styles[istyle] = ( |
421 self.RTF_SETFONTFACE + "0" + |
419 self.RTF_SETFONTFACE |
422 self.RTF_SETFONTSIZE + |
420 + "0" |
423 "{0:d}".format(fontsize) + |
421 + self.RTF_SETFONTSIZE |
424 self.RTF_SETCOLOR + "0" + |
422 + "{0:d}".format(fontsize) |
425 self.RTF_SETBACKGROUND + "1" + |
423 + self.RTF_SETCOLOR |
426 self.RTF_BOLD_OFF + |
424 + "0" |
427 self.RTF_ITALIC_OFF |
425 + self.RTF_SETBACKGROUND |
|
426 + "1" |
|
427 + self.RTF_BOLD_OFF |
|
428 + self.RTF_ITALIC_OFF |
428 ) |
429 ) |
429 |
430 |
430 istyle += 1 |
431 istyle += 1 |
431 else: |
432 else: |
432 styles[0] = ( |
433 styles[0] = ( |
433 self.RTF_SETFONTFACE + "0" + |
434 self.RTF_SETFONTFACE |
434 self.RTF_SETFONTSIZE + |
435 + "0" |
435 "{0:d}".format(fontsize) + |
436 + self.RTF_SETFONTSIZE |
436 self.RTF_SETCOLOR + "0" + |
437 + "{0:d}".format(fontsize) |
437 self.RTF_SETBACKGROUND + "1" + |
438 + self.RTF_SETCOLOR |
438 self.RTF_BOLD_OFF + |
439 + "0" |
439 self.RTF_ITALIC_OFF |
440 + self.RTF_SETBACKGROUND |
|
441 + "1" |
|
442 + self.RTF_BOLD_OFF |
|
443 + self.RTF_ITALIC_OFF |
440 ) |
444 ) |
441 |
445 |
442 f.write(self.RTF_FONTDEFCLOSE + self.RTF_COLORDEFOPEN) |
446 f.write(self.RTF_FONTDEFCLOSE + self.RTF_COLORDEFOPEN) |
443 for value in colors.values(): |
447 for value in colors.values(): |
444 f.write(self.RTF_COLORDEF.format( |
448 f.write(self.RTF_COLORDEF.format(value.red(), value.green(), value.blue())) |
445 value.red(), value.green(), value.blue())) |
|
446 f.write(self.RTF_COLORDEFCLOSE) |
449 f.write(self.RTF_COLORDEFCLOSE) |
447 f.write(self.RTF_INFOOPEN + self.RTF_COMMENT) |
450 f.write(self.RTF_INFOOPEN + self.RTF_COMMENT) |
448 f.write(time.strftime(self.RTF_CREATED)) |
451 f.write(time.strftime(self.RTF_CREATED)) |
449 f.write(self.RTF_INFOCLOSE) |
452 f.write(self.RTF_INFOCLOSE) |
450 f.write(self.RTF_HEADERCLOSE + |
453 f.write( |
451 self.RTF_BODYOPEN + self.RTF_SETFONTFACE + "0" + |
454 self.RTF_HEADERCLOSE |
452 self.RTF_SETFONTSIZE + "{0:d}".format(fontsize) + |
455 + self.RTF_BODYOPEN |
453 self.RTF_SETCOLOR + "0 ") |
456 + self.RTF_SETFONTFACE |
454 |
457 + "0" |
|
458 + self.RTF_SETFONTSIZE |
|
459 + "{0:d}".format(fontsize) |
|
460 + self.RTF_SETCOLOR |
|
461 + "0 " |
|
462 ) |
|
463 |
455 return styles, fontsize |
464 return styles, fontsize |