Cairo Declare Help

Hello,

i do some steps in using Linux specific functions. I wanna draw outlined Text to the Windows Canvas and found this small piece of code and try to translate them into Xojo. But I does not result outlined drawn text. Am I right with my declares?
Python

ctx = cairo.Context(surface) ctx.text_path('Outline') ctx.set_line_width(1) ctx.stroke()
Xojo

[code]#If TargetLinux Then
’ not sure of the declare are right and complete
https://cairographics.org/manual/cairo-cairo-t.html#cairo-stroke
Declare Sub cairo_stroke Lib “cairo.so” (context As Integer)
’ Declare Sub cairo_stroke Lib “libcairo.so” (context As Integer)
cairo_stroke(g.Handle(g.HandleTypeCairoContext))
#Endif

g.PenHeight = 1
g.PenWidth = 1
g.DrawString(“Outline”, 100, 100)[/code]

Here you can find an old VB Implementation for outlined Cairo Text. Looks pretty analog.

Try this:

[code]declare Sub cairo_text_path Lib “libcairo” (ctx As ptr, t As CString)
Declare Sub cairo_set_line_width Lib “libcairo” (ctx As ptr, w As Double)
Declare Sub cairo_set_font_size Lib “libcairo” (ctx As ptr, w As Double)
Declare Sub cairo_set_source_rgb Lib “libcairo” (ctx As ptr,r As Double, g As Double, b As Double)
Declare Sub cairo_move_to Lib “libcairo” (ctx As ptr, x As double, y As double)
Declare Sub cairo_stroke Lib “libcairo” (ctx As ptr)

Dim ctx As ptr = ptr(g.Handle(Graphics.HandleTypeCairoContext))
cairo_move_to(ctx,50,50)
cairo_set_source_rgb(ctx,1,0,0)
cairo_set_font_size(ctx,32)
cairo_text_path(ctx,“Outline”)
cairo_set_line_width(ctx,1)
cairo_stroke(ctx)[/code]

Just remember, drawing coordinates will be relative to the window, not the canvas.

Here’s a link to the main Cairo reference:

Wonderful Jim. Thank you very much. Works like a charme.

If I now would like to set also the Font, I think I’ll need to use

void cairo_set_font_face (cairo_t *cr, cairo_font_face_t *font_face);

But if I do it in Xojo, the the App quits without Compiler Error:

Declare Sub cairo_set_font_face Lib "libcairo" (ctx As Ptr, font As CString) ... cairo_set_font_face(ctx, "Times New Roman")

Also the properties like Graphics.Bold/Graphics.Italic are ignored.

You’ll need to set a font face object. See the asterisk next to font_face? That denotes a ptr.

You can create the font face using cairo-toy-font-face-create and destroy it after
Or you can use cairo-select-font-face

Declare Sub cairo-select-font-face Lib "libcairo" (ctx As ptr, family as cstring, slant as int32, weight as int32)
slant is 0,1,2 =normal, italic objlique
weight is 0,1 = normal, bold