Class: Fontisan::Tables::Head

Inherits:
Binary::BaseRecord show all
Defined in:
lib/fontisan/tables/head.rb

Overview

BinData structure for the ‘head’ (Font Header) table

The head table contains global information about the font, including metadata about the font file, bounding box, and indexing information.

Reference: OpenType specification, head table

Examples:

Reading a head table

data = File.binread("font.ttf", 54, head_offset)
head = Fontisan::Tables::Head.read(data)
puts head.units_per_em  # => 2048
puts head.version_number  # => 1.0

Constant Summary collapse

MAGIC_NUMBER =

Magic number that must be present in the head table

0x5F0F3CF5

Instance Method Summary collapse

Methods inherited from Binary::BaseRecord

#raw_data, read

Instance Method Details

#createdTime

Convert created timestamp to Time object

Returns:

  • (Time)

    Creation time



67
68
69
# File 'lib/fontisan/tables/head.rb', line 67

def created
  longdatetime_to_time(created_raw)
end

#font_revisionFloat

Convert font revision from fixed-point to float

Returns:

  • (Float)

    Font revision number



60
61
62
# File 'lib/fontisan/tables/head.rb', line 60

def font_revision
  fixed_to_float(font_revision_raw)
end

#modifiedTime

Convert modified timestamp to Time object

Returns:

  • (Time)

    Modification time



74
75
76
# File 'lib/fontisan/tables/head.rb', line 74

def modified
  longdatetime_to_time(modified_raw)
end

#valid?Boolean

Validate that the magic number is correct

Returns:

  • (Boolean)

    True if magic number is valid



81
82
83
# File 'lib/fontisan/tables/head.rb', line 81

def valid?
  magic_number == MAGIC_NUMBER
end

#validate_magic_number!Object Also known as: validate!

Validate magic number and raise error if invalid

Raises:



88
89
90
91
92
93
94
95
96
97
# File 'lib/fontisan/tables/head.rb', line 88

def validate_magic_number!
  return if valid?

  message = "Invalid magic number in head table: " \
            "expected 0x#{MAGIC_NUMBER.to_s(16).upcase}, " \
            "got 0x#{magic_number.to_s(16).upcase}"
  error = Fontisan::CorruptedTableError.new(message)
  error.set_backtrace(caller)
  Kernel.raise(error)
end

#versionFloat

Convert version from fixed-point to float

Returns:

  • (Float)

    Version number (e.g., 1.0)



53
54
55
# File 'lib/fontisan/tables/head.rb', line 53

def version
  fixed_to_float(version_raw)
end