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

Inherits:
Table
  • Object
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: https://developer.apple.com/fonts/TrueType-Reference-Manual/RM06/Chap6glyf.html

Defined Under Namespace

Classes: Glyph

Instance Attribute Summary collapse

Instance Method Summary collapse

Instance Attribute Details

#glyphsObject

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



139
140
141
# File 'lib/hexapdf/font/true_type/table/glyf.rb', line 139

def glyphs
  @glyphs
end

Instance Method Details

#[](glyph_id) ⇒ Object

Returns the Glyph object for the given glyph ID. If the glyph has no outline (e.g. the space character), an empty Glyph object is returned.



143
144
145
146
147
148
149
150
151
152
153
154
155
# File 'lib/hexapdf/font/true_type/table/glyf.rb', line 143

def [](glyph_id)
  return @glyphs[glyph_id] if @glyphs.key?(glyph_id)

  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