ttfunk 1.6.2.1 → 1.7.0

Sign up to get free protection for your applications and to get access to all the features.
Files changed (56) hide show
  1. checksums.yaml +4 -4
  2. checksums.yaml.gz.sig +2 -1
  3. data.tar.gz.sig +0 -0
  4. data/CHANGELOG.md +15 -1
  5. data/lib/ttfunk.rb +3 -2
  6. data/lib/ttfunk/bit_field.rb +1 -1
  7. data/lib/ttfunk/collection.rb +8 -2
  8. data/lib/ttfunk/encoded_string.rb +3 -3
  9. data/lib/ttfunk/max.rb +1 -0
  10. data/lib/ttfunk/min.rb +1 -0
  11. data/lib/ttfunk/one_based_array.rb +1 -1
  12. data/lib/ttfunk/otf_encoder.rb +1 -1
  13. data/lib/ttfunk/reader.rb +3 -3
  14. data/lib/ttfunk/sci_form.rb +1 -1
  15. data/lib/ttfunk/subset.rb +3 -3
  16. data/lib/ttfunk/subset/base.rb +24 -21
  17. data/lib/ttfunk/subset/code_page.rb +16 -19
  18. data/lib/ttfunk/subset/unicode.rb +8 -6
  19. data/lib/ttfunk/subset/unicode_8bit.rb +14 -12
  20. data/lib/ttfunk/sum.rb +1 -0
  21. data/lib/ttfunk/table/cff.rb +17 -17
  22. data/lib/ttfunk/table/cff/charset.rb +31 -30
  23. data/lib/ttfunk/table/cff/charsets.rb +3 -3
  24. data/lib/ttfunk/table/cff/charstring.rb +54 -55
  25. data/lib/ttfunk/table/cff/dict.rb +6 -4
  26. data/lib/ttfunk/table/cff/encoding.rb +20 -21
  27. data/lib/ttfunk/table/cff/encodings.rb +1 -1
  28. data/lib/ttfunk/table/cff/fd_selector.rb +14 -11
  29. data/lib/ttfunk/table/cff/font_index.rb +7 -6
  30. data/lib/ttfunk/table/cff/index.rb +6 -5
  31. data/lib/ttfunk/table/cff/one_based_index.rb +7 -3
  32. data/lib/ttfunk/table/cff/path.rb +5 -3
  33. data/lib/ttfunk/table/cff/top_dict.rb +7 -6
  34. data/lib/ttfunk/table/cff/top_index.rb +5 -4
  35. data/lib/ttfunk/table/cmap.rb +8 -6
  36. data/lib/ttfunk/table/cmap/format00.rb +7 -6
  37. data/lib/ttfunk/table/cmap/format04.rb +16 -15
  38. data/lib/ttfunk/table/cmap/format06.rb +6 -5
  39. data/lib/ttfunk/table/cmap/format10.rb +6 -5
  40. data/lib/ttfunk/table/cmap/format12.rb +13 -12
  41. data/lib/ttfunk/table/cmap/subtable.rb +4 -4
  42. data/lib/ttfunk/table/dsig.rb +11 -9
  43. data/lib/ttfunk/table/glyf.rb +3 -3
  44. data/lib/ttfunk/table/glyf/compound.rb +8 -8
  45. data/lib/ttfunk/table/hmtx.rb +6 -5
  46. data/lib/ttfunk/table/kern.rb +4 -4
  47. data/lib/ttfunk/table/kern/format0.rb +1 -1
  48. data/lib/ttfunk/table/loca.rb +7 -6
  49. data/lib/ttfunk/table/name.rb +6 -5
  50. data/lib/ttfunk/table/os2.rb +261 -151
  51. data/lib/ttfunk/table/post.rb +1 -1
  52. data/lib/ttfunk/table/sbix.rb +15 -13
  53. data/lib/ttfunk/table/vorg.rb +1 -1
  54. data/lib/ttfunk/ttf_encoder.rb +4 -4
  55. metadata +29 -99
  56. metadata.gz.sig +0 -0
@@ -44,100 +44,209 @@ module TTFunk
44
44
  attr_reader :max_context
45
45
 
