viachpaliy / cairo-gobject

Cairo bindings for applying with crystal-gobject
MIT License
7 stars 1 forks source link

[error] LibCairo::Rectangle compiling demo #1

Open nodrygo opened 4 years ago

nodrygo commented 4 years ago

hello first of all thank for this great work

trying the sample _gtksample.cr I got this error

crystal run samples/gtk_sample.cr 
Showing last frame. Use --error-trace for full trace.
In src/lib_cairo.cr:20:18
 20 | rectangles : LibCairo::Rectangle*
                   ^------------------
Error: undefined constant LibCairo::Rectangle

please note that crystal-gobject (another great work) samples work on my machine

is it a problem with my cairo release ? my env. is

Linux Mint19  5.3.0-40-generic #32~18.04.1-Ubuntu SMP
libgtk 3.22.30 (standard installed)
libcairo, libcairo-gobject2   1.15.10

thanks for help

nodrygo commented 4 years ago

resolved simply adding this in _src/libcairo.cr make things works correctly

  struct Rectangle
    x: Float64
    y: Float64
    width: Float64
    height: Float64
  end
viachpaliy commented 4 years ago

Hey, sorry this took me so long to look at, but to be honest it also mixes a couple of things so it's a bit harder to look at. When I run gtk_sample.cr in Ubuntu, crystal-gobject use gir1.2-freedesktop for create cairo bindings in runtime. This bindings consists from lib LibCairo and module Cairo. LibCairo wraps "raw" C struct (for example LibCairo::Rectangle). module Cairo includes wrappers-classes for these struct : Context,Device etc. In my opinion, you need install gir1.2-freedesktop package.

CNFloss commented 4 years ago

Hi I have installed gir1.2-freedesktop package in Ubuntu 18.04.4

I still receive the error above, do I have do any thing else besides install and update, to create cairo bindings in runtime?

thank you for your help.

viachpaliy commented 4 years ago

I have installed XUbuntu 19.10 You can check whether "compile-time" bindings run samples/save_binding.cr . Bindings will saved in samples/cairo_binding.cr. This is bindings from my computer:

@[Link("cairo-gobject")] lib LibCairo

###########################################

Structs

###########################################

struct Context # struct _data : UInt8[0] end

struct Device # struct _data : UInt8[0] end

struct Surface # struct _data : UInt8[0] end

struct Matrix # struct _data : UInt8[0] end

struct Pattern # struct _data : UInt8[0] end

struct Region # struct _data : UInt8[0] end

struct FontOptions # struct _data : UInt8[0] end

struct FontFace # struct _data : UInt8[0] end

struct ScaledFont # struct _data : UInt8[0] end

struct Path # struct _data : UInt8[0] end

struct Rectangle # struct x : Float64 y : Float64 width : Float64 height : Float64 end

struct RectangleInt # struct x : Int32 y : Int32 width : Int32 height : Int32 end

###########################################

Enums

###########################################

alias Status = UInt32

alias Content = UInt32

alias Operator = UInt32

alias Antialias = UInt32

alias FillRule = UInt32

alias LineCap = UInt32

alias LineJoin = UInt32

alias TextClusterFlags = UInt32

alias FontSlant = UInt32

alias FontWeight = UInt32

alias SubpixelOrder = UInt32

alias HintStyle = UInt32

alias HintMetrics = UInt32

alias FontType = UInt32

alias PathDataType = UInt32

alias DeviceType = Int32

alias SurfaceType = UInt32

alias Format = Int32

alias PatternType = UInt32

alias Extend = UInt32

alias Filter = UInt32

alias RegionOverlap = UInt32

###########################################

Functions

###########################################

fun image_surface_create = cairo_image_surface_create() : Void end

#<loc:"/usr/lib/x86_64-linux-gnu/girepository-1.0/cairo-1.0.typelib",1,1>

module Cairo# def self.image_surface_create LibCairo.image_surface_create nil end

#<loc:"/usr/lib/x86_64-linux-gnu/girepository-1.0/cairo-1.0.typelib/Context",1,1>

