Class: TTFunk::Table::Sbix

Inherits:
TTFunk::Table show all
Defined in:
lib/ttfunk/table/sbix.rb

Overview

Standard Bitmap Graphics (‘sbix`) table.

Defined Under Namespace

Classes: BitmapData

Instance Attribute Summary collapse

Attributes inherited from TTFunk::Table

#file, #length, #offset

Instance Method Summary collapse

Methods inherited from TTFunk::Table

#exists?, #initialize, #raw, #tag

Constructor Details

This class inherits a constructor from TTFunk::Table

Instance Attribute Details

#flagsInteger (readonly)

Flags.

Returns:

  • (Integer)


15
16
17
# File 'lib/ttfunk/table/sbix.rb', line 15

def flags
  @flags
end

#num_strikesInteger (readonly)

Number of bitmap strikes.

Returns:

  • (Integer)


19
20
21
# File 'lib/ttfunk/table/sbix.rb', line 19

def num_strikes
  @num_strikes
end

#strikesArray<Hash> (readonly)

Strikes.

Returns:

  • (Array<Hash>)


23
24
25
# File 'lib/ttfunk/table/sbix.rb', line 23

def strikes
  @strikes
end

#versionInteger (readonly)

Table version.

Returns:

  • (Integer)


11
12
13
# File 'lib/ttfunk/table/sbix.rb', line 11

def version
  @version
end

Instance Method Details

#all_bitmap_data_for(glyph_id) ⇒ Array<BitmapData>

Get all bitmaps for glyph.

Parameters:

  • glyph_id (Integer)

Returns:



72
73
74
75
76
# File 'lib/ttfunk/table/sbix.rb', line 72

def all_bitmap_data_for(glyph_id)
  strikes.each_index.filter_map { |strike_index|
    bitmap_data_for(glyph_id, strike_index)
  }
end

#bitmap_data_for(glyph_id, strike_index) ⇒ BitmapData

Get bitmap for glyph strike.

Parameters:

  • glyph_id (Integer)
  • strike_index (Integer)

Returns:



49
50
51
52
53
54
55
56
57
58
59
60
61
62
63
64
65
66
# File 'lib/ttfunk/table/sbix.rb', line 49

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.positive?
      parse_from(offset + strike[:offset] + glyph_offset) {
        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