46
46
  CODE_PAGE_BITS = {
47
- 1252 => 0, 1250 => 1, 1251 => 2, 1253 => 3, 1254 => 4,
48
- 1255 => 5, 1256 => 6, 1257 => 7, 1258 => 8, 874 => 16,
49
- 932 => 17, 936 => 18, 949 => 19, 950 => 20, 1361 => 21,
50
- 10_000 => 29, 869 => 48, 866 => 49, 865 => 50, 864 => 51,
51
- 863 => 52, 862 => 53, 861 => 54, 860 => 55, 857 => 56,
52
- 855 => 57, 852 => 58, 775 => 59, 737 => 60, 708 => 61,
53
- 850 => 62, 437 => 63
47
+ 1252 => 0,
48
+ 1250 => 1,
49
+ 1251 => 2,
50
+ 1253 => 3,
51
+ 1254 => 4,
52
+ 1255 => 5,
53
+ 1256 => 6,
54
+ 1257 => 7,
55
+ 1258 => 8,
56
+ 874 => 16,
57
+ 932 => 17,
58
+ 936 => 18,
59
+ 949 => 19,
60
+ 950 => 20,
61
+ 1361 => 21,
62
+ 10_000 => 29,
63
+ 869 => 48,
64
+ 866 => 49,
65
+ 865 => 50,
66
+ 864 => 51,
67
+ 863 => 52,
68
+ 862 => 53,
69
+ 861 => 54,
70
+ 860 => 55,
71
+ 857 => 56,
72
+ 855 => 57,
73
+ 852 => 58,
74
+ 775 => 59,
75
+ 737 => 60,
76
+ 708 => 61,
77
+ 850 => 62,
78
+ 437 => 63
54
79
  }.freeze
55
80
 
