vendor/ttfunk/lib/ttfunk/table.rb in prawn-0.3.0 vs vendor/ttfunk/lib/ttfunk/table.rb in prawn-0.4.0

- old
+ new

@@ -1,27 +1,46 @@ -require "ttfunk/table/directory" +require 'ttfunk/reader' -%w[cmap head hhea hmtx name kern maxp].each do |lib| - require "ttfunk/table/" + lib - TTFunk::File.has_table lib -end - module TTFunk class Table - def method_missing(*args, &block) - var = "@#{args.first}" - if instance_variables.map { |e| e.to_s }.include?(var) - instance_variable_get(var) + 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 - super + nil end end - - private - - def to_signed(n, length=16) - max = 2**length-1 - mid = 2**(length-1) - (n>=mid) ? -((n ^ max) + 1) : n + + def tag + self.class.name.split(/::/).last.downcase end + + private + + def parse! + # do nothing, by default + end end end