8f583de0e69086e8e6c411fa7906a943362f8790
Bernd Wurst Struktur verändern (broken!)

Bernd Wurst authored 16 years ago

1) # -* coding: utf8 *-
2) 
Bernd Wurst Generisch

Bernd Wurst authored 16 years ago

3) import Invoice
Bernd Wurst Struktur verändern (broken!)

Bernd Wurst authored 16 years ago

4) import re
5) 
Bernd Wurst Trennung von Firmen-spezifi...

Bernd Wurst authored 16 years ago

6) # our page size and margins
Bernd Wurst Mache die Invoice-Library f...

Bernd Wurst authored 7 years ago

7) from .metrics import *
Bernd Wurst Trennung von Firmen-spezifi...

Bernd Wurst authored 16 years ago

8) # our custom page style
Bernd Wurst Mache die Invoice-Library f...

Bernd Wurst authored 7 years ago

9) from .custom_elements import basicPage, firstPage, address_header
Bernd Wurst Trennung von Firmen-spezifi...

Bernd Wurst authored 16 years ago

10) 
Bernd Wurst Struktur verändern (broken!)

Bernd Wurst authored 16 years ago

11) # reportlab imports
12) from reportlab.lib.units import cm
13) from reportlab.pdfgen import canvas as Canvas
Bernd Wurst Verstecke Bankdaten bei Rec...

Bernd Wurst authored 7 years ago

14) from reportlab.lib.colors import Color
Bernd Wurst Struktur verändern (broken!)

Bernd Wurst authored 16 years ago

15) 
Bernd Wurst Teile Tabelle auch mittendr...

Bernd Wurst authored 11 years ago

16) num_pages = 1
17) 
18) 
Bernd Wurst Struktur verändern (broken!)

Bernd Wurst authored 16 years ago

19) def _formatPrice(price, symbol='€'):
Bernd Wurst automatische code-style-fixes

Bernd Wurst authored 5 years ago

20)     '''_formatPrice(price, symbol='€'):
21)     Gets a floating point value and returns a formatted price, suffixed by 'symbol'. '''
22)     s = ("%.2f" % price).replace('.', ',')
23)     pat = re.compile(r'([0-9])([0-9]{3}[.,])')
24)     while pat.search(s):
25)         s = pat.sub(r'\1.\2', s)
26)     return s + ' ' + symbol
27) 
Bernd Wurst Struktur verändern (broken!)

Bernd Wurst authored 16 years ago

28) 
29) def _niceCount(value):
Bernd Wurst automatische code-style-fixes

Bernd Wurst authored 5 years ago

30)     '''_niceCount(value):
31)     Returns a tuple (integer , decimals) where decimals can be None'''
32)     if type(value) == int:
33)         return ('%i' % value, None)
34)     if round(value, 2) == int(value):
35)         return ('%i' % int(value), None)
36)     s = '%.2f' % value
37)     (integer, decimals) = s.split('.', 1)
38)     if decimals[-1] == '0':
39)         decimals = decimals[:-1]
40)     return (integer, decimals)
Bernd Wurst Struktur verändern (broken!)

Bernd Wurst authored 16 years ago

41) 
42) 
43) def _splitToWidth(canvas, text, width, font, size):
Bernd Wurst automatische code-style-fixes

Bernd Wurst authored 5 years ago

44)     '''_splitToWidth(canvas, text, width, font, size)
45)     Split a string to several lines of a given width.'''
46)     lines = []
47)     paras = text.split('\n')
48)     for para in paras:
49)         words = para.split(' ')
50)         while len(words) > 0:
51)             mywords = [words[0], ]
52)             del words[0]
53)             while len(words) > 0 and canvas.stringWidth(' '.join(mywords) + ' ' + words[0], font, size) <= width:
54)                 mywords.append(words[0])
55)                 del words[0]
56)             lines.append(' '.join(mywords))
57)     return lines
Bernd Wurst Struktur verändern (broken!)

Bernd Wurst authored 16 years ago

