summaryrefslogtreecommitdiff
path: root/spec
diff options
context:
space:
mode:
authorDan Allen <dan.j.allen@gmail.com>2022-05-18 14:39:12 -0600
committerGitHub <noreply@github.com>2022-05-18 14:39:12 -0600
commit9e843a11add2b25753329a808d43a4ea6dfc3f3d (patch)
tree0dcc1b7c890948f964392fbc9ec508c8de613527 /spec
parent667e66a949f1c66bb7bbee1d0b4cdaf3b8175362 (diff)
add foundation to support multi-column layout; add example to docs (PR #2190)
Diffstat (limited to 'spec')
-rw-r--r--spec/arrange_block_spec.rb59
-rw-r--r--spec/converter_spec.rb22
2 files changed, 81 insertions, 0 deletions
diff --git a/spec/arrange_block_spec.rb b/spec/arrange_block_spec.rb
index ea797672..00d80918 100644
--- a/spec/arrange_block_spec.rb
+++ b/spec/arrange_block_spec.rb
@@ -1829,6 +1829,65 @@ describe 'Asciidoctor::PDF::Converter#arrange_block' do
end
end
+ describe 'column box' do
+ it 'should compute extent for block based on correct width' do
+ pdf_theme[:code_border_radius] = 0
+ backend = nil
+ create_class (Asciidoctor::Converter.for 'pdf') do
+ register_for (backend = %(pdf#{object_id}).to_sym)
+ def traverse node
+ return super unless node.context == :document
+ column_box [0, cursor], columns: 2, width: bounds.width, reflow_margins: true, spacer: 12 do
+ super
+ end
+ end
+ end
+ input = <<~'EOS'
+ ....
+ $ gem install asciidoctor-pdf asciidoctor-mathematical
+ $ asciidoctor-pdf -r asciidoctor-mathematical -a mathematical-format=svg sample.adoc
+ ....
+ EOS
+ lines = (to_pdf input, backend: backend, pdf_theme: pdf_theme, analyze: :line).lines
+ pdf = to_pdf input, backend: backend, pdf_theme: pdf_theme, analyze: true
+ last_line_y = lines.select {|it| it[:from][:y] == it[:to][:y] }.map {|it| it[:from][:y] }.min
+ last_text = pdf.text[-1]
+ (expect last_text[:y]).to be > last_line_y
+ 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,
+ code_border_radius: 0,
+ code_border_width: 0,
+ code_background_color: 'EFEFEF'
+
+ pdf = with_content_spacer 10, 675 do |spacer_path|
+ input = <<~EOS
+ image::#{spacer_path}[]
+
+ ....
+ $ gem install asciidoctor-pdf asciidoctor-mathematical
+ $ asciidoctor-pdf -r asciidoctor-mathematical -a mathematical-format=svg sample.adoc
+ ....
+ EOS
+ pdf = to_pdf input, backend: backend, 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]
+ (expect gs).to have_background color: 'EFEFEF', top_left: [312.0, 742.0], bottom_right: [562.0, 646.3]
+ end
+ end
+ end
+
# NOTE: generate reference files using ./scripts/generate-arrange-block-reference-files.sh
describe 'acceptance', visual: true, if: ENV['COVERAGE'] do
it 'at top, fits' do
diff --git a/spec/converter_spec.rb b/spec/converter_spec.rb
index bacb1192..563181df 100644
--- a/spec/converter_spec.rb
+++ b/spec/converter_spec.rb
@@ -478,6 +478,28 @@ describe Asciidoctor::PDF::Converter do
result = converter.parse_text %(foo\n<strong>bar</strong>), inline_format: [normalize: true]
(expect result).to eql [{ text: 'foo ' }, { text: 'bar', styles: [:bold].to_set }]
end
+
+ it 'should restore current column after float yields to current block' do
+ doc = Asciidoctor.load 'text', backend: :pdf
+ converter = doc.converter
+ actual_column = nil
+ last_visited_column = nil
+ converter.instance_exec do
+ init_pdf doc
+ start_new_page
+ column_box [bounds.left, cursor], width: bounds.width, columns: 2 do
+ float do
+ ink_prose 'before'
+ bounds.move_past_bottom
+ ink_prose 'after'
+ last_visited_column = bounds.instance_variable_get :@current_column
+ end
+ actual_column = bounds.instance_variable_get :@current_column
+ end
+ end
+ (expect actual_column).to eql 0
+ (expect last_visited_column).to eql 1
+ end
end
describe '#next_enclosed_block' do