56
81
  UNICODE_BLOCKS = {
57
- (0x0000..0x007F) => 0, (0x0080..0x00FF) => 1,
58
- (0x0100..0x017F) => 2, (0x0180..0x024F) => 3,
59
- (0x0250..0x02AF) => 4, (0x1D00..0x1D7F) => 4,
60
- (0x1D80..0x1DBF) => 4, (0x02B0..0x02FF) => 5,
61
- (0xA700..0xA71F) => 5, (0x0300..0x036F) => 6,
62
- (0x1DC0..0x1DFF) => 6, (0x0370..0x03FF) => 7,
63
- (0x2C80..0x2CFF) => 8, (0x0400..0x04FF) => 9,
64
- (0x0500..0x052F) => 9, (0x2DE0..0x2DFF) => 9,
65
- (0xA640..0xA69F) => 9, (0x0530..0x058F) => 10,
66
- (0x0590..0x05FF) => 11, (0xA500..0xA63F) => 12,
67
- (0x0600..0x06FF) => 13, (0x0750..0x077F) => 13,
68
- (0x07C0..0x07FF) => 14, (0x0900..0x097F) => 15,
69
- (0x0980..0x09FF) => 16, (0x0A00..0x0A7F) => 17,
70
- (0x0A80..0x0AFF) => 18, (0x0B00..0x0B7F) => 19,
71
- (0x0B80..0x0BFF) => 20, (0x0C00..0x0C7F) => 21,
72
- (0x0C80..0x0CFF) => 22, (0x0D00..0x0D7F) => 23,
73
- (0x0E00..0x0E7F) => 24, (0x0E80..0x0EFF) => 25,
74
- (0x10A0..0x10FF) => 26, (0x2D00..0x2D2F) => 26,
75
- (0x1B00..0x1B7F) => 27, (0x1100..0x11FF) => 28,
76
- (0x1E00..0x1EFF) => 29, (0x2C60..0x2C7F) => 29,
77
- (0xA720..0xA7FF) => 29, (0x1F00..0x1FFF) => 30,
78
- (0x2000..0x206F) => 31, (0x2E00..0x2E7F) => 31,
79
- (0x2070..0x209F) => 32, (0x20A0..0x20CF) => 33,
80
- (0x20D0..0x20FF) => 34, (0x2100..0x214F) => 35,
81
- (0x2150..0x218F) => 36, (0x2190..0x21FF) => 37,
82
- (0x27F0..0x27FF) => 37, (0x2900..0x297F) => 37,
83
- (0x2B00..0x2BFF) => 37, (0x2200..0x22FF) => 38,
84
- (0x2A00..0x2AFF) => 38, (0x27C0..0x27EF) => 38,
85
- (0x2980..0x29FF) => 38, (0x2300..0x23FF) => 39,
86
- (0x2400..0x243F) => 40, (0x2440..0x245F) => 41,
87
- (0x2460..0x24FF) => 42, (0x2500..0x257F) => 43,
88
- (0x2580..0x259F) => 44, (0x25A0..0x25FF) => 45,
89
- (0x2600..0x26FF) => 46, (0x2700..0x27BF) => 47,
90
- (0x3000..0x303F) => 48, (0x3040..0x309F) => 49,
91
- (0x30A0..0x30FF) => 50, (0x31F0..0x31FF) => 50,
92
- (0x3100..0x312F) => 51, (0x31A0..0x31BF) => 51,
93
- (0x3130..0x318F) => 52, (0xA840..0xA87F) => 53,
94
- (0x3200..0x32FF) => 54, (0x3300..0x33FF) => 55,
95
- (0xAC00..0xD7AF) => 56, (0xD800..0xDFFF) => 57,
96
- (0x10900..0x1091F) => 58, (0x4E00..0x9FFF) => 59,
97
- (0x2E80..0x2EFF) => 59, (0x2F00..0x2FDF) => 59,
98
- (0x2FF0..0x2FFF) => 59, (0x3400..0x4DBF) => 59,
99
- (0x20000..0x2A6DF) => 59, (0x3190..0x319F) => 59,
100
- (0xE000..0xF8FF) => 60, (0x31C0..0x31EF) => 61,
101
- (0xF900..0xFAFF) => 61, (0x2F800..0x2FA1F) => 61,
102
- (0xFB00..0xFB4F) => 62, (0xFB50..0xFDFF) => 63,
103
- (0xFE20..0xFE2F) => 64, (0xFE10..0xFE1F) => 65,
104
- (0xFE30..0xFE4F) => 65, (0xFE50..0xFE6F) => 66,
105
- (0xFE70..0xFEFF) => 67, (0xFF00..0xFFEF) => 68,
106
- (0xFFF0..0xFFFF) => 69, (0x0F00..0x0FFF) => 70,
107
- (0x0700..0x074F) => 71, (0x0780..0x07BF) => 72,
108
- (0x0D80..0x0DFF) => 73, (0x1000..0x109F) => 74,
109
- (0x1200..0x137F) => 75, (0x1380..0x139F) => 75,
110
- (0x2D80..0x2DDF) => 75, (0x13A0..0x13FF) => 76,
111
- (0x1400..0x167F) => 77, (0x1680..0x169F) => 78,
112
- (0x16A0..0x16FF) => 79, (0x1780..0x17FF) => 80,
113
- (0x19E0..0x19FF) => 80, (0x1800..0x18AF) => 81,
114
- (0x2800..0x28FF) => 82, (0xA000..0xA48F) => 83,
115
- (0xA490..0xA4CF) => 83, (0x1700..0x171F) => 84,
116
- (0x1720..0x173F) => 84, (0x1740..0x175F) => 84,
117
- (0x1760..0x177F) => 84, (0x10300..0x1032F) => 85,
118
- (0x10330..0x1034F) => 86, (0x10400..0x1044F) => 87,
119
- (0x1D000..0x1D0FF) => 88, (0x1D100..0x1D1FF) => 88,
120
- (0x1D200..0x1D24F) => 88, (0x1D400..0x1D7FF) => 89,
121
- (0xF0000..0xFFFFD) => 90, (0x100000..0x10FFFD) => 90,
122
- (0xFE00..0xFE0F) => 91, (0xE0100..0xE01EF) => 91,
123
- (0xE0000..0xE007F) => 92, (0x1900..0x194F) => 93,
124
- (0x1950..0x197F) => 94, (0x1980..0x19DF) => 95,
125
- (0x1A00..0x1A1F) => 96, (0x2C00..0x2C5F) => 97,
126
- (0x2D30..0x2D7F) => 98, (0x4DC0..0x4DFF) => 99,
127
- (0xA800..0xA82F) => 100, (0x10000..0x1007F) => 101,
128
- (0x10080..0x100FF) => 101, (0x10100..0x1013F) => 101,
129
- (0x10140..0x1018F) => 102, (0x10380..0x1039F) => 103,
130
- (0x103A0..0x103DF) => 104, (0x10450..0x1047F) => 105,
131
- (0x10480..0x104AF) => 106, (0x10800..0x1083F) => 107,
132
- (0x10A00..0x10A5F) => 108, (0x1D300..0x1D35F) => 109,
133
- (0x12000..0x123FF) => 110, (0x12400..0x1247F) => 110,
134
- (0x1D360..0x1D37F) => 111, (0x1B80..0x1BBF) => 112,
135
- (0x1C00..0x1C4F) => 113, (0x1C50..0x1C7F) => 114,
136
- (0xA880..0xA8DF) => 115, (0xA900..0xA92F) => 116,
137
- (0xA930..0xA95F) => 117, (0xAA00..0xAA5F) => 118,
138
- (0x10190..0x101CF) => 119, (0x101D0..0x101FF) => 120,
139
- (0x102A0..0x102DF) => 121, (0x10280..0x1029F) => 121,
140
- (0x10920..0x1093F) => 121, (0x1F030..0x1F09F) => 122,
82
+ (0x0000..0x007F) => 0,
83
+ (0x0080..0x00FF) => 1,
84
+ (0x0100..0x017F) => 2,
85
+ (0x0180..0x024F) => 3,
86
+ (0x0250..0x02AF) => 4,
87
+ (0x1D00..0x1D7F) => 4,
88
+ (0x1D80..0x1DBF) => 4,
89
+ (0x02B0..0x02FF) => 5,
90
+ (0xA700..0xA71F) => 5,
91
+ (0x0300..0x036F) => 6,
92
+ (0x1DC0..0x1DFF) => 6,
93
+ (0x0370..0x03FF) => 7,
94
+ (0x2C80..0x2CFF) => 8,
95
+ (0x0400..0x04FF) => 9,
96
+ (0x0500..0x052F) => 9,
97
+ (0x2DE0..0x2DFF) => 9,
98
+ (0xA640..0xA69F) => 9,
99
+ (0x0530..0x058F) => 10,
100
+ (0x0590..0x05FF) => 11,
101
+ (0xA500..0xA63F) => 12,
102
+ (0x0600..0x06FF) => 13,
103
+ (0x0750..0x077F) => 13,
104
+ (0x07C0..0x07FF) => 14,
105
+ (0x0900..0x097F) => 15,
106
+ (0x0980..0x09FF) => 16,
107
+ (0x0A00..0x0A7F) => 17,
108
+ (0x0A80..0x0AFF) => 18,
109
+ (0x0B00..0x0B7F) => 19,
110
+ (0x0B80..0x0BFF) => 20,
111
+ (0x0C00..0x0C7F) => 21,
112
+ (0x0C80..0x0CFF) => 22,
113
+ (0x0D00..0x0D7F) => 23,
114
+ (0x0E00..0x0E7F) => 24,
115
+ (0x0E80..0x0EFF) => 25,
116
+ (0x10A0..0x10FF) => 26,
117
+ (0x2D00..0x2D2F) => 26,
118
+ (0x1B00..0x1B7F) => 27,
119
+ (0x1100..0x11FF) => 28,
120
+ (0x1E00..0x1EFF) => 29,
121
+ (0x2C60..0x2C7F) => 29,
122
+ (0xA720..0xA7FF) => 29,
123
+ (0x1F00..0x1FFF) => 30,
124
+ (0x2000..0x206F) => 31,
125
+ (0x2E00..0x2E7F) => 31,
126
+ (0x2070..0x209F) => 32,
127
+ (0x20A0..0x20CF) => 33,
128
+ (0x20D0..0x20FF) => 34,
129
+ (0x2100..0x214F) => 35,
130
+ (0x2150..0x218F) => 36,
131
+ (0x2190..0x21FF) => 37,
132
+ (0x27F0..0x27FF) => 37,
133
+ (0x2900..0x297F) => 37,
134
+ (0x2B00..0x2BFF) => 37,
135
+ (0x2200..0x22FF) => 38,
136
+ (0x2A00..0x2AFF) => 38,
137
+ (0x27C0..0x27EF) => 38,
138
+ (0x2980..0x29FF) => 38,
139
+ (0x2300..0x23FF) => 39,
140
+ (0x2400..0x243F) => 40,
141
+ (0x2440..0x245F) => 41,
142
+ (0x2460..0x24FF) => 42,
143
+ (0x2500..0x257F) => 43,
144
+ (0x2580..0x259F) => 44,
145
+ (0x25A0..0x25FF) => 45,
146
+ (0x2600..0x26FF) => 46,
147
+ (0x2700..0x27BF) => 47,
148
+ (0x3000..0x303F) => 48,
149
+ (0x3040..0x309F) => 49,
150
+ (0x30A0..0x30FF) => 50,
151
+ (0x31F0..0x31FF) => 50,
152
+ (0x3100..0x312F) => 51,
153
+ (0x31A0..0x31BF) => 51,
154
+ (0x3130..0x318F) => 52,
155
+ (0xA840..0xA87F) => 53,
156
+ (0x3200..0x32FF) => 54,
157
+ (0x3300..0x33FF) => 55,
158
+ (0xAC00..0xD7AF) => 56,
159
+ (0xD800..0xDFFF) => 57,
160
+ (0x10900..0x1091F) => 58,
161
+ (0x4E00..0x9FFF) => 59,
162
+ (0x2E80..0x2EFF) => 59,
163
+ (0x2F00..0x2FDF) => 59,
164
+ (0x2FF0..0x2FFF) => 59,
165
+ (0x3400..0x4DBF) => 59,
166
+ (0x20000..0x2A6DF) => 59,
167
+ (0x3190..0x319F) => 59,
168
+ (0xE000..0xF8FF) => 60,
169
+ (0x31C0..0x31EF) => 61,
170
+ (0xF900..0xFAFF) => 61,
171
+ (0x2F800..0x2FA1F) => 61,
172
+ (0xFB00..0xFB4F) => 62,
173
+ (0xFB50..0xFDFF) => 63,
174
+ (0xFE20..0xFE2F) => 64,
175
+ (0xFE10..0xFE1F) => 65,
176
+ (0xFE30..0xFE4F) => 65,
177
+ (0xFE50..0xFE6F) => 66,
178
+ (0xFE70..0xFEFF) => 67,
179
+ (0xFF00..0xFFEF) => 68,
180
+ (0xFFF0..0xFFFF) => 69,
181
+ (0x0F00..0x0FFF) => 70,
182
+ (0x0700..0x074F) => 71,
183
+ (0x0780..0x07BF) => 72,
184
+ (0x0D80..0x0DFF) => 73,
185
+ (0x1000..0x109F) => 74,
186
+ (0x1200..0x137F) => 75,
187
+ (0x1380..0x139F) => 75,
188
+ (0x2D80..0x2DDF) => 75,
189
+ (0x13A0..0x13FF) => 76,
190
+ (0x1400..0x167F) => 77,
191
+ (0x1680..0x169F) => 78,
192
+ (0x16A0..0x16FF) => 79,
193
+ (0x1780..0x17FF) => 80,
194
+ (0x19E0..0x19FF) => 80,
195
+ (0x1800..0x18AF) => 81,
196
+ (0x2800..0x28FF) => 82,
197
+ (0xA000..0xA48F) => 83,
198
+ (0xA490..0xA4CF) => 83,
199
+ (0x1700..0x171F) => 84,
200
+ (0x1720..0x173F) => 84,
201
+ (0x1740..0x175F) => 84,
202
+ (0x1760..0x177F) => 84,
203
+ (0x10300..0x1032F) => 85,
204
+ (0x10330..0x1034F) => 86,
205
+ (0x10400..0x1044F) => 87,
206
+ (0x1D000..0x1D0FF) => 88,
207
+ (0x1D100..0x1D1FF) => 88,
208
+ (0x1D200..0x1D24F) => 88,
209
+ (0x1D400..0x1D7FF) => 89,
210
+ (0xF0000..0xFFFFD) => 90,
211
+ (0x100000..0x10FFFD) => 90,
212
+ (0xFE00..0xFE0F) => 91,
213
+ (0xE0100..0xE01EF) => 91,
214
+ (0xE0000..0xE007F) => 92,
215
+ (0x1900..0x194F) => 93,
216
+ (0x1950..0x197F) => 94,
217
+ (0x1980..0x19DF) => 95,
218
+ (0x1A00..0x1A1F) => 96,
219
+ (0x2C00..0x2C5F) => 97,
220
+ (0x2D30..0x2D7F) => 98,
221
+ (0x4DC0..0x4DFF) => 99,
222
+ (0xA800..0xA82F) => 100,
223
+ (0x10000..0x1007F) => 101,
224
+ (0x10080..0x100FF) => 101,
225
+ (0x10100..0x1013F) => 101,
226
+ (0x10140..0x1018F) => 102,
227
+ (0x10380..0x1039F) => 103,
228
+ (0x103A0..0x103DF) => 104,
229
+ (0x10450..0x1047F) => 105,
230
+ (0x10480..0x104AF) => 106,
231
+ (0x10800..0x1083F) => 107,
232
+ (0x10A00..0x10A5F) => 108,
233
+ (0x1D300..0x1D35F) => 109,
234
+ (0x12000..0x123FF) => 110,
235
+ (0x12400..0x1247F) => 110,
236
+ (0x1D360..0x1D37F) => 111,
237
+ (0x1B80..0x1BBF) => 112,
238
+ (0x1C00..0x1C4F) => 113,
239
+ (0x1C50..0x1C7F) => 114,
240
+ (0xA880..0xA8DF) => 115,
241
+ (0xA900..0xA92F) => 116,
242
+ (0xA930..0xA95F) => 117,
243
+ (0xAA00..0xAA5F) => 118,
244
+ (0x10190..0x101CF) => 119,
245
+ (0x101D0..0x101FF) => 120,
246
+ (0x102A0..0x102DF) => 121,
247
+ (0x10280..0x1029F) => 121,
248
+ (0x10920..0x1093F) => 121,
249
+ (0x1F030..0x1F09F) => 122,
141
250
  (0x1F000..0x1F02F) => 122
142
251
  }.freeze
