glyph_imager 0.0.14 → 0.1.0
Sign up to get free protection for your applications and to get access to all the features.
- data/VERSION +1 -1
- data/glyph_imager.gemspec +45 -36
- data/lib/glyph_imager.rb +19 -27
- data/test/fonts/Musica.ttf +0 -0
- data/test/test_glyph_imager.rb +9 -3
- data/vendor/ttfunk/.gitignore +1 -0
- data/vendor/ttfunk/data/fonts/DejaVuSans.ttf +0 -0
- data/vendor/ttfunk/data/fonts/comicsans.ttf +0 -0
- data/vendor/ttfunk/example.rb +45 -0
- data/vendor/ttfunk/lib/ttfunk.rb +102 -0
- data/vendor/ttfunk/lib/ttfunk/directory.rb +17 -0
- data/vendor/ttfunk/lib/ttfunk/encoding/mac_roman.rb +88 -0
- data/vendor/ttfunk/lib/ttfunk/encoding/windows_1252.rb +69 -0
- data/vendor/ttfunk/lib/ttfunk/reader.rb +44 -0
- data/vendor/ttfunk/lib/ttfunk/resource_file.rb +78 -0
- data/vendor/ttfunk/lib/ttfunk/subset.rb +18 -0
- data/vendor/ttfunk/lib/ttfunk/subset/base.rb +141 -0
- data/vendor/ttfunk/lib/ttfunk/subset/mac_roman.rb +50 -0
- data/vendor/ttfunk/lib/ttfunk/subset/unicode.rb +48 -0
- data/vendor/ttfunk/lib/ttfunk/subset/unicode_8bit.rb +63 -0
- data/vendor/ttfunk/lib/ttfunk/subset/windows_1252.rb +55 -0
- data/vendor/ttfunk/lib/ttfunk/subset_collection.rb +72 -0
- data/vendor/ttfunk/lib/ttfunk/table.rb +46 -0
- data/vendor/ttfunk/lib/ttfunk/table/cmap.rb +34 -0
- data/vendor/ttfunk/lib/ttfunk/table/cmap/format00.rb +54 -0
- data/vendor/ttfunk/lib/ttfunk/table/cmap/format04.rb +126 -0
- data/vendor/ttfunk/lib/ttfunk/table/cmap/format12.rb +37 -0
- data/vendor/ttfunk/lib/ttfunk/table/cmap/subtable.rb +82 -0
- data/vendor/ttfunk/lib/ttfunk/table/glyf.rb +64 -0
- data/vendor/ttfunk/lib/ttfunk/table/glyf/compound.rb +81 -0
- data/vendor/ttfunk/lib/ttfunk/table/glyf/simple.rb +37 -0
- data/vendor/ttfunk/lib/ttfunk/table/head.rb +44 -0
- data/vendor/ttfunk/lib/ttfunk/table/hhea.rb +41 -0
- data/vendor/ttfunk/lib/ttfunk/table/hmtx.rb +47 -0
- data/vendor/ttfunk/lib/ttfunk/table/kern.rb +79 -0
- data/vendor/ttfunk/lib/ttfunk/table/kern/format0.rb +62 -0
- data/vendor/ttfunk/lib/ttfunk/table/loca.rb +43 -0
- data/vendor/ttfunk/lib/ttfunk/table/maxp.rb +40 -0
- data/vendor/ttfunk/lib/ttfunk/table/name.rb +125 -0
- data/vendor/ttfunk/lib/ttfunk/table/os2.rb +78 -0
- data/vendor/ttfunk/lib/ttfunk/table/post.rb +91 -0
- data/vendor/ttfunk/lib/ttfunk/table/post/format10.rb +43 -0
- data/vendor/ttfunk/lib/ttfunk/table/post/format20.rb +35 -0
- data/vendor/ttfunk/lib/ttfunk/table/post/format25.rb +23 -0
- data/vendor/ttfunk/lib/ttfunk/table/post/format30.rb +17 -0
- data/vendor/ttfunk/lib/ttfunk/table/post/format40.rb +17 -0
- data/vendor/ttfunk/lib/ttfunk/table/simple.rb +14 -0
- metadata +46 -37
- data/vendor/ttf-ruby-0.1/AUTHORS +0 -1
- data/vendor/ttf-ruby-0.1/COPYING +0 -340
- data/vendor/ttf-ruby-0.1/README +0 -49
- data/vendor/ttf-ruby-0.1/TODO +0 -23
- data/vendor/ttf-ruby-0.1/VERSION +0 -1
- data/vendor/ttf-ruby-0.1/lib/ttf.rb +0 -20
- data/vendor/ttf-ruby-0.1/lib/ttf/datatypes.rb +0 -181
- data/vendor/ttf-ruby-0.1/lib/ttf/encodings.rb +0 -140
- data/vendor/ttf-ruby-0.1/lib/ttf/exceptions.rb +0 -28
- data/vendor/ttf-ruby-0.1/lib/ttf/font_loader.rb +0 -290
- data/vendor/ttf-ruby-0.1/lib/ttf/fontchunk.rb +0 -77
- data/vendor/ttf-ruby-0.1/lib/ttf/table/cmap.rb +0 -408
- data/vendor/ttf-ruby-0.1/lib/ttf/table/cvt.rb +0 -49
- data/vendor/ttf-ruby-0.1/lib/ttf/table/fpgm.rb +0 -48
- data/vendor/ttf-ruby-0.1/lib/ttf/table/gasp.rb +0 -88
- data/vendor/ttf-ruby-0.1/lib/ttf/table/glyf.rb +0 -452
- data/vendor/ttf-ruby-0.1/lib/ttf/table/head.rb +0 -86
- data/vendor/ttf-ruby-0.1/lib/ttf/table/hhea.rb +0 -96
- data/vendor/ttf-ruby-0.1/lib/ttf/table/hmtx.rb +0 -98
- data/vendor/ttf-ruby-0.1/lib/ttf/table/kern.rb +0 -186
- data/vendor/ttf-ruby-0.1/lib/ttf/table/loca.rb +0 -75
- data/vendor/ttf-ruby-0.1/lib/ttf/table/maxp.rb +0 -81
- data/vendor/ttf-ruby-0.1/lib/ttf/table/name.rb +0 -226
- data/vendor/ttf-ruby-0.1/lib/ttf/table/os2.rb +0 -172
- data/vendor/ttf-ruby-0.1/lib/ttf/table/post.rb +0 -120
- data/vendor/ttf-ruby-0.1/lib/ttf/table/prep.rb +0 -27
- data/vendor/ttf-ruby-0.1/lib/ttf/table/vhea.rb +0 -45
- data/vendor/ttf-ruby-0.1/lib/ttf/table/vmtx.rb +0 -36
- data/vendor/ttf-ruby-0.1/setup.rb +0 -1558
- data/vendor/ttf-ruby-0.1/tools/README +0 -44
- data/vendor/ttf-ruby-0.1/tools/ttfcairoglyphviewer +0 -229
- data/vendor/ttf-ruby-0.1/tools/ttfdump +0 -396
- data/vendor/ttf-ruby-0.1/tools/ttfglyph2svg +0 -144
- data/vendor/ttf-ruby-0.1/tools/ttfsubset +0 -273
@@ -1,144 +0,0 @@
|
|
1
|
-
# ttfglyph2svg
|
2
|
-
# Copyright (C) 2006 Mathieu Blondel
|
3
|
-
#
|
4
|
-
# This program is free software; you can redistribute it and/or modify
|
5
|
-
# it under the terms of the GNU General Public License as published by
|
6
|
-
# the Free Software Foundation; either version 2 of the License, or
|
7
|
-
# (at your option) any later version.
|
8
|
-
#
|
9
|
-
# This program is distributed in the hope that it will be useful,
|
10
|
-
# but WITHOUT ANY WARRANTY; without even the implied warranty of
|
11
|
-
# MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
|
12
|
-
# GNU General Public License for more details.
|
13
|
-
#
|
14
|
-
# You should have received a copy of the GNU General Public License
|
15
|
-
# along with this program; if not, write to the Free Software
|
16
|
-
# Foundation, Inc., 51 Franklin St, Fifth Floor, Boston, MA 02110-1301 USA
|
17
|
-
|
18
|
-
$LOAD_PATH.unshift("../lib/")
|
19
|
-
|
20
|
-
require 'ttf'
|
21
|
-
|
22
|
-
def puts_svg_header
|
23
|
-
puts <<XML
|
24
|
-
<?xml version="1.0" standalone="no"?>
|
25
|
-
<!DOCTYPE svg PUBLIC "-//W3C//DTD SVG 1.1//EN"
|
26
|
-
"http://www.w3.org/Graphics/SVG/1.1/DTD/svg11.dtd">
|
27
|
-
|
28
|
-
<svg width="100%" height="100%" version="1.1"
|
29
|
-
xmlns="http://www.w3.org/2000/svg">
|
30
|
-
XML
|
31
|
-
end
|
32
|
-
|
33
|
-
def puts_svg_footer
|
34
|
-
puts "</svg>"
|
35
|
-
end
|
36
|
-
|
37
|
-
def puts_simple_glyph(glyph)
|
38
|
-
points = glyph.points
|
39
|
-
|
40
|
-
|
41
|
-
|
42
|
-
puts "<g>"
|
43
|
-
|
44
|
-
print "<path d=\""
|
45
|
-
|
46
|
-
start_new_contour = true
|
47
|
-
i = 0
|
48
|
-
max_y = 0
|
49
|
-
|
50
|
-
while i < points.length
|
51
|
-
|
52
|
-
max_y = points[i].abs_y if points[i].abs_y > max_y
|
53
|
-
|
54
|
-
if start_new_contour
|
55
|
-
# The -y is needed because the directions of the y-axis
|
56
|
-
# with SVG and TrueType are opposed.
|
57
|
-
print "M#{points[i].abs_x} #{-(points[i].abs_y)}"
|
58
|
-
first_point = points[i]
|
59
|
-
end
|
60
|
-
|
61
|
-
if points[i].end_of_contour?
|
62
|
-
print "Z"
|
63
|
-
start_new_contour = true
|
64
|
-
i += 1
|
65
|
-
else
|
66
|
-
if points[i].on_curve? and points[i + 1].on_curve?
|
67
|
-
print "L#{points[i + 1].abs_x} #{-(points[i + 1].abs_y)}"
|
68
|
-
i += 1
|
69
|
-
else
|
70
|
-
if points[i + 1].end_of_contour?
|
71
|
-
# Close the contour
|
72
|
-
print "Q#{points[i + 1].abs_x} " + \
|
73
|
-
"#{-(points[i + 1].abs_y)} " + \
|
74
|
-
"#{first_point.abs_x} #{-(first_point.abs_y)}"
|
75
|
-
i += 1
|
76
|
-
elsif points[i + 2].on_curve?
|
77
|
-
print "Q#{points[i + 1].abs_x} " + \
|
78
|
-
"#{-(points[i + 1].abs_y)} " + \
|
79
|
-
"#{points[i + 2].abs_x} #{-(points[i + 2].abs_y)}"
|
80
|
-
i += 2
|
81
|
-
else
|
82
|
-
# This is an implied on-curve point
|
83
|
-
impl_x = (points[i + 2].abs_x - points[i + 1].abs_x) / 2
|
84
|
-
impl_x += points[i + 1].abs_x
|
85
|
-
impl_y = (points[i + 2].abs_y - points[i + 1].abs_y) / 2
|
86
|
-
impl_y += points[i + 1].abs_y
|
87
|
-
|
88
|
-
print "Q#{points[i + 1].abs_x} " + \
|
89
|
-
"#{-(points[i + 1].abs_y)} " + \
|
90
|
-
"#{impl_x} #{-(impl_y)}"
|
91
|
-
i += 1
|
92
|
-
end
|
93
|
-
end
|
94
|
-
|
95
|
-
start_new_contour = false
|
96
|
-
end
|
97
|
-
|
98
|
-
end
|
99
|
-
|
100
|
-
|
101
|
-
|
102
|
-
puts "\" transform=\"translate(0, #{max_y + 10})\" " + \
|
103
|
-
"style=\"fill:black;stroke:black;\"/>/>"
|
104
|
-
|
105
|
-
puts "</g>"
|
106
|
-
end
|
107
|
-
|
108
|
-
def puts_composite_glyph(font, glyph)
|
109
|
-
glyph_offsets = font.get_table(:loca).glyph_offsets
|
110
|
-
glyph.components.each do |gc|
|
111
|
-
gc = font.get_table(:glyf).get_glyph_at_offset(glyph_offsets[gc.index])
|
112
|
-
if gc.composite?
|
113
|
-
puts_composite_glyph(font, gc)
|
114
|
-
else
|
115
|
-
puts_simple_glyph(gc)
|
116
|
-
end
|
117
|
-
end
|
118
|
-
end
|
119
|
-
|
120
|
-
font = TTFFont::TTF::File.new(ARGV[0])
|
121
|
-
|
122
|
-
enc_tbl = font.get_table(:cmap).encoding_tables.find do |t|
|
123
|
-
t.class == TTFFont::TTF::Table::Cmap::EncodingTable4
|
124
|
-
end
|
125
|
-
|
126
|
-
if ARGV[1] == "-g"
|
127
|
-
offs = font.get_table(:loca).glyph_offsets[ARGV[2].to_i]
|
128
|
-
glyph = font.get_table(:glyf).get_glyph_at_offset(offs)
|
129
|
-
elsif ARGV[1] == "-c"
|
130
|
-
char_code = ARGV[2].unpack("U")[0]
|
131
|
-
glyph = enc_tbl.get_glyph_for_unicode(char_code)
|
132
|
-
else
|
133
|
-
exit!
|
134
|
-
end
|
135
|
-
|
136
|
-
puts_svg_header
|
137
|
-
|
138
|
-
if glyph.simple?
|
139
|
-
puts_simple_glyph(glyph)
|
140
|
-
else
|
141
|
-
puts_composite_glyph(font, glyph)
|
142
|
-
end
|
143
|
-
|
144
|
-
puts_svg_footer
|
@@ -1,273 +0,0 @@
|
|
1
|
-
# ttfsubset
|
2
|
-
# Copyright (C) 2006 Mathieu Blondel
|
3
|
-
#
|
4
|
-
# This program is free software; you can redistribute it and/or modify
|
5
|
-
# it under the terms of the GNU General Public License as published by
|
6
|
-
# the Free Software Foundation; either version 2 of the License, or
|
7
|
-
# (at your option) any later version.
|
8
|
-
#
|
9
|
-
# This program is distributed in the hope that it will be useful,
|
10
|
-
# but WITHOUT ANY WARRANTY; without even the implied warranty of
|
11
|
-
# MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
|
12
|
-
# GNU General Public License for more details.
|
13
|
-
#
|
14
|
-
# You should have received a copy of the GNU General Public License
|
15
|
-
# along with this program; if not, write to the Free Software
|
16
|
-
# Foundation, Inc., 51 Franklin St, Fifth Floor, Boston, MA 02110-1301 USA
|
17
|
-
|
18
|
-
$KCODE = "u"
|
19
|
-
|
20
|
-
$LOAD_PATH.unshift("../lib/")
|
21
|
-
|
22
|
-
require 'ttf'
|
23
|
-
|
24
|
-
=begin
|
25
|
-
|
26
|
-
We are going to reduce the number of glyphs.
|
27
|
-
|
28
|
-
Required tables concerned are:
|
29
|
-
- cmap
|
30
|
-
- glyf
|
31
|
-
- hmtx
|
32
|
-
- loca
|
33
|
-
- maxp
|
34
|
-
- post
|
35
|
-
|
36
|
-
Optional tables concerned are:
|
37
|
-
- vmtx
|
38
|
-
|
39
|
-
Non-supported tables should be removed because they may become incorrect
|
40
|
-
if number of @glyphs changed.
|
41
|
-
|
42
|
-
=end
|
43
|
-
|
44
|
-
class UnsupportedFont < Exception
|
45
|
-
end
|
46
|
-
|
47
|
-
class Subsetter
|
48
|
-
|
49
|
-
def add_glyph(glyph, glyph_id, char_code)
|
50
|
-
unless @old_to_new_glyph_id.include? glyph_id
|
51
|
-
@glyphs << glyph
|
52
|
-
new_glyph_id = @glyphs.length - 1
|
53
|
-
@glyph_ids << new_glyph_id
|
54
|
-
|
55
|
-
@old_to_new_glyph_id[glyph_id] = new_glyph_id
|
56
|
-
@charmaps[char_code] = new_glyph_id
|
57
|
-
#$stderr.puts "Old Glyph #{glyph_id} => New Glyph #{new_glyph_id}"
|
58
|
-
#$stderr.puts "Char Code #{char_code} " + \
|
59
|
-
# "(#{[char_code].pack("U")}) " + \
|
60
|
-
# "=> New Glyph #{new_glyph_id}\n\n"
|
61
|
-
@hmetrics << @hmtx_tbl.hmetrics[glyph_id]
|
62
|
-
@postscript_names << @post_tbl.names[glyph_id] \
|
63
|
-
if @post_tbl.names.include? glyph_id
|
64
|
-
end
|
65
|
-
end
|
66
|
-
|
67
|
-
def add_composite_glyph(glyph, glyph_id, char_code)
|
68
|
-
glyph_offsets = @font.get_table(:loca).glyph_offsets
|
69
|
-
glyph.components.each do |gc|
|
70
|
-
offs = glyph_offsets[gc.index]
|
71
|
-
gc_glyph = @font.get_table(:glyf).get_glyph_at_offset(offs)
|
72
|
-
gc_cc = @enc_tbl.get_unicode_for_glyph_id(gc.index)
|
73
|
-
|
74
|
-
if gc_glyph.composite?
|
75
|
-
add_composite_glyph(gc_glyph, gc.index, gc_cc)
|
76
|
-
else
|
77
|
-
add_glyph(gc_glyph, gc.index, gc_cc)
|
78
|
-
end
|
79
|
-
gc.index = @old_to_new_glyph_id[gc.index]
|
80
|
-
end
|
81
|
-
add_glyph(glyph, glyph_id, char_code)
|
82
|
-
end
|
83
|
-
|
84
|
-
def initialize(filename, input_chars)
|
85
|
-
|
86
|
-
@font = TTFFont::TTF::File.new(filename)
|
87
|
-
@subset = TTFFont::TTF::File.new
|
88
|
-
|
89
|
-
@enc_tbl = @font.get_table(:cmap).encoding_tables.find do |t|
|
90
|
-
t.class == TTFFont::TTF::Table::Cmap::EncodingTable4
|
91
|
-
end
|
92
|
-
|
93
|
-
raise UnsupportedFont, "Needs an encoding table 4 (unicode)" \
|
94
|
-
if @enc_tbl.nil? or not @enc_tbl.unicode?
|
95
|
-
|
96
|
-
@charmaps = {}
|
97
|
-
@glyphs = []
|
98
|
-
@glyph_ids = []
|
99
|
-
@hmetrics = []
|
100
|
-
@postscript_names = []
|
101
|
-
|
102
|
-
@hmtx_tbl = @font.get_table(:hmtx)
|
103
|
-
@post_tbl = @font.get_table(:post)
|
104
|
-
|
105
|
-
# Glyph 0 (unsupported chars match to this glyph)
|
106
|
-
|
107
|
-
@glyph_ids << 0
|
108
|
-
@glyphs << @font.get_table(:glyf).get_glyph_at_offset(0)
|
109
|
-
@hmetrics << @hmtx_tbl.hmetrics[0]
|
110
|
-
@postscript_names << @post_tbl.names[0] if @post_tbl.names.include? 0
|
111
|
-
@charmaps[0] = 0
|
112
|
-
|
113
|
-
ascii_range = (0..255).to_a
|
114
|
-
|
115
|
-
@old_to_new_glyph_id = {}
|
116
|
-
|
117
|
-
@input_chars = input_chars
|
118
|
-
|
119
|
-
@input_chars.each do |char_code|
|
120
|
-
glyph_id = @enc_tbl.get_glyph_id_for_unicode(char_code)
|
121
|
-
|
122
|
-
if glyph_id != 0
|
123
|
-
# glyph_id == 0 means character is not supported by @font
|
124
|
-
glyph = @enc_tbl.get_glyph_for_unicode(char_code)
|
125
|
-
|
126
|
-
if glyph.simple?
|
127
|
-
add_glyph(glyph, glyph_id, char_code)
|
128
|
-
else
|
129
|
-
add_composite_glyph(glyph, glyph_id, char_code)
|
130
|
-
end
|
131
|
-
end
|
132
|
-
end
|
133
|
-
|
134
|
-
# Cmap
|
135
|
-
subset_cmap_tbl = @subset.get_new_table(:cmap)
|
136
|
-
subset_enc_tbl = subset_cmap_tbl.get_new_encoding_table4
|
137
|
-
subset_enc_tbl.platform_id = \
|
138
|
-
TTFFont::TTF::Encodings::Platform::UNICODE
|
139
|
-
subset_enc_tbl.encoding_id = \
|
140
|
-
TTFFont::TTF::Encodings::UnicodeEncoding::UNICODE
|
141
|
-
|
142
|
-
subset_enc_tbl.charmaps = @charmaps
|
143
|
-
subset_cmap_tbl.encoding_tables << subset_enc_tbl
|
144
|
-
|
145
|
-
#subset_enc_tbl.charmaps.each do |char_code, glyph_id|
|
146
|
-
#$stderr.puts "Char #{char_code} => Glyph #{glyph_id}"
|
147
|
-
#end
|
148
|
-
|
149
|
-
glyph_id_array = [0] * 255
|
150
|
-
@charmaps.each do |char_code, glyph_id|
|
151
|
-
if char_code <= 255
|
152
|
-
glyph_id_array[char_code] = glyph_id
|
153
|
-
end
|
154
|
-
end
|
155
|
-
|
156
|
-
subset_enc_tbl0 = subset_cmap_tbl.get_new_encoding_table0
|
157
|
-
subset_enc_tbl0.glyph_id_array = glyph_id_array
|
158
|
-
subset_cmap_tbl.encoding_tables << subset_enc_tbl0
|
159
|
-
|
160
|
-
subset_enc_tbl = subset_cmap_tbl.get_new_encoding_table4
|
161
|
-
subset_enc_tbl.platform_id = \
|
162
|
-
TTFFont::TTF::Encodings::Platform::MICROSOFT
|
163
|
-
subset_enc_tbl.encoding_id = \
|
164
|
-
TTFFont::TTF::Encodings::MicrosoftEncoding::UNICODE
|
165
|
-
subset_enc_tbl.charmaps = @charmaps
|
166
|
-
subset_cmap_tbl.encoding_tables << subset_enc_tbl
|
167
|
-
|
168
|
-
@subset.set_table(subset_cmap_tbl)
|
169
|
-
|
170
|
-
# Glyf needs Maxp and Post that's why we put them before
|
171
|
-
|
172
|
-
# Maxp
|
173
|
-
@subset.set_table(@font.get_table(:maxp))
|
174
|
-
|
175
|
-
# Post
|
176
|
-
subset_post_tbl = @font.get_table(:post)
|
177
|
-
subset_post_tbl.names = @postscript_names
|
178
|
-
@subset.set_table(subset_post_tbl)
|
179
|
-
|
180
|
-
# Glyf
|
181
|
-
subset_glyf_tbl = @subset.get_new_table(:glyf)
|
182
|
-
subset_glyf_tbl.glyphs = @glyphs
|
183
|
-
@subset.set_table(subset_glyf_tbl)
|
184
|
-
|
185
|
-
# Head
|
186
|
-
@subset.set_table(@font.get_table(:head))
|
187
|
-
|
188
|
-
# Hhea
|
189
|
-
@subset.set_table(@font.get_table(:hhea))
|
190
|
-
|
191
|
-
# Hmtx
|
192
|
-
subset_hmtx_tbl = @subset.get_new_table(:hmtx)
|
193
|
-
subset_hmtx_tbl.hmetrics = @hmetrics
|
194
|
-
@subset.set_table(subset_hmtx_tbl)
|
195
|
-
|
196
|
-
# Loca
|
197
|
-
@subset.set_table(@subset.get_new_table(:loca))
|
198
|
-
|
199
|
-
# Name
|
200
|
-
name_tbl = @font.get_table(:name)
|
201
|
-
name_tbl.name_records.find_all do |nr|
|
202
|
-
[TTFFont::TTF::Table::Name::NameRecord::UNIQUE_FONT_IDENTIFIER,
|
203
|
-
TTFFont::TTF::Table::Name::NameRecord::FONT_FAMILY_NAME,
|
204
|
-
TTFFont::TTF::Table::Name::NameRecord::FULL_FONT_NAME,
|
205
|
-
TTFFont::TTF::Table::Name::NameRecord::POSTSCRIPT_NAME].include? \
|
206
|
-
nr.name_id and (nr.unicode? or nr.roman?)
|
207
|
-
end.each do |nr|
|
208
|
-
nr.utf8_str += "_subset"
|
209
|
-
end
|
210
|
-
@subset.set_table(name_tbl)
|
211
|
-
|
212
|
-
# OS/2
|
213
|
-
os2_tbl = @font.get_table(:"OS/2")
|
214
|
-
os2_tbl.us_first_char_index = @input_chars.first
|
215
|
-
os2_tbl.us_last_char_index = @input_chars.last
|
216
|
-
@subset.set_table(os2_tbl)
|
217
|
-
|
218
|
-
# Kerning
|
219
|
-
|
220
|
-
if @font.table_list.include? :kern
|
221
|
-
kern_tbl = @font.get_table(:kern)
|
222
|
-
subtbl = kern_tbl.subtables.find { |stbl| stbl.format == 0 }
|
223
|
-
|
224
|
-
kerning_pairs = []
|
225
|
-
|
226
|
-
unless subtbl.nil?
|
227
|
-
subtbl.kerning_pairs.each do |kp|
|
228
|
-
if @old_to_new_glyph_id.include? kp.left and \
|
229
|
-
@old_to_new_glyph_id.include? kp.right
|
230
|
-
kp.left = @old_to_new_glyph_id[kp.left]
|
231
|
-
kp.right = @old_to_new_glyph_id[kp.right]
|
232
|
-
kerning_pairs << kp
|
233
|
-
end
|
234
|
-
end
|
235
|
-
end
|
236
|
-
|
237
|
-
unless kerning_pairs.empty?
|
238
|
-
subset_kern_tbl = @subset.get_new_table(:kern)
|
239
|
-
subset_kern_subtbl = subset_kern_tbl.get_new_kerning_subtable0
|
240
|
-
subset_kern_subtbl.kerning_pairs = kerning_pairs
|
241
|
-
subset_kern_tbl.subtables << subset_kern_subtbl
|
242
|
-
@subset.set_table(subset_kern_tbl)
|
243
|
-
end
|
244
|
-
end
|
245
|
-
|
246
|
-
# Optional tables which are important for font hinting (grid-fitting)
|
247
|
-
[:cvt, :fpgm, :gasp, :prep].each do |tbl|
|
248
|
-
@subset.set_table(@font.get_table(tbl)) if @font.table_list.include? tbl
|
249
|
-
end
|
250
|
-
|
251
|
-
end
|
252
|
-
|
253
|
-
def dump
|
254
|
-
@subset.dump
|
255
|
-
end
|
256
|
-
|
257
|
-
end
|
258
|
-
|
259
|
-
require 'pathname'
|
260
|
-
|
261
|
-
input_chars = $stdin.readlines.join.unpack("U*").uniq.sort
|
262
|
-
ARGV.each_with_index do |filename, i|
|
263
|
-
begin
|
264
|
-
subset_path = "subset_" + Pathname.new(filename).basename
|
265
|
-
puts "Creating " + subset_path + "..."
|
266
|
-
File.new(subset_path,
|
267
|
-
File::CREAT|File::RDWR).write(Subsetter.new(filename,
|
268
|
-
input_chars).dump)
|
269
|
-
rescue UnsupportedFont, TTFFont::TTF::MalformedFont,
|
270
|
-
TTFFont::TTF::TableMissing => e
|
271
|
-
puts e
|
272
|
-
end
|
273
|
-
end
|