Class: Fontisan::Tables::Cff::Header
- Inherits:
-
Binary::BaseRecord
- Object
- BinData::Record
- Binary::BaseRecord
- Fontisan::Tables::Cff::Header
- Defined in:
- lib/fontisan/tables/cff/header.rb
Overview
CFF Header structure
The CFF header appears at the beginning of the CFF table and contains basic version and structural information about the CFF data.
Structure (4 bytes minimum):
- uint8: major version (always 1 for CFF, 2 for CFF2)
- uint8: minor version (always 0)
- uint8: hdr_size (header size in bytes, typically 4)
- uint8: off_size (offset size used throughout CFF, 1-4 bytes)
Reference: CFF specification section 4 "Header" https://adobe-type-tools.github.io/font-tech-notes/pdfs/5176.CFF.pdf
Instance Method Summary collapse
-
#cff2? ⇒ Boolean
Check if this is a CFF2 header (variable CFF fonts).
-
#cff? ⇒ Boolean
Check if this is a valid CFF version 1.0 header.
-
#valid? ⇒ Boolean
Validate that the header has correct values.
-
#validate! ⇒ Object
Validate header and raise error if invalid.
-
#version ⇒ String
Get the version as a string.
Methods inherited from Binary::BaseRecord
Instance Method Details
#cff2? ⇒ Boolean
Check if this is a CFF2 header (variable CFF fonts)
53 54 55 |
# File 'lib/fontisan/tables/cff/header.rb', line 53 def cff2? major == 2 end |
#cff? ⇒ Boolean
Check if this is a valid CFF version 1.0 header
46 47 48 |
# File 'lib/fontisan/tables/cff/header.rb', line 46 def cff? major == 1 && minor.zero? end |
#valid? ⇒ Boolean
Validate that the header has correct values
67 68 69 70 71 72 73 74 75 76 77 78 79 80 81 |
# File 'lib/fontisan/tables/cff/header.rb', line 67 def valid? # Major version must be 1 or 2 return false unless [1, 2].include?(major) # Minor version must be 0 return false unless minor.zero? # Header size must be at least 4 bytes return false unless hdr_size >= 4 # Offset size must be between 1 and 4 return false unless (1..4).cover?(off_size) true end |
#validate! ⇒ Object
Validate header and raise error if invalid
86 87 88 89 90 91 92 93 94 95 96 |
# File 'lib/fontisan/tables/cff/header.rb', line 86 def validate! return if valid? = "Invalid CFF header: " \ "version=#{version}, " \ "hdr_size=#{hdr_size}, " \ "off_size=#{off_size}" error = Fontisan::CorruptedTableError.new() error.set_backtrace(caller) Kernel.raise(error) end |
#version ⇒ String
Get the version as a string
60 61 62 |
# File 'lib/fontisan/tables/cff/header.rb', line 60 def version "#{major}.#{minor}" end |