ttfunk 1.0.3 → 1.1.0

Sign up to get free protection for your applications and to get access to all the features.
@@ -0,0 +1,7 @@
1
+ ---
2
+ SHA1:
3
+ metadata.gz: ed69e97b1e7115a2f520ccce3e11cc4c45049e0c
4
+ data.tar.gz: 53b854789acf1d696429c11f205a3563d9181ee4
5
+ SHA512:
6
+ metadata.gz: a629cedf256c3cbb06853f19c17f5aceb8fc6c400cf50e39535905f02a817297f89a17e9f41d8f90ae4f2939eb953031231ab077d62d6e578fd7dc204e16bdaa
7
+ data.tar.gz: 5a75eb4d88249046dfd77cf45d5a64794a0da8d6a60b0c43f2809d667e0673b6ea6e20b3bb649590b4b38fe41fe9a01884e770407a724a2255ff72e0cc762eec
data/GPLv2 CHANGED
@@ -2,7 +2,7 @@
2
2
  Version 2, June 1991
3
3
 
4
4
  Copyright (C) 1989, 1991 Free Software Foundation, Inc.
5
- 59 Temple Place, Suite 330, Boston, MA 02111-1307 USA
5
+ 51 Franklin Street, Fifth Floor, Boston, MA 02110-1301, USA
6
6
  Everyone is permitted to copy and distribute verbatim copies
7
7
  of this license document, but changing it is not allowed.
8
8
 
@@ -21,6 +21,7 @@ For more detailed examples, explore the examples directory.
21
21
 
22
22
  = Maintainers
23
23
 
24
+ - Gregory Brown
24
25
  - Brad Ediger
25
26
  - Daniel Nelson
26
27
  - Jonathan Greenberg
@@ -55,7 +55,11 @@ module TTFunk
55
55
  char = @subsets[current_subset].from_unicode(char)
56
56
 
57
57
  if parts.empty? || parts.last[0] != current_subset
58
- parts << [current_subset, char.chr]
58
+ encoded_char = char.chr
59
+ if encoded_char.respond_to?(:force_encoding)
60
+ encoded_char.force_encoding("ASCII-8BIT")
61
+ end
62
+ parts << [current_subset, encoded_char]
59
63
  else
60
64
  parts.last[1] << char
61
65
  end
@@ -13,7 +13,9 @@ module TTFunk
13
13
  end
14
14
 
15
15
  def unicode
16
- @unicode ||= @tables.select { |table| table.unicode? }
16
+ # Because most callers just call .first on the result, put tables with highest-number format first.
17
+ # (Tables with higher format numbers tend to be more complete, especially in higher/astral Unicode ranges.)
18
+ @unicode ||= @tables.select { |table| table.unicode? }.sort{|a,b| b.format <=> a.format }
17
19
  end
18
20
 
19
21
  private
