Class: Fontisan::Subset::Profile

Inherits:
Object
  • Object
show all
Defined in:
lib/fontisan/subset/profile.rb

Overview

Subsetting profiles

This class manages font subsetting profiles that specify which font tables should be included in the subset. Profiles are loaded from an external YAML configuration file for flexibility and maintainability.

Examples:

Get tables for PDF profile

tables = Fontisan::Subset::Profile.for_name("pdf")
# => ["cmap", "head", "hhea", "hmtx", "maxp", "name", "post", "loca", "glyf"]

Get tables for web profile

tables = Fontisan::Subset::Profile.for_name("web")
# => ["cmap", "head", "hhea", "hmtx", "maxp", "name", "OS/2", "post", "loca", "glyf"]

Create custom profile

tables = Fontisan::Subset::Profile.custom(["cmap", "head", "hhea"])
# => ["cmap", "head", "hhea"]

Constant Summary collapse

KNOWN_TABLES =

All known font table tags

Comprehensive list of all standard TrueType/OpenType tables

%w[
  cmap head hhea hmtx maxp name OS/2 post
  loca glyf cvt fpgm prep gasp
  GSUB GPOS GDEF BASE JSTF
  CFF CFF2 VORG
  EBDT EBLC EBSC
  CBDT CBLC sbix
  kern vhea vmtx
  LTSH PCLT VDMX hdmx
  fvar gvar avar cvar HVAR VVAR MVAR STAT
  DSIG
].freeze

Class Method Summary collapse

Class Method Details

.custom(tables) ⇒ Array<String>

Create a custom profile with specified tables

Validates that all provided table tags are recognized and returns the list of tables in a consistent format.

Examples:

Create custom profile

Profile.custom(["cmap", "head", "glyf"])
# => ["cmap", "head", "glyf"]

Invalid table raises error

Profile.custom(["cmap", "invalid"])
# => ArgumentError: Unknown table tags: invalid

Parameters:

  • tables (Array<String>)

    array of table tags

Returns:

  • (Array<String>)

    validated array of table tags

Raises:

  • (ArgumentError)

    if any table tag is unknown



79
80
81
82
83
84
85
86
87
88
89
# File 'lib/fontisan/subset/profile.rb', line 79

def custom(tables)
  tables = Array(tables)
  unknown = tables - KNOWN_TABLES

  unless unknown.empty?
    raise ArgumentError,
          "Unknown table tags: #{unknown.join(', ')}"
  end

  tables.dup
end

.description(name) ⇒ String?

Get profile description

Examples:

Profile.description("pdf")
# => "Minimal tables required for PDF font embedding"

Parameters:

  • name (String)

    profile name

Returns:

  • (String, nil)

    profile description or nil if not found



121
122
123
124
125
# File 'lib/fontisan/subset/profile.rb', line 121

def description(name)
  profiles = load_profiles
  profile_config = profiles[name.to_s.downcase]
  profile_config&.dig("description")
end

.for_name(name) ⇒ Array<String>

Get table list for a named profile

Examples:

Profile.for_name("pdf")
# => ["cmap", "head", "hhea", "hmtx", "maxp", "name", "post", "loca", "glyf"]

Parameters:

  • name (String)

    profile name (pdf, web, minimal, full)

Returns:

  • (Array<String>)

    array of table tags

Raises:

  • (ArgumentError)

    if profile name is unknown



51
52
53
54
55
56
57
58
59
60
61
# File 'lib/fontisan/subset/profile.rb', line 51

def for_name(name)
  profiles = load_profiles
  profile_config = profiles[name.to_s.downcase]

  unless profile_config
    raise ArgumentError,
          "Unknown profile '#{name}'. Valid profiles: #{valid_names.join(', ')}"
  end

  profile_config["tables"].dup
end

.known_table?(table) ⇒ Boolean

Check if a table tag is recognized

Examples:

Profile.known_table?("cmap") # => true
Profile.known_table?("invalid") # => false

Parameters:

  • table (String)

    table tag to check

Returns:

  • (Boolean)

    true if table is known



99
100
101
# File 'lib/fontisan/subset/profile.rb', line 99

def known_table?(table)
  KNOWN_TABLES.include?(table.to_s)
end

.valid_namesArray<String>

Get list of all valid profile names

Examples:

Profile.valid_names # => ["pdf", "web", "minimal", "full"]

Returns:

  • (Array<String>)

    array of profile names



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

def valid_names
  load_profiles.keys.sort
end