diff --git a/CHANGELOG.adoc b/CHANGELOG.adoc index 68b5affe5..9a4e28251 100644 --- a/CHANGELOG.adoc +++ b/CHANGELOG.adoc @@ -40,6 +40,9 @@ Improvements:: * refactor formatted text transform to simplify how inner space is collapsed; verify only inner hard breaks are preserved * allow relative font size for sub and sup to be set independently; support combined setting for backwards compatibility * don't hyphenate autolink when hyphenation is enabled (#2521) (*@meonkeys*) +* always use /Producer field in document info to credit Asciidoctor PDF and Prawn, even when author is set (#2510) +* map `publisher` attribute to /Creator field instead of /Producer field in document info; use author as fallback (#2510) +* map `producer` attribute to /Producer field in document info to override or default value (#2510) Bug Fixes:: diff --git a/lib/asciidoctor/pdf/converter.rb b/lib/asciidoctor/pdf/converter.rb index a53c26077..f0e9c7c61 100644 --- a/lib/asciidoctor/pdf/converter.rb +++ b/lib/asciidoctor/pdf/converter.rb @@ -531,13 +531,12 @@ def build_pdf_info doc end info[:Subject] = (sanitize doc.attr 'subject').as_pdf if doc.attr? 'subject' info[:Keywords] = (sanitize doc.attr 'keywords').as_pdf if doc.attr? 'keywords' - info[:Producer] = (sanitize doc.attr 'publisher').as_pdf if doc.attr? 'publisher' + info[:Creator] = (doc.attr? 'publisher') ? (sanitize doc.attr 'publisher').as_pdf : (info[:Author] || '') + info[:Producer] = (sanitize doc.attr 'producer').as_pdf if doc.attr? 'producer' if doc.attr? 'reproducible' - info[:Creator] = 'Asciidoctor PDF, based on Prawn'.as_pdf - info[:Producer] ||= (info[:Author] || info[:Creator]) + info[:Producer] ||= 'Asciidoctor PDF, based on Prawn'.as_pdf else - info[:Creator] = %(Asciidoctor PDF #{::Asciidoctor::PDF::VERSION}, based on Prawn #{::Prawn::VERSION}).as_pdf - info[:Producer] ||= (info[:Author] || info[:Creator]) + info[:Producer] ||= %(Asciidoctor PDF #{::Asciidoctor::PDF::VERSION}, based on Prawn #{::Prawn::VERSION}).as_pdf # NOTE: since we don't track the creation date of the input file, we map the ModDate header to the last modified # date of the input document and the CreationDate header to the date the PDF was produced by the converter. info[:ModDate] = (::Time.parse doc.attr 'docdatetime') rescue (now ||= ::Time.now) diff --git a/spec/pdf_info_spec.rb b/spec/pdf_info_spec.rb index 1dce42734..91d6e881b 100644 --- a/spec/pdf_info_spec.rb +++ b/spec/pdf_info_spec.rb @@ -18,20 +18,42 @@ end context 'attribution' do - it 'should include Asciidoctor PDF and Prawn versions in Creator field' do + it 'should set the Creator field to empty by default' do creator = (to_pdf 'hello').info[:Creator] - (expect creator).not_to be_nil - (expect creator).to include %(Asciidoctor PDF #{Asciidoctor::PDF::VERSION}) - (expect creator).to include %(Prawn #{Prawn::VERSION}) + (expect creator).to be_empty end - it 'should set Producer field to value of Creator field by default' do - pdf = to_pdf 'hello' - (expect pdf.info[:Producer]).not_to be_nil - (expect pdf.info[:Producer]).to eql pdf.info[:Creator] + it 'should set the Producer field to Asciidoctor PDF and Prawn by default' do + producer = (to_pdf 'hello').info[:Producer] + (expect producer).not_to be_nil + (expect producer).to include %(Asciidoctor PDF #{Asciidoctor::PDF::VERSION}) + (expect producer).to include %(Prawn #{Prawn::VERSION}) end - it 'should set Author and Producer field to value of author attribute if set' do + it 'should allow Producer field to be overridden using producer attribute' do + pdf = to_pdf <<~'END' + = Document Title + :producer: ACME + + hello + END + producer = pdf.info[:Producer] + (expect producer).not_to be_nil + (expect producer).to eql 'ACME' + end + + it 'should set the Creator field to the author if author is specified' do + pdf = to_pdf <<~'END' + = Document Title + Author Name + + hello + END + creator = pdf.info[:Creator] + (expect creator).to eql 'Author Name' + end + + it 'should set Author and Creator field to value of author attribute if set' do ['Author Name', ':author: Author Name'].each do |author_line| pdf = to_pdf <<~END = Document Title @@ -39,12 +61,12 @@ content END - (expect pdf.info[:Producer]).to eql pdf.info[:Author] (expect pdf.info[:Author]).to eql 'Author Name' + (expect pdf.info[:Creator]).to eql pdf.info[:Author] end end - it 'should set Author and Producer field to value of author attribute if set to multiple authors' do + it 'should set Author and Creator field to value of author attribute if set to multiple authors' do ['Author Name; Assistant Name', ':authors: Author Name; Assistant Name'].each do |author_line| pdf = to_pdf <<~END = Document Title @@ -55,14 +77,14 @@ Second Author: {author_2} END lines = ((pdf.page 1).text.split ?\n).map(&:strip) - (expect pdf.info[:Producer]).to eql pdf.info[:Author] (expect pdf.info[:Author]).to eql 'Author Name, Assistant Name' + (expect pdf.info[:Creator]).to eql pdf.info[:Author] (expect lines).to include 'First Author: Author Name' (expect lines).to include 'Second Author: Assistant Name' end end - it 'should set Author and Producer field using authors attribute with non-Latin characters' do + it 'should set Author and Creator field using authors attribute with non-Latin characters' do ['Doc Writer; Antonín Dvořák', ':authors: Doc Writer; Antonín Dvořák'].each do |author_line| pdf = to_pdf <<~END = Document Title @@ -73,8 +95,8 @@ Second Author: {author_2} END lines = ((pdf.page 1).text.split ?\n).map(&:strip) - (expect pdf.info[:Producer]).to eql pdf.info[:Author] (expect pdf.info[:Author]).to eql 'Doc Writer, Antonín Dvořák' + (expect pdf.info[:Creator]).to eql pdf.info[:Author] (expect lines).to include 'First Author: Doc Writer' (expect lines).to include 'Second Author: Antonín Dvořák' end @@ -132,7 +154,7 @@ (expect pdf.info[:Author]).to eql 'Author Name' end - it 'should set Producer field to value of publisher attribute if set' do + it 'should set Creator field to value of publisher attribute if set' do pdf = to_pdf <<~'END' = Document Title Author Name @@ -141,7 +163,7 @@ content END (expect pdf.info[:Author]).to eql 'Author Name' - (expect pdf.info[:Producer]).to eql 'Big Cheese' + (expect pdf.info[:Creator]).to eql 'Big Cheese' end it 'should set Subject field to value of subject attribute if set' do @@ -179,7 +201,7 @@ (expect pdf_info[:Author]).to eql 'D_J Allen' (expect pdf_info[:Subject]).to eql 'Science & Math' (expect pdf_info[:Keywords]).to eql 'mass–energy equivalence' - (expect pdf_info[:Producer]).to eql 'Schrödinger’s Cat' + (expect pdf_info[:Creator]).to eql 'Schrödinger’s Cat' end it 'should parse date attributes as local date objects' do @@ -239,7 +261,7 @@ content END - (expect pdf.info[:Creator]).to eql 'Asciidoctor PDF, based on Prawn' + (expect pdf.info[:Producer]).to eql 'Asciidoctor PDF, based on Prawn' end it 'should set mod and creation dates to match SOURCE_DATE_EPOCH environment variable' do