News:

Masm32 SDK description, downloads and other helpful links
Message to All Guests

Main Menu

Cairo

Started by jj2007, November 18, 2018, 03:26:49 PM

Previous topic - Next topic

jj2007

This looks promising, I hope I'll find some time to explore Cairo:

include \masm32\MasmBasic\MasmBasic.inc         ; download
  Init
  Dll "\Masm32\Cairo\lib\x86\cairo.dll"
  Declare cairo_version
  Inkey Str$("This is Cairo version %i", cairo_version())
EndOfCode


This is Cairo version 11512

Biterider

#1
Hello
I saw the opportunity to add something to this project and translated the header files with h2incX.
Since it worked fine, I share the result with those who want to experiment with Cairo.

Biterider

jj2007

Very good idea, biterider :t

Does it run on your machine? I get some errors:
*** Assemble using \masm32\bin\UAsm64 /c /coff  tmp_file.asm ***
UASM v2.46, Dec  8 2017, Masm-compatible assembler.
Portions Copyright (c) 1992-2002 Sybase, Inc. All Rights Reserved.
Source code is available under the Sybase Open Watcom Public License.

Cairo.inc(18) : Error A2102: Symbol not defined : Defined
Cairo.inc(18): Included by
  Tmp_File.asm(2): Main line code
Cairo.inc(35) : Error A2210: Syntax error: @DefProto
Cairo.inc(35): Included by
  Tmp_File.asm(2): Main line code
Cairo.inc(36) : Error A2210: Syntax error: @DefProto
Cairo.inc(36): Included by
  Tmp_File.asm(2): Main line code
Cairo.inc(38) : Error A2102: Symbol not defined : _cairo
Cairo.inc(38): Included by
  Tmp_File.asm(2): Main line code
Cairo.inc(40) : Error A2102: Symbol not defined : _cairo_surface
Cairo.inc(40): Included by
  Tmp_File.asm(2): Main line code
Cairo.inc(42) : Error A2102: Symbol not defined : _cairo_device
Cairo.inc(42): Included by
  Tmp_File.asm(2): Main line code
Cairo.inc(54) : Error A2102: Symbol not defined : _cairo_pattern
Cairo.inc(54): Included by
  Tmp_File.asm(2): Main line code
Cairo.inc(136) : Error A2210: Syntax error: @DefProto
Cairo.inc(136): Included by
  Tmp_File.asm(2): Main line code
Cairo.inc(137) : Error A2210: Syntax error: @DefProto
Cairo.inc(137): Included by
  Tmp_File.asm(2): Main line code
Cairo.inc(138) : Error A2210: Syntax error: @DefProto
Cairo.inc(138): Included by
  Tmp_File.asm(2): Main line code
Cairo.inc(139) : Error A2210: Syntax error: @DefProto
Cairo.inc(139): Included by
  Tmp_File.asm(2): Main line code
Cairo.inc(140) : Error A2210: Syntax error: @DefProto
Cairo.inc(140): Included by
  Tmp_File.asm(2): Main line code
Cairo.inc(141) : Error A2210: Syntax error: @DefProto
Cairo.inc(141): Included by
  Tmp_File.asm(2): Main line code
Cairo.inc(142) : Error A2210: Syntax error: @DefProto
Cairo.inc(142): Included by
  Tmp_File.asm(2): Main line code
Cairo.inc(143) : Error A2210: Syntax error: @DefProto
Cairo.inc(143): Included by
  Tmp_File.asm(2): Main line code
Cairo.inc(144) : Error A2210: Syntax error: @DefProto
Cairo.inc(144): Included by
  Tmp_File.asm(2): Main line code
Cairo.inc(145) : Error A2210: Syntax error: @DefProto
Cairo.inc(145): Included by
  Tmp_File.asm(2): Main line code
Cairo.inc(146) : Error A2210: Syntax error: @DefProto
Cairo.inc(146): Included by
  Tmp_File.asm(2): Main line code
Cairo.inc(147) : Error A2210: Syntax error: @DefProto
Cairo.inc(147): Included by
  Tmp_File.asm(2): Main line code
Cairo.inc(180) : Error A2210: Syntax error: @DefProto
Cairo.inc(180): Included by
  Tmp_File.asm(2): Main line code
