Class: Asciidoctor::Prawn::Extensions::ScratchExtent

Inherits:
Struct
  • Object
show all
Defined in:
lib/asciidoctor/pdf/ext/prawn/extensions.rb

Instance Attribute Summary collapse

Instance Method Summary collapse

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

#fromObject

Returns the value of attribute from

Returns:

  • (Object)

    the current value of from



66
67
68
# File 'lib/asciidoctor/pdf/ext/prawn/extensions.rb', line 66

def from
  @from
end

#toObject

Returns the value of attribute to

Returns:

  • (Object)

    the current value of 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

Returns:

  • (Boolean)


87
88
89
# File 'lib/asciidoctor/pdf/ext/prawn/extensions.rb', line 87

def single_page?
  from.page == to.page
end

#single_page_heightObject



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