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

Correct processing of soft-hyphens #773

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.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
13 changes: 13 additions & 0 deletions lib/prawn/text/formatted/fragment.rb
Original file line number Diff line number Diff line change
Expand Up @@ -211,6 +211,8 @@ def process_text(text)
string = strip_zero_width_spaces(text)
if exclude_trailing_white_space?
string = process_soft_hyphens(string.rstrip)
else
string = process_soft_hyphens_complete(string)
end
case direction
when :rtl
Expand Down Expand Up @@ -239,6 +241,17 @@ def process_soft_hyphens(string)
end
end

def process_soft_hyphens_complete(string)
if string.length > 0 && normalized_soft_hyphen
if string.encoding != normalized_soft_hyphen.encoding
string.force_encoding(normalized_soft_hyphen.encoding)
end
string.gsub(normalized_soft_hyphen, "")
else
string
end
end

def strip_zero_width_spaces(string)
if string.encoding == ::Encoding::UTF_8
string.gsub(Prawn::Text::ZWSP, "")
Expand Down
19 changes: 12 additions & 7 deletions spec/line_wrap_spec.rb
Original file line number Diff line number Diff line change
Expand Up @@ -128,27 +128,32 @@
string.should == "hello#{Prawn::Text::SHY}"
end

it "should not display soft hyphens except at the end of a line" do
string = @pdf.font.normalize_encoding("hello#{Prawn::Text::SHY}world")
array = [{ :text => string }]
it "should not display soft hyphens except at the end of a line " +
"for more than one element in format_array", :issue => 347 do
string1 = @pdf.font.normalize_encoding("hello#{Prawn::Text::SHY}world ")
string2 = @pdf.font.normalize_encoding("hi#{Prawn::Text::SHY}earth")
array = [{ :text => string1 }, { :text => string2 }]
@arranger.format_array = array
string = @line_wrap.wrap_line(:arranger => @arranger,
:width => 300,
:document => @pdf)
string.should == "helloworld"
string.should == "helloworld hiearth"

@pdf.font("#{Prawn::DATADIR}/fonts/DejaVuSans.ttf")
@line_wrap = Prawn::Text::Formatted::LineWrap.new

string = "hello#{Prawn::Text::SHY}world"
array = [{ :text => string }]
string1 = "hello#{Prawn::Text::SHY}world "
string2 = @pdf.font.normalize_encoding("hi#{Prawn::Text::SHY}earth")
array = [{ :text => string1 }, { :text => string2 }]
@arranger.format_array = array
string = @line_wrap.wrap_line(:arranger => @arranger,
:width => 300,
:document => @pdf)
string.should == "helloworld"
string.should == "helloworld hiearth"
end

it 'should not display soft hyphens except at the end of a line'

it "should not break before a hard hyphen that follows a word" do
enough_width_for_hello_world = 60

Expand Down