Module: Fontisan::Ufo::Compile::GlyfLoca
- Defined in:
- lib/fontisan/ufo/compile/glyf_loca.rb
Overview
Builds the TrueType glyf + loca tables. Each glyph's
outline is delta-encoded into the glyf table; loca is the
offset index.
For OTF output this module is NOT used — CFF takes its place.
Constant Summary collapse
- FLAG_ON_CURVE =
Flag bits (simple glyph)
0x01- FLAG_X_SHORT =
0x02- FLAG_Y_SHORT =
0x04- FLAG_REPEAT =
0x08- FLAG_X_IS_POSITIVE =
only meaningful if FLAG_X_SHORT
0x10- FLAG_Y_IS_POSITIVE =
only meaningful if FLAG_Y_SHORT
0x20- FLAG_OVERLAP_SIMPLE =
0x40
Class Method Summary collapse
-
.build(_font, glyphs:) ⇒ Hash<String, String>
=> bytes, "loca" => bytes.
Class Method Details
.build(_font, glyphs:) ⇒ Hash<String, String>
Returns => bytes, "loca" => bytes.
25 26 27 28 29 30 31 32 33 34 35 36 37 38 39 40 41 42 43 44 45 |
# File 'lib/fontisan/ufo/compile/glyf_loca.rb', line 25 def self.build(_font, glyphs:) glyf_bytes = +"" offsets = [0] glyphs.each do |glyph| glyf_bytes << encode_glyph(glyph) glyf_bytes << "\x00" while glyf_bytes.bytesize.odd? # 2-byte align offsets << glyf_bytes.bytesize end # Choose loca format based on the largest offset. use_long = offsets.max > 0x1FFFE # 2 × uint16 max loca_bytes = if use_long offsets.pack("N*") else offsets.map { |o| o / 2 }.pack("n*") end { "glyf" => glyf_bytes, "loca" => loca_bytes, :loca_format => use_long ? 1 : 0 } end |