58) 
59) 
Bernd Wurst InvoiceText als Blocksatz d...

Bernd Wurst authored 16 years ago

60) def _drawJustifiedString(x, y, text, canvas, width, font, size):
Bernd Wurst automatische code-style-fixes

Bernd Wurst authored 5 years ago

61)     text = text.strip()
62)     if canvas.stringWidth(text, font, size) > width:
63)         canvas.drawString(x, y, text)
64)         # too long line, I cannot handle this
65)         return
66)     if ' ' not in text:
67)         canvas.drawString(x, y, text)
68)         # no space in there, nothing to justify
69)         return
70) 
71)     words = ['%s' % w for w in text.split(' ')]
72)     words_width = 0.0
73)     for word in words:
74)         words_width += canvas.stringWidth(word, font, size)
75) 
76)     available_space = width - words_width
77)     available_each = available_space / float((len(words) - 1))
78) 
79)     my_x = x
80)     for idx in range(len(words)):
81)         word = words[idx]
82)         canvas.drawString(my_x, y, word)
83)         my_x += canvas.stringWidth(word, font, size) + available_each
Bernd Wurst InvoiceText als Blocksatz d...

Bernd Wurst authored 16 years ago

84)     return
85) 
Bernd Wurst Struktur verändern (broken!)

Bernd Wurst authored 16 years ago

86) 
Bernd Wurst Break long address-lines

Bernd Wurst authored 15 years ago

87) def address(canvas, lines):
Bernd Wurst automatische code-style-fixes

Bernd Wurst authored 5 years ago

88)     x = 2.0 * cm
89)     y = page_height - 5.0 * cm
90)     canvas.setFont(font, 8)
91)     canvas.drawString(x + 0.5 * cm, y + 0.1 * cm, 'schokokeks.org · Köchersberg 32 · 71540 Murrhardt')
92)     canvas.setLineWidth(1)
93)     canvas.line(x + 0.4 * cm, y, x + address_width, y)
94)     y = y - 0.2 * cm
95) 
96)     line_height = 11 + 0.1 * cm
97)     y -= line_height
98) 
99)     fontsize = 11
100)     for line in lines:
101)         if canvas.stringWidth(line, font, fontsize) > address_width:
102)             # Wenn es in zwei Zeilen passt, dann ist alles okay, ansonsten verkleinern
103)             if len(lines) > 4 or canvas.stringWidth(line, font, fontsize) > 2 * address_width:
104)                 for candidate in [10.5, 10, 9.5, 9, 8.5, 8]:
105)                     fontsize = candidate
106)                     if (len(lines) <= 4 and canvas.stringWidth(line, font, fontsize) <= 2 * address_width) or canvas.stringWidth(line, font, fontsize) <= address_width:
107)                         break
108)     for line in lines:
109)         if canvas.stringWidth(line, font, fontsize) > address_width:
110)             mylines = _splitToWidth(canvas, line, address_width, font, fontsize)
111)             for l in mylines:
112)                 canvas.setFont(font, fontsize)
113)                 canvas.drawString(x + 0.5 * cm, y, l)
114)                 y -= line_height
115)         else:
116)             canvas.setFont(font, fontsize)
117)             canvas.drawString(x + 0.5 * cm, y, line)
118)             y -= line_height
Bernd Wurst Break long address-lines

Bernd Wurst authored 15 years ago

119) 
Bernd Wurst Struktur verändern (broken!)

Bernd Wurst authored 16 years ago

120) 
Bernd Wurst Verstecke Bankdaten bei Rec...

Bernd Wurst authored 7 years ago

121) def InvoiceToPDF(iv, bankdata=True):
Bernd Wurst automatische code-style-fixes

Bernd Wurst authored 5 years ago

122)     try:
123)         from StringIO import StringIO
124)     except ImportError:
125)         from io import StringIO
126)     fd = StringIO()
127)     canvas = Canvas.Canvas(fd, pagesize=A4)
128) 
129)     if iv.tender:
130)         canvas.setTitle("Angebot von schokokeks.org")
Bernd Wurst Teile Tabelle auch mittendr...

