##// END OF EJS Templates
PDF: add missing rfpdf requires (#61)....
Toshi MARUYAMA -
r5128:ad5dcaf179ea
parent child
Show More
@@ -1,317 +1,319
1 1 # encoding: utf-8
2 2 #
3 3 # Redmine - project management software
4 4 # Copyright (C) 2006-2009 Jean-Philippe Lang
5 5 #
6 6 # This program is free software; you can redistribute it and/or
7 7 # modify it under the terms of the GNU General Public License
8 8 # as published by the Free Software Foundation; either version 2
9 9 # of the License, or (at your option) any later version.
10 10 #
11 11 # This program is distributed in the hope that it will be useful,
12 12 # but WITHOUT ANY WARRANTY; without even the implied warranty of
13 13 # MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
14 14 # GNU General Public License for more details.
15 15 #
16 16 # You should have received a copy of the GNU General Public License
17 17 # along with this program; if not, write to the Free Software
18 18 # Foundation, Inc., 51 Franklin Street, Fifth Floor, Boston, MA 02110-1301, USA.
19 19
20 20 require 'iconv'
21 21 require 'rfpdf/fpdf'
22 require 'rfpdf/chinese'
22 require 'fpdf/chinese'
23 require 'fpdf/japanese'
24 require 'fpdf/korean'
23 25
24 26 module Redmine
25 27 module Export
26 28 module PDF
27 29 include ActionView::Helpers::TextHelper
28 30 include ActionView::Helpers::NumberHelper
29 31
30 32 class IFPDF < FPDF
31 33 include Redmine::I18n
32 34 attr_accessor :footer_date
33 35
34 36 def initialize(lang)
35 37 super()
36 38 set_language_if_valid lang
37 39 case current_language.to_s.downcase
38 40 when 'ko'
39 41 extend(PDF_Korean)
40 42 AddUHCFont()
41 43 @font_for_content = 'UHC'
42 44 @font_for_footer = 'UHC'
43 45 when 'ja'
44 46 extend(PDF_Japanese)
45 47 AddSJISFont()
46 48 @font_for_content = 'SJIS'
47 49 @font_for_footer = 'SJIS'
48 50 when 'zh'
49 51 extend(PDF_Chinese)
50 52 AddGBFont()
51 53 @font_for_content = 'GB'
52 54 @font_for_footer = 'GB'
53 55 when 'zh-tw'
54 56 extend(PDF_Chinese)
55 57 AddBig5Font()
56 58 @font_for_content = 'Big5'
57 59 @font_for_footer = 'Big5'
58 60 else
59 61 @font_for_content = 'Arial'
60 62 @font_for_footer = 'Helvetica'
61 63 end
62 64 SetCreator(Redmine::Info.app_name)
63 65 SetFont(@font_for_content)
64 66 end
65 67
66 68 def SetFontStyle(style, size)
67 69 SetFont(@font_for_content, style, size)
68 70 end
69 71
70 72 def SetTitle(txt)
71 73 txt = begin
72 74 utf16txt = Iconv.conv('UTF-16BE', 'UTF-8', txt)
73 75 hextxt = "<FEFF" # FEFF is BOM
74 76 hextxt << utf16txt.unpack("C*").map {|x| sprintf("%02X",x) }.join
75 77 hextxt << ">"
76 78 rescue
77 79 txt
78 80 end || ''
79 81 super(txt)
80 82 end
81 83
82 84 def textstring(s)
83 85 # Format a text string
84 86 if s =~ /^</ # This means the string is hex-dumped.
85 87 return s
86 88 else
87 89 return '('+escape(s)+')'
88 90 end
89 91 end
90 92
91 93 def Cell(w,h=0,txt='',border=0,ln=0,align='',fill=0,link='')
92 94 @ic ||= Iconv.new(l(:general_pdf_encoding), 'UTF-8')
93 95 # these quotation marks are not correctly rendered in the pdf
94 96 txt = txt.gsub(/[Ò€œÒ€�]/, '"') if txt
95 97 txt = begin
96 98 # 0x5c char handling
97 99 txtar = txt.split('\\')
98 100 txtar << '' if txt[-1] == ?\\
99 101 txtar.collect {|x| @ic.iconv(x)}.join('\\').gsub(/\\/, "\\\\\\\\")
100 102 rescue
101 103 txt
102 104 end || ''
103 105 super w,h,txt,border,ln,align,fill,link
104 106 end
105 107
106 108 def Footer
107 109 SetFont(@font_for_footer, 'I', 8)
108 110 SetY(-15)
109 111 SetX(15)
110 112 Cell(0, 5, @footer_date, 0, 0, 'L')
111 113 SetY(-15)
112 114 SetX(-30)
113 115 Cell(0, 5, PageNo().to_s + '/{nb}', 0, 0, 'C')
114 116 end
115 117 end
116 118
117 119 # Returns a PDF string of a list of issues
118 120 def issues_to_pdf(issues, project, query)
119 121 pdf = IFPDF.new(current_language)
120 122 title = query.new_record? ? l(:label_issue_plural) : query.name
121 123 title = "#{project} - #{title}" if project
122 124 pdf.SetTitle(title)
123 125 pdf.AliasNbPages
124 126 pdf.footer_date = format_date(Date.today)
125 127 pdf.AddPage("L")
126 128
127 129 row_height = 6
128 130 col_width = []
129 131 unless query.columns.empty?
130 132 col_width = query.columns.collect {|column| column.name == :subject ? 4.0 : 1.0 }
131 133 ratio = 262.0 / col_width.inject(0) {|s,w| s += w}
132 134 col_width = col_width.collect {|w| w * ratio}
133 135 end
134 136
135 137 # title
136 138 pdf.SetFontStyle('B',11)
137 139 pdf.Cell(190,10, title)
138 140 pdf.Ln
139 141
140 142 # headers
141 143 pdf.SetFontStyle('B',8)
142 144 pdf.SetFillColor(230, 230, 230)
143 145 pdf.Cell(15, row_height, "#", 1, 0, 'L', 1)
144 146 query.columns.each_with_index do |column, i|
145 147 pdf.Cell(col_width[i], row_height, column.caption, 1, 0, 'L', 1)
146 148 end
147 149 pdf.Ln
148 150
149 151 # rows
150 152 pdf.SetFontStyle('',8)
151 153 pdf.SetFillColor(255, 255, 255)
152 154 previous_group = false
153 155 issues.each do |issue|
154 156 if query.grouped? && (group = query.group_by_column.value(issue)) != previous_group
155 157 pdf.SetFontStyle('B',9)
156 158 pdf.Cell(277, row_height,
157 159 (group.blank? ? 'None' : group.to_s) + " (#{query.issue_count_by_group[group]})",
158 160 1, 1, 'L')
159 161 pdf.SetFontStyle('',8)
160 162 previous_group = group
161 163 end
162 164 pdf.Cell(15, row_height, issue.id.to_s, 1, 0, 'L', 1)
163 165 query.columns.each_with_index do |column, i|
164 166 s = if column.is_a?(QueryCustomFieldColumn)
165 167 cv = issue.custom_values.detect {|v| v.custom_field_id == column.custom_field.id}
166 168 show_value(cv)
167 169 else
168 170 value = issue.send(column.name)
169 171 if value.is_a?(Date)
170 172 format_date(value)
171 173 elsif value.is_a?(Time)
172 174 format_time(value)
173 175 else
174 176 value
175 177 end
176 178 end
177 179 pdf.Cell(col_width[i], row_height, s.to_s, 1, 0, 'L', 1)
178 180 end
179 181 pdf.Ln
180 182 end
181 183 if issues.size == Setting.issues_export_limit.to_i
182 184 pdf.SetFontStyle('B',10)
183 185 pdf.Cell(0, row_height, '...')
184 186 end
185 187 pdf.Output
186 188 end
187 189
188 190 # Returns a PDF string of a single issue
189 191 def issue_to_pdf(issue)
190 192 pdf = IFPDF.new(current_language)
191 193 pdf.SetTitle("#{issue.project} - ##{issue.tracker} #{issue.id}")
192 194 pdf.AliasNbPages
193 195 pdf.footer_date = format_date(Date.today)
194 196 pdf.AddPage
195 197
196 198 pdf.SetFontStyle('B',11)
197 199 pdf.Cell(190,10, "#{issue.project} - #{issue.tracker} # #{issue.id}: #{issue.subject}")
198 200 pdf.Ln
199 201
200 202 y0 = pdf.GetY
201 203
202 204 pdf.SetFontStyle('B',9)
203 205 pdf.Cell(35,5, l(:field_status) + ":","LT")
204 206 pdf.SetFontStyle('',9)
205 207 pdf.Cell(60,5, issue.status.to_s,"RT")
206 208 pdf.SetFontStyle('B',9)
207 209 pdf.Cell(35,5, l(:field_priority) + ":","LT")
208 210 pdf.SetFontStyle('',9)
209 211 pdf.Cell(60,5, issue.priority.to_s,"RT")
210 212 pdf.Ln
211 213
212 214 pdf.SetFontStyle('B',9)
213 215 pdf.Cell(35,5, l(:field_author) + ":","L")
214 216 pdf.SetFontStyle('',9)
215 217 pdf.Cell(60,5, issue.author.to_s,"R")
216 218 pdf.SetFontStyle('B',9)
217 219 pdf.Cell(35,5, l(:field_category) + ":","L")
218 220 pdf.SetFontStyle('',9)
219 221 pdf.Cell(60,5, issue.category.to_s,"R")
220 222 pdf.Ln
221 223
222 224 pdf.SetFontStyle('B',9)
223 225 pdf.Cell(35,5, l(:field_created_on) + ":","L")
224 226 pdf.SetFontStyle('',9)
225 227 pdf.Cell(60,5, format_date(issue.created_on),"R")
226 228 pdf.SetFontStyle('B',9)
227 229 pdf.Cell(35,5, l(:field_assigned_to) + ":","L")
228 230 pdf.SetFontStyle('',9)
229 231 pdf.Cell(60,5, issue.assigned_to.to_s,"R")
230 232 pdf.Ln
231 233
232 234 pdf.SetFontStyle('B',9)
233 235 pdf.Cell(35,5, l(:field_updated_on) + ":","LB")
234 236 pdf.SetFontStyle('',9)
235 237 pdf.Cell(60,5, format_date(issue.updated_on),"RB")
236 238 pdf.SetFontStyle('B',9)
237 239 pdf.Cell(35,5, l(:field_due_date) + ":","LB")
238 240 pdf.SetFontStyle('',9)
239 241 pdf.Cell(60,5, format_date(issue.due_date),"RB")
240 242 pdf.Ln
241 243
242 244 for custom_value in issue.custom_field_values
243 245 pdf.SetFontStyle('B',9)
244 246 pdf.Cell(35,5, custom_value.custom_field.name + ":","L")
245 247 pdf.SetFontStyle('',9)
246 248 pdf.MultiCell(155,5, (show_value custom_value),"R")
247 249 end
248 250
249 251 pdf.SetFontStyle('B',9)
250 252 pdf.Cell(35,5, l(:field_subject) + ":","LTB")
251 253 pdf.SetFontStyle('',9)
252 254 pdf.Cell(155,5, issue.subject,"RTB")
253 255 pdf.Ln
254 256
255 257 pdf.SetFontStyle('B',9)
256 258 pdf.Cell(35,5, l(:field_description) + ":")
257 259 pdf.SetFontStyle('',9)
258 260 pdf.MultiCell(155,5, issue.description.to_s,"BR")
259 261
260 262 pdf.Line(pdf.GetX, y0, pdf.GetX, pdf.GetY)
261 263 pdf.Line(pdf.GetX, pdf.GetY, 170, pdf.GetY)
262 264 pdf.Ln
263 265
264 266 if issue.changesets.any? && User.current.allowed_to?(:view_changesets, issue.project)
265 267 pdf.SetFontStyle('B',9)
266 268 pdf.Cell(190,5, l(:label_associated_revisions), "B")
267 269 pdf.Ln
268 270 for changeset in issue.changesets
269 271 pdf.SetFontStyle('B',8)
270 272 pdf.Cell(190,5, format_time(changeset.committed_on) + " - " + changeset.author.to_s)
271 273 pdf.Ln
272 274 unless changeset.comments.blank?
273 275 pdf.SetFontStyle('',8)
274 276 pdf.MultiCell(190,5, changeset.comments.to_s)
275 277 end
276 278 pdf.Ln
277 279 end
278 280 end
279 281
280 282 pdf.SetFontStyle('B',9)
281 283 pdf.Cell(190,5, l(:label_history), "B")
282 284 pdf.Ln
283 285 for journal in issue.journals.find(:all, :include => [:user, :details], :order => "#{Journal.table_name}.created_on ASC")
284 286 pdf.SetFontStyle('B',8)
285 287 pdf.Cell(190,5, format_time(journal.created_on) + " - " + journal.user.name)
286 288 pdf.Ln
287 289 pdf.SetFontStyle('I',8)
288 290 for detail in journal.details
289 291 pdf.Cell(190,5, "- " + show_detail(detail, true))
290 292 pdf.Ln
291 293 end
292 294 if journal.notes?
293 295 pdf.SetFontStyle('',8)
294 296 pdf.MultiCell(190,5, journal.notes.to_s)
295 297 end
296 298 pdf.Ln
297 299 end
298 300
299 301 if issue.attachments.any?
300 302 pdf.SetFontStyle('B',9)
301 303 pdf.Cell(190,5, l(:label_attachment_plural), "B")
302 304 pdf.Ln
303 305 for attachment in issue.attachments
304 306 pdf.SetFontStyle('',8)
305 307 pdf.Cell(80,5, attachment.filename)
306 308 pdf.Cell(20,5, number_to_human_size(attachment.filesize),0,0,"R")
307 309 pdf.Cell(25,5, format_date(attachment.created_on),0,0,"R")
308 310 pdf.Cell(65,5, attachment.author.name,0,0,"R")
309 311 pdf.Ln
310 312 end
311 313 end
312 314 pdf.Output
313 315 end
314 316
315 317 end
316 318 end
317 319 end
General Comments 0
You need to be logged in to leave comments. Login now