Class: Memopri::Renderer
- Inherits:
-
Object
- Object
- Memopri::Renderer
- Defined in:
- lib/memopri/renderer.rb
Instance Attribute Summary collapse
-
#nol ⇒ Object
Returns the value of attribute nol.
-
#str ⇒ Object
Returns the value of attribute str.
Instance Method Summary collapse
- #conv ⇒ Object
-
#initialize(str = "") ⇒ Renderer
constructor
A new instance of Renderer.
Constructor Details
#initialize(str = "") ⇒ Renderer
Returns a new instance of Renderer.
11 12 13 |
# File 'lib/memopri/renderer.rb', line 11 def initialize(str="") @str = str end |
Instance Attribute Details
#nol ⇒ Object
Returns the value of attribute nol.
9 10 11 |
# File 'lib/memopri/renderer.rb', line 9 def nol @nol end |
#str ⇒ Object
Returns the value of attribute str.
9 10 11 |
# File 'lib/memopri/renderer.rb', line 9 def str @str end |
Instance Method Details
#conv ⇒ Object
15 16 17 18 19 20 21 22 23 24 25 26 27 28 29 30 31 32 33 34 35 36 37 38 39 40 41 42 43 44 45 46 47 48 49 50 51 52 53 54 55 56 57 58 59 60 61 62 63 64 65 66 |
# File 'lib/memopri/renderer.rb', line 15 def conv() format = Cairo::FORMAT_ARGB32 width = nil height = 128 surface = Cairo::ImageSurface.new(format, 0, 128) context = Cairo::Context.new(surface) layout = context.create_pango_layout layout.text = str font_description = Pango::FontDescription.new("Sans-serif 18") size = nil begin font_description.size *= 1.06 layout.font_description = font_description size = layout.size.map{|x| x/Pango::SCALE} end while size[1] <= 111 width = size[0] + 5 surface = Cairo::ImageSurface.new(format, width, 128) context = Cairo::Context.new(surface) layout = context.create_pango_layout layout.text = str #layout.width = width * Pango::SCALE * 0.9 layout.wrap = Pango::WRAP_CHAR layout.font_description = font_description context.translate(0, 7) context.show_pango_layout(layout) context.show_page surface.write_to_png("/tmp/hinomaru.png") data = [] surface.data.unpack("C*").each_slice(4) {|x| x = x[3] > 10 ? 1 : 0 data.push(x) } data2 = [] data.each_slice(width) {|x| data2.push(x) } data = data2.transpose.flatten ret = [] data.each_slice(8) {|x| ret.push([x.join()].pack("B*")) } ret = ret.map{|x| x.unpack("C*")[0]} return ret end |