Skip to content

Commit

Permalink
automatically set height on column box if not specified; update value…
Browse files Browse the repository at this point in the history
… automatically when reflowing margins
  • Loading branch information
mojavelinux committed Jun 8, 2022
1 parent 4b75ba9 commit 63c9374
Show file tree
Hide file tree
Showing 2 changed files with 13 additions and 5 deletions.
1 change: 1 addition & 0 deletions CHANGELOG.adoc
Original file line number Diff line number Diff line change
Expand Up @@ -10,6 +10,7 @@ For a detailed view of what has changed, refer to the {url-repo}/commits/main[co
Improvements::

* encapsulate logic to adjust column box inside float and dry run
* automatically set height on column box if not specified; update value automatically when reflowing margins

Bug Fixes::

Expand Down
17 changes: 12 additions & 5 deletions lib/asciidoctor/pdf/ext/prawn/document/column_box.rb
Original file line number Diff line number Diff line change
@@ -1,17 +1,24 @@
# frozen_string_literal: true

Prawn::Document.prepend (Module.new do
# Wraps the column_box method and automatically sets the height unless the :height option is specified.
def column_box point, options, &block
options[:height] = cursor unless options.key? :height
super
end
end)

Prawn::Document::ColumnBox.prepend (Module.new do
attr_accessor :current_column

def absolute_bottom
stretchy? ? @parent.absolute_bottom : super
end

def move_past_bottom
(doc = @document).y = @y
return if (@current_column = (@current_column + 1) % @columns) > 0
par = @parent
@y = par.absolute_top if (reset_y = @reflow_margins) && (reset_y == true || reset_y > doc.page_number)
if (reset_y = @reflow_margins) && (reset_y == true || reset_y > doc.page_number)
@y = par.absolute_top
@height = par.height unless stretchy?
end
initial_margins = doc.page.margins
par.move_past_bottom
if doc.page.margins != initial_margins
Expand Down

0 comments on commit 63c9374

Please sign in to comment.