05d059c8aff273f6bc4f14e40892bab85bf6c6c3
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
7) from metrics import *
8) # our custom page style
Bernd Wurst Break long address-lines

Bernd Wurst authored 15 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
14) 
15) 
16) def _formatPrice(price, symbol='€'):
17)   '''_formatPrice(price, symbol='€'):
18)   Gets a floating point value and returns a formatted price, suffixed by 'symbol'. '''
19)   s = ("%.2f" % price).replace('.', ',')
20)   pat = re.compile(r'([0-9])([0-9]{3}[.,])')
21)   while pat.search(s):
22)     s = pat.sub(r'\1.\2', s)
23)   return s+' '+symbol
24) 
25) def _niceCount(value):
26)   '''_niceCount(value):
27)   Returns a tuple (integer , decimals) where decimals can be None'''
28)   if type(value) == int:
29)     return ('%i' % value, None)
30)   if round(value, 2) == int(value):
31)     return ('%i' % int(value), None)
32)   s = '%.2f' % value
33)   (integer, decimals) = s.split('.', 1)
34)   if decimals[-1] == '0':
35)     decimals = decimals[:-1]
36)   return (integer, decimals)
37) 
38) 
39) def _splitToWidth(canvas, text, width, font, size):
40)   '''_splitToWidth(canvas, text, width, font, size)
41)   Split a string to several lines of a given width.'''
42)   lines = []
43)   paras = text.split('\n')
44)   for para in paras:
45)     words = para.split(' ')
46)     while len(words) > 0:
47)       mywords = [words[0], ]
48)       del words[0]
49)       while len(words) > 0 and canvas.stringWidth(' '.join(mywords) + ' ' + words[0], font, size) <= width:
50)         mywords.append(words[0])
51)         del words[0]
52)       lines.append(' '.join(mywords))
53)   return lines
54) 
55) 
Bernd Wurst InvoiceText als Blocksatz d...

Bernd Wurst authored 16 years ago

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

Bernd Wurst authored 16 years ago

82) 
83) def _PageWrap(canvas):
84)   '''Seitenumbruch'''
85)   canvas.showPage()
Bernd Wurst Trennung von Firmen-spezifi...

Bernd Wurst authored 16 years ago

86)   basicPage(canvas)
Bernd Wurst Struktur verändern (broken!)

Bernd Wurst authored 16 years ago

87) 
88) 
Bernd Wurst Break long address-lines

Bernd Wurst authored 15 years ago

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

Bernd Wurst authored 16 years ago

119) 
120) def InvoiceToPDF(iv):
121)   from StringIO import StringIO
122)   fd = StringIO()
123)   canvas = Canvas.Canvas(fd, pagesize=A4)
Bernd Wurst Trennung von Firmen-spezifi...

Bernd Wurst authored 16 years ago

124)   
Bernd Wurst Setze PDF-Dokument-Titel

Bernd Wurst authored 14 years ago

125)   if iv.tender:
126)     canvas.setTitle("Angebot von schokokeks.org")
127)   else:
128)     canvas.setTitle("Rechnung von schokokeks.org")
Bernd Wurst Trennung von Firmen-spezifi...

Bernd Wurst authored 16 years ago

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

Bernd Wurst authored 16 years ago

130)   canvas.setFont(font, 12)
131) 
132)   num_pages = 1
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
Bernd Wurst Generisch

Bernd Wurst authored 16 years ago

144)     if type(part) == Invoice.Text:
Bernd Wurst Struktur verändern (broken!)

Bernd Wurst authored 16 years ago

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
Bernd Wurst Höhen noch genauer approxim...

Bernd Wurst authored 15 years ago

150)         # Rechne eine Zeile mehr für den Rahmen
151)         height += line_height
Bernd Wurst Struktur verändern (broken!)

Bernd Wurst authored 16 years ago

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
Bernd Wurst Generisch

