Class: TTFunk::File
- Inherits:
-
Object
- Object
- TTFunk::File
- Defined in:
- lib/ttfunk.rb
Instance Attribute Summary collapse
-
#contents ⇒ Object
readonly
Returns the value of attribute contents.
-
#directory ⇒ Object
readonly
Returns the value of attribute directory.
Class Method Summary collapse
- .from_dfont(file, which = 0) ⇒ Object
- .open(io_or_path) ⇒ Object
- .verify_and_open(io_or_path) ⇒ Object
Instance Method Summary collapse
- #ascent ⇒ Object
- #bbox ⇒ Object
- #cmap ⇒ Object
- #descent ⇒ Object
- #directory_info(tag) ⇒ Object
- #glyph_locations ⇒ Object
- #glyph_outlines ⇒ Object
- #header ⇒ Object
- #horizontal_header ⇒ Object
- #horizontal_metrics ⇒ Object
-
#initialize(contents) ⇒ File
constructor
A new instance of File.
- #kerning ⇒ Object
- #line_gap ⇒ Object
- #maximum_profile ⇒ Object
- #name ⇒ Object
- #os2 ⇒ Object
- #postscript ⇒ Object
Constructor Details
Instance Attribute Details
#contents ⇒ Object (readonly)
Returns the value of attribute contents.
9 10 11 |
# File 'lib/ttfunk.rb', line 9 def contents @contents end |
#directory ⇒ Object (readonly)
Returns the value of attribute directory.
10 11 12 |
# File 'lib/ttfunk.rb', line 10 def directory @directory end |
Class Method Details
.from_dfont(file, which = 0) ⇒ Object
16 17 18 |
# File 'lib/ttfunk.rb', line 16 def self.from_dfont(file, which=0) new(ResourceFile.open(file) { |dfont| dfont["sfnt", which] }) end |
.open(io_or_path) ⇒ Object
12 13 14 |
# File 'lib/ttfunk.rb', line 12 def self.open(io_or_path) new verify_and_open(io_or_path).read end |
.verify_and_open(io_or_path) ⇒ Object
20 21 22 23 24 25 26 27 28 29 30 31 32 33 34 35 36 37 |
# File 'lib/ttfunk.rb', line 20 def self.verify_and_open(io_or_path) # File or IO if io_or_path.respond_to?(:rewind) io = io_or_path # Rewind if the object we're passed is an IO, so that multiple embeds of # the same IO object will work io.rewind # read the file as binary so the size is calculated correctly # guard binmode because some objects acting io-like don't implement it io.binmode if io.respond_to?(:binmode) return io end # String or Pathname io_or_path = Pathname.new(io_or_path) raise ArgumentError, "#{io_or_path} not found" unless io_or_path.file? io = io_or_path.open('rb') io end |
Instance Method Details
#ascent ⇒ Object
45 46 47 |
# File 'lib/ttfunk.rb', line 45 def ascent @ascent ||= (os2.exists? && os2.ascent && os2.ascent.nonzero?) || horizontal_header.ascent end |
#bbox ⇒ Object
57 58 59 |
# File 'lib/ttfunk.rb', line 57 def bbox [header.x_min, header.y_min, header.x_max, header.y_max] end |
#cmap ⇒ Object
70 71 72 |
# File 'lib/ttfunk.rb', line 70 def cmap @cmap ||= TTFunk::Table::Cmap.new(self) end |
#descent ⇒ Object
49 50 51 |
# File 'lib/ttfunk.rb', line 49 def descent @descent ||= (os2.exists? && os2.descent && os2.descent.nonzero?) || horizontal_header.descent end |
#directory_info(tag) ⇒ Object
62 63 64 |
# File 'lib/ttfunk.rb', line 62 def directory_info(tag) directory.tables[tag.to_s] end |
#glyph_locations ⇒ Object
102 103 104 |
# File 'lib/ttfunk.rb', line 102 def glyph_locations @glyph_locations ||= TTFunk::Table::Loca.new(self) end |
#glyph_outlines ⇒ Object
106 107 108 |
# File 'lib/ttfunk.rb', line 106 def glyph_outlines @glyph_outlines ||= TTFunk::Table::Glyf.new(self) end |
#header ⇒ Object
66 67 68 |
# File 'lib/ttfunk.rb', line 66 def header @header ||= TTFunk::Table::Head.new(self) end |
#horizontal_header ⇒ Object
74 75 76 |
# File 'lib/ttfunk.rb', line 74 def horizontal_header @horizontal_header ||= TTFunk::Table::Hhea.new(self) end |
#horizontal_metrics ⇒ Object
78 79 80 |
# File 'lib/ttfunk.rb', line 78 def horizontal_metrics @horizontal_metrics ||= TTFunk::Table::Hmtx.new(self) end |
#kerning ⇒ Object
86 87 88 |
# File 'lib/ttfunk.rb', line 86 def kerning @kerning ||= TTFunk::Table::Kern.new(self) end |
#line_gap ⇒ Object
53 54 55 |
# File 'lib/ttfunk.rb', line 53 def line_gap @line_gap ||= (os2.exists? && os2.line_gap && os2.line_gap.nonzero?) || horizontal_header.line_gap end |
#maximum_profile ⇒ Object
82 83 84 |
# File 'lib/ttfunk.rb', line 82 def maximum_profile @maximum_profile ||= TTFunk::Table::Maxp.new(self) end |
#name ⇒ Object
90 91 92 |
# File 'lib/ttfunk.rb', line 90 def name @name ||= TTFunk::Table::Name.new(self) end |