summaryrefslogtreecommitdiff
diff options
context:
space:
mode:
authorDan Allen <dan.j.allen@gmail.com>2022-05-02 03:45:26 -0600
committerGitHub <noreply@github.com>2022-05-02 03:45:26 -0600
commitecba0ed587cbccda8995615878e3d49c2448656b (patch)
treed7ab48ccaafed34f16a7d838e6522b9f49048cb3
parentc332c9fdd105543d4b675a0c8748e4ff5c9ae091 (diff)
resolves #2119 allow border width of block image to be specified as an array (PR #2122)
-rw-r--r--CHANGELOG.adoc1
-rw-r--r--lib/asciidoctor/pdf/converter.rb2
-rw-r--r--spec/image_spec.rb30
3 files changed, 32 insertions, 1 deletions
diff --git a/CHANGELOG.adoc b/CHANGELOG.adoc
index b41a0660..6c49dae7 100644
--- a/CHANGELOG.adoc
+++ b/CHANGELOG.adoc
@@ -14,6 +14,7 @@ Enhancements::
Bug Fixes::
+* allow border width of block image to be specified as an array (1, 2, or 4 values) (#2119)
* rename `delete_page` extension method to `delete_current_page` to avoid conflict with incompatible method on `Prawn::Document`
== 2.0.0.alpha.3 (2022-05-01) - @mojavelinux
diff --git a/lib/asciidoctor/pdf/converter.rb b/lib/asciidoctor/pdf/converter.rb
index 6f291b75..82ef6162 100644
--- a/lib/asciidoctor/pdf/converter.rb
+++ b/lib/asciidoctor/pdf/converter.rb
@@ -1653,7 +1653,7 @@ module Asciidoctor
end
def draw_image_border top, w, h, alignment
- if @theme.image_border_width > 0 && @theme.image_border_color
+ if (Array @theme.image_border_width).any? {|it| it&.> 0 } && @theme.image_border_color
if (@theme.image_border_fit || 'content') == 'auto'
bb_width = bounds.width
elsif alignment == :center
diff --git a/spec/image_spec.rb b/spec/image_spec.rb
index 55d72aba..a6a89650 100644
--- a/spec/image_spec.rb
+++ b/spec/image_spec.rb
@@ -2140,6 +2140,36 @@ describe 'Asciidoctor::PDF::Converter - Image' do
(expect pdf.lines.select {|it| it[:color] == 'DEDEDE' }).to be_empty
end
+ it 'should allow border on block image to be specified per edge' do
+ pdf_theme = {
+ image_border_width: [1, 2, 3, 4],
+ image_border_color: 'DEDEDE',
+ }
+ pdf = to_pdf <<~'EOS', pdf_theme: pdf_theme, analyze: :line
+ image::square.png[]
+ EOS
+ lines = pdf.lines
+ (expect lines).to have_size 4
+ (expect lines.map {|it| it[:width] }.sort).to eql [1, 2, 3, 4]
+ (expect lines.map {|it| it[:color] }.uniq).to eql %w(DEDEDE)
+ end
+
+ it 'should allow border on block image to be specified on ends and sides' do
+ pdf_theme = {
+ image_border_width: [4, 1],
+ image_border_color: 'DEDEDE',
+ }
+ pdf = to_pdf <<~'EOS', pdf_theme: pdf_theme, analyze: :line
+ image::square.png[]
+ EOS
+ lines = pdf.lines
+ (expect lines).to have_size 4
+ (expect lines.map {|it| it[:width] }.sort).to eql [1, 1, 4, 4]
+ (expect lines.select {|it| it[:width] == 4 && it[:from][:y] == it[:to][:y] }).to have_size 2
+ (expect lines.select {|it| it[:width] == 1 && it[:from][:x] == it[:to][:x] }).to have_size 2
+ (expect lines.map {|it| it[:color] }.uniq).to eql %w(DEDEDE)
+ end
+
it 'should draw border around inline image if border width and border color are set in the theme', visual: true do
pdf_theme = {
role_enclose_border_width: 0.5,