File: table.rb

package info (click to toggle)
ruby-ttfunk 1.0.3%2Bdfsg-1
  • links: PTS, VCS
  • area: main
  • in suites: wheezy
  • size: 916 kB
  • sloc: ruby: 1,719; makefile: 16
file content (46 lines) | stat: -rw-r--r-- 680 bytes parent folder | download
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
require 'ttfunk/reader'

module TTFunk
  class Table
    include Reader

    attr_reader :file
    attr_reader :offset
    attr_reader :length

    def initialize(file)
      @file = file

      info = file.directory_info(tag)

      if info
        @offset = info[:offset]
        @length = info[:length]

        parse_from(@offset) { parse! }
      end
    end

    def exists?
      !@offset.nil?
    end

    def raw
      if exists?
        parse_from(offset) { io.read(length) }
      else
        nil
      end
    end

    def tag
      self.class.name.split(/::/).last.downcase
    end

    private

      def parse!
        # do nothing, by default
      end
  end
end