class Context include GObject::WrappedType

@pointer : Void*
def initialize(pointer : LibCairo::Context*)
  @pointer = pointer.as(Void*)
end

def to_unsafe
  @pointer.not_nil!.as(LibCairo::Context*)
end

end

#<loc:"/usr/lib/x86_64-linux-gnu/girepository-1.0/cairo-1.0.typelib/Device",1,1>

class Device include GObject::WrappedType

@pointer : Void*
def initialize(pointer : LibCairo::Device*)
  @pointer = pointer.as(Void*)
end

def to_unsafe
  @pointer.not_nil!.as(LibCairo::Device*)
end

end

#<loc:"/usr/lib/x86_64-linux-gnu/girepository-1.0/cairo-1.0.typelib/Surface",1,1>

class Surface include GObject::WrappedType

@pointer : Void*
def initialize(pointer : LibCairo::Surface*)
  @pointer = pointer.as(Void*)
end

def to_unsafe
  @pointer.not_nil!.as(LibCairo::Surface*)
end

end

#<loc:"/usr/lib/x86_64-linux-gnu/girepository-1.0/cairo-1.0.typelib/Matrix",1,1>

class Matrix include GObject::WrappedType

@pointer : Void*
def initialize(pointer : LibCairo::Matrix*)
  @pointer = pointer.as(Void*)
end

def to_unsafe
  @pointer.not_nil!.as(LibCairo::Matrix*)
end

end

#<loc:"/usr/lib/x86_64-linux-gnu/girepository-1.0/cairo-1.0.typelib/Pattern",1,1>

class Pattern include GObject::WrappedType

@pointer : Void*
def initialize(pointer : LibCairo::Pattern*)
  @pointer = pointer.as(Void*)
end

def to_unsafe
  @pointer.not_nil!.as(LibCairo::Pattern*)
end

end

#<loc:"/usr/lib/x86_64-linux-gnu/girepository-1.0/cairo-1.0.typelib/Region",1,1>

class Region include GObject::WrappedType

@pointer : Void*
def initialize(pointer : LibCairo::Region*)
  @pointer = pointer.as(Void*)
end

def to_unsafe
  @pointer.not_nil!.as(LibCairo::Region*)
end

end

#<loc:"/usr/lib/x86_64-linux-gnu/girepository-1.0/cairo-1.0.typelib/Status",1,1>

enum Status : UInt32 ZERO_NONE = 0 SUCCESS = 0 NO_MEMORY = 1 INVALID_RESTORE = 2 INVALID_POP_GROUP = 3 NO_CURRENT_POINT = 4 INVALID_MATRIX = 5 INVALID_STATUS = 6 NULL_POINTER = 7 INVALID_STRING = 8 INVALID_PATH_DATA = 9 READ_ERROR = 10 WRITE_ERROR = 11 SURFACE_FINISHED = 12 SURFACE_TYPE_MISMATCH = 13 PATTERN_TYPE_MISMATCH = 14 INVALID_CONTENT = 15 INVALID_FORMAT = 16 INVALID_VISUAL = 17 FILE_NOT_FOUND = 18 INVALID_DASH = 19 INVALID_DSC_COMMENT = 20 INVALID_INDEX = 21 CLIP_NOT_REPRESENTABLE = 22 TEMP_FILE_ERROR = 23 INVALID_STRIDE = 24 FONT_TYPE_MISMATCH = 25 USER_FONT_IMMUTABLE = 26 USER_FONT_ERROR = 27 NEGATIVE_COUNT = 28 INVALID_CLUSTERS = 29 INVALID_SLANT = 30 INVALID_WEIGHT = 31 INVALID_SIZE = 32 USER_FONT_NOT_IMPLEMENTED = 33 DEVICE_TYPE_MISMATCH = 34 DEVICE_ERROR = 35 INVALID_MESH_CONSTRUCTION = 36 DEVICE_FINISHED = 37 JBIG2_GLOBAL_MISSING = 38 end

