Class: Fontisan::Commands::DumpTableCommand

Inherits:
Object
  • Object
show all
Defined in:
lib/fontisan/commands/dump_table_command.rb

Overview

Command to dump raw table data from fonts

This command extracts the binary data of a specific OpenType table and outputs it directly. This is useful for examining table contents or extracting tables for external processing.

Instance Method Summary collapse

Constructor Details

#initialize(font_path, table_tag, options = {}) ⇒ DumpTableCommand

Initialize a new dump table command

Parameters:

  • font_path (String)

    Path to the font file

  • table_tag (String)

    Four-character table tag (e.g., 'name', 'head')

  • options (Hash) (defaults to: {})

    Optional command options

Options Hash (options):

  • :font_index (Integer)

    Index of font in TTC/OTC collection (default: 0)



17
18
19
20
21
22
# File 'lib/fontisan/commands/dump_table_command.rb', line 17

def initialize(font_path, table_tag, options = {})
  @font_path = font_path
  @table_tag = table_tag
  @options = options
  @font = load_font
end

Instance Method Details

#runString

Execute the dump table command

Returns:

  • (String)

    Raw binary table data

Raises:

  • (Error)

    if table does not exist or data is not available



28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
# File 'lib/fontisan/commands/dump_table_command.rb', line 28

def run
  unless @font.has_table?(@table_tag)
    raise Error,
          "Font does not have '#{@table_tag}' table"
  end

  # Get raw table data
  table_data = @font.instance_variable_get(:@table_data)
  raw_data = table_data[@table_tag]

  unless raw_data
    raise Error,
          "Table data not available for '#{@table_tag}'"
  end

  raw_data
end