@@ -0,0 +1,51 @@
1
+ module TTFunk
2
+ class Table
3
+ class Cmap
4
+
5
+ module Format06
6
+ attr_reader :language
7
+ attr_reader :code_map
8
+
9
+ def self.encode(charmap)
10
+ next_id = 0
11
+ glyph_map = { 0 => 0 }
12
+
13
+ sorted_chars = charmap.keys.sort
14
+ low_char, high_char = sorted_chars.first, sorted_chars.last
15
+ entry_count = (1+high_char-low_char)
16
+ glyph_indexes = Array.new(entry_count, 0)
17
+
18
+ new_map = charmap.keys.sort.inject({}) do |map, code|
19
+ glyph_map[charmap[code]] ||= next_id += 1
20
+ map[code] = { :old => charmap[code], :new => glyph_map[charmap[code]] }
21
+ glyph_indexes[code - low_char] = glyph_map[charmap[code]]
22
+ map
23
+ end
24
+
25
+ subtable = [6, 10+entry_count*2, 0, low_char, entry_count, *glyph_indexes].pack('n*')
26
+
27
+ { :charmap => new_map, :subtable => subtable, :max_glyph_id => next_id+1 }
28
+ end
29
+
30
+ def [](code)
31
+ @code_map[code] || 0
32
+ end
33
+
34
+ def supported?
35
+ true
36
+ end
37
+
38
+ private
39
+ def parse_cmap!
40
+ length, @language, firstcode, entrycount = read(8, 'nnnn')
41
+ @code_map = {}
42
+ (firstcode...(firstcode+entrycount)).each do |code|
43
+ @code_map[code] = read(2, 'n').first & 0xFFFF
44
+ end
45
+ end
46
+
47
+ end
48
+
49
+ end
50
+ end
51
+ end
@@ -0,0 +1,52 @@
1
+ module TTFunk
2
+ class Table
3
+ class Cmap
4
+
5
+ module Format10
6
+ attr_reader :language
7
+ attr_reader :code_map
8
+
9
+ def self.encode(charmap)
10
+ next_id = 0
11
+ glyph_map = { 0 => 0 }
12
+
13
+ sorted_chars = charmap.keys.sort
14
+ low_char, high_char = sorted_chars.first, sorted_chars.last
15
+ entry_count = (1+high_char-low_char)
16
+ glyph_indexes = Array.new(entry_count, 0)
17
+
18
+ new_map = charmap.keys.sort.inject({}) do |map, code|
19
+ glyph_map[charmap[code]] ||= next_id += 1
20
+ map[code] = { :old => charmap[code], :new => glyph_map[charmap[code]] }
21
+ glyph_indexes[code - low_char] = glyph_map[charmap[code]]
22
+ map
23
+ end
24
+
25
+ subtable = [10, 0, 20+entry_count*4, 0, low_char, entry_count, *glyph_indexes].pack('nnN*')
26
+
27
+ { :charmap => new_map, :subtable => subtable, :max_glyph_id => next_id+1 }
28
+ end
29
+
30
+ def [](code)
31
+ @code_map[code] || 0
32
+ end
33
+
34
+ def supported?
35
+ true
36
+ end
37
+
38
+ private
39
+ def parse_cmap!
40
+ fractional_version, length, @language, firstcode, entrycount = read(18, 'nNNNN')
41
+ raise NotImplementedError, "cmap version 10.#{fractional_version} is not supported" if fractional_version != 0
42
+ @code_map = {}
43
+ (firstcode...(firstcode+entrycount)).each do |code|
44
+ @code_map[code] = read(2, 'n').first & 0xFFFF
45
+ end
46
+ end
47
+
48
+ end
49
+
50
+ end
51
+ end
52
+ end
@@ -0,0 +1,66 @@
1
+ module TTFunk
2
+ class Table
3
+ class Cmap
4
+
5
+ module Format12
6
+ attr_reader :language
7
+ attr_reader :code_map
8
+
9
+ def self.encode(charmap)
10
+ next_id = 0
11
+ glyph_map = { 0 => 0 }
12
+ range_firstglyphs, range_firstcodes, range_lengths = [], [], []
13
+ last_glyph = last_code = -999
14
+
15
+ new_map = charmap.keys.sort.inject({}) do |map, code|
16
+ glyph_map[charmap[code]] ||= next_id += 1
17
+ map[code] = { :old => charmap[code], :new => glyph_map[charmap[code]] }
18
+
19
+ if code > last_code+1 || glyph_map[charmap[code]] > last_glyph+1
20
+ range_firstcodes << code
21
+ range_firstglyphs << glyph_map[charmap[code]]
22
+ range_lengths << 1
23
+ else
24
+ range_lengths.push(range_lengths.pop) + 1
25
+ end
26
+ last_code = code
27
+ last_glyph = glyph_map[charmap[code]]
28
+
29
+ map
30
+ end
31
+
32
+ subtable = [12, 0, 16+12*range_lengths.size, 0, range_lengths.size].pack('nnNNN')
33
+ range_lengths.each_with_index do |length, i|
34
+ firstglyph, firstcode = range_firstglyphs[i], range_firstcodes[i]
35
+ subtable << [firstcode, firstcode+length-1, firstglyph].pack('NNN')
36
+ end
37
+
38
+ { :charmap => new_map, :subtable => subtable, :max_glyph_id => next_id+1 }
39
+ end
40
+
41
+ def [](code)
42
+ @code_map[code] || 0
43
+ end
44
+
45
+ def supported?
46
+ true
47
+ end
48
+
49
+ private
50
+ def parse_cmap!
51
+ fractional_version, length, @language, groupcount = read(14, 'nNNN')
52
+ raise NotImplementedError, "cmap version 12.#{fractional_version} is not supported" if fractional_version != 0
53
+ @code_map = {}
54
+ (1..groupcount).each do
55
+ startchar, endchar, startglyph = read(12, 'NNN')
56
+ (0..(endchar-startchar)).each do |offset|
57
+ @code_map[startchar+offset] = startglyph+offset
58
+ end
59
+ end
60
+ end
61
+
62
+ end
63
+
64
+ end
65
+ end
66
+ end
@@ -13,7 +13,8 @@ module TTFunk
13
13
  ENCODING_MAPPINGS = {
14
14
  :mac_roman => { :platform_id => 1, :encoding_id => 0 },
15
15
  # use microsoft unicode, instead of generic unicode, for optimal windows support
16
- :unicode => { :platform_id => 3, :encoding_id => 1 }
16
+ :unicode => { :platform_id => 3, :encoding_id => 1 },
17
+ :unicode_ucs4 => { :platform_id => 3, :encoding_id => 10 }
17
18
  }
18
19
 
19
20
  def self.encode(charmap, encoding)
