Skip to content

Instantly share code, notes, and snippets.

@joshmh
Created February 25, 2009 21:20
Show Gist options
  • Star 0 You must be signed in to star a gist
  • Fork 0 You must be signed in to fork a gist
  • Save joshmh/70419 to your computer and use it in GitHub Desktop.
Save joshmh/70419 to your computer and use it in GitHub Desktop.
require 'pango'
mini_surface = Cairo::ImageSurface.new Cairo::FORMAT_ARGB32, 1, 1
mini_ctx = Cairo::Context.new mini_surface
layout = mini_ctx.create_pango_layout
fd = Pango::FontDescription.new('Raanan')
fd.set_size(90 * Pango::SCALE)
layout.set_font_description(fd)
layout.text = 'אהלן!'
width = layout.get_pixel_extents.last.width
height = layout.get_pixel_extents.last.height
surface = Cairo::ImageSurface.new Cairo::FORMAT_ARGB32, width, height
ctx = Cairo::Context.new surface
# background
ctx.set_source_rgba [0,0,0,0]
ctx.move_to(0, 0)
ctx.rectangle(0, 0, width, height)
ctx.fill()
ctx.set_source_rgba [0,0,0,1]
ctx.move_to(0, 0)
ctx.show_pango_layout(layout)
surface.write_to_png('out.png')
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment