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
@@ -24,15 +24,15 @@ module TTFunk
24
24
  @fixed_pitch != 0
25
25
  end
26
26
 
27
- def glyph_for(code)
28
- ".notdef"
27
+ def glyph_for(_code)
28
+ '.notdef'
29
29
  end
30
30
 
31
31
  def recode(mapping)
32
32
  return raw if format == 0x00030000
33
33
 
34
- table = raw[0,32]
35
- table[0,4] = [0x00020000].pack("N")
34
+ table = raw[0, 32]
35
+ table[0, 4] = [0x00020000].pack('N')
36
36
 
37
37
  index = []
38
38
  strings = []
@@ -48,43 +48,43 @@ module TTFunk
48
48
  end
49
49
  end
50
50
 
51
- table << [mapping.length, *index].pack("n*")
51
+ table << [mapping.length, *index].pack('n*')
52
52
  strings.each do |string|
53
- table << [string.length, string].pack("CA*")
53
+ table << [string.length, string].pack('CA*')
54
54
  end
55
55
 
56
- return table
56
+ table
57
57
  end
58
58
 
59
59
  private
60
60
 
61
- def parse!
62
- @format, @italic_angle, @underline_position, @underline_thickness,
63
- @fixed_pitch, @min_mem_type42, @max_mem_type42,
64
- @min_mem_type1, @max_mem_type1 = read(32, "N2n2N*")
65
-
66
- @subtable = case @format
67
- when 0x00010000
68
- extend(Post::Format10)
69
- when 0x00020000
70
- extend(Post::Format20)
71
- when 0x00025000
72
- raise NotImplementedError,
73
- "Post format 2.5 is not supported by TTFunk"
74
- when 0x00030000
75
- extend(Post::Format30)
76
- when 0x00040000
77
- extend(Post::Format40)
78
- end
79
-
80
- parse_format!
81
- end
61
+ def parse!
62
+ @format, @italic_angle, @underline_position, @underline_thickness,
63
+ @fixed_pitch, @min_mem_type42, @max_mem_type42,
64
+ @min_mem_type1, @max_mem_type1 = read(32, 'N2n2N*')
65
+
66
+ @subtable =
67
+ case @format
68
+ when 0x00010000
69
+ extend(Post::Format10)
70
+ when 0x00020000
71
+ extend(Post::Format20)
72
+ when 0x00025000
73
+ raise NotImplementedError,
74
+ 'Post format 2.5 is not supported by TTFunk'
75
+ when 0x00030000
76
+ extend(Post::Format30)
77
+ when 0x00040000
78
+ extend(Post::Format40)
79
+ end
82
80
 
83
- def parse_format!
84
- warn "postscript table format 0x%08X is not supported" % @format
85
- end
86
- end
81
+ parse_format!
82
+ end
87
83
 
84
+ def parse_format!
85
+ warn format('postscript table format 0x%08X is not supported', @format)
86
+ end
87
+ end
88
88
  end
89
89
  end
90
90
 
@@ -2,41 +2,47 @@ module TTFunk
2
2
  class Table
3
3
  class Post
4
4
  module Format10