143
252
 
@@ -174,70 +283,71 @@ module TTFunk
174
283
 
175
284
  class << self
176
285
  def encode(os2, subset)
177
- ''.b.tap do |result|
286
+ result = ''.b
287
+ result << [
288
+ os2.version, avg_char_width_for(os2, subset), os2.weight_class,
289
+ os2.width_class, os2.type, os2.y_subscript_x_size,
290
+ os2.y_subscript_y_size, os2.y_subscript_x_offset,
291
+ os2.y_subscript_y_offset, os2.y_superscript_x_size,
292
+ os2.y_superscript_y_size, os2.y_superscript_x_offset,
293
+ os2.y_superscript_y_offset, os2.y_strikeout_size,
294
+ os2.y_strikeout_position, os2.family_class
295
+ ].pack('n*')
296
+
297
+ result << os2.panose
298
+
299
+ new_char_range = unicode_blocks_for(os2, os2.char_range, subset)
300
+ result << BinUtils
301
+ .slice_int(
302
+ new_char_range.value,
303
+ bit_width: 32,
304
+ slice_count: 4
305
+ )
306
+ .pack('N*')
307
+
308
+ result << os2.vendor_id
309
+
310
+ new_cmap_table = subset.new_cmap_table[:charmap]
311
+ code_points = new_cmap_table
312
+ .keys
313
+ .select { |k| (new_cmap_table[k][:new]).positive? }
314
+ .sort
315
+
316
+ # "This value depends on which character sets the font supports.
317
+ # This field cannot represent supplementary character values
318
+ # (codepoints greater than 0xFFFF). Fonts that support
319
+ # supplementary characters should set the value in this field
320
+ # to 0xFFFF."
321
+ first_char_index = [code_points.first || 0, UNICODE_MAX].min
322
+ last_char_index = [code_points.last || 0, UNICODE_MAX].min
323
+
324
+ result << [
325
+ os2.selection, first_char_index, last_char_index
326
+ ].pack('n*')
327
+
328
+ if os2.version.positive?
178
329
  result << [
179
- os2.version, avg_char_width_for(os2, subset), os2.weight_class,
180
- os2.width_class, os2.type, os2.y_subscript_x_size,
181
- os2.y_subscript_y_size, os2.y_subscript_x_offset,
182
- os2.y_subscript_y_offset, os2.y_superscript_x_size,
183
- os2.y_superscript_y_size, os2.y_superscript_x_offset,
184
- os2.y_superscript_y_offset, os2.y_strikeout_size,
185
- os2.y_strikeout_position, os2.family_class
330
+ os2.ascent, os2.descent, os2.line_gap,
331
+ os2.win_ascent, os2.win_descent
186
332
  ].pack('n*')
