class TTFunk::Table::Sbix

Constants

BitmapData

Attributes

flags[R]
num_strikes[R]
strikes[R]
version[R]

Public Instance Methods

all_bitmap_data_for(glyph_id) click to toggle source
# File lib/ttfunk/table/sbix.rb, line 34
def all_bitmap_data_for(glyph_id)
  strikes.each_index.map do |strike_index|
    bitmap_data_for(glyph_id, strike_index)
  end.compact
end
bitmap_data_for(glyph_id, strike_index) click to toggle source
# File lib/ttfunk/table/sbix.rb, line 13
def bitmap_data_for(glyph_id, strike_index)
  strike = strikes[strike_index]
  return if strike.nil?

  glyph_offset = strike[:glyph_data_offset][glyph_id]
  next_glyph_offset = strike[:glyph_data_offset][glyph_id + 1]

  if glyph_offset && next_glyph_offset
    bytes = next_glyph_offset - glyph_offset
    if bytes > 0
      parse_from(offset + strike[:offset] + glyph_offset) do
        x, y, type = read(8, 's2A4')
        data = StringIO.new(io.read(bytes - 8))
        BitmapData.new(
          x, y, type, data, strike[:ppem], strike[:resolution]
        )
      end
    end
  end
end

Private Instance Methods

parse!() click to toggle source
# File lib/ttfunk/table/sbix.rb, line 42
def parse!
  @version, @flags, @num_strikes = read(8, 'n2N')
  strike_offsets = Array.new(num_strikes) { read(4, 'N').first }

  @strikes = strike_offsets.map do |strike_offset|
    parse_from(offset + strike_offset) do
      ppem, resolution = read(4, 'n2')
      data_offsets = Array.new(file.maximum_profile.num_glyphs + 1) do
        read(4, 'N').first
      end
      {
        ppem: ppem,
        resolution: resolution,
        offset: strike_offset,
        glyph_data_offset: data_offsets
      }
    end
  end
end