lib/shoes/swt/text_block/fitter.rb in shoes-swt-4.0.0.pre2 vs lib/shoes/swt/text_block/fitter.rb in shoes-swt-4.0.0.pre3
- old
+ new
@@ -82,11 +82,10 @@
def fit_as_two_layouts(layout, height, width)
first_text, second_text = split_text(layout, height)
# Since we regenerate layouts, we must dispose of first try here.
layout.dispose
- layout = nil
first_layout = generate_layout(width, first_text)
if second_text.empty?
fit_as_one_layout(first_layout)
@@ -183,19 +182,22 @@
segment = generate_layout(1, @dsl.text)
segment.text = ""
segment
end
+ # Splits the text into two pieces based on height. Allows one final
+ # line to exceed the requested height, which results in smoother
+ # flowing text between different sized fonts on a line.
def split_text(layout, height)
ending_offset = 0
height_so_far = 0
offsets = layout.line_offsets
offsets[0...-1].each_with_index do |_, i|
height_so_far += layout.line_bounds(i).height
- break if height_so_far > height
+ ending_offset = offsets[i + 1]
- ending_offset = offsets[i+1]
+ break if height_so_far > height
end
[layout.text[0...ending_offset], layout.text[ending_offset..-1]]
end
# If first text is empty, height may be smaller than an actual line in