summaryrefslogtreecommitdiff
path: root/spec/spec_helper.rb
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 /spec/spec_helper.rb
parentc96a467e5f68237d98d240d91ea3614145f9fde0 (diff)
use enhanced RectInspector in test suite that can pick up fill and stroke color
Diffstat (limited to 'spec/spec_helper.rb')
-rw-r--r--spec/spec_helper.rb50
1 files changed, 49 insertions, 1 deletions
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