Module: Pdfrb::Document::Fonts::Subsetting

Included in:
Pdfrb::Document::Fonts
Defined in:
lib/pdfrb/document/fonts/subsetting.rb

Overview

Font-program subsetting (s9.6.4). Mixed into the Fonts facade; the seam it owns is "replace every embedded font program with a subset covering only the used codepoints", dispatching on the outline format (TrueType vs CFF-in-OTF).

Instance Method Summary collapse

Instance Method Details

#subset_fonts!Object

Entry point, invoked by Document#write. Fonts that were never drawn with (no recorded codepoints) keep their full program; failures fall back to the full font.



14
15
16
17
18
19
20
21
22
23
24
25
26
27
# File 'lib/pdfrb/document/fonts/subsetting.rb', line 14

def subset_fonts!
  @font_streams.each do |resource, data|
    next unless valid_font_data?(data)

    codepoints = @used_codepoints[resource]
    next if codepoints.empty?

    begin
      subset_font(resource, data, codepoints)
    rescue StandardError
      next
    end
  end
end