Class: Fontisan::Woff2::GlyfLocaReconstruct
- Inherits:
-
Object
- Object
- Fontisan::Woff2::GlyfLocaReconstruct
- Defined in:
- lib/fontisan/woff2/glyf_loca_reconstruct.rb
Overview
Reconstructs glyf and loca tables from the WOFF2 transformed glyf stream per spec section 5.1. This is the decoder counterpart of GlyfLocaTransform.
The transformed glyf table is split into 7 streams preceded by a 36-byte header (uint16 version + uint16 optionFlags + uint16 numGlyphs
- uint16 indexFormat + 7 × uint32 stream sizes). An optional overlapSimpleBitmap follows when optionFlags bit 0 is set.
Reference: W3C WOFF2 spec, section 5.1.
Constant Summary collapse
- FLAG_ON_CURVE =
TrueType simple-glyph flag bits per OpenType spec.
0x01- FLAG_X_SHORT =
0x02- FLAG_Y_SHORT =
0x04- FLAG_REPEAT =
0x08- FLAG_X_SAME_OR_POS =
0x10- FLAG_Y_SAME_OR_POS =
0x20- FLAG_OVERLAP_SIMPLE =
0x40- ARG_1_AND_2_ARE_WORDS =
TrueType composite-glyph flag bits.
0x0001- WE_HAVE_A_SCALE =
0x0008- MORE_COMPONENTS =
0x0020- WE_HAVE_AN_X_AND_Y_SCALE =
0x0040- WE_HAVE_A_TWO_BY_TWO =
0x0080- WE_HAVE_INSTRUCTIONS =
0x0100- HEADER_SIZE =
8-byte header + 7 × 4-byte stream sizes.
36
Instance Attribute Summary collapse
-
#index_format ⇒ Object
readonly
Returns the value of attribute index_format.
-
#num_glyphs ⇒ Object
readonly
Returns the value of attribute num_glyphs.
Instance Method Summary collapse
-
#initialize(transformed_glyf:, num_glyphs:, index_format:) ⇒ GlyfLocaReconstruct
constructor
A new instance of GlyfLocaReconstruct.
-
#reconstruct ⇒ Hash{Symbol => String}
Reconstruct glyf and loca tables.
Constructor Details
#initialize(transformed_glyf:, num_glyphs:, index_format:) ⇒ GlyfLocaReconstruct
Returns a new instance of GlyfLocaReconstruct.
43 44 45 46 47 |
# File 'lib/fontisan/woff2/glyf_loca_reconstruct.rb', line 43 def initialize(transformed_glyf:, num_glyphs:, index_format:) @data = transformed_glyf @num_glyphs = num_glyphs @index_format = index_format end |
Instance Attribute Details
#index_format ⇒ Object (readonly)
Returns the value of attribute index_format.
38 39 40 |
# File 'lib/fontisan/woff2/glyf_loca_reconstruct.rb', line 38 def index_format @index_format end |
#num_glyphs ⇒ Object (readonly)
Returns the value of attribute num_glyphs.
38 39 40 |
# File 'lib/fontisan/woff2/glyf_loca_reconstruct.rb', line 38 def num_glyphs @num_glyphs end |
Instance Method Details
#reconstruct ⇒ Hash{Symbol => String}
Reconstruct glyf and loca tables.
52 53 54 55 56 57 58 59 60 61 62 63 64 65 66 |
# File 'lib/fontisan/woff2/glyf_loca_reconstruct.rb', line 52 def reconstruct header = parse_header streams = read_streams(header) glyf = String.new(encoding: Encoding::BINARY) offsets = [0] num_glyphs.times do |glyph_id| glyph = decode_glyph(glyph_id, streams) glyf << glyph offsets << glyf.bytesize end { glyf:, loca: build_loca(offsets) } end |