test/hexapdf/layout/test_inline_box.rb in hexapdf-0.45.0 vs test/hexapdf/layout/test_inline_box.rb in hexapdf-0.46.0
- old
+ new
@@ -21,50 +21,39 @@
assert_equal(:baseline, ibox.valign)
ibox = inline_box(box, valign: :top)
assert_equal(:top, ibox.valign)
end
-
- it "fails if the wrapped box has not width set" do
- box = HexaPDF::Document.new.layout.text("test is not going good")
- assert_raises(HexaPDF::Error) { inline_box(box) }
- end
end
describe "fit_wrapped_box" do
- it "automatically fits the provided box into the given frame" do
- ibox = inline_box(HexaPDF::Document.new.layout.text("test is going good", width: 20))
+ it "automatically fits the provided box when given a frame" do
+ ibox = inline_box(HexaPDF::Document.new.layout.text("test is going good", margin: [5, 10]))
ibox.fit_wrapped_box(HexaPDF::Layout::Frame.new(0, 0, 50, 50))
- assert_equal(20, ibox.width)
- assert_equal(45, ibox.height)
+ assert_equal(90.84, ibox.width)
+ assert_equal(19, ibox.height)
+ fit_result = ibox.instance_variable_get(:@fit_result)
+ assert_equal(10, fit_result.x)
+ assert_equal(5, fit_result.y)
+ assert_equal(70.84 + 2 * 10, fit_result.mask.width)
+ assert_equal(9 + 2 * 5, fit_result.mask.height)
end
- it "automatically fits the provided box into a custom frame" do
- ibox = inline_box(HexaPDF::Document.new.layout.text("test is going good", width: 20))
- ibox.fit_wrapped_box(nil)
- assert_equal(20, ibox.width)
- assert_equal(45, ibox.height)
+ it "automatically fits the provided box without a given frame" do
+ ibox = inline_box(HexaPDF::Document.new.layout.text("test is going good"))
+ ibox.fit_wrapped_box
+ assert_equal(70.84, ibox.width)
+ assert_equal(9, ibox.height)
end
-
- it "fails if the wrapped box could not be fit" do
- box = HexaPDF::Document.new.layout.text("test is not going good", width: 1)
- assert_raises(HexaPDF::Error) { inline_box(box).fit_wrapped_box(nil) }
- end
-
- it "fails if the height is not set explicitly and during fitting" do
- assert_raises(HexaPDF::Error) do
- inline_box(HexaPDF::Layout::Box.create(width: 10)).fit_wrapped_box(nil)
- end
- end
end
it "draws the wrapped box at the correct position" do
doc = HexaPDF::Document.new
canvas = doc.pages.add.canvas
- box = inline_box(doc.layout.text("", width: 20, margin: [15, 10]))
- box.fit_wrapped_box(nil)
+ box = HexaPDF::Layout::InlineBox.create(width: 10, margin: [15, 10]) {}
+ box.fit_wrapped_box
box.draw(canvas, 100, 200)
- assert_equal("q\n1 0 0 1 110 -99785 cm\nQ\n", canvas.contents)
+ assert_equal("q\n1 0 0 1 110 215 cm\nQ\n", canvas.contents)
end
it "returns true if the inline box is empty with no drawing operations" do
assert(@box.empty?)
refute(HexaPDF::Layout::InlineBox.create(width: 10, height: 15) {}.empty?)