From 710dacc4719d00a46882b878a147a5172eaed2be Mon Sep 17 00:00:00 2001 From: Dan Allen Date: Sun, 8 Sep 2019 23:28:05 -0600 Subject: [PATCH] resolves #1204 ensure line height of list items and toc entries is consistent (PR #1261) --- CHANGELOG.adoc | 1 + examples/chronicles-example.pdf | Bin 328091 -> 328715 bytes lib/asciidoctor-pdf/converter.rb | 18 ++++++++++-------- spec/list_spec.rb | 28 ++++++++++++++++++++++++++++ spec/toc_spec.rb | 20 ++++++++++++++++++++ 5 files changed, 59 insertions(+), 8 deletions(-) diff --git a/CHANGELOG.adoc b/CHANGELOG.adoc index 6e4d66508..5fed6bc85 100644 --- a/CHANGELOG.adoc +++ b/CHANGELOG.adoc @@ -8,6 +8,7 @@ For a detailed view of what has changed, refer to the {uri-repo}/commits/master[ == Unreleased * preserve indentation that uses tabs in verbatim blocks when tabsize is not set (#1258) +* use consistent line height for list items and toc entries if text is entirely monospace (#1204) * fix spacing between items in qanda list * expand home directory reference in theme name when value ends with .yml and no themedir is specified diff --git a/examples/chronicles-example.pdf b/examples/chronicles-example.pdf index 6b9bdf6ef790cb3c4a9641c971626723207196c4..b0bb530f6be6993c9c684678faf86bf59d50436f 100644 GIT binary patch delta 3269 zcmZuzKZu=05NG#$_moGpdKV0cyl5gZCLg;qyR*BfUCXo;H%oL@$ZnHO}|${qdXiHOKe6*_q$Y%x`ADSQ~$G zd3^nZQhx2EYELS4d9zBE@`r2c{r2fE)ei?Yc22*Tw|-JDv|Hb(bJgNAzy7IOX%Bs; zZV7Dt_6^nEzM(f)HKvWNub#`-pVaTQzu(c{Kf7`E-mxdh`r1a?xPSWPyj^L0%EcPo zWCrKo{?H$-_(ZkK7k^aaJh`d{`Qm-OIiy$iZSt@8^lHBQr~Y_osD^3K>ES{5nXjCyR`dD4^qFA{wKsFu$A)hDz3+RQ z|F0?L?H&D0{$NM1E0YhuS{=-fcJ#FhYug1G=d<53&0juO2ijW?_48_oDbyJAsn3|t z-XncnRko(?Myu^>f9n&f^33+V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8zU`k0Y9ZEThvz>+BQj&d~sT3J7W6w$ou_{?+oUzJf-J#1M?|Tiw;tx(}!CNFO0z&*&pN;78 zadPkraz$gFClp>fW+gauQ;}28+k!zV&JH_Yuz&{3a&3F42oHRptCpS)!KuqEWhn39sNVH+1$zip>i@d7R@7cRW|`fDry E14mtr2><{9 diff --git a/lib/asciidoctor-pdf/converter.rb b/lib/asciidoctor-pdf/converter.rb index 67ed749d0..f5e88e535 100644 --- a/lib/asciidoctor-pdf/converter.rb +++ b/lib/asciidoctor-pdf/converter.rb @@ -1078,7 +1078,7 @@ def convert_colist_item node end indent marker_width do - convert_content_for_list_item node, :colist, margin_bottom: @theme.outline_list_item_spacing + convert_content_for_list_item node, :colist, margin_bottom: @theme.outline_list_item_spacing, normalize_line_height: true end end @@ -1113,10 +1113,10 @@ def convert_dlist node else term_text = term.text end - layout_prose term_text, margin_top: 0, margin_bottom: @theme.description_list_term_spacing, align: :left + layout_prose term_text, margin_top: 0, margin_bottom: @theme.description_list_term_spacing, align: :left, normalize_line_height: true end indent(@theme.description_list_description_indent || 0) do - convert_content_for_list_item desc, :dlist_desc + convert_content_for_list_item desc, :dlist_desc, normalize_line_height: true end if desc end end @@ -1313,9 +1313,9 @@ def convert_outline_list_item node, list, opts = {} end if complex - convert_content_for_list_item node, list_type, opts + convert_content_for_list_item node, list_type, (opts.merge normalize_line_height: true) else - convert_content_for_list_item node, list_type, (opts.merge margin_bottom: @theme.outline_list_item_spacing) + convert_content_for_list_item node, list_type, (opts.merge margin_bottom: @theme.outline_list_item_spacing, normalize_line_height: true) end end @@ -2236,7 +2236,7 @@ def convert_index_list_item term end text = %(#{text}, #{pagenums.join ', '}) end - layout_prose text, align: :left, margin: 0 + layout_prose text, align: :left, margin: 0, normalize_line_height: true term.subterms.each do |subterm| indent @theme.description_list_description_indent do @@ -2700,6 +2700,7 @@ def layout_prose string, opts = {} string = %(#{string}) end margin_top top_margin + string = ZeroWidthSpace + string if opts.delete :normalize_line_height typeset_text string, calc_line_metrics((opts.delete :line_height) || @theme.base_line_height), { color: @font_color, # NOTE normalize makes endlines soft (replaces "\n" with ' ') @@ -2748,7 +2749,8 @@ def layout_caption subject, opts = {} margin_top: margin[:top], margin_bottom: margin[:bottom], align: (@theme.caption_align || @base_align).to_sym, - normalize: false + normalize: false, + normalize_line_height: true }.merge(opts) if side == :top && @theme.caption_border_bottom_color stroke_horizontal_rule @theme.caption_border_bottom_color @@ -2830,7 +2832,7 @@ def layout_toc_level sections, num_levels, line_metrics, dot_leader, num_front_m end sections.each do |sect| theme_font :toc, level: (sect.level + 1) do - sect_title = @text_transform ? (transform_text sect.numbered_title, @text_transform) : sect.numbered_title + sect_title = ZeroWidthSpace + (@text_transform ? (transform_text sect.numbered_title, @text_transform) : sect.numbered_title) # NOTE only write section title (excluding dots and page number) if this is a dry run if scratch? # FIXME use layout_prose diff --git a/spec/list_spec.rb b/spec/list_spec.rb index 01f54fa03..6acef1c31 100644 --- a/spec/list_spec.rb +++ b/spec/list_spec.rb @@ -91,6 +91,20 @@ (expect pdf.lines).to eql [%(\u25cadiamond), %(\u25ccdotted circle), %(\u25a1white square)] end + it 'should use consistent line height even if list item is entirely monospace' do + pdf = to_pdf <<~'EOS', analyze: true + * foo + * `mono` + * bar + EOS + + mark_texts = pdf.find_text '•' + (expect mark_texts).to have_size 3 + first_to_second_spacing = (mark_texts[0][:y] - mark_texts[1][:y]).round 2 + second_to_third_spacing = (mark_texts[1][:y] - mark_texts[2][:y]).round 2 + (expect first_to_second_spacing).to eql second_to_third_spacing + end + it 'should apply correct margin if primary text of list item is blank' do pdf = to_pdf <<~'EOS', analyze: true * foo @@ -188,6 +202,20 @@ (expect pdf.lines).to eql ['i.one', 'ii.two', 'iii.three'] end + it 'should use consistent line height even if list item is entirely monospace' do + pdf = to_pdf <<~'EOS', analyze: true + . foo + . `mono` + . bar + EOS + + mark_texts = pdf.text.select {|it| it[:string].end_with? '.' } + (expect mark_texts).to have_size 3 + first_to_second_spacing = (mark_texts[0][:y] - mark_texts[1][:y]).round 2 + second_to_third_spacing = (mark_texts[1][:y] - mark_texts[2][:y]).round 2 + (expect first_to_second_spacing).to eql second_to_third_spacing + end + it 'should align list numbers to right and extend towards left margin' do pdf = to_pdf <<~'EOS', analyze: true . one diff --git a/spec/toc_spec.rb b/spec/toc_spec.rb index 6ea4f6344..b9b1aa471 100644 --- a/spec/toc_spec.rb +++ b/spec/toc_spec.rb @@ -36,6 +36,26 @@ (expect pdf.find_text string: 'Introduction', page_number: 3).not_to be_empty end + it 'should space items in toc evently even if title is entirely monospace' do + pdf = to_pdf <<~'EOS', doctype: :book, analyze: true + = Document Title + :toc: + + == Beginning + + == `Middle` + + == End + EOS + (expect pdf.find_text string: 'Table of Contents', page_number: 2).not_to be_empty + beginning_pagenum_text = (pdf.find_text string: '1', page_number: 2)[0] + middle_pagenum_text = (pdf.find_text string: '2', page_number: 2)[0] + end_pagenum_text = (pdf.find_text string: '3', page_number: 2)[0] + beginning_to_middle_spacing = (beginning_pagenum_text[:y] - middle_pagenum_text[:y]).round 2 + middle_to_end_spacing = (middle_pagenum_text[:y] - end_pagenum_text[:y]).round 2 + (expect beginning_to_middle_spacing).to eql middle_to_end_spacing + end + it 'should only include preface in toc if preface-title is set' do input = <<~'EOS' = Document Title