glyph_imager 0.0.5 → 0.0.7
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.
- data/VERSION +1 -1
- data/glyph_imager.gemspec +1 -1
- data/lib/glyph_imager.rb +3 -3
- data/test/test_glyph_imager.rb +1 -0
- data/vendor/ttf-ruby-0.1/README +1 -1
- data/vendor/ttf-ruby-0.1/lib/ttf/encodings.rb +1 -1
- data/vendor/ttf-ruby-0.1/lib/ttf/exceptions.rb +1 -1
- data/vendor/ttf-ruby-0.1/lib/ttf/font_loader.rb +44 -44
- data/vendor/ttf-ruby-0.1/lib/ttf/fontchunk.rb +2 -2
- data/vendor/ttf-ruby-0.1/lib/ttf/table/cmap.rb +8 -8
- data/vendor/ttf-ruby-0.1/lib/ttf/table/cvt.rb +2 -2
- data/vendor/ttf-ruby-0.1/lib/ttf/table/fpgm.rb +2 -2
- data/vendor/ttf-ruby-0.1/lib/ttf/table/gasp.rb +3 -3
- data/vendor/ttf-ruby-0.1/lib/ttf/table/glyf.rb +6 -6
- data/vendor/ttf-ruby-0.1/lib/ttf/table/head.rb +2 -2
- data/vendor/ttf-ruby-0.1/lib/ttf/table/hhea.rb +2 -2
- data/vendor/ttf-ruby-0.1/lib/ttf/table/hmtx.rb +2 -2
- data/vendor/ttf-ruby-0.1/lib/ttf/table/kern.rb +3 -3
- data/vendor/ttf-ruby-0.1/lib/ttf/table/loca.rb +8 -8
- data/vendor/ttf-ruby-0.1/lib/ttf/table/maxp.rb +2 -2
- data/vendor/ttf-ruby-0.1/lib/ttf/table/name.rb +8 -4
- data/vendor/ttf-ruby-0.1/lib/ttf/table/os2.rb +2 -2
- data/vendor/ttf-ruby-0.1/lib/ttf/table/post.rb +2 -2
- data/vendor/ttf-ruby-0.1/lib/ttf/table/prep.rb +1 -1
- data/vendor/ttf-ruby-0.1/lib/ttf/table/vhea.rb +1 -1
- data/vendor/ttf-ruby-0.1/lib/ttf/table/vmtx.rb +1 -1
- data/vendor/ttf-ruby-0.1/tools/ttfcairoglyphviewer +2 -2
- data/vendor/ttf-ruby-0.1/tools/ttfdump +13 -13
- data/vendor/ttf-ruby-0.1/tools/ttfglyph2svg +2 -2
- data/vendor/ttf-ruby-0.1/tools/ttfsubset +13 -13
- metadata +2 -2
data/VERSION
CHANGED
@@ -1 +1 @@
|
|
1
|
-
0.0.
|
1
|
+
0.0.7
|
data/glyph_imager.gemspec
CHANGED
data/lib/glyph_imager.rb
CHANGED
@@ -46,12 +46,12 @@ module GlyphImager
|
|
46
46
|
|
47
47
|
@@metadata_ids.each do |m|
|
48
48
|
define_method(m) do
|
49
|
-
name_table.
|
49
|
+
name_table.find_record_by_id(@@metadata_ids.index(m)).to_s
|
50
50
|
end
|
51
51
|
end
|
52
52
|
|
53
53
|
def initialize(filename)
|
54
|
-
@font =
|
54
|
+
@font = TTFFont::TTF::FontLoader.new(filename)
|
55
55
|
end
|
56
56
|
|
57
57
|
def font
|
@@ -64,7 +64,7 @@ module GlyphImager
|
|
64
64
|
|
65
65
|
def get_encoding_table4
|
66
66
|
@enc_tbl ||= @font.get_table(:cmap).encoding_tables.find do |t|
|
67
|
-
t.class ==
|
67
|
+
t.class == TTFFont::TTF::Table::Cmap::EncodingTable4
|
68
68
|
end
|
69
69
|
end
|
70
70
|
|
data/test/test_glyph_imager.rb
CHANGED
@@ -21,6 +21,7 @@ class TestGlyphImager < Test::Unit::TestCase
|
|
21
21
|
should "return font metadata" do
|
22
22
|
assert_equal "DejaVu Serif", @font.full_font_name
|
23
23
|
assert_equal "Copyright (c) 2003 by Bitstream, Inc. All Rights Reserved.\nDejaVu changes are in public domain\n", @font.copyright_notice
|
24
|
+
assert_equal "DejaVu fonts team", @font.manufacturer_name
|
24
25
|
end
|
25
26
|
|
26
27
|
should "return true when glyph exists for character" do
|
data/vendor/ttf-ruby-0.1/README
CHANGED
@@ -38,7 +38,7 @@ require 'ttf/table/prep'
|
|
38
38
|
require 'ttf/table/vhea'
|
39
39
|
require 'ttf/table/vmtx'
|
40
40
|
|
41
|
-
module
|
41
|
+
module TTFFont
|
42
42
|
module TTF
|
43
43
|
# TTF/Ruby is a library to read and write TrueType fonts in Ruby.
|
44
44
|
#
|
@@ -46,12 +46,12 @@ module TTF
|
|
46
46
|
# Copyright:: Copyright (c) 2006 Mathieu Blondel
|
47
47
|
# License:: GPL
|
48
48
|
#
|
49
|
-
# This
|
49
|
+
# This TTFFont::TTF::File class is TTF/Ruby's main class and is a subclass
|
50
50
|
# of Ruby's File class. Here is some sample code:
|
51
51
|
#
|
52
52
|
# require 'ttf'
|
53
53
|
#
|
54
|
-
# font =
|
54
|
+
# font = TTFFont::TTF::File.new("copy.ttf")
|
55
55
|
#
|
56
56
|
# cmap_tbl = font.get_table(:cmap)
|
57
57
|
# enc_tbl4 = cmap_tbl.encoding_tables.find { |t| t.format == 4 }
|
@@ -69,29 +69,29 @@ module TTF
|
|
69
69
|
#
|
70
70
|
# Here are the tables and their associated Symbol:
|
71
71
|
#
|
72
|
-
# * :cmap =>
|
73
|
-
# * :cvt =>
|
74
|
-
# * :fpgm =>
|
75
|
-
# * :gasp =>
|
76
|
-
# * :glyf =>
|
77
|
-
# * :head =>
|
78
|
-
# * :hhea =>
|
79
|
-
# * :hmtx =>
|
80
|
-
# * :kern =>
|
81
|
-
# * :loca =>
|
82
|
-
# * :maxp =>
|
83
|
-
# * :name =>
|
84
|
-
# * :"OS/2" =>
|
85
|
-
# * :post =>
|
86
|
-
# * :prep =>
|
87
|
-
# * :vhea =>
|
88
|
-
# * :vmtx =>
|
72
|
+
# * :cmap => TTFFont::TTF::Table::Cmap
|
73
|
+
# * :cvt => TTFFont::TTF::Table::Cvt
|
74
|
+
# * :fpgm => TTFFont::TTF::Table::Fpgm
|
75
|
+
# * :gasp => TTFFont::TTF::Table::Gasp
|
76
|
+
# * :glyf => TTFFont::TTF::Table::Glyf
|
77
|
+
# * :head => TTFFont::TTF::Table::Head
|
78
|
+
# * :hhea => TTFFont::TTF::Table::Hhea
|
79
|
+
# * :hmtx => TTFFont::TTF::Table::Hmtx
|
80
|
+
# * :kern => TTFFont::TTF::Table::Kern
|
81
|
+
# * :loca => TTFFont::TTF::Table::Loca
|
82
|
+
# * :maxp => TTFFont::TTF::Table::Maxp
|
83
|
+
# * :name => TTFFont::TTF::Table::Name
|
84
|
+
# * :"OS/2" => TTFFont::TTF::Table::OS2
|
85
|
+
# * :post => TTFFont::TTF::Table::Post
|
86
|
+
# * :prep => TTFFont::TTF::Table::Prep
|
87
|
+
# * :vhea => TTFFont::TTF::Table::Vhea
|
88
|
+
# * :vmtx => TTFFont::TTF::Table::Vmtx
|
89
89
|
#
|
90
90
|
# Of course, you may modify attributes and generate a new font file.
|
91
91
|
#
|
92
92
|
# require "ttf"
|
93
93
|
#
|
94
|
-
# font =
|
94
|
+
# font = TTFFont::TTF::File.new("file.ttf", "w")
|
95
95
|
# name_tbl = font.get_table(:name)
|
96
96
|
# nr = name_tbl.name_records[0]
|
97
97
|
# nr.utf8_str = "blablabla"
|
@@ -99,23 +99,23 @@ module TTF
|
|
99
99
|
#
|
100
100
|
class FontLoader < File
|
101
101
|
|
102
|
-
TABLES = {:cmap =>
|
103
|
-
:cvt =>
|
104
|
-
:fpgm =>
|
105
|
-
:gasp =>
|
106
|
-
:glyf =>
|
107
|
-
:head =>
|
108
|
-
:hhea =>
|
109
|
-
:hmtx =>
|
110
|
-
:kern =>
|
111
|
-
:loca =>
|
112
|
-
:maxp =>
|
113
|
-
:name =>
|
114
|
-
:"OS/2" =>
|
115
|
-
:post =>
|
116
|
-
:prep =>
|
117
|
-
:vhea =>
|
118
|
-
:vmtx =>
|
102
|
+
TABLES = {:cmap => TTFFont::TTF::Table::Cmap,
|
103
|
+
:cvt => TTFFont::TTF::Table::Cvt,
|
104
|
+
:fpgm => TTFFont::TTF::Table::Fpgm,
|
105
|
+
:gasp => TTFFont::TTF::Table::Gasp,
|
106
|
+
:glyf => TTFFont::TTF::Table::Glyf,
|
107
|
+
:head => TTFFont::TTF::Table::Head,
|
108
|
+
:hhea => TTFFont::TTF::Table::Hhea,
|
109
|
+
:hmtx => TTFFont::TTF::Table::Hmtx,
|
110
|
+
:kern => TTFFont::TTF::Table::Kern,
|
111
|
+
:loca => TTFFont::TTF::Table::Loca,
|
112
|
+
:maxp => TTFFont::TTF::Table::Maxp,
|
113
|
+
:name => TTFFont::TTF::Table::Name,
|
114
|
+
:"OS/2" => TTFFont::TTF::Table::OS2,
|
115
|
+
:post => TTFFont::TTF::Table::Post,
|
116
|
+
:prep => TTFFont::TTF::Table::Prep,
|
117
|
+
:vhea => TTFFont::TTF::Table::Vhea,
|
118
|
+
:vmtx => TTFFont::TTF::Table::Vmtx}
|
119
119
|
|
120
120
|
DIR_ENTRY_SIZE = 4 * IO::SIZEOF_ULONG
|
121
121
|
|
@@ -124,7 +124,7 @@ class FontLoader < File
|
|
124
124
|
|
125
125
|
attr_writer :version, :search_range, :entry_selector, :range_shift
|
126
126
|
|
127
|
-
#
|
127
|
+
# TTFFont::TTF::File being a subclass of Ruby's File class, you may
|
128
128
|
# create new objects with the same parameters as Ruby's File class.
|
129
129
|
#
|
130
130
|
# But you may also create new objects without parameters in case you want
|
@@ -167,7 +167,7 @@ class FontLoader < File
|
|
167
167
|
end
|
168
168
|
|
169
169
|
# Returns table associated with tag tbl_tag. It may return one of
|
170
|
-
#
|
170
|
+
# TTFFont::TTF::Table::* object or a TTFFont::TTF::FontChunk object if the
|
171
171
|
# table is not implemented yet by ttf-ruby.
|
172
172
|
#
|
173
173
|
# The table returned is kept internally so that every future call to
|
@@ -185,7 +185,7 @@ class FontLoader < File
|
|
185
185
|
@tables[tbl_tag] = \
|
186
186
|
TABLES[tbl_tag].new(self, tbli[:offset], tbli[:len])
|
187
187
|
else
|
188
|
-
|
188
|
+
TTFFont::TTF::FontChunk.new(self, tbli[:offset], tbli[:len])
|
189
189
|
end
|
190
190
|
end
|
191
191
|
|
@@ -200,7 +200,7 @@ class FontLoader < File
|
|
200
200
|
if TABLES.include? tbl_tag
|
201
201
|
TABLES[tbl_tag].new(self)
|
202
202
|
else
|
203
|
-
|
203
|
+
TTFFont::TTF::FontChunk.new(self)
|
204
204
|
end
|
205
205
|
end
|
206
206
|
|
@@ -222,7 +222,7 @@ class FontLoader < File
|
|
222
222
|
private :table_list_update!
|
223
223
|
|
224
224
|
# Adds tbl to font. tbl is a table object
|
225
|
-
# (e.g. an instance of
|
225
|
+
# (e.g. an instance of TTFFont::TTF::Table::Loca).
|
226
226
|
def set_table(tbl)
|
227
227
|
tbl_tag = tbl.tag
|
228
228
|
|
@@ -234,7 +234,7 @@ class FontLoader < File
|
|
234
234
|
end
|
235
235
|
|
236
236
|
# Removes tbl from font. tbl may be a Symbol (e.g. :loca for the loca table)
|
237
|
-
# or a table object (e.g. an instance of
|
237
|
+
# or a table object (e.g. an instance of TTFFont::TTF::Table::Loca).
|
238
238
|
def unset_table(tbl)
|
239
239
|
if tbl.kind_of? Symbol
|
240
240
|
tbl_tag = tbl
|
@@ -15,7 +15,7 @@
|
|
15
15
|
# along with this program; if not, write to the Free Software
|
16
16
|
# Foundation, Inc., 51 Franklin St, Fifth Floor, Boston, MA 02110-1301 USA
|
17
17
|
|
18
|
-
module
|
18
|
+
module TTFFont
|
19
19
|
module TTF
|
20
20
|
|
21
21
|
# A FontChunk is a portion of font. It starts at an offset and has a given
|
@@ -36,7 +36,7 @@ class FontChunk
|
|
36
36
|
|
37
37
|
# Returns the end of the class name as a Symbol.
|
38
38
|
# Will be useful for tables, which are subclasses of FontChunk.
|
39
|
-
# For example, calling tag on
|
39
|
+
# For example, calling tag on TTFFont::TTF:Table::Loca object will return
|
40
40
|
# :loca.
|
41
41
|
def tag
|
42
42
|
t = self.class.name.split("::").last.downcase.to_sym
|
@@ -15,16 +15,16 @@
|
|
15
15
|
# along with this program; if not, write to the Free Software
|
16
16
|
# Foundation, Inc., 51 Franklin St, Fifth Floor, Boston, MA 02110-1301 USA
|
17
17
|
|
18
|
-
module
|
18
|
+
module TTFFont
|
19
19
|
module TTF
|
20
20
|
module Table
|
21
21
|
|
22
22
|
# Cmap is the character to glyph index mapping table.
|
23
|
-
class Cmap <
|
23
|
+
class Cmap < TTFFont::TTF::FontChunk
|
24
24
|
|
25
25
|
# Base class for encoding table classes. It provides attributes which are
|
26
26
|
# common to those classes such as platform_id and encoding_id.
|
27
|
-
class EncodingTable <
|
27
|
+
class EncodingTable < TTFFont::TTF::FontChunk
|
28
28
|
|
29
29
|
attr_accessor :table, :platform_id, :encoding_id, :offset_from_table
|
30
30
|
|
@@ -44,9 +44,9 @@ class Cmap < Font::TTF::FontChunk
|
|
44
44
|
end
|
45
45
|
|
46
46
|
def unicode?
|
47
|
-
@platform_id ==
|
48
|
-
(@platform_id ==
|
49
|
-
@encoding_id ==
|
47
|
+
@platform_id == TTFFont::TTF::Encodings::Platform::UNICODE or \
|
48
|
+
(@platform_id == TTFFont::TTF::Encodings::Platform::MICROSOFT and \
|
49
|
+
@encoding_id == TTFFont::TTF::Encodings::MicrosoftEncoding::UNICODE)
|
50
50
|
end
|
51
51
|
|
52
52
|
# Returns the format (a Fixnum) of the encoding table.
|
@@ -265,8 +265,8 @@ class Cmap < Font::TTF::FontChunk
|
|
265
265
|
id
|
266
266
|
end
|
267
267
|
|
268
|
-
# Returns the
|
269
|
-
#
|
268
|
+
# Returns the TTFFont::TTF::Table::Glyf::SimpleGlyph or
|
269
|
+
# TTFFont::TTF::Table::Glyf::CompositeGlyph associated with unicode.
|
270
270
|
def get_glyph_for_unicode(unicode)
|
271
271
|
id = get_glyph_id_for_unicode(unicode)
|
272
272
|
offs = @font.get_table(:loca).glyph_offsets[id]
|
@@ -15,13 +15,13 @@
|
|
15
15
|
# along with this program; if not, write to the Free Software
|
16
16
|
# Foundation, Inc., 51 Franklin St, Fifth Floor, Boston, MA 02110-1301 USA
|
17
17
|
|
18
|
-
module
|
18
|
+
module TTFFont
|
19
19
|
module TTF
|
20
20
|
module Table
|
21
21
|
|
22
22
|
# Cvt is the Control Value table. It references values that can be
|
23
23
|
# referenced by instructions (used for hinting, aka grid-fitting).
|
24
|
-
class Cvt <
|
24
|
+
class Cvt < TTFFont::TTF::FontChunk
|
25
25
|
|
26
26
|
attr_accessor :instructions
|
27
27
|
|
@@ -15,13 +15,13 @@
|
|
15
15
|
# along with this program; if not, write to the Free Software
|
16
16
|
# Foundation, Inc., 51 Franklin St, Fifth Floor, Boston, MA 02110-1301 USA
|
17
17
|
|
18
|
-
module
|
18
|
+
module TTFFont
|
19
19
|
module TTF
|
20
20
|
module Table
|
21
21
|
|
22
22
|
# Fpgm is the Font Program table. It is similar to the Cvt table except
|
23
23
|
# it is only run once, when the font is first used.
|
24
|
-
class Fpgm <
|
24
|
+
class Fpgm < TTFFont::TTF::FontChunk
|
25
25
|
|
26
26
|
attr_accessor :instructions
|
27
27
|
|
@@ -15,14 +15,14 @@
|
|
15
15
|
# along with this program; if not, write to the Free Software
|
16
16
|
# Foundation, Inc., 51 Franklin St, Fifth Floor, Boston, MA 02110-1301 USA
|
17
17
|
|
18
|
-
module
|
18
|
+
module TTFFont
|
19
19
|
module TTF
|
20
20
|
module Table
|
21
21
|
|
22
22
|
# Gasp is the Grid-fitting and scan conversion procedure table.
|
23
|
-
class Gasp <
|
23
|
+
class Gasp < TTFFont::TTF::FontChunk
|
24
24
|
|
25
|
-
class GaspRange <
|
25
|
+
class GaspRange < TTFFont::TTF::FontChunk
|
26
26
|
|
27
27
|
SIZEOF_GASP_RANGE = 2 * IO::SIZEOF_USHORT
|
28
28
|
|
@@ -15,15 +15,15 @@
|
|
15
15
|
# along with this program; if not, write to the Free Software
|
16
16
|
# Foundation, Inc., 51 Franklin St, Fifth Floor, Boston, MA 02110-1301 USA
|
17
17
|
|
18
|
-
module
|
18
|
+
module TTFFont
|
19
19
|
module TTF
|
20
20
|
module Table
|
21
21
|
|
22
22
|
# Glyf is the Glyph data table.
|
23
|
-
class Glyf <
|
23
|
+
class Glyf < TTFFont::TTF::FontChunk
|
24
24
|
|
25
25
|
# Base class for SimpleGlyph and CompositeGlyph.
|
26
|
-
class Glyph <
|
26
|
+
class Glyph < TTFFont::TTF::FontChunk
|
27
27
|
|
28
28
|
attr_accessor :num_contours, :x_min, :y_min, :x_max, :y_max
|
29
29
|
|
@@ -384,7 +384,7 @@ class Glyf < Font::TTF::FontChunk
|
|
384
384
|
|
385
385
|
# Returns all Glyph (SimpleGlyph or CompositeGlyph) in an Array.
|
386
386
|
# This method may be real overkill if you just need to access a few glyphs.
|
387
|
-
# In this case, you should use the loca table (
|
387
|
+
# In this case, you should use the loca table (TTFFont::TTF::Table::Loca)
|
388
388
|
# to get offsets and get_glyph_at_offset to get glyph associated with them.
|
389
389
|
def glyphs
|
390
390
|
@glyphs ||= get_glyphs
|
@@ -434,10 +434,10 @@ class Glyf < Font::TTF::FontChunk
|
|
434
434
|
# Using shorts saves two bytes per glyph!
|
435
435
|
if offs < 131072
|
436
436
|
@font.get_table(:head).index_to_loc_format = \
|
437
|
-
|
437
|
+
TTFFont::TTF::Table::Head::SHORT_FORMAT
|
438
438
|
else
|
439
439
|
@font.get_table(:head).index_to_loc_format = \
|
440
|
-
|
440
|
+
TTFFont::TTF::Table::Head::LONG_FORMAT
|
441
441
|
end
|
442
442
|
|
443
443
|
@font.get_table(:loca).glyph_offsets = glyph_offsets
|
@@ -15,12 +15,12 @@
|
|
15
15
|
# along with this program; if not, write to the Free Software
|
16
16
|
# Foundation, Inc., 51 Franklin St, Fifth Floor, Boston, MA 02110-1301 USA
|
17
17
|
|
18
|
-
module
|
18
|
+
module TTFFont
|
19
19
|
module TTF
|
20
20
|
module Table
|
21
21
|
|
22
22
|
# Head is the font header table, which gives global informations about the font.
|
23
|
-
class Head <
|
23
|
+
class Head < TTFFont::TTF::FontChunk
|
24
24
|
|
25
25
|
LONG_FORMAT = 1
|
26
26
|
SHORT_FORMAT = 0
|
@@ -15,12 +15,12 @@
|
|
15
15
|
# along with this program; if not, write to the Free Software
|
16
16
|
# Foundation, Inc., 51 Franklin St, Fifth Floor, Boston, MA 02110-1301 USA
|
17
17
|
|
18
|
-
module
|
18
|
+
module TTFFont
|
19
19
|
module TTF
|
20
20
|
module Table
|
21
21
|
|
22
22
|
# Hea is a base class for Hhea and Vhea.
|
23
|
-
class Hea <
|
23
|
+
class Hea < TTFFont::TTF::FontChunk
|
24
24
|
|
25
25
|
attr_accessor :version, :ascender, :descender, :line_gap,
|
26
26
|
:advance_max, :min_side_bearing_1,
|
@@ -15,12 +15,12 @@
|
|
15
15
|
# along with this program; if not, write to the Free Software
|
16
16
|
# Foundation, Inc., 51 Franklin St, Fifth Floor, Boston, MA 02110-1301 USA
|
17
17
|
|
18
|
-
module
|
18
|
+
module TTFFont
|
19
19
|
module TTF
|
20
20
|
module Table
|
21
21
|
|
22
22
|
# Mtx is a base class for Hmtx and Vmtx.
|
23
|
-
class Mtx <
|
23
|
+
class Mtx < TTFFont::TTF::FontChunk
|
24
24
|
|
25
25
|
def initialize(*args)
|
26
26
|
super(*args)
|
@@ -15,15 +15,15 @@
|
|
15
15
|
# along with this program; if not, write to the Free Software
|
16
16
|
# Foundation, Inc., 51 Franklin St, Fifth Floor, Boston, MA 02110-1301 USA
|
17
17
|
|
18
|
-
module
|
18
|
+
module TTFFont
|
19
19
|
module TTF
|
20
20
|
module Table
|
21
21
|
|
22
22
|
# Kern is the Kerning table, which contains values for intercharacter spacing.
|
23
|
-
class Kern <
|
23
|
+
class Kern < TTFFont::TTF::FontChunk
|
24
24
|
|
25
25
|
# KerningSubtable is a base class for KerningSubtable0 and KerningSubtable2.
|
26
|
-
class KerningSubtable <
|
26
|
+
class KerningSubtable < TTFFont::TTF::FontChunk
|
27
27
|
|
28
28
|
HORIZONTAL = 0b1
|
29
29
|
MINIMUM = 0b10
|
@@ -15,18 +15,18 @@
|
|
15
15
|
# along with this program; if not, write to the Free Software
|
16
16
|
# Foundation, Inc., 51 Franklin St, Fifth Floor, Boston, MA 02110-1301 USA
|
17
17
|
|
18
|
-
module
|
18
|
+
module TTFFont
|
19
19
|
module TTF
|
20
20
|
module Table
|
21
21
|
|
22
22
|
# Loca is the Location table class. It provides the offsets of glyphs in
|
23
23
|
# the glyf table.
|
24
|
-
class Loca <
|
24
|
+
class Loca < TTFFont::TTF::FontChunk
|
25
25
|
|
26
26
|
# An array of glyphs offsets with number of glyphs + 1 elements.
|
27
27
|
# The value associated with a given index of that array
|
28
28
|
# is the offset associated with glyph with index index.
|
29
|
-
# This offset may be used with
|
29
|
+
# This offset may be used with TTFFont::TTF::Table::Glyf#get_glyph_at_offset
|
30
30
|
# to get the glyph object associated with offset.
|
31
31
|
#
|
32
32
|
# The additional offset is added so that the length of the
|
@@ -35,7 +35,7 @@ class Loca < Font::TTF::FontChunk
|
|
35
35
|
attr_accessor :glyph_offsets
|
36
36
|
|
37
37
|
# It is not recommended to create Loca objects by hand.
|
38
|
-
# Use
|
38
|
+
# Use TTFFont::TTF::File#get_table or TTFFont::TTF::File#get_new_table
|
39
39
|
# with :loca as parameter instead.
|
40
40
|
def initialize(*args)
|
41
41
|
super(*args)
|
@@ -45,10 +45,10 @@ class Loca < Font::TTF::FontChunk
|
|
45
45
|
n = @font.get_table(:maxp).num_glyphs + 1
|
46
46
|
|
47
47
|
case @font.get_table(:head).index_to_loc_format
|
48
|
-
when
|
48
|
+
when TTFFont::TTF::Table::Head::SHORT_FORMAT
|
49
49
|
@glyph_offsets = @font.read_ushorts(n)
|
50
50
|
@glyph_offsets.collect! { |o| o * 2 }
|
51
|
-
when
|
51
|
+
when TTFFont::TTF::Table::Head::LONG_FORMAT
|
52
52
|
@glyph_offsets = @font.read_ulongs(n)
|
53
53
|
|
54
54
|
end
|
@@ -60,9 +60,9 @@ class Loca < Font::TTF::FontChunk
|
|
60
60
|
# file.
|
61
61
|
def dump
|
62
62
|
case @font.get_table(:head).index_to_loc_format
|
63
|
-
when
|
63
|
+
when TTFFont::TTF::Table::Head::SHORT_FORMAT
|
64
64
|
@glyph_offsets.collect { |o| o / 2 }.to_ushorts
|
65
|
-
when
|
65
|
+
when TTFFont::TTF::Table::Head::LONG_FORMAT
|
66
66
|
@glyph_offsets.to_ulongs
|
67
67
|
|
68
68
|
end
|
@@ -15,13 +15,13 @@
|
|
15
15
|
# along with this program; if not, write to the Free Software
|
16
16
|
# Foundation, Inc., 51 Franklin St, Fifth Floor, Boston, MA 02110-1301 USA
|
17
17
|
|
18
|
-
module
|
18
|
+
module TTFFont
|
19
19
|
module TTF
|
20
20
|
module Table
|
21
21
|
|
22
22
|
# Maxp is the Maximum profile tables, which establishes memory requirements
|
23
23
|
# for the associated font.
|
24
|
-
class Maxp <
|
24
|
+
class Maxp < TTFFont::TTF::FontChunk
|
25
25
|
|
26
26
|
attr_accessor :version, :num_glyphs, :max_points, :max_contours,
|
27
27
|
:max_composite_points, :max_composite_contours,
|
@@ -17,17 +17,17 @@
|
|
17
17
|
|
18
18
|
require 'iconv'
|
19
19
|
|
20
|
-
module
|
20
|
+
module TTFFont
|
21
21
|
module TTF
|
22
22
|
module Table
|
23
23
|
|
24
24
|
# Name is the the Naming table which allows multilingual strings to be
|
25
25
|
# associated with the TrueType font file.
|
26
|
-
class Name <
|
26
|
+
class Name < TTFFont::TTF::FontChunk
|
27
27
|
|
28
28
|
# A NameRecord holds a string for a given Platform and Encoding.
|
29
|
-
class NameRecord <
|
30
|
-
include
|
29
|
+
class NameRecord < TTFFont::TTF::FontChunk
|
30
|
+
include TTFFont::TTF::Encodings
|
31
31
|
|
32
32
|
COPYRIGHT_NOTICE = 0
|
33
33
|
FONT_FAMILY_NAME = 1
|
@@ -181,6 +181,10 @@ class Name < Font::TTF::FontChunk
|
|
181
181
|
end
|
182
182
|
end
|
183
183
|
end
|
184
|
+
|
185
|
+
def find_record_by_id(id)
|
186
|
+
@name_records.detect { |r| r.name_id == id }
|
187
|
+
end
|
184
188
|
|
185
189
|
# Gets a new empty NameRecord which may then be added to the
|
186
190
|
# name_records array.
|
@@ -15,12 +15,12 @@
|
|
15
15
|
# along with this program; if not, write to the Free Software
|
16
16
|
# Foundation, Inc., 51 Franklin St, Fifth Floor, Boston, MA 02110-1301 USA
|
17
17
|
|
18
|
-
module
|
18
|
+
module TTFFont
|
19
19
|
module TTF
|
20
20
|
module Table
|
21
21
|
|
22
22
|
# OS2 is the OS/2 and Windows font metrics table.
|
23
|
-
class OS2 <
|
23
|
+
class OS2 < TTFFont::TTF::FontChunk
|
24
24
|
|
25
25
|
INSTALLABLE_EMBEDDING = 0x0000
|
26
26
|
RESTRICTED_LICENCE_EMBEDDING = 0x0002
|
@@ -15,13 +15,13 @@
|
|
15
15
|
# along with this program; if not, write to the Free Software
|
16
16
|
# Foundation, Inc., 51 Franklin St, Fifth Floor, Boston, MA 02110-1301 USA
|
17
17
|
|
18
|
-
module
|
18
|
+
module TTFFont
|
19
19
|
module TTF
|
20
20
|
module Table
|
21
21
|
|
22
22
|
# Post is the PostScript table, which contains additional informations needed
|
23
23
|
# to use TrueType fonts on PostScript printers
|
24
|
-
class Post <
|
24
|
+
class Post < TTFFont::TTF::FontChunk
|
25
25
|
|
26
26
|
attr_accessor :format_type, :italic_angle, :underline_position,
|
27
27
|
:underline_thickness, :is_fixed_pitch,
|
@@ -189,10 +189,10 @@ class Cairo::Context
|
|
189
189
|
end
|
190
190
|
end
|
191
191
|
|
192
|
-
font =
|
192
|
+
font = TTFFont::TTF::File.new(ARGV[0])
|
193
193
|
|
194
194
|
enc_tbl = font.get_table(:cmap).encoding_tables.find do |t|
|
195
|
-
t.class ==
|
195
|
+
t.class == TTFFont::TTF::Table::Cmap::EncodingTable4
|
196
196
|
end
|
197
197
|
|
198
198
|
if ARGV[1] == "-g"
|
@@ -56,7 +56,7 @@ if ARGV.length == 0 or ["h", "-h", "help", "--help"].include? ARGV[0]
|
|
56
56
|
usage
|
57
57
|
exit!
|
58
58
|
else
|
59
|
-
ttf =
|
59
|
+
ttf = TTFFont::TTF::File.new(ARGV[0])
|
60
60
|
end
|
61
61
|
|
62
62
|
if ARGV.length == 1 or (ARGV.length == 2 and ARGV[1] == "all")
|
@@ -70,17 +70,17 @@ if ARGV.length == 1 or (ARGV.length == 2 and ARGV[1] == "all")
|
|
70
70
|
name = ttf.get_table(:name)
|
71
71
|
|
72
72
|
fontname = name.name_records.find do |nr|
|
73
|
-
[
|
74
|
-
|
75
|
-
|
76
|
-
|
73
|
+
[TTFFont::TTF::Table::Name::NameRecord::UNIQUE_FONT_IDENTIFIER,
|
74
|
+
TTFFont::TTF::Table::Name::NameRecord::FONT_FAMILY_NAME,
|
75
|
+
TTFFont::TTF::Table::Name::NameRecord::FULL_FONT_NAME,
|
76
|
+
TTFFont::TTF::Table::Name::NameRecord::POSTSCRIPT_NAME].include? \
|
77
77
|
nr.name_id and (nr.unicode? or nr.roman?)
|
78
78
|
end
|
79
79
|
|
80
80
|
define("Font Name", fontname.utf8_str) unless fontname.nil?
|
81
81
|
|
82
82
|
fontcopyright = name.name_records.find do |nr|
|
83
|
-
nr.name_id ==
|
83
|
+
nr.name_id == TTFFont::TTF::Table::Name::NameRecord::COPYRIGHT_NOTICE \
|
84
84
|
and (nr.unicode? or nr.roman?)
|
85
85
|
end
|
86
86
|
|
@@ -215,7 +215,7 @@ if ARGV.length == 4 and ARGV[1] == "glyf" and
|
|
215
215
|
glyf = ttf.get_table(:glyf)
|
216
216
|
|
217
217
|
enc_tbl = ttf.get_table(:cmap).encoding_tables.find do |t|
|
218
|
-
t.class ==
|
218
|
+
t.class == TTFFont::TTF::Table::Cmap::EncodingTable4
|
219
219
|
end
|
220
220
|
|
221
221
|
if ARGV[2] == "-g"
|
@@ -322,21 +322,21 @@ if ARGV.length == 2 and (ARGV[1] == "name" or ARGV[1] == "all") and
|
|
322
322
|
name.name_records.each_with_index do |nr, i|
|
323
323
|
define("Name record number", i)
|
324
324
|
define("Platform id", "%d (%s)" % [nr.platform_id,
|
325
|
-
|
325
|
+
TTFFont::TTF::Encodings::Platform::ID2NAME[nr.platform_id]])
|
326
326
|
|
327
327
|
if nr.platform_id == \
|
328
|
-
|
328
|
+
TTFFont::TTF::Encodings::Platform::MICROSOFT
|
329
329
|
define("Encoding id", "%d (%s)" % [nr.encoding_id,
|
330
|
-
|
330
|
+
TTFFont::TTF::Encodings::MicrosoftEncoding::ID2NAME[nr.encoding_id]])
|
331
331
|
elsif nr.platform_id == \
|
332
|
-
|
332
|
+
TTFFont::TTF::Encodings::Platform::MACINTOSH
|
333
333
|
define("Encoding id", "%d (%s)" % [nr.encoding_id,
|
334
|
-
|
334
|
+
TTFFont::TTF::Encodings::MacintoshEncoding::ID2NAME[nr.encoding_id]])
|
335
335
|
end
|
336
336
|
|
337
337
|
define("Language id", nr.language_id)
|
338
338
|
define("Name id", "%d (%s)" % [nr.name_id,
|
339
|
-
|
339
|
+
TTFFont::TTF::Table::Name::NameRecord::ID2NAME[nr.name_id]])
|
340
340
|
define("String length", nr.to_s.length)
|
341
341
|
define("String offset", nr.str_offset)
|
342
342
|
define("String value", nr.utf8_str)
|
@@ -117,10 +117,10 @@ def puts_composite_glyph(font, glyph)
|
|
117
117
|
end
|
118
118
|
end
|
119
119
|
|
120
|
-
font =
|
120
|
+
font = TTFFont::TTF::File.new(ARGV[0])
|
121
121
|
|
122
122
|
enc_tbl = font.get_table(:cmap).encoding_tables.find do |t|
|
123
|
-
t.class ==
|
123
|
+
t.class == TTFFont::TTF::Table::Cmap::EncodingTable4
|
124
124
|
end
|
125
125
|
|
126
126
|
if ARGV[1] == "-g"
|
@@ -83,11 +83,11 @@ end
|
|
83
83
|
|
84
84
|
def initialize(filename, input_chars)
|
85
85
|
|
86
|
-
@font =
|
87
|
-
@subset =
|
86
|
+
@font = TTFFont::TTF::File.new(filename)
|
87
|
+
@subset = TTFFont::TTF::File.new
|
88
88
|
|
89
89
|
@enc_tbl = @font.get_table(:cmap).encoding_tables.find do |t|
|
90
|
-
t.class ==
|
90
|
+
t.class == TTFFont::TTF::Table::Cmap::EncodingTable4
|
91
91
|
end
|
92
92
|
|
93
93
|
raise UnsupportedFont, "Needs an encoding table 4 (unicode)" \
|
@@ -135,9 +135,9 @@ end
|
|
135
135
|
subset_cmap_tbl = @subset.get_new_table(:cmap)
|
136
136
|
subset_enc_tbl = subset_cmap_tbl.get_new_encoding_table4
|
137
137
|
subset_enc_tbl.platform_id = \
|
138
|
-
|
138
|
+
TTFFont::TTF::Encodings::Platform::UNICODE
|
139
139
|
subset_enc_tbl.encoding_id = \
|
140
|
-
|
140
|
+
TTFFont::TTF::Encodings::UnicodeEncoding::UNICODE
|
141
141
|
|
142
142
|
subset_enc_tbl.charmaps = @charmaps
|
143
143
|
subset_cmap_tbl.encoding_tables << subset_enc_tbl
|
@@ -159,9 +159,9 @@ subset_cmap_tbl.encoding_tables << subset_enc_tbl0
|
|
159
159
|
|
160
160
|
subset_enc_tbl = subset_cmap_tbl.get_new_encoding_table4
|
161
161
|
subset_enc_tbl.platform_id = \
|
162
|
-
|
162
|
+
TTFFont::TTF::Encodings::Platform::MICROSOFT
|
163
163
|
subset_enc_tbl.encoding_id = \
|
164
|
-
|
164
|
+
TTFFont::TTF::Encodings::MicrosoftEncoding::UNICODE
|
165
165
|
subset_enc_tbl.charmaps = @charmaps
|
166
166
|
subset_cmap_tbl.encoding_tables << subset_enc_tbl
|
167
167
|
|
@@ -199,10 +199,10 @@ subset_hmtx_tbl.hmetrics = @hmetrics
|
|
199
199
|
# Name
|
200
200
|
name_tbl = @font.get_table(:name)
|
201
201
|
name_tbl.name_records.find_all do |nr|
|
202
|
-
[
|
203
|
-
|
204
|
-
|
205
|
-
|
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
206
|
nr.name_id and (nr.unicode? or nr.roman?)
|
207
207
|
end.each do |nr|
|
208
208
|
nr.utf8_str += "_subset"
|
@@ -266,8 +266,8 @@ ARGV.each_with_index do |filename, i|
|
|
266
266
|
File.new(subset_path,
|
267
267
|
File::CREAT|File::RDWR).write(Subsetter.new(filename,
|
268
268
|
input_chars).dump)
|
269
|
-
rescue UnsupportedFont,
|
270
|
-
|
269
|
+
rescue UnsupportedFont, TTFFont::TTF::MalformedFont,
|
270
|
+
TTFFont::TTF::TableMissing => e
|
271
271
|
puts e
|
272
272
|
end
|
273
273
|
end
|