Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Workaround (fix?) for #603 encoding issue during line wrap #714

Closed
wants to merge 2 commits into from
Closed
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Jump to
Jump to file
Failed to load files.
Diff view
Diff view
2 changes: 1 addition & 1 deletion lib/prawn/text/formatted/line_wrap.rb
Expand Up @@ -212,7 +212,7 @@ def determine_whether_to_pull_preceding_fragment_to_join_this_one(current_fragme

def remember_this_fragment_for_backward_looking_ops
@previous_fragment = @fragment_output.dup
pf = @previous_fragment
pf = @previous_fragment.encode('UTF-8', invalid: :replace, undef: :replace, replace: '')
@previous_fragment_ended_with_breakable = pf =~ /[#{break_chars}]$/
last_word = pf.slice(/[^#{break_chars}]*$/)
last_word_length = last_word.nil? ? 0 : last_word.length
Expand Down
12 changes: 12 additions & 0 deletions spec/line_wrap_spec.rb
Expand Up @@ -235,6 +235,18 @@
:document => @pdf)
string.should == "Test"
end

it "should process UTF-8 chars in shrink_to_fit", :unresolved, :issue => 603 do

# set UTF-8 font
@pdf.font_families.update("dejavu" => { :normal => "#{Prawn::DATADIR}/fonts/DejaVuSans.ttf" })
@pdf.fallback_fonts = ["dejavu"]

@pdf.bounding_box([1, 1], :width => 90, :height => 50) do
broken_text = " Sample Text\nSAMPLE SAMPLE SAMPLEoddělení ZMĚN\nSAMPLE"
@pdf.text broken_text, :overflow => :shrink_to_fit
end
end
end

describe "Core::Text::Formatted::LineWrap#space_count" do
Expand Down