Comments (2)
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.
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)
- High level objects
- High level Glyphs class
- High level TextClusters class
- Cannot install
- get_font_face compile error
- Dependency Issue on Fresh Install HOT 3
- Error Upon simply importing the shard. lib/cairo/src/cairo/c/lib_cairo.cr HOT 2
- Surface.get_type causes error HOT 2
- SvgSurface creates an empty svg file HOT 2
- How to use the Cairo::Surface#write_to_png_stream ..? HOT 3
Recommend Projects
-
React
A declarative, efficient, and flexible JavaScript library for building user interfaces.
-
Vue.js
🖖 Vue.js is a progressive, incrementally-adoptable JavaScript framework for building UI on the web.
-
Typescript
TypeScript is a superset of JavaScript that compiles to clean JavaScript output.
-
TensorFlow
An Open Source Machine Learning Framework for Everyone
-
Django
The Web framework for perfectionists with deadlines.
-
Laravel
A PHP framework for web artisans
-
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.
-
Visualization
Some thing interesting about visualization, use data art
-
Game
Some thing interesting about game, make everyone happy.
Recommend Org
-
Facebook
We are working to build community through open source technology. NB: members must have two-factor auth.
-
Microsoft
Open source projects and samples from Microsoft.
-
Google
Google ❤️ Open Source for everyone.
-
Alibaba
Alibaba Open Source for everyone
-
D3
Data-Driven Documents codes.
-
Tencent
China tencent open source team.
from cairo-cr.