test/hexapdf/layout/test_text_layouter.rb in hexapdf-0.31.0 vs test/hexapdf/layout/test_text_layouter.rb in hexapdf-0.32.0
- old
+ new
@@ -5,17 +5,17 @@
require 'hexapdf/document'
module TestTextLayouterHelpers
def boxes(*dims)
dims.map do |width, height|
- box = HexaPDF::Layout::InlineBox.create(width: width, height: height || 0) {}
+ box = HexaPDF::Layout::InlineBox.create(width: width, height: height || 10) {}
HexaPDF::Layout::TextLayouter::Box.new(box)
end
end
def glue(width)
- HexaPDF::Layout::TextLayouter::Glue.new(HexaPDF::Layout::InlineBox.create(width: width) {})
+ HexaPDF::Layout::TextLayouter::Glue.new(HexaPDF::Layout::InlineBox.create(width: width, height: 10) {})
end
def penalty(penalty, item = nil)
if item
HexaPDF::Layout::TextLayouter::Penalty.new(penalty, item.width, item: item)
@@ -134,20 +134,12 @@
result = @obj.call([frag])
assert_equal(20, result.size)
[1, 3, 5, 7, 9, 11, 13, 17, 19].each do |index|
assert_penalty(result[index],
HexaPDF::Layout::TextLayouter::Penalty::PARAGRAPH_BREAK)
- assert_equal([], result[index].item.items)
- assert(result[index].item.items.frozen?)
- assert_same(frag.style, result[index].item.style)
- assert_equal(frag.properties, result[index].item.properties)
end
assert_penalty(result[15], HexaPDF::Layout::TextLayouter::Penalty::LINE_BREAK)
- assert_equal([], result[15].item.items)
- assert(result[15].item.items.frozen?)
- assert_same(frag.style, result[15].item.style)
- assert_equal(frag.properties, result[15].item.properties)
end
it "insert a standard penalty after a hyphen" do
frag = setup_fragment("hy-phen-a-tion - cool!")
@@ -622,11 +614,11 @@
end
end
describe "horizontal alignment" do
before do
- @items = boxes(*[[20, 20]] * 4) + [glue(10), penalty(-5000, boxes(0).first.item)]
+ @items = boxes(*[[20, 20]] * 4) + [glue(10), penalty(-5000)]
end
it "aligns the contents to the left" do
@style.align = :left
result = @layouter.fit(@items, 100, 100)
@@ -787,10 +779,13 @@
@layouter.fit([box1, box2], 200, 100).draw(@canvas, 0, 0)
assert_operators(@canvas.contents, [[:save_graphics_state],
[:restore_graphics_state],
[:save_graphics_state],
[:concatenate_matrix, [1, 0, 0, 1, 10, -40]],
+ [:save_graphics_state],
+ [:concatenate_matrix, [1, 0, 0, 1, 0, 0]],
[:set_line_width, [2]],
+ [:restore_graphics_state],
[:restore_graphics_state],
[:save_graphics_state],
[:restore_graphics_state]])
end
end