#<loc:"/usr/lib/x86_64-linux-gnu/girepository-1.0/cairo-1.0.typelib/Content",1,1>

enum Content : UInt32 ZERO_NONE = 0 COLOR = 4096 ALPHA = 8192 COLOR_ALPHA = 12288 end

#<loc:"/usr/lib/x86_64-linux-gnu/girepository-1.0/cairo-1.0.typelib/Operator",1,1>

enum Operator : UInt32 ZERO_NONE = 0 CLEAR = 0 SOURCE = 1 OVER = 2 IN = 3 OUT = 4 ATOP = 5 DEST = 6 DEST_OVER = 7 DEST_IN = 8 DEST_OUT = 9 DEST_ATOP = 10 XOR = 11 ADD = 12 SATURATE = 13 MULTIPLY = 14 SCREEN = 15 OVERLAY = 16 DARKEN = 17 LIGHTEN = 18 COLOR_DODGE = 19 COLOR_BURN = 20 HARD_LIGHT = 21 SOFT_LIGHT = 22 DIFFERENCE = 23 EXCLUSION = 24 HSL_HUE = 25 HSL_SATURATION = 26 HSL_COLOR = 27 HSL_LUMINOSITY = 28 end

#<loc:"/usr/lib/x86_64-linux-gnu/girepository-1.0/cairo-1.0.typelib/Antialias",1,1>

enum Antialias : UInt32 ZERO_NONE = 0 DEFAULT = 0 NONE = 1 GRAY = 2 SUBPIXEL = 3 FAST = 4 GOOD = 5 BEST = 6 end

#<loc:"/usr/lib/x86_64-linux-gnu/girepository-1.0/cairo-1.0.typelib/FillRule",1,1>

enum FillRule : UInt32 ZERO_NONE = 0 WINDING = 0 EVEN_ODD = 1 end

#<loc:"/usr/lib/x86_64-linux-gnu/girepository-1.0/cairo-1.0.typelib/LineCap",1,1>

enum LineCap : UInt32 ZERO_NONE = 0 BUTT = 0 ROUND = 1 SQUARE = 2 end

#<loc:"/usr/lib/x86_64-linux-gnu/girepository-1.0/cairo-1.0.typelib/LineJoin",1,1>

enum LineJoin : UInt32 ZERO_NONE = 0 MITER = 0 ROUND = 1 BEVEL = 2 end

#<loc:"/usr/lib/x86_64-linux-gnu/girepository-1.0/cairo-1.0.typelib/TextClusterFlags",1,1>

enum TextClusterFlags : UInt32 ZERO_NONE = 0 BACKWARD = 1 end

#<loc:"/usr/lib/x86_64-linux-gnu/girepository-1.0/cairo-1.0.typelib/FontSlant",1,1>

enum FontSlant : UInt32 ZERO_NONE = 0 NORMAL = 0 ITALIC = 1 OBLIQUE = 2 end

#<loc:"/usr/lib/x86_64-linux-gnu/girepository-1.0/cairo-1.0.typelib/FontWeight",1,1>

enum FontWeight : UInt32 ZERO_NONE = 0 NORMAL = 0 BOLD = 1 end

#<loc:"/usr/lib/x86_64-linux-gnu/girepository-1.0/cairo-1.0.typelib/SubpixelOrder",1,1>

enum SubpixelOrder : UInt32 ZERO_NONE = 0 DEFAULT = 0 RGB = 1 BGR = 2 VRGB = 3 VBGR = 4 end

#<loc:"/usr/lib/x86_64-linux-gnu/girepository-1.0/cairo-1.0.typelib/HintStyle",1,1>

enum HintStyle : UInt32 ZERO_NONE = 0 DEFAULT = 0 NONE = 1 SLIGHT = 2 MEDIUM = 3 FULL = 4 end

viachpaliy commented 4 years ago

In my opinion, matter in different version "gir1.2-freedesktop" package for different version of Ubuntu. I added commented Rectangle structure definition in src/lib_cairo.cr file. Uncomment its definition (lines 7...12).