Sha256: 94015860716588561817a510de31db78116bf99dcbc5310f43f5155f61ca7296

Contents?: true

Size: 771 Bytes

Versions: 8

Compression:

Stored size: 771 Bytes

Contents

class SugarPNG
  class Glyph
    attr_accessor :width, :height, :data, :ord

    def initialize h = {}
      @ord    = h[:ord]
      @data   = h[:data]
      @width  = h[:width]
      @height = h[:height]
    end

    def blank?
      @data.tr("\x00","").empty?
    end

    def to_s repl=" #"
      bytes_in_row = (@width/8.0).ceil
      r = ''; ptr = 0
      @height.times.each do
        r += @data[ptr,bytes_in_row].unpack("B#@width")[0].tr("01",repl) + "\n"
        ptr += bytes_in_row
      end
      r.chomp
    end

    def to_a
      bytes_in_row = (@width/8.0).ceil
      r = []; ptr = 0
      @height.times.each do
        r << @data[ptr,bytes_in_row].unpack("B#@width")[0].split('').map(&:to_i)
        ptr += bytes_in_row
      end
      r
    end
  end
end

Version data entries

8 entries across 8 versions & 1 rubygems

Version Path
sugar_png-0.5.5 lib/sugar_png/glyph.rb
sugar_png-0.5.4 lib/sugar_png/glyph.rb
sugar_png-0.5.3 lib/sugar_png/glyph.rb
sugar_png-0.5.2 lib/sugar_png/glyph.rb
sugar_png-0.5.1 lib/sugar_png/glyph.rb
sugar_png-0.5.0 lib/sugar_png/glyph.rb
sugar_png-0.4.1 lib/sugar_png/glyph.rb
sugar_png-0.4.0 lib/sugar_png/glyph.rb