Skip to content

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

feat(logo): use CustomStyle.current.logo if defined

as-op8f6050aa10d2
diff --git a/app/models/work_package/pdf_export/attachments.rb b/app/models/work_package/pdf_export/attachments.rb
index 682f6d0816f..5639c525a74 100644
--- a/app/models/work_package/pdf_export/attachments.rb
+++ b/app/models/work_package/pdf_export/attachments.rb
@@ -48,8 +48,8 @@ module WorkPackage::PDFExport::Attachments
File.join(dir_path, "#{file_name}#{name_suffix}#{file_extension}")
end
- def pdf_embeddable?(attachment)
- %w[image/jpeg image/png].include?(attachment.content_type)
+ def pdf_embeddable?(content_type)
+ %w[image/jpeg image/png].include?(content_type)
end
def delete_all_resized_images
diff --git a/app/models/work_package/pdf_export/markdown.rb b/app/models/work_package/pdf_export/markdown.rb
index 069afcdffee..802446e8dd4 100644
--- a/app/models/work_package/pdf_export/markdown.rb
+++ b/app/models/work_package/pdf_export/markdown.rb
@@ -207,7 +207,7 @@ module WorkPackage::PDFExport::Markdown
def attachment_image_filepath(work_package, src)
# images are embedded into markup with the api-path as img.src
attachment = attachment_by_api_content_src(work_package, src)
- return nil if attachment.nil? || attachment.file.local_file.nil? || !pdf_embeddable?(attachment)
+ return nil if attachment.nil? || attachment.file.local_file.nil? || !pdf_embeddable?(attachment.content_type)
resize_image(attachment.file.local_file.path)
end
diff --git a/app/models/work_package/pdf_export/page.rb b/app/models/work_package/pdf_export/page.rb
index 003997e359c..eb810d73abf 100644
--- a/app/models/work_package/pdf_export/page.rb
+++ b/app/models/work_package/pdf_export/page.rb
@@ -15,12 +15,23 @@ module WorkPackage::PDFExport::Page
end
def logo_pdf_image
- image_file = Rails.root.join("app/assets/images/logo_openproject.png")
+ image_file = custom_logo_image
+ image_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
[image_obj, image_info, scale]
end
+ def custom_logo_image
+ return unless CustomStyle.current.logo.present? && CustomStyle.current.logo.local_file.present?
+
+ image_file = CustomStyle.current.logo.local_file.path
+ content_type = OpenProject::ContentTypeDetector.new(image_file).detect
+ return unless pdf_embeddable?(content_type)
+
+ image_file
+ end
+
def write_title!
pdf.title = heading
pdf.formatted_text([page_heading_style.merge({ text: heading })])