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.
-
#raw_data ⇒ Object
readonly
Returns the value of attribute raw_data.
-
#tables ⇒ Object
readonly
Returns the value of attribute tables.
Class Method Summary collapse
Instance Method Summary collapse
- #cmap ⇒ Object
- #cmap_table ⇒ Object
- #glyf_parsed ⇒ 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.
- #kern_parsed ⇒ Object
- #kern_table ⇒ Object
- #loca_parsed ⇒ Object
- #loca_table ⇒ Object
- #maxp ⇒ Object
- #maxp_table ⇒ Object
- #name_table ⇒ Object
- #name_table_parsed ⇒ Object
- #num_glyphs ⇒ Object
- #os2 ⇒ Object
- #os2_table ⇒ Object
- #post ⇒ Object
- #post_table ⇒ Object
- #table(tag) ⇒ Object
Constructor Details
#initialize(data) ⇒ File
Returns a new instance of File.
12 13 14 15 16 17 |
# File 'lib/pdfrb/font/true_type/file.rb', line 12 def initialize(data) @data = data.b @raw_data = @data @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 |
#raw_data ⇒ Object (readonly)
Returns the value of attribute raw_data.
10 11 12 |
# File 'lib/pdfrb/font/true_type/file.rb', line 10 def raw_data @raw_data 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
19 20 21 |
# File 'lib/pdfrb/font/true_type/file.rb', line 19 def self.read(path) new(::File.binread(path)) end |
Instance Method Details
#cmap ⇒ Object
57 |
# File 'lib/pdfrb/font/true_type/file.rb', line 57 def cmap; @cmap ||= Cmap.new(cmap_table); end |
#cmap_table ⇒ Object
34 |
# File 'lib/pdfrb/font/true_type/file.rb', line 34 def cmap_table; table("cmap"); end |
#glyf_parsed ⇒ Object
53 |
# File 'lib/pdfrb/font/true_type/file.rb', line 53 def glyf_parsed; @glyf_parsed ||= Glyf.new(glyf_table, loca_parsed); end |
#glyf_table ⇒ Object
42 |
# File 'lib/pdfrb/font/true_type/file.rb', line 42 def glyf_table; table("glyf"); end |
#head ⇒ Object
Parsed-table accessors. Lazy and memoised on the instance.
47 |
# File 'lib/pdfrb/font/true_type/file.rb', line 47 def head; @head ||= Head.new(head_table); end |
#head_table ⇒ Object
35 |
# File 'lib/pdfrb/font/true_type/file.rb', line 35 def head_table; table("head"); end |
#hhea ⇒ Object
55 |
# File 'lib/pdfrb/font/true_type/file.rb', line 55 def hhea; @hhea ||= Hhea.new(hhea_table); end |
#hhea_table ⇒ Object
36 |
# File 'lib/pdfrb/font/true_type/file.rb', line 36 def hhea_table; table("hhea"); end |
#hmtx ⇒ Object
59 60 61 |
# File 'lib/pdfrb/font/true_type/file.rb', line 59 def hmtx @hmtx ||= Hmtx.new(hmtx_table, number_of_hmetrics: hhea.number_of_hmetrics || 0) end |
#hmtx_table ⇒ Object
37 |
# File 'lib/pdfrb/font/true_type/file.rb', line 37 def hmtx_table; table("hmtx"); end |
#kern_parsed ⇒ Object
54 |
# File 'lib/pdfrb/font/true_type/file.rb', line 54 def kern_parsed; @kern_parsed ||= Kern.new(kern_table); end |
#kern_table ⇒ Object
44 |
# File 'lib/pdfrb/font/true_type/file.rb', line 44 def kern_table; table("kern"); end |
#loca_parsed ⇒ Object
52 |
# File 'lib/pdfrb/font/true_type/file.rb', line 52 def loca_parsed; @loca_parsed ||= Loca.new(loca_table, long_format: head.long_loca?, num_glyphs: maxp.num_glyphs); end |
#loca_table ⇒ Object
43 |
# File 'lib/pdfrb/font/true_type/file.rb', line 43 def loca_table; table("loca"); end |
#maxp ⇒ Object
49 |
# File 'lib/pdfrb/font/true_type/file.rb', line 49 def maxp; @maxp ||= Maxp.new(maxp_table); end |
#maxp_table ⇒ Object
39 |
# File 'lib/pdfrb/font/true_type/file.rb', line 39 def maxp_table; table("maxp"); end |
#name_table ⇒ Object
38 |
# File 'lib/pdfrb/font/true_type/file.rb', line 38 def name_table; table("name"); end |
#name_table_parsed ⇒ Object
51 |
# File 'lib/pdfrb/font/true_type/file.rb', line 51 def name_table_parsed; @name_table_parsed ||= Name.new(name_table); end |
#num_glyphs ⇒ Object
63 64 65 66 67 |
# File 'lib/pdfrb/font/true_type/file.rb', line 63 def num_glyphs return 0 unless maxp_table maxp_table.getbyte(4) * 256 + maxp_table.getbyte(5) end |
#os2 ⇒ Object
56 |
# File 'lib/pdfrb/font/true_type/file.rb', line 56 def os2; @os2 ||= OS2.new(os2_table); end |
#os2_table ⇒ Object
41 |
# File 'lib/pdfrb/font/true_type/file.rb', line 41 def os2_table; table("OS/2"); end |
#post ⇒ Object
50 |
# File 'lib/pdfrb/font/true_type/file.rb', line 50 def post; @post ||= Post.new(post_table); end |
#post_table ⇒ Object
40 |
# File 'lib/pdfrb/font/true_type/file.rb', line 40 def post_table; table("post"); end |
#table(tag) ⇒ Object
23 24 25 26 27 28 29 30 31 32 |
# File 'lib/pdfrb/font/true_type/file.rb', line 23 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 |