Class: Fontisan::Subset::TableStrategy::Cmap::Builder

Inherits:
Object
  • Object
show all
Defined in:
lib/fontisan/subset/table_strategy/cmap.rb

Overview

Builds a minimal valid cmap table from a => gid map. Extracted as a sibling class so [Cmap] stays focused on subsetting dispatch while the binary arithmetic lives separately.

Instance Method Summary collapse

Constructor Details

#initialize(mappings) ⇒ Builder

Returns a new instance of Builder.



29
30
31
# File 'lib/fontisan/subset/table_strategy/cmap.rb', line 29

def initialize(mappings)
  @mappings = mappings
end

Instance Method Details

#buildObject



33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
# File 'lib/fontisan/subset/table_strategy/cmap.rb', line 33

def build
  @mappings = { 0 => 0 } if @mappings.empty?

  bmp = @mappings.select { |cp, _| cp <= 0xFFFF }
  supp = @mappings.select { |cp, _| cp > 0xFFFF }

  subtables = []
  records = []

  unless bmp.empty?
    subtables << build_format_4(bmp)
    idx = subtables.size - 1
    records << [3, 1, idx] # Windows BMP
    records << [0, 3, idx] # Unicode BMP
  end

  unless supp.empty?
    subtables << build_format_12(@mappings)
    idx = subtables.size - 1
    records << [3, 10, idx] # Windows UCS-4
    records << [0, 4, idx]  # Unicode full
  end

  assemble(records, subtables)
end