ttfunk 1.2.2 → 1.3.0

Sign up to get free protection for your applications and to get access to all the features.
checksums.yaml CHANGED
@@ -1,7 +1,7 @@
1
1
  ---
2
2
  SHA1:
3
- metadata.gz: a769f887e0602c169c60cd4dd6bc124abc7381e4
4
- data.tar.gz: 24f486228876268dc8d9f7ce7eb9150c39f70642
3
+ metadata.gz: 177f0f3efc15ab66c0ea79eb2487cf99c490ba6c
4
+ data.tar.gz: 7626c05ec3d7e39f747ad0d057ad9b7deef0953a
5
5
  SHA512:
6
- metadata.gz: 6d9690af986ed9ff9d4a0d395e84a7fd79b7ee112a03c88085d6670c8eb2d2f5c637193da617da0b2f9dca562da56701aebd0dd35cf0921a930da801096af058
7
- data.tar.gz: 43fc358d94b88e59668c8954f08e633de8dbd5f0e90497b2e606a6d21d9e768c67342ce227c52d7af1fb33253f3eb1446796ee891f640cbf5fb901fc63f7b719
6
+ metadata.gz: cc35b7fecf4001efabab23ddbac642f852506ed574c9d2a1ebcb54fd03f7b70819d3de3ca81b711116564eb8ea91dfa01f649ca6d244598d8d1048077bd534be
7
+ data.tar.gz: 92a5ad612492679643e34e5c231b9de256afb0a5f3c7cf1d178c0f6f3f5e68bc108a35cf773675ad02da000b233bc9b370b0a43763080135e02248801859cfa9
data/examples/metrics.rb CHANGED
@@ -1,6 +1,5 @@
1
1
  # encoding: utf-8
2
- $LOAD_PATH << "#{File.dirname(__FILE__)}/../lib"
3
- require "ttfunk"
2
+ require_relative "../lib/ttfunk"
4
3
 
5
4
  def character_lookup(file, character)
6
5
  puts "character : #{character}"
@@ -4,9 +4,8 @@ module TTFunk
4
4
  attr_reader :scaler_type
5
5
 
6
6
  def initialize(io)
7
- @scaler_type, table_count, search_range,
8
- entry_selector, range_shift = io.read(12).unpack("Nn*")
9
-
7
+ @scaler_type, table_count = io.read(12).unpack("Nn")
8
+
10
9
  @tables = {}
11
10
  table_count.times do
12
11
  tag, checksum, offset, length = io.read(16).unpack("a4N*")
@@ -12,7 +12,7 @@ module TTFunk
12
12
  def initialize(io)
13
13
  @io = io
14
14
 
15
- data_offset, map_offset, data_length, map_length = @io.read(16).unpack("N*")
15
+ data_offset, map_offset, map_length = @io.read(16).unpack("NNx4N")
16
16
 
17
17
  @map = {}
18
18
  @io.pos = map_offset + 24 # skip header copy, next map handle, file reference, and attrs
@@ -1,14 +1,14 @@
1
- require 'ttfunk/table/cmap'
2
- require 'ttfunk/table/glyf'
3
- require 'ttfunk/table/head'
4
- require 'ttfunk/table/hhea'
5
- require 'ttfunk/table/hmtx'
6
- require 'ttfunk/table/kern'
7
- require 'ttfunk/table/loca'
8
- require 'ttfunk/table/maxp'
9
- require 'ttfunk/table/name'
10
- require 'ttfunk/table/post'
11
- require 'ttfunk/table/simple'
1
+ require_relative '../table/cmap'
2
+ require_relative '../table/glyf'
3
+ require_relative '../table/head'
4
+ require_relative '../table/hhea'
5
+ require_relative '../table/hmtx'
6
+ require_relative '../table/kern'
7
+ require_relative '../table/loca'
8
+ require_relative '../table/maxp'
9
+ require_relative '../table/name'
10
+ require_relative '../table/post'
11
+ require_relative '../table/simple'
12
12
 
13
13
  module TTFunk
14
14
  module Subset
@@ -31,11 +31,11 @@ module TTFunk
31
31
  cmap_table = new_cmap_table(options)
32
32
  glyphs = collect_glyphs(original_glyph_ids)
33
33
 
