Class: Fontisan::Woff2::Directory::Entry

Inherits:
Object
  • Object
show all
Defined in:
lib/fontisan/woff2/directory.rb

Overview

WOFF2 Table Directory Entry

Represents a single table in the WOFF2 font with all metadata needed for decompression and reconstruction.

Instance Attribute Summary collapse

Instance Method Summary collapse

Constructor Details

#initializeEntry

Returns a new instance of Entry.



64
65
66
67
68
69
70
# File 'lib/fontisan/woff2/directory.rb', line 64

def initialize
  @tag = nil
  @flags = 0
  @orig_length = 0
  @transform_length = nil
  @offset = 0
end

Instance Attribute Details

#flagsObject

Calculated during encoding



62
63
64
# File 'lib/fontisan/woff2/directory.rb', line 62

def flags
  @flags
end

#offsetObject

Calculated during encoding



62
63
64
# File 'lib/fontisan/woff2/directory.rb', line 62

def offset
  @offset
end

#orig_lengthObject

Calculated during encoding



62
63
64
# File 'lib/fontisan/woff2/directory.rb', line 62

def orig_length
  @orig_length
end

#tagObject

Calculated during encoding



62
63
64
# File 'lib/fontisan/woff2/directory.rb', line 62

def tag
  @tag
end

#transform_lengthObject

Calculated during encoding



62
63
64
# File 'lib/fontisan/woff2/directory.rb', line 62

def transform_length
  @transform_length
end

Instance Method Details

#calculate_flagsInteger

Calculate flags byte for this entry

Returns:

  • (Integer)

    Flags byte (0-255)



75
76
77
78
79
80
81
# File 'lib/fontisan/woff2/directory.rb', line 75

def calculate_flags
  tag_index = KNOWN_TAGS.index(tag) || CUSTOM_TAG_INDEX
  transform_version = determine_transform_version

  # Combine tag index (bits 0-5) and transform version (bits 6-7)
  (transform_version << 6) | tag_index
end

#determine_transform_versionInteger

Determine if this table should be transformed

For Phase 2 Milestone 2.1, we support transformation flags but don’t implement the actual transformations yet.

Returns:

  • (Integer)

    Transform version



117
118
119
120
121
# File 'lib/fontisan/woff2/directory.rb', line 117

def determine_transform_version
  # For this milestone, we don't apply transformations
  # but we recognize which tables could be transformed
  TRANSFORM_NONE
end

#known_tag?Boolean

Check if table uses a known tag

Returns:

  • (Boolean)

    True if known tag



86
87
88
# File 'lib/fontisan/woff2/directory.rb', line 86

def known_tag?
  KNOWN_TAGS.include?(tag)
end

#serialized_sizeInteger

Calculate size of this entry when serialized

Returns:

  • (Integer)

    Size in bytes



133
134
135
136
137
138
139
# File 'lib/fontisan/woff2/directory.rb', line 133

def serialized_size
  size = 1 # flags byte
  size += 4 unless known_tag? # custom tag
  size += uint_base128_size(orig_length)
  size += uint_base128_size(transform_length) if transformed?
  size
end

#tag_indexInteger

Get tag index from flags

Returns:

  • (Integer)

    Tag index (0-63)



107
108
109
# File 'lib/fontisan/woff2/directory.rb', line 107

def tag_index
  flags & 0x3F
end

#transform_versionInteger

Get transformation version from flags

Returns:

  • (Integer)

    Transform version (0-3)



100
101
102
# File 'lib/fontisan/woff2/directory.rb', line 100

def transform_version
  (flags >> 6) & 0x03
end

#transformable?Boolean

Check if table can be transformed (glyf, loca, hmtx)

Returns:

  • (Boolean)

    True if transformable



126
127
128
# File 'lib/fontisan/woff2/directory.rb', line 126

def transformable?
  %w[glyf loca hmtx].include?(tag)
end

#transformed?Boolean

Check if table is transformed

Returns:

  • (Boolean)

    True if transformed



93
94
95
# File 'lib/fontisan/woff2/directory.rb', line 93

def transformed?
  transform_version != TRANSFORM_NONE && transform_length
end