Bernd Wurst authored 16 years ago

156)     elif type(part) == Invoice.Table:
Bernd Wurst Höhen noch genauer approxim...

Bernd Wurst authored 15 years ago

157)       # Eine Zeile plus 2 mal line_padding für Tabellenkopf
158)       height = line_height + 2 * line_padding
Bernd Wurst Höhe der Tabelle besser app...

Bernd Wurst authored 15 years ago

159)       for el in part.entries:
Bernd Wurst Höhen noch genauer approxim...

Bernd Wurst authored 15 years ago

160)         # Die Abstände oben und unten
161)         height += 2 * line_padding
Bernd Wurst Höhe der Tabelle besser app...

Bernd Wurst authored 15 years ago

162)         # Die Breite ist konservativ
163)         height += line_height*len(_splitToWidth(canvas, el['subject'], 9.3*cm, font, font_size))
164)         if 'desc' in el and el['desc'] != '':
165)           height += line_height * len(_splitToWidth(canvas, el['desc'], 11*cm, font, font_size))
Bernd Wurst Höhen noch genauer approxim...

Bernd Wurst authored 15 years ago

166)       if part.vatType == 'net':
167)         # Eine Zeile mehr
168)         height += line_height + line_padding
169)       # Für die MwSt-Summen
170)       height += (line_height + line_padding) * len(part.vat)
171)       # Für den Rechnungsbetrag
172)       height += line_height + line_padding
Bernd Wurst Struktur verändern (broken!)

Bernd Wurst authored 16 years ago

173)     return height
174) 
175) 
Bernd Wurst Trennung von Firmen-spezifi...

Bernd Wurst authored 16 years ago

176)    
177)   address(canvas, iv.addresslines)
Bernd Wurst Struktur verändern (broken!)

Bernd Wurst authored 16 years ago

178) 
179)   font_size = default_font_size
Bernd Wurst Trennung von Firmen-spezifi...

Bernd Wurst authored 16 years ago

180)   y = firstPage(canvas)
Bernd Wurst Struktur verändern (broken!)

Bernd Wurst authored 16 years ago

181) 
182)   canvas.setFont(font+'-Bold', font_size+3)
Bernd Wurst Generisch

Bernd Wurst authored 16 years ago

183)   min_y = y
184)   if iv.caption:
185)     canvas.drawString(leftcontent, y, iv.caption)
186)     min_y -= (font_size + 3) + 0.5*cm
Bernd Wurst Struktur verändern (broken!)

Bernd Wurst authored 16 years ago

187) 
Bernd Wurst Generisch

Bernd Wurst authored 16 years ago

188)   if type(iv) == Invoice.Tender:
Bernd Wurst Struktur verändern (broken!)

Bernd Wurst authored 16 years ago

189)     canvas.setFont(font, font_size)
190)     canvas.drawString(rightcolumn, y, "Erstellungsdatum:")
191)     canvas.drawRightString(rightcontent, y, "%s" % iv.date.strftime('%d. %m. %Y'))
192)     y -= (font_size + 0.1*cm)
Bernd Wurst Generisch

Bernd Wurst authored 16 years ago

193)   elif type(iv) == Invoice.Generic:
194)     canvas.setFont(font, font_size)
195)     canvas.drawString(rightcolumn, y, "Datum:")
196)     canvas.drawRightString(rightcontent, y, "%s" % iv.date.strftime('%d. %m. %Y'))
197)     y -= (font_size + 0.1*cm)
198)   elif type(iv) == Invoice.Invoice:
Bernd Wurst Struktur verändern (broken!)

Bernd Wurst authored 16 years ago

