-
Hey guys, I am having a weird behaviour after moving from If you run the following code, you will notice that the rendered PDF plots the text in different positions: Prawn::Document.generate("a.pdf") do |document|
document.stroke_axis
document.text_box 'text', at: [200, 400]
document.draw_text 'draw', at: [200, 400]
end Apparently, they use different origins, which cause them to render the text in different positions. If I adjust the Prawn::Document.generate("a.pdf") do |document|
document.stroke_axis
document.text_box 'text', at: [200, 400 + (0.7 * document.font_size)]
document.draw_text 'draw', at: [200, 400]
end Any ideas on how to elegantly fix this? Or just adjusting it by 70% would suffice? |
Beta Was this translation helpful? Give feedback.
Replies: 3 comments
-
Haven't looked at the code but I guess the difference is because of different text origins. With With |
Beta Was this translation helpful? Give feedback.
-
Thanks for getting back @gettalong Any specific reason on why those two methods use two different origins? It seems confusing to me that one uses top-down and the other bottom-up. Do you think it's worth to add an option that specifies the origin so we can have both methods behaving the same way? Or do you think it's possible to add support to fallback fonts in the draw-text method? I'm opened to implement that if you think that's feasible. Cheers, |
Beta Was this translation helpful? Give feedback.
-
The reason is that these two methods do different things. As I mentioned Therefore it doesn't really make sense for the As for fallback fonts in |
Beta Was this translation helpful? Give feedback.
Haven't looked at the code but I guess the difference is because of different text origins.
With
#draw_text
you define the lower-left corner where drawing should be done since this method is basically a one-to-one mapping of the PDF text drawing command. Therefore the word "draw" appears above the 400 line.With
#text_box
you use a high-level method that defines a box into which text should be drawn. And theat
option defines the upper-left corner of this box (see the API spec, therefore the text appears below the 400 line.