@@ -22,6 +23,8 @@ module TTFunk
22
23
  result = Format00.encode(charmap)
23
24
  when :unicode
24
25
  result = Format04.encode(charmap)
26
+ when :unicode_ucs4
27
+ result = Format12.encode(charmap)
25
28
  else
26
29
  raise NotImplementedError, "encoding #{encoding.inspect} is not supported"
27
30
  end
@@ -44,8 +47,11 @@ module TTFunk
44
47
  @format = read(2, "n").first
45
48
 
46
49
  case @format
47
- when 0 then extend(TTFunk::Table::Cmap::Format00)
48
- when 4 then extend(TTFunk::Table::Cmap::Format04)
50
+ when 0 then extend(TTFunk::Table::Cmap::Format00)
51
+ when 4 then extend(TTFunk::Table::Cmap::Format04)
52
+ when 6 then extend(TTFunk::Table::Cmap::Format06)
53
+ when 10 then extend(TTFunk::Table::Cmap::Format10)
54
+ when 12 then extend(TTFunk::Table::Cmap::Format12)
49
55
  end
50
56
 
51
57
  parse_cmap!
@@ -53,8 +59,8 @@ module TTFunk
53
59
  end
54
60
 
55
61
  def unicode?
56
- platform_id == 3 && encoding_id == 1 && format == 4 ||
57
- platform_id == 0 && format == 4
62
+ platform_id == 3 && (encoding_id == 1 || encoding_id == 10) && format != 0 ||
63
+ platform_id == 0 && format != 0
58
64
  end
59
65
 
60
66
  def supported?
@@ -77,3 +83,6 @@ end
77
83
 
78
84
  require 'ttfunk/table/cmap/format00'
79
85
  require 'ttfunk/table/cmap/format04'
86
+ require 'ttfunk/table/cmap/format06'
87
+ require 'ttfunk/table/cmap/format10'
88
+ require 'ttfunk/table/cmap/format12'
metadata CHANGED
@@ -1,8 +1,7 @@
1
1
  --- !ruby/object:Gem::Specification
2
2
  name: ttfunk
3
3
  version: !ruby/object:Gem::Version
4
- version: 1.0.3
5
- prerelease:
4
+ version: 1.1.0
6
5
  platform: ruby
7
6
  authors:
8
7
  - Gregory Brown
@@ -13,9 +12,50 @@ authors:
13
12
  autorequire:
14
13
  bindir: bin
15
14
  cert_chain: []
16
- date: 2011-10-11 00:00:00.000000000 -05:00
17
- default_executable:
18
- dependencies: []
15
+ date: 2014-01-21 00:00:00.000000000 Z
16
+ dependencies:
17
+ - !ruby/object:Gem::Dependency
18
+ name: rdoc
19
+ requirement: !ruby/object:Gem::Requirement
20
+ requirements:
21
+ - - '>='
22
+ - !ruby/object:Gem::Version
23
+ version: '0'
24
+ type: :development
25
+ prerelease: false
26
+ version_requirements: !ruby/object:Gem::Requirement
27
+ requirements:
28
+ - - '>='
29
+ - !ruby/object:Gem::Version
30
+ version: '0'
31
+ - !ruby/object:Gem::Dependency
32
+ name: rspec
33
+ requirement: !ruby/object:Gem::Requirement
34
+ requirements:
35
+ - - '>='
36
+ - !ruby/object:Gem::Version
37
+ version: '0'
38
+ type: :development
39
+ prerelease: false
40
+ version_requirements: !ruby/object:Gem::Requirement
41
+ requirements:
42
+ - - '>='
43
+ - !ruby/object:Gem::Version
44
+ version: '0'
45
+ - !ruby/object:Gem::Dependency
46
+ name: rake
47
+ requirement: !ruby/object:Gem::Requirement
48
+ requirements:
49
+ - - '>='
50
+ - !ruby/object:Gem::Version
51
+ version: '0'
52
+ type: :development
53
+ prerelease: false
54
+ version_requirements: !ruby/object:Gem::Requirement
55
+ requirements:
56
+ - - '>='
57
+ - !ruby/object:Gem::Version
58
+ version: '0'
19
59
  description: Get Ya TrueType Funk On! (Font Metrics Parser for Prawn)
20
60
  email:
21
61
  - gregory.t.brown@gmail.com
@@ -27,42 +67,45 @@ executables: []
27
67
  extensions: []
28
68
  extra_rdoc_files: []
29
69
  files:
30
- - lib/ttfunk/encoding/windows_1252.rb
31
- - lib/ttfunk/encoding/mac_roman.rb
32
70
  - lib/ttfunk/directory.rb
