Guest User

Untitled

a guest
Apr 23rd, 2018
96
0
Never
Not a member of Pastebin yet? Sign Up, it unlocks many cool features!
text 1.25 KB | None | 0 0
  1. #!/usr/bin/env ruby
  2.  
  3. top = File.expand_path(File.join(File.dirname(__FILE__), ".."))
  4. src = File.join(top, "src")
  5. $LOAD_PATH.unshift src
  6. $LOAD_PATH.unshift File.join(src, "lib")
  7.  
  8. require 'cairo'
  9. require 'pango'
  10.  
  11. def render_background(cr)
  12. cr.set_source_color(:white)
  13. cr.paint
  14. end
  15.  
  16. def make_layout(cr, text)
  17. layout = cr.create_pango_layout
  18. layout.text = text
  19. layout.font_description = Pango::FontDescription.new("Serif 36")
  20. cr.update_pango_layout(layout)
  21. layout
  22. end
  23.  
  24. def render(surface)
  25. text = "It was a dream... Oh Just a dream..."
  26.  
  27. cr = Cairo::Context.new(surface)
  28.  
  29. render_background(cr)
  30.  
  31. cr.set_source_color(:red)
  32. cr.move_to(25, 350)
  33. cr.line_to(150, 375)
  34. cr.curve_to(275, 400, 450, 350, 450, 200)
  35. cr.curve_to(450, 0, 300, 150, 50, 50)
  36. cr.stroke_preserve
  37. path = cr.copy_path_flat
  38.  
  39. cr.line_width = 1
  40. cr.new_path
  41. layout = make_layout(cr, text)
  42. cr.pango_layout_line_path(layout.get_line(0))
  43. cr.map_path_onto(path)
  44.  
  45. cr.set_source_rgba(0.3, 0.3, 1.0, 0.3)
  46. cr.fill_preserve
  47. cr.set_source_rgba(0.1, 0.1, 0.1)
  48. cr.stroke
  49.  
  50. cr.show_page
  51. end
  52.  
  53. def output
  54. Cairo::ImageSurface.new(500, 500) do |surface|
  55. render(surface)
  56. surface.write_to_png("text-on-path.png")
  57. end
  58. end
  59.  
  60. output
Add Comment
Please, Sign In to add comment