Class: Ucode::Glyphs::Grid

Inherits:
Struct
  • Object
show all
Defined in:
lib/ucode/glyphs/grid.rb

Instance Attribute Summary collapse

Instance Method Summary collapse

Instance Attribute Details

#block_first_cpObject

Returns the value of attribute block_first_cp

Returns:

  • (Object)

    the current value of block_first_cp



5
6
7
# File 'lib/ucode/glyphs/grid.rb', line 5

def block_first_cp
  @block_first_cp
end

#column_pitchObject

Returns the value of attribute column_pitch

Returns:

  • (Object)

    the current value of column_pitch



5
6
7
# File 'lib/ucode/glyphs/grid.rb', line 5

def column_pitch
  @column_pitch
end

#columnsObject

Returns the value of attribute columns

Returns:

  • (Object)

    the current value of columns



5
6
7
# File 'lib/ucode/glyphs/grid.rb', line 5

def columns
  @columns
end

#origin_xObject

Returns the value of attribute origin_x

Returns:

  • (Object)

    the current value of origin_x



5
6
7
# File 'lib/ucode/glyphs/grid.rb', line 5

def origin_x
  @origin_x
end

#origin_yObject

Returns the value of attribute origin_y

Returns:

  • (Object)

    the current value of origin_y



5
6
7
# File 'lib/ucode/glyphs/grid.rb', line 5

def origin_y
  @origin_y
end

#row_pitchObject

Returns the value of attribute row_pitch

Returns:

  • (Object)

    the current value of row_pitch



5
6
7
# File 'lib/ucode/glyphs/grid.rb', line 5

def row_pitch
  @row_pitch
end

#rowsObject

Returns the value of attribute rows

Returns:

  • (Object)

    the current value of rows



5
6
7
# File 'lib/ucode/glyphs/grid.rb', line 5

def rows
  @rows
end

Instance Method Details

#cell_position(codepoint) ⇒ Object



12
13
14
15
16
17
18
19
20
# File 'lib/ucode/glyphs/grid.rb', line 12

def cell_position(codepoint)
  offset = codepoint - block_first_cp
  return nil if offset.negative?

  row, col = offset.divmod(columns)
  return nil if row >= rows

  [origin_x + (col * column_pitch), origin_y + (row * row_pitch)]
end

#codepoint_at(row, col) ⇒ Object



22
23
24
25
26
27
# File 'lib/ucode/glyphs/grid.rb', line 22

def codepoint_at(row, col)
  return nil if row.negative? || row >= rows
  return nil if col.negative? || col >= columns

  block_first_cp + (row * columns) + col
end