Sha256: 9247a712e10d8cba722b6259856d36c94d0fb5d9c85d9a6deddb25b6906d4c86

Contents?: true

Size: 1.25 KB

Versions: 117

Compression:

Stored size: 1.25 KB

Contents

#!/usr/bin/env ruby

top = File.expand_path(File.join(File.dirname(__FILE__), ".."))
$LOAD_PATH.unshift File.join(top, "ext", "cairo")
$LOAD_PATH.unshift File.join(top, "lib")

require 'cairo'
require 'stringio'

def render(output, surface_class)
  surface_class.new(output, 200, 200) do |surface|
    cr = Cairo::Context.new(surface)

    # fill background with white
    cr.set_source_color("#fffc")
    cr.paint

    # create shape
    cr.move_to(50, 50)
    cr.curve_to(100, 25, 100, 75, 150, 50)
    cr.line_to(150, 150)
    cr.line_to(50, 150)
    cr.close_path

    cr.set_source_color(:black)
    cr.fill_preserve
    cr.set_source_color(:red)
    cr.set_line_join(Cairo::LINE_JOIN_MITER)
    cr.set_line_width(4)
    cr.stroke

    cr.show_page
    surface.finish
  end
end

def output(surface_class_name, suffix)
  if Cairo.const_defined?(surface_class_name)
    surface_class = Cairo.const_get(surface_class_name)
    render("test.#{suffix}", surface_class)

    output = StringIO.new
    render(output, surface_class)
    output.rewind
    File.open("test2.#{suffix}", "wb") do |f|
      f.print(output.read)
    end
  else
    puts("#{surface_class_name} isn't supported.")
  end
end

output("PSSurface", "ps")
output("PDFSurface", "pdf")
output("SVGSurface", "svg")

Version data entries

117 entries across 109 versions & 2 rubygems

Version Path
cairo-1.17.13 samples/scalable.rb
cairo-1.17.12 samples/scalable.rb
cairo-1.17.11 samples/scalable.rb
cairo-1.17.10 samples/scalable.rb
cairo-1.17.9 samples/scalable.rb
cairo-1.17.8 samples/scalable.rb
cairo-1.17.7 samples/scalable.rb
cairo-1.17.6 samples/scalable.rb
cairo-1.17.5 samples/scalable.rb
cairo-1.17.4 samples/scalable.rb
cairo-1.16.6 samples/scalable.rb
cairo-1.16.5 samples/scalable.rb
cairo-1.16.4 samples/scalable.rb
cairo-1.16.3 samples/scalable.rb
cairo-1.16.2 samples/scalable.rb
cairo-1.16.1-x86-mingw32 samples/scalable.rb
cairo-1.16.1-x64-mingw32 samples/scalable.rb
cairo-1.16.1 samples/scalable.rb
cairo-1.16.0-x86-mingw32 samples/scalable.rb
cairo-1.16.0-x64-mingw32 samples/scalable.rb