Description
Certain fonts have a glyph width that is wider than the width of a space character (and wider than latin characters in general). This is typically seen in the box drawing glyphs. For example, in the M+ 1mn font, the char width of the space (and "a") is 500. But the char width of the horizontal box line is 1000. As a result, the box drawings don't align correctly.
Here's an example that demonstrates the problem:
require 'prawn'
Prawn::Document.generate 'mono.pdf' do
font_families['mplus1mn'] = {
normal: '/usr/share/fonts/mplus/mplus-1mn-regular.ttf'
}
font 'mplus1mn', size: 10 do
text '---'
warn width_of '---' # prints 15.0
text '———'
warn width_of '———' # prints 15.0
text '───'
warn width_of '───' # prints 30.0
end
end
The last line is twice as wide as the first two.
(This behavior is not seen with DejaVu Sans Mono since all the glyphs have the same width)
If I look at the PDF source, I see something like:
BT
36.0 725.6 Td
/F1.1 10 Tf
<212121> Tj
ET
It may be that Prawn can't do anything about this and that it's something the PDF viewer is responsible for handling. I'm not sure.
The only thing I can really see that Prawn could do is adjust the character spacing. The alternative is when Prawn embeds the font in the PDF, it can somehow scale the glyph widths of the monospace font so that they are all the same. But even if I try to force that to happen, I still get overlap. So maybe it is just an issue with this font.
Activity