Cairo.inc(181) : Error A2210: Syntax error: @DefProto
Cairo.inc(181): Included by
  Tmp_File.asm(2): Main line code
Cairo.inc(182) : Error A2210: Syntax error: @DefProto
Cairo.inc(182): Included by
  Tmp_File.asm(2): Main line code
Cairo.inc(183) : Error A2210: Syntax error: @DefProto
Cairo.inc(183): Included by
  Tmp_File.asm(2): Main line code
Cairo.inc(184) : Error A2210: Syntax error: @DefProto
Cairo.inc(184): Included by
  Tmp_File.asm(2): Main line code
Cairo.inc(185) : Error A2210: Syntax error: @DefProto
Cairo.inc(185): Included by
  Tmp_File.asm(2): Main line code
Cairo.inc(196) : Error A2210: Syntax error: @DefProto
Cairo.inc(196): Included by
  Tmp_File.asm(2): Main line code
Cairo.inc(202) : Error A2210: Syntax error: @DefProto
Cairo.inc(202): Included by
  Tmp_File.asm(2): Main line code
Cairo.inc(203) : Error A2210: Syntax error: @DefProto
Cairo.inc(203): Included by
  Tmp_File.asm(2): Main line code
Cairo.inc(210) : Error A2210: Syntax error: @DefProto
Cairo.inc(210): Included by
  Tmp_File.asm(2): Main line code
Cairo.inc(217) : Error A2210: Syntax error: @DefProto
Cairo.inc(217): Included by
  Tmp_File.asm(2): Main line code
Cairo.inc(218) : Error A2210: Syntax error: @DefProto
Cairo.inc(218): Included by
  Tmp_File.asm(2): Main line code
Cairo.inc(219) : Error A2210: Syntax error: @DefProto
Cairo.inc(219): Included by
  Tmp_File.asm(2): Main line code
Cairo.inc(220) : Error A2210: Syntax error: @DefProto
Cairo.inc(220): Included by
  Tmp_File.asm(2): Main line code
Cairo.inc(221) : Error A2210: Syntax error: @DefProto
Cairo.inc(221): Included by
  Tmp_File.asm(2): Main line code
Cairo.inc(222) : Error A2210: Syntax error: @DefProto
Cairo.inc(222): Included by
  Tmp_File.asm(2): Main line code
Cairo.inc(223) : Error A2210: Syntax error: @DefProto
Cairo.inc(223): Included by
  Tmp_File.asm(2): Main line code
Cairo.inc(224) : Error A2210: Syntax error: @DefProto
Cairo.inc(224): Included by
  Tmp_File.asm(2): Main line code
Cairo.inc(225) : Error A2210: Syntax error: @DefProto
Cairo.inc(225): Included by
  Tmp_File.asm(2): Main line code
Cairo.inc(226) : Error A2210: Syntax error: @DefProto
Cairo.inc(226): Included by
  Tmp_File.asm(2): Main line code
Cairo.inc(227) : Error A2210: Syntax error: @DefProto
Cairo.inc(227): Included by
  Tmp_File.asm(2): Main line code
Cairo.inc(228) : Error A2210: Syntax error: @DefProto
Cairo.inc(228): Included by
  Tmp_File.asm(2): Main line code
Cairo.inc(229) : Error A2210: Syntax error: @DefProto
Cairo.inc(229): Included by
  Tmp_File.asm(2): Main line code
Cairo.inc(230) : Error A2210: Syntax error: @DefProto
Cairo.inc(230): Included by
  Tmp_File.asm(2): Main line code
Cairo.inc(231) : Error A2210: Syntax error: @DefProto
Cairo.inc(231): Included by
  Tmp_File.asm(2): Main line code
Cairo.inc(232) : Error A2210: Syntax error: @DefProto
Cairo.inc(232): Included by
  Tmp_File.asm(2): Main line code
Cairo.inc(233) : Error A2210: Syntax error: @DefProto
Cairo.inc(233): Included by
  Tmp_File.asm(2): Main line code
Cairo.inc(234) : Error A2210: Syntax error: @DefProto
Cairo.inc(234): Included by
  Tmp_File.asm(2): Main line code
Cairo.inc(235) : Error A2210: Syntax error: @DefProto
Cairo.inc(235): Included by
  Tmp_File.asm(2): Main line code