199)     canvas.setFont(font+'-Bold', font_size)
200)     canvas.drawString(rightcolumn, y, "Bei Fragen bitte immer angeben:")
201)     y -= (font_size + 0.2*cm)
202)     canvas.setFont(font, font_size)
203)     canvas.drawString(rightcolumn, y, "Rechnungsdatum:")
204)     canvas.drawRightString(rightcontent, y, "%s" % iv.date.strftime('%d. %m. %Y'))
205)     y -= (font_size + 0.1*cm)
206)     canvas.drawString(rightcolumn, y, "Rechnungsnummer:")
207)     canvas.drawRightString(rightcontent, y, "%i" % iv.id)
208)     y -= (font_size + 0.1*cm)
209)   if iv.customerno:
210)     canvas.drawString(rightcolumn, y, "Kundennummer:")
211)     canvas.drawRightString(rightcontent, y, "%s" % iv.customerno)
212)     y -= (font_size + 0.5*cm)
213)   canvas.setFont(font, font_size)
Bernd Wurst Generisch

Bernd Wurst authored 16 years ago

214)   y = min(min_y, y)
215) 
216)   if iv.salutation:
217)     canvas.drawString(leftcontent, y, iv.salutation)
218)     y -= font_size + 0.2*cm
219)     if type(iv) in [Invoice.Tender, Invoice.Invoice]:
220)       introText = 'hiermit stellen wir Ihnen die nachfolgend genannten Leistungen in Rechnung.'
221)       if type(iv) == Invoice.Tender:
222)         introText = 'hiermit unterbreiten wir Ihnen folgendes Angebot.'
223)       intro = _splitToWidth(canvas, introText, rightcontent - leftcontent, font, font_size)
224)       for line in intro:
225)         canvas.drawString(leftcontent, y, line)
226)         y -= font_size + 0.1*cm
227)       y -= font_size + 0.1*cm
Bernd Wurst Struktur verändern (broken!)

Bernd Wurst authored 16 years ago

228) 
229)   
230)   font_size = default_font_size
231)   for part in iv.parts:
232)     if y - _partHeight(part) < (bottomcontent + (0.5*cm)):
233)       num_pages += 1
234)       y = bottomcontent + (0.5*cm)
235)       canvas.setFont(font, default_font_size-2)
236)       canvas.drawRightString(rightcontent, bottomcontent + line_padding, 'Fortsetzung auf Seite %i' % num_pages)
237)       _PageWrap(canvas)
238)       y = topcontent - font_size
239)       canvas.setFillColor((0,0,0))
240)       canvas.setFont(font, font_size-2)
241)       canvas.drawCentredString(leftcontent + (rightcontent - leftcontent) / 2, y, '- Seite %i -' % num_pages)
242)       y -= line_padding*3
Bernd Wurst Höhen noch genauer approxim...

Bernd Wurst authored 15 years ago

243)     # Debug: Was hat die Höhenbestimmung für diesen Teil als Höhe herausgefunden?
244)     #canvas.line(leftcontent, y-_partHeight(part), rightcontent, y-_partHeight(part))
245) 
Bernd Wurst Generisch

Bernd Wurst authored 16 years ago

246)     if type(part) == Invoice.Table:
Bernd Wurst Struktur verändern (broken!)

Bernd Wurst authored 16 years ago

247)         
248)       left = leftcontent
249)       right = rightcontent
250)       top = topcontent
251)       bottom = bottomcontent
252)       canvas.setFont(font, font_size)
253)       canvas.drawString(left+(0.1*cm), y-line_height+line_padding, 'Anz.')
254)       canvas.drawString(left+(1.6*cm), y-line_height+line_padding, 'Beschreibung')
255)       if len(part.vat) == 1:
256)         canvas.drawRightString(left+(14.3*cm), y-line_height+line_padding, 'Einzelpreis')
257)       else:
258)         canvas.drawRightString(left+(13.7*cm), y-line_height+line_padding, 'Einzelpreis')
259)       canvas.drawRightString(left+(16.8*cm), y-line_height+line_padding, 'Gesamtpreis')
260)       canvas.setLineWidth(0.01*cm)
261)       canvas.line(left, y - line_height, right, y - line_height)
262)       y -= line_height + 0.02*cm
263)       odd=True
264)       for el in part.entries:
265)         subject = []
266)         if len(part.vat) == 1:
267)           subject = _splitToWidth(canvas, el['subject'], 10.3*cm, font, font_size)
268)         else:
269)           subject = _splitToWidth(canvas, el['subject'], 9.3*cm, font, font_size)
270)         desc = []
271)         if 'desc' in el and el['desc'] != '':
Bernd Wurst Blocksatz auch für Beschrei...

