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):
|
Python-3-anpassungen
Bernd Wurst authored 5 years ago
|
123) from io import BytesIO
124) fd = BytesIO()
|
automatische code-style-fixes
Bernd Wurst authored 5 years ago
|
125) canvas = Canvas.Canvas(fd, pagesize=A4)
126)
127) if iv.tender:
128) canvas.setTitle("Angebot von schokokeks.org")
|
Teile Tabelle auch mittendr...
Bernd Wurst authored 11 years ago
|
129) else:
|
automatische code-style-fixes
Bernd Wurst authored 5 years ago
|
130) canvas.setTitle("Rechnung von schokokeks.org")
131)
132) canvas.setFont(font, 12)
133)
134) # Waehrungssysmbol
135) symbol = '€'
136) y = topcontent
137) font_size = default_font_size
138) font_height = 0.35 * cm
139) line_padding = 0.1 * cm
140) line_height = font_height + 0.1 * cm
141)
142) def _partHeight(part):
143) height = 0
144) if type(part) == Invoice.Text:
145) left, right = leftcontent, rightcontent
146) if part.urgent:
147) left += 1.5 * cm
148) right -= 1.5 * cm
149) height += len(part.paragraphs) * 3 * line_padding
150) # Rechne eine Zeile mehr für den Rahmen
151) height += line_height
152) if part.headline:
153) height += (len(_splitToWidth(canvas, part.headline, right - left, font + '-Bold', default_font_size + 1)) * line_height) + line_padding
154) for para in part.paragraphs:
155) height += (len(_splitToWidth(canvas, para, right - left, font, default_font_size)) * line_height) + line_padding
156) elif type(part) == Invoice.Table:
157) # Eine Zeile plus 2 mal line_padding für Tabellenkopf
158) height = line_height + 2 * line_padding
159) # Wenn nur ein Element (plus Summen) hin passt, reicht uns das
160) el = part.entries[0]
161) # Die Abstände oben und unten
162) height += 2 * line_padding
163) # Die Breite ist konservativ
164) height += line_height * len(_splitToWidth(canvas, el['subject'], 9.3 * cm, font, font_size))
165) if 'desc' in el and el['desc'] != '':
166) height += line_height * len(_splitToWidth(canvas, el['desc'], 11 * cm, font, font_size))
167) if part.vatType == 'net':
168) # Eine Zeile mehr
169) height += line_height + line_padding
170) # Für die MwSt-Summen
171) height += (line_height + line_padding) * len(part.vat)
172) # Für den Rechnungsbetrag
173) height += line_height + line_padding
174) return height
175)
176) def _tableHead(y):
177) canvas.setFont(font, font_size)
178) canvas.drawString(left + (0.1 * cm), y - line_height + line_padding, 'Anz.')
179) canvas.drawString(left + (2.6 * cm), y - line_height + line_padding, 'Beschreibung')
|
Struktur verändern (broken!)
Bernd Wurst authored 16 years ago
|
180) if len(part.vat) == 1:
|
automatische code-style-fixes
Bernd Wurst authored 5 years ago
|
181) canvas.drawRightString(left + (14.3 * cm), y - line_height + line_padding, 'Einzelpreis')
|
Struktur verändern (broken!)
Bernd Wurst authored 16 years ago
|
182) else:
|
automatische code-style-fixes
Bernd Wurst authored 5 years ago
|
183) canvas.drawRightString(left + (13.7 * cm), y - line_height + line_padding, 'Einzelpreis')
184) canvas.drawRightString(left + (16.8 * cm), y - line_height + line_padding, 'Gesamtpreis')
185) canvas.setLineWidth(0.01 * cm)
186) canvas.line(left, y - line_height, right, y - line_height)
187) y -= line_height + 0.02 * cm
188) return y
189)
190) def _PageWrap(canvas):
191) '''Seitenumbruch'''
192) global num_pages
193) num_pages += 1
194) canvas.setFont(font, default_font_size - 2)
195) canvas.drawRightString(rightcontent, bottomcontent + line_padding, 'Fortsetzung auf Seite %i' % num_pages)
196) canvas.showPage()
197) basicPage(canvas)
198) y = topcontent - font_size
199) canvas.setFillColor((0, 0, 0))
200) canvas.setFont(font, font_size - 2)
|
Python-3-Migration
Bernd Wurst authored 5 years ago
|
201) canvas.drawCentredString(leftcontent + (rightcontent - leftcontent) // 2, y, '- Seite %i -' % num_pages)
|
automatische code-style-fixes
Bernd Wurst authored 5 years ago
|
202)
203) address(canvas, iv.addresslines)
204)
205) font_size = default_font_size
206) y = firstPage(canvas)
207) if not bankdata:
208) # Bankdaten überschreiben wenn Lastschrift
209) canvas.setFillColor(Color(255, 255, 255, alpha=0.8))
|
Python-3-Migration
Bernd Wurst authored 5 years ago
|
210) 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
|
211) canvas.setFillColor(Color(0, 0, 0, alpha=1))
212) canvas.saveState()
|
Python-3-Migration
Bernd Wurst authored 5 years ago
|
213) canvas.translate(leftcontent + ((rightcontent - leftcontent) // 3) * 2 + 2, bottomcontent - 40)
|
automatische code-style-fixes
Bernd Wurst authored 5 years ago
|
214) canvas.rotate(15)
215) canvas.drawString(0, 0, "Bitte nicht überweisen")
216) canvas.restoreState()
217) # canvas.drawString(leftcontent+((rightcontent-leftcontent)/3)*2 + 2, bottomcontent - 20, "Bitte nicht überweisen")
218)
219) canvas.setFont(font + '-Bold', font_size + 3)
220) min_y = y
221) if iv.caption:
222) canvas.drawString(leftcontent, y, iv.caption)
223) min_y -= (font_size + 3) + 0.5 * cm
224)
225) if type(iv) == Invoice.Tender:
226) canvas.setFont(font, font_size)
227) canvas.drawString(rightcolumn, y, "Erstellungsdatum:")
228) canvas.drawRightString(rightcontent, y, "%s" % iv.date.strftime('%d. %m. %Y'))
229) y -= (font_size + 0.1 * cm)
230) elif type(iv) == Invoice.Generic:
231) canvas.setFont(font, font_size)
232) canvas.drawString(rightcolumn, y, "Datum:")
233) canvas.drawRightString(rightcontent, y, "%s" % iv.date.strftime('%d. %m. %Y'))
234) y -= (font_size + 0.1 * cm)
235) elif type(iv) == Invoice.Invoice:
236) canvas.setFont(font + '-Bold', font_size)
237) canvas.drawString(rightcolumn, y, "Bei Fragen bitte immer angeben:")
238) y -= (font_size + 0.2 * cm)
239) canvas.setFont(font, font_size)
240) canvas.drawString(rightcolumn, y, "Rechnungsdatum:")
241) canvas.drawRightString(rightcontent, y, "%s" % iv.date.strftime('%d. %m. %Y'))
242) y -= (font_size + 0.1 * cm)
243) canvas.drawString(rightcolumn, y, "Rechnungsnummer:")
244) canvas.drawRightString(rightcontent, y, "%i" % iv.id)
245) y -= (font_size + 0.1 * cm)
246) if iv.customerno:
247) canvas.drawString(rightcolumn, y, "Kundennummer:")
248) canvas.drawRightString(rightcontent, y, "%s" % iv.customerno)
249) y -= (font_size + 0.5 * cm)
250) canvas.setFont(font, font_size)
251) y = min(min_y, y)
252)
253) if iv.salutation:
254) canvas.drawString(leftcontent, y, iv.salutation)
255) y -= font_size + 0.2 * cm
256) if type(iv) in [Invoice.Tender, Invoice.Invoice]:
257) introText = 'hiermit stellen wir Ihnen die nachfolgend genannten Leistungen in Rechnung.'
258) if type(iv) == Invoice.Tender:
259) introText = 'hiermit unterbreiten wir Ihnen folgendes Angebot.'
260) intro = _splitToWidth(canvas, introText, rightcontent - leftcontent, font, font_size)
261) for line in intro:
262) canvas.drawString(leftcontent, y, line)
263) y -= font_size + 0.1 * cm
264) y -= font_size + 0.1 * cm
265)
266) font_size = default_font_size
267) for part in iv.parts:
268) if y - _partHeight(part) < (bottomcontent + (0.5 * cm)):
269) _PageWrap(canvas)
270) y = topcontent - font_size - line_padding * 3
271) # Debug: Was hat die Höhenbestimmung für diesen Teil als Höhe herausgefunden?
272) # canvas.line(leftcontent, y-_partHeight(part), rightcontent, y-_partHeight(part))
273)
274) if type(part) == Invoice.Table:
275)
276) left = leftcontent
277) right = rightcontent
278) top = topcontent
279) bottom = bottomcontent
280) temp_sum = 0.0
281) y = _tableHead(y)
282) odd = True
283) for el in part.entries:
284) subject = []
285) if len(part.vat) == 1:
286) subject = _splitToWidth(canvas, el['subject'], 10.3 * cm, font, font_size)
287) else:
288) subject = _splitToWidth(canvas, el['subject'], 9.3 * cm, font, font_size)
289) desc = []
290) if 'desc' in el and el['desc'] != '':
291) desc = _splitToWidth(canvas, el['desc'], 11 * cm, font, font_size)
292) need_lines = len(subject) + len(desc)
293)
294) # need page wrap?
295) if y - (need_lines + 2 * font_size) < (bottomcontent + 2 * cm):
296) canvas.setFont(font, font_size)
297) # Zwischensumme
298) canvas.drawRightString(left + 14.5 * cm, y - font_height, 'Zwischensumme:')
299) canvas.drawRightString(left + 16.8 * cm, y - font_height, _formatPrice(temp_sum))
300) # page wrap
301) _PageWrap(canvas)
302) y = topcontent - font_size - line_padding * 3
303) # header
304) y = _tableHead(y)
305) odd = True
306) # übertrag
307) canvas.setFont(font, font_size)
308) canvas.drawRightString(left + 14.5 * cm, y - font_height, 'Übertrag:')
309) canvas.drawRightString(left + 16.8 * cm, y - font_height, _formatPrice(temp_sum))
310) y -= font_height + line_padding
311)
312) # Zwischensumme (inkl. aktueller Posten)
313) temp_sum += el['total']
314) # draw the background
315) if not odd:
316) canvas.setFillColorRGB(0.9, 0.9, 0.9)
317) else:
318) canvas.setFillColorRGB(1, 1, 1)
319) 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)
320) canvas.setFillColorRGB(0, 0, 0)
321) y -= line_padding
322) (integer, decimals) = _niceCount(el['count'])
323) canvas.drawRightString(left + 0.8 * cm, y - font_height, integer)
324) suffix = ''
325) if decimals:
326) suffix = ',%s' % decimals
327) if el['unit']:
328) suffix = suffix + ' ' + el['unit']
329) if suffix:
330) canvas.drawString(left + 0.8 * cm, y - font_height, '%s' % suffix)
331)
332) if len(part.vat) < 2:
333) canvas.drawString(left + 2.7 * cm, y - font_height, subject[0])
334) canvas.drawRightString(left + 14.3 * cm, y - font_height, _formatPrice(el['price']))
335) if el['tender']:
336) canvas.drawRightString(left + 16.8 * cm, y - font_height, 'eventual')
337) else:
338) canvas.drawRightString(left + 16.8 * cm, y - font_height, _formatPrice(el['total']))
339) subject = subject[1:]
340) x = 1
341) for line in subject:
342) canvas.drawString(left + 2.7 * cm, y - (x * line_height) - font_height, line)
343) x += 1
344) for line in desc[:-1]:
345) _drawJustifiedString(left + 2.7 * cm, y - (x * line_height) - font_height, line, canvas, 11 * cm, font, font_size)
346) x += 1
347) canvas.drawString(left + 2.7 * cm, y - (x * line_height) - font_height, desc[-1])
348) x += 1
349) else:
350) canvas.drawString(left + 2.7 * cm, y - font_height, subject[0])
351) canvas.drawRightString(left + 13.3 * cm, y - font_height, _formatPrice(el['price']))
352) canvas.drawString(left + 13.7 * cm, y - font_height, str(part.vat[el['vat']][1]))
353) if el['tender']:
354) canvas.drawRightString(left + 16.8 * cm, y - font_height, 'eventual')
355) else:
356) canvas.drawRightString(left + 16.8 * cm, y - font_height, _formatPrice(el['total']))
357) subject = subject[1:]
358) x = 1
359) for line in subject:
360) canvas.drawString(left + 2.7 * cm, y - (x * line_height) - font_height, line)
361) x += 1
362) for line in desc:
363) canvas.drawString(left + 2.7 * cm, y - (x * line_height) - font_height, line)
364) x += 1
365) odd = not odd
366) y -= (need_lines * line_height) + line_padding
367) if part.summary:
368) y -= (0.3 * cm)
369) if part.vatType == 'gross':
370) summaries = []
371) if len(part.vat) == 1:
372) vat = list(part.vat.keys())[0]
373) (integer, decimals) = _niceCount((vat * 100))
374) vatstr = '%s' % integer
375) if decimals:
376) vatstr += ',%s' % decimals
377) canvas.drawRightString(left + 14.5 * cm, y - font_height, 'Nettobetrag:')
378) canvas.drawRightString(left + 16.8 * cm, y - font_height, _formatPrice(part.sum - (part.sum / (vat + 1)) * vat))
379) y -= line_height
380) summaries.append(('%s%% MwSt:' % vatstr, _formatPrice((part.sum / (vat + 1)) * vat)))
381) else:
382) net = 0.0
|
Python-3-Migration
Bernd Wurst authored 5 years ago
|
383) for vat, vatdata in list(part.vat.items()):
|
automatische code-style-fixes
Bernd Wurst authored 5 years ago
|
384) (integer, decimals) = _niceCount((vat * 100))
385) vatstr = '%s' % integer
386) if decimals:
387) vatstr += ',%s' % decimals
|
Python-3-Migration
Bernd Wurst authored 5 years ago
|
388) 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
|
389) net += vatdata[0]
390) summaries.append(('Nettobetrag gesamt:', _formatPrice(net)))
391) summaries.sort()
392) for line in summaries:
393) canvas.drawRightString(left + 14.5 * cm, y - font_height, line[0])
394) canvas.drawRightString(left + 16.8 * cm, y - font_height, line[1])
395) y -= line_height
396) canvas.setFont(font + '-Bold', font_size)
397) if iv.tender:
398) canvas.drawRightString(left + 14.5 * cm, y - font_height, 'Gesamtbetrag:')
399) else:
400) canvas.drawRightString(left + 14.5 * cm, y - font_height, 'Rechnungsbetrag:')
401) canvas.drawRightString(left + 16.8 * cm, y - font_height, _formatPrice(part.sum))
402) canvas.setFont(font, font_size)
403) y -= line_height + line_padding
404) else:
405) canvas.drawRightString(left + 14.5 * cm, y - font_height, 'Nettobetrag:')
406) canvas.drawRightString(left + 16.8 * cm, y - font_height, _formatPrice(part.sum))
407) y -= line_height
408) summaries = []
409) if len(part.vat) == 1:
410) vat = list(part.vat.keys())[0]
411) (integer, decimals) = _niceCount((vat * 100))
412) vatstr = '%s' % integer
413) if decimals:
414) vatstr += ',%s' % decimals
415) summaries.append(('zzgl. %s%% MwSt:' % vatstr, _formatPrice(vat * part.sum)))
416) elif len(part.vat) > 1:
|
Python-3-Migration
Bernd Wurst authored 5 years ago
|
417) for vat, vatdata in list(part.vat.items()):
|
automatische code-style-fixes
Bernd Wurst authored 5 years ago
|
418) (integer, decimals) = _niceCount((vat * 100))
419) vatstr = '%s' % integer
420) if decimals:
421) vatstr += ',%s' % decimals
422) summaries.append(('zzgl. %s%% MwSt (%s):' % (vatstr, vatdata[1]), _formatPrice(vat * vatdata[0])))
423) summaries.sort()
424) for line in summaries:
425) canvas.drawRightString(left + 14.5 * cm, y - font_height, line[0])
426) canvas.drawRightString(left + 16.8 * cm, y - font_height, line[1])
427) y -= line_height
428) sum = part.sum
|
Python-3-Migration
Bernd Wurst authored 5 years ago
|
429) for vat, vatdata in list(part.vat.items()):
|
automatische code-style-fixes
Bernd Wurst authored 5 years ago
|
430) sum += vat * vatdata[0]
431) canvas.setFont(font + '-Bold', font_size)
432) if iv.tender:
433) canvas.drawRightString(left + 14.5 * cm, y - font_height, 'Gesamtbetrag:')
434) else:
435) canvas.drawRightString(left + 14.5 * cm, y - font_height, 'Rechnungsbetrag:')
436) canvas.drawRightString(left + 16.8 * cm, y - font_height, _formatPrice(sum))
437) canvas.setFont(font, font_size)
438) y -= line_height + line_padding
439) elif type(part) == Invoice.Text:
440) my_font_size = font_size
441) canvas.setFont(font, my_font_size)
442) left, right = leftcontent, rightcontent
443) firsttime = True
444) headlines = []
445) if part.urgent:
446) left += 1.5 * cm
447) right -= 1.5 * cm
448) if part.headline:
449) headlines = _splitToWidth(canvas, part.headline, right - left, font, my_font_size)
450) for para in part.paragraphs:
451) lines = _splitToWidth(canvas, para, right - left, font, my_font_size)
452) if part.urgent:
453) need_height = len(lines) * line_height
454) if len(headlines) > 0:
455) need_height += len(headlines) * (line_height + 1) + line_padding
456) canvas.setFillColorRGB(0.95, 0.95, 0.95)
457) 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)
458) canvas.setFillColorRGB(0, 0, 0)
459) y -= line_padding * 3
460) if part.headline and firsttime:
461) firsttime = False
462) canvas.setFont(font + '-Bold', my_font_size + 1)
463) for line in headlines:
464) canvas.drawString(left, y - (font_height + 1), line)
465) y -= line_height + 1
466) y -= line_padding
467) canvas.setFont(font, my_font_size)
468) for line in lines[:-1]:
469) _drawJustifiedString(left, y - font_height, line, canvas, right - left, font, my_font_size)
470) y -= line_height
471) canvas.drawString(left, y - font_height, lines[-1])
472) y -= line_height
473)
474) y -= line_padding * 3
475) left, right = leftcontent, rightcontent
|
Struktur verändern (broken!)
Bernd Wurst authored 16 years ago
|
476) else:
|
automatische code-style-fixes
Bernd Wurst authored 5 years ago
|
477) raise NotImplementedError("Cannot handle part of type %s" % type(part))
478) y -= (0.5 * cm)
|
Struktur verändern (broken!)
Bernd Wurst authored 16 years ago
|
479)
|