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
feat(pdf-export): move logo to right, remove author in header, refactor styles
as-op2eab433012f4
diff --git a/app/models/work_package/pdf_export/common.rb b/app/models/work_package/pdf_export/common.rbindex 1c0de7c1e57..1789b108a64 100644--- a/app/models/work_package/pdf_export/common.rb+++ b/app/models/work_package/pdf_export/common.rb@@ -111,7 +111,7 @@ module WorkPackage::PDFExport::Commonenddef make_link_href_cell(href, caption)- "<link href='#{href}'>#{caption}</link>"+ "<color rgb='#{overview_table_link_color}'><link href='#{href}'>#{caption}</link></color>"enddef make_link_anchor_cell(anchor, caption)diff --git a/app/models/work_package/pdf_export/markdown.rb b/app/models/work_package/pdf_export/markdown.rbindex 802446e8dd4..ee9f2f3ecf1 100644--- a/app/models/work_package/pdf_export/markdown.rb+++ b/app/models/work_package/pdf_export/markdown.rb@@ -97,7 +97,7 @@ module WorkPackage::PDFExport::Markdownenddef write_markdown!(work_package, markdown)- md2pdf = MD2PDF.new(styling_yml)+ md2pdf = MD2PDF.new(markdown_styling_yml)md2pdf.draw_markdown(markdown, pdf, ->(src) {with_attachments? ? attachment_image_filepath(work_package, src) : nil})@@ -105,105 +105,6 @@ module WorkPackage::PDFExport::Markdownprivate- def styling_yml- # rubocop:disable Naming/VariableNumber- {- header: {- size: 8,- styles: [:bold]- },- header_1: {- size: 10,- padding_bottom: 4- },- header_2: {- size: 10- },- header_3: {- size: 9- },- page: {- size: 10,- leading: 3- },- paragraph: {- align: 'left'- },- unordered_list: {- spacing: 1- },- unordered_list_point: {- spacing: 4- },- ordered_list: {- spacing: 1- },- ordered_list_point: {- spacing: 4- },- task_list: {- spacing: 1- },- task_list_point: {- spacing: 4,- checked: '☑', # fallback font is needed- unchecked: '☐' # fallback font is needed- },- link: {- styles: ['underline']- },- code: {- color: '880000',- size: 9,- font: 'SpaceMono'- },- blockquote: {- background_color: 'f4f9ff',- size: 10,- styles: ['italic'],- color: '0f3b66',- border_color: 'b8d6f4',- border_width: 1,- padding: 4,- padding_left: 6,- margin_top: 4,- margin_bottom: 4,- no_border_left: false,- no_border_right: true,- no_border_bottom: true,- no_border_top: true- },- image: {- align: 'left'- },- codeblock: {- background_color: 'F5F5F5',- color: '880000',- padding: '3mm',- size: 8,- margin_top: '2mm',- margin_bottom: '2mm',- font: 'SpaceMono'- },- table: {- auto_width: true,- margin_top: 4,- margin_bottom: 4,- header: {- size: 9,- styles: ['bold'],- background_color: 'F0F0F0'- },- cell: {- size: 9,- border_width: '0.25mm',- padding: 5- }- }- }- # rubocop:enable Naming/VariableNumber- end-def attachment_image_filepath(work_package, src)# images are embedded into markup with the api-path as img.srcattachment = attachment_by_api_content_src(work_package, src)diff --git a/app/models/work_package/pdf_export/markdown_field.rb b/app/models/work_package/pdf_export/markdown_field.rbindex a8e3c008d37..89f9ceb4128 100644--- a/app/models/work_package/pdf_export/markdown_field.rb+++ b/app/models/work_package/pdf_export/markdown_field.rb@@ -32,14 +32,8 @@ module WorkPackage::PDFExport::MarkdownFielddef write_markdown_field!(work_package, markdown, label)return if markdown.blank?- with_margin(margins_style) do- write_markdown! work_package, "# <font size=\"12\">#{label}</font>\n\n#{markdown}"+ with_margin(wp_markdown_field_margins_style) do+ write_markdown! work_package, "# <font size=\"#{wp_markdown_field_label_size}\">#{label}</font>\n\n#{markdown}"endend-- private-- def margins_style- { margin_top: 12, margin_bottom: 8 }- endenddiff --git a/app/models/work_package/pdf_export/overview_table.rb b/app/models/work_package/pdf_export/overview_table.rbindex 67de15cb73c..cc432b60308 100644--- a/app/models/work_package/pdf_export/overview_table.rb+++ b/app/models/work_package/pdf_export/overview_table.rb@@ -175,42 +175,4 @@ module WorkPackage::PDFExport::OverviewTablesum_row[0] = 'Sum' # TODO: I18n and in which column should the sum text besum_rowend-- def overview_group_header_style- { size: 11, styles: [:bold] }- end-- def overview_group_header_margins_style- { margin_bottom: 4 }- end-- def overview_table_margins_style- { margin_top: 20, margin_bottom: 0, margin_left: 0, margin_right: 0 }- end-- def overview_table_header_cell_style- { size: 9, text_color: "000000", font_style: :bold,- padding_left: 5, padding_right: 5, padding_top: 0, padding_bottom: 5 }- end-- def overview_table_sums_cell_style- { size: 8, text_color: "000000", font_style: :bold }- end-- def overview_table_subject_indent_style- 8- end-- def overview_table_cell_padding_style- { padding_left: 5,- padding_right: 5,- padding_top: 0,- padding_bottom: 5 }- end-- def overview_table_cell_style- { size: 9,- text_color: "000000",- border_widths: [0.25, 0.25, 0.25, 0.25] }- endenddiff --git a/app/models/work_package/pdf_export/page.rb b/app/models/work_package/pdf_export/page.rbindex 0c1a147f682..89770784bfd 100644--- a/app/models/work_package/pdf_export/page.rb+++ b/app/models/work_package/pdf_export/page.rb@@ -1,6 +1,34 @@+#-- copyright+# OpenProject is an open source project management software.+# Copyright (C) 2012-2023 the OpenProject GmbH+#+# This program is free software; you can redistribute it and/or+# modify it under the terms of the GNU General Public License version 3.+#+# OpenProject is a fork of ChiliProject, which is a fork of Redmine. The copyright follows:+# Copyright (C) 2006-2013 Jean-Philippe Lang+# Copyright (C) 2010-2013 the ChiliProject Team+#+# This program is free software; you can redistribute it and/or+# modify it under the terms of the GNU General Public License+# as published by the Free Software Foundation; either version 2+# of the License, or (at your option) any later version.+#+# This program is distributed in the hope that it will be useful,+# but WITHOUT ANY WARRANTY; without even the implied warranty of+# MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the+# GNU General Public License for more details.+#+# You should have received a copy of the GNU General Public License+# along with this program; if not, write to the Free Software+# Foundation, Inc., 51 Franklin Street, Fifth Floor, Boston, MA 02110-1301, USA.+#+# See COPYRIGHT and LICENSE files for more details.+#+++module WorkPackage::PDFExport::Pagedef configure_page_size!(layout)- pdf.options[:page_size] = 'EXECUTIVE' # TODO: 'A4'?+ pdf.options[:page_size] = page_sizepdf.options[:page_layout] = layoutpdf.options[:top_margin] = page_top_marginpdf.options[:bottom_margin] = page_bottom_margin@@ -9,8 +37,16 @@ module WorkPackage::PDFExport::Pagedef write_logo!image_obj, image_info, scale = logo_pdf_imagepdf.repeat :all do- top = pdf.bounds.top + page_header_top + (logo_height / 2)- pdf.embed_image image_obj, image_info, { at: [0, top], scale: }+ top = pdf.bounds.top + page_header_top + (page_logo_height / 2)+ left = case page_logo_align+ when :middle+ ((pdf.bounds.right - pdf.bounds.left) - (image_info.width.to_f * scale)) / 2+ when :right+ pdf.bounds.right - (image_info.width.to_f * scale)+ else+ 0 # :left+ end+ pdf.embed_image image_obj, image_info, { at: [left, top], scale: }endend@@ -18,7 +54,7 @@ module WorkPackage::PDFExport::Pageimage_file = custom_logo_imageimage_file = Rails.root.join("app/assets/images/logo_openproject.png") if image_file.nil?image_obj, image_info = pdf.build_image_object(image_file)- scale = [logo_height / image_info.height.to_f, 1].min+ scale = [page_logo_height / image_info.height.to_f, 1].min[image_obj, image_info, scale]end@@ -35,17 +71,13 @@ module WorkPackage::PDFExport::Pagedef write_title!pdf.title = heading- pdf.formatted_text([page_heading_style.merge({ text: heading })])+ with_margin(page_heading_margins_style) do+ pdf.formatted_text([page_heading_style.merge({ text: heading })])+ endenddef write_headers!write_logo!- write_header_user!(User.current) unless User.current.nil?- end-- def write_header_user!(user)- draw_repeating_text("#{user.firstname} #{user.lastname}",- :right, pdf.bounds.top + logo_height, page_header_style)enddef write_footers!@@ -71,36 +103,4 @@ module WorkPackage::PDFExport::Pagedef write_footer_date!draw_repeating_text(format_date(Time.zone.today), :left, -page_footer_top, page_footer_style)end-- def page_header_top- 20- end-- def page_bottom_margin- 60- end-- def page_footer_top- 30- end-- def logo_height- 20- end-- def page_top_margin- 60- end-- def page_heading_style- { size: 14, styles: [:bold] }- end-- def page_header_style- { size: 8, style: :normal }- end-- def page_footer_style- { size: 8, style: :normal }- endenddiff --git a/app/models/work_package/pdf_export/style.rb b/app/models/work_package/pdf_export/style.rbnew file mode 100644index 00000000000..8f23e031049--- /dev/null+++ b/app/models/work_package/pdf_export/style.rb@@ -0,0 +1,277 @@+#-- copyright+# OpenProject is an open source project management software.+# Copyright (C) 2012-2023 the OpenProject GmbH+#+# This program is free software; you can redistribute it and/or+# modify it under the terms of the GNU General Public License version 3.+#+# OpenProject is a fork of ChiliProject, which is a fork of Redmine. The copyright follows:+# Copyright (C) 2006-2013 Jean-Philippe Lang+# Copyright (C) 2010-2013 the ChiliProject Team+#+# This program is free software; you can redistribute it and/or+# modify it under the terms of the GNU General Public License+# as published by the Free Software Foundation; either version 2+# of the License, or (at your option) any later version.+#+# This program is distributed in the hope that it will be useful,+# but WITHOUT ANY WARRANTY; without even the implied warranty of+# MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the+# GNU General Public License for more details.+#+# You should have received a copy of the GNU General Public License+# along with this program; if not, write to the Free Software+# Foundation, Inc., 51 Franklin Street, Fifth Floor, Boston, MA 02110-1301, USA.+#+# See COPYRIGHT and LICENSE files for more details.+#++++module WorkPackage::PDFExport::Style+ def page_size+ 'EXECUTIVE' # TODO: 'A4'?+ end++ def page_header_top+ 20+ end++ def page_bottom_margin+ 60+ end++ def page_footer_top+ 30+ end++ def page_logo_height+ 20+ end++ def page_logo_align+ :right+ end++ def page_top_margin+ 60+ end++ def page_heading_style+ { size: 14, styles: [:bold] }+ end++ def page_heading_margins_style+ { margin_bottom: 10 }+ end++ def page_header_style+ { size: 8, style: :normal }+ end++ def page_footer_style+ { size: 8, style: :normal }+ end++ def overview_table_link_color+ '175A8E'+ end++ def overview_group_header_style+ { size: 11, styles: [:bold] }+ end++ def overview_group_header_margins_style+ { margin_bottom: 20 }+ end++ def overview_table_margins_style+ { margin_bottom: 20, margin_left: 0, margin_right: 0 }+ end++ def overview_table_header_cell_style+ { size: 9, text_color: "000000", font_style: :bold,+ padding_left: 5, padding_right: 5, padding_top: 0, padding_bottom: 5 }+ end++ def overview_table_sums_cell_style+ { size: 8, text_color: "000000", font_style: :bold }+ end++ def overview_table_subject_indent_style+ 8+ end++ def overview_table_cell_padding_style+ { padding_left: 5,+ padding_right: 5,+ padding_top: 0,+ padding_bottom: 5 }+ end++ def overview_table_cell_style+ { size: 9,+ text_color: "000000",+ border_widths: [0.25, 0.25, 0.25, 0.25] }+ end++ def wp_headline_margins_style+ { margin_top: 4, margin_bottom: 4 }+ end++ def wp_headline_style+ { size: 9, styles: [:bold] }+ end++ def wp_item_margins_style+ { margin_left: 10 }+ end++ def wp_item_style+ { size: 9, styles: [:italic] }+ end++ def wp_label_margins_style+ { margin_top: 12, margin_bottom: 8 }+ end++ def wp_label_style+ { size: 11, styles: [:bold] }+ end++ def wp_detail_margins_style+ { margin_bottom: 20 }+ end++ def wp_detail_subject_margins_style+ { margin_bottom: 4 }+ end++ def wp_detail_subject_font_style+ { size: 14, styles: [:bold] }+ end++ def wp_attributes_table_margins_style+ { margin_top: 4, margin_bottom: 2 }+ end++ def wp_attributes_table_label_font_style+ { font_style: :bold }+ end++ def wp_attributes_table_cell_style+ { size: 9,+ text_color: "000000",+ border_widths: [0.25, 0.25, 0.25, 0.25],+ padding_left: 5,+ padding_right: 5,+ padding_top: 0,+ padding_bottom: 4 }+ end++ def wp_markdown_field_label_size+ 12+ end++ def wp_markdown_field_margins_style+ { margin_top: 12, margin_bottom: 8 }+ end++ def markdown_styling_yml+ # rubocop:disable Naming/VariableNumber+ {+ header: {+ size: 8,+ styles: [:bold]+ },+ header_1: {+ size: 10,+ padding_bottom: 4+ },+ header_2: {+ size: 10+ },+ header_3: {+ size: 9+ },+ page: {+ size: 10,+ leading: 3+ },+ paragraph: {+ align: 'left'+ },+ unordered_list: {+ spacing: 1+ },+ unordered_list_point: {+ spacing: 4+ },+ ordered_list: {+ spacing: 1+ },+ ordered_list_point: {+ spacing: 4+ },+ task_list: {+ spacing: 1+ },+ task_list_point: {+ spacing: 4,+ checked: '☑', # fallback font is needed+ unchecked: '☐' # fallback font is needed+ },+ link: {+ color: '175A8E',+ styles: []+ },+ code: {+ color: '880000',+ size: 9,+ font: 'SpaceMono'+ },+ blockquote: {+ background_color: 'f4f9ff',+ size: 10,+ styles: ['italic'],+ color: '0f3b66',+ border_color: 'b8d6f4',+ border_width: 1,+ padding: 4,+ padding_left: 6,+ margin_top: 4,+ margin_bottom: 4,+ no_border_left: false,+ no_border_right: true,+ no_border_bottom: true,+ no_border_top: true+ },+ image: {+ align: 'left'+ },+ codeblock: {+ background_color: 'F5F5F5',+ color: '880000',+ padding: '3mm',+ size: 8,+ margin_top: '2mm',+ margin_bottom: '2mm',+ font: 'SpaceMono'+ },+ table: {+ auto_width: true,+ margin_top: 4,+ margin_bottom: 4,+ header: {+ size: 9,+ styles: ['bold'],+ background_color: 'F0F0F0'+ },+ cell: {+ size: 9,+ border_width: '0.25mm',+ padding: 5+ }+ }+ }+ # rubocop:enable Naming/VariableNumber+ end+enddiff --git a/app/models/work_package/pdf_export/work_package_detail.rb b/app/models/work_package/pdf_export/work_package_detail.rbindex 4bea5a4a103..e89c076dead 100644--- a/app/models/work_package/pdf_export/work_package_detail.rb+++ b/app/models/work_package/pdf_export/work_package_detail.rb@@ -39,7 +39,7 @@ module WorkPackage::PDFExport::WorkPackageDetaildef write_work_package_detail!(work_package, level_path)# TODO: move page break threshold const to style settings and implement conditional break with height measuringwrite_optional_page_break(200)- with_margin(detail_margins_style) do+ with_margin(wp_detail_margins_style) dowrite_work_package_subject! work_package, level_pathwrite_work_package_detail_content! work_packageend@@ -54,11 +54,11 @@ module WorkPackage::PDFExport::WorkPackageDetailprivatedef write_work_package_subject!(work_package, level_path)- with_margin(subject_margins_style) do+ with_margin(wp_detail_subject_margins_style) dolink_target_at_current_y(work_package.id)level_string_width = write_work_package_level!(level_path)title = get_column_value work_package, :subject- @pdf.indent(level_string_width) { pdf.formatted_text([subject_font_style.merge({ text: title })]) }+ @pdf.indent(level_string_width) { pdf.formatted_text([wp_detail_subject_font_style.merge({ text: title })]) }endend@@ -66,18 +66,18 @@ module WorkPackage::PDFExport::WorkPackageDetailreturn 0 if level_path.empty?level_string = "#{level_path.join('.')}. "- level_string_width = measure_text_width(level_string, subject_font_style)- @pdf.float { @pdf.formatted_text([subject_font_style.merge({ text: level_string })]) }+ level_string_width = measure_text_width(level_string, wp_detail_subject_font_style)+ @pdf.float { @pdf.formatted_text([wp_detail_subject_font_style.merge({ text: level_string })]) }level_string_widthenddef write_attributes_table!(work_package)rows = build_attributes_table_rows work_package- with_margin(attributes_table_margins_style) do+ with_margin(wp_attributes_table_margins_style) dopdf.table(rows,column_widths: attributes_table_column_widths,- cell_style: attributes_table_cell_style.merge({ inline_format: true })+ cell_style: wp_attributes_table_cell_style.merge({ inline_format: true }))endend@@ -117,7 +117,7 @@ module WorkPackage::PDFExport::WorkPackageDetaillabel = (WorkPackage.human_attribute_name(attribute) || '').upcase[- pdf.make_cell(label, attributes_table_label_font_style),+ pdf.make_cell(label, wp_attributes_table_label_font_style),get_column_value_cell(work_package, attribute.to_sym)]end@@ -133,34 +133,4 @@ module WorkPackage::PDFExport::WorkPackageDetailwrite_markdown_field!(work_package, custom_value.value, custom_value.custom_field.name)endend-- def detail_margins_style- { margin_top: 20 }- end-- def subject_margins_style- { margin_bottom: 4 }- end-- def subject_font_style- { size: 14, styles: [:bold] }- end-- def attributes_table_margins_style- { margin_top: 4, margin_bottom: 2 }- end-- def attributes_table_label_font_style- { font_style: :bold }- end-- def attributes_table_cell_style- { size: 9,- text_color: "000000",- border_widths: [0.25, 0.25, 0.25, 0.25],- padding_left: 5,- padding_right: 5,- padding_top: 0,- padding_bottom: 4 }- endenddiff --git a/app/models/work_package/pdf_export/work_package_list_to_pdf.rb b/app/models/work_package/pdf_export/work_package_list_to_pdf.rbindex 5f8a53027e4..9b27b6055b0 100644--- a/app/models/work_package/pdf_export/work_package_list_to_pdf.rb+++ b/app/models/work_package/pdf_export/work_package_list_to_pdf.rb@@ -37,7 +37,7 @@# grow beyond limits. Therefore we create multiple smaller PDFs that we finally# merge do one file.-require 'hexapdf'+# require 'hexapdf'require 'open3'class WorkPackage::PDFExport::WorkPackageListToPdf < WorkPackage::Exports::QueryExporter@@ -46,6 +46,7 @@ class WorkPackage::PDFExport::WorkPackageListToPdf < WorkPackage::Exports::Queryinclude WorkPackage::PDFExport::OverviewTableinclude WorkPackage::PDFExport::WorkPackageDetailinclude WorkPackage::PDFExport::Page+ include WorkPackage::PDFExport::Styleattr_accessor :pdf,:options@@ -231,5 +232,4 @@ class WorkPackage::PDFExport::WorkPackageListToPdf < WorkPackage::Exports::Querytitleendend-enddiff --git a/app/models/work_package/pdf_export/work_package_to_pdf.rb b/app/models/work_package/pdf_export/work_package_to_pdf.rbindex ceeb989cbc9..69bd011dbf6 100644--- a/app/models/work_package/pdf_export/work_package_to_pdf.rb+++ b/app/models/work_package/pdf_export/work_package_to_pdf.rb@@ -31,6 +31,7 @@ class WorkPackage::PDFExport::WorkPackageToPdf < Exports::Exporterinclude WorkPackage::PDFExport::Attachmentsinclude WorkPackage::PDFExport::WorkPackageDetailinclude WorkPackage::PDFExport::Page+ include WorkPackage::PDFExport::Styleattr_accessor :pdf, :columns@@ -99,13 +100,13 @@ class WorkPackage::PDFExport::WorkPackageToPdf < Exports::Exporterdef write_history_item_headline!(journal)headline = "#{format_time(journal.created_at)} - #{journal.user.name}"- with_margin(headline_margins_style) do- pdf.formatted_text([headline_style.merge({ text: headline })])+ with_margin(wp_headline_margins_style) do+ pdf.formatted_text([wp_headline_style.merge({ text: headline })])endenddef write_history_item_content!(journal)- with_margin(item_margins_style) do+ with_margin(wp_item_margins_style) dojournal.details.each do |detail|text = journal.render_detail(detail, html: true, only_path: false)write_markdown! work_package, "* #{text}"@@ -126,8 +127,8 @@ class WorkPackage::PDFExport::WorkPackageToPdf < Exports::Exporterenddef write_label!(label)- with_margin(label_margins_style) do- pdf.formatted_text([label_style.merge({ text: label })])+ with_margin(wp_label_margins_style) do+ pdf.formatted_text([wp_label_style.merge({ text: label })])endend@@ -138,40 +139,16 @@ class WorkPackage::PDFExport::WorkPackageToPdf < Exports::Exporterdef write_changeset_item_headline!(changeset)headline = "#{format_time(changeset.committed_on)} - #{changeset.author}"- with_margin(headline_margins_style) do- pdf.formatted_text([headline_style.merge({ text: headline })])+ with_margin(wp_headline_margins_style) do+ pdf.formatted_text([wp_headline_style.merge({ text: headline })])endenddef write_changeset_item_content!(changeset)if changeset.comments.present?- with_margin(item_margins_style) do- pdf.formatted_text([headline_style.merge({ text: changeset.comments.to_s })])+ with_margin(wp_item_margins_style) do+ pdf.formatted_text([wp_headline_style.merge({ text: changeset.comments.to_s })])endendend-- def headline_margins_style- { margin_top: 4, margin_bottom: 4 }- end-- def headline_style- { size: 9, styles: [:bold] }- end-- def item_margins_style- { margin_left: 10 }- end-- def item_style- { size: 9, styles: [:italic] }- end-- def label_margins_style- { margin_top: 12, margin_bottom: 8 }- end-- def label_style- { size: 11, styles: [:bold] }- endend