test/hexapdf/layout/test_inline_box.rb in hexapdf-0.33.0 vs test/hexapdf/layout/test_inline_box.rb in hexapdf-0.34.0
- old
+ new
@@ -22,42 +22,51 @@
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 a 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)
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
-
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) }
+ 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))
+ 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
- inline_box(doc.layout.text("", width: 20, margin: [15, 10])).draw(canvas, 100, 200)
+ box = inline_box(doc.layout.text("", width: 20, margin: [15, 10]))
+ box.fit_wrapped_box(nil)
+ box.draw(canvas, 100, 200)
assert_equal("q\n1 0 0 1 110 -99785 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?)
+ end
+
+ it "returns the style of the box" do
+ assert_same(@box.box.style, @box.style)
end
describe "valign" do
it "has a default value of :baseline" do
assert_equal(:baseline, @box.valign)