asciidoctor-pdf 2.0.0.beta.2 → 2.0.0.rc.1

Sign up to get free protection for your applications and to get access to all the features.
@@ -0,0 +1,31 @@
1
+ # frozen_string_literal: true
2
+
3
+ Asciidoctor::AbstractBlock.prepend (Module.new do
4
+ def empty?
5
+ blocks.empty?
6
+ end
7
+
8
+ def first_child
9
+ blocks[0]
10
+ end
11
+
12
+ def last_child
13
+ blocks[-1]
14
+ end
15
+
16
+ def last_child?
17
+ self == parent.blocks[-1]
18
+ end
19
+
20
+ def next_sibling
21
+ (siblings = parent.blocks)[(siblings.index self) + 1]
22
+ end
23
+
24
+ def previous_sibling
25
+ (self_idx = (siblings = parent.blocks).index self) > 0 ? siblings[self_idx - 1] : nil
26
+ end
27
+
28
+ def remove
29
+ parent.blocks.delete self
30
+ end
31
+ end)
@@ -1,6 +1,7 @@
1
1
  # frozen_string_literal: true
2
2
 
3
3
  # NOTE: these are either candidates for inclusion in Asciidoctor core or backports
4
+ require_relative 'asciidoctor/abstract_block'
4
5
  require_relative 'asciidoctor/document'
5
6
  require_relative 'asciidoctor/section'
6
7
  require_relative 'asciidoctor/list'
@@ -5,12 +5,16 @@ Prawn::Document::ColumnBox.prepend (Module.new do
5
5
  stretchy? ? @parent.absolute_bottom : super
6
6
  end
7
7
 
8
- def move_past_bottom *_args
9
- initial_page = @document.page
10
- super
11
- if (page = @document.page) != initial_page && page.margins != initial_page.margins
12
- @document.bounds = self.class.new @document, @parent, (margin_box = @document.margin_box).absolute_top_left,
8
+ def move_past_bottom
9
+ (doc = @document).y = @y
10
+ return if (@current_column = (@current_column + 1) % @columns) > 0
11
+ @y = (par = @parent).absolute_top if @reflow_margins
12
+ initial_margins = doc.page.margins
13
+ par.move_past_bottom
14
+ if doc.page.margins != initial_margins
15
+ doc.bounds = self.class.new doc, par, (margin_box = doc.margin_box).absolute_top_left,
13
16
  columns: @columns, reflow_margins: true, spacer: @spacer, width: margin_box.width
14
17
  end
18
+ nil
15
19
  end
16
20
  end)
@@ -429,14 +429,17 @@ module Asciidoctor
429
429
 
430
430
  # NOTE: override built-in fill_formatted_text_box to insert leading before second line when :first_line is true
431
431
  def fill_formatted_text_box text, options
432
+ if (initial_gap = options[:initial_gap]) && (first_text = text[0]) && first_text[:from_page] != page_number
433
+ self.y -= initial_gap
434
+ end
432
435
  merge_text_box_positioning_options options
433
436
  box = ::Prawn::Text::Formatted::Box.new text, options
434
437
  remaining_text = box.render
435
438
  @no_text_printed = box.nothing_printed?
436
439
  @all_text_printed = box.everything_printed?
440
+ remaining_text[0][:from_page] = page_number unless remaining_text.empty?
437
441
 
438
- if ((defined? @final_gap) && @final_gap) ||
439
- (options[:first_line] && (options[:final_gap] || !(@no_text_printed || @all_text_printed)))
442
+ if @final_gap || (options[:first_line] && !(@no_text_printed || @all_text_printed))
440
443
  self.y -= box.height + box.line_gap + box.leading
441
444
  else
442
445
  self.y -= box.height
@@ -455,7 +458,7 @@ module Asciidoctor
455
458
  # remaining lines (which is the default behavior in Prawn).
456
459
  def text_with_formatted_first_line string, first_line_options, options
457
460
  if (first_line_font_color = first_line_options.delete :color)
458
- other_lines_font_color, options[:color] = options[:color], first_line_font_color
461
+ remaining_lines_font_color, options[:color] = options[:color], first_line_font_color
459
462
  end
460
463
  fragments = parse_text string, options
461
464
  # NOTE: the low-level APIs we're using don't recognize the :styles option, so we must resolve
@@ -468,19 +471,19 @@ module Asciidoctor
468
471
  end
469
472
  first_line_text_transform = first_line_options.delete :text_transform
470
473
  options = options.merge document: self
474
+ @final_gap = final_gap = options.delete :final_gap
471
475
  text_indent = options.delete :indent_paragraphs
472
476
  # QUESTION: should we merge more carefully here? (hand-select keys?)
473
477
  first_line_options = (options.merge first_line_options).merge single_line: true, first_line: true
474
478
  box = ::Prawn::Text::Formatted::Box.new fragments, first_line_options
475
479
  if text_indent
476
- remaining_fragments = indent text_indent do
477
- box.render dry_run: true
478
- end
480
+ remaining_fragments = indent(text_indent) { box.render dry_run: true }
479
481
  else
480
482
  remaining_fragments = box.render dry_run: true
481
483
  end
484
+ remaining_fragments.empty? ? (remaining_fragments = nil) : (remaining_fragments[0][:from_page] = page_number)
482
485
  if first_line_text_transform
483
- # NOTE: applying text transform here could alter the wrapping, so we need to isolate first line and shrink to fit
486
+ # NOTE: applying text transform here could alter the wrapping, so isolate first line and shrink it to fit
484
487
  first_line_text = (box.instance_variable_get :@printed_lines)[0]
