314 |
314 |
col_width_avg.map! {|x| x / k}
|
315 |
315 |
|
316 |
316 |
# calculate columns width
|
317 |
|
ratio = table_width / col_width_avg.inject(0) {|s,w| s += w}
|
|
317 |
ratio = table_width / col_width_avg.inject(0, :+)
|
318 |
318 |
col_width = col_width_avg.map {|w| w * ratio}
|
319 |
319 |
|
320 |
320 |
# correct max word width if too many columns
|
321 |
|
ratio = table_width / word_width_max.inject(0) {|s,w| s += w}
|
|
321 |
ratio = table_width / word_width_max.inject(0, :+)
|
322 |
322 |
word_width_max.map! {|v| v * ratio} if ratio < 1
|
323 |
323 |
|
324 |
324 |
# correct and lock width of some columns
|
... | ... | |
354 |
354 |
|
355 |
355 |
# calculate column normalizing ratio
|
356 |
356 |
if free_col_width == 0
|
357 |
|
ratio = table_width / col_width.inject(0) {|s,w| s += w}
|
|
357 |
ratio = table_width / col_width.inject(0, :+)
|
358 |
358 |
else
|
359 |
359 |
ratio = (table_width - fix_col_width) / free_col_width
|
360 |
360 |
end
|
... | ... | |
380 |
380 |
col_width
|
381 |
381 |
end
|
382 |
382 |
|
383 |
|
def render_table_header(pdf, query, col_width, row_height, col_id_width, table_width)
|
|
383 |
def render_table_header(pdf, query, col_width, row_height, table_width)
|
384 |
384 |
# headers
|
385 |
385 |
pdf.SetFontStyle('B',8)
|
386 |
386 |
pdf.SetFillColor(230, 230, 230)
|
... | ... | |
389 |
389 |
base_x = pdf.GetX
|
390 |
390 |
base_y = pdf.GetY
|
391 |
391 |
max_height = issues_to_pdf_write_cells(pdf, query.inline_columns, col_width, row_height, true)
|
392 |
|
pdf.Rect(base_x, base_y, table_width + col_id_width, max_height, 'FD');
|
|
392 |
pdf.Rect(base_x, base_y, table_width, max_height, 'FD');
|
393 |
393 |
pdf.SetXY(base_x, base_y);
|
394 |
394 |
|
395 |
395 |
# write the cells on page
|
396 |
|
pdf.RDMCell(col_id_width, row_height, "#", "T", 0, 'C', 1)
|
397 |
396 |
issues_to_pdf_write_cells(pdf, query.inline_columns, col_width, row_height, true)
|
398 |
|
issues_to_pdf_draw_borders(pdf, base_x, base_y, base_y + max_height, col_id_width, col_width)
|
|
397 |
issues_to_pdf_draw_borders(pdf, base_x, base_y, base_y + max_height, col_width)
|
399 |
398 |
pdf.SetY(base_y + max_height);
|
400 |
399 |
|
401 |
400 |
# rows
|
... | ... | |
417 |
416 |
# Landscape A4 = 210 x 297 mm
|
418 |
417 |
page_height = 210
|
419 |
418 |
page_width = 297
|
|
419 |
left_margin = 10
|
420 |
420 |
right_margin = 10
|
421 |
421 |
bottom_margin = 20
|
422 |
|
col_id_width = 10
|
423 |
422 |
row_height = 4
|
424 |
423 |
|
425 |
424 |
# column widths
|
426 |
|
table_width = page_width - right_margin - 10 # fixed left margin
|
|
425 |
table_width = page_width - right_margin - left_margin
|
427 |
426 |
col_width = []
|
428 |
427 |
unless query.inline_columns.empty?
|
429 |
|
col_width = calc_col_width(issues, query, table_width - col_id_width, pdf)
|
430 |
|
table_width = col_width.inject(0) {|s,v| s += v}
|
|
428 |
col_width = calc_col_width(issues, query, table_width, pdf)
|
|
429 |
table_width = col_width.inject(0, :+)
|
431 |
430 |
end
|
432 |
431 |
|
433 |
|
# use full width if the description is displayed
|
|
432 |
# use full width if the description is displayed
|
434 |
433 |
if table_width > 0 && query.has_column?(:description)
|
435 |
|
col_width = col_width.map {|w| w = w * (page_width - right_margin - 10 - col_id_width) / table_width}
|
436 |
|
table_width = col_width.inject(0) {|s,v| s += v}
|
|
434 |
col_width = col_width.map {|w| w * (page_width - right_margin - left_margin) / table_width}
|
|
435 |
table_width = col_width.inject(0, :+)
|
437 |
436 |
end
|
438 |
437 |
|
439 |
438 |
# title
|
440 |
439 |
pdf.SetFontStyle('B',11)
|
441 |
440 |
pdf.RDMCell(190,10, title)
|
442 |
441 |
pdf.Ln
|
443 |
|
render_table_header(pdf, query, col_width, row_height, col_id_width, table_width)
|
|
442 |
render_table_header(pdf, query, col_width, row_height, table_width)
|
444 |
443 |
previous_group = false
|
445 |
444 |
issue_list(issues) do |issue, level|
|
446 |
445 |
if query.grouped? &&
|
... | ... | |
449 |
448 |
group_label = group.blank? ? 'None' : group.to_s.dup
|
450 |
449 |
group_label << " (#{query.issue_count_by_group[group]})"
|
451 |
450 |
pdf.Bookmark group_label, 0, -1
|
452 |
|
pdf.RDMCell(table_width + col_id_width, row_height * 2, group_label, 1, 1, 'L')
|
|
451 |
pdf.RDMCell(table_width, row_height * 2, group_label, 1, 1, 'L')
|
453 |
452 |
pdf.SetFontStyle('',8)
|
454 |
453 |
previous_group = group
|
455 |
454 |
end
|
... | ... | |
468 |
467 |
space_left = page_height - base_y - bottom_margin
|
469 |
468 |
if max_height > space_left
|
470 |
469 |
pdf.AddPage("L")
|
471 |
|
render_table_header(pdf, query, col_width, row_height, col_id_width, table_width)
|
|
470 |
render_table_header(pdf, query, col_width, row_height, table_width)
|
472 |
471 |
base_x = pdf.GetX
|
473 |
472 |
base_y = pdf.GetY
|
474 |
473 |
end
|
475 |
474 |
|
476 |
475 |
# write the cells on page
|
477 |
|
pdf.RDMCell(col_id_width, row_height, issue.id.to_s, "T", 0, 'C', 1)
|
478 |
476 |
issues_to_pdf_write_cells(pdf, col_values, col_width, row_height)
|
479 |
|
issues_to_pdf_draw_borders(pdf, base_x, base_y, base_y + max_height, col_id_width, col_width)
|
|
477 |
issues_to_pdf_draw_borders(pdf, base_x, base_y, base_y + max_height, col_width)
|
480 |
478 |
pdf.SetY(base_y + max_height);
|
481 |
479 |
|
482 |
480 |
if query.has_column?(:description) && issue.description?
|
... | ... | |
495 |
493 |
end
|
496 |
494 |
|
497 |
495 |
# Renders MultiCells and returns the maximum height used
|
498 |
|
def issues_to_pdf_write_cells(pdf, col_values, col_widths,
|
499 |
|
row_height, head=false)
|
|
496 |
def issues_to_pdf_write_cells(pdf, col_values, col_widths, row_height, head=false)
|
500 |
497 |
base_y = pdf.GetY
|
501 |
498 |
max_height = row_height
|
502 |
499 |
col_values.each_with_index do |column, i|
|
... | ... | |
513 |
510 |
end
|
514 |
511 |
|
515 |
512 |
# Draw lines to close the row (MultiCell border drawing in not uniform)
|
516 |
|
def issues_to_pdf_draw_borders(pdf, top_x, top_y, lower_y,
|
517 |
|
id_width, col_widths)
|
518 |
|
col_x = top_x + id_width
|
|
513 |
def issues_to_pdf_draw_borders(pdf, top_x, top_y, lower_y, col_widths)
|
|
514 |
col_x = top_x
|
519 |
515 |
pdf.Line(col_x, top_y, col_x, lower_y) # id right border
|
520 |
516 |
col_widths.each do |width|
|
521 |
517 |
col_x += width
|