Class: Asciidoctor::Prawn::Extensions::ScratchExtent
- Defined in:
- lib/asciidoctor/pdf/ext/prawn/extensions.rb
Instance Attribute Summary collapse
-
#from ⇒ Object
Returns the value of attribute from.
-
#to ⇒ Object
Returns the value of attribute to.
Instance Method Summary collapse
-
#initialize(start_page, start_cursor, end_page, end_cursor) ⇒ ScratchExtent
constructor
A new instance of ScratchExtent.
- #position_onto(pdf, keep_together = nil) ⇒ Object
- #single_page? ⇒ Boolean
- #single_page_height ⇒ Object
- #try_to_fit_on_previous(reference_cursor) ⇒ Object
Constructor Details
#initialize(start_page, start_cursor, end_page, end_cursor) ⇒ ScratchExtent
Returns a new instance of ScratchExtent.
67 68 69 70 |
# File 'lib/asciidoctor/pdf/ext/prawn/extensions.rb', line 67 def initialize start_page, start_cursor, end_page, end_cursor self.from = Position.new start_page, 0, start_cursor self.to = Position.new end_page, 0, end_cursor end |
Instance Attribute Details
#from ⇒ Object
Returns the value of attribute from
66 67 68 |
# File 'lib/asciidoctor/pdf/ext/prawn/extensions.rb', line 66 def from @from end |
#to ⇒ Object
Returns the value of attribute to
66 67 68 |
# File 'lib/asciidoctor/pdf/ext/prawn/extensions.rb', line 66 def to @to end |
Instance Method Details
#position_onto(pdf, keep_together = nil) ⇒ Object
72 73 74 75 76 77 78 79 80 81 82 83 84 85 |
# File 'lib/asciidoctor/pdf/ext/prawn/extensions.rb', line 72 def position_onto pdf, keep_together = nil current_page = pdf.page_number current_column = ColumnBox === pdf.bounds ? (column_box = pdf.bounds).current_column : 0 current_cursor = pdf.cursor if (advance_by = from.page - 1) > 0 advance_by.times { pdf.advance_page } elsif keep_together && single_page? && !(try_to_fit_on_previous current_cursor) pdf.advance_page end from_page = pdf.page_number from_column = column_box&.current_column || 0 to_page = from_page + (to.page - from.page) Extent.new current_page, current_column, current_cursor, from_page, from_column, from.cursor, to_page, to.cursor end |
#single_page? ⇒ Boolean
87 88 89 |
# File 'lib/asciidoctor/pdf/ext/prawn/extensions.rb', line 87 def single_page? from.page == to.page end |
#single_page_height ⇒ Object
91 92 93 |
# File 'lib/asciidoctor/pdf/ext/prawn/extensions.rb', line 91 def single_page_height single_page? ? from.cursor - to.cursor : nil end |
#try_to_fit_on_previous(reference_cursor) ⇒ Object
95 96 97 98 99 100 101 102 103 |
# File 'lib/asciidoctor/pdf/ext/prawn/extensions.rb', line 95 def try_to_fit_on_previous reference_cursor if (height = from.cursor - to.cursor) <= reference_cursor from.cursor = reference_cursor to.cursor = reference_cursor - height true else false end end |