From b50d46be56b803d66c056838b7ffab51d9d5ea59 Mon Sep 17 00:00:00 2001 From: Dan Allen Date: Fri, 20 May 2022 03:19:45 -0600 Subject: resolves #2193 fix size and position of full height inline image so it fits within available height of page - always use bounds height as max height for inline image - subtract top padding from line metrics from ascender for full height image - don't protect bottom gutter if line contains a full height image - add tests --- spec/image_spec.rb | 46 ++++++++++++++++++++- .../image-inline-in-block-scale-down-height.pdf | Bin 0 -> 26063 bytes spec/reference/image-inline-scale-down-height.pdf | Bin 24180 -> 23834 bytes 3 files changed, 45 insertions(+), 1 deletion(-) create mode 100644 spec/reference/image-inline-in-block-scale-down-height.pdf (limited to 'spec') diff --git a/spec/image_spec.rb b/spec/image_spec.rb index d0b7a2ec..4305c2bb 100644 --- a/spec/image_spec.rb +++ b/spec/image_spec.rb @@ -507,7 +507,23 @@ describe 'Asciidoctor::PDF::Converter - Image' do pdf = to_pdf input, analyze: :line image_h = pdf.lines[1][:to][:y] - pdf.lines[1][:from][:y] - (expect image_h).to be_within(1).of(350) + (expect image_h).to eql 350.0 + end + + it 'should scale down inline SVG to fit height of next page' do + input = <<~'EOS' + :pdf-page-size: 200x350 + :pdf-page-margin: 0 + + before + + image:tall.svg[] + EOS + + pdf = to_pdf input, analyze: :line + (expect pdf.lines.map {|it| it[:page_number] }.uniq).to eql [2] + image_h = pdf.lines[1][:to][:y] - pdf.lines[1][:from][:y] + (expect image_h).to eql 350.0 end it 'should display text inside link' do @@ -1615,6 +1631,34 @@ describe 'Asciidoctor::PDF::Converter - Image' do (expect line1_spacing).to eql line2_spacing end + it 'should scale image down to fit available height on next page', visual: true do + to_file = to_pdf_file <<~'EOS', 'image-inline-pushed-scale-down-height.pdf' + :pdf-page-size: A6 + :pdf-page-layout: landscape + + before + + image:cover.jpg[] + EOS + + to_file = to_pdf_file %(image::#{to_file}[page=2]), 'image-inline-pushed-scale-down-height-2.pdf' + + (expect to_file).to visually_match 'image-inline-scale-down-height.pdf' + end + + it 'should scale image down to fit available height inside delimited block', visual: true do + to_file = to_pdf_file <<~'EOS', 'image-inline-in-block-scale-down-height.pdf' + :pdf-page-size: A6 + :pdf-page-layout: landscape + + **** + image:cover.jpg[] + **** + EOS + + (expect to_file).to visually_match 'image-inline-in-block-scale-down-height.pdf' + end + it 'should not scale image if pdfwidth matches intrinsic width' do pdf = to_pdf <<~'EOS', analyze: :image see image:tux.png[pdfwidth=204] run diff --git a/spec/reference/image-inline-in-block-scale-down-height.pdf b/spec/reference/image-inline-in-block-scale-down-height.pdf new file mode 100644 index 00000000..1db693d4 Binary files /dev/null and b/spec/reference/image-inline-in-block-scale-down-height.pdf differ diff --git a/spec/reference/image-inline-scale-down-height.pdf b/spec/reference/image-inline-scale-down-height.pdf index 562c1914..4cbc9a2f 100644 Binary files a/spec/reference/image-inline-scale-down-height.pdf and b/spec/reference/image-inline-scale-down-height.pdf differ -- cgit v1.2.3