summaryrefslogtreecommitdiff
path: root/spec
diff options
context:
space:
mode:
authorDan Allen <dan.j.allen@gmail.com>2022-06-10 15:07:33 -0600
committerGitHub <noreply@github.com>2022-06-10 15:07:33 -0600
commitf4bd057f69b3d72da73bf20e31fca7a2bfedbf3a (patch)
treeeee20f12c66dad23f8f57c8e5e3b2f97f5cc5951 /spec
parent8d25b995f19cd8ada4b692227e59bf7c33dc3868 (diff)
resolves #327 arrange body of article or manpage doctype into multiple columns if page-columns key is set in theme (PR #2232)
Diffstat (limited to 'spec')
-rw-r--r--spec/arrange_block_spec.rb26
-rw-r--r--spec/index_spec.rb21
-rw-r--r--spec/manpage_spec.rb27
-rw-r--r--spec/page_spec.rb171
4 files changed, 225 insertions, 20 deletions
diff --git a/spec/arrange_block_spec.rb b/spec/arrange_block_spec.rb
index 729c1b9c..ac57252e 100644
--- a/spec/arrange_block_spec.rb
+++ b/spec/arrange_block_spec.rb
@@ -1856,16 +1856,9 @@ describe 'Asciidoctor::PDF::Converter#arrange_block' do
end
it 'should fill extent when block is advanced to next column' do
- source_file = doc_file 'modules/extend/examples/pdf-converter-columns.rb'
- source_lines = (File.readlines source_file).select {|l| l == ?\n || (l.start_with? ' ') }
- ext_class = create_class Asciidoctor::Converter.for 'pdf'
- backend = %(pdf#{ext_class.object_id})
- source_lines[0] = %( register_for '#{backend}'\n)
- ext_class.class_eval source_lines.join, source_file
-
pdf_theme.update \
- base_columns: 2,
- base_column_gap: 12,
+ page_columns: 2,
+ page_column_gap: 12,
code_border_radius: 0,
code_border_width: 0,
code_background_color: 'EFEFEF'
@@ -1879,7 +1872,7 @@ describe 'Asciidoctor::PDF::Converter#arrange_block' do
$ asciidoctor-pdf -r asciidoctor-mathematical -a mathematical-format=svg sample.adoc
....
EOS
- pdf = to_pdf input, backend: backend, pdf_theme: pdf_theme, analyze: true
+ pdf = to_pdf input, pdf_theme: pdf_theme, analyze: true
pages = pdf.pages
(expect pages).to have_size 1
gs = (pdf.extract_graphic_states pages[0][:raw_content])[1]
@@ -1888,14 +1881,7 @@ describe 'Asciidoctor::PDF::Converter#arrange_block' do
end
it 'should correctly compute to cursor value on extent when column_box starts below top of page' do
- source_file = doc_file 'modules/extend/examples/pdf-converter-columns.rb'
- source_lines = (File.readlines source_file).select {|l| l == ?\n || (l.start_with? ' ') }
- ext_class = create_class Asciidoctor::Converter.for 'pdf'
- backend = %(pdf#{ext_class.object_id})
- source_lines[0] = %( register_for '#{backend}'\n)
- ext_class.class_eval source_lines.join, source_file
-
- pdf_theme.update base_columns: 2, base_column_gap: 12, admonition_column_rule_color: '0000FF'
+ pdf_theme.update page_columns: 2, page_column_gap: 12, admonition_column_rule_color: '0000FF'
pdf = with_content_spacer 10, 400 do |spacer_path|
input = <<~EOS
@@ -1912,10 +1898,10 @@ describe 'Asciidoctor::PDF::Converter#arrange_block' do
====
EOS
- pdf = to_pdf input, backend: backend, pdf_theme: pdf_theme, analyze: true
+ pdf = to_pdf input, pdf_theme: pdf_theme, analyze: true
pages = pdf.pages
(expect pages).to have_size 1
- lines = (to_pdf input, backend: backend, pdf_theme: pdf_theme, analyze: :line).lines
+ lines = (to_pdf input, pdf_theme: pdf_theme, analyze: :line).lines
column_rules = lines.select {|it| it[:color] == '0000FF' }
(expect column_rules).to have_size 2
(expect column_rules[0][:from][:x]).to be < column_rules[1][:from][:x]
diff --git a/spec/index_spec.rb b/spec/index_spec.rb
index 3a8bf3c0..13cdc112 100644
--- a/spec/index_spec.rb
+++ b/spec/index_spec.rb
@@ -818,6 +818,27 @@ describe 'Asciidoctor::PDF::Converter - Index' do
(expect category_l_text[:x]).to be > category_a_text[:x]
end
+ it 'should ignore index columns if columns are set on page' do
+ pdf = to_pdf <<~EOS, pdf_theme: { page_columns: 2, index_columns: 3 }, analyze: true
+ = Document Title
+ :notitle:
+
+ #{('a'..'z').map {|it| %(((#{it}-keyword))((#{it}-term))) }.join}
+
+ [index]
+ == Index
+ EOS
+
+ midpoint = (get_page_size pdf)[0] * 0.5
+ category_g_text = (pdf.find_text 'A')[0]
+ category_s_text = (pdf.find_text 'L')[0]
+ category_t_text = (pdf.find_text 'W')[0]
+ (expect category_g_text[:page_number]).to be 1
+ (expect category_g_text[:x]).to eql 48.24
+ (expect category_s_text[:x]).to be > midpoint
+ (expect category_t_text[:x]).to eql 48.24
+ end
+
it 'should not allocate space for anchor if font is missing glyph for null character' do
pdf_theme = {
extends: 'default',
diff --git a/spec/manpage_spec.rb b/spec/manpage_spec.rb
index 5d832e23..a3e320e1 100644
--- a/spec/manpage_spec.rb
+++ b/spec/manpage_spec.rb
@@ -93,4 +93,31 @@ describe 'Asciidoctor::PDF::Converter - Manpage' do
(expect name_title_text[:font_size]).to be 22
(expect pdf.lines).to include 'cmd - does stuff'
end
+
+ it 'should arrange body of manpage into columns if specified in theme' do
+ pdf = to_pdf <<~'EOS', doctype: :manpage, pdf_theme: { page_columns: 2 }, analyze: true
+ = cmd(1)
+
+ == Name
+
+ cmd - does stuff
+
+ == Synopsis
+
+ *cmd* [_OPTION_]... _FILE_...
+
+ <<<
+
+ == Options
+
+ *-v*:: Prints the version.
+ EOS
+
+ midpoint = (get_page_size pdf)[0] * 0.5
+ name_text = pdf.find_unique_text 'Name'
+ options_text = pdf.find_unique_text 'Options'
+ (expect name_text[:x]).to eql 48.24
+ (expect options_text[:x]).to be > midpoint
+ (expect name_text[:y]).to eql options_text[:y]
+ end
end
diff --git a/spec/page_spec.rb b/spec/page_spec.rb
index 62ec84e2..be80b9be 100644
--- a/spec/page_spec.rb
+++ b/spec/page_spec.rb
@@ -538,6 +538,177 @@ describe 'Asciidoctor::PDF::Converter - Page' do
end
end
+ context 'Columns' do
+ it 'should ignore columns for book doctype' do
+ pdf = to_pdf <<~'EOS', pdf_theme: { page_columns: 2 }, analyze: true
+ = Document Title
+ :doctype: book
+ :notitle:
+
+ [.text-right]
+ first page
+
+ <<<
+
+ second page
+ EOS
+
+ midpoint = (get_page_size pdf)[0] * 0.5
+ (expect pdf.pages).to have_size 2
+ (expect (pdf.find_unique_text 'first page')[:page_number]).to eql 1
+ (expect (pdf.find_unique_text 'first page')[:x]).to be > midpoint
+ (expect (pdf.find_unique_text 'second page')[:page_number]).to eql 2
+ end
+
+ it 'should ignore columns if less than 2' do
+ pdf = to_pdf <<~'EOS', pdf_theme: { page_columns: 1 }, analyze: true
+ = Document Title
+ :notitle:
+
+ first page
+
+ <<<
+
+ 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 arrange article body into columns' do
+ pdf = to_pdf <<~'EOS', pdf_theme: { page_columns: 2 }, analyze: true
+ first column
+
+ <<<
+
+ second column
+
+ <<<
+
+ [.text-right]
+ first column again
+ EOS
+
+ midpoint = (get_page_size pdf)[0] * 0.5
+ (expect pdf.pages).to have_size 2
+ (expect (pdf.find_unique_text 'first column')[:page_number]).to eql 1
+ (expect (pdf.find_unique_text 'second column')[:page_number]).to eql 1
+ (expect (pdf.find_unique_text 'second column')[:x]).to be > midpoint
+ (expect (pdf.find_unique_text 'first column again')[:page_number]).to eql 2
+ (expect (pdf.find_unique_text 'first column again')[:x]).to be < midpoint
+ end
+
+ it 'should put footnotes at bottom of last column with content' do
+ pdf = to_pdf <<~'EOS', pdf_theme: { page_columns: 2 }, analyze: true
+ first columnfootnote:[This page has two columns.]
+
+ <<<
+
+ second column
+ EOS
+
+ midpoint = (get_page_size pdf)[0] * 0.5
+ (expect pdf.pages).to have_size 1
+ (expect (pdf.find_unique_text 'second column')[:x]).to be > midpoint
+ right_column_text = pdf.text.select {|it| it[:x] > midpoint }
+ right_column_lines = pdf.lines right_column_text
+ (expect right_column_lines).to have_size 2
+ (expect right_column_lines[-1]).to eql '[1] This page has two columns.'
+ end
+
+ it 'should place document title outside of column box' do
+ pdf = to_pdf <<~'EOS', pdf_theme: { page_columns: 2 }, analyze: true
+ = Article Title Goes Here
+
+ first column
+
+ <<<
+
+ second column
+ EOS
+
+ midpoint = (get_page_size pdf)[0] * 0.5
+ (expect pdf.pages).to have_size 1
+ title_text = pdf.find_unique_text 'Article Title Goes Here'
+ (expect title_text[:x]).to be < midpoint
+ (expect title_text[:x] + title_text[:width]).to be > midpoint
+ (expect (pdf.find_unique_text 'second column')[:x]).to be > midpoint
+ end
+
+ it 'should place TOC outside of column box' do
+ pdf = to_pdf <<~'EOS', pdf_theme: { page_columns: 2 }, analyze: true
+ = Article Title Goes Here
+ :toc:
+
+ == First Column
+
+ <<<
+
+ == Second Column
+ EOS
+
+ midpoint = (get_page_size pdf)[0] * 0.5
+ (expect pdf.pages).to have_size 1
+ first_column_text = (pdf.find_text 'First Column').sort_by {|it| -it[:y] }
+ second_column_text = (pdf.find_text 'Second Column').sort_by {|it| -it[:y] }
+ (expect first_column_text[0][:x]).to eql 48.24
+ (expect first_column_text[1][:x]).to eql 48.24
+ (expect second_column_text[0][:x]).to eql 48.24
+ (expect second_column_text[1][:x]).to be > midpoint
+ dots_text = pdf.text.select {|it| it[:string].include? '.' }
+ dots_text.each do |it|
+ (expect it[:x]).to be < midpoint
+ (expect it[:x] + it[:width]).to be > midpoint
+ end
+ end
+
+ it 'should allow theme to control number of columns' do
+ pdf = to_pdf <<~'EOS', pdf_theme: { page_columns: 4 }, analyze: true
+ one
+
+ <<<
+
+ two
+
+ <<<
+
+ three
+
+ <<<<
+
+ four
+ EOS
+
+ midpoint = (get_page_size pdf)[0] * 0.5
+ (expect pdf.pages).to have_size 1
+ one_text = pdf.find_unique_text 'one'
+ two_text = pdf.find_unique_text 'two'
+ three_text = pdf.find_unique_text 'three'
+ four_text = pdf.find_unique_text 'four'
+ (expect two_text[:x]).to be > one_text[:x]
+ (expect two_text[:x]).to be < midpoint
+ (expect four_text[:x]).to be > three_text[:x]
+ (expect three_text[:x]).to be > midpoint
+ end
+
+ it 'should allow theme to control column gap' do
+ pdf = to_pdf <<~'EOS', pdf_theme: { page_columns: 2, page_column_gap: 12 }, analyze: :image
+ image::square.png[pdfwidth=100%]
+
+ <<<
+
+ image::square.png[pdfwidth=100%]
+ EOS
+
+ images = pdf.images
+ (expect images).to have_size 2
+ column_gap = (images[1][:x] - (images[0][:x] + images[0][:width])).to_f
+ (expect column_gap).to eql 12.0
+ end
+ end
+
context 'Background' do
it 'should set page background to white if value is not defined or transparent', visual: true do
[nil, 'transparent'].each do |bg_color|