Module: Fontisan::Ufo::Compile::Cff2Subrs

Defined in:
lib/fontisan/ufo/compile/cff2_subroutines.rb

Overview

CFF2 subroutine utilities — bias calculation and INDEX building.

Subroutines are shared charstring sequences referenced by index from the caller. CFF2 supports two kinds:

- GlobalSubr: shared across all CharStrings
- LocalSubr: per Font DICT, referenced via operator 19 (0x13)

The bias for callsubr/callgsubr index lookup is:

0-1240       → bias 107
1241-33800   → bias 1131
33801+       → bias 32768

Class Method Summary collapse

Class Method Details

.bias(count) ⇒ Integer

Calculate the bias for subroutine index lookup.

Parameters:

  • count (Integer)

    number of subroutines in the INDEX

Returns:

  • (Integer)

    bias



23
24
25
26
27
28
# File 'lib/fontisan/ufo/compile/cff2_subroutines.rb', line 23

def self.bias(count)
  return 107 if count <= 1240
  return 1131 if count <= 33800

  32768
end

.build_index(subrs) ⇒ String

Build a Subr INDEX (same structure for Global and Local).

Parameters:

  • subrs (Array<String>)

    charstring bytes for each subr

Returns:

  • (String)

    INDEX binary



33
34
35
# File 'lib/fontisan/ufo/compile/cff2_subroutines.rb', line 33

def self.build_index(subrs)
  Tables::Cff2::IndexBuilder.build(subrs.map(&:b))
end