Cairo.inc(236) : Error A2210: Syntax error: @DefProto
Cairo.inc(236): Included by
  Tmp_File.asm(2): Main line code
Cairo.inc(237) : Error A2210: Syntax error: @DefProto
Cairo.inc(237): Included by
  Tmp_File.asm(2): Main line code
Cairo.inc(238) : Error A2210: Syntax error: @DefProto
Cairo.inc(238): Included by
  Tmp_File.asm(2): Main line code
Cairo.inc(238) : Fatal error A1113: Too many errors
*** Assembly Error ***

TimoVJL

#3
A link for Cairo
EDIT: example compiled with PellesC 9
May the source be with you

Biterider

Hi JJ
I was able to compile a test application changing some of the symbols that point to nirvana. It seems to be a leftover from the windows translation.
I commented them out and I could compile.
Since I'm using a variation of the WinInc project with the most recent header files, I had no problems with the @DefProto macro. If you are using another source, like "MASM32 windows.inc", you have to define your own macro. Here the original:
  ifdef _WIN64
    WIN_STD_CALL_CONV equ <fastcall>
    @DefProto macro ApiQual, ProcName, CallConv, NameSuffix, Params, DecorSuffix
      ifdif <CallConv>, <vectorcall>
        ??CallConv equ <fastcall>
      else
        ??CallConv equ <&CallConv>
      endif

      ifidn <ApiQual>, <DllImport>                      ;;Call [IAT], a bit faster
        TYPE_&ProcName typedef proto ??CallConv Params
        externdef __imp_&ProcName: ptr TYPE_&ProcName
        ProcName&NameSuffix equ <__imp_&ProcName>
      else
        ProcName&NameSuffix proto ??CallConv Params     ;;Call thunk (jmp [IAT])
      endif
    endm
  else
    WIN_STD_CALL_CONV equ <stdcall>
    @DefProto macro ApiQual, ProcName, CallConv, NameSuffix, Params, DecorSuffix

      ifidn <ApiQual>, <DllImport>                      ;;Call [IAT], a bit faster
        TYPE_&ProcName typedef proto CallConv Params
        ifnb <DecorSuffix>
          externdef WIN_STD_CALL_CONV _imp__&ProcName&@&DecorSuffix: ptr TYPE_&ProcName
          ProcName&NameSuffix equ <_imp__&ProcName&@&DecorSuffix>
        else
          externdef c _imp__&ProcName: ptr TYPE_&ProcName
          ProcName&NameSuffix equ <_imp__&ProcName>
        endif
      else
        ProcName&NameSuffix proto CallConv Params       ;;Call thunk (jmp [IAT])
      endif
    endm
  endif


I noticed, that the symbol naming decoration of the import library is not the windows standard, so you have to change the macro to fit to cairo.lib.
I did it and found that the loader had some problems resolving some addresses.
I reuploaded the files to the previous post with the uncommented symbols.

Tomorrow I'll try to generate my own import lib with windows native tools. We will see...  :biggrin:

Biterider

jj2007

Quote from: Biterider on November 19, 2018, 12:20:45 AMTomorrow I'll try to generate my own import lib with windows native tools. We will see...  :biggrin:

Good luck :bgrin:

Quote from: TimoVJL on November 19, 2018, 12:09:35 AM
A link for Cairo

Thanks, Timo - that was actually the binary I was already using, it pops up on top for googling cairo windows binaries. Here is my first successful attempt:

GuiParas equ "Cairo demo", x550, y20, w160, h180, cblack, b RgbCol(255, 255, 160)
include \masm32\MasmBasic\Res\MbGui.asm         ; part of MasmBasic
Dll "\Masm32\Cairo\lib\x86\cairo.dll"  ; suggested path to the Dll
Declare cairo_version
Declare cairo_win32_surface_create, C:1
Declare cairo_create, C:1
Declare void cairo_rectangle, C:5
Declare void cairo_set_source_rgba, C:5
Declare void cairo_set_fill_rule, C:2
Declare void cairo_fill, C:1
Declare void cairo_destroy, C:1
Declare void cairo_surface_write_to_png, C:2
Declare void cairo_surface_destroy, C:1
Declare void cairo_status, C:1
Declare void cairo_surface_status, C:1
Declare void cairo_status_to_string, C:1
Enum 0:CAIRO_FILL_RULE_WINDING, CAIRO_FILL_RULE_EVEN_ODD
SetGlobals surface, context, double red, green, blue

