Skip to content

Commit

Permalink
Merge branch 'master' of git://github.com/mbklein/prawn
Browse files Browse the repository at this point in the history
  • Loading branch information
bradediger committed May 18, 2011
2 parents b2415f2 + e2ee4e7 commit e0ab545
Show file tree
Hide file tree
Showing 2 changed files with 42 additions and 1 deletion.
3 changes: 2 additions & 1 deletion lib/prawn/core/text/formatted/line_wrap.rb
Expand Up @@ -203,7 +203,8 @@ def remember_this_fragment_for_backward_looking_ops
@previous_fragment = @fragment_output.dup
pf = @previous_fragment
@previous_fragment_ended_with_breakable = pf =~ /[#{break_chars}]$/
last_word_length = pf.slice(/[^#{break_chars}]*$/).length
last_word = pf.slice(/[^#{break_chars}]*$/)
last_word_length = last_word.nil? ? 0 : last_word.length
@previous_fragment_output_without_last_word = pf.slice(0, pf.length - last_word_length)
end

Expand Down
40 changes: 40 additions & 0 deletions spec/formatted_text_box_spec.rb
Expand Up @@ -75,6 +75,46 @@
text_box.render
text_box.text.should == "Hello World\n2"
end

it "should properly handle empty slices using default encoding" do
texts = [{ :text => "Noua Delineatio Geographica generalis | Apostolicarum peregrinationum | S FRANCISCI XAUERII | Indiarum & Iaponiæ Apostoli", :font => 'Courier', :size => 10 }]
text_box = Prawn::Text::Formatted::Box.new(texts, :document => @pdf, :width => @pdf.width_of("Noua Delineatio Geographica gen"))
assert_nothing_raised do
text_box.render
end
text_box.text.should == "Noua Delineatio Geographica\ngeneralis | Apostolicarum\nperegrinationum | S FRANCISCI\nXAUERII | Indiarum & Iaponi\346\nApostoli"
end

describe "Unicode" do
before do
if RUBY_VERSION < '1.9'
@reset_value = $KCODE
$KCODE='u'
else
@reset_value = [Encoding.default_external, Encoding.default_internal]
Encoding.default_external = Encoding::UTF_8
Encoding.default_internal = Encoding::UTF_8
end
end

after do
if RUBY_VERSION < '1.9'
$KCODE=@reset_value
else
Encoding.default_external = @reset_value[0]
Encoding.default_internal = @reset_value[1]
end
end

it "should properly handle empty slices using Unicode encoding" do
texts = [{ :text => "Noua Delineatio Geographica generalis | Apostolicarum peregrinationum | S FRANCISCI XAUERII | Indiarum & Iaponiæ Apostoli", :font => 'Courier', :size => 10 }]
text_box = Prawn::Text::Formatted::Box.new(texts, :document => @pdf, :width => @pdf.width_of("Noua Delineatio Geographica gen"))
assert_nothing_raised do
text_box.render
end
text_box.text.should == "Noua Delineatio Geographica\ngeneralis | Apostolicarum\nperegrinationum | S FRANCISCI\nXAUERII | Indiarum & Iaponi\346\nApostoli"
end
end
end

describe "Text::Formatted::Box with :fallback_fonts option that includes" +
Expand Down

0 comments on commit e0ab545

Please sign in to comment.