ttfunk 1.4.0 → 1.5.0

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.
Files changed (50) hide show
  1. checksums.yaml +4 -4
  2. checksums.yaml.gz.sig +0 -0
  3. data.tar.gz.sig +0 -0
  4. data/CHANGELOG.md +114 -0
  5. data/{README.rdoc → README.md} +12 -8
  6. data/lib/ttfunk.rb +27 -21
  7. data/lib/ttfunk/collection.rb +41 -0
  8. data/lib/ttfunk/directory.rb +10 -4
  9. data/lib/ttfunk/encoding/mac_roman.rb +50 -40
  10. data/lib/ttfunk/encoding/windows_1252.rb +28 -22
  11. data/lib/ttfunk/reader.rb +11 -10
  12. data/lib/ttfunk/resource_file.rb +28 -21
  13. data/lib/ttfunk/subset.rb +5 -5
  14. data/lib/ttfunk/subset/base.rb +66 -38
  15. data/lib/ttfunk/subset/mac_roman.rb +11 -10
  16. data/lib/ttfunk/subset/unicode.rb +10 -8
  17. data/lib/ttfunk/subset/unicode_8bit.rb +16 -16
  18. data/lib/ttfunk/subset/windows_1252.rb +16 -15
  19. data/lib/ttfunk/subset_collection.rb +7 -8
  20. data/lib/ttfunk/table.rb +3 -5
  21. data/lib/ttfunk/table/cmap.rb +13 -13
  22. data/lib/ttfunk/table/cmap/format00.rb +8 -10
  23. data/lib/ttfunk/table/cmap/format04.rb +37 -32
  24. data/lib/ttfunk/table/cmap/format06.rb +16 -16
  25. data/lib/ttfunk/table/cmap/format10.rb +22 -17
  26. data/lib/ttfunk/table/cmap/format12.rb +28 -22
  27. data/lib/ttfunk/table/cmap/subtable.rb +30 -23
  28. data/lib/ttfunk/table/glyf.rb +13 -11
  29. data/lib/ttfunk/table/glyf/compound.rb +13 -10
  30. data/lib/ttfunk/table/glyf/simple.rb +5 -4
  31. data/lib/ttfunk/table/head.rb +13 -13
  32. data/lib/ttfunk/table/hhea.rb +13 -13
  33. data/lib/ttfunk/table/hmtx.rb +23 -18
  34. data/lib/ttfunk/table/kern.rb +57 -48
  35. data/lib/ttfunk/table/kern/format0.rb +18 -10
  36. data/lib/ttfunk/table/loca.rb +9 -9
  37. data/lib/ttfunk/table/maxp.rb +9 -9
  38. data/lib/ttfunk/table/name.rb +65 -56
  39. data/lib/ttfunk/table/os2.rb +21 -21
  40. data/lib/ttfunk/table/post.rb +32 -32
  41. data/lib/ttfunk/table/post/format10.rb +33 -27
  42. data/lib/ttfunk/table/post/format20.rb +10 -10
  43. data/lib/ttfunk/table/post/format30.rb +5 -5
  44. data/lib/ttfunk/table/post/format40.rb +3 -3
  45. data/lib/ttfunk/table/sbix.rb +19 -10
  46. metadata +55 -32
  47. metadata.gz.sig +0 -0
  48. data/CHANGELOG +0 -5
  49. data/data/fonts/DejaVuSans.ttf +0 -0
  50. data/examples/metrics.rb +0 -45
checksums.yaml CHANGED
@@ -1,7 +1,7 @@
1
1
  ---
2
2
  SHA1:
3
- metadata.gz: 78159985ca295665778e7a61bc86f5fb60e64576
4
- data.tar.gz: f4c79101f0f684003183e32d9251ca96c3e72222
3
+ metadata.gz: b26efe5c04617356a8a8fdcc35a89bb20c995dd8
4
+ data.tar.gz: 117c4486162e7ef29d4f7f517005a733250affe1
5
5
  SHA512:
6
- metadata.gz: 6b7fa90240e932b32b7f8e5423783bdc295856a3154ac42be83606d5a67cf466f0fab02bcdd2a6a60f5297d69adfcd7fe25f0d7b542fd81500710b1b2a1a8203
7
- data.tar.gz: 9d66adee4258dec0600aa5fb76838f583872aaec2d6ef6772b13596f4b1bda9af1370f50123af195f38bb67accb48e10925ba6542a538d730e80395a6a92f05a
6
+ metadata.gz: 45ce04b7124a8ccea39d8bbe06094ccaf09039f4a55f24f31ed676a397373ffd2dafb930d72c6e97cbf3c6ea5bc99f5877f83de46cec5db19b9ac55844c37722
7
+ data.tar.gz: a3ab18306f52ec8bd0c6bbe163458236b3e4ba4c4713fe19eb9aa1e9d50bd42b291ed4e41ebac21ef17e224f90b09b49598d758d17114d6088efe2391721b324
checksums.yaml.gz.sig ADDED
Binary file
data.tar.gz.sig ADDED
Binary file
data/CHANGELOG.md ADDED
@@ -0,0 +1,114 @@
1
+ # Change Log
2
+
3
+ All notable changes to this project will be documented in this file.
4
+
5
+ The format is based on [Keep a Changelog](http://keepachangelog.com/).
6
+
7
+
8
+ ## [Unreleased]
9
+
10
+ ## [1.5.0] - 2017-02-13
11
+
12
+ ### Added
13
+
14
+ * Support for reading TTF fonts from TTC files
15
+
16
+ ### Changed
17
+
18
+ * Subset font naming is consistent now and depends on content
19
+
20
+
21
+ ## [1.4.0] - 2014-09-21
22
+
23
+ ### Added
24
+
25
+ * sbix table support
26
+
27
+
28
+ ## [1.3.0] - 2014-09-10
29
+
30
+ ### Removed
31
+
32
+ * Post table version 2.5
33
+
34
+
35
+ ## [1.2.2] - 2014-08-29
36
+
37
+ ### Fixed
38
+
39
+ * Ignore unsupported cmap table versions
40
+
41
+
42
+ ## [1.2.1] - 2014-08-28
43
+
44
+ ### Fixed
45
+
46
+ * Added missing Pathname require
47
+
48
+
49
+ ## [1.2.0] - 2014-06-23
50
+
51
+ ### Added
52
+
53
+ * Rubocop checks
54
+ * Ability to parse IO objects
55
+
56
+ ### Changed
57
+
58
+ * Improved preferred family name selection
59
+
60
+
61
+ ## [1.1.1] - 2014-02-24
62
+
63
+ ### Changed
64
+
65
+ * Clarified licensing
66
+
67
+ ### Removed
68
+
69
+ * comicsans.ttf
70
+
71
+
72
+ ## [1.1.0] - 2014-01-21
73
+
74
+ ### Added
75
+
76
+ * Improved Unicode astral planes support
77
+ * Support for cmap table formats 6, 10, 12
78
+ * RSpec-based specs
79
+
80
+ ### Fixed
81
+
82
+ * Subsetting in JRuby
83
+
84
+
85
+ ## [1.0.3] - 2011-10-11
86
+
87
+ ### Added
88
+
89
+ * Authorship information
90
+
91
+
92
+ ## 1.0.2 - 2011-08-08
93
+
94
+ ### Fixed
95
+
96
+ * Ruby 1.9.2 segmentation fault on Enumerable#zip(range)
97
+
98
+
99
+ ## 1.0.0 - 2011-04-02 [YANKED]
100
+
101
+ Initial release as a standalone gem
102
+
103
+
104
+
105
+ [Unreleased]: https://github.com/prawnpdf/ttfunk/compare/1.5.0...HEAD
106
+ [1.5.0]: https://github.com/prawnpdf/ttfunk/compare/1.4.0...1.5.0
107
+ [1.4.0]: https://github.com/prawnpdf/ttfunk/compare/1.3.0...1.4.0
108
+ [1.3.0]: https://github.com/prawnpdf/ttfunk/compare/1.2.2...1.3.0
109
+ [1.2.2]: https://github.com/prawnpdf/ttfunk/compare/1.2.1...1.2.2
110
+ [1.2.1]: https://github.com/prawnpdf/ttfunk/compare/1.2.0...1.2.1
111
+ [1.2.0]: https://github.com/prawnpdf/ttfunk/compare/1.1.1...1.2.0
112
+ [1.1.1]: https://github.com/prawnpdf/ttfunk/compare/1.1.0...1.1.1
113
+ [1.1.0]: https://github.com/prawnpdf/ttfunk/compare/1.0.3...1.1.0
114
+ [1.0.3]: https://github.com/prawnpdf/ttfunk/compare/1.0.2...1.0.3
@@ -1,12 +1,16 @@
1
+ # TTFunk
2
+
3
+ ![Maintained: yes](https://img.shields.io/badge/maintained-yes-brightgreen.png)
4
+
1
5
  TTFunk is a TrueType font parser written in pure ruby.
2
6
 
3
- = Installation
7
+ ## Installation
4
8
 
5
9
  The recommended installation method is via Rubygems.
6
10
 
7
- gem install ttfunk
11
+ gem install ttfunk
8
12
 
9
- = Usage
13
+ ## Usage
10
14
 
11
15
  Basic usage:
12
16
 
@@ -19,11 +23,11 @@ Basic usage:
19
23
 
20
24
  For more detailed examples, explore the examples directory.
21
25
 
22
- = Licensing
26
+ ## Licensing
23
27
 
24
28
  Matz's terms for Ruby, GPLv2, or GPLv3. See LICENSE for details.
25
29
 
26
- = Authorship
30
+ ## Authorship
27
31
 
28
32
  This project is maintained by the same folks who run the Prawn PDF project.
29
33
 
@@ -32,10 +36,10 @@ to ttfunk at:
32
36
 
33
37
  https://github.com/prawnpdf/ttfunk/contributors
34
38
 
35
- = Mailing List
39
+ ## Mailing List
36
40
 
37
- TTFunk is maintained as a dependency of prawn, the ruby PDF generation library.
41
+ TTFunk is maintained as a dependency of Prawn, the ruby PDF generation library.
38
42
 
39
43
  Any questions or feedback should be sent to the Prawn google group.
40
44
 
41
- http://groups.google.com/group/prawn-ruby
45
+ https://groups.google.com/group/prawn-ruby
data/lib/ttfunk.rb CHANGED
@@ -3,6 +3,7 @@ require 'pathname'
3
3
 
4
4
  require_relative 'ttfunk/directory'
5
5
  require_relative 'ttfunk/resource_file'
6
+ require_relative 'ttfunk/collection'
6
7
 
7
8
  module TTFunk
8
9
  class File
@@ -13,8 +14,12 @@ module TTFunk
13
14
  new verify_and_open(io_or_path).read
14
15
  end
15
16
 
16
- def self.from_dfont(file, which=0)
17
- new(ResourceFile.open(file) { |dfont| dfont["sfnt", which] })
17
+ def self.from_dfont(file, which = 0)
18
+ new(ResourceFile.open(file) { |dfont| dfont['sfnt', which] })
19
+ end
20
+
21
+ def self.from_ttc(file, which = 0)
22
+ Collection.open(file) { |ttc| ttc[which] }
18
23
  end
19
24
 
20
25
  def self.verify_and_open(io_or_path)
@@ -36,29 +41,30 @@ module TTFunk
36
41
  io
37
42
  end
38
43
 
39
- def initialize(contents)
44
+ def initialize(contents, offset = 0)
40
45
  @contents = StringIO.new(contents)
41
- @directory = Directory.new(@contents)
46
+ @directory = Directory.new(@contents, offset)
42
47
  end
43
48
 
44
-
45
49
  def ascent
46
- @ascent ||= (os2.exists? && os2.ascent && os2.ascent.nonzero?) || horizontal_header.ascent
50
+ @ascent ||= (os2.exists? && os2.ascent && os2.ascent.nonzero?) ||
51
+ horizontal_header.ascent
47
52
  end
48
53
 
49
54
  def descent
50
- @descent ||= (os2.exists? && os2.descent && os2.descent.nonzero?) || horizontal_header.descent
55
+ @descent ||= (os2.exists? && os2.descent && os2.descent.nonzero?) ||
56
+ horizontal_header.descent
51
57
  end
52
58
 
53
59
  def line_gap
54
- @line_gap ||= (os2.exists? && os2.line_gap && os2.line_gap.nonzero?) || horizontal_header.line_gap
60
+ @line_gap ||= (os2.exists? && os2.line_gap && os2.line_gap.nonzero?) ||
61
+ horizontal_header.line_gap
55
62
  end
56
63
 
57
64
  def bbox
58
65
  [header.x_min, header.y_min, header.x_max, header.y_max]
59
66
  end
60
67
 
61
-
62
68
  def directory_info(tag)
63
69
  directory.tables[tag.to_s]
64
70
  end
@@ -113,15 +119,15 @@ module TTFunk
113
119
  end
114
120
  end
115
121
 
116
- require_relative "ttfunk/table/cmap"
117
- require_relative "ttfunk/table/glyf"
118
- require_relative "ttfunk/table/head"
119
- require_relative "ttfunk/table/hhea"
120
- require_relative "ttfunk/table/hmtx"
121
- require_relative "ttfunk/table/kern"
122
- require_relative "ttfunk/table/loca"
123
- require_relative "ttfunk/table/maxp"
124
- require_relative "ttfunk/table/name"
125
- require_relative "ttfunk/table/os2"
126
- require_relative "ttfunk/table/post"
127
- require_relative "ttfunk/table/sbix"
122
+ require_relative 'ttfunk/table/cmap'
123
+ require_relative 'ttfunk/table/glyf'
124
+ require_relative 'ttfunk/table/head'
125
+ require_relative 'ttfunk/table/hhea'
126
+ require_relative 'ttfunk/table/hmtx'
127
+ require_relative 'ttfunk/table/kern'
128
+ require_relative 'ttfunk/table/loca'
129
+ require_relative 'ttfunk/table/maxp'
130
+ require_relative 'ttfunk/table/name'
131
+ require_relative 'ttfunk/table/os2'
132
+ require_relative 'ttfunk/table/post'
133
+ require_relative 'ttfunk/table/sbix'
@@ -0,0 +1,41 @@
1
+ require 'ttfunk'
2
+
3
+ module TTFunk
4
+ class Collection
5
+ include Enumerable
6
+
7
+ def self.open(path)
8
+ ::File.open(path, 'rb') do |io|
9
+ yield new(io)
10
+ end
11
+ end
12
+
13
+ def initialize(io)
14
+ tag = io.read(4)
15
+ raise ArgumentError, 'not a TTC file' unless tag == 'ttcf'
16
+
17
+ _major, _minor = io.read(4).unpack('n*')
18
+ count = io.read(4).unpack('N').first
19
+ @offsets = io.read(count * 4).unpack('N*')
20
+
21
+ io.rewind
22
+ @contents = io.read
23
+ @cache = []
24
+ end
25
+
26
+ def count
27
+ @offsets.length
28
+ end
29
+
30
+ def each
31
+ count.times do |index|
32
+ yield self[index]
33
+ end
34
+ self
35
+ end
36
+
37
+ def [](index)
38
+ @cache[index] ||= TTFunk::File.new(@contents, @offsets[index])
39
+ end
40
+ end
41
+ end
@@ -3,13 +3,19 @@ module TTFunk
3
3
  attr_reader :tables
4
4
  attr_reader :scaler_type
5
5
 
6
- def initialize(io)
7
- @scaler_type, table_count = io.read(12).unpack("Nn")
6
+ def initialize(io, offset = 0)
7
+ io.seek(offset)
8
+ @scaler_type, table_count = io.read(12).unpack('Nn')
8
9
 
9
10
  @tables = {}
10
11
  table_count.times do
11
- tag, checksum, offset, length = io.read(16).unpack("a4N*")
12
- @tables[tag] = { :tag => tag, :checksum => checksum, :offset => offset, :length => length }
12
+ tag, checksum, offset, length = io.read(16).unpack('a4N*')
13
+ @tables[tag] = {
14
+ tag: tag,
15
+ checksum: checksum,
16
+ offset: offset,
17
+ length: length
18
+ }
13
19
  end
14
20
  end
15
21
  end
@@ -1,44 +1,52 @@
1
1
  module TTFunk
2
2
  module Encoding
3
3
  class MacRoman
4
- # XXX: Ruby 1.9.2 on OS X Lion segfaults on range1.zip(range2)
5
- TO_UNICODE = Hash[*(0..255).zip((0..255).to_a).flatten]
4
+ # rubocop: disable Style/ExtraSpacing
6
5
 
7
- TO_UNICODE.update(
8
- 0x81 => 0x00C5, 0x82 => 0x00C7, 0x83 => 0x00C9, 0x84 => 0x00D1, 0x85 => 0x00D6,
9
- 0x86 => 0x00DC, 0x87 => 0x00E1, 0x88 => 0x00E0, 0x89 => 0x00E2, 0x8A => 0x00E4,
10
- 0x8B => 0x00E3, 0x8C => 0x00E5, 0x8D => 0x00E7, 0x8E => 0x00E9, 0x8F => 0x00E8,
11
- 0x90 => 0x00EA, 0x91 => 0x00EB, 0x92 => 0x00ED, 0x93 => 0x00EC, 0x94 => 0x00EE,
12
- 0x95 => 0x00EF, 0x96 => 0x00F1, 0x97 => 0x00F3, 0x98 => 0x00F2, 0x99 => 0x00F4,
13
- 0x9A => 0x00F6, 0x9B => 0x00F5, 0x9C => 0x00FA, 0x9D => 0x00F9, 0x9E => 0x00FB,
14
- 0x9F => 0x00FC, 0xA0 => 0x2020, 0xA1 => 0x00B0, 0xA4 => 0x00A7, 0xA5 => 0x2022,
15
- 0xA6 => 0x00B6, 0xA7 => 0x00DF, 0xA8 => 0x00AE, 0xAA => 0x2122, 0xAB => 0x00B4,
16
- 0xAC => 0x00A8, 0xAD => 0x2260, 0xAE => 0x00C6, 0xAF => 0x00D8, 0xB0 => 0x221E,
17
- 0xB2 => 0x2264, 0xB3 => 0x2265, 0xB4 => 0x00A5, 0xB6 => 0x2202, 0xB7 => 0x2211,
18
- 0xB8 => 0x220F, 0xB9 => 0x03C0, 0xBA => 0x222B, 0xBB => 0x00AA, 0xBC => 0x00BA,
19
- 0xBD => 0x03A9, 0xBE => 0x00E6, 0xBF => 0x00F8, 0xC0 => 0x00BF, 0xC1 => 0x00A1,
20
- 0xC2 => 0x00AC, 0xC3 => 0x221A, 0xC4 => 0x0192, 0xC5 => 0x2248, 0xC6 => 0x2206,
21
- 0xC7 => 0x00AB, 0xC8 => 0x00BB, 0xC9 => 0x2026, 0xCA => 0x00A0, 0xCB => 0x00C0,
22
- 0xCC => 0x00C3, 0xCD => 0x00D5, 0xCE => 0x0152, 0xCF => 0x0153, 0xD0 => 0x2013,
23
- 0xD1 => 0x2014, 0xD2 => 0x201C, 0xD3 => 0x201D, 0xD4 => 0x2018, 0xD5 => 0x2019,
24
- 0xD6 => 0x00F7, 0xD7 => 0x25CA, 0xD8 => 0x00FF, 0xD9 => 0x0178, 0xDA => 0x2044,
25
- 0xDB => 0x20AC, 0xDC => 0x2039, 0xDD => 0x203A, 0xDE => 0xFB01, 0xDF => 0xFB02,
26
- 0xE0 => 0x2021, 0xE1 => 0x00B7, 0xE2 => 0x201A, 0xE3 => 0x201E, 0xE4 => 0x2030,
27
- 0xE5 => 0x00C2, 0xE6 => 0x00CA, 0xE7 => 0x00C1, 0xE8 => 0x00CB, 0xE9 => 0x00C8,
28
- 0xEA => 0x00CD, 0xEB => 0x00CE, 0xEC => 0x00CF, 0xED => 0x00CC, 0xEE => 0x00D3,
29
- 0xEF => 0x00D4, 0xF0 => 0xF8FF, 0xF1 => 0x00D2, 0xF2 => 0x00DA, 0xF3 => 0x00DB,
30
- 0xF4 => 0x00D9, 0xF5 => 0x0131, 0xF6 => 0x02C6, 0xF7 => 0x02DC, 0xF8 => 0x00AF,
31
- 0xF9 => 0x02D8, 0xFA => 0x02D9, 0xFB => 0x02DA, 0xFC => 0x00B8, 0xFD => 0x02DD,
32
- 0xFE => 0x02DB, 0xFF => 0x02C7
33
- )
6
+ TO_UNICODE =
7
+ Hash[*(0..255).zip(0..255).flatten]
8
+ .update(
9
+ 0x81 => 0x00C5, 0x82 => 0x00C7, 0x83 => 0x00C9, 0x84 => 0x00D1,
10
+ 0x85 => 0x00D6, 0x86 => 0x00DC, 0x87 => 0x00E1, 0x88 => 0x00E0,
11
+ 0x89 => 0x00E2, 0x8A => 0x00E4, 0x8B => 0x00E3, 0x8C => 0x00E5,
12
+ 0x8D => 0x00E7, 0x8E => 0x00E9, 0x8F => 0x00E8, 0x90 => 0x00EA,
13
+ 0x91 => 0x00EB, 0x92 => 0x00ED, 0x93 => 0x00EC, 0x94 => 0x00EE,
14
+ 0x95 => 0x00EF, 0x96 => 0x00F1, 0x97 => 0x00F3, 0x98 => 0x00F2,
15
+ 0x99 => 0x00F4, 0x9A => 0x00F6, 0x9B => 0x00F5, 0x9C => 0x00FA,
16
+ 0x9D => 0x00F9, 0x9E => 0x00FB, 0x9F => 0x00FC, 0xA0 => 0x2020,
17
+ 0xA1 => 0x00B0, 0xA4 => 0x00A7, 0xA5 => 0x2022, 0xA6 => 0x00B6,
18
+ 0xA7 => 0x00DF, 0xA8 => 0x00AE, 0xAA => 0x2122, 0xAB => 0x00B4,
19
+ 0xAC => 0x00A8, 0xAD => 0x2260, 0xAE => 0x00C6, 0xAF => 0x00D8,
20
+ 0xB0 => 0x221E, 0xB2 => 0x2264, 0xB3 => 0x2265, 0xB4 => 0x00A5,
21
+ 0xB6 => 0x2202, 0xB7 => 0x2211, 0xB8 => 0x220F, 0xB9 => 0x03C0,
22
+ 0xBA => 0x222B, 0xBB => 0x00AA, 0xBC => 0x00BA, 0xBD => 0x03A9,
23
+ 0xBE => 0x00E6, 0xBF => 0x00F8, 0xC0 => 0x00BF, 0xC1 => 0x00A1,
24
+ 0xC2 => 0x00AC, 0xC3 => 0x221A, 0xC4 => 0x0192, 0xC5 => 0x2248,
25
+ 0xC6 => 0x2206, 0xC7 => 0x00AB, 0xC8 => 0x00BB, 0xC9 => 0x2026,
26
+ 0xCA => 0x00A0, 0xCB => 0x00C0, 0xCC => 0x00C3, 0xCD => 0x00D5,
27
+ 0xCE => 0x0152, 0xCF => 0x0153, 0xD0 => 0x2013, 0xD1 => 0x2014,
28
+ 0xD2 => 0x201C, 0xD3 => 0x201D, 0xD4 => 0x2018, 0xD5 => 0x2019,
29
+ 0xD6 => 0x00F7, 0xD7 => 0x25CA, 0xD8 => 0x00FF, 0xD9 => 0x0178,
30
+ 0xDA => 0x2044, 0xDB => 0x20AC, 0xDC => 0x2039, 0xDD => 0x203A,
31
+ 0xDE => 0xFB01, 0xDF => 0xFB02, 0xE0 => 0x2021, 0xE1 => 0x00B7,
32
+ 0xE2 => 0x201A, 0xE3 => 0x201E, 0xE4 => 0x2030, 0xE5 => 0x00C2,
33
+ 0xE6 => 0x00CA, 0xE7 => 0x00C1, 0xE8 => 0x00CB, 0xE9 => 0x00C8,
34
+ 0xEA => 0x00CD, 0xEB => 0x00CE, 0xEC => 0x00CF, 0xED => 0x00CC,
35
+ 0xEE => 0x00D3, 0xEF => 0x00D4, 0xF0 => 0xF8FF, 0xF1 => 0x00D2,
36
+ 0xF2 => 0x00DA, 0xF3 => 0x00DB, 0xF4 => 0x00D9, 0xF5 => 0x0131,
37
+ 0xF6 => 0x02C6, 0xF7 => 0x02DC, 0xF8 => 0x00AF, 0xF9 => 0x02D8,
38
+ 0xFA => 0x02D9, 0xFB => 0x02DA, 0xFC => 0x00B8, 0xFD => 0x02DD,
39
+ 0xFE => 0x02DB, 0xFF => 0x02C7
40
+ ).freeze
34
41
 
35
- FROM_UNICODE = {}
36
- (0..255).each { |key| FROM_UNICODE[TO_UNICODE[key]] = key }
42
+ FROM_UNICODE = TO_UNICODE.invert.freeze
37
43
 
38
44
  # Maps MacRoman codes to their corresponding index in the Postscript glyph
39
- # table (see TTFunk::Table::Post::Format10). If any entry in this array is a string,
40
- # it is a postscript glyph that is not in the standard list, and which should be
41
- # emitted specially in the TTF postscript table ('post', see format 2).
45
+ # table (see TTFunk::Table::Post::Format10). If any entry in this array is
46
+ # a string, it is a postscript glyph that is not in the standard list, and
47
+ # which should be emitted specially in the TTF postscript table ('post',
48
+ # see format 2).
49
+ # rubocop: disable Metrics/LineLength,Style/AlignArray,Style/IndentArray
42
50
  POSTSCRIPT_GLYPH_MAPPING = [
43
51
  0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, # 0x0F
44
52
  0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, # 0x1F
@@ -53,29 +61,31 @@ module TTFunk
53
61
  130, 131, 132, 133, 134, 135, 136, 137, 138, 139, 140, 141, 142, 143, 144, 145, # 0xAF
54
62
  146, 147, 148, 149, 150, 151, 152, 153, 154, 155, 156, 157, 158, 159, 160, 161, # 0xBF
55
63
  162, 163, 164, 165, 166, 167, 168, 169, 170, 171, 172, 173, 174, 175, 176, 177, # 0xCF
56
- 178, 179, 180, 181, 182, 183, 184, 185, 186, 187, 188, "Euro", 190, 191, 192, 193, # 0xDF
64
+ 178, 179, 180, 181, 182, 183, 184, 185, 186, 187, 188, 'Euro', 190, 191, 192, 193, # 0xDF
57
65
  194, 195, 196, 197, 198, 199, 200, 201, 202, 203, 204, 205, 206, 207, 208, 209, # 0xEF
58
66
  210, 211, 212, 213, 214, 215, 216, 217, 218, 219, 220, 221, 222, 223, 224, 225 # 0xFF
59
- ]
67
+ ].freeze
68
+
69
+ # rubocop: enable Style/AlignArray,Metrics/LineLength,Style/ExtraSpacing,Style/IndentArray
60
70
 
61
71
  def self.covers?(character)
62
72
  !FROM_UNICODE[character].nil?
63
73
  end
64
74
 
65
75
  def self.to_utf8(string)
66
- to_unicode_codepoints(string.unpack("C*")).pack("U*")
76
+ to_unicode_codepoints(string.unpack('C*')).pack('U*')
67
77
  end
68
78
 
69
79
  def self.to_unicode(string)
70
- to_unicode_codepoints(string.unpack("C*")).pack("n*")
80
+ to_unicode_codepoints(string.unpack('C*')).pack('n*')
71
81
  end
72
82
 
73
83
  def self.from_utf8(string)
74
- from_unicode_codepoints(string.unpack("U*")).pack("C*")
84
+ from_unicode_codepoints(string.unpack('U*')).pack('C*')
75
85
  end
76
86
 
77
87
  def self.from_unicode(string)
78
- from_unicode_codepoints(string.unpack("n*")).pack("C*")
88
+ from_unicode_codepoints(string.unpack('n*')).pack('C*')
79
89
  end
80
90
 
81
91
  def self.to_unicode_codepoints(array)