Coder Social home page Coder Social logo

cairo-cr's People

Contributors

aravindavk avatar dmitrybochkarev avatar erikwdev avatar hodefoting avatar ryanscottlewis avatar tamasszekeres avatar

Stargazers

 avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar

Watchers

 avatar  avatar  avatar

cairo-cr's Issues

Examples With SVG/PDF Surface

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.

High level objects

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

SvgSurface creates an empty svg file

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?

How to use the Cairo::Surface#write_to_png_stream ..?

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

get_font_face compile error

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

Dependency Issue on Fresh Install

Steps to Reproduce

  • Delete shard.lock and lib/ folder
  • Add the provided dependency from the README
# shard.yml
# ...

dependencies:
  x11:
    github: TamasSzekeres/x11-cr

  cairo:
    github: TamasSzekeres/cairo-cr
  • Then, upon executing 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

Solution

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

Disclaimer

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.

Surface.get_type causes error

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.

Cannot install

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

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.