33
- - lib/ttfunk/table/cmap/subtable.rb
71
+ - lib/ttfunk/encoding/mac_roman.rb
72
+ - lib/ttfunk/encoding/windows_1252.rb
73
+ - lib/ttfunk/reader.rb
74
+ - lib/ttfunk/resource_file.rb
75
+ - lib/ttfunk/subset/base.rb
76
+ - lib/ttfunk/subset/mac_roman.rb
77
+ - lib/ttfunk/subset/unicode.rb
78
+ - lib/ttfunk/subset/unicode_8bit.rb
79
+ - lib/ttfunk/subset/windows_1252.rb
80
+ - lib/ttfunk/subset.rb
81
+ - lib/ttfunk/subset_collection.rb
34
82
  - lib/ttfunk/table/cmap/format00.rb
35
83
  - lib/ttfunk/table/cmap/format04.rb
36
- - lib/ttfunk/table/post.rb
37
- - lib/ttfunk/table/loca.rb
38
- - lib/ttfunk/table/post/format40.rb
39
- - lib/ttfunk/table/post/format20.rb
40
- - lib/ttfunk/table/post/format10.rb
41
- - lib/ttfunk/table/post/format30.rb
42
- - lib/ttfunk/table/post/format25.rb
84
+ - lib/ttfunk/table/cmap/format06.rb
85
+ - lib/ttfunk/table/cmap/format10.rb
86
+ - lib/ttfunk/table/cmap/format12.rb
87
+ - lib/ttfunk/table/cmap/subtable.rb
43
88
  - lib/ttfunk/table/cmap.rb
44
- - lib/ttfunk/table/os2.rb
45
89
  - lib/ttfunk/table/glyf/compound.rb
46
90
  - lib/ttfunk/table/glyf/simple.rb
47
- - lib/ttfunk/table/hhea.rb
48
- - lib/ttfunk/table/maxp.rb
49
- - lib/ttfunk/table/kern.rb
50
91
  - lib/ttfunk/table/glyf.rb
51
92
  - lib/ttfunk/table/head.rb
52
- - lib/ttfunk/table/simple.rb
93
+ - lib/ttfunk/table/hhea.rb
53
94
  - lib/ttfunk/table/hmtx.rb
54
95
  - lib/ttfunk/table/kern/format0.rb
96
+ - lib/ttfunk/table/kern.rb
97
+ - lib/ttfunk/table/loca.rb
98
+ - lib/ttfunk/table/maxp.rb
55
99
  - lib/ttfunk/table/name.rb
56
- - lib/ttfunk/subset.rb
57
- - lib/ttfunk/subset_collection.rb
58
- - lib/ttfunk/reader.rb
59
- - lib/ttfunk/subset/base.rb
60
- - lib/ttfunk/subset/unicode.rb
61
- - lib/ttfunk/subset/windows_1252.rb
62
- - lib/ttfunk/subset/unicode_8bit.rb
63
- - lib/ttfunk/subset/mac_roman.rb
100
+ - lib/ttfunk/table/os2.rb
101
+ - lib/ttfunk/table/post/format10.rb
102
+ - lib/ttfunk/table/post/format20.rb
103
+ - lib/ttfunk/table/post/format25.rb
104
+ - lib/ttfunk/table/post/format30.rb
105
+ - lib/ttfunk/table/post/format40.rb
106
+ - lib/ttfunk/table/post.rb
107
+ - lib/ttfunk/table/simple.rb
64
108
  - lib/ttfunk/table.rb
65
- - lib/ttfunk/resource_file.rb
66
109
  - lib/ttfunk.rb
67
110
  - data/fonts/comicsans.ttf
68
111
  - data/fonts/DejaVuSans.ttf
@@ -73,29 +116,28 @@ files:
73
116
  - LICENSE
74
117
  - GPLv2
75
118
  - GPLv3
76
- has_rdoc: true
77
119
  homepage:
78
120
  licenses: []
121
+ metadata: {}
79
122
  post_install_message:
80
123
  rdoc_options: []
81
124
  require_paths:
82
125
  - lib
83
126
  required_ruby_version: !ruby/object:Gem::Requirement
84
- none: false
85
127
  requirements:
86
- - - ! '>='
128
+ - - '>='
87
129
  - !ruby/object:Gem::Version
88
- version: 1.8.7
130
+ version: 1.9.3
89
131
  required_rubygems_version: !ruby/object:Gem::Requirement
90
- none: false
91
132
  requirements:
92
- - - ! '>='
133
+ - - '>='
93
134
  - !ruby/object:Gem::Version
94
- version: 1.3.6
135
+ version: '0'
95
136
  requirements: []
96
137
  rubyforge_project:
97
- rubygems_version: 1.6.2
138
+ rubygems_version: 2.0.14
98
139
  signing_key:
99
- specification_version: 3
140
+ specification_version: 4
100
141
  summary: TrueType Font Metrics Parser
101
142
  test_files: []
143
+ has_rdoc: