summaryrefslogtreecommitdiff
diff options
context:
space:
mode:
authorDan Allen <dan.j.allen@gmail.com>2022-08-27 23:49:00 -0600
committerDan Allen <dan.j.allen@gmail.com>2022-08-28 00:49:19 -0600
commit603dd2d46cb744adbdfd1326c13a7cb6b9b4ffa5 (patch)
tree4595f21c496316744ea353efef3f25fcb7e7532c
parent2c2e6652fdcb16e26f52ea565bddd93cb2a82040 (diff)
don't force justify first line of abstract if it ends with a hard break
-rw-r--r--CHANGELOG.adoc1
-rw-r--r--lib/asciidoctor/pdf/ext/prawn/extensions.rb15
-rw-r--r--spec/abstract_spec.rb22
-rw-r--r--spec/reference/abstract-first-line-text-transform-hard-break.pdfbin0 -> 17688 bytes
4 files changed, 33 insertions, 5 deletions
diff --git a/CHANGELOG.adoc b/CHANGELOG.adoc
index 08ef7d09..1625a9bc 100644
--- a/CHANGELOG.adoc
+++ b/CHANGELOG.adoc
@@ -22,6 +22,7 @@ Bug Fixes::
* keep caret between items in menu macro with previous item if items wrap
* draw border on heading (section title or discrete heading) if it is advanced to next page (#2322)
+* don't force justify first line of abstract if it ends with a hard break
== 2.3.0 (2022-08-16) - @mojavelinux
diff --git a/lib/asciidoctor/pdf/ext/prawn/extensions.rb b/lib/asciidoctor/pdf/ext/prawn/extensions.rb
index 646ad814..c8190fe8 100644
--- a/lib/asciidoctor/pdf/ext/prawn/extensions.rb
+++ b/lib/asciidoctor/pdf/ext/prawn/extensions.rb
@@ -500,14 +500,14 @@ module Asciidoctor
end
if first_line_text_transform
# NOTE: applying text transform here could alter the wrapping, so isolate first line and shrink it to fit
- first_line_text = (box.instance_variable_get :@printed_lines)[0]
- unless first_line_text == fragments[0][:text]
+ first_printed_line = (box.instance_variable_get :@printed_lines)[0]
+ unless first_printed_line == fragments[0][:text]
original_fragments, fragments = fragments, []
original_fragments.reduce '' do |traced, fragment|
fragments << fragment
# NOTE: we could just do a length comparison here
- if (traced += fragment[:text]).start_with? first_line_text
- fragment[:text] = fragment[:text][0...-(traced.length - first_line_text.length)]
+ if (traced += fragment[:text]).start_with? first_printed_line
+ fragment[:text] = fragment[:text][0...-(traced.length - first_printed_line.length)]
break
end
traced
@@ -515,7 +515,12 @@ module Asciidoctor
end
fragments.each {|fragment| fragment[:text] = transform_text fragment[:text], first_line_text_transform }
first_line_options[:overflow] = :shrink_to_fit
- @final_gap = first_line_options[:force_justify] = true if remaining_fragments
+ if remaining_fragments
+ @final_gap = true
+ if first_line_options[:align] == :justify && (box.instance_variable_get :@arranger).consumed[-1]&.[](:text) != ?\n
+ first_line_options[:force_justify] = true
+ end
+ end
end
if text_indent
indent(text_indent) { fill_formatted_text_box fragments, first_line_options }
diff --git a/spec/abstract_spec.rb b/spec/abstract_spec.rb
index 9ed93edb..efffcabb 100644
--- a/spec/abstract_spec.rb
+++ b/spec/abstract_spec.rb
@@ -235,6 +235,28 @@ describe 'Asciidoctor::PDF::Converter - Abstract' do
(expect to_file).to visually_match 'abstract-first-line-text-transform.pdf'
end
+ it 'should not force justify first line of abstract with text transform if ends with hard break', visual: true do
+ pdf_theme = { abstract_first_line_text_transform: 'uppercase' }
+ to_file = to_pdf_file <<~'EOS', 'abstract-first-line-text-transform-hard-break.pdf', pdf_theme: pdf_theme
+ [abstract]
+ Welcome young Jedi. +
+ This tutorial will show you the way.
+ EOS
+
+ (expect to_file).to visually_match 'abstract-first-line-text-transform-hard-break.pdf'
+ end
+
+ it 'should not force justify first line of abstract with text transform if not justified', visual: true do
+ pdf_theme = { abstract_text_align: 'left', abstract_first_line_text_transform: 'uppercase' }
+ to_file = to_pdf_file <<~'EOS', 'abstract-first-line-text-transform-hard-break-not-justified.pdf', pdf_theme: pdf_theme
+ [abstract]
+ Welcome young Jedi. +
+ This tutorial will show you the way.
+ EOS
+
+ (expect to_file).to visually_match 'abstract-first-line-text-transform-hard-break.pdf'
+ end
+
it 'should not crash when applying text transform to first line of abstract inside column box' do
backend = nil
create_class (Asciidoctor::Converter.for 'pdf') do
diff --git a/spec/reference/abstract-first-line-text-transform-hard-break.pdf b/spec/reference/abstract-first-line-text-transform-hard-break.pdf
new file mode 100644
index 00000000..8f25a95e
--- /dev/null
+++ b/spec/reference/abstract-first-line-text-transform-hard-break.pdf
Binary files differ