comparison lib/redmine/export/.svn/text-base/pdf.rb.svn-base @ 22:40f7cfd4df19

* Update to SVN trunk rev 4173
author Chris Cannam <chris.cannam@soundsoftware.ac.uk>
date Fri, 24 Sep 2010 14:06:04 +0100
parents cca12e1c1fd4
children 0579821a129a
comparison
equal deleted inserted replaced
14:1d32c0a0efbf 22:40f7cfd4df19
152 previous_group = false 152 previous_group = false
153 issues.each do |issue| 153 issues.each do |issue|
154 if query.grouped? && (group = query.group_by_column.value(issue)) != previous_group 154 if query.grouped? && (group = query.group_by_column.value(issue)) != previous_group
155 pdf.SetFontStyle('B',9) 155 pdf.SetFontStyle('B',9)
156 pdf.Cell(277, row_height, 156 pdf.Cell(277, row_height,
157 (group.blank? ? 'None' : group.to_s) + " (#{@issue_count_by_group[group]})", 157 (group.blank? ? 'None' : group.to_s) + " (#{query.issue_count_by_group[group]})",
158 1, 1, 'L') 158 1, 1, 'L')
159 pdf.SetFontStyle('',8) 159 pdf.SetFontStyle('',8)
160 previous_group = group 160 previous_group = group
161 end 161 end
162 pdf.Cell(15, row_height, issue.id.to_s, 1, 0, 'L', 1) 162 pdf.Cell(15, row_height, issue.id.to_s, 1, 0, 'L', 1)
182 pdf.SetFontStyle('B',10) 182 pdf.SetFontStyle('B',10)
183 pdf.Cell(0, row_height, '...') 183 pdf.Cell(0, row_height, '...')
184 end 184 end
185 pdf.Output 185 pdf.Output
186 end 186 end
187 187
188 # Returns a PDF string of a single issue 188 # Returns a PDF string of a single issue
189 def issue_to_pdf(issue) 189 def issue_to_pdf(issue)
190 pdf = IFPDF.new(current_language) 190 pdf = IFPDF.new(current_language)
191 pdf.SetTitle("#{issue.project} - ##{issue.tracker} #{issue.id}") 191 pdf.SetTitle("#{issue.project} - ##{issue.tracker} #{issue.id}")
192 pdf.AliasNbPages 192 pdf.AliasNbPages
206 pdf.SetFontStyle('B',9) 206 pdf.SetFontStyle('B',9)
207 pdf.Cell(35,5, l(:field_priority) + ":","LT") 207 pdf.Cell(35,5, l(:field_priority) + ":","LT")
208 pdf.SetFontStyle('',9) 208 pdf.SetFontStyle('',9)
209 pdf.Cell(60,5, issue.priority.to_s,"RT") 209 pdf.Cell(60,5, issue.priority.to_s,"RT")
210 pdf.Ln 210 pdf.Ln
211 211
212 pdf.SetFontStyle('B',9) 212 pdf.SetFontStyle('B',9)
213 pdf.Cell(35,5, l(:field_author) + ":","L") 213 pdf.Cell(35,5, l(:field_author) + ":","L")
214 pdf.SetFontStyle('',9) 214 pdf.SetFontStyle('',9)
215 pdf.Cell(60,5, issue.author.to_s,"R") 215 pdf.Cell(60,5, issue.author.to_s,"R")
216 pdf.SetFontStyle('B',9) 216 pdf.SetFontStyle('B',9)
236 pdf.SetFontStyle('B',9) 236 pdf.SetFontStyle('B',9)
237 pdf.Cell(35,5, l(:field_due_date) + ":","LB") 237 pdf.Cell(35,5, l(:field_due_date) + ":","LB")
238 pdf.SetFontStyle('',9) 238 pdf.SetFontStyle('',9)
239 pdf.Cell(60,5, format_date(issue.due_date),"RB") 239 pdf.Cell(60,5, format_date(issue.due_date),"RB")
240 pdf.Ln 240 pdf.Ln
241 241
242 for custom_value in issue.custom_field_values 242 for custom_value in issue.custom_field_values
243 pdf.SetFontStyle('B',9) 243 pdf.SetFontStyle('B',9)
244 pdf.Cell(35,5, custom_value.custom_field.name + ":","L") 244 pdf.Cell(35,5, custom_value.custom_field.name + ":","L")
245 pdf.SetFontStyle('',9) 245 pdf.SetFontStyle('',9)
246 pdf.MultiCell(155,5, (show_value custom_value),"R") 246 pdf.MultiCell(155,5, (show_value custom_value),"R")
247 end 247 end
248 248
249 pdf.SetFontStyle('B',9) 249 pdf.SetFontStyle('B',9)
250 pdf.Cell(35,5, l(:field_subject) + ":","LTB") 250 pdf.Cell(35,5, l(:field_subject) + ":","LTB")
251 pdf.SetFontStyle('',9) 251 pdf.SetFontStyle('',9)
252 pdf.Cell(155,5, issue.subject,"RTB") 252 pdf.Cell(155,5, issue.subject,"RTB")
253 pdf.Ln 253 pdf.Ln
254 254
255 pdf.SetFontStyle('B',9) 255 pdf.SetFontStyle('B',9)
256 pdf.Cell(35,5, l(:field_description) + ":") 256 pdf.Cell(35,5, l(:field_description) + ":")
257 pdf.SetFontStyle('',9) 257 pdf.SetFontStyle('',9)
258 pdf.MultiCell(155,5, @issue.description,"BR") 258 pdf.MultiCell(155,5, issue.description,"BR")
259 259
260 pdf.Line(pdf.GetX, y0, pdf.GetX, pdf.GetY) 260 pdf.Line(pdf.GetX, y0, pdf.GetX, pdf.GetY)
261 pdf.Line(pdf.GetX, pdf.GetY, 170, pdf.GetY) 261 pdf.Line(pdf.GetX, pdf.GetY, 170, pdf.GetY)
262 pdf.Ln 262 pdf.Ln
263 263
309 pdf.Ln 309 pdf.Ln
310 end 310 end
311 end 311 end
312 pdf.Output 312 pdf.Output
313 end 313 end
314 314
315 # Returns a PDF string of a gantt chart
316 def gantt_to_pdf(gantt, project)
317 pdf = IFPDF.new(current_language)
318 pdf.SetTitle("#{l(:label_gantt)} #{project}")
319 pdf.AliasNbPages
320 pdf.footer_date = format_date(Date.today)
321 pdf.AddPage("L")
322 pdf.SetFontStyle('B',12)
323 pdf.SetX(15)
324 pdf.Cell(70, 20, project.to_s)
325 pdf.Ln
326 pdf.SetFontStyle('B',9)
327
328 subject_width = 100
329 header_heigth = 5
330
331 headers_heigth = header_heigth
332 show_weeks = false
333 show_days = false
334
335 if gantt.months < 7
336 show_weeks = true
337 headers_heigth = 2*header_heigth
338 if gantt.months < 3
339 show_days = true
340 headers_heigth = 3*header_heigth
341 end
342 end
343
344 g_width = 280 - subject_width
345 zoom = (g_width) / (gantt.date_to - gantt.date_from + 1)
346 g_height = 120
347 t_height = g_height + headers_heigth
348
349 y_start = pdf.GetY
350
351 # Months headers
352 month_f = gantt.date_from
353 left = subject_width
354 height = header_heigth
355 gantt.months.times do
356 width = ((month_f >> 1) - month_f) * zoom
357 pdf.SetY(y_start)
358 pdf.SetX(left)
359 pdf.Cell(width, height, "#{month_f.year}-#{month_f.month}", "LTR", 0, "C")
360 left = left + width
361 month_f = month_f >> 1
362 end
363
364 # Weeks headers
365 if show_weeks
366 left = subject_width
367 height = header_heigth
368 if gantt.date_from.cwday == 1
369 # gantt.date_from is monday
370 week_f = gantt.date_from
371 else
372 # find next monday after gantt.date_from
373 week_f = gantt.date_from + (7 - gantt.date_from.cwday + 1)
374 width = (7 - gantt.date_from.cwday + 1) * zoom-1
375 pdf.SetY(y_start + header_heigth)
376 pdf.SetX(left)
377 pdf.Cell(width + 1, height, "", "LTR")
378 left = left + width+1
379 end
380 while week_f <= gantt.date_to
381 width = (week_f + 6 <= gantt.date_to) ? 7 * zoom : (gantt.date_to - week_f + 1) * zoom
382 pdf.SetY(y_start + header_heigth)
383 pdf.SetX(left)
384 pdf.Cell(width, height, (width >= 5 ? week_f.cweek.to_s : ""), "LTR", 0, "C")
385 left = left + width
386 week_f = week_f+7
387 end
388 end
389
390 # Days headers
391 if show_days
392 left = subject_width
393 height = header_heigth
394 wday = gantt.date_from.cwday
395 pdf.SetFontStyle('B',7)
396 (gantt.date_to - gantt.date_from + 1).to_i.times do
397 width = zoom
398 pdf.SetY(y_start + 2 * header_heigth)
399 pdf.SetX(left)
400 pdf.Cell(width, height, day_name(wday).first, "LTR", 0, "C")
401 left = left + width
402 wday = wday + 1
403 wday = 1 if wday > 7
404 end
405 end
406
407 pdf.SetY(y_start)
408 pdf.SetX(15)
409 pdf.Cell(subject_width+g_width-15, headers_heigth, "", 1)
410
411 # Tasks
412 top = headers_heigth + y_start
413 pdf.SetFontStyle('B',7)
414 gantt.events.each do |i|
415 pdf.SetY(top)
416 pdf.SetX(15)
417
418 text = ""
419 if i.is_a? Issue
420 text = "#{i.tracker} #{i.id}: #{i.subject}"
421 else
422 text = i.name
423 end
424 text = "#{i.project} - #{text}" unless project && project == i.project
425 pdf.Cell(subject_width-15, 5, text, "LR")
426
427 pdf.SetY(top + 0.2)
428 pdf.SetX(subject_width)
429 pdf.SetFillColor(255, 255, 255)
430 pdf.Cell(g_width, 4.6, "", "LR", 0, "", 1)
431 pdf.SetY(top+1.5)
432
433 if i.is_a? Issue
434 i_start_date = (i.start_date >= gantt.date_from ? i.start_date : gantt.date_from )
435 i_end_date = (i.due_before <= gantt.date_to ? i.due_before : gantt.date_to )
436
437 i_done_date = i.start_date + ((i.due_before - i.start_date+1)*i.done_ratio/100).floor
438 i_done_date = (i_done_date <= gantt.date_from ? gantt.date_from : i_done_date )
439 i_done_date = (i_done_date >= gantt.date_to ? gantt.date_to : i_done_date )
440
441 i_late_date = [i_end_date, Date.today].min if i_start_date < Date.today
442
443 i_left = ((i_start_date - gantt.date_from)*zoom)
444 i_width = ((i_end_date - i_start_date + 1)*zoom)
445 d_width = ((i_done_date - i_start_date)*zoom)
446 l_width = ((i_late_date - i_start_date+1)*zoom) if i_late_date
447 l_width ||= 0
448
449 pdf.SetX(subject_width + i_left)
450 pdf.SetFillColor(200,200,200)
451 pdf.Cell(i_width, 2, "", 0, 0, "", 1)
452
453 if l_width > 0
454 pdf.SetY(top+1.5)
455 pdf.SetX(subject_width + i_left)
456 pdf.SetFillColor(255,100,100)
457 pdf.Cell(l_width, 2, "", 0, 0, "", 1)
458 end
459 if d_width > 0
460 pdf.SetY(top+1.5)
461 pdf.SetX(subject_width + i_left)
462 pdf.SetFillColor(100,100,255)
463 pdf.Cell(d_width, 2, "", 0, 0, "", 1)
464 end
465
466 pdf.SetY(top+1.5)
467 pdf.SetX(subject_width + i_left + i_width)
468 pdf.Cell(30, 2, "#{i.status} #{i.done_ratio}%")
469 else
470 i_left = ((i.start_date - gantt.date_from)*zoom)
471
472 pdf.SetX(subject_width + i_left)
473 pdf.SetFillColor(50,200,50)
474 pdf.Cell(2, 2, "", 0, 0, "", 1)
475
476 pdf.SetY(top+1.5)
477 pdf.SetX(subject_width + i_left + 3)
478 pdf.Cell(30, 2, "#{i.name}")
479 end
480
481 top = top + 5
482 pdf.SetDrawColor(200, 200, 200)
483 pdf.Line(15, top, subject_width+g_width, top)
484 if pdf.GetY() > 180
485 pdf.AddPage("L")
486 top = 20
487 pdf.Line(15, top, subject_width+g_width, top)
488 end
489 pdf.SetDrawColor(0, 0, 0)
490 end
491
492 pdf.Line(15, top, subject_width+g_width, top)
493 pdf.Output
494 end
495 end 315 end
496 end 316 end
497 end 317 end