34
- old2new_glyph = cmap_table[:charmap].inject({ 0 => 0 }) { |map, (code, ids)| map[ids[:old]] = ids[:new]; map }
34
+ old2new_glyph = cmap_table[:charmap].inject({ 0 => 0 }) { |map, (_, ids)| map[ids[:old]] = ids[:new]; map }
35
35
  next_glyph_id = cmap_table[:max_glyph_id]
36
36
 
37
37
  glyphs.keys.each do |old_id|
38
- unless old2new_glyph.key?(old_id)
38
+ unless old2new_glyph.key?(old_id)
39
39
  old2new_glyph[old_id] = next_glyph_id
40
40
  next_glyph_id += 1
41
41
  end
@@ -1,6 +1,7 @@
1
1
  require 'set'
2
- require 'ttfunk/subset/base'
3
- require 'ttfunk/encoding/mac_roman'
2
+
3
+ require_relative 'base'
4
+ require_relative '../encoding/mac_roman'
4
5
 
5
6
  module TTFunk
6
7
  module Subset
@@ -1,5 +1,5 @@
1
1
  require 'set'
2
- require 'ttfunk/subset/base'
2
+ require_relative 'base'
3
3
 
4
4
  module TTFunk
5
5
  module Subset
@@ -1,5 +1,5 @@
1
1
  require 'set'
2
- require 'ttfunk/subset/base'
2
+ require_relative 'base'
3
3
 
4
4
  module TTFunk
5
5
  module Subset
@@ -1,6 +1,7 @@
1
1
  require 'set'
2
- require 'ttfunk/subset/base'
3
- require 'ttfunk/encoding/windows_1252'
2
+
3
+ require_relative 'base'
4
+ require_relative '../encoding/windows_1252'
4
5
 
5
6
  module TTFunk
6
7
  module Subset
data/lib/ttfunk/subset.rb CHANGED
@@ -1,7 +1,7 @@
1
- require 'ttfunk/subset/unicode'
2
- require 'ttfunk/subset/unicode_8bit'
3
- require 'ttfunk/subset/mac_roman'
4
- require 'ttfunk/subset/windows_1252'
1
+ require_relative 'subset/unicode'
2
+ require_relative 'subset/unicode_8bit'
3
+ require_relative 'subset/mac_roman'
4
+ require_relative 'subset/windows_1252'
5
5
 
6
6
  module TTFunk
7
7
  module Subset
@@ -1,4 +1,4 @@
1
- require 'ttfunk/subset'
1
+ require_relative 'subset'
2
2
 
3
3
  module TTFunk
4
4
  class SubsetCollection
@@ -1,5 +1,5 @@
1
- require 'ttfunk/encoding/mac_roman'
2
- require 'ttfunk/encoding/windows_1252'
1
+ require_relative '../../encoding/mac_roman'
2
+ require_relative '../../encoding/windows_1252'
3
3
 
4
4
  module TTFunk
5
5
  class Table
@@ -16,7 +16,7 @@ module TTFunk
16
16
  # ids. The returned hash also includes a :subtable key, which contains
17
17
  # the encoded subtable for the given charmap.
18
18
  def self.encode(charmap)
19
- next_id = 0
19
+ next_id = 0
20
20
  glyph_indexes = Array.new(256, 0)
21
21
  glyph_map = { 0 => 0 }
22
22
 
@@ -44,7 +44,7 @@ module TTFunk
44
44
  private
45
45
 
46
46
  def parse_cmap!
47
- length, @language = read(4, "nn")
47
+ @language = read(4, "x2n")
48
48
  @code_map = read(256, "C*")
49
49
  end
50
50
  end
@@ -7,7 +7,7 @@ module TTFunk
7
7
  attr_reader :code_map
8
8
 
9
9
  def self.encode(charmap)
10
- next_id = 0
10
+ next_id = 0
11
11
  glyph_map = { 0 => 0 }
12
12
 
13
13
  sorted_chars = charmap.keys.sort
@@ -37,7 +37,7 @@ module TTFunk
37
37
 
38
38
  private
39
39
  def parse_cmap!
40
- length, @language, firstcode, entrycount = read(8, 'nnnn')
40
+ @language, firstcode, entrycount = read(8, 'x2nnn')
41
41
  @code_map = {}
