Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Examples With SVG/PDF Surface #11

Closed
EriKWDev opened this issue Oct 28, 2020 · 2 comments
Closed

Examples With SVG/PDF Surface #11

EriKWDev opened this issue Oct 28, 2020 · 2 comments

Comments

@EriKWDev
Copy link
Contributor

EriKWDev commented Oct 28, 2020

It would be nice to have some examples using just Cairo without neccessarily using an x11 surface.
For example using the available svg or pdf surfaces for pdf/svg creation.

@EriKWDev EriKWDev changed the title Examples Without X11 Examples With SVG/PDF Surface Oct 28, 2020
@EriKWDev
Copy link
Contributor Author

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

@EriKWDev
Copy link
Contributor Author

EriKWDev commented Oct 28, 2020

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

EriKWDev added a commit to EriKWDev/cairo-cr that referenced this issue Oct 28, 2020
EriKWDev added a commit to EriKWDev/cairo-cr that referenced this issue Oct 28, 2020
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
None yet
Projects
None yet
Development

No branches or pull requests

1 participant