Class: Fontisan::Export::Exporter

Inherits:
Object
  • Object
show all
Defined in:
lib/fontisan/export/exporter.rb

Overview

Exporter orchestrates font export to YAML/JSON/TTX

Main entry point for exporting fonts to debugging formats. Handles table extraction, serialization, and metadata generation.

Examples:

Exporting a font to YAML

exporter = Exporter.new(font, "font.ttf")
export = exporter.export(format: :yaml)
File.write("font.yaml", export.to_yaml)

Exporting to TTX format

exporter = Exporter.new(font, "font.ttf")
ttx_xml = exporter.to_ttx
File.write("font.ttx", ttx_xml)

Selective table export

export = exporter.export(tables: ["head", "name", "cmap"])

Instance Method Summary collapse

Constructor Details

#initialize(font, source_path, options = {}) ⇒ Exporter

Initialize exporter

Parameters:

  • font (TrueTypeFont, OpenTypeFont)

    The font to export

  • source_path (String)

    Path to source font file

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

    Export options

Options Hash (options):

  • :binary_format (Symbol)

    Format for binary data (:hex or :base64)



35
36
37
38
39
40
# File 'lib/fontisan/export/exporter.rb', line 35

def initialize(font, source_path, options = {})
  @font = font
  @source_path = source_path
  @binary_format = options.fetch(:binary_format, :hex)
  @serializer = TableSerializer.new(binary_format: @binary_format)
end

Instance Method Details

#export(options = {}) ⇒ Models::FontExport, String

Export font to FontExport model

Parameters:

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

    Export options

Options Hash (options):

  • :tables (Array<String>)

    Specific tables to export (default: all)

  • :format (Symbol)

    Output format (:yaml, :json, or :ttx)

Returns:



48
49
50
51
52
53
54
55
56
# File 'lib/fontisan/export/exporter.rb', line 48

def export(options = {})
  format = options[:format] || :yaml

  if format == :ttx
    to_ttx(options)
  else
    export_to_model(options)
  end
end

#to_json(options = {}) ⇒ String

Export font and return as JSON string

Parameters:

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

    Export options

Returns:

  • (String)

    JSON representation



71
72
73
74
# File 'lib/fontisan/export/exporter.rb', line 71

def to_json(options = {})
  export_model = export_to_model(options)
  export_model.to_json
end

#to_ttx(options = {}) ⇒ String

Export font and return as TTX XML string

Uses model-based architecture with FontToTtx transformer and lutaml-model serialization.

Parameters:

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

    Export options

Options Hash (options):

  • :tables (Array<String>)

    Specific tables to export

  • :pretty (Boolean)

    Pretty-print XML (default: true)

  • :indent (Integer)

    Indentation spaces (default: 2)

Returns:

  • (String)

    TTX XML representation



86
87
88
89
90
91
92
93
94
95
96
# File 'lib/fontisan/export/exporter.rb', line 86

def to_ttx(options = {})
  # Use new model-based architecture
  transformer = Transformers::FontToTtx.new(@font)
  ttx_model = transformer.transform(options)

  # Let lutaml-model handle XML serialization
  ttx_model.to_xml(
    pretty: options.fetch(:pretty, true),
    indent: options.fetch(:indent, 2),
  )
end

#to_yaml(options = {}) ⇒ String

Export font and return as YAML string

Parameters:

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

    Export options

Returns:

  • (String)

    YAML representation



62
63
64
65
# File 'lib/fontisan/export/exporter.rb', line 62

def to_yaml(options = {})
  export_model = export_to_model(options)
  export_model.to_yaml
end