187
333
 
188
- result << os2.panose
189
-
190
- new_char_range = unicode_blocks_for(os2, os2.char_range, subset)
191
334
  result << BinUtils
192
- .slice_int(
193
- new_char_range.value,
194
- bit_width: 32,
195
- slice_count: 4
196
- )
197
- .pack('N*')
198
-
199
- result << os2.vendor_id
200
-
201
- new_cmap_table = subset.new_cmap_table[:charmap]
202
- code_points = new_cmap_table
203
- .keys
204
- .select { |k| new_cmap_table[k][:new] > 0 }
205
- .sort
206
-
207
- # "This value depends on which character sets the font supports.
208
- # This field cannot represent supplementary character values
209
- # (codepoints greater than 0xFFFF). Fonts that support
210
- # supplementary characters should set the value in this field
211
- # to 0xFFFF."
212
- first_char_index = [code_points.first || 0, UNICODE_MAX].min
213
- last_char_index = [code_points.last || 0, UNICODE_MAX].min
214
-
215
- result << [
216
- os2.selection, first_char_index, last_char_index
217
- ].pack('n*')
218
-
219
- if os2.version > 0
335
+ .slice_int(
336
+ code_pages_for(subset).value,
337
+ bit_width: 32,
338
+ slice_count: 2
339
+ )
340
+ .pack('N*')
341
+
342
+ if os2.version > 1
220
343
  result << [
221
- os2.ascent, os2.descent, os2.line_gap,
222
- os2.win_ascent, os2.win_descent
344
+ os2.x_height, os2.cap_height, os2.default_char,
345
+ os2.break_char, os2.max_context
223
346
  ].pack('n*')
