Class: Pdfrb::Font::TrueType::File
- Inherits:
-
Object
- Object
- Pdfrb::Font::TrueType::File
- Defined in:
- lib/pdfrb/font/true_type/file.rb
Overview
Minimal TrueType / OpenType font file reader. Parses the sfnt header + table directory; lazy-loads individual tables on access.
Instance Attribute Summary collapse
-
#num_tables ⇒ Object
readonly
Returns the value of attribute num_tables.
-
#tables ⇒ Object
readonly
Returns the value of attribute tables.
Class Method Summary collapse
Instance Method Summary collapse
- #cmap ⇒ Object
- #cmap_table ⇒ Object
- #glyf_table ⇒ Object
-
#head ⇒ Object
Parsed-table accessors.
- #head_table ⇒ Object
- #hhea ⇒ Object
- #hhea_table ⇒ Object
- #hmtx ⇒ Object
- #hmtx_table ⇒ Object
-
#initialize(data) ⇒ File
constructor
A new instance of File.
- #loca_table ⇒ Object
- #maxp_table ⇒ Object
- #name_table ⇒ Object
- #num_glyphs ⇒ Object
- #os2 ⇒ Object
- #os2_table ⇒ Object
- #post_table ⇒ Object
- #table(tag) ⇒ Object
Constructor Details
#initialize(data) ⇒ File
Returns a new instance of File.
12 13 14 15 16 |
# File 'lib/pdfrb/font/true_type/file.rb', line 12 def initialize(data) @data = data.b @tables = {} parse_directory end |
Instance Attribute Details
#num_tables ⇒ Object (readonly)
Returns the value of attribute num_tables.
10 11 12 |
# File 'lib/pdfrb/font/true_type/file.rb', line 10 def num_tables @num_tables end |
#tables ⇒ Object (readonly)
Returns the value of attribute tables.
10 11 12 |
# File 'lib/pdfrb/font/true_type/file.rb', line 10 def tables @tables end |
Class Method Details
.read(path) ⇒ Object
18 19 20 |
# File 'lib/pdfrb/font/true_type/file.rb', line 18 def self.read(path) new(::File.binread(path)) end |
Instance Method Details
#cmap ⇒ Object
48 |
# File 'lib/pdfrb/font/true_type/file.rb', line 48 def cmap; @cmap ||= Cmap.new(cmap_table); end |
#cmap_table ⇒ Object
33 |
# File 'lib/pdfrb/font/true_type/file.rb', line 33 def cmap_table; table("cmap"); end |
#glyf_table ⇒ Object
41 |
# File 'lib/pdfrb/font/true_type/file.rb', line 41 def glyf_table; table("glyf"); end |
#head ⇒ Object
Parsed-table accessors. Lazy and memoised on the instance.
45 |
# File 'lib/pdfrb/font/true_type/file.rb', line 45 def head; @head ||= Head.new(head_table); end |
#head_table ⇒ Object
34 |
# File 'lib/pdfrb/font/true_type/file.rb', line 34 def head_table; table("head"); end |
#hhea ⇒ Object
46 |
# File 'lib/pdfrb/font/true_type/file.rb', line 46 def hhea; @hhea ||= Hhea.new(hhea_table); end |
#hhea_table ⇒ Object
35 |
# File 'lib/pdfrb/font/true_type/file.rb', line 35 def hhea_table; table("hhea"); end |
#hmtx ⇒ Object
50 51 52 |
# File 'lib/pdfrb/font/true_type/file.rb', line 50 def hmtx @hmtx ||= Hmtx.new(hmtx_table, number_of_hmetrics: hhea.number_of_hmetrics || 0) end |
#hmtx_table ⇒ Object
36 |
# File 'lib/pdfrb/font/true_type/file.rb', line 36 def hmtx_table; table("hmtx"); end |
#loca_table ⇒ Object
42 |
# File 'lib/pdfrb/font/true_type/file.rb', line 42 def loca_table; table("loca"); end |
#maxp_table ⇒ Object
38 |
# File 'lib/pdfrb/font/true_type/file.rb', line 38 def maxp_table; table("maxp"); end |
#name_table ⇒ Object
37 |
# File 'lib/pdfrb/font/true_type/file.rb', line 37 def name_table; table("name"); end |
#num_glyphs ⇒ Object
54 55 56 57 58 |
# File 'lib/pdfrb/font/true_type/file.rb', line 54 def num_glyphs return 0 unless maxp_table maxp_table.getbyte(4) * 256 + maxp_table.getbyte(5) end |
#os2 ⇒ Object
47 |
# File 'lib/pdfrb/font/true_type/file.rb', line 47 def os2; @os2 ||= OS2.new(os2_table); end |
#os2_table ⇒ Object
40 |
# File 'lib/pdfrb/font/true_type/file.rb', line 40 def os2_table; table("OS/2"); end |
#post_table ⇒ Object
39 |
# File 'lib/pdfrb/font/true_type/file.rb', line 39 def post_table; table("post"); end |
#table(tag) ⇒ Object
22 23 24 25 26 27 28 29 30 31 |
# File 'lib/pdfrb/font/true_type/file.rb', line 22 def table(tag) return @tables[tag][:data] if @tables[tag] entry = find_table_entry(tag) return nil unless entry offset = entry[:offset] length = entry[:length] @data.byteslice(offset, length).force_encoding(::Encoding::BINARY) end |