485
488
  unless first_line_text == fragments[0][:text]
486
489
  original_fragments, fragments = fragments, []
@@ -496,17 +499,16 @@ module Asciidoctor
496
499
  end
497
500
  fragments.each {|fragment| fragment[:text] = transform_text fragment[:text], first_line_text_transform }
498
501
  first_line_options[:overflow] = :shrink_to_fit
499
- first_line_options[:final_gap] = first_line_options[:force_justify] = true unless remaining_fragments.empty?
502
+ @final_gap = first_line_options[:force_justify] = true if remaining_fragments
500
503
  end
501
504
  if text_indent
502
- indent text_indent do
503
- fill_formatted_text_box fragments, first_line_options
504
- end
505
+ indent(text_indent) { fill_formatted_text_box fragments, first_line_options }
505
506
  else
506
507
  fill_formatted_text_box fragments, first_line_options
507
508
  end
508
- unless remaining_fragments.empty?
509
- options[:color] = other_lines_font_color if first_line_font_color
509
+ if remaining_fragments
510
+ options[:color] = remaining_lines_font_color if first_line_font_color
511
+ @final_gap = final_gap if first_line_text_transform
510
512
  remaining_fragments = fill_formatted_text_box remaining_fragments, options
511
513
  draw_remaining_formatted_text_on_new_pages remaining_fragments, options
512
514
  end
@@ -589,7 +591,7 @@ module Asciidoctor
589
591
  p_top, p_right, p_bottom, p_left = expand_padding_value padding
590
592
  # logic is intentionally inlined
591
593
  begin
592
- if node && ((last_block = node).content_model != :compound || (last_block = node.blocks[-1])&.context == :paragraph)
594
+ if node && ((last_block = node).content_model != :compound || (last_block = node.last_child)&.context == :paragraph)
593
595
  @bottom_gutters << { last_block => p_bottom }
594
596
  else
595
597
  @bottom_gutters << {}
@@ -599,7 +601,7 @@ module Asciidoctor
599
601
  bounds.add_right_padding p_right
600
602
  yield
601
603
  ensure
602
- cursor > p_bottom ? (move_down p_bottom) : reference_bounds.move_past_bottom unless at_page_top?
604
+ cursor > p_bottom ? (move_down p_bottom) : bounds.move_past_bottom unless at_page_top?
603
605
  @bottom_gutters.pop
604
606
  bounds.subtract_left_padding p_left
605
607
  bounds.subtract_right_padding p_right
@@ -943,7 +945,7 @@ module Asciidoctor
943
945
  # if the current page is the last page of the document. Otherwise, it simply
944
946
  # advances to the next existing page.
945
947
  def advance_page options = {}
946
- last_page? ? (start_new_page options) : (go_to_page page_number + 1)
948
+ !options.empty? && last_page? ? (start_new_page options) : bounds.move_past_bottom
947
949
  end
948
950
 
949
951
  # Start a new page without triggering the on_page_create callback
@@ -952,14 +954,14 @@ module Asciidoctor
952
954
  perform_discretely { start_new_page options }
953
955
  end
954
956
 
955
- # Grouping
957
+ # Scratch
956
958
 
957
- def allocate_prototype
958
- @prototype = create_prototype { ::Marshal.load ::Marshal.dump self }
959
+ def allocate_scratch_prototype
960
+ @scratch_prototype = create_scratch_prototype { ::Marshal.load ::Marshal.dump self }
959
961
  end
960
962
 
961
963
  def scratch
962
- @scratch ||= ((Marshal.load Marshal.dump @prototype).send :init_scratch, self)
964
+ @scratch ||= ((Marshal.load Marshal.dump @scratch_prototype).send :init_scratch, self)
963
965
  end
964
966
 
965
967
  def scratch?
@@ -2,6 +2,6 @@
2
2
 
3
3
  module Asciidoctor
4
4
  module PDF
5
- VERSION = '2.0.0.beta.2'
5
+ VERSION = '2.0.0.rc.1'
6
6
  end
7
7
  end
metadata CHANGED
@@ -1,7 +1,7 @@
1
1
  --- !ruby/object:Gem::Specification
2
2
  name: asciidoctor-pdf
3
3
  version: !ruby/object:Gem::Version
4
- version: 2.0.0.beta.2
4
+ version: 2.0.0.rc.1
5
5
  platform: ruby
6
6
  authors:
7
7
  - Dan Allen
@@ -9,7 +9,7 @@ authors:
9
9
  autorequire:
10
10
  bindir: bin
11
11
  cert_chain: []
12
- date: 2022-05-14 00:00:00.000000000 Z
12
+ date: 2022-05-17 00:00:00.000000000 Z
13
13
  dependencies:
14
14
  - !ruby/object:Gem::Dependency
15
15
  name: asciidoctor
@@ -246,6 +246,7 @@ files:
246
246
  - lib/asciidoctor/pdf/converter.rb
247
247
  - lib/asciidoctor/pdf/ext.rb
248
248
  - lib/asciidoctor/pdf/ext/asciidoctor.rb
249
+ - lib/asciidoctor/pdf/ext/asciidoctor/abstract_block.rb
249
250
  - lib/asciidoctor/pdf/ext/asciidoctor/document.rb
250
251
  - lib/asciidoctor/pdf/ext/asciidoctor/image.rb
251
252
  - lib/asciidoctor/pdf/ext/asciidoctor/list.rb