summaryrefslogtreecommitdiff
diff options
context:
space:
mode:
authorDan Allen <dan.j.allen@gmail.com>2022-06-14 01:38:29 -0600
committerDan Allen <dan.j.allen@gmail.com>2022-06-14 01:38:29 -0600
commitb68cfc70097e52e548009b1f7a498917aaa34d58 (patch)
treee1c40aa1c8bef09ec11cee612bcacf9a7455e874
parentc96a467e5f68237d98d240d91ea3614145f9fde0 (diff)
use enhanced RectInspector in test suite that can pick up fill and stroke color
-rw-r--r--spec/cover_page_spec.rb2
-rw-r--r--spec/formatted_text_formatter_spec.rb4
-rw-r--r--spec/spec_helper.rb50
3 files changed, 53 insertions, 3 deletions
diff --git a/spec/cover_page_spec.rb b/spec/cover_page_spec.rb
index 3d810b74..3feab3a3 100644
--- a/spec/cover_page_spec.rb
+++ b/spec/cover_page_spec.rb
@@ -402,7 +402,7 @@ describe 'Asciidoctor::PDF::Converter - Cover Page' do
pdf = to_pdf input, analyze: :rect
rects = pdf.rectangles
(expect rects).to have_size 1
- (expect rects[0]).to eql point: [0.0, 0.0], width: 612.0, height: 792.0
+ (expect rects[0]).to eql point: [0.0, 0.0], width: 612.0, height: 792.0, fill_color: '0000FF'
pdf = to_pdf input, analyze: true
(expect pdf.pages).to have_size 2
diff --git a/spec/formatted_text_formatter_spec.rb b/spec/formatted_text_formatter_spec.rb
index d9cb3b78..f37968d7 100644
--- a/spec/formatted_text_formatter_spec.rb
+++ b/spec/formatted_text_formatter_spec.rb
@@ -1029,8 +1029,10 @@ describe Asciidoctor::PDF::FormattedText::Formatter do
role_box_border_color: '333333',
role_box_border_width: 0.5,
}
- rects = (to_pdf '[.box]#text in a box# needs more work', pdf_theme: pdf_theme, analyze: :rect).rectangles
+ rects = (to_pdf '[.box]#text in a box# needs more work', pdf_theme: pdf_theme, analyze: :rect).rects
(expect rects).to have_size 1
+ (expect rects[0][:stroke_color]).to eql '333333'
+ (expect rects[0][:stroke_width]).to eql 0.5
end
it 'should allow theme to set only border for custom role', visual: true do
diff --git a/spec/spec_helper.rb b/spec/spec_helper.rb
index 1658bb4c..64e1c889 100644
--- a/spec/spec_helper.rb
+++ b/spec/spec_helper.rb
@@ -286,6 +286,54 @@ class LineInspector < PDF::Inspector
end
end
+class RectInspector < PDF::Inspector
+ attr_reader :rectangles
+
+ alias rects rectangles
+
+ def initialize
+ @next_rectangle = nil
+ @rectangles = []
+ @fill_color = @stroke_color = @line_width = nil
+ end
+
+ # re
+ def append_rectangle x, y, width, height
+ @next_rectangle = { point: [x, y], width: width, height: height }
+ end
+
+ # f
+ def fill_path_with_nonzero
+ if @next_rectangle
+ @rectangles << (@next_rectangle.merge fill_color: @fill_color)
+ @next_rectangle = nil
+ end
+ end
+
+ # w
+ def set_line_width line_width
+ @line_width = line_width
+ end
+
+ # S
+ def stroke_path
+ if @next_rectangle
+ @rectangles << (@next_rectangle.merge stroke_color: @stroke_color, stroke_width: @line_width)
+ @next_rectangle = nil
+ end
+ end
+
+ # scn
+ def set_color_for_nonstroking_and_special *params
+ @fill_color = params.size == 4 ? params.map {|it| it * 100 } : params.map {|it| sprintf '%02X', (it.to_f * 255).round }.join
+ end
+
+ # SCN
+ def set_color_for_stroking_and_special *params
+ @stroke_color = params.size == 4 ? params.map {|it| it * 100 } : params.map {|it| sprintf '%02X', (it.to_f * 255).round }.join
+ end
+end
+
module TareFirstPageContentStreamNoop
def tare_first_page_content_stream
yield
@@ -397,7 +445,7 @@ RSpec.configure do |config|
image: ImageInspector,
line: LineInspector,
page: PDF::Inspector::Page,
- rect: PDF::Inspector::Graphics::Rectangle,
+ rect: RectInspector,
text: EnhancedPDFTextInspector,
}).default = EnhancedPDFTextInspector