42
42
  (firstcode...(firstcode+entrycount)).each do |code|
43
43
  @code_map[code] = read(2, 'n').first & 0xFFFF
@@ -7,7 +7,7 @@ module TTFunk
7
7
  attr_reader :code_map
8
8
 
9
9
  def self.encode(charmap)
10
- next_id = 0
10
+ next_id = 0
11
11
  glyph_map = { 0 => 0 }
12
12
 
13
13
  sorted_chars = charmap.keys.sort
@@ -37,7 +37,7 @@ module TTFunk
37
37
 
38
38
  private
39
39
  def parse_cmap!
40
- fractional_version, length, @language, firstcode, entrycount = read(18, 'nNNNN')
40
+ fractional_version, @language, firstcode, entrycount = read(18, 'nx4NNN')
41
41
  raise NotImplementedError, "cmap version 10.#{fractional_version} is not supported" if fractional_version != 0
42
42
  @code_map = {}
43
43
  (firstcode...(firstcode+entrycount)).each do |code|
@@ -7,7 +7,7 @@ module TTFunk
7
7
  attr_reader :code_map
8
8
 
9
9
  def self.encode(charmap)
10
- next_id = 0
10
+ next_id = 0
11
11
  glyph_map = { 0 => 0 }
12
12
  range_firstglyphs, range_firstcodes, range_lengths = [], [], []
13
13
  last_glyph = last_code = -999
@@ -18,7 +18,7 @@ module TTFunk
18
18
 
19
19
  if code > last_code+1 || glyph_map[charmap[code]] > last_glyph+1
20
20
  range_firstcodes << code
21
- range_firstglyphs << glyph_map[charmap[code]]
21
+ range_firstglyphs << glyph_map[charmap[code]]
22
22
  range_lengths << 1
23
23
  else
24
24
  range_lengths.push(range_lengths.pop) + 1
@@ -48,7 +48,7 @@ module TTFunk
48
48
 
49
49
  private
50
50
  def parse_cmap!
51
- fractional_version, length, @language, groupcount = read(14, 'nNNN')
51
+ fractional_version, @language, groupcount = read(14, 'nx4NN')
52
52
  raise NotImplementedError, "cmap version 12.#{fractional_version} is not supported" if fractional_version != 0
53
53
  @code_map = {}
54
54
  (1..groupcount).each do
@@ -1,4 +1,4 @@
1
- require 'ttfunk/reader'
1
+ require_relative '../../reader'
2
2
 
3
3
  module TTFunk
4
4
  class Table
@@ -81,8 +81,8 @@ module TTFunk
81
81
  end
82
82
  end
83
83
 
84
- require 'ttfunk/table/cmap/format00'
85
- require 'ttfunk/table/cmap/format04'
86
- require 'ttfunk/table/cmap/format06'
87
- require 'ttfunk/table/cmap/format10'
88
- require 'ttfunk/table/cmap/format12'
84
+ require_relative 'format00'
85
+ require_relative 'format04'
86
+ require_relative 'format06'
87
+ require_relative 'format10'
88
+ require_relative 'format12'
@@ -34,4 +34,4 @@ module TTFunk
34
34
  end
35
35
  end
36
36
 
37
- require 'ttfunk/table/cmap/subtable'
37
+ require_relative 'cmap/subtable'
@@ -1,4 +1,4 @@
1
- require 'ttfunk/reader'
1
+ require_relative '../../reader'
2
2
 
3
3
  module TTFunk
4
4
  class Table
@@ -1,4 +1,4 @@
1
- require 'ttfunk/reader'
1
+ require_relative '../../reader'
2
2
 
3
3
  module TTFunk
4
4
  class Table
@@ -1,4 +1,4 @@
1
- require 'ttfunk/table'
1
+ require_relative '../table'
2
2
 
3
3
  module TTFunk
4
4
  class Table
@@ -60,5 +60,5 @@ module TTFunk
60
60
  end
61
61
  end
62
62
 
63
- require 'ttfunk/table/glyf/compound'
64
- require 'ttfunk/table/glyf/simple'
63
+ require_relative 'glyf/compound'
64
+ require_relative 'glyf/simple'
@@ -1,4 +1,4 @@
1
- require 'ttfunk/table'
1
+ require_relative '../table'
2
2
 
