summaryrefslogtreecommitdiff
diff options
context:
space:
mode:
authorDan Allen <dan.j.allen@gmail.com>2022-05-16 03:07:27 -0600
committerGitHub <noreply@github.com>2022-05-16 03:07:27 -0600
commit23a295c371e5b9da122996c55e9d064eb3df1909 (patch)
tree943a57cdfd66f23ebd0bc0eeafa0f2d535ac8736
parentc67f403bba9981dd34f27af773ff04a978cbcf2c (diff)
resolves #2176 look for block align roles on image instead of text align roles (PR #2177)
-rw-r--r--CHANGELOG.adoc1
-rw-r--r--lib/asciidoctor/pdf/converter.rb26
-rw-r--r--spec/image_spec.rb8
3 files changed, 18 insertions, 17 deletions
diff --git a/CHANGELOG.adoc b/CHANGELOG.adoc
index a4da5278..5f16ac9d 100644
--- a/CHANGELOG.adoc
+++ b/CHANGELOG.adoc
@@ -20,6 +20,7 @@ Bug Fixes::
* apply top line height padding to first line of text when text runs to top of next page (#2173)
* don't add entry to outline for notitle section if no content follows it
* don't add entry to TOC for notitle section if no content follows it
+* look for block align roles on image instead of text align roles (#2176)
== 2.0.0.beta.2 (2022-05-14) - @mojavelinux
diff --git a/lib/asciidoctor/pdf/converter.rb b/lib/asciidoctor/pdf/converter.rb
index 31373622..e1035556 100644
--- a/lib/asciidoctor/pdf/converter.rb
+++ b/lib/asciidoctor/pdf/converter.rb
@@ -1619,6 +1619,16 @@ module Asciidoctor
def convert_image node, opts = {}
target, image_format = (node.extend ::Asciidoctor::Image).target_and_format
+ unless image_format == 'pdf'
+ if (float_to = node.attr 'float') && ((BlockFloatNames.include? float_to) ? float_to : (float_to = nil))
+ alignment = float_to.to_sym
+ elsif (alignment = node.attr 'align')
+ alignment = (BlockAlignmentNames.include? alignment) ? alignment.to_sym : :left
+ elsif !(alignment = node.roles.reverse.find {|r| BlockAlignmentNames.include? r }&.to_sym)
+ alignment = @theme.image_align&.to_sym || :left
+ end
+ end
+
if image_format == 'gif' && !(defined? ::GMagick::Image)
log :warn, %(GIF image format not supported. Install the prawn-gmagick gem or convert #{target} to PNG.)
image_path = nil
@@ -1666,15 +1676,8 @@ module Asciidoctor
end
end
- return on_image_error :missing, node, target, opts unless image_path
+ return on_image_error :missing, node, target, (opts.merge align: alignment) unless image_path
- if (float_to = node.attr 'float') && ((BlockFloatNames.include? float_to) ? float_to : (float_to = nil))
- alignment = float_to.to_sym
- elsif (alignment = node.attr 'align')
- alignment = (BlockAlignmentNames.include? alignment) ? alignment.to_sym : :left
- else
- alignment = (resolve_text_align_from_role node.roles) || @theme.image_align&.to_sym || :left
- end
# TODO: support cover (aka canvas) image layout using "canvas" (or "cover") role
width = resolve_explicit_width node.attributes, bounds_width: (available_w = bounds.width), support_vw: true, use_fallback: true, constrain_to_bounds: true
# TODO: add `to_pt page_width` method to ViewportWidth type
@@ -1778,7 +1781,7 @@ module Asciidoctor
end
rescue => e
raise if ::StopIteration === e
- on_image_error :exception, node, target, (opts.merge message: %(could not embed image: #{image_path}; #{e.message}#{::Prawn::Errors::UnsupportedImageType === e && !(defined? ::GMagick::Image) ? '; install prawn-gmagick gem to add support' : ''}))
+ on_image_error :exception, node, target, (opts.merge align: alignment, message: %(could not embed image: #{image_path}; #{e.message}#{::Prawn::Errors::UnsupportedImageType === e && !(defined? ::GMagick::Image) ? '; install prawn-gmagick gem to add support' : ''}))
end
end
@@ -4801,10 +4804,7 @@ module Asciidoctor
alt_text_vars[:'/link'] = ''
end
theme_font :image_alt do
- alignment = (alignment = node.attr 'align') ?
- ((BlockAlignmentNames.include? alignment) ? alignment.to_sym : :left) :
- (resolve_text_align_from_role node.roles) || (@theme.image_align&.to_sym || :left)
- ink_prose alt_text_template % alt_text_vars, align: alignment, margin: 0, normalize: false, single_line: true
+ ink_prose alt_text_template % alt_text_vars, align: opts[:align], margin: 0, normalize: false, single_line: true
end
ink_caption node, category: :image, end: :bottom if node.title?
theme_margin :block, :bottom, (next_enclosed_block node) unless opts[:pinned]
diff --git a/spec/image_spec.rb b/spec/image_spec.rb
index c933e086..d0b7a2ec 100644
--- a/spec/image_spec.rb
+++ b/spec/image_spec.rb
@@ -85,8 +85,8 @@ describe 'Asciidoctor::PDF::Converter - Image' do
it 'should align alt text using alignment specified on image' do
[
['', image_align: nil],
- [',align=center', {}],
- [',role=text-center', {}],
+ ['align=center', {}],
+ ['role=center', {}],
['', image_align: 'center'],
].each do |attrlist, pdf_theme|
(expect do
@@ -172,9 +172,9 @@ describe 'Asciidoctor::PDF::Converter - Image' do
(expect images[0][:x]).to eql 48.24
end
- it 'should align block image as indicated by text alignment role on macro', visual: true do
+ it 'should align block image as indicated by block alignment role on macro', visual: true do
to_file = to_pdf_file <<~'EOS', 'image-align-right-attribute.pdf', attribute_overrides: { 'imagesdir' => examples_dir }
- [.text-right]
+ [.right]
image::wolpertinger.jpg[]
EOS