5
- POSTSCRIPT_GLYPHS = %w(
6
- .notdef .null nonmarkingreturn space exclam quotedbl numbersign dollar percent
7
- ampersand quotesingle parenleft parenright asterisk plus comma hyphen period slash
8
- zero one two three four five six seven eight nine colon semicolon less equal greater
9
- question at A B C D E F G H I J K L M N O P Q R S T U V W X Y Z
5
+ POSTSCRIPT_GLYPHS = %w[
6
+ .notdef .null nonmarkingreturn space exclam quotedbl numbersign dollar
7
+ percent ampersand quotesingle parenleft parenright asterisk plus comma
8
+ hyphen period slash zero one two three four five six seven eight nine
9
+ colon semicolon less equal greater question at
10
+ A B C D E F G H I J K L M N O P Q R S T U V W X Y Z
10
11
  bracketleft backslash bracketright asciicircum underscore grave
11
12
  a b c d e f g h i j k l m n o p q r s t u v w x y z
12
- braceleft bar braceright asciitilde Adieresis Aring Ccedilla Eacute Ntilde Odieresis
13
- Udieresis aacute agrave acircumflex adieresis atilde aring ccedilla eacute egrave
14
- ecircumflex edieresis iacute igrave icircumflex idieresis ntilde oacute ograve
15
- ocircumflex odieresis otilde uacute ugrave ucircumflex udieresis dagger degree cent
16
- sterling section bullet paragraph germandbls registered copyright trademark acute
17
- dieresis notequal AE Oslash infinity plusminus lessequal greaterequal yen mu
18
- partialdiff summation product pi integral ordfeminine ordmasculine Omega ae oslash
19
- questiondown exclamdown logicalnot radical florin approxequal Delta guillemotleft
20
- guillemotright ellipsis nonbreakingspace Agrave Atilde Otilde OE oe endash emdash
21
- quotedblleft quotedblright quoteleft quoteright divide lozenge ydieresis Ydieresis
22
- fraction currency guilsinglleft guilsinglright fi fl daggerdbl periodcentered
23
- quotesinglbase quotedblbase perthousand Acircumflex Ecircumflex Aacute Edieresis
24
- Egrave Iacute Icircumflex Idieresis Igrave Oacute Ocircumflex apple Ograve Uacute
25
- Ucircumflex Ugrave dotlessi circumflex tilde macron breve dotaccent ring cedilla
26
- hungarumlaut ogonek caron Lslash lslash Scaron scaron Zcaron zcaron brokenbar Eth
27
- eth Yacute yacute Thorn thorn minus multiply onesuperior twosuperior threesuperior
28
- onehalf onequarter threequarters franc Gbreve gbreve Idotaccent Scedilla scedilla
29
- Cacute cacute Ccaron ccaron dcroat)
13
+ braceleft bar braceright asciitilde Adieresis Aring Ccedilla Eacute
14
+ Ntilde Odieresis Udieresis aacute agrave acircumflex adieresis atilde
15
+ aring ccedilla eacute egrave ecircumflex edieresis iacute igrave
16
+ icircumflex idieresis ntilde oacute ograve ocircumflex odieresis
17
+ otilde uacute ugrave ucircumflex udieresis dagger degree cent sterling
18
+ section bullet paragraph germandbls registered copyright trademark
19
+ acute dieresis notequal AE Oslash infinity plusminus lessequal
20
+ greaterequal yen mu partialdiff summation product pi integral
21
+ ordfeminine ordmasculine Omega ae oslash questiondown exclamdown
22
+ logicalnot radical florin approxequal Delta guillemotleft
23
+ guillemotright ellipsis nonbreakingspace Agrave Atilde Otilde OE oe
24
+ endash emdash quotedblleft quotedblright quoteleft quoteright divide
25
+ lozenge ydieresis Ydieresis fraction currency guilsinglleft
26
+ guilsinglright fi fl daggerdbl periodcentered quotesinglbase
27
+ quotedblbase perthousand Acircumflex Ecircumflex Aacute Edieresis
28
+ Egrave Iacute Icircumflex Idieresis Igrave Oacute Ocircumflex apple
29
+ Ograve Uacute Ucircumflex Ugrave dotlessi circumflex tilde macron
30
+ breve dotaccent ring cedilla hungarumlaut ogonek caron Lslash lslash
31
+ Scaron scaron Zcaron zcaron brokenbar Eth eth Yacute yacute Thorn
32
+ thorn minus multiply onesuperior twosuperior threesuperior onehalf
33
+ onequarter threequarters franc Gbreve gbreve Idotaccent Scedilla
34
+ scedilla Cacute cacute Ccaron ccaron dcroat
35
+ ].freeze
30
36
 
31
37
  def glyph_for(code)
32
- POSTSCRIPT_GLYPHS[code] || ".notdef"
38
+ POSTSCRIPT_GLYPHS[code] || '.notdef'
33
39
  end
34
40
 
35
41
  private
36
42
 
37
- def parse_format!
38
- # do nothing. Format 1 is easy-sauce.
39
- end
43
+ def parse_format!
44
+ # do nothing. Format 1 is easy-sauce.
45
+ end
40
46
  end
41
47
  end
42
48
  end
@@ -12,23 +12,23 @@ module TTFunk
12
12
  if index <= 257
13
13
  POSTSCRIPT_GLYPHS[index]
14
14
  else
15
- @names[index - 258] || ".notdef"
15
+ @names[index - 258] || '.notdef'
16
16
  end