3
3
  module TTFunk
4
4
  class Table
@@ -1,4 +1,4 @@
1
- require 'ttfunk/table'
1
+ require_relative '../table'
2
2
 
3
3
  module TTFunk
4
4
  class Table
@@ -1,4 +1,4 @@
1
- require 'ttfunk/table'
1
+ require_relative '../table'
2
2
 
3
3
  module TTFunk
4
4
  class Table
@@ -1,4 +1,4 @@
1
- require 'ttfunk/reader'
1
+ require_relative '../../reader'
2
2
 
3
3
  module TTFunk
4
4
  class Table
@@ -12,8 +12,7 @@ module TTFunk
12
12
  def initialize(attributes={})
13
13
  @attributes = attributes
14
14
 
15
- num_pairs, search_range, entry_selector, range_shift, *pairs =
16
- attributes.delete(:data).unpack("n*")
15
+ num_pairs, *pairs = attributes.delete(:data).unpack("nx6n*")
17
16
 
18
17
  @pairs = {}
19
18
  num_pairs.times do |i|
@@ -1,4 +1,4 @@
1
- require 'ttfunk/table'
1
+ require_relative '../table'
2
2
 
3
3
  module TTFunk
4
4
  class Table
@@ -76,4 +76,4 @@ module TTFunk
76
76
  end
77
77
  end
78
78
 
79
- require 'ttfunk/table/kern/format0'
79
+ require_relative 'kern/format0'
@@ -1,4 +1,4 @@
1
- require 'ttfunk/table'
1
+ require_relative '../table'
2
2
 
3
3
  module TTFunk
4
4
  class Table
@@ -1,4 +1,4 @@
1
- require 'ttfunk/table'
1
+ require_relative '../table'
2
2
 
3
3
  module TTFunk
4
4
  class Table
@@ -1,4 +1,4 @@
1
- require 'ttfunk/table'
1
+ require_relative '../table'
2
2
 
3
3
  module TTFunk
4
4
  class Table
@@ -53,7 +53,7 @@ module TTFunk
53
53
 
54
54
  strings = names.strings.dup
55
55
  strings[6] = [postscript_name]
56
- str_count = strings.inject(0) { |sum, (id, list)| sum + list.length }
56
+ str_count = strings.inject(0) { |sum, (_, list)| sum + list.length }
57
57
 
58
58
  table = [0, str_count, 6 + 12 * str_count].pack("n*")
59
59
  strtable = ""
@@ -76,7 +76,7 @@ module TTFunk
76
76
  private
77
77
 
78
78
  def parse!
79
- format, count, string_offset = read(6, "n*")
79
+ count, string_offset = read(6, "x2n*")
80
80
 
81
81
  entries = []
82
82
  count.times do
@@ -1,4 +1,4 @@
1
- require 'ttfunk/table'
1
+ require_relative '../table'
2
2
 
3
3
  module TTFunk
4
4
  class Table
@@ -1,4 +1,4 @@
1
- require 'ttfunk/table/post/format10'
1
+ require_relative 'format10'
2
2
  require 'stringio'
3
3
 
4
4
  module TTFunk
@@ -1,6 +1,6 @@
1
- require 'ttfunk/table'
1
+ require_relative '../table'
2
2
 
3
- module TTFunk
3
+ module TTFunk
4
4
  class Table
5
5
  class Post < Table
6
6
  attr_reader :format
@@ -60,17 +60,21 @@ module TTFunk
60
60
 
61
61
  def parse!
62
62
  @format, @italic_angle, @underline_position, @underline_thickness,
63
- @fixed_pitch, @min_mem_type42, @max_mem_type42,
63
+ @fixed_pitch, @min_mem_type42, @max_mem_type42,
64
64
  @min_mem_type1, @max_mem_type1 = read(32, "N2n2N*")
65
65
 
66
- end_of_table = offset + length
67
-
68
66
  @subtable = case @format
69
- when 0x00010000 then extend(Post::Format10)
70
- when 0x00020000 then extend(Post::Format20)
71
- when 0x00025000 then extend(Post::Format25)
72
- when 0x00030000 then extend(Post::Format30)
73
- when 0x00040000 then extend(Post::Format40)
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)
74
78
  end
75
79
 
76
80
  parse_format!