Bernd Wurst authored 11 years ago

131)     else:
Bernd Wurst automatische code-style-fixes

Bernd Wurst authored 5 years ago

132)         canvas.setTitle("Rechnung von schokokeks.org")
133) 
134)     canvas.setFont(font, 12)
135) 
136)     # Waehrungssysmbol
137)     symbol = '€'
138)     y = topcontent
139)     font_size = default_font_size
140)     font_height = 0.35 * cm
141)     line_padding = 0.1 * cm
142)     line_height = font_height + 0.1 * cm
143) 
144)     def _partHeight(part):
145)         height = 0
146)         if type(part) == Invoice.Text:
147)             left, right = leftcontent, rightcontent
148)             if part.urgent:
149)                 left += 1.5 * cm
150)                 right -= 1.5 * cm
151)                 height += len(part.paragraphs) * 3 * line_padding
152)                 # Rechne eine Zeile mehr für den Rahmen
153)                 height += line_height
154)             if part.headline:
155)                 height += (len(_splitToWidth(canvas, part.headline, right - left, font + '-Bold', default_font_size + 1)) * line_height) + line_padding
156)             for para in part.paragraphs:
157)                 height += (len(_splitToWidth(canvas, para, right - left, font, default_font_size)) * line_height) + line_padding
158)         elif type(part) == Invoice.Table:
159)             # Eine Zeile plus 2 mal line_padding für Tabellenkopf
160)             height = line_height + 2 * line_padding
161)             # Wenn nur ein Element (plus Summen) hin passt, reicht uns das
162)             el = part.entries[0]
163)             # Die Abstände oben und unten
164)             height += 2 * line_padding
165)             # Die Breite ist konservativ
166)             height += line_height * len(_splitToWidth(canvas, el['subject'], 9.3 * cm, font, font_size))
167)             if 'desc' in el and el['desc'] != '':
168)                 height += line_height * len(_splitToWidth(canvas, el['desc'], 11 * cm, font, font_size))
169)             if part.vatType == 'net':
170)                 # Eine Zeile mehr
171)                 height += line_height + line_padding
172)             # Für die MwSt-Summen
173)             height += (line_height + line_padding) * len(part.vat)
174)             # Für den Rechnungsbetrag
175)             height += line_height + line_padding
176)         return height
177) 
178)     def _tableHead(y):
179)         canvas.setFont(font, font_size)
180)         canvas.drawString(left + (0.1 * cm), y - line_height + line_padding, 'Anz.')
181)         canvas.drawString(left + (2.6 * cm), y - line_height + line_padding, 'Beschreibung')
Bernd Wurst Struktur verändern (broken!)

Bernd Wurst authored 16 years ago

182)         if len(part.vat) == 1:
Bernd Wurst automatische code-style-fixes

Bernd Wurst authored 5 years ago

183)             canvas.drawRightString(left + (14.3 * cm), y - line_height + line_padding, 'Einzelpreis')
Bernd Wurst Struktur verändern (broken!)

Bernd Wurst authored 16 years ago

184)         else:
Bernd Wurst automatische code-style-fixes

Bernd Wurst authored 5 years ago