Bernd Wurst authored 16 years ago

272)           desc = _splitToWidth(canvas, el['desc'], 11*cm, font, font_size)
Bernd Wurst Struktur verändern (broken!)

Bernd Wurst authored 16 years ago

273) 
274)         # draw the background
275)         if not odd:
276)           canvas.setFillColorRGB(0.9, 0.9, 0.9)
277)         else:
278)           canvas.setFillColorRGB(1, 1, 1)
279)         need_lines = len(subject) + len(desc)
280)         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)
281)         canvas.setFillColorRGB(0, 0, 0)
282)         y -= line_padding
283)         (integer, decimals) = _niceCount(el['count'])
284)         canvas.drawRightString(left+0.8*cm, y-font_height, integer)
285)         if decimals:
286)           canvas.drawString(left+0.8*cm, y-font_height, ',%s' % decimals)
Bernd Wurst Innergemeinschaftliche Leis...

Bernd Wurst authored 12 years ago

287)         if len(part.vat) < 2:
Bernd Wurst Struktur verändern (broken!)

Bernd Wurst authored 16 years ago

288)           canvas.drawString(left+1.7*cm, y-font_height, subject[0])
289)           canvas.drawRightString(left+14.3*cm, y-font_height, _formatPrice(el['price']))
290)           if el['tender']:  
291)             canvas.drawRightString(left+16.8*cm, y-font_height, 'eventual')
292)           else:
293)             canvas.drawRightString(left+16.8*cm, y-font_height, _formatPrice(el['total']))
294)           subject = subject[1:]
295)           x = 1
296)           for line in subject:
297)             canvas.drawString(left+1.7*cm, y-(x * line_height)-font_height, line)
298)             x += 1
Bernd Wurst Blocksatz auch für Beschrei...

Bernd Wurst authored 16 years ago

299)           for line in desc[:-1]:
300)             _drawJustifiedString(left+1.7*cm, y-(x * line_height)-font_height, line, canvas, 11*cm, font, font_size)
Bernd Wurst Struktur verändern (broken!)

Bernd Wurst authored 16 years ago

301)             x += 1
Bernd Wurst Blocksatz auch für Beschrei...

Bernd Wurst authored 16 years ago

302)           canvas.drawString(left+1.7*cm, y-(x * line_height)-font_height, desc[-1])
303)           x += 1
Bernd Wurst Struktur verändern (broken!)

Bernd Wurst authored 16 years ago

304)         else:
305)           canvas.drawString(left+1.7*cm, y-font_height, subject[0])
306)           canvas.drawRightString(left+13.3*cm, y-font_height, _formatPrice(el['price']))
307)           canvas.drawString(left+13.7*cm, y-font_height, str(part.vat[el['vat']][1]))
308)           if el['tender']:  
309)             canvas.drawRightString(left+16.8*cm, y-font_height, 'eventual')
310)           else:
311)             canvas.drawRightString(left+16.8*cm, y-font_height, _formatPrice(el['total']))
312)           subject = subject[1:]
313)           x = 1
314)           for line in subject:
315)             canvas.drawString(left+1.7*cm, y-(x * line_height)-font_height, line)
316)             x += 1
317)           for line in desc:
318)             canvas.drawString(left+1.7*cm, y-(x * line_height)-font_height, line)
319)             x += 1
320)         odd = not odd
321)         y -= (need_lines * line_height) + line_padding
322)       if part.summary:
323)         y -= (0.3*cm)
324)         if part.vatType == 'gross':
325)           canvas.setFont(font+'-Bold', font_size)
326)           if iv.tender:
327)             canvas.drawRightString(left + 14.5*cm, y-font_height, 'Gesamtbetrag:')
328)           else:
329)             canvas.drawRightString(left + 14.5*cm, y-font_height, 'Rechnungsbetrag:')
330)           canvas.drawRightString(left + 16.8*cm, y-font_height, _formatPrice(part.sum))
331)           canvas.setFont(font, font_size)
332)           y -= line_height + line_padding
333)           summaries = []
334)           if len(part.vat) == 1:
335)             vat = part.vat.keys()[0]
Bernd Wurst Trennung von Firmen-spezifi...

Bernd Wurst authored 16 years ago

336)             (integer, decimals) = _niceCount( (vat * 100) )
337)             vatstr = '%s' % integer
338)             if decimals:
339)               vatstr += ',%s' % decimals
Bernd Wurst Struktur verändern (broken!)

Bernd Wurst authored 16 years ago

340)             if iv.tender:
Bernd Wurst Trennung von Firmen-spezifi...

Bernd Wurst authored 16 years ago

341)               summaries.append(('Im Gesamtbetrag sind %s%% MwSt enthalten:' % vatstr, _formatPrice((part.sum/(vat+1))*vat)))
Bernd Wurst Struktur verändern (broken!)

Bernd Wurst authored 16 years ago

342)             else:
Bernd Wurst Trennung von Firmen-spezifi...

Bernd Wurst authored 16 years ago

343)               summaries.append(('Im Rechnungsbetrag sind %s%% MwSt enthalten:' % vatstr, _formatPrice((part.sum/(vat+1))*vat)))
Bernd Wurst Struktur verändern (broken!)

Bernd Wurst authored 16 years ago

344)           else:
345)             for vat, vatdata in part.vat.iteritems():
Bernd Wurst Trennung von Firmen-spezifi...

Bernd Wurst authored 16 years ago

346)               (integer, decimals) = _niceCount( (vat * 100) )
347)               vatstr = '%s' % integer
348)               if decimals:
349)                 vatstr += ',%s' % decimals
350)               summaries.append(('%s: Im Teilbetrag von %s sind %s%% MwSt enthalten:' % (vatdata[1], _formatPrice(vatdata[0]), vatstr), _formatPrice((vatdata[0]/(vat+1))*vat)))
Bernd Wurst Struktur verändern (broken!)

Bernd Wurst authored 16 years ago

351)           summaries.sort()
352)           for line in summaries:
353)             canvas.drawRightString(left + 14.5*cm, y-font_height, line[0])
354)             canvas.drawRightString(left + 16.8*cm, y-font_height, line[1])
355)             y -= line_height
356)         else:
357)           canvas.drawRightString(left + 14.5*cm, y-font_height, 'Nettobetrag:')
358)           canvas.drawRightString(left + 16.8*cm, y-font_height, _formatPrice(part.sum))
359)           y -= line_height
360)           summaries = []
361)           if len(part.vat) == 1:
362)             vat = part.vat.keys()[0]
Bernd Wurst Trennung von Firmen-spezifi...

Bernd Wurst authored 16 years ago

363)             (integer, decimals) = _niceCount( (vat * 100) )
364)             vatstr = '%s' % integer
365)             if decimals:
366)               vatstr += ',%s' % decimals
367)             summaries.append(('zzgl. %s%% MwSt:' % vatstr, _formatPrice(vat*part.sum)))
Bernd Wurst Innergemeinschaftliche Leis...

Bernd Wurst authored 12 years ago

368)           elif len(part.vat) > 1:
Bernd Wurst Struktur verändern (broken!)

Bernd Wurst authored 16 years ago

