Class: TTFunk::Table

Inherits:
Object
  • Object
show all
Includes:
Reader
Defined in:
lib/ttfunk/table.rb,
lib/ttfunk/table/cff.rb,
lib/ttfunk/table/os2.rb,
lib/ttfunk/table/cmap.rb,
lib/ttfunk/table/dsig.rb,
lib/ttfunk/table/glyf.rb,
lib/ttfunk/table/head.rb,
lib/ttfunk/table/hhea.rb,
lib/ttfunk/table/hmtx.rb,
lib/ttfunk/table/kern.rb,
lib/ttfunk/table/loca.rb,
lib/ttfunk/table/maxp.rb,
lib/ttfunk/table/name.rb,
lib/ttfunk/table/post.rb,
lib/ttfunk/table/sbix.rb,
lib/ttfunk/table/vorg.rb,
lib/ttfunk/table/simple.rb,
lib/ttfunk/table/cff/dict.rb,
lib/ttfunk/table/cff/path.rb,
lib/ttfunk/table/cff/index.rb,
lib/ttfunk/table/cff/header.rb,
lib/ttfunk/table/cff/charset.rb,
lib/ttfunk/table/glyf/simple.rb,
lib/ttfunk/table/cff/charsets.rb,
lib/ttfunk/table/cff/encoding.rb,
lib/ttfunk/table/cff/top_dict.rb,
lib/ttfunk/table/kern/format0.rb,
lib/ttfunk/table/cff/encodings.rb,
lib/ttfunk/table/cff/font_dict.rb,
lib/ttfunk/table/cff/top_index.rb,
lib/ttfunk/table/cmap/format00.rb,
lib/ttfunk/table/cmap/format04.rb,
lib/ttfunk/table/cmap/format06.rb,
lib/ttfunk/table/cmap/format10.rb,
lib/ttfunk/table/cmap/format12.rb,
lib/ttfunk/table/cmap/subtable.rb,
lib/ttfunk/table/glyf/compound.rb,
lib/ttfunk/table/post/format10.rb,
lib/ttfunk/table/post/format20.rb,
lib/ttfunk/table/post/format30.rb,
lib/ttfunk/table/post/format40.rb,
lib/ttfunk/table/cff/charstring.rb,
lib/ttfunk/table/cff/font_index.rb,
lib/ttfunk/table/cff/subr_index.rb,
lib/ttfunk/table/cff/fd_selector.rb,
lib/ttfunk/table/glyf/path_based.rb,
lib/ttfunk/table/cff/private_dict.rb,
lib/ttfunk/table/cff/charsets/expert.rb,
lib/ttfunk/table/cff/one_based_index.rb,
lib/ttfunk/table/cff/encodings/expert.rb,
lib/ttfunk/table/cff/charstrings_index.rb,
lib/ttfunk/table/cff/charsets/iso_adobe.rb,
lib/ttfunk/table/cff/encodings/standard.rb,
lib/ttfunk/table/cff/charsets/expert_subset.rb,
lib/ttfunk/table/cff/charsets/standard_strings.rb

Overview

SFNT table

Direct Known Subclasses

Cff, Cmap, Dsig, Glyf, Head, Hhea, Hmtx, Kern, Loca, Maxp, Name, OS2, Post, Sbix, Simple, Vorg

Defined Under Namespace

Classes: Cff, Cmap, Dsig, Glyf, Head, Hhea, Hmtx, Kern, Loca, Maxp, Name, OS2, Post, Sbix, Simple, Vorg

Instance Attribute Summary collapse

Instance Method Summary collapse

Constructor Details

#initialize(file) ⇒ Table

Returns a new instance of Table.

Parameters:



23
24
25
26
27
28
29
30
31
32
33
34
35
36
# File 'lib/ttfunk/table.rb', line 23

def initialize(file)
  @file = file
  @offset = nil
  @length = nil

  info = file.directory_info(tag)

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

    parse_from(@offset) { parse! }
  end
end

Instance Attribute Details

#fileTTFunk::File (readonly)

File this table is in.

Returns:



12
13
14
# File 'lib/ttfunk/table.rb', line 12

def file
  @file
end

#lengthInteger? (readonly)

This table’s length in byes.

Returns:

  • (Integer, nil)


20
21
22
# File 'lib/ttfunk/table.rb', line 20

def length
  @length
end

#offsetInteger (readonly)

This table’s offset from the file beginning.

Returns:

  • (Integer)


16
17
18
# File 'lib/ttfunk/table.rb', line 16

def offset
  @offset
end

Instance Method Details

#exists?Boolean

Does this table exist in the file?

Returns:

  • (Boolean)


41
42
43
# File 'lib/ttfunk/table.rb', line 41

def exists?
  !@offset.nil?
end

#rawString?

Raw bytes of this table in the file.

Returns:

  • (String, nil)


48
49
50
51
52
# File 'lib/ttfunk/table.rb', line 48

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

#tagString

Table tag.

Returns:

  • (String)


57
58
59
# File 'lib/ttfunk/table.rb', line 57

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