17
17
  end
18
18
 
19
19
  private
20
20
 
21
- def parse_format!
22
- number_of_glyphs = read(2, 'n').first
23
- @glyph_name_index = read(number_of_glyphs*2, 'n*')
24
- @names = []
21
+ def parse_format!
22
+ number_of_glyphs = read(2, 'n').first
23
+ @glyph_name_index = read(number_of_glyphs * 2, 'n*')
24
+ @names = []
25
25
 
26
- strings = StringIO.new(io.read(offset + length - io.pos))
27
- while !strings.eof?
28
- length = strings.read(1).unpack("C").first
29
- @names << strings.read(length)
30
- end
26
+ strings = StringIO.new(io.read(offset + length - io.pos))
27
+ until strings.eof?
28
+ length = strings.read(1).unpack('C').first
29
+ @names << strings.read(length)
31
30
  end
31
+ end
32
32
  end
33
33
  end
34
34
  end
@@ -2,15 +2,15 @@ module TTFunk
2
2
  class Table
3
3
  class Post
4
4
  module Format30
5
- def glyph_for(code)
6
- ".notdef"
5
+ def glyph_for(_code)
6
+ '.notdef'
7
7
  end
8
8
 
9
9
  private
10
10
 
11
- def parse_format!
12
- # do nothing. Format 3 is easy-sauce.
13
- end
11
+ def parse_format!
12
+ # do nothing. Format 3 is easy-sauce.
13
+ end
14
14
  end
15
15
  end
16
16
  end
@@ -8,9 +8,9 @@ module TTFunk
8
8
 
9
9
  private
10
10
 
11
- def parse_format!
12
- @map = read(file.maximum_profile.num_glyphs * 2, "N*")
13
- end
11
+ def parse_format!
12
+ @map = read(file.maximum_profile.num_glyphs * 2, 'N*')
13
+ end
14
14
  end
15
15
  end
16
16
  end
@@ -21,9 +21,11 @@ module TTFunk
21
21
  bytes = next_glyph_offset - glyph_offset
22
22
  if bytes > 0
23
23
  parse_from(offset + strike[:offset] + glyph_offset) do
24
- x, y, type = read(8, "s2A4")
24
+ x, y, type = read(8, 's2A4')
25
25
  data = StringIO.new(io.read(bytes - 8))
26
- BitmapData.new(x, y, type, data, strike[:ppem], strike[:resolution])
26
+ BitmapData.new(
27
+ x, y, type, data, strike[:ppem], strike[:resolution]
28
+ )
27
29
  end
28
30
  end
29
31
  end
@@ -37,18 +39,25 @@ module TTFunk
37
39
 
38
40
  private
39
41
 
40
- def parse!
41
- @version, @flags, @num_strikes = read(8, "n2N")
42
- strike_offsets = num_strikes.times.map { read(4, "N").first }
42
+ def parse!
43
+ @version, @flags, @num_strikes = read(8, 'n2N')
44
+ strike_offsets = Array.new(num_strikes) { read(4, 'N').first }
43
45
 
44
- @strikes = strike_offsets.map do |strike_offset|
45
- parse_from(offset + strike_offset) do
46
- ppem, resolution = read(4, "n2")
47
- data_offsets = (file.maximum_profile.num_glyphs + 1).times.map { read(4, "N").first }
48
- { ppem: ppem, resolution: resolution, offset: strike_offset, glyph_data_offset: data_offsets }
46
+ @strikes = strike_offsets.map do |strike_offset|
47
+ parse_from(offset + strike_offset) do
48
+ ppem, resolution = read(4, 'n2')
49
+ data_offsets = Array.new(file.maximum_profile.num_glyphs + 1) do
50
+ read(4, 'N').first
49
51
  end
52
+ {
53
+ ppem: ppem,
54
+ resolution: resolution,
55
+ offset: strike_offset,
56
+ glyph_data_offset: data_offsets
57
+ }
50
58
  end
51
59
  end
60
+ end
52
61
  end
53
62
  end
54
63
  end
metadata CHANGED
@@ -1,7 +1,7 @@
1
1
  --- !ruby/object:Gem::Specification
2
2
  name: ttfunk
3
3
  version: !ruby/object:Gem::Version
4
- version: 1.4.0
4
+ version: 1.5.0
5
5
  platform: ruby
6
6
  authors:
7
7
  - Gregory Brown
@@ -11,65 +11,87 @@ authors:
11
11
  - James Healy
12
12
  autorequire:
13
13
  bindir: bin
14
- cert_chain: []
15
- date: 2014-09-21 00:00:00.000000000 Z
14
+ cert_chain:
15
+ - |
16
+ -----BEGIN CERTIFICATE-----
17
+ MIIDcDCCAligAwIBAgIBATANBgkqhkiG9w0BAQUFADA/MQ0wCwYDVQQDDARhbGV4
18
+ MRkwFwYKCZImiZPyLGQBGRYJcG9pbnRsZXNzMRMwEQYKCZImiZPyLGQBGRYDb25l
19
+ MB4XDTE3MDEwNDExNDAzM1oXDTE4MDEwNDExNDAzM1owPzENMAsGA1UEAwwEYWxl
20
+ eDEZMBcGCgmSJomT8ixkARkWCXBvaW50bGVzczETMBEGCgmSJomT8ixkARkWA29u
21
+ ZTCCASIwDQYJKoZIhvcNAQEBBQADggEPADCCAQoCggEBAM85Us8YQr55o/rMl+J+
22
+ ula89ODiqjdc0kk+ibzRLCpfaFUJWxEMrhFiApRCopFDMeGXHXjBkfBYsRMFVs0M
23
+ Zfe6rIKdNZQlQqHfJ2JlKFek0ehX81buGERi82wNwECNhOZu9c6G5gKjRPP/Q3Y6
24
+ K6f/TAggK0+/K1j1NjT+WSVaMBuyomM067ejwhiQkEA3+tT3oT/paEXCOfEtxOdX
25
+ 1F8VFd2MbmMK6CGgHbFLApfyDBtDx+ydplGZ3IMZg2nPqwYXTPJx+IuRO21ssDad
26
+ gBMIAvL3wIeezJk2xONvhYg0K5jbIQOPB6zD1/9E6Q0LrwSBDkz5oyOn4PRZxgZ/
27
+ OiMCAwEAAaN3MHUwCQYDVR0TBAIwADALBgNVHQ8EBAMCBLAwHQYDVR0OBBYEFE+A
28
+ jBJVt6ie5r83L/znvqjF1RuuMB0GA1UdEQQWMBSBEmFsZXhAcG9pbnRsZXNzLm9u
29
+ ZTAdBgNVHRIEFjAUgRJhbGV4QHBvaW50bGVzcy5vbmUwDQYJKoZIhvcNAQEFBQAD
30
+ ggEBAEmhsdVfgxHfXtOG6AP3qe7/PBjJPdUzNOkE/elj6TgpdvvJkOZ6QNyyqvpl
31
+ CsoDWL0EXPM5pIETaj5z9iBRK9fAi8YNS3zckhBJwhR78cb4+MiCPIBC+iiGx5bw
32
+ BFER2ASPeeY4uC0AHWHnURDLdxyZr+xp6pb/TitTAaCm18Kvkk1u60lOa4Jtdb+9
33
+ 2U1KICEBoX6UAzdT3N0nZ3VKq/vHVrvV2oePYCMIlNkghWp+VUE91OTBDMjnjjj8
34
+ wxx1aB3kGoI0T6JXywKpPnzUt/qji/qpzCNiVJ0RZxzDHyZuL8NEoA9ORZnAIGiW
35
+ 5u3JK+T0toNEYkMuV6W8NU+gVyo=
36
+ -----END CERTIFICATE-----
37
+ date: 2017-02-13 00:00:00.000000000 Z
16
38
  dependencies:
17
39
  - !ruby/object:Gem::Dependency
18
- name: rdoc
40
+ name: rake
19
41
  requirement: !ruby/object:Gem::Requirement
20
42
  requirements:
21
- - - ">="
43
+ - - "~>"
22
44
  - !ruby/object:Gem::Version
23
- version: '0'
45
+ version: '12'
24
46
  type: :development
25
47
  prerelease: false
26
48
  version_requirements: !ruby/object:Gem::Requirement
27
49
  requirements:
28
- - - ">="
50
+ - - "~>"
29
51
  - !ruby/object:Gem::Version