369)             for vat, vatdata in part.vat.iteritems():
Bernd Wurst Trennung von Firmen-spezifi...

Bernd Wurst authored 16 years ago

370)               (integer, decimals) = _niceCount( (vat * 100) )
371)               vatstr = '%s' % integer
372)               if decimals:
373)                 vatstr += ',%s' % decimals
374)               summaries.append(('zzgl. %s%% MwSt (%s):' % (vatstr, vatdata[1]), _formatPrice(vat*vatdata[0])))
Bernd Wurst Struktur verändern (broken!)

Bernd Wurst authored 16 years ago

375)           summaries.sort()
376)           for line in summaries:
377)             canvas.drawRightString(left + 14.5*cm, y-font_height, line[0])
378)             canvas.drawRightString(left + 16.8*cm, y-font_height, line[1])
379)             y -= line_height
Bernd Wurst Innergemeinschaftliche Leis...

Bernd Wurst authored 12 years ago

380)           sum = part.sum
Bernd Wurst Struktur verändern (broken!)

Bernd Wurst authored 16 years ago

381)           for vat, vatdata in part.vat.iteritems():
Bernd Wurst Innergemeinschaftliche Leis...

Bernd Wurst authored 12 years ago

382)             sum += vat*vatdata[0]
Bernd Wurst Struktur verändern (broken!)

Bernd Wurst authored 16 years ago

383)           canvas.setFont(font+'-Bold', font_size)
384)           if iv.tender:
385)             canvas.drawRightString(left + 14.5*cm, y-font_height, 'Gesamtbetrag:')
386)           else:
387)             canvas.drawRightString(left + 14.5*cm, y-font_height, 'Rechnungsbetrag:')
388)           canvas.drawRightString(left + 16.8*cm, y-font_height, _formatPrice(sum))
389)           canvas.setFont(font, font_size)
390)           y -= line_height + line_padding
Bernd Wurst Generisch

Bernd Wurst authored 16 years ago

391)     elif type(part) == Invoice.Text:
Bernd Wurst Struktur verändern (broken!)

Bernd Wurst authored 16 years ago

392)       my_font_size = font_size
393)       canvas.setFont(font, my_font_size)
394)       left, right = leftcontent, rightcontent
395)       firsttime = True
396)       headlines = []
397)       if part.urgent:
398)         left += 1.5*cm
399)         right -= 1.5*cm
400)       if part.headline:
401)         headlines = _splitToWidth(canvas, part.headline, right-left, font, my_font_size)
402)       for para in part.paragraphs:
403)         lines = _splitToWidth(canvas, para, right-left, font, my_font_size)
404)         if part.urgent:
405)           need_height = len(lines) * line_height
406)           if len(headlines) > 0:
407)             need_height += len(headlines) * (line_height + 1) + line_padding
408)           canvas.setFillColorRGB(0.95, 0.95, 0.95)
409)           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)
410)           canvas.setFillColorRGB(0, 0, 0)
411)           y -= line_padding*3
412)         if part.headline and firsttime:
413)           firsttime = False
414)           canvas.setFont(font+'-Bold', my_font_size+1)
415)           for line in headlines:
416)             canvas.drawString(left, y-(font_height+1), line)
417)             y -= line_height + 1
418)           y -= line_padding
419)           canvas.setFont(font, my_font_size)
Bernd Wurst InvoiceText als Blocksatz d...

Bernd Wurst authored 16 years ago

420)         for line in lines[:-1]:
421)           _drawJustifiedString(left, y-font_height, line, canvas, right-left, font, my_font_size)
Bernd Wurst Struktur verändern (broken!)

Bernd Wurst authored 16 years ago

422)           y -= line_height
Bernd Wurst InvoiceText als Blocksatz d...

Bernd Wurst authored 16 years ago

423)         canvas.drawString(left, y-font_height, lines[-1])
424)         y -= line_height
425)