Module: Fontisan::Ufo::Compile::Cmap
- Defined in:
- lib/fontisan/ufo/compile/cmap.rb
Overview
Builds the OpenType cmap (character-to-glyph mapping) table.
Emits two subtables:
- Format 4 (BMP), platform 3 encoding 1 (Windows Unicode BMP)
- Format 12 (full Unicode), platform 3 encoding 10 (Windows Unicode full)
Both subtables share the same segment list (capped to BMP for format 4); format 4 is required by Windows even though format 12 is more capable.
Contract — first-wins: when multiple glyphs declare the same
codepoint, the glyph at the LOWER GID wins the cp→gid mapping.
Callers that want one donor to outrank another for a shared
codepoint (e.g. outline donor vs. CBDT placeholder) MUST order
the higher-priority glyphs earlier in the glyphs: array.
Stitcher relies on this for outline-first stitching.
Constant Summary collapse
- PLATFORM_WINDOWS =
3- ENCODING_WINDOWS_BMP =
1- ENCODING_WINDOWS_FULL =
10
Class Method Summary collapse
-
.build(_font, glyphs:) ⇒ String
Cmap table bytes.
Class Method Details
.build(_font, glyphs:) ⇒ String
Returns cmap table bytes.
31 32 33 34 35 36 37 38 39 40 41 42 43 44 45 46 47 48 49 50 |
# File 'lib/fontisan/ufo/compile/cmap.rb', line 31 def self.build(_font, glyphs:) mappings = {} glyphs.each_with_index do |glyph, gid| glyph.unicodes.each do |cp| mappings[cp] = gid unless mappings.key?(cp) end end subtable_bmp = format4_subtable(mappings.reject { |cp, _| cp > 0xFFFF }) subtable_full = format12_subtable(mappings) header_size = 4 + (2 * 8) # version + numTables + 2 records offset_bmp = header_size offset_full = header_size + subtable_bmp.bytesize header = [0, 2].pack("nn") header << subtable_record(PLATFORM_WINDOWS, ENCODING_WINDOWS_BMP, offset_bmp) header << subtable_record(PLATFORM_WINDOWS, ENCODING_WINDOWS_FULL, offset_full) header + subtable_bmp + subtable_full end |