185)             canvas.drawRightString(left + (13.7 * cm), y - line_height + line_padding, 'Einzelpreis')
186)         canvas.drawRightString(left + (16.8 * cm), y - line_height + line_padding, 'Gesamtpreis')
187)         canvas.setLineWidth(0.01 * cm)
188)         canvas.line(left, y - line_height, right, y - line_height)
189)         y -= line_height + 0.02 * cm
190)         return y
191) 
192)     def _PageWrap(canvas):
193)         '''Seitenumbruch'''
194)         global num_pages
195)         num_pages += 1
196)         canvas.setFont(font, default_font_size - 2)
197)         canvas.drawRightString(rightcontent, bottomcontent + line_padding, 'Fortsetzung auf Seite %i' % num_pages)
198)         canvas.showPage()
199)         basicPage(canvas)
200)         y = topcontent - font_size
201)         canvas.setFillColor((0, 0, 0))
202)         canvas.setFont(font, font_size - 2)
203)         canvas.drawCentredString(leftcontent + (rightcontent - leftcontent) / 2, y, '- Seite %i -' % num_pages)
204) 
205)     address(canvas, iv.addresslines)
206) 
207)     font_size = default_font_size
208)     y = firstPage(canvas)
209)     if not bankdata:
210)         # Bankdaten überschreiben wenn Lastschrift
211)         canvas.setFillColor(Color(255, 255, 255, alpha=0.8))
212)         canvas.rect(leftcontent + ((rightcontent - leftcontent) / 3) * 2 - 2, bottomcontent - 2, (rightcontent - leftcontent) / 3, -40, fill=True, stroke=False)
213)         canvas.setFillColor(Color(0, 0, 0, alpha=1))
214)         canvas.saveState()
215)         canvas.translate(leftcontent + ((rightcontent - leftcontent) / 3) * 2 + 2, bottomcontent - 40)
216)         canvas.rotate(15)
217)         canvas.drawString(0, 0, "Bitte nicht überweisen")
218)         canvas.restoreState()
219)         # canvas.drawString(leftcontent+((rightcontent-leftcontent)/3)*2 + 2, bottomcontent - 20, "Bitte nicht überweisen")
220) 
221)     canvas.setFont(font + '-Bold', font_size + 3)
222)     min_y = y
223)     if iv.caption:
224)         canvas.drawString(leftcontent, y, iv.caption)
225)         min_y -= (font_size + 3) + 0.5 * cm
226) 
227)     if type(iv) == Invoice.Tender:
228)         canvas.setFont(font, font_size)
229)         canvas.drawString(rightcolumn, y, "Erstellungsdatum:")
230)         canvas.drawRightString(rightcontent, y, "%s" % iv.date.strftime('%d. %m. %Y'))
231)         y -= (font_size + 0.1 * cm)
232)     elif type(iv) == Invoice.Generic:
233)         canvas.setFont(font, font_size)
234)         canvas.drawString(rightcolumn, y, "Datum:")
235)         canvas.drawRightString(rightcontent, y, "%s" % iv.date.strftime('%d. %m. %Y'))
236)         y -= (font_size + 0.1 * cm)
237)     elif type(iv) == Invoice.Invoice:
238)         canvas.setFont(font + '-Bold', font_size)
239)         canvas.drawString(rightcolumn, y, "Bei Fragen bitte immer angeben:")
240)         y -= (font_size + 0.2 * cm)
241)         canvas.setFont(font, font_size)
242)         canvas.drawString(rightcolumn, y, "Rechnungsdatum:")
243)         canvas.drawRightString(rightcontent, y, "%s" % iv.date.strftime('%d. %m. %Y'))
244)         y -= (font_size + 0.1 * cm)
245)         canvas.drawString(rightcolumn, y, "Rechnungsnummer:")
246)         canvas.drawRightString(rightcontent, y, "%i" % iv.id)
247)         y -= (font_size + 0.1 * cm)
248)     if iv.customerno:
249)         canvas.drawString(rightcolumn, y, "Kundennummer:")
250)         canvas.drawRightString(rightcontent, y, "%s" % iv.customerno)
251)         y -= (font_size + 0.5 * cm)
252)     canvas.setFont(font, font_size)
253)     y = min(min_y, y)
254) 
255)     if iv.salutation:
256)         canvas.drawString(leftcontent, y, iv.salutation)
257)         y -= font_size + 0.2 * cm
258)         if type(iv) in [Invoice.Tender, Invoice.Invoice]:
259)             introText = 'hiermit stellen wir Ihnen die nachfolgend genannten Leistungen in Rechnung.'
260)             if type(iv) == Invoice.Tender:
261)                 introText = 'hiermit unterbreiten wir Ihnen folgendes Angebot.'
262)             intro = _splitToWidth(canvas, introText, rightcontent - leftcontent, font, font_size)
263)             for line in intro:
264)                 canvas.drawString(leftcontent, y, line)
265)                 y -= font_size + 0.1 * cm
266)             y -= font_size + 0.1 * cm
267) 
268)     font_size = default_font_size
269)     for part in iv.parts:
270)         if y - _partHeight(part) < (bottomcontent + (0.5 * cm)):
271)             _PageWrap(canvas)
272)             y = topcontent - font_size - line_padding * 3
273)         # Debug: Was hat die Höhenbestimmung für diesen Teil als Höhe herausgefunden?
274)         # canvas.line(leftcontent, y-_partHeight(part), rightcontent, y-_partHeight(part))
275) 
276)         if type(part) == Invoice.Table:
277) 
278)             left = leftcontent
279)             right = rightcontent
280)             top = topcontent
281)             bottom = bottomcontent
282)             temp_sum = 0.0
283)             y = _tableHead(y)
284)             odd = True
285)             for el in part.entries:
286)                 subject = []
287)                 if len(part.vat) == 1:
288)                     subject = _splitToWidth(canvas, el['subject'], 10.3 * cm, font, font_size)
289)                 else:
290)                     subject = _splitToWidth(canvas, el['subject'], 9.3 * cm, font, font_size)
291)                 desc = []
292)                 if 'desc' in el and el['desc'] != '':
293)                     desc = _splitToWidth(canvas, el['desc'], 11 * cm, font, font_size)
294)                 need_lines = len(subject) + len(desc)
295) 
296)                 # need page wrap?
297)                 if y - (need_lines + 2 * font_size) < (bottomcontent + 2 * cm):
298)                     canvas.setFont(font, font_size)
299)                     # Zwischensumme
300)                     canvas.drawRightString(left + 14.5 * cm, y - font_height, 'Zwischensumme:')
301)                     canvas.drawRightString(left + 16.8 * cm, y - font_height, _formatPrice(temp_sum))
302)                     # page wrap
303)                     _PageWrap(canvas)
304)                     y = topcontent - font_size - line_padding * 3
305)                     # header
306)                     y = _tableHead(y)
307)                     odd = True
308)                     # übertrag
309)                     canvas.setFont(font, font_size)
310)                     canvas.drawRightString(left + 14.5 * cm, y - font_height, 'Übertrag:')
311)                     canvas.drawRightString(left + 16.8 * cm, y - font_height, _formatPrice(temp_sum))
312)                     y -= font_height + line_padding
313) 
314)                 # Zwischensumme (inkl. aktueller Posten)
315)                 temp_sum += el['total']
316)                 # draw the background
317)                 if not odd:
318)                     canvas.setFillColorRGB(0.9, 0.9, 0.9)
319)                 else:
320)                     canvas.setFillColorRGB(1, 1, 1)
321)                 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)
322)                 canvas.setFillColorRGB(0, 0, 0)
323)                 y -= line_padding
324)                 (integer, decimals) = _niceCount(el['count'])
325)                 canvas.drawRightString(left + 0.8 * cm, y - font_height, integer)
326)                 suffix = ''
327)                 if decimals:
328)                     suffix = ',%s' % decimals
329)                 if el['unit']:
330)                     suffix = suffix + ' ' + el['unit']
331)                 if suffix:
332)                     canvas.drawString(left + 0.8 * cm, y - font_height, '%s' % suffix)
333) 
334)                 if len(part.vat) < 2:
335)                     canvas.drawString(left + 2.7 * cm, y - font_height, subject[0])
336)                     canvas.drawRightString(left + 14.3 * cm, y - font_height, _formatPrice(el['price']))
337)                     if el['tender']:
338)                         canvas.drawRightString(left + 16.8 * cm, y - font_height, 'eventual')
339)                     else:
340)                         canvas.drawRightString(left + 16.8 * cm, y - font_height, _formatPrice(el['total']))
341)                     subject = subject[1:]
342)                     x = 1
343)                     for line in subject:
344)                         canvas.drawString(left + 2.7 * cm, y - (x * line_height) - font_height, line)
345)                         x += 1
346)                     for line in desc[:-1]:
347)                         _drawJustifiedString(left + 2.7 * cm, y - (x * line_height) - font_height, line, canvas, 11 * cm, font, font_size)
348)                         x += 1
349)                     canvas.drawString(left + 2.7 * cm, y - (x * line_height) - font_height, desc[-1])
350)                     x += 1
351)                 else:
352)                     canvas.drawString(left + 2.7 * cm, y - font_height, subject[0])
353)                     canvas.drawRightString(left + 13.3 * cm, y - font_height, _formatPrice(el['price']))
354)                     canvas.drawString(left + 13.7 * cm, y - font_height, str(part.vat[el['vat']][1]))
355)                     if el['tender']:
356)                         canvas.drawRightString(left + 16.8 * cm, y - font_height, 'eventual')
357)                     else:
358)                         canvas.drawRightString(left + 16.8 * cm, y - font_height, _formatPrice(el['total']))
359)                     subject = subject[1:]
360)                     x = 1
361)                     for line in subject:
362)                         canvas.drawString(left + 2.7 * cm, y - (x * line_height) - font_height, line)
363)                         x += 1
364)                     for line in desc:
365)                         canvas.drawString(left + 2.7 * cm, y - (x * line_height) - font_height, line)
366)                         x += 1
367)                 odd = not odd
368)                 y -= (need_lines * line_height) + line_padding
369)             if part.summary:
370)                 y -= (0.3 * cm)
371)                 if part.vatType == 'gross':
372)                     summaries = []
373)                     if len(part.vat) == 1:
374)                         vat = list(part.vat.keys())[0]
375)                         (integer, decimals) = _niceCount((vat * 100))
376)                         vatstr = '%s' % integer
377)                         if decimals:
378)                             vatstr += ',%s' % decimals
379)                         canvas.drawRightString(left + 14.5 * cm, y - font_height, 'Nettobetrag:')
380)                         canvas.drawRightString(left + 16.8 * cm, y - font_height, _formatPrice(part.sum - (part.sum / (vat + 1)) * vat))
381)                         y -= line_height
382)                         summaries.append(('%s%% MwSt:' % vatstr, _formatPrice((part.sum / (vat + 1)) * vat)))
383)                     else:
384)                         net = 0.0
385)                         for vat, vatdata in part.vat.items():
386)                             (integer, decimals) = _niceCount((vat * 100))
387)                             vatstr = '%s' % integer
388)                             if decimals:
389)                                 vatstr += ',%s' % decimals
390)                             summaries.append(('%s: Teilbetrag %s zzgl. %s%% MwSt:' % (vatdata[1], _formatPrice(vatdata[0]), vatstr), _formatPrice((vatdata[0] / (vat + 1)) * vat)))
391)                             net += vatdata[0]
392)                         summaries.append(('Nettobetrag gesamt:', _formatPrice(net)))
393)                     summaries.sort()
394)                     for line in summaries:
395)                         canvas.drawRightString(left + 14.5 * cm, y - font_height, line[0])
396)                         canvas.drawRightString(left + 16.8 * cm, y - font_height, line[1])
397)                         y -= line_height
398)                     canvas.setFont(font + '-Bold', font_size)
399)                     if iv.tender:
400)                         canvas.drawRightString(left + 14.5 * cm, y - font_height, 'Gesamtbetrag:')
401)                     else:
402)                         canvas.drawRightString(left + 14.5 * cm, y - font_height, 'Rechnungsbetrag:')
403)                     canvas.drawRightString(left + 16.8 * cm, y - font_height, _formatPrice(part.sum))
404)                     canvas.setFont(font, font_size)
405)                     y -= line_height + line_padding
406)                 else:
407)                     canvas.drawRightString(left + 14.5 * cm, y - font_height, 'Nettobetrag:')
408)                     canvas.drawRightString(left + 16.8 * cm, y - font_height, _formatPrice(part.sum))
409)                     y -= line_height
410)                     summaries = []
411)                     if len(part.vat) == 1:
412)                         vat = list(part.vat.keys())[0]
413)                         (integer, decimals) = _niceCount((vat * 100))
414)                         vatstr = '%s' % integer
415)                         if decimals:
416)                             vatstr += ',%s' % decimals
417)                         summaries.append(('zzgl. %s%% MwSt:' % vatstr, _formatPrice(vat * part.sum)))
418)                     elif len(part.vat) > 1:
419)                         for vat, vatdata in part.vat.items():
420)                             (integer, decimals) = _niceCount((vat * 100))
421)                             vatstr = '%s' % integer
422)                             if decimals:
423)                                 vatstr += ',%s' % decimals
424)                             summaries.append(('zzgl. %s%% MwSt (%s):' % (vatstr, vatdata[1]), _formatPrice(vat * vatdata[0])))
425)                     summaries.sort()
426)                     for line in summaries:
427)                         canvas.drawRightString(left + 14.5 * cm, y - font_height, line[0])
428)                         canvas.drawRightString(left + 16.8 * cm, y - font_height, line[1])
429)                         y -= line_height
430)                     sum = part.sum
431)                     for vat, vatdata in part.vat.items():
432)                         sum += vat * vatdata[0]
433)                     canvas.setFont(font + '-Bold', font_size)
434)                     if iv.tender:
435)                         canvas.drawRightString(left + 14.5 * cm, y - font_height, 'Gesamtbetrag:')
436)                     else:
437)                         canvas.drawRightString(left + 14.5 * cm, y - font_height, 'Rechnungsbetrag:')
438)                     canvas.drawRightString(left + 16.8 * cm, y - font_height, _formatPrice(sum))
439)                     canvas.setFont(font, font_size)
440)                     y -= line_height + line_padding
441)         elif type(part) == Invoice.Text:
442)             my_font_size = font_size
443)             canvas.setFont(font, my_font_size)
444)             left, right = leftcontent, rightcontent
445)             firsttime = True
446)             headlines = []
447)             if part.urgent:
448)                 left += 1.5 * cm
449)                 right -= 1.5 * cm
450)             if part.headline:
451)                 headlines = _splitToWidth(canvas, part.headline, right - left, font, my_font_size)
452)             for para in part.paragraphs:
453)                 lines = _splitToWidth(canvas, para, right - left, font, my_font_size)
454)                 if part.urgent:
455)                     need_height = len(lines) * line_height
456)                     if len(headlines) > 0:
457)                         need_height += len(headlines) * (line_height + 1) + line_padding
458)                     canvas.setFillColorRGB(0.95, 0.95, 0.95)
459)                     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)
460)                     canvas.setFillColorRGB(0, 0, 0)
461)                     y -= line_padding * 3
462)                 if part.headline and firsttime:
463)                     firsttime = False
464)                     canvas.setFont(font + '-Bold', my_font_size + 1)
465)                     for line in headlines:
466)                         canvas.drawString(left, y - (font_height + 1), line)
467)                         y -= line_height + 1
468)                     y -= line_padding
469)                     canvas.setFont(font, my_font_size)
470)                 for line in lines[:-1]:
471)                     _drawJustifiedString(left, y - font_height, line, canvas, right - left, font, my_font_size)
472)                     y -= line_height
473)                 canvas.drawString(left, y - font_height, lines[-1])
474)                 y -= line_height
475) 
476)                 y -= line_padding * 3
477)             left, right = leftcontent, rightcontent
Bernd Wurst Struktur verändern (broken!)

Bernd Wurst authored 16 years ago

478)         else:
Bernd Wurst automatische code-style-fixes

Bernd Wurst authored 5 years ago

479)             raise NotImplementedError("Cannot handle part of type %s" % type(part))
480)         y -= (0.5 * cm)
Bernd Wurst Struktur verändern (broken!)

Bernd Wurst authored 16 years ago

481)