tamasszekeres / cairo-cr Goto Github PK
View Code? Open in Web Editor NEWCairo bindings for Crystal language.
License: MIT License
Cairo bindings for Crystal language.
License: MIT License
shard.lock
and lib/
folder# shard.yml
# ...
dependencies:
x11:
github: TamasSzekeres/x11-cr
cairo:
github: TamasSzekeres/cairo-cr
shards install
, I got:Resolving dependencies
Fetching https://github.com/TamasSzekeres/x11-cr.git
Fetching https://github.com/TamasSzekeres/cairo-cr.git
Unable to satisfy the following requirements:
- `x11 (*)` required by `shard.yml`
- `x11 (branch master)` required by `cairo 0.3.0`
Failed to resolve dependencies
By commenting out cairo and running shards install
with only the x11 dependency, and then uncommenting the cairo line and running shards install
again, everything installed correctly.
dependencies:
x11:
github: TamasSzekeres/x11-cr
# cairo:
# github: TamasSzekeres/cairo-cr
I'm very new to the crystal language and eco-system, so this might not be an issue with this repository specifically, but just thought I'd point it out anyway.
Add TextClusters class which encapsulates more TextClusterT structures in an array.
Make crystal classes to use cairo oo-style.
Example:
my_surface.draw do |ctx|
ctx.rectangle(0, 0, 20, 10)
ctx.fill
# or directly: ctx.rectangle(0, 0, 20, 10).fill
end
I was reading the source for different methods to explore and decided to try some at random.
When calling get_type on the SvgSurface i go the following error:
In lib/cairo/src/cairo/surface.cr:141:20
141 | def get_type : SurfaceType
^
Error: undefined constant SurfaceType
Did you mean 'SurfaceTypeT'?
require "cairo"
module SvgCreation
include Cairo
def self.main
surface = Cairo::SvgSurface.new "test.svg", 400, 400
context = Cairo::Context.new surface
# context.set_source(surface)
context.rectangle 0.0, 0.0, 200.0, 150.0
context.set_source_rgb 0.0, 10.0, 0.0
context.fill
puts surface.get_type
end
main
end
By editing the implementation on line 141 in surface.cr from
def get_type : SurfaceType
SurfaceType.new(LibCairo.surface_get_type(@surface).value)
end
to
def get_type : SurfaceTypeT
SurfaceTypeT.new(LibCairo.surface_get_type(@surface).value)
end
the error disappears and "SVG" is printed as expected.
Add Glyphs class which encapsulates more PGlyphT pointers in an array.
Error in cairo_tst.cr:42: instantiating 'Cairo::Context#font_face()'
ff = context.font_face
^~~~~~~~~
in lib/cairo/src/cairo/context.cr:472: wrong number of arguments for 'Cairo::C::LibCairo#get_font_face' (given 2, expected 1)
LibCairo.get_font_face(@cairo, font_face.to_unsafe)
^~~~~~~~~~~~~
Fix
def font_face : FontFace
#font_face = FontFace.new
#LibCairo.get_font_face(@cairo, font_face.to_unsafe)
#font_face
font_face = LibCairo.get_font_face(@cairo)
FontFace.new(font_face)
end
Upon simply running crystal test.cr
where test.cr is:
require "cairo"
puts "Hello, World!"
I get the following error:
In lib/cairo/src/cairo/c/lib_cairo.cr:60:7
60 | SUCCESS = 0,
^
Error: expecting ';', 'end' or newline after enum member
I'm trying to access the raw png data of the surface without calling surface.write_to_png(<filename>)
.
current code:
require "cairo"
at_exit do
GC.collect
end
surface = Cairo::Surface.new Cairo::Format::ARGB32, 400, 300
ctx = Cairo::Context.new surface
ctx.set_source_rgba 1.0, 0.0, 1.0, 1.0
ctx.rectangle 0.0, 0.0, 400.0, 300.0
ctx.fill
# ...
# somehow call surface.write_to_png_stream to access png data without writing to disk...
# ...
surface.finish
I don't quite understand how to use the implemented version:
def write_to_png_stream(write_func : LibCairo::WriteFuncT, closure : Void*) : Status
Status.new(LibCairo.surface_write_to_png_stream(@surface, write_func, closure).value)
end
In my shard.yml:
dependencies:
x11:
github: TamasSzekeres/x11-cr
branch: master
cairo:
github: TamasSzekeres/cairo-cr
branch: master
Error:
$ crystal deps
Updating https://github.com/TamasSzekeres/x11-cr.git
Updating https://github.com/TamasSzekeres/cairo-cr.git
Error resolving x11 (*, 0.2.1)
Note that using branch: high-level
under cairo:
allows it to install just fine
I'm trying to draw the same surface as in the high-level x11 window example using the code below.
While I can create a nice png image with
surface.write_to_png "test.png"
... I can't find a way to write it to svg. There doesn't seem to be a write_to_svg
..?
When I run the code below, however, an empty "test.svg" is written
require "cairo"
module SvgCreation
include Cairo
def self.main
surface = Cairo::SvgSurface.new "test.svg", 400, 300
# surface.restrict_to_version Cairo::SvgVersion::V_1_2
context = Cairo::Context.new surface
context.set_source_rgba 1.0, 0.0, 1.0, 1.0
context.rectangle 0.0, 0.0, 400.0, 300.0
context.fill
context.set_source_rgb 0.0, 0.0, 0.0
context.move_to 0.0, 0.0
context.line_to 400.0, 300.0
context.move_to 400.0, 0.0
context.line_to 0.0, 300.0
context.line_width = 10.0
context.stroke
context.rectangle 0.0, 0.0, 200.0, 150.0
context.set_source_rgba 1.0, 0.0, 0.0, 0.80
context.fill
context.rectangle 0.0, 150.0, 200.0, 150.0
context.set_source_rgba 0.0, 1.0, 0.0, 0.60
context.fill
context.rectangle 200.0, 0.0, 200.0, 150.0
context.set_source_rgba 0.0, 0.0, 1.0, 0.40
context.fill
# surface.write_to_png "test.png"
end
main
end
Is there a close
/destroy
/save
method or something that I'm missing?
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.
A declarative, efficient, and flexible JavaScript library for building user interfaces.
๐ Vue.js is a progressive, incrementally-adoptable JavaScript framework for building UI on the web.
TypeScript is a superset of JavaScript that compiles to clean JavaScript output.
An Open Source Machine Learning Framework for Everyone
The Web framework for perfectionists with deadlines.
A PHP framework for web artisans
Bring data to life with SVG, Canvas and HTML. ๐๐๐
JavaScript (JS) is a lightweight interpreted programming language with first-class functions.
Some thing interesting about web. New door for the world.
A server is a program made to process requests and deliver data to clients.
Machine learning is a way of modeling and interpreting data that allows a piece of software to respond intelligently.
Some thing interesting about visualization, use data art
Some thing interesting about game, make everyone happy.
We are working to build community through open source technology. NB: members must have two-factor auth.
Open source projects and samples from Microsoft.
Google โค๏ธ Open Source for everyone.
Alibaba Open Source for everyone
Data-Driven Documents codes.
China tencent open source team.