test/hexapdf/layout/test_text_layouter.rb in hexapdf-0.33.0 vs test/hexapdf/layout/test_text_layouter.rb in hexapdf-0.34.0
- old
+ new
@@ -260,11 +260,11 @@
result = call(boxes(70) + [glue(10)] + boxes(10) + [penalty(5000)] + boxes(30))
assert_line_wrapping(result, [70, 40])
end
it "handles prohibited breakpoint penalties with non-zero width" do
- item = boxes(20).first
+ item = boxes(20).first.item
result = call(boxes(70) + [glue(10)] + boxes(10) + [penalty(5000, item)] + boxes(30))
assert_line_wrapping(result, [70, 60])
end
it "stops when nil is returned by the block: last item is a box" do
@@ -293,35 +293,62 @@
rest, lines = call(boxes(20, 20), 20) { done ? nil : done = true }
assert_equal(1, rest.count)
assert_equal(2, lines.count)
end
+ it "handles items with fill_horizontal correctly" do
+ doc = HexaPDF::Document.new
+ font = doc.fonts.add("Times")
+ box1 = HexaPDF::Layout::TextLayouter::Box.new(
+ HexaPDF::Layout::TextFragment.create('.', font: font, fill_horizontal: 1)
+ )
+ box2 = HexaPDF::Layout::TextLayouter::Box.new(
+ HexaPDF::Layout::TextFragment.create('.', font: font, fill_horizontal: 2)
+ )
+ items = [box1, *boxes(10), box2]
+ rest, lines = call(items, 40)
+ assert_equal(0, rest.size)
+ assert_equal(1, lines.size)
+
+ line = lines.first
+ refute_same(items[0].item, line.items[0])
+ assert_same(items[1].item, line.items[1])
+ refute_same(items[2].item, line.items[2])
+ assert_equal(10, line.items[0].width)
+ assert_equal(10, line.items[1].width)
+ assert_equal(20, line.items[2].width)
+ end
end
describe HexaPDF::Layout::TextLayouter::SimpleLineWrapping do
before do
@obj = HexaPDF::Layout::TextLayouter::SimpleLineWrapping
+ @mock_frame = nil
end
describe "fixed width wrapping" do
include CommonLineWrappingTests
def call(items, width = 100, &block)
lines = []
block ||= proc { true }
- rest = @obj.call(items, proc { width }) {|line, item| lines << line; block.call(line, item) }
+ rest = @obj.call(items, proc { width }, @mock_frame) do |line, item|
+ lines << line; block.call(line, item)
+ end
[rest, lines]
end
end
describe "variable width wrapping" do
include CommonLineWrappingTests
def call(items, width = 100, &block)
lines = []
block ||= proc { true }
- rest = @obj.call(items, proc {|_| width }) {|line, i| lines << line; block.call(line, i) }
+ rest = @obj.call(items, proc {|_| width }, @mock_frame) do |line, i|
+ lines << line; block.call(line, i)
+ end
[rest, lines]
end
it "handles changing widths" do
height = 0
@@ -332,11 +359,11 @@
when 21..30 then 20
else 60
end
end
lines = []
- rest = @obj.call(boxes([20, 10], [10, 10], [20, 15], [40, 10]), width_block) do |line|
+ rest = @obj.call(boxes([20, 10], [10, 10], [20, 15], [40, 10]), width_block, @mock_frame) do |line|
height += line.height
lines << line
true
end
assert(rest.empty?)
@@ -355,10 +382,10 @@
end
end
lines = []
item = HexaPDF::Layout::InlineBox.create(width: 20, height: 10) {}
items = boxes([20, 10]) + [penalty(0, item)] + boxes([40, 15])
- rest = @obj.call(items, width_block) do |line|
+ rest = @obj.call(items, width_block, @mock_frame) do |line|
height += line.height
lines << line
true
end
assert(rest.empty?)