From ad7612478119a9452e04113a82a2bb15408d9603 Mon Sep 17 00:00:00 2001 From: Alexander Mankuta Date: Mon, 22 Jan 2024 17:46:50 +0200 Subject: [PATCH] Fix missing glyph width. Prawn correctly used width of missing glyphs to layout text but didn't encode the widths correctly in subset fonts. The resulted in characters with missing glyphs to have 0 width. And even though Prawn drawn Replacement Character glyphs they were stacking on top of each other because their widths were wrong. --- lib/prawn/fonts/ttf.rb | 12 ++++++------ 1 file changed, 6 insertions(+), 6 deletions(-) diff --git a/lib/prawn/fonts/ttf.rb b/lib/prawn/fonts/ttf.rb index 5e55220f9..779234de8 100644 --- a/lib/prawn/fonts/ttf.rb +++ b/lib/prawn/fonts/ttf.rb @@ -393,18 +393,18 @@ def embed_simple_font(reference, font, unicode_mapping) XHeight: x_height ) - first_char = font.cmap.tables.first.code_map.index { |gid| !gid.zero? } - last_char = font.cmap.tables.first.code_map.rindex { |gid| !gid.zero? } + first_char, last_char = unicode_mapping.keys.minmax hmtx = font.horizontal_metrics widths = - font.cmap.tables.first.code_map[first_char..last_char].map do |gid| - if gid.zero? + (first_char..last_char).map do |code| + if unicode_mapping.key?(code) + gid = font.cmap.tables.first.code_map[code] + Integer(hmtx.widths[gid] * scale_factor) + else # These characters are not in the document so we don't ever use # these values but we need to encode them so let's use as little # sapce as possible. 0 - else - Integer(hmtx.widths[gid] * scale_factor) end end