Module: Fontisan::Converters::Woff2Encoder::Woff2FontMemoryLoader
- Included in:
- Fontisan::Converters::Woff2Encoder
- Defined in:
- lib/fontisan/converters/woff2_encoder.rb
Overview
Helper method to load WOFF2 from StringIO
This is added to Woff2Font to support in-memory validation
Class Method Summary collapse
Class Method Details
.from_file_io(io, path_for_report) ⇒ Object
177 178 179 180 181 182 183 184 185 186 187 188 189 190 191 192 193 194 195 196 197 198 199 200 201 202 203 204 205 206 |
# File 'lib/fontisan/converters/woff2_encoder.rb', line 177 def self.from_file_io(io, path_for_report) io.rewind woff2 = Woff2Font.new woff2.io_source = Woff2Font::IOSource.new(path_for_report) # Read header woff2.header = Woff2::Woff2Header.read(io) # Validate signature unless woff2.header.signature == Woff2::Woff2Header::SIGNATURE raise InvalidFontError, "Invalid WOFF2 signature: expected 0x#{Woff2::Woff2Header::SIGNATURE.to_s(16)}, " \ "got 0x#{woff2.header.signature.to_i.to_s(16)}" end # Read table directory woff2.table_entries = Woff2Font.read_table_directory_from_io(io, woff2.header) # Decompress tables woff2.decompressed_tables = Woff2Font.decompress_tables(io, woff2.header, woff2.table_entries) # Apply transformations Woff2Font.apply_transformations!(woff2.table_entries, woff2.decompressed_tables) woff2 end |