Class: HexaPDF::Font::TrueType::Table::Glyf

Inherits:
HexaPDF::Font::TrueType::Table show all
Defined in:
lib/hexapdf/font/true_type/table/glyf.rb

Overview

The ‘glyf’ table contains the instructions for rendering glyphs and some additional glyph information.

This is probably always the largest table in a TrueType font, so care is taken to perform operations lazily.

See: developer.apple.com/fonts/TrueType-Reference-Manual/RM06/Chap6glyf.html

Defined Under Namespace

Classes: Glyph

Constant Summary

Constants inherited from HexaPDF::Font::TrueType::Table

TIME_EPOCH

Instance Attribute Summary collapse

Attributes inherited from HexaPDF::Font::TrueType::Table

#font

Instance Method Summary collapse

Methods inherited from HexaPDF::Font::TrueType::Table

calculate_checksum, #checksum_valid?, #directory_entry, #initialize

Constructor Details

This class inherits a constructor from HexaPDF::Font::TrueType::Table

Instance Attribute Details

#glyphsObject

The mapping from glyph ID to Glyph object or nil (if the glyph has no outline).



128
129
130
# File 'lib/hexapdf/font/true_type/table/glyf.rb', line 128

def glyphs
  @glyphs
end

Instance Method Details

#[](glyph_id) ⇒ Object

Returns the Glyph object for the given glyph ID, or nil if it has no outline (e.g. the space character).



132
133
134
135
136
137
138
139
140
141
142
143
144
145
146
147
148
# File 'lib/hexapdf/font/true_type/table/glyf.rb', line 132

def [](glyph_id)
  if @glyphs.key?(glyph_id)
    return @glyphs[glyph_id]
  elsif !directory_entry
    return nil
  end

  offset = font[:loca].offset(glyph_id)
  length = font[:loca].length(glyph_id)

  if length == 0
    @glyphs[glyph_id] = Glyph.new('')
  else
    raw_data = with_io_pos(directory_entry.offset + offset) { io.read(length) }
    @glyphs[glyph_id] = Glyph.new(raw_data)
  end
end