Stretch or shrink text in one dimension only #1309
-
Just getting my feet wet in Prawn, and hoping to migrate a very old project at my workplace that uses a custom PostScript-generating library. Where I'm stuck at the moment is in font scaling. We've been used to separate control of font :size and :hscale (horizontal scale) and it's not uncommon here to set :hscale to 2.0, yielding double width text from a relatively small font size, e.g. in some table column headers. Is a capability like this already offered in Prawn somehow? If not, might it be a workable request? I can approach my employer about offering a bounty for it, if need be, so that some stylistic choices can be preserved if we do this. Edit - whoa, I just found transformation_matrix() in the graphics/transformation.rb file. This might be the ticket.... |
Beta Was this translation helpful? Give feedback.
Replies: 2 comments
-
I don't believe there's a separate horizontal scale for text in PDF. PDF supports text matrices that are more general transformation mechanism but Prawn doesn't support it (apart from text rotation). Other than that you can manipulate user-space transformation with |
Beta Was this translation helpful? Give feedback.
-
Thanks for the reply. I see you're right, transformation is more general than just text. And looking at the source of our postscript lib it's the same: when horizontally scaled text is requested that happens in a wrapper around the text call. I should be able to make this work by tweaking on scale() so it accepts two scale factors instead of one -- or leaving it alone and making a variant scaleXY() or whatever. |
Beta Was this translation helpful? Give feedback.
I don't believe there's a separate horizontal scale for text in PDF. PDF supports text matrices that are more general transformation mechanism but Prawn doesn't support it (apart from text rotation). Other than that you can manipulate user-space transformation with
transformation_matrix
. Just keep in mind that it will have effect on everything. For example, if you're drawing a box around text it might have uneven line thickness if you apply non-uniform scaling (i.e. for horizontal scaling side borders might be wider than top and bottom borders). To avoid that, only apply transformation to the text. This might also apply to text box sizes and margin boxes, I don't remember from the top of …