Module: Fontisan::Stitcher::GlyphLimit

Defined in:
lib/fontisan/stitcher/glyph_limit.rb

Overview

Format-specific glyph-count caps.

Both TTF and OTF (CFF1) cap at 65,535 because:

- TTF: maxp.num_glyphs is uint16
- OTF (CFF1): maxp.num_glyphs is uint16 AND the CFF CharStrings
INDEX count is card16

Exceeding the cap produces a silently truncated font (the BinData uint16 writer truncates without raising). The Stitcher checks the cap BEFORE writing so the user gets a clear error.

To exceed 65,535 glyphs, the font must be split into a TTC (TrueType Collection) or fontisan must implement CFF2 (card24 INDEX counts). Both are future work.

Constant Summary collapse

TTF_GLYPH_CAP =
65_535
OTF_GLYPH_CAP =
65_535

Class Method Summary collapse

Class Method Details

.check!(glyph_count, format:) ⇒ Object

Raise GlyphLimitExceededError if glyph_count exceeds the cap for the given format.

Parameters:

  • glyph_count (Integer)
  • format (Symbol)

Raises:



41
42
43
44
45
46
47
48
49
50
# File 'lib/fontisan/stitcher/glyph_limit.rb', line 41

def self.check!(glyph_count, format:)
  limit = for_format(format)
  return if glyph_count <= limit

  raise GlyphLimitExceededError.new(
    actual: glyph_count,
    limit: limit,
    format: format,
  )
end

.for_format(format) ⇒ Integer, Float::INFINITY

Returns the max glyph count.

Parameters:

  • format (Symbol)

    :ttf or :otf

Returns:

  • (Integer, Float::INFINITY)

    the max glyph count



25
26
27
28
29
30
31
32
33
# File 'lib/fontisan/stitcher/glyph_limit.rb', line 25

def self.for_format(format)
  case format.to_sym
  when :ttf then TTF_GLYPH_CAP
  when :otf then OTF_GLYPH_CAP
  when :otf2 then OTF_GLYPH_CAP # CFF2 CharStrings count must match maxp.numGlyphs
  else
    raise ArgumentError, "unknown format: #{format.inspect}"
  end
end