Event Paint
  invoke TextOut, PtDC, 9, 5, Str$("Cairo version %i\n", cairo_version()), s$Len
  mov surface, cairo_win32_surface_create(PtDC)
  mov context, cairo_create(surface)
  cairo_rectangle(context, FP8(20.0), FP8(30.0), FP8(100.0), FP8(100.0))
  Rand(0.0, 1.0, red)
  Rand(0.0, 1.0, green)         ; generate random colours
  Rand(0.0, 1.0, blue)
  cairo_set_source_rgba(context, red, green, blue, FP8(0.5))    ; last arg is transparency
  cairo_set_fill_rule(context, CAIRO_FILL_RULE_EVEN_ODD)
  cairo_fill(context)
  cairo_destroy(context);
  ; cairo_surface_write_to_png(surface, "test.png")    ; saves client area to disk
  cairo_surface_destroy(surface);
GuiEnd


When sizing, you can see the random colours generated. I ran it with a timer and MemState, no leaks detected.

Source & exe attached, including my Pelles C test case (which works only when in the same folder as the DLL... :()

The DLL is 2MB, too big to be posted here; but all you need is cairo.dll from the link you posted (download), which I suggest to save to \Masm32\Cairo\lib\x86\cairo.dll for those who want to follow this thread.

HSE

A problem with Declare:
N:\jj\varios>asmC cairo2.asm
Asmc Macro Assembler Version 2.28.05
Copyright (C) The Asmc Contributors. All Rights Reserved.

Assembling: cairo2.asm
*** MasmBasic version 25.12.2017 ***
** SetProcessUserModeExceptionPolicy
## MasmBasic GUI build ##
cairo2.asm(5) : error A2091: index value past end of string
Declare(50)[MasmBasic.inc]: Macro called from
  cairo2.asm(5): Main line code
cairo2.asm(5) : error A2006: undefined symbol : ??03BB
Declare(51)[MasmBasic.inc]: Macro called from
  cairo2.asm(5): Main line code
cairo2.asm(5) : error A2091: index value past end of string
Declare(73)[MasmBasic.inc]: Macro called from
  cairo2.asm(5): Main line code
cairo2.asm(22) : error A2091: index value past end of string
cairo_version(6)[cairo2.asm]: Macro called from
  cairo2.asm(22): Main line code
cairo2.asm(22) : error A2006: undefined symbol : ??04A0
cairo_version(7)[cairo2.asm]: Macro called from
  cairo2.asm(22): Main line code
cairo2.asm(22) : error A2006: undefined symbol : ??04A0
cairo_version(99)[cairo2.asm]: Macro called from
  cairo2.asm(22): Main line code
cairo2.asm(22) : error A2006: undefined symbol : ??04A0
cairo_version(140)[cairo2.asm]: Macro called from
  cairo2.asm(22): Main line code
Equations in Assembly: SmplMath

jj2007

Quote from: HSE on November 19, 2018, 09:07:49 AM
A problem with Declare

Sorry, I haven't updated the package for a while. Attached the new Declare version, to be inserted after the Dll line.

HSE

Equations in Assembly: SmplMath

jj2007

If you are successful in testing other Cairo functions, please post them. I am curious if this lib offers any advantage over plain Gdi or Gdi+.

Complete Cairo API

P.S.: Try inserting a MakePath/GuiDraw element (resizable!):

SetGlobals surface, context, double red, green, blue
MakePath 111, Bezier(150:0, 0:90, 0:120, 300:300)
MakePen hPenBez, RgbCol(200, 160, 160, 0), width 4, startarrow LineCapRoundAnchor, endarrow 12:9, inset 2
Event Paint
  invoke TextOut, PtDC, 9, 5, Str$("Cairo version %i\n", cairo_version()), s$Len
  GuiDraw 111, hPenBez, 45.0, 25.0
  mov surface, cairo_win32_surface_create(PtDC)

Biterider

Hi
I got it working now after changing the calling convention!  ;)
I had to change the proto definition macro accordingly and all works fine now.

Attached is a demo that uses the code shown by JJ

