1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
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
58
59
60
61
//! CFF subroutine resolution helpers.
//!
//! Type 2 charstrings reference local and global subroutines via the
//! `callsubr` (op 10) and `callgsubr` (op 29) operators. The
//! subroutine number on the stack is *biased* — the actual INDEX
//! lookup uses `index = number + bias`, where the bias depends on
//! the INDEX size (TN5177 §4.7):
//!
//! ```text
//! count < 1240 → bias = 107
//! count < 33900 → bias = 1131
//! else → bias = 32768
//! ```
//!
//! This compaction puts the most-used subroutine numbers (the small
//! ones) closest to zero in the encoded charstring, saving bytes.
//! Get the bias wrong and every callsubr / callgsubr in the font
//! lands on the wrong subroutine — which is exactly the kind of
//! breakage the spec calls out as a common implementation mistake.
/// Compute the Type 2 subroutine bias for an INDEX of `count` subrs.
pub