Class: Fontisan::Export::TtxGenerator

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

Overview

TtxGenerator generates TTX XML format from font data

Generates fonttools-compatible TTX XML format for font debugging and interoperability. Handles various table types with appropriate XML structures per the TTX specification.

Examples:

Generating TTX from a font

generator = TtxGenerator.new(font, "font.ttf")
ttx_xml = generator.generate
File.write("font.ttx", ttx_xml)

Selective table generation

ttx_xml = generator.generate(tables: ["head", "name", "glyf"])

Instance Method Summary collapse

Constructor Details

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

Initialize TTX generator

Parameters:

  • font (TrueTypeFont, OpenTypeFont)

    The font to export

  • source_path (String)

    Path to source font file

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

    Generation options

Options Hash (options):

  • :pretty (Boolean)

    Pretty-print XML (default: true)

  • :indent (Integer)

    Indentation spaces (default: 2)



28
29
30
31
32
33
# File 'lib/fontisan/export/ttx_generator.rb', line 28

def initialize(font, source_path, options = {})
  @font = font
  @source_path = source_path
  @pretty = options.fetch(:pretty, true)
  @indent = options.fetch(:indent, 2)
end

Instance Method Details

#generate(options = {}) ⇒ String

Generate TTX XML

Parameters:

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

    Generation options

Options Hash (options):

  • :tables (Array<String>)

    Specific tables to include

Returns:

  • (String)

    TTX XML content



40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
# File 'lib/fontisan/export/ttx_generator.rb', line 40

def generate(options = {})
  table_list = options[:tables] || :all

  builder = Nokogiri::XML::Builder.new(encoding: "UTF-8") do |xml|
    xml.ttFont(
      "sfntVersion" => format_sfnt_version(to_int(@font.header.sfnt_version)),
      "ttLibVersion" => "4.0",
    ) do
      generate_glyph_order(xml)

      tables_to_generate = select_tables(table_list)
      tables_to_generate.each do |tag|
        generate_table(xml, tag)
      end
    end
  end

  format_output(builder.to_xml)
end