comparison lib/redmine/export/pdf.rb @ 507:0c939c159af4 redmine-1.2

Update to Redmine 1.2.1 on 1.2-stable branch (Redmine SVN rev 6270)
author Chris Cannam
date Thu, 14 Jul 2011 10:32:19 +0100
parents cbce1fd3b1b7
children cbb26bc654de
comparison
equal deleted inserted replaced
441:cbce1fd3b1b7 507:0c939c159af4
38 pdf_encoding = l(:general_pdf_encoding).upcase 38 pdf_encoding = l(:general_pdf_encoding).upcase
39 if RUBY_VERSION < '1.9' 39 if RUBY_VERSION < '1.9'
40 @ic = Iconv.new(pdf_encoding, 'UTF-8') 40 @ic = Iconv.new(pdf_encoding, 'UTF-8')
41 end 41 end
42 super('P', 'mm', 'A4', (pdf_encoding == 'UTF-8'), pdf_encoding) 42 super('P', 'mm', 'A4', (pdf_encoding == 'UTF-8'), pdf_encoding)
43 case pdf_encoding 43 case current_language.to_s.downcase
44 when 'UTF-8' 44 when 'vi'
45 @font_for_content = 'FreeSans' 45 @font_for_content = 'DejaVuSans'
46 @font_for_footer = 'FreeSans' 46 @font_for_footer = 'DejaVuSans'
47 when 'CP949'
48 extend(PDF_Korean)
49 AddUHCFont()
50 @font_for_content = 'UHC'
51 @font_for_footer = 'UHC'
52 when 'CP932'
53 extend(PDF_Japanese)
54 AddSJISFont()
55 @font_for_content = 'SJIS'
56 @font_for_footer = 'SJIS'
57 when 'GB18030'
58 extend(PDF_Chinese)
59 AddGBFont()
60 @font_for_content = 'GB'
61 @font_for_footer = 'GB'
62 when 'BIG5'
63 extend(PDF_Chinese)
64 AddBig5Font()
65 @font_for_content = 'Big5'
66 @font_for_footer = 'Big5'
67 else 47 else
68 @font_for_content = 'Arial' 48 case pdf_encoding
69 @font_for_footer = 'Helvetica' 49 when 'UTF-8'
50 @font_for_content = 'FreeSans'
51 @font_for_footer = 'FreeSans'
52 when 'CP949'
53 extend(PDF_Korean)
54 AddUHCFont()
55 @font_for_content = 'UHC'
56 @font_for_footer = 'UHC'
57 when 'CP932', 'SJIS', 'SHIFT_JIS'
58 extend(PDF_Japanese)
59 AddSJISFont()
60 @font_for_content = 'SJIS'
61 @font_for_footer = 'SJIS'
62 when 'GB18030'
63 extend(PDF_Chinese)
64 AddGBFont()
65 @font_for_content = 'GB'
66 @font_for_footer = 'GB'
67 when 'BIG5'
68 extend(PDF_Chinese)
69 AddBig5Font()
70 @font_for_content = 'Big5'
71 @font_for_footer = 'Big5'
72 else
73 @font_for_content = 'Arial'
74 @font_for_footer = 'Helvetica'
75 end
70 end 76 end
71 SetCreator(Redmine::Info.app_name) 77 SetCreator(Redmine::Info.app_name)
72 SetFont(@font_for_content) 78 SetFont(@font_for_content)
73 end 79 end
74 80
99 105
100 def fix_text_encoding(txt) 106 def fix_text_encoding(txt)
101 RDMPdfEncoding::rdm_pdf_iconv(@ic, txt) 107 RDMPdfEncoding::rdm_pdf_iconv(@ic, txt)
102 end 108 end
103 109
104 def RDMCell(w,h=0,txt='',border=0,ln=0,align='',fill=0,link='') 110 def RDMCell(w ,h=0, txt='', border=0, ln=0, align='', fill=0, link='')
105 Cell(w,h,fix_text_encoding(txt),border,ln,align,fill,link) 111 Cell(w, h, fix_text_encoding(txt), border, ln, align, fill, link)
106 end 112 end
107 113
108 def RDMMultiCell(w,h=0,txt='',border=0,align='',fill=0) 114 def RDMMultiCell(w, h=0, txt='', border=0, align='', fill=0, ln=1)
109 MultiCell(w,h,fix_text_encoding(txt),border,align,fill) 115 MultiCell(w, h, fix_text_encoding(txt), border, align, fill, ln)
110 end 116 end
111 117
112 def Footer 118 def Footer
113 SetFont(@font_for_footer, 'I', 8) 119 SetFont(@font_for_footer, 'I', 8)
114 SetY(-15) 120 SetY(-15)
274 pdf.SetFontStyle('B',11) 280 pdf.SetFontStyle('B',11)
275 pdf.RDMMultiCell(190,5, 281 pdf.RDMMultiCell(190,5,
276 "#{issue.project} - #{issue.tracker} # #{issue.id}: #{issue.subject}") 282 "#{issue.project} - #{issue.tracker} # #{issue.id}: #{issue.subject}")
277 pdf.Ln 283 pdf.Ln
278 284
279 y0 = pdf.GetY
280
281 pdf.SetFontStyle('B',9) 285 pdf.SetFontStyle('B',9)
282 pdf.RDMCell(35,5, l(:field_status) + ":","LT") 286 pdf.RDMCell(35,5, l(:field_status) + ":","LT")
283 pdf.SetFontStyle('',9) 287 pdf.SetFontStyle('',9)
284 pdf.RDMCell(60,5, issue.status.to_s,"RT") 288 pdf.RDMCell(60,5, issue.status.to_s,"RT")
285 pdf.SetFontStyle('B',9) 289 pdf.SetFontStyle('B',9)
323 pdf.RDMCell(35,5, custom_value.custom_field.name + ":","L") 327 pdf.RDMCell(35,5, custom_value.custom_field.name + ":","L")
324 pdf.SetFontStyle('',9) 328 pdf.SetFontStyle('',9)
325 pdf.RDMMultiCell(155,5, (show_value custom_value),"R") 329 pdf.RDMMultiCell(155,5, (show_value custom_value),"R")
326 end 330 end
327 331
332 y0 = pdf.GetY
333
328 pdf.SetFontStyle('B',9) 334 pdf.SetFontStyle('B',9)
329 pdf.RDMCell(35,5, l(:field_subject) + ":","LT") 335 pdf.RDMCell(35,5, l(:field_subject) + ":","LT")
330 pdf.SetFontStyle('',9) 336 pdf.SetFontStyle('',9)
331 pdf.RDMMultiCell(155,5, issue.subject,"RT") 337 pdf.RDMMultiCell(155,5, issue.subject,"RT")
332
333 pdf.SetFontStyle('B',9)
334 pdf.RDMCell(35,5, l(:field_description) + ":","LT")
335 pdf.SetFontStyle('',9)
336 pdf.RDMMultiCell(155,5, issue.description.to_s,"RT")
337
338 pdf.Line(pdf.GetX, y0, pdf.GetX, pdf.GetY) 338 pdf.Line(pdf.GetX, y0, pdf.GetX, pdf.GetY)
339 pdf.Line(pdf.GetX, pdf.GetY, pdf.GetX + 190, pdf.GetY) 339
340 pdf.SetFontStyle('B',9)
341 pdf.RDMCell(35+155, 5, l(:field_description), "LRT", 1)
342 pdf.SetFontStyle('',9)
343 pdf.RDMMultiCell(35+155, 5, issue.description.to_s, "LRB")
340 pdf.Ln 344 pdf.Ln
341 345
342 if issue.changesets.any? && 346 if issue.changesets.any? &&
343 User.current.allowed_to?(:view_changesets, issue.project) 347 User.current.allowed_to?(:view_changesets, issue.project)
344 pdf.SetFontStyle('B',9) 348 pdf.SetFontStyle('B',9)
345 pdf.RDMCell(190,5, l(:label_associated_revisions), "B") 349 pdf.RDMCell(190,5, l(:label_associated_revisions), "B")
346 pdf.Ln 350 pdf.Ln
347 for changeset in issue.changesets 351 for changeset in issue.changesets
348 pdf.SetFontStyle('B',8) 352 pdf.SetFontStyle('B',8)
349 pdf.RDMCell(190,5, 353 csstr = "#{l(:label_revision)} #{changeset.format_identifier} - "
350 format_time(changeset.committed_on) + " - " + changeset.author.to_s) 354 csstr += format_time(changeset.committed_on) + " - " + changeset.author.to_s
355 pdf.RDMCell(190, 5, csstr)
351 pdf.Ln 356 pdf.Ln
352 unless changeset.comments.blank? 357 unless changeset.comments.blank?
353 pdf.SetFontStyle('',8) 358 pdf.SetFontStyle('',8)
354 pdf.RDMMultiCell(190,5, changeset.comments.to_s) 359 pdf.RDMMultiCell(190,5, changeset.comments.to_s)
355 end 360 end
406 :undef => :replace, :replace => '?') 411 :undef => :replace, :replace => '?')
407 else 412 else
408 txt = Redmine::CodesetUtil.replace_invalid_utf8(txt) 413 txt = Redmine::CodesetUtil.replace_invalid_utf8(txt)
409 end 414 end
410 txt.force_encoding('ASCII-8BIT') 415 txt.force_encoding('ASCII-8BIT')
416 elsif RUBY_PLATFORM == 'java'
417 begin
418 ic ||= Iconv.new(l(:general_pdf_encoding), 'UTF-8')
419 txt = ic.iconv(txt)
420 rescue
421 txt = txt.gsub(%r{[^\r\n\t\x20-\x7e]}, '?')
422 end
411 else 423 else
412 ic ||= Iconv.new(l(:general_pdf_encoding), 'UTF-8') 424 ic ||= Iconv.new(l(:general_pdf_encoding), 'UTF-8')
413 txtar = "" 425 txtar = ""
414 begin 426 begin
415 txtar += ic.iconv(txt) 427 txtar += ic.iconv(txt)