Method CairoApp.OnPaint, uses esi, wParam:WPARAM, lParam:LPARAM
    local PS:PAINTSTRUCT, hDC:HDC, Rct:RECT
    local Surface:HANDLE, Context:HANDLE

    SetObject esi
    mov hDC, $invoke(BeginPaint, [esi].hWnd, addr PS)

    mov Surface, $invoke(cairo_win32_surface_create, hDC)
    mov Context, $invoke(cairo_create, Surface)
   
    invoke cairo_rectangle, Context, $CReal8(20.0), $CReal8(30.0), $CReal8(100.0), $CReal8(100.0)
    invoke cairo_set_source_rgba, Context, $CReal8(0.1), $CReal8(0.5), $CReal8(0.8), $CReal8(0.5)
    invoke cairo_set_fill_rule, Context, CAIRO_FILL_RULE_EVEN_ODD
    invoke cairo_fill, Context

    invoke cairo_rectangle, Context, $CReal8(50.0), $CReal8(60.0), $CReal8(100.0), $CReal8(100.0)
    invoke cairo_set_source_rgba, Context, $CReal8(0.3), $CReal8(0.7), $CReal8(0.8), $CReal8(0.5)
    invoke cairo_set_fill_rule, Context, CAIRO_FILL_RULE_EVEN_ODD
    invoke cairo_fill, Context

    invoke cairo_rectangle, Context, $CReal8(80.0), $CReal8(90.0), $CReal8(100.0), $CReal8(100.0)
    invoke cairo_set_source_rgba, Context, $CReal8(0.8), $CReal8(0.7), $CReal8(0.8), $CReal8(0.5)
    invoke cairo_set_fill_rule, Context, CAIRO_FILL_RULE_EVEN_ODD
    invoke cairo_fill, Context

    invoke cairo_destroy, Context
    invoke cairo_surface_destroy, Surface

    invoke GetClientRect, [esi].hWnd, addr Rct
    invoke DrawEdge, hDC, addr Rct, EDGE_SUNKEN, BF_RECT

    invoke EndPaint, [esi].hWnd, addr PS
    mov eax, TRUE
MethodEnd


To use the exe, put the cairo.dll in the same directory.

The rest is now experimenting with the API.

I reuploaded the modified include file set to the above post.

Biterider


jj2007

Quote from: Biterider on November 20, 2018, 06:45:59 AMI reuploaded the modified include file set to the above post.

Your exe works fine, but the includes still throw numerous errors despite using this macro as you suggested:
    WIN_STD_CALL_CONV equ <stdcall>
    @DefProto macro ApiQual, ProcName, CallConv, NameSuffix, Params, DecorSuffix

      ifidn <ApiQual>, <DllImport>                      ;;Call [IAT], a bit faster
        TYPE_&ProcName typedef proto CallConv Params
        ifnb <DecorSuffix>
          externdef WIN_STD_CALL_CONV _imp__&ProcName&@&DecorSuffix: ptr TYPE_&ProcName
          ProcName&NameSuffix equ <_imp__&ProcName&@&DecorSuffix>
        else
          externdef c _imp__&ProcName: ptr TYPE_&ProcName
          ProcName&NameSuffix equ <_imp__&ProcName>
        endif
      else
        ProcName&NameSuffix proto CallConv Params       ;;Call thunk (jmp [IAT])
      endif
    endm
include \Masm32\Cairo\cairo.inc


Biterider

Hi JJ
Cairo.inc contains the macro used for prototyping (@DefCairoProto). The one I posted is the standard for Windows API, which does not apply here. Theoretically, you do not have to add anything special to the include files.

For the posted application I simply used:
include .\Inc\cairo-win32.inc


The .inc files include the required files. Some of them are part of the windows header files. This is the case for Cairo_ft.inc. Others include Windows.inc. I did not test it with the masm32 set of include files. Maybe there is an incompatibility.
I used UASM as an assembler.
I have not experimented with SVG or PDF backends yet. I hope I can spend some time this weekend to play with them.

You can PM me sending the errors you are seeing and the context of your application. 8)
If there is of any use, I cam post the sources of the demo application.

Regards, Biterider

jj2007

Quote from: Biterider on November 20, 2018, 06:10:47 PMYou can PM me sending the errors you are seeing and the context of your application. 8)
Done.

QuoteIf there is of any use, I cam post the sources of the demo application.
That would certainly be interesting, thanks :icon14:

Biterider

Hi
Here are the sources of the demo application.
Biterider