Class: Fontisan::Subset::Options

Inherits:
Lutaml::Model::Serializable
  • Object
show all
Defined in:
lib/fontisan/subset/options.rb

Overview

Subsetting configuration class

This class defines all available options for font subsetting operations. It provides sensible defaults for various subsetting scenarios and uses Lutaml::Model for serialization support.

Examples:

Create default PDF subsetting options

options = Fontisan::Subset::Options.new
options.profile # => "pdf"
options.drop_hints # => false

Create custom web subsetting options

options = Fontisan::Subset::Options.new(
  profile: "web",
  drop_hints: true,
  unicode_ranges: false
)

Retain original glyph IDs

options = Fontisan::Subset::Options.new(retain_gids: true)

Instance Method Summary collapse

Constructor Details

#initialize(attributes = {}) ⇒ Options

Initialize options with custom values

Parameters:

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

    hash of attribute values

Options Hash (attributes):

  • :profile (String) — default: "pdf"

    subsetting profile

  • :drop_hints (Boolean) — default: false

    drop hinting

  • :drop_names (Boolean) — default: false

    drop glyph names

  • :unicode_ranges (Boolean) — default: true

    prune OS/2 ranges

  • :retain_gids (Boolean) — default: false

    retain glyph IDs

  • :include_notdef (Boolean) — default: true

    include .notdef

  • :include_null (Boolean) — default: false

    include .null

  • :features (Array<String>) — default: []

    features to keep

  • :scripts (Array<String>) — default: ["*"]

    scripts to keep



109
110
111
# File 'lib/fontisan/subset/options.rb', line 109

def initialize(attributes = {})
  super
end

Instance Method Details

#all_features?Boolean

Check if all features should be retained

Returns:

  • (Boolean)

    true if features array is empty



116
117
118
# File 'lib/fontisan/subset/options.rb', line 116

def all_features?
  features.empty?
end

#all_scripts?Boolean

Check if all scripts should be retained

Returns:

  • (Boolean)

    true if scripts contains “*”



123
124
125
# File 'lib/fontisan/subset/options.rb', line 123

def all_scripts?
  scripts.include?("*")
end

#drop_hintsBoolean

Whether to drop hinting instructions

Hinting improves text rendering at small sizes but increases file size. Web fonts typically don’t need hints due to modern rendering engines.

Returns:

  • (Boolean)

    true to drop hints, false to retain them



39
# File 'lib/fontisan/subset/options.rb', line 39

attribute :drop_hints, :boolean, default: -> { false }

#drop_namesBoolean

Whether to drop glyph names from the post table

Glyph names are useful for debugging but not required for rendering. Dropping them reduces file size.

Returns:

  • (Boolean)

    true to drop names, false to retain them



47
# File 'lib/fontisan/subset/options.rb', line 47

attribute :drop_names, :boolean, default: -> { false }

#featuresArray<String>

OpenType features to retain in the subset

An empty array means all features are retained. Specify feature tags (e.g., [‘liga’, ‘kern’]) to keep only those features.

Returns:

  • (Array<String>)

    array of feature tags to retain



87
# File 'lib/fontisan/subset/options.rb', line 87

attribute :features, :string, collection: true, default: -> { [] }

#include_notdefBoolean

Whether to include the .notdef glyph

The .notdef glyph is displayed for missing characters. It is typically required by font specifications.

Returns:

  • (Boolean)

    true to include .notdef, false to exclude



72
# File 'lib/fontisan/subset/options.rb', line 72

attribute :include_notdef, :boolean, default: -> { true }

#include_nullBoolean

Whether to include the .null glyph

The .null glyph (U+0000) is sometimes used for control purposes.

Returns:

  • (Boolean)

    true to include .null, false to exclude



79
# File 'lib/fontisan/subset/options.rb', line 79

attribute :include_null, :boolean, default: -> { false }

#profileString

Subsetting profile name (pdf, web, minimal, or custom)

Returns:

  • (String)

    the profile name



31
# File 'lib/fontisan/subset/options.rb', line 31

attribute :profile, :string, default: -> { "pdf" }

#retain_gidsBoolean

Whether to retain original glyph IDs

When true, removed glyphs leave empty slots in the glyf table, preserving original GID assignments. When false, glyphs are compacted to eliminate gaps.

Returns:

  • (Boolean)

    true to retain GIDs, false to compact



64
# File 'lib/fontisan/subset/options.rb', line 64

attribute :retain_gids, :boolean, default: -> { false }

#scriptsArray<String>

Script tags to retain in the subset

An array containing “*” means all scripts are retained. Specify script tags (e.g., [‘latn’, ‘arab’]) to keep only those scripts.

Returns:

  • (Array<String>)

    array of script tags to retain



95
# File 'lib/fontisan/subset/options.rb', line 95

attribute :scripts, :string, collection: true, default: -> { ["*"] }

#unicode_rangesBoolean

Whether to prune OS/2 Unicode ranges

Updates the OS/2 table’s Unicode range bits to reflect only the glyphs present in the subset.

Returns:

  • (Boolean)

    true to prune ranges, false to keep original



55
# File 'lib/fontisan/subset/options.rb', line 55

attribute :unicode_ranges, :boolean, default: -> { true }

#validate!Boolean

Validate the options configuration

Returns:

  • (Boolean)

    true if valid

Raises:

  • (ArgumentError)

    if profile is invalid



131
132
133
134
135
136
137
138
139
# File 'lib/fontisan/subset/options.rb', line 131

def validate!
  valid_profiles = %w[pdf web minimal custom]
  unless valid_profiles.include?(profile)
    raise ArgumentError,
          "Invalid profile '#{profile}'. Must be one of: #{valid_profiles.join(', ')}"
  end

  true
end