Module: Fontisan::LoadingModes
- Defined in:
- lib/fontisan/loading_modes.rb
Overview
Loading modes module that defines which tables are loaded in each mode.
This module provides a MECE (Mutually Exclusive, Collectively Exhaustive) architecture for font loading modes. Each mode defines a specific set of tables to load, enabling efficient parsing for different use cases.
Constant Summary collapse
- METADATA =
Metadata mode: loads only tables needed for font identification and metrics Equivalent to otfinfo functionality
:metadata- FULL =
Full mode: loads all tables in the font
:full- MODES =
Mode definitions with their respective table lists
{ METADATA => { tables: %w[name head hhea maxp OS/2 post].freeze, description: "Metadata mode - loads only identification and metrics tables (otfinfo-equivalent)", }.freeze, FULL => { tables: :all, description: "Full mode - loads all tables in the font", }.freeze, }.freeze
- METADATA_TABLES_SET =
Pre-computed Set for O(1) lookup of metadata tables This constant avoids recreating the Set on every font load
MODES[METADATA][:tables].to_set.freeze
Class Method Summary collapse
-
.all_modes ⇒ Array<Symbol>
Get all available modes.
-
.default_lazy?(mode) ⇒ Boolean
Get the default lazy loading setting for a mode.
-
.description(mode) ⇒ String
Get mode description.
-
.table_allowed?(mode, tag) ⇒ Boolean
Check if a table is allowed in a given mode.
-
.tables_for(mode) ⇒ Array<String>, Symbol
Get the list of tables allowed for a given mode.
-
.valid_mode?(mode) ⇒ Boolean
Validate that a mode is valid.
-
.validate_mode!(mode) ⇒ void
Validate mode and raise error if invalid.
Class Method Details
.all_modes ⇒ Array<Symbol>
Get all available modes
97 98 99 |
# File 'lib/fontisan/loading_modes.rb', line 97 def self.all_modes MODES.keys end |
.default_lazy?(mode) ⇒ Boolean
Get the default lazy loading setting for a mode
79 80 81 82 |
# File 'lib/fontisan/loading_modes.rb', line 79 def self.default_lazy?(mode) validate_mode!(mode) true # Lazy loading is recommended for all modes end |
.description(mode) ⇒ String
Get mode description
89 90 91 92 |
# File 'lib/fontisan/loading_modes.rb', line 89 def self.description(mode) validate_mode!(mode) MODES[mode][:description] end |
.table_allowed?(mode, tag) ⇒ Boolean
Check if a table is allowed in a given mode
57 58 59 60 61 62 63 64 |
# File 'lib/fontisan/loading_modes.rb', line 57 def self.table_allowed?(mode, tag) validate_mode!(mode) tables = MODES[mode][:tables] return true if tables == :all tables.include?(tag) end |
.tables_for(mode) ⇒ Array<String>, Symbol
Get the list of tables allowed for a given mode
46 47 48 49 |
# File 'lib/fontisan/loading_modes.rb', line 46 def self.tables_for(mode) validate_mode!(mode) MODES[mode][:tables] end |
.valid_mode?(mode) ⇒ Boolean
Validate that a mode is valid
70 71 72 |
# File 'lib/fontisan/loading_modes.rb', line 70 def self.valid_mode?(mode) MODES.key?(mode) end |
.validate_mode!(mode) ⇒ void
This method returns an undefined value.
Validate mode and raise error if invalid
106 107 108 109 110 111 |
# File 'lib/fontisan/loading_modes.rb', line 106 def self.validate_mode!(mode) return if valid_mode?(mode) raise ArgumentError, "Invalid mode: #{mode.inspect}. Valid modes are: #{all_modes.map(&:inspect).join(', ')}" end |