OpenProject is the leading open source project management software for product, project and portfolio management. A powerful Jira alternative with agile planning, issue tracking, roadmaps, Gantt charts, time tracking, collaboration features, and more. Available on premises or in the cloud. ⭐ Star us on GitHub
Ruby agile-developmentangularbcfboardsbug-trackerganttgantt-chartifcissue-trackerjira-alternativekanbanopenprojectproduct-managementproject-managementproject-planningroadmaprubyscrumtimelineworkflows
[#48647] Manage long query titles in footer of pdf export
as-op881e45c4df4e
diff --git a/app/models/work_package/pdf_export/common.rb b/app/models/work_package/pdf_export/common.rbindex 66092c78b8a..81bbdd84542 100644--- a/app/models/work_package/pdf_export/common.rb+++ b/app/models/work_package/pdf_export/common.rb@@ -136,16 +136,16 @@ module WorkPackage::PDFExport::Commonpdf.table(data, options.merge({ column_widths: }), &)end- def draw_text_multiline_left(text, text_style, max_left, top)- lines = wrap_to_lines(text, max_left - pdf.bounds.left, text_style)+ def draw_text_multiline_left(text:, text_style:, max_left:, top:, max_lines:)+ lines = wrap_to_lines(text, max_left - pdf.bounds.left, text_style, max_lines)starting_position = toplines.reverse.each do |line|starting_position += draw_text_multiline_part(line, text_style, pdf.bounds.left, starting_position)endend- def draw_text_multiline_right(text, text_style, max_left, top)- lines = wrap_to_lines(text, pdf.bounds.right - max_left, text_style)+ def draw_text_multiline_right(text:, text_style:, max_left:, top:, max_lines:)+ lines = wrap_to_lines(text, pdf.bounds.right - max_left, text_style, max_lines)starting_position = toplines.reverse.each do |line|line_width = measure_text_width(line, text_style)@@ -166,20 +166,38 @@ module WorkPackage::PDFExport::Commonmeasure_text_height(line, text_style)end- def wrap_to_lines(text, available_width, text_style)+ def truncate_ellipsis(text, available_width, text_style)+ line = text.dup+ while line.present? && (measure_text_width("#{line}...", text_style) > available_width)+ line = line.chop+ end+ "#{line}..."+ end++ def split_wrapped_lines(text, available_width, text_style)+ split_text = text.dup+ lines = []+ arranger = Prawn::Text::Formatted::Arranger.new(pdf)+ line_wrapper = Prawn::Text::Formatted::LineWrap.new+ until split_text.blank?+ arranger.format_array = [text_style.merge({ text: split_text })]+ single_line = line_wrapper.wrap_line(arranger:, width: available_width, document: pdf)+ lines << single_line+ split_text.slice!(single_line)+ end+ lines+ end++ def wrap_to_lines(text, available_width, text_style, max_lines)split_text = text.duptitle_text_width = measure_text_width(split_text, text_style)if title_text_width < available_width[split_text]else- lines = []- arranger = Prawn::Text::Formatted::Arranger.new(pdf)- line_wrapper = Prawn::Text::Formatted::LineWrap.new- until split_text.blank?- arranger.format_array = [text_style.merge({ text: split_text })]- single_line = line_wrapper.wrap_line(arranger:, width: available_width, document: pdf)- lines << single_line- split_text.slice!(single_line)+ lines = split_wrapped_lines(text, available_width, text_style)+ if lines.length > max_lines+ lines[max_lines - 1] = truncate_ellipsis(lines[max_lines - 1], available_width, text_style)+ lines = lines.first(3)endlinesenddiff --git a/app/models/work_package/pdf_export/page.rb b/app/models/work_package/pdf_export/page.rbindex 86edbb9bea5..f3b670bff3b 100644--- a/app/models/work_package/pdf_export/page.rb+++ b/app/models/work_package/pdf_export/page.rb@@ -27,6 +27,8 @@#++module WorkPackage::PDFExport::Page+ MAX_NR_OF_PDF_FOOTER_LINES = 3+def configure_page_size!(layout)pdf.options[:page_layout] = layoutpdf.options[:page_size] = styles.page_size@@ -92,16 +94,23 @@ module WorkPackage::PDFExport::Pagedef write_footers!pdf.repeat :all, dynamic: true do- draw_footer_on_page!+ draw_footer_on_pageendend- def draw_footer_on_page!+ def draw_footer_on_pagetop = styles.page_footer_offsettext_style = styles.page_footer+ spacing = styles.page_footer_horizontal_spacingpage_nr_x, page_nr_width = draw_text_centered(footer_page_nr, text_style, top)- draw_text_multiline_left(footer_date, text_style, page_nr_x, top)- draw_text_multiline_right(footer_title, text_style, page_nr_x + page_nr_width, top)+ draw_text_multiline_left(+ text: footer_date, max_left: page_nr_x - spacing,+ text_style:, top:, max_lines: MAX_NR_OF_PDF_FOOTER_LINES+ )+ draw_text_multiline_right(+ text: footer_title, max_left: page_nr_x + page_nr_width + spacing,+ text_style:, top:, max_lines: MAX_NR_OF_PDF_FOOTER_LINES+ )enddef footer_page_nrdiff --git a/app/models/work_package/pdf_export/style.rb b/app/models/work_package/pdf_export/style.rbindex cef670600a5..f6b4f6c9ac1 100644--- a/app/models/work_package/pdf_export/style.rb+++ b/app/models/work_package/pdf_export/style.rb@@ -49,6 +49,10 @@ module WorkPackage::PDFExport::Styleresolve_pt(@styles.dig(:page_footer, :offset), -30)end+ def page_footer_horizontal_spacing+ resolve_pt(@styles.dig(:page_footer, :spacing), 6)+ end+def page_logo_heightresolve_pt(@styles.dig(:page_logo, :height), 20)end