Class: Fontisan::Variable::StaticFontBuilder

Inherits:
Object
  • Object
show all
Defined in:
lib/fontisan/variable/static_font_builder.rb

Overview

Builds static font instances from variable font data

This class takes a variable font and applied variation data, then constructs a complete static font by:

  1. Copying all non-variation tables unchanged

  2. Removing variation-specific tables (fvar, gvar, HVAR, etc.)

  3. Updating metric tables (hmtx, hhea) with varied values

  4. Updating head table’s modified timestamp

  5. Writing the complete static font binary

The result is a valid static font at the specified instance point.

Examples:

Build static font

builder = StaticFontBuilder.new(font)
static_binary = builder.build(varied_metrics, font_metrics)

Constant Summary collapse

VARIATION_TABLES =

Tables to remove from static font (variation-specific)

%w[fvar avar gvar cvar HVAR VVAR MVAR STAT].freeze

Instance Attribute Summary collapse

Instance Method Summary collapse

Constructor Details

#initialize(font) ⇒ StaticFontBuilder

Initialize the builder

Parameters:



33
34
35
36
# File 'lib/fontisan/variable/static_font_builder.rb', line 33

def initialize(font)
  @font = font
  @table_updater = TableUpdater.new
end

Instance Attribute Details

#table_updaterTableUpdater (readonly)

Returns Table updater instance.

Returns:



28
29
30
# File 'lib/fontisan/variable/static_font_builder.rb', line 28

def table_updater
  @table_updater
end

Instance Method Details

#build(varied_metrics = {}, font_metrics = {}, options = {}) ⇒ String

Build static font from varied data

Parameters:

  • varied_metrics (Hash<Integer, Hash>) (defaults to: {})

    Varied metrics by glyph ID { glyph_id => { advance_width: 500, lsb: 50 } }

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

    Varied font-level metrics { ascent: 2048, descent: -512, line_gap: 0 }

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

    Build options

Options Hash (options):

  • :update_modified (Boolean)

    Update head modified timestamp

Returns:

  • (String)

    Complete static font binary



47
48
49
50
51
52
53
54
55
56
# File 'lib/fontisan/variable/static_font_builder.rb', line 47

def build(varied_metrics = {}, font_metrics = {}, options = {})
  # Collect tables for static font
  tables = collect_tables(varied_metrics, font_metrics, options)

  # Detect sfnt version
  sfnt_version = detect_sfnt_version(tables)

  # Write font using FontWriter
  FontWriter.write_font(tables, sfnt_version: sfnt_version)
end

#build_to_file(output_path, varied_metrics = {}, font_metrics = {}, options = {}) ⇒ Integer

Build static font and write to file

Parameters:

  • output_path (String)

    Output file path

  • varied_metrics (Hash<Integer, Hash>) (defaults to: {})

    Varied metrics by glyph ID

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

    Varied font-level metrics

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

    Build options

Returns:

  • (Integer)

    Number of bytes written



65
66
67
68
69
# File 'lib/fontisan/variable/static_font_builder.rb', line 65

def build_to_file(output_path, varied_metrics = {}, font_metrics = {},
options = {})
  binary = build(varied_metrics, font_metrics, options)
  File.binwrite(output_path, binary)
end