Class: TTFunk::Table::Glyf
- Inherits:
-
TTFunk::Table
- Object
- TTFunk::Table
- TTFunk::Table::Glyf
- Defined in:
- lib/ttfunk/table/glyf.rb,
lib/ttfunk/table/glyf/simple.rb,
lib/ttfunk/table/glyf/compound.rb,
lib/ttfunk/table/glyf/path_based.rb
Overview
Glyph Data (glyf
) table.
Defined Under Namespace
Classes: Compound, PathBased, Simple
Instance Attribute Summary
Attributes inherited from TTFunk::Table
Class Method Summary collapse
-
.encode(glyphs, new_to_old, old_to_new) ⇒ Hash
Encode table.
Instance Method Summary collapse
-
#for(glyph_id) ⇒ TTFunk::Table::Glyf::Simple, ...
Get glyph by ID.
Methods inherited from TTFunk::Table
#exists?, #initialize, #raw, #tag
Constructor Details
This class inherits a constructor from TTFunk::Table
Class Method Details
.encode(glyphs, new_to_old, old_to_new) ⇒ Hash
Encode table.
Source Code
lib/ttfunk/table/glyf.rb, line 19
19 | def self.encode(glyphs, new_to_old, old_to_new) |
20 | result = { table: +'', offsets: [] } |
21 | |
22 | new_to_old.keys.sort.each do |new_id| |
23 | glyph = glyphs[new_to_old[new_id]] |
24 | result[:offsets] << result[:table].length |
25 | result[:table] << glyph.recode(old_to_new) if glyph |
26 | end
|
27 | |
28 | # include an offset at the end of the table, for use in computing the
|
29 | # size of the last glyph
|
30 | result[:offsets] << result[:table].length |
31 | result
|
32 | end
|
Instance Method Details
#for(glyph_id) ⇒ TTFunk::Table::Glyf::Simple, ...
Get glyph by ID.
Source Code
lib/ttfunk/table/glyf.rb, line 39
39 | def for(glyph_id) |
40 | return @cache[glyph_id] if @cache.key?(glyph_id) |
41 | |
42 | index = file.glyph_locations.index_of(glyph_id) |
43 | size = file.glyph_locations.size_of(glyph_id) |
44 | |
45 | if size.zero? # blank glyph, e.g. space character |
46 | @cache[glyph_id] = nil |
47 | return
|
48 | end
|
49 | |
50 | parse_from(offset + index) do |
51 | raw = io.read(size) |
52 | number_of_contours = to_signed(raw.unpack1('n')) |
53 | |
54 | @cache[glyph_id] = |
55 | if number_of_contours == -1 |
56 | Compound.new(glyph_id, raw) |
57 | else
|
58 | Simple.new(glyph_id, raw) |
59 | end
|
60 | end
|
61 | end
|