From 437cd7c45270ceccebf5db73f43d0b186a3bf093 Mon Sep 17 00:00:00 2001 From: Dan Allen Date: Sat, 1 Jun 2019 04:36:23 -0600 Subject: [PATCH] resolves #731 warn if image referenced in running content is missing (PR #1085) --- CHANGELOG.adoc | 1 + lib/asciidoctor-pdf/converter.rb | 30 +++++++++++++++++------------- 2 files changed, 18 insertions(+), 13 deletions(-) diff --git a/CHANGELOG.adoc b/CHANGELOG.adoc index 336b9d0de..18c7c43ca 100644 --- a/CHANGELOG.adoc +++ b/CHANGELOG.adoc @@ -30,6 +30,7 @@ For a detailed view of what has changed, refer to the {uri-repo}/commits/master[ * ensure index section doesn't get numbered when using Asciidoctor < 1.5.7 * add part signifier and part number to part title if partnums is set; allow signifier to be customized using part-signifier attribute (#597) * add support for the chapter-signifier attribute as the prefered alternative to chapter-label +* warn if the image referenced in the running content cannot be found (#731) == 1.5.0.alpha.17 (2019-04-23) - @mojavelinux diff --git a/lib/asciidoctor-pdf/converter.rb b/lib/asciidoctor-pdf/converter.rb index 2fff5f833..5b41ea8d8 100644 --- a/lib/asciidoctor-pdf/converter.rb +++ b/lib/asciidoctor-pdf/converter.rb @@ -2913,21 +2913,25 @@ def layout_running_content periphery, doc, opts = {} ColumnPositions.each do |position| unless (val = @theme[%(#{periphery}_#{side}_#{position}_content)]).nil_or_empty? # TODO support image URL (using resolve_image_path) - if (val.include? ':') && val =~ ImageAttributeValueRx && - ::File.readable?(path = (ThemeLoader.resolve_theme_asset $1, (doc.attr 'pdf-stylesdir'))) - attrs = (AttributeList.new $2).parse - col_width = colspec_dict[side][position][:width] - if (fit = attrs['fit']) == 'contain' - width = col_width - else - unless (width = resolve_explicit_width attrs, col_width) - # QUESTION should we lookup and scale intrinsic width if explicit width is not given? - # NOTE failure message will be reported later when image is rendered - width = (to_pt intrinsic_image_dimensions(path)[:width], :px) rescue 0 + if (val.include? ':') && val =~ ImageAttributeValueRx + if ::File.readable?(path = (ThemeLoader.resolve_theme_asset $1, (doc.attr 'pdf-stylesdir'))) + attrs = (AttributeList.new $2).parse + col_width = colspec_dict[side][position][:width] + if (fit = attrs['fit']) == 'contain' + width = col_width + else + unless (width = resolve_explicit_width attrs, col_width) + # QUESTION should we lookup and scale intrinsic width if explicit width is not given? + # NOTE failure message will be reported later when image is rendered + width = (to_pt intrinsic_image_dimensions(path)[:width], :px) rescue 0 + end + width = col_width if fit == 'scale-down' && width > col_width end - width = col_width if fit == 'scale-down' && width > col_width + side_content[position] = { path: path, width: width, fit: !!fit } + else + logger.warn %(image to embed not found or not readable: #{path}) + side_content[position] = val end - side_content[position] = { path: path, width: width, fit: !!fit } else side_content[position] = val end