Class: Fontisan::Woff2::Directory::Entry
- Inherits:
-
Object
- Object
- Fontisan::Woff2::Directory::Entry
- 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
-
#flags ⇒ Object
Calculated during encoding.
-
#offset ⇒ Object
Calculated during encoding.
-
#orig_length ⇒ Object
Calculated during encoding.
-
#tag ⇒ Object
Calculated during encoding.
-
#transform_length ⇒ Object
Calculated during encoding.
Instance Method Summary collapse
-
#calculate_flags ⇒ Integer
Calculate flags byte for this entry.
-
#determine_transform_version ⇒ Integer
Determine transformation version for this table.
-
#initialize ⇒ Entry
constructor
A new instance of Entry.
-
#known_tag? ⇒ Boolean
Check if table uses a known tag.
-
#serialized_size ⇒ Integer
Calculate size of this entry when serialized.
-
#tag_index ⇒ Integer
Get tag index from flags.
-
#transform_version ⇒ Integer
Get transformation version from flags.
-
#transformable? ⇒ Boolean
Check if table can be transformed (glyf, loca, hmtx).
-
#transformed? ⇒ Boolean
Check if table is transformed.
Constructor Details
#initialize ⇒ Entry
Returns a new instance of Entry.
69 70 71 72 73 74 75 |
# File 'lib/fontisan/woff2/directory.rb', line 69 def initialize @tag = nil @flags = 0 @orig_length = 0 @transform_length = nil @offset = 0 end |
Instance Attribute Details
#flags ⇒ Object
Calculated during encoding
67 68 69 |
# File 'lib/fontisan/woff2/directory.rb', line 67 def flags @flags end |
#offset ⇒ Object
Calculated during encoding
67 68 69 |
# File 'lib/fontisan/woff2/directory.rb', line 67 def offset @offset end |
#orig_length ⇒ Object
Calculated during encoding
67 68 69 |
# File 'lib/fontisan/woff2/directory.rb', line 67 def orig_length @orig_length end |
#tag ⇒ Object
Calculated during encoding
67 68 69 |
# File 'lib/fontisan/woff2/directory.rb', line 67 def tag @tag end |
#transform_length ⇒ Object
Calculated during encoding
67 68 69 |
# File 'lib/fontisan/woff2/directory.rb', line 67 def transform_length @transform_length end |
Instance Method Details
#calculate_flags ⇒ Integer
Calculate flags byte for this entry
80 81 82 83 84 85 86 |
# File 'lib/fontisan/woff2/directory.rb', line 80 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_version ⇒ Integer
Determine transformation version for this table
Returns the appropriate version based on:
-
Whether table has transform_length set (is transformed)
-
Which table it is (glyf/loca vs hmtx vs other)
123 124 125 126 127 128 129 130 131 132 133 134 135 136 137 138 139 140 141 142 143 144 145 146 147 148 149 150 |
# File 'lib/fontisan/woff2/directory.rb', line 123 def determine_transform_version if transformed? # Table IS transformed - use appropriate transform version case tag when "glyf", "loca" TRANSFORM_GLYF_LOCA # Version 0 for transformed glyf/loca when "hmtx" TRANSFORM_HMTX # Version 1 for transformed hmtx else TRANSFORM_NONE # Shouldn't happen, but use safe default end else # Table is NOT transformed - use version that indicates no transformation case tag when "glyf", "loca" # For glyf/loca, version 0 means transformed # so use version 3 to indicate NOT transformed TRANSFORM_NONE # Version 3 when "hmtx" # For hmtx, version 1 means transformed # so use version 0 to indicate NOT transformed 0 else # All other tables use version 0 (no transformation) 0 end end end |
#known_tag? ⇒ Boolean
Check if table uses a known tag
91 92 93 |
# File 'lib/fontisan/woff2/directory.rb', line 91 def known_tag? KNOWN_TAGS.include?(tag) end |
#serialized_size ⇒ Integer
Calculate size of this entry when serialized
162 163 164 165 166 167 168 |
# File 'lib/fontisan/woff2/directory.rb', line 162 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_index ⇒ Integer
Get tag index from flags
112 113 114 |
# File 'lib/fontisan/woff2/directory.rb', line 112 def tag_index flags & 0x3F end |
#transform_version ⇒ Integer
Get transformation version from flags
105 106 107 |
# File 'lib/fontisan/woff2/directory.rb', line 105 def transform_version (flags >> 6) & 0x03 end |
#transformable? ⇒ Boolean
Check if table can be transformed (glyf, loca, hmtx)
155 156 157 |
# File 'lib/fontisan/woff2/directory.rb', line 155 def transformable? %w[glyf loca hmtx].include?(tag) end |
#transformed? ⇒ Boolean
Check if table is transformed
98 99 100 |
# File 'lib/fontisan/woff2/directory.rb', line 98 def transformed? !transform_length.nil? && transform_length.positive? end |