224
-
225
- result << BinUtils
226
- .slice_int(
227
- code_pages_for(subset).value,
228
- bit_width: 32,
229
- slice_count: 2
230
- )
231
- .pack('N*')
232
-
233
- if os2.version > 1
234
- result << [
235
- os2.x_height, os2.cap_height, os2.default_char,
236
- os2.break_char, os2.max_context
237
- ].pack('n*')
238
- end
239
347
  end
240
348
  end
349
+
350
+ result
241
351
  end
242
352
 
243
353
  private
@@ -298,11 +408,11 @@ module TTFunk
298
408
  subset.new_to_old_glyph.each do |_, old_gid|
299
409
  if (metric = os2.file.horizontal_metrics.for(old_gid))
300
410
  total_width += metric.advance_width
301
- num_glyphs += 1 if metric.advance_width > 0
411
+ num_glyphs += 1 if metric.advance_width.positive?
302
412
  end
303
413
  end
304
414
 
305
- return 0 if num_glyphs == 0
415
+ return 0 if num_glyphs.zero?
306
416
 
307
417
  total_width / num_glyphs # this should be a whole number
308
418
  end
@@ -352,7 +462,7 @@ module TTFunk
352
462
  end
353
463
  end
354
464
 
355
- return 0 if num_glyphs == 0
465
+ return 0 if num_glyphs.zero?
356
466
 
357
467
  total_width / num_glyphs # this should be a whole number
358
468
  end
@@ -378,7 +488,7 @@ module TTFunk
378
488
  @vendor_id = io.read(4)
379
489
  @selection, @first_char_index, @last_char_index = read(6, 'n*')
380
490
 
381
- if @version > 0
491
+ if @version.positive?
382
492
  @ascent, @descent, @line_gap = read_signed(3)
383
493
  @win_ascent, @win_descent = read(4, 'nn')
384
494
  @code_page_range = BitField.new(