Class: Prawn::Table::Cell::AsciiDoc
- Inherits:
-
Prawn::Table::Cell
- Object
- Prawn::Table::Cell
- Prawn::Table::Cell::AsciiDoc
- Includes:
- Asciidoctor::Logging
- Defined in:
- lib/asciidoctor/pdf/ext/prawn-table/cell/asciidoc.rb
Instance Attribute Summary collapse
-
#align ⇒ Object
Returns the value of attribute align.
-
#root_font_size ⇒ Object
Returns the value of attribute root_font_size.
-
#valign ⇒ Object
Returns the value of attribute valign.
Instance Method Summary collapse
-
#draw_content ⇒ Object
NOTE: prawn-table doesn’t support cells that exceed the height of a single page.
-
#dry_run ⇒ Object
NOTE: automatic image sizing only works if cell has fixed width.
- #font=(val) ⇒ Object
- #font_style=(val) ⇒ Object
-
#initialize(pdf, opts = {}) ⇒ AsciiDoc
constructor
A new instance of AsciiDoc.
- #natural_content_height ⇒ Object
- #natural_content_width ⇒ Object
- #size=(val) ⇒ Object
- #text_color=(val) ⇒ Object
Constructor Details
#initialize(pdf, opts = {}) ⇒ AsciiDoc
Returns a new instance of AsciiDoc.
13 14 15 16 17 |
# File 'lib/asciidoctor/pdf/ext/prawn-table/cell/asciidoc.rb', line 13 def initialize pdf, opts = {} @font_options = {} @align = @valign = @root_font_size = nil super pdf, [], opts end |
Instance Attribute Details
#align ⇒ Object
Returns the value of attribute align.
9 10 11 |
# File 'lib/asciidoctor/pdf/ext/prawn-table/cell/asciidoc.rb', line 9 def align @align end |
#root_font_size ⇒ Object
Returns the value of attribute root_font_size.
10 11 12 |
# File 'lib/asciidoctor/pdf/ext/prawn-table/cell/asciidoc.rb', line 10 def root_font_size @root_font_size end |
#valign ⇒ Object
Returns the value of attribute valign.
11 12 13 |
# File 'lib/asciidoctor/pdf/ext/prawn-table/cell/asciidoc.rb', line 11 def valign @valign end |
Instance Method Details
#draw_content ⇒ Object
NOTE: prawn-table doesn’t support cells that exceed the height of a single page
69 70 71 72 73 74 75 76 77 78 79 80 81 82 83 84 85 86 87 88 89 90 91 92 93 94 95 96 97 98 99 100 101 |
# File 'lib/asciidoctor/pdf/ext/prawn-table/cell/asciidoc.rb', line 69 def draw_content if (pdf = @pdf).scratch? pdf.move_down natural_content_height return end # NOTE: draw_bounded_content automatically adds FPTolerance to width and height pdf.bounds.instance_variable_set :@width, spanned_content_width # NOTE: we've already reserved the space, so just let the box stretch to the maximum that could fit on a page pdf.bounds.instance_variable_set :@height, (pdf.margin_box.height - padding_top - padding_bottom) if @valign != :top && (excess_y = spanned_content_height - natural_content_height) > 0 # QUESTION: could this cause a unexpected page overrun? pdf.move_down(@valign == :center ? (excess_y.fdiv 2) : excess_y) end # # use perform_on_single_page to prevent content from being written on extra pages # # the problem with this approach is that we don't know whether any content is written to next page # apply_font_properties do # if (pdf.perform_on_single_page { pdf.traverse content }) # logger.error %(the table cell on page #{pdf.page_number} has been truncated; Asciidoctor PDF does not support table cell content that exceeds the height of a single page) # end # end start_page = pdf.page_number parent_doc = (doc = content.document).nested? ? doc.parent_document : doc doc.catalog[:footnotes] = parent_doc.catalog[:footnotes] # TODO: apply horizontal alignment; currently it is necessary to specify alignment on content blocks apply_font_properties { pdf.traverse content } if (extra_pages = pdf.page_number - start_page) > 0 unless extra_pages == 1 && pdf.page.empty? logger.error %(the table cell on page #{start_page} has been truncated; Asciidoctor PDF does not support table cell content that exceeds the height of a single page), source_location: @source_location end extra_pages.times { pdf.delete_current_page } end nil end |
#dry_run ⇒ Object
NOTE: automatic image sizing only works if cell has fixed width
36 37 38 39 40 41 42 43 44 45 46 47 48 49 50 51 52 53 54 55 56 |
# File 'lib/asciidoctor/pdf/ext/prawn-table/cell/asciidoc.rb', line 36 def dry_run cell = self parent_doc = (doc = content.document).nested? ? doc.parent_document : doc padding_y = cell.padding_top + cell.padding_bottom max_height = @pdf.bounds.height extent = nil apply_font_properties do extent = @pdf.dry_run keep_together: true, single_page: true do push_scratch parent_doc # NOTE: we should be able to use cell.max_width, but returns 0 in some conditions (like when colspan > 1) indent cell.padding_left, bounds.width - cell.width + cell.padding_right do move_down padding_y if padding_y > 0 conceal_page_top { traverse cell.content } end pop_scratch parent_doc end end # NOTE: prawn-table doesn't support cells that exceed the height of a single page # NOTE: height does not include top/bottom padding, but must account for it when checking for overrun (extent.single_page_height || max_height) - padding_y end |
#font=(val) ⇒ Object
31 32 33 |
# File 'lib/asciidoctor/pdf/ext/prawn-table/cell/asciidoc.rb', line 31 def font= val @font_options[:family] = val end |
#font_style=(val) ⇒ Object
19 20 21 |
# File 'lib/asciidoctor/pdf/ext/prawn-table/cell/asciidoc.rb', line 19 def font_style= val @font_options[:style] = val end |
#natural_content_height ⇒ Object
63 64 65 66 |
# File 'lib/asciidoctor/pdf/ext/prawn-table/cell/asciidoc.rb', line 63 def natural_content_height # NOTE: when natural_content_height is called, we already know max width @natural_content_height ||= dry_run end |
#natural_content_width ⇒ Object
58 59 60 61 |
# File 'lib/asciidoctor/pdf/ext/prawn-table/cell/asciidoc.rb', line 58 def natural_content_width # QUESTION: can we get a better estimate of the natural width? @natural_content_width ||= (@pdf.bounds.width - padding_left - padding_right) end |
#size=(val) ⇒ Object
27 28 29 |
# File 'lib/asciidoctor/pdf/ext/prawn-table/cell/asciidoc.rb', line 27 def size= val @font_options[:size] = val end |
#text_color=(val) ⇒ Object
23 24 25 |
# File 'lib/asciidoctor/pdf/ext/prawn-table/cell/asciidoc.rb', line 23 def text_color= val @font_options[:color] = val end |