www.digitalmars.com         C & C++   DMDScript  

digitalmars.D - using cairo with gtkd

reply llee <llee goucher.edu> writes:
A number of functions in Cairo return objects with the following naming
conventions, according to the documention on:
http://devel.akbkhome.com/gtkd_docs/src/cairoLib:

cairo_<object name>_t

When I try to create instances of these objects, I get an error. For example,
when I try to instantiate the following:

cairo_text_extents_t* textExtents

The compiler says that cairo_text_extents_t is undefined. I tried importing the
following modules:

cairoLib.Cairo, and cairoLib.Types.

Neither of these resolved the problem. If anyone can tell me how I can use the
following functions I'd appreciate it. 

void textExtents (char[] utf8, cairo_text_extents_t * extents);
void selectFontFace (char[] family, cairo_font_slant_t slant,
cairo_font_weight_t weight);

Thanks in advance.
Jan 22 2008
parent reply llee <llee goucher.edu> writes:
llee Wrote:

 A number of functions in Cairo return objects with the following naming
conventions, according to the documention on:
http://devel.akbkhome.com/gtkd_docs/src/cairoLib:
 
 cairo_<object name>_t
 
 When I try to create instances of these objects, I get an error. For example,
when I try to instantiate the following:
 
 cairo_text_extents_t* textExtents
 
 The compiler says that cairo_text_extents_t is undefined. I tried importing
the following modules:
 
 cairoLib.Cairo, and cairoLib.Types.
 
 Neither of these resolved the problem. If anyone can tell me how I can use the
following functions I'd appreciate it. 
 
 void textExtents (char[] utf8, cairo_text_extents_t * extents);
 void selectFontFace (char[] family, cairo_font_slant_t slant,
cairo_font_weight_t weight);
 
 Thanks in advance.
never mind, I solved it.
Jan 22 2008
parent reply llee <llee goucher.edu> writes:
llee Wrote:

 llee Wrote:
 
 A number of functions in Cairo return objects with the following naming
conventions, according to the documention on:
http://devel.akbkhome.com/gtkd_docs/src/cairoLib:
 
 cairo_<object name>_t
 
 When I try to create instances of these objects, I get an error. For example,
when I try to instantiate the following:
 
 cairo_text_extents_t* textExtents
 
 The compiler says that cairo_text_extents_t is undefined. I tried importing
the following modules:
 
 cairoLib.Cairo, and cairoLib.Types.
 
 Neither of these resolved the problem. If anyone can tell me how I can use the
following functions I'd appreciate it. 
 
 void textExtents (char[] utf8, cairo_text_extents_t * extents);
 void selectFontFace (char[] family, cairo_font_slant_t slant,
cairo_font_weight_t weight);
 
 Thanks in advance.
I imported gtkc.cairoLibtypes. This stoped the compiler from saying that cairo_text_extents_t is undefined, but the structure is missing data members. When I tried to dereference cairo_text_extents_t.width the compiler says that width is not a recognized data member. I get the same error when I try to dereference Xadvance. I'm really running out of ideas here. Any help would be appreciated.
Jan 22 2008
parent reply John Reimer <terminal.node gmail.com> writes:
llee wrote:
 llee Wrote:
 
 llee Wrote:

 A number of functions in Cairo return objects with the following naming
conventions, according to the documention on:
http://devel.akbkhome.com/gtkd_docs/src/cairoLib:

 cairo_<object name>_t

 When I try to create instances of these objects, I get an error. For example,
when I try to instantiate the following:

 cairo_text_extents_t* textExtents

 The compiler says that cairo_text_extents_t is undefined. I tried importing
the following modules:

 cairoLib.Cairo, and cairoLib.Types.

 Neither of these resolved the problem. If anyone can tell me how I can use the
following functions I'd appreciate it. 

 void textExtents (char[] utf8, cairo_text_extents_t * extents);
 void selectFontFace (char[] family, cairo_font_slant_t slant,
cairo_font_weight_t weight);

 Thanks in advance.
I imported gtkc.cairoLibtypes. This stoped the compiler from saying that cairo_text_extents_t is undefined, but the structure is missing data members. When I tried to dereference cairo_text_extents_t.width the compiler says that width is not a recognized data member. I get the same error when I try to dereference Xadvance. I'm really running out of ideas here. Any help would be appreciated.
GtkD uses gtk+ (and related bindings like cairo) that are not full definitions of the C counterparts. This means many of the gtkc structs (including cairoLib) are declared as opaque types. That is, the struct members are not defined. The assumption is that these data members are not going to be accessed by the D programmer. This is sufficient for implementing GtkD itself but may not be sufficient for those that want to direct access to the complete C header definitions of the struct types. You could do a couple of things. (1) You could look in the C Cairo headers and find the complete definition of the struct and add the D equivalent to the gtkc/cairoLibtypes.d module yourself. This probably would be a fairly simple fix. or... (2) You could get the complete gtk+ (including cairo) from the bcd generated bindings (www.dsource.org/projects/bcd). These bindings include the full struct definitions for all types. But, if you need to use GtkD, these are not set up to work correctly along side it. In summary, the GtkD gtk+ bindings are not complete and are insufficient if you want to use them to work with pure gtk+ (this you can do, but there is limited support)... they are mostly available to accomodate GtkD wrapping and therefore provide the functionality that GtkD needs. -JJR
Jan 22 2008
parent reply Frank Benoit <keinfarbton googlemail.com> writes:
the dwt-linux project contains also the cairo bindings.
What is special about them is, that all struct sizes are verified too 
match them in C.

See dwt/internal/c
Jan 22 2008
parent John Reimer <terminal.node gmail.com> writes:
Frank Benoit wrote:
 the dwt-linux project contains also the cairo bindings.
 What is special about them is, that all struct sizes are verified too 
 match them in C.
 
 See dwt/internal/c
Ah, right. This would be the best solution for correct bindings. They also have correct conversions for many of the struct bitfields in gtk+. Thanks, Frank. -JJR
Jan 23 2008