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

text() supresses leading whitespace #89

Closed
practicingruby opened this issue Feb 11, 2010 · 6 comments
Closed

text() supresses leading whitespace #89

practicingruby opened this issue Feb 11, 2010 · 6 comments

Comments

@practicingruby
Copy link
Member

Prawn::Document.generate('x.pdf") do
   text "    x"
   text "          x"
end

Contrast to:

Prawn::Document.generate('x.pdf") do
   text "|    x"
   text "|         x"
end
@practicingruby
Copy link
Member Author

Not a bug. Intentional behavior change by Daniel. See:
http://groups.google.com/group/prawn-ruby/browse_thread/thread/836c1349ec76c720

@dimasivanov
Copy link

Ok, but how i can render this indentation:

   Prawn::Document.generate('x.pdf") do 
   text "              xxxxxx
               xxxxxx      
                   xxxxxxxxxxxxx"
   end

:indent_paragraphs property couldn`t help me with this.

@practicingruby
Copy link
Member Author

Use non-breaking space: http://en.wikipedia.org/wiki/Non-breaking_space

@thbar
Copy link

thbar commented Nov 10, 2010

Here's an example of how to do this using non-breaking spaces (here to display some code):

content = "def function(param)\n  puts 'this'\nend"
content = content.gsub(/^(\s+)/m) { |m| "\xC2\xA0" * m.size }
font "courier" do
  text content
end

@ykessler
Copy link

@thbar your example breaks if you have multiple newlines. Use this instead:

content = content.gsub(/^([^\S\r\n]+)/m) { |m| "\xC2\xA0" * m.size }

From http://stackoverflow.com/a/17752989/165673

@gsum
Copy link

gsum commented Jan 28, 2019

content = content.gsub(/^([^\S\r\n]+)/m) { |m| "\xC2\xA0" * m.size }
after doing this I got

PDF's built-in fonts have very limited support for internationalized text.
If you need full UTF-8 support, consider using a TTF font instead.

To disable this warning, add the following line to your code:
Prawn::Font::AFM.hide_m17n_warning = true

Then downloaded a font and it works.
Thank you.

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

5 participants