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

Cell width is calculated wrong when cell text contains multiple lines #49

Open
J-F-Liu opened this issue Aug 1, 2015 · 3 comments
Open

Comments

@J-F-Liu
Copy link

J-F-Liu commented Aug 1, 2015

Cell width is calculated wrong when cell text contains multiple lines

        def styled_width_of(text)
          @pdf.width_of(text, @text_options)
        end

Should calculate the width of each line then return the maximum, i.e.

        def styled_width_of(text)
          if text.empty?
            0
          else
            text.lines.collect{|line|@pdf.width_of(line, @text_options)}.max
          end
        end
@packetmonkey
Copy link
Contributor

Can you please submit a full script that reproduces the problem? Also it looks like you have looked into this a bit so a spec + fix in a PR would also be welcome and help this get fixed faster.

Thanks!

@J-F-Liu
Copy link
Author

J-F-Liu commented Aug 5, 2015

Test code:

require 'prawn'
require 'prawn/table'

Prawn::Document.generate("table.pdf") do
  table([
  ["short", "loooooooooooooooooooong", "multiline text\nline 1\nlong line 2","short", "loooooooooooooooooooong"]
  ], :position => :center, :width => bounds.width, :cell_style => {:border_width => 0.6})
end

@J-F-Liu
Copy link
Author

J-F-Liu commented Aug 5, 2015

PR created: #50

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
None yet
Development

No branches or pull requests

2 participants