summaryrefslogtreecommitdiff
diff options
context:
space:
mode:
authorDan Allen <dan.j.allen@gmail.com>2022-08-06 04:39:25 -0600
committerGitHub <noreply@github.com>2022-08-06 04:39:25 -0600
commit6614e0b170f8ae24e05537afd5f8dffeaf3c1757 (patch)
tree7619842f9c3cfe666e6f67ab93231cf775403b90
parent1f333b0d5c3e0877eeade53f73f96154992ce5da (diff)
resolves #2293 insert column break multi-column layout if column role is specified on page break macro (PR #2299)
-rw-r--r--CHANGELOG.adoc3
-rw-r--r--lib/asciidoctor/pdf/converter.rb2
-rw-r--r--lib/asciidoctor/pdf/ext/prawn/document/column_box.rb4
-rw-r--r--spec/admonition_spec.rb1
-rw-r--r--spec/break_spec.rb120
-rw-r--r--spec/converter_spec.rb2
-rw-r--r--spec/image_spec.rb2
-rw-r--r--spec/manpage_spec.rb1
-rw-r--r--spec/page_spec.rb17
9 files changed, 150 insertions, 2 deletions
diff --git a/CHANGELOG.adoc b/CHANGELOG.adoc
index 62f27d46..d1d77017 100644
--- a/CHANGELOG.adoc
+++ b/CHANGELOG.adoc
@@ -10,7 +10,8 @@ For a detailed view of what has changed, refer to the {url-repo}/commits/main[co
Enhancements::
* allow footnotes to be placed directly below last block of content if `footnotes_margin_top` theme key is 0 (#2291)
-* allow page break to be forced using `always` option (e.g., `[%always]`) (#2300)
+* insert column break instead of page break in multi-column layout if `column` role is specified on page break macro (#2293)
+* allow page / column break to be forced using `always` option (e.g., `[%always]`) (#2300)
Bug Fixes::
diff --git a/lib/asciidoctor/pdf/converter.rb b/lib/asciidoctor/pdf/converter.rb
index 669efdda..2454f3c8 100644
--- a/lib/asciidoctor/pdf/converter.rb
+++ b/lib/asciidoctor/pdf/converter.rb
@@ -1924,8 +1924,10 @@ module Asciidoctor
advance_page layout: page_layout, margin: @page_margin[page_layout][page_side nil, @folio_placement[:inverted]]
end
elsif page_layout
+ bounds.current_column = bounds.last_column if ColumnBox === bounds && !(node.has_role? 'column')
advance_page layout: page_layout, margin: @page_margin[page_layout][page_side nil, @folio_placement[:inverted]]
else
+ bounds.current_column = bounds.last_column if ColumnBox === bounds && !(node.has_role? 'column')
advance_page
end
end
diff --git a/lib/asciidoctor/pdf/ext/prawn/document/column_box.rb b/lib/asciidoctor/pdf/ext/prawn/document/column_box.rb
index 6f2b7b19..c61baf0a 100644
--- a/lib/asciidoctor/pdf/ext/prawn/document/column_box.rb
+++ b/lib/asciidoctor/pdf/ext/prawn/document/column_box.rb
@@ -3,6 +3,10 @@
Prawn::Document::ColumnBox.prepend (Module.new do
attr_accessor :current_column
+ def last_column
+ @columns - 1
+ end
+
def move_past_bottom
(doc = @document).y = @y
return if (@current_column = (@current_column + 1) % @columns) > 0
diff --git a/spec/admonition_spec.rb b/spec/admonition_spec.rb
index 18f67712..9978eea2 100644
--- a/spec/admonition_spec.rb
+++ b/spec/admonition_spec.rb
@@ -610,6 +610,7 @@ describe 'Asciidoctor::PDF::Converter - Admonition' do
left column
+ [.column]
<<<
right column
diff --git a/spec/break_spec.rb b/spec/break_spec.rb
index 7087cd83..bf498dff 100644
--- a/spec/break_spec.rb
+++ b/spec/break_spec.rb
@@ -113,6 +113,24 @@ describe 'Asciidoctor::PDF::Converter - Break' do
(expect pdf.pages[1][:strings]).to include 'bar'
end
+ it 'should insert page break if page does not have columns' do
+ pdf = to_pdf <<~'EOS', analyze: true
+ = Document Title
+ :notitle:
+
+ first page
+
+ [.column]
+ <<<
+
+ second page
+ EOS
+
+ (expect pdf.pages).to have_size 2
+ (expect (pdf.find_unique_text 'first page')[:page_number]).to eql 1
+ (expect (pdf.find_unique_text 'second page')[:page_number]).to eql 2
+ end
+
it 'should not advance to next page if at start of document' do
pdf = to_pdf <<~'EOS', analyze: :page
<<<
@@ -166,10 +184,11 @@ describe 'Asciidoctor::PDF::Converter - Break' do
(expect start_of_page_text[:page_number]).to be 2
end
- it 'should not advance to next page if at start of column in multi-column layout' do
+ it 'should not advance to next column if at start of column in multi-column layout' do
pdf = to_pdf <<~'EOS', pdf_theme: { page_columns: 2 }, analyze: true
= Article Title
+ [.column]
<<<
column 1
@@ -181,6 +200,22 @@ describe 'Asciidoctor::PDF::Converter - Break' do
(expect text[:y]).to be < (pdf.find_unique_text 'Article Title')[:y]
end
+ it 'should advance to next column if at start of column in multi-column layout and always option is specified' do
+ pdf = to_pdf <<~'EOS', pdf_theme: { page_columns: 2 }, analyze: true
+ = Article Title
+
+ [.column%always]
+ <<<
+
+ column 1
+ EOS
+
+ (expect pdf.pages).to have_size 1
+ text = pdf.find_unique_text 'column 1'
+ (expect text[:x]).to be > 48.24
+ (expect text[:y]).to be < (pdf.find_unique_text 'Article Title')[:y]
+ end
+
it 'should not leave blank page at the end of document' do
input = <<~'EOS'
foo
@@ -300,5 +335,88 @@ describe 'Asciidoctor::PDF::Converter - Break' do
(expect (pdf.page 3)[:size]).to eql (pdf.page 2)[:size]
end
+
+ it 'should insert page break in column layout' do
+ pdf = to_pdf <<~EOS, pdf_theme: { page_columns: 2 }, analyze: true
+ = Article Title
+
+ column 1, page 1
+
+ <<<
+
+ column 1, page 2
+ EOS
+
+ c1p1_text = pdf.find_unique_text 'column 1, page 1'
+ (expect c1p1_text[:x]).to eql 48.24
+ (expect c1p1_text[:page_number]).to eql 1
+ c1p2_text = pdf.find_unique_text 'column 1, page 2'
+ (expect c1p2_text[:x]).to eql 48.24
+ (expect c1p2_text[:page_number]).to eql 2
+ end
+
+ it 'should insert page break with custom layout in column layout' do
+ pdf = to_pdf <<~EOS, pdf_theme: { page_columns: 2 }, analyze: true
+ = Article Title
+
+ column 1, page 1
+
+ [page-layout=landscape]
+ <<<
+
+ column 1, page 2
+ EOS
+
+ c1p1_text = pdf.find_unique_text 'column 1, page 1'
+ (expect c1p1_text[:x]).to eql 48.24
+ (expect c1p1_text[:page_number]).to eql 1
+ p1 = pdf.pages[0]
+ (expect p1[:size][0]).to be < p1[:size][1]
+ c1p2_text = pdf.find_unique_text 'column 1, page 2'
+ (expect c1p2_text[:x]).to eql 48.24
+ (expect c1p2_text[:page_number]).to eql 2
+ p2 = pdf.pages[1]
+ (expect p2[:size][0]).to be > p2[:size][1]
+ end
+
+ it 'should insert column break in column layout if column role is specified' do
+ pdf = to_pdf <<~EOS, pdf_theme: { page_columns: 2 }, analyze: true
+ = Article Title
+
+ column 1, page 1
+
+ [.column]
+ <<<
+
+ column 2, page 1
+ EOS
+
+ c1p1_text = pdf.find_unique_text 'column 1, page 1'
+ (expect c1p1_text[:x]).to eql 48.24
+ (expect c1p1_text[:page_number]).to eql 1
+ c2p1_text = pdf.find_unique_text 'column 2, page 1'
+ (expect c2p1_text[:x]).to be > 48.24
+ (expect c2p1_text[:page_number]).to eql 1
+ end
+
+ it 'should insert page break in column layout if page layout is specified even if column role is specified' do
+ pdf = to_pdf <<~EOS, pdf_theme: { page_columns: 2 }, analyze: true
+ = Article Title
+
+ column 1, page 1
+
+ [.column,page-layout=landscape]
+ <<<
+
+ column 1, page 2
+ EOS
+
+ c1p1_text = pdf.find_unique_text 'column 1, page 1'
+ (expect c1p1_text[:x]).to eql 48.24
+ (expect c1p1_text[:page_number]).to eql 1
+ c1p2_text = pdf.find_unique_text 'column 1, page 2'
+ (expect c1p2_text[:x]).to eql 48.24
+ (expect c1p2_text[:page_number]).to eql 2
+ end
end
end
diff --git a/spec/converter_spec.rb b/spec/converter_spec.rb
index 13af727d..a2ce88f3 100644
--- a/spec/converter_spec.rb
+++ b/spec/converter_spec.rb
@@ -1171,10 +1171,12 @@ describe Asciidoctor::PDF::Converter do
column 1, page 1
+ [.column]
<<<
column 2, page 1
+ [.column]
<<<
column 1, page 2
diff --git a/spec/image_spec.rb b/spec/image_spec.rb
index f01b9083..9c8ac0a7 100644
--- a/spec/image_spec.rb
+++ b/spec/image_spec.rb
@@ -671,6 +671,7 @@ describe 'Asciidoctor::PDF::Converter - Image' do
input = <<~'EOS'
left column
+ [.column]
<<<
---
@@ -697,6 +698,7 @@ describe 'Asciidoctor::PDF::Converter - Image' do
input = <<~'EOS'
left column
+ [.column]
<<<
---
diff --git a/spec/manpage_spec.rb b/spec/manpage_spec.rb
index a3e320e1..3e449852 100644
--- a/spec/manpage_spec.rb
+++ b/spec/manpage_spec.rb
@@ -106,6 +106,7 @@ describe 'Asciidoctor::PDF::Converter - Manpage' do
*cmd* [_OPTION_]... _FILE_...
+ [.column]
<<<
== Options
diff --git a/spec/page_spec.rb b/spec/page_spec.rb
index 2d3e70bf..327bc489 100644
--- a/spec/page_spec.rb
+++ b/spec/page_spec.rb
@@ -631,6 +631,7 @@ describe 'Asciidoctor::PDF::Converter - Page' do
[.text-right]
first page
+ [.column]
<<<
second page
@@ -650,6 +651,7 @@ describe 'Asciidoctor::PDF::Converter - Page' do
first page
+ [.column]
<<<
second page
@@ -664,10 +666,12 @@ describe 'Asciidoctor::PDF::Converter - Page' do
pdf = to_pdf <<~'EOS', pdf_theme: { page_columns: 2 }, analyze: true
first column
+ [.column]
<<<
second column
+ [.column]
<<<
[.text-right]
@@ -687,6 +691,7 @@ describe 'Asciidoctor::PDF::Converter - Page' do
pdf = to_pdf <<~'EOS', pdf_theme: { page_columns: 2 }, analyze: true
first columnfootnote:[This page has two columns.]
+ [.column]
<<<
second column
@@ -707,6 +712,7 @@ describe 'Asciidoctor::PDF::Converter - Page' do
first column
+ [.column]
<<<
second column
@@ -727,6 +733,7 @@ describe 'Asciidoctor::PDF::Converter - Page' do
== First Column
+ [.column]
<<<
== Second Column
@@ -751,14 +758,17 @@ describe 'Asciidoctor::PDF::Converter - Page' do
pdf = to_pdf <<~'EOS', pdf_theme: { page_columns: 4 }, analyze: true
one
+ [.column]
<<<
two
+ [.column]
<<<
three
+ [.column]
<<<<
four
@@ -780,6 +790,7 @@ describe 'Asciidoctor::PDF::Converter - Page' do
pdf = to_pdf <<~'EOS', pdf_theme: { page_columns: 2, page_column_gap: 12 }, analyze: :image
image::square.png[pdfwidth=100%]
+ [.column]
<<<
image::square.png[pdfwidth=100%]
@@ -801,6 +812,7 @@ describe 'Asciidoctor::PDF::Converter - Page' do
left column
+ [.column]
<<<
right column
@@ -828,6 +840,7 @@ describe 'Asciidoctor::PDF::Converter - Page' do
left column
+ [.column]
<<<
right column
@@ -836,6 +849,7 @@ describe 'Asciidoctor::PDF::Converter - Page' do
left column
+ [.column]
<<<
right column
@@ -863,6 +877,7 @@ describe 'Asciidoctor::PDF::Converter - Page' do
left column
+ [.column]
<<<
right column
@@ -871,6 +886,7 @@ describe 'Asciidoctor::PDF::Converter - Page' do
left column
+ [.column]
<<<
right column
@@ -897,6 +913,7 @@ describe 'Asciidoctor::PDF::Converter - Page' do
pdf = to_pdf <<~'EOS', pdf_theme: { page_columns: 2 }, analyze: true
left column
+ [.column]
<<<
right column