-
Notifications
You must be signed in to change notification settings - Fork 101
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
Calculate cell width of multi-line cells correctly #91
base: master
Are you sure you want to change the base?
Conversation
Ensures that the optimal cell width is calculated correctly when the column's content contains more than one line. Fixes #49
lib/prawn/table/cell/text.rb
Outdated
@@ -135,7 +135,13 @@ def text_box(extra_options={}) | |||
# | |||
def styled_width_of(text) | |||
options = @text_options.reject { |k| k == :style } | |||
with_font { @pdf.width_of(text, options) } | |||
if text.empty? |
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
Doesn't this case get properly handled by width_of
?
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
You are correct, width_of
handles it correctly, but line 142 would subsequently call #max
on an empty array and return nil; thus the conditional.
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
I personally would've preferred .max || 0
but it's not critical.
Is this case covered by a spec?
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
Yeah, I think .max || 0
is probably more readable. I'll change that and add a spec.
I'll take closer look a bit later. Thank you for your contribution. |
Ensures that the optimal cell width is calculated correctly when its content has more than one line.
This is similar to #50 but with specs.
Fixes #49.