Module: Fontisan::Constants
- Defined in:
- lib/fontisan/constants.rb
Overview
Constants module containing immutable constant definitions for font file operations.
This module defines all magic numbers, version identifiers, and file format constants used throughout the fontisan gem. These values are based on the TrueType Collection, TrueType Font, and OpenType Font specifications.
Constant Summary collapse
- TTC_TAG =
TrueType Collection file signature tag. All valid TTC files must begin with this 4-byte tag.
"ttcf".b.freeze
- TTC_VERSION_1 =
TrueType Collection Version 1.0 identifier. Represents the original TTC format version.
0x00010000- TTC_VERSION_2 =
TrueType Collection Version 2.0 identifier. Represents the extended TTC format with digital signature support.
0x00020000- SFNT_VERSION_TRUETYPE =
SFNT version for TrueType fonts
0x00010000- SFNT_VERSION_OTTO =
SFNT version for OpenType fonts with CFF outlines ('OTTO')
0x4F54544F- SFNT_VERSION_TRUE =
Apple 'true' TrueType signature (alternate to 0x00010000). Bytes: 0x74 ('t') 0x72 ('r') 0x75 ('u') 0x65 ('e').
0x74727565- SFNT_TRUETYPE_MAGIC =
Four-byte file signatures used for content-based format detection. Pre-packed once here so format detection doesn't repack on every call.
"\x00\x01\x00\x00".b.freeze
- SFNT_TRUE_MAGIC =
packed SFNT_VERSION_TRUETYPE
"true".b.freeze
- SFNT_OTTO_MAGIC =
Apple legacy TrueType
"OTTO".b.freeze
- WOFF_MAGIC =
OpenType / CFF
"wOFF".b.freeze
- WOFF2_MAGIC =
"wOF2".b.freeze
- DFONT_RESOURCE_HEADER =
dfont resource fork signatures. Note: bytes differ from SFNT_TRUETYPE_MAGIC despite the visual similarity — dfont is "\x00\x00\x01\x00" (resource-data offset 256, big-endian), SFNT_TRUETYPE_MAGIC is "\x00\x01\x00\x00" (sfnt version 0x00010000).
"\x00\x00\x01\x00".b.freeze
- SFNT_RESOURCE_TYPE =
"sfnt"- FOND_RESOURCE_TYPE =
"FOND"- HEAD_TAG =
Head table tag identifier. The 'head' table contains global font header information including the checksum adjustment field.
"head"- HHEA_TAG =
Hhea table tag identifier (Horizontal Header)
"hhea"- HMTX_TAG =
Hmtx table tag identifier (Horizontal Metrics)
"hmtx"- MAXP_TAG =
Maxp table tag identifier (Maximum Profile)
"maxp"- NAME_TAG =
Name table tag identifier
"name"- OS2_TAG =
OS/2 table tag identifier
"OS/2"- POST_TAG =
Post table tag identifier
"post"- CMAP_TAG =
Cmap table tag identifier
"cmap"- GLYF_TAG =
Glyf table tag identifier (TrueType glyph data)
"glyf"- LOCA_TAG =
Loca table tag identifier (TrueType glyph index to location)
"loca"- CFF_TAG =
CFF table tag identifier (OpenType CFF glyph data)
"CFF "- GSUB_TAG =
GSUB table tag identifier (Glyph Substitution)
"GSUB"- GPOS_TAG =
GPOS table tag identifier (Glyph Positioning)
"GPOS"- FVAR_TAG =
Fvar table tag identifier (Font Variations)
"fvar"- AVAR_TAG =
Avar table tag identifier (Axis Variation)
"avar"- GVAR_TAG =
Gvar table tag identifier (Glyph Variations for TrueType)
"gvar"- HVAR_TAG =
HVAR table tag identifier (Horizontal Metrics Variations)
"HVAR"- MVAR_TAG =
MVAR table tag identifier (Metrics Variations)
"MVAR"- VVAR_TAG =
VVAR table tag identifier (Vertical Metrics Variations)
"VVAR"- CVAR_TAG =
Cvar table tag identifier (CVT Variations)
"cvar"- CFF2_TAG =
CFF2 table tag identifier (CFF version 2 with variations)
"CFF2"- PFB_ASCII_CHUNK =
Adobe Type 1 font format constants PFB (Printer Font Binary) chunk markers
0x8001- PFB_BINARY_CHUNK =
0x8002- PFA_SIGNATURE_ADOBE_1_0 =
PFA (Printer Font ASCII) file signatures
"%!PS-AdobeFont-1.0"- PFA_SIGNATURE_ADOBE_3_0 =
"%!PS-Adobe-3.0 Resource-Font"- TYPE1_SEAC_ESCAPE =
Type 1 CharString operators
6- FPGM_TAG =
TrueType hinting tables Font Program table (TrueType bytecode executed once at font load)
"fpgm"- PREP_TAG =
Control Value Program table (TrueType bytecode for initialization)
"prep"- CVT_TAG =
Control Value Table (metrics used by TrueType hinting)
"cvt "- GASP_TAG =
Grid-fitting And Scan-conversion Procedure table (per-ppem hinting policy)
"gasp"- COLR_TAG =
Color font tables. COLR: COLR vector color glyph table (v0 or v1). CPAL: Color Palette table. SVG: SVG-in-OpenType color glyph table (tag is "SVG " — 4 bytes incl. trailing space). CBDT/CBLC: Color Bitmap Data / Location (paired — EBLC/EBDT equivalents for color). sbix: Apple bitmap glyph table.
"COLR"- CPAL_TAG =
"CPAL"- SVG_TAG =
"SVG "- CBDT_TAG =
"CBDT"- CBLC_TAG =
"CBLC"- SBIX_TAG =
"sbix"- CHECKSUM_ADJUSTMENT_MAGIC =
Magic number used for font file checksum adjustment calculation. This constant is used in conjunction with the file checksum to compute the checksumAdjustment value stored in the 'head' table. Formula: checksumAdjustment = CHECKSUM_ADJUSTMENT_MAGIC - file_checksum
0xB1B0AFBA- SUPPORTED_VERSIONS =
Supported TTC version numbers. An array of valid version identifiers for TrueType Collection files.
[TTC_VERSION_1, TTC_VERSION_2].freeze
- TABLE_ALIGNMENT =
Table data alignment boundary in bytes. All table data in TTF files must be aligned to 4-byte boundaries, with padding added as necessary.
4- STRING_POOL =
Common font subfamily names for string interning
These strings are frozen and reused to reduce memory allocations when parsing fonts with common subfamily names.
{ "Regular" => "Regular", "Bold" => "Bold", "Italic" => "Italic", "Bold Italic" => "Bold Italic", "BoldItalic" => "BoldItalic", "Light" => "Light", "Medium" => "Medium", "Semibold" => "Semibold", "SemiBold" => "SemiBold", "Black" => "Black", "Thin" => "Thin", "ExtraLight" => "ExtraLight", "Extra Light" => "Extra Light", "ExtraBold" => "ExtraBold", "Extra Bold" => "Extra Bold", "Heavy" => "Heavy", "Book" => "Book", "Roman" => "Roman", "Normal" => "Normal", "Oblique" => "Oblique", "Light Italic" => "Light Italic", "Medium Italic" => "Medium Italic", "Semibold Italic" => "Semibold Italic", "Bold Oblique" => "Bold Oblique", }.freeze
Class Method Summary collapse
-
.intern_string(str) ⇒ String
Intern a string using the string pool.
-
.sfnt_format_for(signature) ⇒ Symbol?
Classify a 4-byte SFNT-style signature read from a font file's magic.
Class Method Details
.intern_string(str) ⇒ String
Intern a string using the string pool
If the string is in the pool, returns the pooled instance. Otherwise, freezes and returns the original string.
204 205 206 |
# File 'lib/fontisan/constants.rb', line 204 def self.intern_string(str) STRING_POOL[str] || str.freeze end |
.sfnt_format_for(signature) ⇒ Symbol?
Classify a 4-byte SFNT-style signature read from a font file's magic.
212 213 214 215 216 217 |
# File 'lib/fontisan/constants.rb', line 212 def self.sfnt_format_for(signature) case signature when SFNT_TRUETYPE_MAGIC, SFNT_TRUE_MAGIC then :ttf when SFNT_OTTO_MAGIC then :otf end end |