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

center layout incorrect #32

Closed
tbf opened this issue Aug 24, 2009 · 2 comments
Closed

center layout incorrect #32

tbf opened this issue Aug 24, 2009 · 2 comments

Comments

@tbf
Copy link

tbf commented Aug 24, 2009

using center layout in prawn is not correct as the length of lines is not correctly determined (incloding '\n' character)

This was published and discussed on in google group:
http://groups.google.com/group/prawn-ruby/browse_thread/thread/6754ada443dd22cd
workaround is to overwrite width_of method by manually removing tailing '\n' characters. (sorry the layout is broken as githup is always reformating this as coding)

module Prawn
class Document
alias_method :orig_width_of, :width_of
def width_of(string, options={})
orig_width_of(string.gsub(/\n\z/,""),options)
end
end
end

@practicingruby
Copy link
Member

I don't think we can make an assumption about newlines.

The documentation in Prawn already states:

"Text wrap in Prawn does not re-flow linebreaks, so if you want fully automated text wrapping, be sure to remove newlines before attempting to draw your string. "

I could clarify that a little more, but this basically means it's up to you to remove your newlines. If font designers include a width for \n, it's best for us to respect those intentions even if they don't make much sense.

@fastpencil
Copy link

This particular issue is driving me crazy when using the Arial TTF font, which apparently has a width defined for the newline character, although I'm hard-pressed to figure out why anyone would want a newline to have width.

This issue was closed.
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