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 if this table should be transformed.
-
#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.
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
#flags ⇒ Object
Calculated during encoding
62 63 64 |
# File 'lib/fontisan/woff2/directory.rb', line 62 def flags @flags end |
#offset ⇒ Object
Calculated during encoding
62 63 64 |
# File 'lib/fontisan/woff2/directory.rb', line 62 def offset @offset end |
#orig_length ⇒ Object
Calculated during encoding
62 63 64 |
# File 'lib/fontisan/woff2/directory.rb', line 62 def orig_length @orig_length end |
#tag ⇒ Object
Calculated during encoding
62 63 64 |
# File 'lib/fontisan/woff2/directory.rb', line 62 def tag @tag end |
#transform_length ⇒ Object
Calculated during encoding
62 63 64 |
# File 'lib/fontisan/woff2/directory.rb', line 62 def transform_length @transform_length end |
Instance Method Details
#calculate_flags ⇒ Integer
Calculate flags byte for this entry
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_version ⇒ Integer
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.
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
86 87 88 |
# File 'lib/fontisan/woff2/directory.rb', line 86 def known_tag? KNOWN_TAGS.include?(tag) end |
#serialized_size ⇒ Integer
Calculate size of this entry when serialized
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_index ⇒ Integer
Get tag index from flags
107 108 109 |
# File 'lib/fontisan/woff2/directory.rb', line 107 def tag_index flags & 0x3F end |
#transform_version ⇒ Integer
Get transformation version from flags
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)
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
93 94 95 |
# File 'lib/fontisan/woff2/directory.rb', line 93 def transformed? transform_version != TRANSFORM_NONE && transform_length end |