summaryrefslogtreecommitdiff
diff options
context:
space:
mode:
-rw-r--r--CHANGELOG.adoc2
-rw-r--r--lib/asciidoctor/pdf/converter.rb14
-rw-r--r--lib/asciidoctor/pdf/ext/prawn.rb1
-rw-r--r--lib/asciidoctor/pdf/ext/prawn/document/column_box.rb16
-rw-r--r--spec/index_spec.rb44
5 files changed, 64 insertions, 13 deletions
diff --git a/CHANGELOG.adoc b/CHANGELOG.adoc
index 77264602..a5f4f313 100644
--- a/CHANGELOG.adoc
+++ b/CHANGELOG.adoc
@@ -16,6 +16,8 @@ Bug Fixes::
* allow theme to set font style of first line of abstract to `normal_italic` (#2138)
* add support for `:color` option to `Prawn::Text::Formatted::Box` directly and remove workarounds
+* preserve columns on subsequent pages in the index section (#2149)
+* fix return value of `cursor` method inside block for column box
== 2.0.0.beta.1 (2022-05-04) - @mojavelinux
diff --git a/lib/asciidoctor/pdf/converter.rb b/lib/asciidoctor/pdf/converter.rb
index 17aa6f53..229138bd 100644
--- a/lib/asciidoctor/pdf/converter.rb
+++ b/lib/asciidoctor/pdf/converter.rb
@@ -2415,25 +2415,15 @@ module Asciidoctor
space_needed_for_category = @theme.description_list_term_spacing + (2 * (height_of_typeset_text 'A'))
pagenum_sequence_style = node.document.attr 'index-pagenum-sequence-style'
column_box [0, cursor], columns: @theme.index_columns, width: bounds.width, reflow_margins: true do
- def @bounding_box.move_past_bottom *args # rubocop:disable Lint/NestedMethodDefinition
- super(*args)
- @document.bounds = @parent = @document.margin_box if @current_column == 0 && @reflow_margins
- end
@index.categories.each do |category|
- # NOTE: cursor method always returns 0 inside column_box; breaks reference_bounds.move_past_bottom
- bounds.move_past_bottom if space_needed_for_category > y - reference_bounds.absolute_bottom
+ bounds.move_past_bottom if space_needed_for_category > cursor
ink_prose category.name,
align: :left,
inline_format: false,
margin_bottom: @theme.description_list_term_spacing,
style: @theme.description_list_term_font_style&.to_sym
category.terms.each {|term| convert_index_list_item term, pagenum_sequence_style }
- # NOTE: see previous note for why we can't use margin_bottom method
- if @theme.prose_margin_bottom > y - reference_bounds.absolute_bottom
- bounds.move_past_bottom
- else
- move_down @theme.prose_margin_bottom
- end
+ @theme.prose_margin_bottom > cursor ? bounds.move_past_bottom : (move_down @theme.prose_margin_bottom)
end
end
nil
diff --git a/lib/asciidoctor/pdf/ext/prawn.rb b/lib/asciidoctor/pdf/ext/prawn.rb
index 5c644a64..61745111 100644
--- a/lib/asciidoctor/pdf/ext/prawn.rb
+++ b/lib/asciidoctor/pdf/ext/prawn.rb
@@ -1,6 +1,7 @@
# frozen_string_literal: true
# the following are organized under the Asciidoctor::Prawn namespace
+require_relative 'prawn/document/column_box'
require_relative 'prawn/font_metric_cache'
require_relative 'prawn/font/afm'
require_relative 'prawn/images'
diff --git a/lib/asciidoctor/pdf/ext/prawn/document/column_box.rb b/lib/asciidoctor/pdf/ext/prawn/document/column_box.rb
new file mode 100644
index 00000000..fcef75ad
--- /dev/null
+++ b/lib/asciidoctor/pdf/ext/prawn/document/column_box.rb
@@ -0,0 +1,16 @@
+# frozen_string_literal: true
+
+Prawn::Document::ColumnBox.prepend (Module.new do
+ def absolute_bottom
+ stretchy? ? @parent.absolute_bottom : super
+ end
+
+ def move_past_bottom *_args
+ initial_page = @document.page
+ super
+ if (page = @document.page) != initial_page && page.margins != initial_page.margins
+ @document.bounds = self.class.new @document, @parent, (margin_box = @document.margin_box).absolute_top_left,
+ columns: @columns, reflow_margins: true, spacer: @spacer, width: margin_box.width
+ end
+ end
+end)
diff --git a/spec/index_spec.rb b/spec/index_spec.rb
index e12a32bd..d30d9f1e 100644
--- a/spec/index_spec.rb
+++ b/spec/index_spec.rb
@@ -787,7 +787,6 @@ describe 'Asciidoctor::PDF::Converter - Index' do
((melody)) and ((harmony))
-
[index]
== Index
EOS
@@ -800,6 +799,49 @@ describe 'Asciidoctor::PDF::Converter - Index' do
(expect s_category_text[:x]).to eql 36.0
end
+ it 'should preserve column count on subsequent pages' do
+ pdf_theme = {
+ page_margin: 36,
+ page_margin_inner: 54,
+ page_margin_outer: 18,
+ }
+ pdf = to_pdf <<~EOS, pdf_theme: pdf_theme, analyze: true
+ = Document Title
+ :doctype: book
+ :notitle:
+ :media: prepress
+ :pdf-page-size: A5
+
+ == Chapter
+
+ #{('a'..'z').map {|l| [l, l * 2, l * 3, l * 4] }.flatten.map {|it| '((' + it + '))' }.join ' '}
+
+ [index]
+ == Index
+ EOS
+
+ (expect pdf.pages).to have_size 5
+ midpoint_recto = 54 + (pdf.pages[0][:size][0] - 72) * 0.5
+ midpoint_verso = 18 + (pdf.pages[0][:size][0] - 72) * 0.5
+
+ a_category_text = pdf.find_unique_text 'A', page_number: 3
+ f_category_text = pdf.find_unique_text 'F', page_number: 3
+ k_category_text = pdf.find_unique_text 'K', page_number: 4
+ q_category_text = pdf.find_unique_text 'Q', page_number: 4
+ z_category_text = pdf.find_unique_text 'Z', page_number: 5
+ (expect a_category_text).not_to be_nil
+ (expect a_category_text[:x]).to eql 54.0
+ (expect f_category_text).not_to be_nil
+ (expect f_category_text[:x]).to be > midpoint_recto
+ (expect k_category_text).not_to be_nil
+ (expect k_category_text[:x]).to eql 18.0
+ (expect q_category_text).not_to be_nil
+ (expect q_category_text[:x]).to be > midpoint_verso
+ (expect q_category_text[:x]).to be < midpoint_recto
+ (expect z_category_text).not_to be_nil
+ (expect z_category_text[:x]).to eql 54.0
+ end
+
it 'should indent TOC title properly when index exceeds a page and section indent is positive' do
pdf = to_pdf <<~EOS, pdf_theme: { section_indent: 50 }, analyze: true
= Document Title