Sha256: 539d24e4f6fba34549fe3b22f5399d6d9fc3d00cee88f33c086ad628b9e81598
Contents?: true
Size: 1.04 KB
Versions: 18
Compression:
Stored size: 1.04 KB
Contents
class PSD class Renderer # Adapted from # http://www.hokstad.com/simple-drawing-in-ruby-with-cairo module CairoHelpers def cairo_image_surface(w, h, bg=nil) surface = Cairo::ImageSurface.new(w, h) cr = Cairo::Context.new(surface) if bg cr.set_source_rgba(*bg) cr.paint end yield cr surface.finish data = cr.target.data.to_s[0, 4 * w * h] # Cairo data is stored as BGRA, ugh. data = data.unpack("N*").map do |color| color = ChunkyPNG::Color.to_truecolor_alpha_bytes(color) ChunkyPNG::Color.rgba(color[2], color[1], color[0], color[3]) end ChunkyPNG::Canvas.new(w, h, data) end def cairo_path(cr, *pairs) first = true pairs.each do |cmd| if cmd == :c cr.close_path first = true elsif first cr.move_to(*cmd) first = false else cr.curve_to(*cmd) end end end end end end
Version data entries
18 entries across 18 versions & 1 rubygems