Class: Pdfrb::Font::TrueType::Subsetter
- Inherits:
-
Object
- Object
- Pdfrb::Font::TrueType::Subsetter
- Defined in:
- lib/pdfrb/font/true_type/subsetter.rb
Overview
Glyph subsetting for embedded TrueType fonts. Given a set of used glyph IDs, produces a new TTF with only those glyphs.
Rewrites: glyf, loca, cmap, hmtx, hhea, maxp, head. Handles composite glyphs (diacritics) by recursively including referenced component glyphs.
Falls back to returning the full font if subsetting fails.
Constant Summary collapse
- NOTDEF_GID =
0- SFNT_VERSION =
[0x00010000].freeze
Instance Attribute Summary collapse
-
#glyph_ids ⇒ Object
readonly
Returns the value of attribute glyph_ids.
-
#ttf ⇒ Object
readonly
Returns the value of attribute ttf.
Instance Method Summary collapse
-
#glyph_map ⇒ Object
Returns the mapping old_gid → new_gid.
-
#initialize(ttf, glyph_ids) ⇒ Subsetter
constructor
A new instance of Subsetter.
-
#subset ⇒ Object
Returns the subset font bytes.
Constructor Details
#initialize(ttf, glyph_ids) ⇒ Subsetter
Returns a new instance of Subsetter.
24 25 26 27 |
# File 'lib/pdfrb/font/true_type/subsetter.rb', line 24 def initialize(ttf, glyph_ids) @ttf = ttf @glyph_ids = ([NOTDEF_GID] + glyph_ids).sort.uniq end |
Instance Attribute Details
#glyph_ids ⇒ Object (readonly)
Returns the value of attribute glyph_ids.
20 21 22 |
# File 'lib/pdfrb/font/true_type/subsetter.rb', line 20 def glyph_ids @glyph_ids end |
#ttf ⇒ Object (readonly)
Returns the value of attribute ttf.
20 21 22 |
# File 'lib/pdfrb/font/true_type/subsetter.rb', line 20 def ttf @ttf end |
Instance Method Details
#glyph_map ⇒ Object
Returns the mapping old_gid → new_gid.
35 36 37 38 39 40 41 |
# File 'lib/pdfrb/font/true_type/subsetter.rb', line 35 def glyph_map @glyph_map ||= begin map = {} resolved_gids.each_with_index { |old_gid, new_gid| map[old_gid] = new_gid } map end end |
#subset ⇒ Object
Returns the subset font bytes.
30 31 32 |
# File 'lib/pdfrb/font/true_type/subsetter.rb', line 30 def subset @subset ||= build_subset end |