Feature #44362 » 0001-Preview-Adobe-Illustrator-files-saved-in-the-PDF-com.patch
| app/controllers/attachments_controller.rb | ||
|---|---|---|
| 58 | 58 |
render :action => 'diff' |
| 59 | 59 |
elsif @attachment.is_image? |
| 60 | 60 |
render :action => 'image' |
| 61 |
elsif @attachment.is_pdf?
|
|
| 61 |
elsif @attachment.pdf_previewable?
|
|
| 62 | 62 |
render :action => 'pdf' |
| 63 | 63 |
elsif @attachment.is_text? && @attachment.filesize <= Setting.file_max_size_displayed.to_i.kilobyte |
| 64 | 64 |
@content = File.read(@attachment.diskfile, :mode => "rb") |
| ... | ... | |
| 299 | 299 |
content_type = |
| 300 | 300 |
Redmine::MimeType.of(attachment.filename).presence || |
| 301 | 301 |
"application/octet-stream" |
| 302 |
elsif Marcel::Magic.child?(content_type, "application/pdf") |
|
| 303 |
# Send PDF compatible files, such as Illustrator files, as PDF so that |
|
| 304 |
# browsers display them inline |
|
| 305 |
content_type = "application/pdf" |
|
| 302 | 306 |
end |
| 303 | 307 |
if is_thumb && !content_type.start_with?("image/")
|
| app/models/attachment.rb | ||
|---|---|---|
| 326 | 326 |
Redmine::MimeType.of(filename) == "application/pdf" |
| 327 | 327 |
end |
| 328 |
# Returns true for attachments that can be previewed as PDF files, |
|
| 329 |
# including PDF compatible files such as Adobe Illustrator |
|
| 330 |
# (application/illustrator) |
|
| 331 |
def pdf_previewable? |
|
| 332 |
if content_type.blank? || content_type == 'application/octet-stream' |
|
| 333 |
# The type of attachments created before Redmine started detecting the |
|
| 334 |
# content type from the file contents can only be guessed from the name |
|
| 335 |
is_pdf? |
|
| 336 |
else |
|
| 337 |
!!Marcel::Magic.child?(content_type, 'application/pdf') |
|
| 338 |
end |
|
| 339 |
end |
|
| 340 | ||
| 328 | 341 |
def is_video? |
| 329 | 342 |
Redmine::MimeType.is_type?('video', filename)
|
| 330 | 343 |
end |
| test/functional/attachments_controller_test.rb | ||
|---|---|---|
| 406 | 406 |
assert_match %r{\Aattachment}, @response.headers['Content-Disposition']
|
| 407 | 407 |
end |
| 408 |
def test_show_pdf_compatible_illustrator_file_should_be_previewed |
|
| 409 |
set_tmp_attachments_directory |
|
| 410 |
attachment = Attachment.create!( |
|
| 411 |
:file => mock_file_with_options( |
|
| 412 |
:original_filename => 'logo.ai', |
|
| 413 |
:content => File.binread("#{Rails.root}/test/fixtures/files/hello.pdf")
|
|
| 414 |
), |
|
| 415 |
:author_id => 2, |
|
| 416 |
:container => Issue.find(1) |
|
| 417 |
) |
|
| 418 |
assert_equal 'application/illustrator', attachment.content_type |
|
| 419 | ||
| 420 |
get(:show, :params => {:id => attachment.id})
|
|
| 421 |
assert_response :success |
|
| 422 |
assert_select 'div.filecontent.pdf object[type=?]', 'application/pdf' |
|
| 423 |
end |
|
| 424 | ||
| 425 |
def test_download_pdf_compatible_illustrator_file_should_be_sent_inline_as_pdf |
|
| 426 |
set_tmp_attachments_directory |
|
| 427 |
attachment = Attachment.create!( |
|
| 428 |
:file => mock_file_with_options( |
|
| 429 |
:original_filename => 'logo.ai', |
|
| 430 |
:content => File.binread("#{Rails.root}/test/fixtures/files/hello.pdf")
|
|
| 431 |
), |
|
| 432 |
:author_id => 2, |
|
| 433 |
:container => Issue.find(1) |
|
| 434 |
) |
|
| 435 | ||
| 436 |
get(:download, :params => {:id => attachment.id})
|
|
| 437 |
assert_response :success |
|
| 438 |
# Sent as PDF so that browsers display it inline |
|
| 439 |
assert_equal 'application/pdf', @response.media_type |
|
| 440 |
assert_match %r{\Ainline}, @response.headers['Content-Disposition']
|
|
| 441 |
end |
|
| 442 | ||
| 408 | 443 |
def test_download_version_file_with_issue_tracking_disabled |
| 409 | 444 |
Project.find(1).disable_module! :issue_tracking |
| 410 | 445 |
get(:download, :params => {:id => 9})
|
| test/unit/attachment_test.rb | ||
|---|---|---|
| 838 | 838 |
assert_equal expected, Attachment.new(:filename => filename).is_pdf?, filename |
| 839 | 839 |
end |
| 840 | 840 |
end |
| 841 | ||
| 842 |
def test_pdf_previewable |
|
| 843 |
to_test = {
|
|
| 844 |
['application/pdf', 'report.pdf'] => true, |
|
| 845 |
# PDF compatible Illustrator files are detected as application/illustrator |
|
| 846 |
['application/illustrator', 'logo.ai'] => true, |
|
| 847 |
# Illustrator files saved in the PostScript format are not PDF files |
|
| 848 |
['application/postscript', 'logo.ai'] => false, |
|
| 849 |
# The type of attachments created before Redmine started detecting the |
|
| 850 |
# content type from the file contents can only be guessed from the name |
|
| 851 |
['application/octet-stream', 'report.pdf'] => true, |
|
| 852 |
['application/octet-stream', 'logo.ai'] => false, |
|
| 853 |
} |
|
| 854 |
to_test.each do |(content_type, filename), expected| |
|
| 855 |
attachment = Attachment.new(:content_type => content_type, :filename => filename) |
|
| 856 |
assert_equal expected, attachment.pdf_previewable?, "#{content_type} (#{filename})"
|
|
| 857 |
end |
|
| 858 |
end |
|
| 841 | 859 |
end |