prawnx 0.1.1 → 0.1.2

This diff represents the content of publicly available package versions that have been released to one of the supported registries. The information contained in this diff is provided for informational purposes only and reflects changes between package versions as they appear in their respective public registries.
checksums.yaml CHANGED
@@ -1,7 +1,7 @@
1
1
  ---
2
2
  SHA256:
3
- metadata.gz: e60737d0cdb31b35fd87d7ca956ab4e4f50328228d0b4073251c2285c0346c44
4
- data.tar.gz: dea3be495ccff7a9b66aad18f3aa9ae7532ed939cca5f851ed21aa65a28302b0
3
+ metadata.gz: 1810084418cb875d2923b99bda0e35ac9554b06aabbe28a5b6018f2b1d8c9e70
4
+ data.tar.gz: c824566dad95353df788a7f4ec5d75990cdd2aebb850ede877fc871b381fd60c
5
5
  SHA512:
6
- metadata.gz: 840c3fb787c44f77858586937b8a606a4d25e1a82b526c2746d1df4578f87f94564491bb81634a264756a6a4efc3cc3430bd889011f8a06a3f4f345f94f376f5
7
- data.tar.gz: 2e8a93a63e8b4e920131f97df9e0a016e380b43c14ce4304515a48703315b51efa4675389877eb20b6de344fc94b2725eaddfb40c26dfb1d14c796129618d2b2
6
+ metadata.gz: e3620c13261d1a55bd031c38161a1613abe867d3ec7a78ba60288b7b7fc0f0c414fb73b560c7b3c6b1c10e72b923ca84e65edbfe889be5e61ccb3310e50f8e59
7
+ data.tar.gz: ed772792d477cf06e54ff27283b6d0dfb49b7759ea22fe763cbeb0f1de73cdc3d602765a0fb456d04483eec685a98f3b05ca0296ff42566c0bcb0a48ec14e707
@@ -149,33 +149,13 @@ module PrawnX
149
149
  !read_unicode_cmap.nil?
150
150
  end
151
151
 
152
- # The first kerning subtable's pairs of glyphs, in font units.
153
- def kerning_by_glyph_pair
154
- @kerning_by_glyph_pair ||= begin
155
- kern = table("kern")
156
- next_pairs = nil
157
- if kern
158
- version = kern.unpack1("n")
159
- if version == 1
160
- length, coverage = kern.unpack("@8 N n")
161
- next_pairs = kern.byteslice(16, length - 8) if (coverage & 0xFF).zero?
162
- elsif kern.unpack1("@2 n").positive?
163
- coverage = kern.unpack1("@8 n")
164
- next_pairs = kern.byteslice(10..) if (coverage >> 8).zero?
165
- end
166
- end
167
- next_pairs ? format0_pairs(next_pairs) : {}
168
- end
169
- end
170
-
171
152
  def kerning?
172
- !kerning_by_glyph_pair.empty?
153
+ !kerning_by_glyph_key.empty?
173
154
  end
174
155
 
175
156
  # Kerning between two glyphs, in font units, or nil.
176
157
  def kerning_offset(left, right)
177
- @kerning_by_glyph_key ||= kerning_by_glyph_pair.transform_keys { |(first, second)| (first << 16) | second }
178
- @kerning_by_glyph_key[(left << 16) | right]
158
+ kerning_by_glyph_key[(left << 16) | right]
179
159
  end
180
160
 
181
161
  def glyph_data(glyph)
@@ -201,7 +181,7 @@ module PrawnX
201
181
  header
202
182
  advance_widths
203
183
  read_unicode_cmap
204
- kerning_by_glyph_pair
184
+ kerning_by_glyph_key
205
185
  validate_glyph_offsets! if outline_format == :true_type
206
186
  end
207
187
 
@@ -237,16 +217,31 @@ module PrawnX
237
217
  end
238
218
  end
239
219
 
240
- def format0_pairs(subtable)
241
- pair_count = subtable.unpack1("n")
242
- values = subtable.unpack("@8 n#{pair_count * 3}")
243
- values.each_slice(3).each_with_object({}) do |(left, right, value), pairs|
244
- break pairs if value.nil?
245
-
246
- pairs[[left, right]] = value >= 0x8000 ? value - 0x10000 : value
220
+ # The first kerning subtable's values, keyed by `left << 16 | right` like its records.
221
+ def kerning_by_glyph_key
222
+ @kerning_by_glyph_key ||= begin
223
+ kern = table("kern")
224
+ subtable = nil
225
+ if kern
226
+ version = kern.unpack1("n")
227
+ if version == 1
228
+ length, coverage = kern.unpack("@8 N n")
229
+ subtable = kern.byteslice(16, length - 8) if (coverage & 0xFF).zero?
230
+ elsif kern.unpack1("@2 n").positive?
231
+ coverage = kern.unpack1("@8 n")
232
+ subtable = kern.byteslice(10..) if (coverage >> 8).zero?
233
+ end
234
+ end
235
+ subtable ? format0_kerning_by_glyph_key(subtable) : {}
247
236
  end
248
237
  end
249
238
 
239
+ # A format 0 record is a uint32 glyph pair key then an int16 value: `N s>` reads both as they are stored.
240
+ def format0_kerning_by_glyph_key(subtable)
241
+ pair_count = [subtable.unpack1("n"), (subtable.bytesize - 8) / 6].min
242
+ Hash[*subtable.unpack("@8 #{"N s>" * pair_count}")]
243
+ end
244
+
250
245
  def read_table_directory
251
246
  version, table_count = @bytes.unpack("@#{@offset} a4 n")
252
247
  raise Error, "Not a TrueType font" unless TRUE_TYPE_VERSIONS.include?(version) || version == "OTTO"
@@ -3,5 +3,5 @@
3
3
  module PrawnX
4
4
  # The Prawn API PrawnX reproduces. Prawn is PrawnX, so this is also Prawn::VERSION, which prawn-svg and others check.
5
5
  VERSION = "2.5.0"
6
- GEM_VERSION = "0.1.1"
6
+ GEM_VERSION = "0.1.2"
7
7
  end
metadata CHANGED
@@ -1,7 +1,7 @@
1
1
  --- !ruby/object:Gem::Specification
2
2
  name: prawnx
3
3
  version: !ruby/object:Gem::Version
4
- version: 0.1.1
4
+ version: 0.1.2
5
5
  platform: ruby
6
6
  authors:
7
7
  - Clément Joubert