Prawn: text() suprime los espacios en blanco iniciales

Creado en 11 feb. 2010  ·  6Comentarios  ·  Fuente: prawnpdf/prawn

 Langostino::Documento.generar('x.pdf") hacer
 texto "x"
 texto "x"
 final

Contraste con:

 Langostino::Documento.generar('x.pdf") hacer
 texto "|x"
 texto "|x"
 final

Comentario más útil

@thbar, su ejemplo se rompe si tiene varias líneas nuevas. Usa esto en su lugar:

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

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

Todos 6 comentarios

No es un error. Cambio de comportamiento intencional por Daniel. Ver:
http://groups.google.com/group/prawn-ruby/browse_thread/thread/836c1349ec76c720

Ok, pero ¿cómo puedo representar esta sangría?

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

La propiedad :indent_paragraphs no pudo ayudarme con esto.

Utilice espacios de no separación: http://en.wikipedia.org/wiki/Non-breaking_space

Aquí hay un ejemplo de cómo hacer esto usando espacios que no se rompen (aquí para mostrar algo de código):

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

@thbar, su ejemplo se rompe si tiene varias líneas nuevas. Usa esto en su lugar:

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

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

contenido = contenido.gsub(/^([^\S\r\n]+)/m) { |m| "\xC2\xA0" * m.tamaño }
después de hacer esto obtuve

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

Luego descargué una fuente y funciona.
Gracias.

¿Fue útil esta página
0 / 5 - 0 calificaciones

Temas relacionados

caseyohara picture caseyohara  ·  3Comentarios

OTF
PascalPixel picture PascalPixel  ·  8Comentarios

mojavelinux picture mojavelinux  ·  9Comentarios

afdev82 picture afdev82  ·  12Comentarios

timokleemann picture timokleemann  ·  4Comentarios