Skip to content

Commit

Permalink
Fix missing glyph width.
Browse files Browse the repository at this point in the history
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.
  • Loading branch information
pointlessone committed Jan 22, 2024
1 parent 11c73c2 commit ad76124
Showing 1 changed file with 6 additions and 6 deletions.
12 changes: 6 additions & 6 deletions lib/prawn/fonts/ttf.rb
Original file line number Diff line number Diff line change
Expand Up @@ -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

Expand Down

0 comments on commit ad76124

Please sign in to comment.