Skip to content

Commit

Permalink
resolves asciidoctor#1334 fix value of implicit page-count attribute
Browse files Browse the repository at this point in the history
- handle case when page numbering and running content don't start on same page
  • Loading branch information
mojavelinux committed Oct 18, 2019
1 parent 1dfd1d6 commit 115267d
Show file tree
Hide file tree
Showing 3 changed files with 58 additions and 1 deletion.
1 change: 1 addition & 0 deletions CHANGELOG.adoc
Original file line number Diff line number Diff line change
Expand Up @@ -7,6 +7,7 @@ For a detailed view of what has changed, refer to the {uri-repo}/commits/master[

== Unreleased

* fix value of implicit page-count attribute when page numbering and running content don't start on same page (#1334)
* set default footer content in base theme; remove logic to process `footer_<side>_content: none` key (#1320)
* include doctitle in outline for article when article is only a single page (#1322)
* allow custom (inline) role to control text decoration property (#1326)
Expand Down
2 changes: 1 addition & 1 deletion lib/asciidoctor/pdf/converter.rb
Original file line number Diff line number Diff line change
Expand Up @@ -3044,7 +3044,7 @@ def layout_running_content periphery, doc, opts = {}
# NOTE find and advance to first non-imported content page to use as model page
return unless (content_start_page = state.pages[skip..-1].index {|it| !it.imported_page? })
content_start_page += (skip + 1)
num_pages = page_count - skip
num_pages = page_count - skip_pagenums
prev_page_number = page_number
go_to_page content_start_page

Expand Down
56 changes: 56 additions & 0 deletions spec/running_content_spec.rb
Original file line number Diff line number Diff line change
Expand Up @@ -489,6 +489,62 @@
end
(expect pgnum_labels).to eq %w(1 2 3 4)
end

it 'should compute page-count attribute correctly when running content starts after page numbering' do
pdf_theme = {
page_numbering_start_at: 'toc',
running_content_start_at: 'body',
footer_recto_right_content: '{page-number} of {page-count}',
footer_verso_left_content: '{page-number} of {page-count}',
footer_font_color: 'AA0000',
}

pdf = to_pdf <<~'EOS', attribute_overrides: { 'nofooter' => nil }, pdf_theme: pdf_theme, analyze: true
= Document Title
:doctype: book
:toc:
== Beginning
== End
EOS

footer_texts = pdf.find_text font_color: 'AA0000'
(expect footer_texts).to have_size 2
(expect footer_texts[0][:page_number]).to eql 3
(expect footer_texts[0][:string]).to eql '2 of 3'
(expect footer_texts[1][:page_number]).to eql 4
(expect footer_texts[1][:string]).to eql '3 of 3'
end

it 'should compute page-count attribute correctly when running content starts after page numbering' do
pdf_theme = {
page_numbering_start_at: 'body',
running_content_start_at: 'toc',
footer_recto_right_content: '{page-number} of {page-count}',
footer_verso_left_content: '{page-number} of {page-count}',
footer_font_color: 'AA0000',
}

pdf = to_pdf <<~'EOS', attribute_overrides: { 'nofooter' => nil }, pdf_theme: pdf_theme, analyze: true
= Document Title
:doctype: book
:toc:
== Beginning
== End
EOS

footer_texts = pdf.find_text font_color: 'AA0000'
(expect footer_texts).to have_size 3
(expect footer_texts[0][:page_number]).to eql 2
(expect footer_texts[0][:string]).to eql 'ii of 2'
(expect footer_texts[1][:page_number]).to eql 3
(expect footer_texts[1][:string]).to eql '1 of 2'
(expect footer_texts[2][:page_number]).to eql 4
(expect footer_texts[2][:string]).to eql '2 of 2'
end
end

context 'Theming' do
Expand Down

0 comments on commit 115267d

Please sign in to comment.