Module: Fontisan::Ufo::Compile::Sbix
- Defined in:
- lib/fontisan/ufo/compile/sbix.rb
Overview
Builds the OpenType sbix (Apple Bitmap) table.
sbix stores bitmap strikes (PNG/JPEG) at multiple sizes. Each strike is a set of glyph-to-bitmap mappings at a specific ppem and resolution.
Layout:
Header (8 bytes):
uint16 version (= 1)
uint16 flags
uint32 numStrikes
Offset32 strikeOffsets[numStrikes]
Strike (per ppem):
uint16 ppem
uint16 resolution (ppi)
Offset32 glyphDataOffsets[numGlyphs + 1]
Glyph Data (per glyph):
int16 originOffsetX
int16 originOffsetY
uint16 graphicType ("png " or "jpeg")
uint8 bitmapData[]
Constant Summary collapse
- VERSION =
1- PNG_TYPE =
"png "- JPEG_TYPE =
"jpeg"
Class Method Summary collapse
-
.build(strikes:, num_glyphs:) ⇒ String?
Sbix bytes, or nil if no strikes.
Class Method Details
.build(strikes:, num_glyphs:) ⇒ String?
Returns sbix bytes, or nil if no strikes.
41 42 43 44 45 46 47 48 49 50 51 52 53 54 55 56 57 58 59 |
# File 'lib/fontisan/ufo/compile/sbix.rb', line 41 def self.build(strikes:, num_glyphs:) return nil if strikes.nil? || strikes.empty? num_strikes = strikes.size header_size = 4 + 4 + (num_strikes * 4) # version + flags + offsets strike_bytes = strikes.map { |s| build_strike(s, num_glyphs) } io = +"" io << [VERSION, 0, num_strikes].pack("nnN") offset = header_size strike_bytes.each do |s| io << [offset].pack("N") offset += s.bytesize io << s end io end |