test/hexapdf/layout/test_style.rb in hexapdf-0.7.0 vs test/hexapdf/layout/test_style.rb in hexapdf-0.8.0
- old
+ new
@@ -155,17 +155,25 @@
describe "draw" do
before do
@canvas = HexaPDF::Document.new.pages.add.canvas
end
+ it "draws nothing if no border is defined" do
+ border = create_border
+ border.draw(@canvas, 0, 0, 100, 100)
+ assert_operators(@canvas.contents, [])
+ end
+
describe "simple - same width, color and style on all sides" do
it "works with style solid" do
border = create_border(width: 10, color: 0.5, style: :solid)
border.draw(@canvas, 0, 0, 100, 100)
assert_operators(@canvas.contents, [[:save_graphics_state],
[:set_device_gray_stroking_color, [0.5]],
[:set_line_width, [10]],
+ [:append_rectangle, [0, 0, 100, 100]],
+ [:clip_path_non_zero], [:end_path],
[:append_rectangle, [5, 5, 90, 90]],
[:stroke_path],
[:restore_graphics_state]])
end
@@ -338,9 +346,75 @@
[:set_device_gray_stroking_color, [0.75]], [:set_line_width, [30]],
[:set_line_cap_style, [1]], [:set_line_dash_pattern, [[0, 42.5], 27.5]],
[:move_to, [15, 0]], [:line_to, [15, 200]], [:stroke_path],
[:restore_graphics_state], [:restore_graphics_state]]
assert_operators(@canvas.contents, ops)
+ end
+ end
+
+ describe "border width greater than edge length" do
+ it "works for solid borders" do
+ border = create_border(width: 100, style: :solid)
+ border.draw(@canvas, 0, 0, 10, 10)
+ assert_operators(@canvas.contents, [[:save_graphics_state],
+ [:set_line_width, [100]],
+ [:append_rectangle, [0, 0, 10, 10]],
+ [:clip_path_non_zero], [:end_path],
+ [:append_rectangle, [50, 50, -90, -90]],
+ [:stroke_path],
+ [:restore_graphics_state]])
+ end
+
+ it "works for dashed borders" do
+ border = create_border(width: 100, style: :dashed)
+ border.draw(@canvas, 0, 0, 10, 10)
+ assert_operators(@canvas.contents, [[:save_graphics_state],
+ [:set_line_width, [100]],
+ [:set_line_cap_style, [2]],
+ [:append_rectangle, [0, 0, 10, 10]],
+ [:clip_path_non_zero], [:end_path],
+ [:set_line_dash_pattern, [[100, 0], 50]],
+ [:move_to, [0, -40]], [:line_to, [10, -40]],
+ [:move_to, [10, 50]], [:line_to, [0, 50]],
+ [:stroke_path],
+ [:move_to, [-40, 10]], [:line_to, [-40, 0]],
+ [:move_to, [50, 0]], [:line_to, [50, 10]],
+ [:stroke_path],
+ [:restore_graphics_state]])
+ end
+ it "works for dashed-round borders" do
+ border = create_border(width: 100, style: :dashed_round)
+ border.draw(@canvas, 0, 0, 10, 10)
+ assert_operators(@canvas.contents, [[:save_graphics_state],
+ [:set_line_width, [100]],
+ [:set_line_cap_style, [1]],
+ [:append_rectangle, [0, 0, 10, 10]],
+ [:clip_path_non_zero], [:end_path],
+ [:set_line_dash_pattern, [[100, 0], 50]],
+ [:move_to, [0, -40]], [:line_to, [10, -40]],
+ [:move_to, [10, 50]], [:line_to, [0, 50]],
+ [:stroke_path],
+ [:move_to, [-40, 10]], [:line_to, [-40, 0]],
+ [:move_to, [50, 0]], [:line_to, [50, 10]],
+ [:stroke_path],
+ [:restore_graphics_state]])
+ end
+ it "works for dotted borders" do
+ border = create_border(width: 100, style: :dotted)
+ border.draw(@canvas, 0, 0, 10, 10)
+ assert_operators(@canvas.contents, [[:save_graphics_state],
+ [:set_line_width, [100]],
+ [:set_line_cap_style, [1]],
+ [:append_rectangle, [0, 0, 10, 10]],
+ [:clip_path_non_zero], [:end_path],
+ [:set_line_dash_pattern, [[0, 1], 0]],
+ [:move_to, [0, -40]], [:line_to, [10, -40]],
+ [:move_to, [10, 50]], [:line_to, [0, 50]],
+ [:stroke_path],
+ [:move_to, [-40, 10]], [:line_to, [-40, 0]],
+ [:move_to, [50, 0]], [:line_to, [50, 10]],
+ [:stroke_path],
+ [:restore_graphics_state]])
end
end
it "raises an error if an invalid style is provided" do
assert_raises(ArgumentError) do