@@ -80,12 +84,11 @@ module TTFunk
80
84
  warn "postscript table format 0x%08X is not supported" % @format
81
85
  end
82
86
  end
83
-
87
+
84
88
  end
85
89
  end
86
90
 
87
- require 'ttfunk/table/post/format10'
88
- require 'ttfunk/table/post/format20'
89
- require 'ttfunk/table/post/format25'
90
- require 'ttfunk/table/post/format30'
91
- require 'ttfunk/table/post/format40'
91
+ require_relative 'post/format10'
92
+ require_relative 'post/format20'
93
+ require_relative 'post/format30'
94
+ require_relative 'post/format40'
@@ -1,4 +1,4 @@
1
- require 'ttfunk/table'
1
+ require_relative '../table'
2
2
 
3
3
  module TTFunk
4
4
  class Table
data/lib/ttfunk/table.rb CHANGED
@@ -1,4 +1,4 @@
1
- require 'ttfunk/reader'
1
+ require_relative 'reader'
2
2
 
3
3
  module TTFunk
4
4
  class Table
data/lib/ttfunk.rb CHANGED
@@ -1,7 +1,8 @@
1
1
  require 'stringio'
2
2
  require 'pathname'
3
- require 'ttfunk/directory'
4
- require 'ttfunk/resource_file'
3
+
4
+ require_relative 'ttfunk/directory'
5
+ require_relative 'ttfunk/resource_file'
5
6
 
6
7
  module TTFunk
7
8
  class File
@@ -108,15 +109,14 @@ module TTFunk
108
109
  end
109
110
  end
110
111
 
111
- require "ttfunk/table/cmap"
112
- require "ttfunk/table/glyf"
113
- require "ttfunk/table/head"
114
- require "ttfunk/table/hhea"
115
- require "ttfunk/table/hmtx"
116
- require "ttfunk/table/kern"
117
- require "ttfunk/table/loca"
118
- require "ttfunk/table/maxp"
119
- require "ttfunk/table/name"
120
- require "ttfunk/table/os2"
121
- require "ttfunk/table/post"
122
-
112
+ require_relative "ttfunk/table/cmap"
113
+ require_relative "ttfunk/table/glyf"
114
+ require_relative "ttfunk/table/head"
115
+ require_relative "ttfunk/table/hhea"
116
+ require_relative "ttfunk/table/hmtx"
117
+ require_relative "ttfunk/table/kern"
118
+ require_relative "ttfunk/table/loca"
119
+ require_relative "ttfunk/table/maxp"
120
+ require_relative "ttfunk/table/name"
121
+ require_relative "ttfunk/table/os2"
122
+ require_relative "ttfunk/table/post"
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.2.2
4
+ version: 1.3.0
5
5
  platform: ruby
6
6
  authors:
7
7
  - Gregory Brown
@@ -12,7 +12,7 @@ authors:
12
12
  autorequire:
13
13
  bindir: bin
14
14
  cert_chain: []
15
- date: 2014-08-29 00:00:00.000000000 Z
15
+ date: 2014-09-10 00:00:00.000000000 Z
16
16
  dependencies:
17
17
  - !ruby/object:Gem::Dependency
18
18
  name: rdoc
@@ -125,7 +125,6 @@ files:
125
125
  - lib/ttfunk/table/post.rb
126
126
  - lib/ttfunk/table/post/format10.rb
127
127
  - lib/ttfunk/table/post/format20.rb
128
- - lib/ttfunk/table/post/format25.rb
129
128
  - lib/ttfunk/table/post/format30.rb
130
129
  - lib/ttfunk/table/post/format40.rb
131
130
  - lib/ttfunk/table/simple.rb
@@ -1,23 +0,0 @@
1
- require 'ttfunk/table/post/format10'
2
- require 'stringio'
3
-
4
- module TTFunk
5
- class Table
6
- class Post
7
- module Format25
8
- include Format10
9
-
10
- def glyph_for(code)
11
- POSTSCRIPT_GLYPHS[code + @offsets[code]] || ".notdef"
12
- end
13
-
14
- private
15
-
16
- def parse_format!
17
- number_of_glyphs = read(2, 'n').first
18
- @offsets = read(@number_of_glyphs, "c*")
19
- end
20
- end
21
- end
22
- end
23
- end