Struktur verändern (broken!)
Bernd Wurst authored 16 years ago
|
1) # -* coding: utf8 *-
2)
|
Python-3-Migration
Bernd Wurst authored 5 years ago
|
3) from __future__ import division
|
Generisch
Bernd Wurst authored 16 years ago
|
4) import Invoice
|
Struktur verändern (broken!)
Bernd Wurst authored 16 years ago
|
5) import re
6)
|
Trennung von Firmen-spezifi...
Bernd Wurst authored 16 years ago
|
7) # our page size and margins
|
Mache die Invoice-Library f...
Bernd Wurst authored 7 years ago
|
8) from .metrics import *
|
Trennung von Firmen-spezifi...
Bernd Wurst authored 16 years ago
|
9) # our custom page style
|
Mache die Invoice-Library f...
Bernd Wurst authored 7 years ago
|
10) from .custom_elements import basicPage, firstPage, address_header
|
Trennung von Firmen-spezifi...
Bernd Wurst authored 16 years ago
|
11)
|
Struktur verändern (broken!)
Bernd Wurst authored 16 years ago
|
12) # reportlab imports
13) from reportlab.lib.units import cm
14) from reportlab.pdfgen import canvas as Canvas
|
Verstecke Bankdaten bei Rec...
Bernd Wurst authored 7 years ago
|
15) from reportlab.lib.colors import Color
|
Struktur verändern (broken!)
Bernd Wurst authored 16 years ago
|
16)
|
Teile Tabelle auch mittendr...
Bernd Wurst authored 11 years ago
|
17) num_pages = 1
18)
19)
|
Struktur verändern (broken!)
Bernd Wurst authored 16 years ago
|
20) def _formatPrice(price, symbol='€'):
|
automatische code-style-fixes
Bernd Wurst authored 5 years ago
|
21) '''_formatPrice(price, symbol='€'):
22) Gets a floating point value and returns a formatted price, suffixed by 'symbol'. '''
23) s = ("%.2f" % price).replace('.', ',')
24) pat = re.compile(r'([0-9])([0-9]{3}[.,])')
25) while pat.search(s):
26) s = pat.sub(r'\1.\2', s)
27) return s + ' ' + symbol
28)
|
Struktur verändern (broken!)
Bernd Wurst authored 16 years ago
|
29)
30) def _niceCount(value):
|
automatische code-style-fixes
Bernd Wurst authored 5 years ago
|
31) '''_niceCount(value):
32) Returns a tuple (integer , decimals) where decimals can be None'''
33) if type(value) == int:
34) return ('%i' % value, None)
35) if round(value, 2) == int(value):
36) return ('%i' % int(value), None)
37) s = '%.2f' % value
38) (integer, decimals) = s.split('.', 1)
39) if decimals[-1] == '0':
40) decimals = decimals[:-1]
41) return (integer, decimals)
|
Struktur verändern (broken!)
Bernd Wurst authored 16 years ago
|
42)
43)
44) def _splitToWidth(canvas, text, width, font, size):
|
automatische code-style-fixes
Bernd Wurst authored 5 years ago
|
45) '''_splitToWidth(canvas, text, width, font, size)
46) Split a string to several lines of a given width.'''
47) lines = []
48) paras = text.split('\n')
49) for para in paras:
50) words = para.split(' ')
51) while len(words) > 0:
52) mywords = [words[0], ]
53) del words[0]
54) while len(words) > 0 and canvas.stringWidth(' '.join(mywords) + ' ' + words[0], font, size) <= width:
55) mywords.append(words[0])
56) del words[0]
57) lines.append(' '.join(mywords))
58) return lines
|
Struktur verändern (broken!)
Bernd Wurst authored 16 years ago
|
59)
60)
|
InvoiceText als Blocksatz d...
Bernd Wurst authored 16 years ago
|
61) def _drawJustifiedString(x, y, text, canvas, width, font, size):
|
automatische code-style-fixes
Bernd Wurst authored 5 years ago
|
62) text = text.strip()
63) if canvas.stringWidth(text, font, size) > width:
64) canvas.drawString(x, y, text)
65) # too long line, I cannot handle this
66) return
67) if ' ' not in text:
68) canvas.drawString(x, y, text)
69) # no space in there, nothing to justify
70) return
71)
72) words = ['%s' % w for w in text.split(' ')]
73) words_width = 0.0
74) for word in words:
75) words_width += canvas.stringWidth(word, font, size)
76)
77) available_space = width - words_width
|
Python-3-Migration
Bernd Wurst authored 5 years ago
|
78) available_each = available_space // float((len(words) - 1))
|
automatische code-style-fixes
Bernd Wurst authored 5 years ago
|
79)
80) my_x = x
81) for idx in range(len(words)):
82) word = words[idx]
83) canvas.drawString(my_x, y, word)
84) my_x += canvas.stringWidth(word, font, size) + available_each
|
InvoiceText als Blocksatz d...
Bernd Wurst authored 16 years ago
|
85) return
86)
|
Struktur verändern (broken!)
Bernd Wurst authored 16 years ago
|
87)
|
Break long address-lines
Bernd Wurst authored 15 years ago
|
88) def address(canvas, lines):
|
automatische code-style-fixes
Bernd Wurst authored 5 years ago
|
89) x = 2.0 * cm
90) y = page_height - 5.0 * cm
91) canvas.setFont(font, 8)
92) canvas.drawString(x + 0.5 * cm, y + 0.1 * cm, 'schokokeks.org · Köchersberg 32 · 71540 Murrhardt')
93) canvas.setLineWidth(1)
94) canvas.line(x + 0.4 * cm, y, x + address_width, y)
95) y = y - 0.2 * cm
96)
97) line_height = 11 + 0.1 * cm
98) y -= line_height
99)
100) fontsize = 11
101) for line in lines:
102) if canvas.stringWidth(line, font, fontsize) > address_width:
103) # Wenn es in zwei Zeilen passt, dann ist alles okay, ansonsten verkleinern
104) if len(lines) > 4 or canvas.stringWidth(line, font, fontsize) > 2 * address_width:
105) for candidate in [10.5, 10, 9.5, 9, 8.5, 8]:
106) fontsize = candidate
107) if (len(lines) <= 4 and canvas.stringWidth(line, font, fontsize) <= 2 * address_width) or canvas.stringWidth(line, font, fontsize) <= address_width:
108) break
109) for line in lines:
110) if canvas.stringWidth(line, font, fontsize) > address_width:
111) mylines = _splitToWidth(canvas, line, address_width, font, fontsize)
112) for l in mylines:
113) canvas.setFont(font, fontsize)
114) canvas.drawString(x + 0.5 * cm, y, l)
115) y -= line_height
116) else:
117) canvas.setFont(font, fontsize)
118) canvas.drawString(x + 0.5 * cm, y, line)
119) y -= line_height
|
Break long address-lines
Bernd Wurst authored 15 years ago
|
120)
|
Struktur verändern (broken!)
Bernd Wurst authored 16 years ago
|
121)
|
Verstecke Bankdaten bei Rec...
Bernd Wurst authored 7 years ago
|
122) def InvoiceToPDF(iv, bankdata=True):
|
automatische code-style-fixes
Bernd Wurst authored 5 years ago
|
123) try:
|
Python-3-Migration
Bernd Wurst authored 5 years ago
|
124) from io import StringIO
|
automatische code-style-fixes
Bernd Wurst authored 5 years ago
|
125) except ImportError:
126) from io import StringIO
127) fd = StringIO()
128) canvas = Canvas.Canvas(fd, pagesize=A4)
129)
130) if iv.tender:
131) canvas.setTitle("Angebot von schokokeks.org")
|
Teile Tabelle auch mittendr...
Bernd Wurst authored 11 years ago
|
132) else:
|
automatische code-style-fixes
Bernd Wurst authored 5 years ago
|
133) canvas.setTitle("Rechnung von schokokeks.org")
134)
135) canvas.setFont(font, 12)
136)
137) # Waehrungssysmbol
138) symbol = '€'
139) y = topcontent
140) font_size = default_font_size
141) font_height = 0.35 * cm
142) line_padding = 0.1 * cm
143) line_height = font_height + 0.1 * cm
144)
145) def _partHeight(part):
146) height = 0
147) if type(part) == Invoice.Text:
148) left, right = leftcontent, rightcontent
149) if part.urgent:
150) left += 1.5 * cm
151) right -= 1.5 * cm
152) height += len(part.paragraphs) * 3 * line_padding
153) # Rechne eine Zeile mehr für den Rahmen
154) height += line_height
155) if part.headline:
156) height += (len(_splitToWidth(canvas, part.headline, right - left, font + '-Bold', default_font_size + 1)) * line_height) + line_padding
157) for para in part.paragraphs:
158) height += (len(_splitToWidth(canvas, para, right - left, font, default_font_size)) * line_height) + line_padding
159) elif type(part) == Invoice.Table:
160) # Eine Zeile plus 2 mal line_padding für Tabellenkopf
161) height = line_height + 2 * line_padding
162) # Wenn nur ein Element (plus Summen) hin passt, reicht uns das
163) el = part.entries[0]
164) # Die Abstände oben und unten
165) height += 2 * line_padding
166) # Die Breite ist konservativ
167) height += line_height * len(_splitToWidth(canvas, el['subject'], 9.3 * cm, font, font_size))
168) if 'desc' in el and el['desc'] != '':
169) height += line_height * len(_splitToWidth(canvas, el['desc'], 11 * cm, font, font_size))
170) if part.vatType == 'net':
171) # Eine Zeile mehr
172) height += line_height + line_padding
173) # Für die MwSt-Summen
174) height += (line_height + line_padding) * len(part.vat)
175) # Für den Rechnungsbetrag
176) height += line_height + line_padding
177) return height
178)
179) def _tableHead(y):
180) canvas.setFont(font, font_size)
181) canvas.drawString(left + (0.1 * cm), y - line_height + line_padding, 'Anz.')
182) canvas.drawString(left + (2.6 * cm), y - line_height + line_padding, 'Beschreibung')
|
Struktur verändern (broken!)
Bernd Wurst authored 16 years ago
|
183) if len(part.vat) == 1:
|
automatische code-style-fixes
Bernd Wurst authored 5 years ago
|
184) canvas.drawRightString(left + (14.3 * cm), y - line_height + line_padding, 'Einzelpreis')
|
Struktur verändern (broken!)
Bernd Wurst authored 16 years ago
|
185) else:
|
automatische code-style-fixes
Bernd Wurst authored 5 years ago
|
186) canvas.drawRightString(left + (13.7 * cm), y - line_height + line_padding, 'Einzelpreis')
187) canvas.drawRightString(left + (16.8 * cm), y - line_height + line_padding, 'Gesamtpreis')
188) canvas.setLineWidth(0.01 * cm)
189) canvas.line(left, y - line_height, right, y - line_height)
190) y -= line_height + 0.02 * cm
191) return y
192)
193) def _PageWrap(canvas):
194) '''Seitenumbruch'''
195) global num_pages
196) num_pages += 1
197) canvas.setFont(font, default_font_size - 2)
198) canvas.drawRightString(rightcontent, bottomcontent + line_padding, 'Fortsetzung auf Seite %i' % num_pages)
199) canvas.showPage()
200) basicPage(canvas)
201) y = topcontent - font_size
202) canvas.setFillColor((0, 0, 0))
203) canvas.setFont(font, font_size - 2)
|
Python-3-Migration
Bernd Wurst authored 5 years ago
|
204) canvas.drawCentredString(leftcontent + (rightcontent - leftcontent) // 2, y, '- Seite %i -' % num_pages)
|
automatische code-style-fixes
Bernd Wurst authored 5 years ago
|
205)
206) address(canvas, iv.addresslines)
207)
208) font_size = default_font_size
209) y = firstPage(canvas)
210) if not bankdata:
211) # Bankdaten überschreiben wenn Lastschrift
212) canvas.setFillColor(Color(255, 255, 255, alpha=0.8))
|
Python-3-Migration
Bernd Wurst authored 5 years ago
|
213) canvas.rect(leftcontent + ((rightcontent - leftcontent) // 3) * 2 - 2, bottomcontent - 2, (rightcontent - leftcontent) // 3, -40, fill=True, stroke=False)
|
automatische code-style-fixes
Bernd Wurst authored 5 years ago
|
214) canvas.setFillColor(Color(0, 0, 0, alpha=1))
215) canvas.saveState()
|
Python-3-Migration
Bernd Wurst authored 5 years ago
|
216) canvas.translate(leftcontent + ((rightcontent - leftcontent) // 3) * 2 + 2, bottomcontent - 40)
|
automatische code-style-fixes
Bernd Wurst authored 5 years ago
|
217) canvas.rotate(15)
218) canvas.drawString(0, 0, "Bitte nicht überweisen")
219) canvas.restoreState()
220) # canvas.drawString(leftcontent+((rightcontent-leftcontent)/3)*2 + 2, bottomcontent - 20, "Bitte nicht überweisen")
221)
222) canvas.setFont(font + '-Bold', font_size + 3)
223) min_y = y
224) if iv.caption:
225) canvas.drawString(leftcontent, y, iv.caption)
226) min_y -= (font_size + 3) + 0.5 * cm
227)
228) if type(iv) == Invoice.Tender:
229) canvas.setFont(font, font_size)
230) canvas.drawString(rightcolumn, y, "Erstellungsdatum:")
231) canvas.drawRightString(rightcontent, y, "%s" % iv.date.strftime('%d. %m. %Y'))
232) y -= (font_size + 0.1 * cm)
233) elif type(iv) == Invoice.Generic:
234) canvas.setFont(font, font_size)
235) canvas.drawString(rightcolumn, y, "Datum:")
236) canvas.drawRightString(rightcontent, y, "%s" % iv.date.strftime('%d. %m. %Y'))
237) y -= (font_size + 0.1 * cm)
238) elif type(iv) == Invoice.Invoice:
239) canvas.setFont(font + '-Bold', font_size)
240) canvas.drawString(rightcolumn, y, "Bei Fragen bitte immer angeben:")
241) y -= (font_size + 0.2 * cm)
242) canvas.setFont(font, font_size)
243) canvas.drawString(rightcolumn, y, "Rechnungsdatum:")
244) canvas.drawRightString(rightcontent, y, "%s" % iv.date.strftime('%d. %m. %Y'))
245) y -= (font_size + 0.1 * cm)
246) canvas.drawString(rightcolumn, y, "Rechnungsnummer:")
247) canvas.drawRightString(rightcontent, y, "%i" % iv.id)
248) y -= (font_size + 0.1 * cm)
249) if iv.customerno:
250) canvas.drawString(rightcolumn, y, "Kundennummer:")
251) canvas.drawRightString(rightcontent, y, "%s" % iv.customerno)
252) y -= (font_size + 0.5 * cm)
253) canvas.setFont(font, font_size)
254) y = min(min_y, y)
255)
256) if iv.salutation:
257) canvas.drawString(leftcontent, y, iv.salutation)
258) y -= font_size + 0.2 * cm
259) if type(iv) in [Invoice.Tender, Invoice.Invoice]:
260) introText = 'hiermit stellen wir Ihnen die nachfolgend genannten Leistungen in Rechnung.'
261) if type(iv) == Invoice.Tender:
262) introText = 'hiermit unterbreiten wir Ihnen folgendes Angebot.'
263) intro = _splitToWidth(canvas, introText, rightcontent - leftcontent, font, font_size)
264) for line in intro:
265) canvas.drawString(leftcontent, y, line)
266) y -= font_size + 0.1 * cm
267) y -= font_size + 0.1 * cm
268)
269) font_size = default_font_size
270) for part in iv.parts:
271) if y - _partHeight(part) < (bottomcontent + (0.5 * cm)):
272) _PageWrap(canvas)
273) y = topcontent - font_size - line_padding * 3
274) # Debug: Was hat die Höhenbestimmung für diesen Teil als Höhe herausgefunden?
275) # canvas.line(leftcontent, y-_partHeight(part), rightcontent, y-_partHeight(part))
276)
277) if type(part) == Invoice.Table:
278)
279) left = leftcontent
280) right = rightcontent
281) top = topcontent
282) bottom = bottomcontent
283) temp_sum = 0.0
284) y = _tableHead(y)
285) odd = True
286) for el in part.entries:
287) subject = []
288) if len(part.vat) == 1:
289) subject = _splitToWidth(canvas, el['subject'], 10.3 * cm, font, font_size)
290) else:
291) subject = _splitToWidth(canvas, el['subject'], 9.3 * cm, font, font_size)
292) desc = []
293) if 'desc' in el and el['desc'] != '':
294) desc = _splitToWidth(canvas, el['desc'], 11 * cm, font, font_size)
295) need_lines = len(subject) + len(desc)
296)
297) # need page wrap?
298) if y - (need_lines + 2 * font_size) < (bottomcontent + 2 * cm):
299) canvas.setFont(font, font_size)
300) # Zwischensumme
301) canvas.drawRightString(left + 14.5 * cm, y - font_height, 'Zwischensumme:')
302) canvas.drawRightString(left + 16.8 * cm, y - font_height, _formatPrice(temp_sum))
303) # page wrap
304) _PageWrap(canvas)
305) y = topcontent - font_size - line_padding * 3
306) # header
307) y = _tableHead(y)
308) odd = True
309) # übertrag
310) canvas.setFont(font, font_size)
311) canvas.drawRightString(left + 14.5 * cm, y - font_height, 'Übertrag:')
312) canvas.drawRightString(left + 16.8 * cm, y - font_height, _formatPrice(temp_sum))
313) y -= font_height + line_padding
314)
315) # Zwischensumme (inkl. aktueller Posten)
316) temp_sum += el['total']
317) # draw the background
318) if not odd:
319) canvas.setFillColorRGB(0.9, 0.9, 0.9)
320) else:
321) canvas.setFillColorRGB(1, 1, 1)
322) canvas.rect(left, y - (need_lines * line_height) - (2 * line_padding), height=(need_lines * line_height) + (2 * line_padding), width=right - left, fill=1, stroke=0)
323) canvas.setFillColorRGB(0, 0, 0)
324) y -= line_padding
325) (integer, decimals) = _niceCount(el['count'])
326) canvas.drawRightString(left + 0.8 * cm, y - font_height, integer)
327) suffix = ''
328) if decimals:
329) suffix = ',%s' % decimals
330) if el['unit']:
331) suffix = suffix + ' ' + el['unit']
332) if suffix:
333) canvas.drawString(left + 0.8 * cm, y - font_height, '%s' % suffix)
334)
335) if len(part.vat) < 2:
336) canvas.drawString(left + 2.7 * cm, y - font_height, subject[0])
337) canvas.drawRightString(left + 14.3 * cm, y - font_height, _formatPrice(el['price']))
338) if el['tender']:
339) canvas.drawRightString(left + 16.8 * cm, y - font_height, 'eventual')
340) else:
341) canvas.drawRightString(left + 16.8 * cm, y - font_height, _formatPrice(el['total']))
342) subject = subject[1:]
343) x = 1
344) for line in subject:
345) canvas.drawString(left + 2.7 * cm, y - (x * line_height) - font_height, line)
346) x += 1
347) for line in desc[:-1]:
348) _drawJustifiedString(left + 2.7 * cm, y - (x * line_height) - font_height, line, canvas, 11 * cm, font, font_size)
349) x += 1
350) canvas.drawString(left + 2.7 * cm, y - (x * line_height) - font_height, desc[-1])
351) x += 1
352) else:
353) canvas.drawString(left + 2.7 * cm, y - font_height, subject[0])
354) canvas.drawRightString(left + 13.3 * cm, y - font_height, _formatPrice(el['price']))
355) canvas.drawString(left + 13.7 * cm, y - font_height, str(part.vat[el['vat']][1]))
356) if el['tender']:
357) canvas.drawRightString(left + 16.8 * cm, y - font_height, 'eventual')
358) else:
359) canvas.drawRightString(left + 16.8 * cm, y - font_height, _formatPrice(el['total']))
360) subject = subject[1:]
361) x = 1
362) for line in subject:
363) canvas.drawString(left + 2.7 * cm, y - (x * line_height) - font_height, line)
364) x += 1
365) for line in desc:
366) canvas.drawString(left + 2.7 * cm, y - (x * line_height) - font_height, line)
367) x += 1
368) odd = not odd
369) y -= (need_lines * line_height) + line_padding
370) if part.summary:
371) y -= (0.3 * cm)
372) if part.vatType == 'gross':
373) summaries = []
374) if len(part.vat) == 1:
375) vat = list(part.vat.keys())[0]
376) (integer, decimals) = _niceCount((vat * 100))
377) vatstr = '%s' % integer
378) if decimals:
379) vatstr += ',%s' % decimals
380) canvas.drawRightString(left + 14.5 * cm, y - font_height, 'Nettobetrag:')
381) canvas.drawRightString(left + 16.8 * cm, y - font_height, _formatPrice(part.sum - (part.sum / (vat + 1)) * vat))
382) y -= line_height
383) summaries.append(('%s%% MwSt:' % vatstr, _formatPrice((part.sum / (vat + 1)) * vat)))
384) else:
385) net = 0.0
|
Python-3-Migration
Bernd Wurst authored 5 years ago
|
386) for vat, vatdata in list(part.vat.items()):
|
automatische code-style-fixes
Bernd Wurst authored 5 years ago
|
387) (integer, decimals) = _niceCount((vat * 100))
388) vatstr = '%s' % integer
389) if decimals:
390) vatstr += ',%s' % decimals
|
Python-3-Migration
Bernd Wurst authored 5 years ago
|
391) summaries.append(('%s: Teilbetrag %s zzgl. %s%% MwSt:' % (vatdata[1], _formatPrice(vatdata[0]), vatstr), _formatPrice((vatdata[0] // (vat + 1)) * vat)))
|
automatische code-style-fixes
Bernd Wurst authored 5 years ago
|
392) net += vatdata[0]
393) summaries.append(('Nettobetrag gesamt:', _formatPrice(net)))
394) summaries.sort()
395) for line in summaries:
396) canvas.drawRightString(left + 14.5 * cm, y - font_height, line[0])
397) canvas.drawRightString(left + 16.8 * cm, y - font_height, line[1])
398) y -= line_height
399) canvas.setFont(font + '-Bold', font_size)
400) if iv.tender:
401) canvas.drawRightString(left + 14.5 * cm, y - font_height, 'Gesamtbetrag:')
402) else:
403) canvas.drawRightString(left + 14.5 * cm, y - font_height, 'Rechnungsbetrag:')
404) canvas.drawRightString(left + 16.8 * cm, y - font_height, _formatPrice(part.sum))
405) canvas.setFont(font, font_size)
406) y -= line_height + line_padding
407) else:
408) canvas.drawRightString(left + 14.5 * cm, y - font_height, 'Nettobetrag:')
409) canvas.drawRightString(left + 16.8 * cm, y - font_height, _formatPrice(part.sum))
410) y -= line_height
411) summaries = []
412) if len(part.vat) == 1:
413) vat = list(part.vat.keys())[0]
414) (integer, decimals) = _niceCount((vat * 100))
415) vatstr = '%s' % integer
416) if decimals:
417) vatstr += ',%s' % decimals
418) summaries.append(('zzgl. %s%% MwSt:' % vatstr, _formatPrice(vat * part.sum)))
419) elif len(part.vat) > 1:
|
Python-3-Migration
Bernd Wurst authored 5 years ago
|
420) for vat, vatdata in list(part.vat.items()):
|
automatische code-style-fixes
Bernd Wurst authored 5 years ago
|
421) (integer, decimals) = _niceCount((vat * 100))
422) vatstr = '%s' % integer
423) if decimals:
424) vatstr += ',%s' % decimals
425) summaries.append(('zzgl. %s%% MwSt (%s):' % (vatstr, vatdata[1]), _formatPrice(vat * vatdata[0])))
426) summaries.sort()
427) for line in summaries:
428) canvas.drawRightString(left + 14.5 * cm, y - font_height, line[0])
429) canvas.drawRightString(left + 16.8 * cm, y - font_height, line[1])
430) y -= line_height
431) sum = part.sum
|
Python-3-Migration
Bernd Wurst authored 5 years ago
|
432) for vat, vatdata in list(part.vat.items()):
|
automatische code-style-fixes
Bernd Wurst authored 5 years ago
|
433) sum += vat * vatdata[0]
434) canvas.setFont(font + '-Bold', font_size)
435) if iv.tender:
436) canvas.drawRightString(left + 14.5 * cm, y - font_height, 'Gesamtbetrag:')
437) else:
438) canvas.drawRightString(left + 14.5 * cm, y - font_height, 'Rechnungsbetrag:')
439) canvas.drawRightString(left + 16.8 * cm, y - font_height, _formatPrice(sum))
440) canvas.setFont(font, font_size)
441) y -= line_height + line_padding
442) elif type(part) == Invoice.Text:
443) my_font_size = font_size
444) canvas.setFont(font, my_font_size)
445) left, right = leftcontent, rightcontent
446) firsttime = True
447) headlines = []
448) if part.urgent:
449) left += 1.5 * cm
450) right -= 1.5 * cm
451) if part.headline:
452) headlines = _splitToWidth(canvas, part.headline, right - left, font, my_font_size)
453) for para in part.paragraphs:
454) lines = _splitToWidth(canvas, para, right - left, font, my_font_size)
455) if part.urgent:
456) need_height = len(lines) * line_height
457) if len(headlines) > 0:
458) need_height += len(headlines) * (line_height + 1) + line_padding
459) canvas.setFillColorRGB(0.95, 0.95, 0.95)
460) canvas.rect(left - 0.5 * cm, y - (need_height + (6 * line_padding)), height=need_height + (6 * line_padding), width=right - left + 1 * cm, fill=1, stroke=1)
461) canvas.setFillColorRGB(0, 0, 0)
462) y -= line_padding * 3
463) if part.headline and firsttime:
464) firsttime = False
465) canvas.setFont(font + '-Bold', my_font_size + 1)
466) for line in headlines:
467) canvas.drawString(left, y - (font_height + 1), line)
468) y -= line_height + 1
469) y -= line_padding
470) canvas.setFont(font, my_font_size)
471) for line in lines[:-1]:
472) _drawJustifiedString(left, y - font_height, line, canvas, right - left, font, my_font_size)
473) y -= line_height
474) canvas.drawString(left, y - font_height, lines[-1])
475) y -= line_height
476)
477) y -= line_padding * 3
478) left, right = leftcontent, rightcontent
|
Struktur verändern (broken!)
Bernd Wurst authored 16 years ago
|
479) else:
|
automatische code-style-fixes
Bernd Wurst authored 5 years ago
|
480) raise NotImplementedError("Cannot handle part of type %s" % type(part))
481) y -= (0.5 * cm)
|
Struktur verändern (broken!)
Bernd Wurst authored 16 years ago
|
482)
|