Coder Social home page Coder Social logo

Comments (2)

EriKWDev avatar EriKWDev commented on July 28, 2024

I'm still experimenting, but if I come up with something I might submit a PR with an example using Cairo::SvgSurface

from cairo-cr.

EriKWDev avatar EriKWDev commented on July 28, 2024

Ok, I have a working example for SvgSurface which draws the same image as in the other examples.

require "cairo"

at_exit do
  GC.collect
end


module SvgDrawing
  include Cairo

  def self.main
    # Create a new SvgSurface and specify a filename and dimensions
    surface = Cairo::SvgSurface.new "test.svg", 400, 300

    # (Optional) Restrict which version of SVG that Cairo should use.
    surface.restrict_to_version Cairo::SvgVersion::V_1_2

    # Create a context based on the surface
    ctx = Cairo::Context.new surface


    # Draw some nice shapes
    ctx.set_source_rgba 1.0, 0.0, 1.0, 1.0
    ctx.rectangle 0.0, 0.0, 400.0, 300.0
    ctx.fill

    ctx.set_source_rgb 0.0, 0.0, 0.0
    ctx.move_to 0.0, 0.0
    ctx.line_to 400.0, 300.0
    ctx.move_to 400.0, 0.0
    ctx.line_to 0.0, 300.0
    ctx.line_width = 10.0
    ctx.stroke

    ctx.rectangle 0.0, 0.0, 200.0, 150.0
    ctx.set_source_rgba 1.0, 0.0, 0.0, 0.80
    ctx.fill

    ctx.rectangle 0.0, 150.0, 200.0, 150.0
    ctx.set_source_rgba 0.0, 1.0, 0.0, 0.60
    ctx.fill

    ctx.rectangle 200.0, 0.0, 200.0, 150.0
    ctx.set_source_rgba 0.0, 0.0, 1.0, 0.40
    ctx.fill

    # Finish the surface by calling surface.finish
    surface.finish
  end

  main
end

from cairo-cr.

Related Issues (11)

Recommend Projects

  • React photo React

    A declarative, efficient, and flexible JavaScript library for building user interfaces.

  • Vue.js photo Vue.js

    🖖 Vue.js is a progressive, incrementally-adoptable JavaScript framework for building UI on the web.

  • Typescript photo Typescript

    TypeScript is a superset of JavaScript that compiles to clean JavaScript output.

  • TensorFlow photo TensorFlow

    An Open Source Machine Learning Framework for Everyone

  • Django photo Django

    The Web framework for perfectionists with deadlines.

  • D3 photo D3

    Bring data to life with SVG, Canvas and HTML. 📊📈🎉

Recommend Topics

  • javascript

    JavaScript (JS) is a lightweight interpreted programming language with first-class functions.

  • web

    Some thing interesting about web. New door for the world.

  • server

    A server is a program made to process requests and deliver data to clients.

  • Machine learning

    Machine learning is a way of modeling and interpreting data that allows a piece of software to respond intelligently.

  • Game

    Some thing interesting about game, make everyone happy.

Recommend Org

  • Facebook photo Facebook

    We are working to build community through open source technology. NB: members must have two-factor auth.

  • Microsoft photo Microsoft

    Open source projects and samples from Microsoft.

  • Google photo Google

    Google ❤️ Open Source for everyone.

  • D3 photo D3

    Data-Driven Documents codes.