30
- version: '0'
52
+ version: '12'
31
53
  - !ruby/object:Gem::Dependency
32
54
  name: rspec
33
55
  requirement: !ruby/object:Gem::Requirement
34
56
  requirements:
35
- - - ">="
57
+ - - "~>"
36
58
  - !ruby/object:Gem::Version
37
- version: '0'
59
+ version: '3.5'
38
60
  type: :development
39
61
  prerelease: false
40
62
  version_requirements: !ruby/object:Gem::Requirement
41
63
  requirements:
42
- - - ">="
64
+ - - "~>"
43
65
  - !ruby/object:Gem::Version
44
- version: '0'
66
+ version: '3.5'
45
67
  - !ruby/object:Gem::Dependency
46
- name: rake
68
+ name: rubocop
47
69
  requirement: !ruby/object:Gem::Requirement
48
70
  requirements:
49
- - - ">="
71
+ - - "~>"
50
72
  - !ruby/object:Gem::Version
51
- version: '0'
73
+ version: '0.46'
52
74
  type: :development
53
75
  prerelease: false
54
76
  version_requirements: !ruby/object:Gem::Requirement
55
77
  requirements:
56
- - - ">="
78
+ - - "~>"
57
79
  - !ruby/object:Gem::Version
58
- version: '0'
80
+ version: '0.46'
59
81
  - !ruby/object:Gem::Dependency
60
- name: rubocop
82
+ name: yard
61
83
  requirement: !ruby/object:Gem::Requirement
62
84
  requirements:
63
- - - '='
85
+ - - "~>"
64
86
  - !ruby/object:Gem::Version
65
- version: 0.20.1
87
+ version: '0.9'
66
88
  type: :development
67
89
  prerelease: false
68
90
  version_requirements: !ruby/object:Gem::Requirement
69
91
  requirements:
70
- - - '='
92
+ - - "~>"
71
93
  - !ruby/object:Gem::Version
72
- version: 0.20.1
94
+ version: '0.9'
73
95
  description: Font Metrics Parser for the Prawn PDF generator
74
96
  email:
75
97
  - gregory.t.brown@gmail.com
@@ -81,15 +103,14 @@ executables: []
81
103
  extensions: []
82
104
  extra_rdoc_files: []
83
105
  files:
84
- - CHANGELOG
106
+ - CHANGELOG.md
85
107
  - COPYING
86
108
  - GPLv2
87
109
  - GPLv3
88
110
  - LICENSE
89
- - README.rdoc
90
- - data/fonts/DejaVuSans.ttf
91
- - examples/metrics.rb
111
+ - README.md
92
112
  - lib/ttfunk.rb
113
+ - lib/ttfunk/collection.rb
93
114
  - lib/ttfunk/directory.rb
94
115
  - lib/ttfunk/encoding/mac_roman.rb
95
116
  - lib/ttfunk/encoding/windows_1252.rb
@@ -129,8 +150,11 @@ files:
129
150
  - lib/ttfunk/table/post/format40.rb
130
151
  - lib/ttfunk/table/sbix.rb
131
152
  - lib/ttfunk/table/simple.rb
132
- homepage:
133
- licenses: []
153
+ homepage: https://prawnpdf.org
154
+ licenses:
155
+ - Nonstandard
156
+ - GPL-2.0
157
+ - GPL-3.0
134
158
  metadata: {}
135
159
  post_install_message:
136
160
  rdoc_options: []
@@ -138,9 +162,9 @@ require_paths:
138
162
  - lib
139
163
  required_ruby_version: !ruby/object:Gem::Requirement
140
164
  requirements:
141
- - - ">="
165
+ - - "~>"
142
166
  - !ruby/object:Gem::Version
143
- version: 1.9.3
167
+ version: '2.1'
144
168
  required_rubygems_version: !ruby/object:Gem::Requirement
145
169
  requirements:
146
170
  - - ">="
@@ -148,9 +172,8 @@ required_rubygems_version: !ruby/object:Gem::Requirement
148
172
  version: '0'
149
173
  requirements: []
150
174
  rubyforge_project:
151
- rubygems_version: 2.2.2
175
+ rubygems_version: 2.6.10
152
176
  signing_key:
153
177
  specification_version: 4
154
178
  summary: TrueType Font Metrics Parser
155
179
  test_files: []
156
- has_rdoc: