diff options
| author | Dan Allen <dan.j.allen@gmail.com> | 2022-05-12 02:27:50 -0600 |
|---|---|---|
| committer | Dan Allen <dan.j.allen@gmail.com> | 2022-05-12 02:52:42 -0600 |
| commit | 0261c04a675c589531b47d37d9e1b073cf3e9a6b (patch) | |
| tree | 0f8109880d823522f6da9f5628f63d60c51bcd76 | |
| parent | ba5e2881e0f4eb44569e152588cf5e06b0f318c9 (diff) | |
add utility to conceal page top to force margin to be applied
| -rw-r--r-- | lib/asciidoctor/pdf/converter.rb | 9 | ||||
| -rw-r--r-- | lib/asciidoctor/pdf/ext/prawn-table/cell/asciidoc.rb | 11 | ||||
| -rw-r--r-- | lib/asciidoctor/pdf/ext/prawn/extensions.rb | 9 | ||||
| -rw-r--r-- | spec/reference/image-svg-with-caption-scale-to-fit-page.pdf | bin | 12351 -> 12048 bytes |
4 files changed, 16 insertions, 13 deletions
diff --git a/lib/asciidoctor/pdf/converter.rb b/lib/asciidoctor/pdf/converter.rb index 34abd4ab..dd3ace3f 100644 --- a/lib/asciidoctor/pdf/converter.rb +++ b/lib/asciidoctor/pdf/converter.rb @@ -3090,11 +3090,12 @@ module Asciidoctor # title (i.e., subject.title? returns true). def ink_caption subject, opts = {} if opts.delete :dry_run - force_top_margin = !at_page_top? if (force_top_margin = opts.delete :force_top_margin).nil? return (dry_run keep_together: true, single_page: :enforce do - # TODO: encapsulate this logic to force top margin to be applied - margin_box.instance_variable_set :@y, margin_box.absolute_top + 0.0001 if force_top_margin - ink_caption subject, opts + if opts.delete :force_top_margin + conceal_page_top { ink_caption subject, opts } + else + ink_caption subject, opts + end end).single_page_height end if ::Asciidoctor::AbstractBlock === subject diff --git a/lib/asciidoctor/pdf/ext/prawn-table/cell/asciidoc.rb b/lib/asciidoctor/pdf/ext/prawn-table/cell/asciidoc.rb index 01698156..0af9cd52 100644 --- a/lib/asciidoctor/pdf/ext/prawn-table/cell/asciidoc.rb +++ b/lib/asciidoctor/pdf/ext/prawn-table/cell/asciidoc.rb @@ -41,17 +41,10 @@ module Prawn extent = @pdf.dry_run keep_together: true, single_page: true do push_scratch parent_doc doc.catalog[:footnotes] = parent_doc.catalog[:footnotes] - if padding_y > 0 - move_down padding_y - #elsif at_page_top? - else - # TODO: encapsulate this logic to force top margin to be applied - margin_box.instance_variable_set :@y, margin_box.absolute_top + 0.0001 - end # 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 - # TODO: truncate margin bottom of last block - traverse cell.content + move_down padding_y if padding_y > 0 + conceal_page_top { traverse cell.content } end pop_scratch parent_doc doc.catalog[:footnotes] = parent_doc.catalog[:footnotes] diff --git a/lib/asciidoctor/pdf/ext/prawn/extensions.rb b/lib/asciidoctor/pdf/ext/prawn/extensions.rb index 713c20d5..2be47aec 100644 --- a/lib/asciidoctor/pdf/ext/prawn/extensions.rb +++ b/lib/asciidoctor/pdf/ext/prawn/extensions.rb @@ -252,6 +252,15 @@ module Asciidoctor @y == @margin_box.absolute_top end + # Prevents at_page_top? from returning true while yielding to the specified block. + # + def conceal_page_top + margin_box.instance_variable_set :@y, (old_top = margin_box.absolute_top) + 0.0001 + yield + ensure + margin_box.instance_variable_set :@y, old_top + end + # Returns whether the current page is the last page in the document. # def last_page? diff --git a/spec/reference/image-svg-with-caption-scale-to-fit-page.pdf b/spec/reference/image-svg-with-caption-scale-to-fit-page.pdf Binary files differindex 10e975e6..6ca95fab 100644 --- a/spec/reference/image-svg-with-caption-scale-to-fit-page.pdf +++ b/spec/reference/image-svg-with-caption-scale-to-fit-page.pdf |
