VitoVan / pango-cairo-wasm

PangoCairo on the Web
https://vitovan.com/pango-cairo-wasm/
Do What The F*ck You Want To Public License
10 stars 4 forks source link

JavaScript Bindings #1

Closed jlarmstrongiv closed 1 year ago

jlarmstrongiv commented 1 year ago

Really cool that you were able to compile pango and cairo to wasm 🚀

I noticed that the pango layout is defined in https://github.com/VitoVan/pango-cairo-wasm/blob/main/hello-pangocairo.c#L112

Is there a JavaScript API for pango? It’d be great to be able to call pango_layout from the JS side

VitoVan commented 1 year ago

I didn't expose the JavaScript API by default.

But all you need is to add the expected functions into the list of "-s EXPORTED_FUNCTIONS=_main, ...`.

Here is a live example:

https://github.com/VitoVan/calm/blob/637bdc6abcdba2fa79ba03b3efe3919af250e416/s/usr/web/wasm.lisp#L47-L68

In the above example, it exposed some Cairo functions such as: cairo_create, cairo_reference and cairo_destroy.

Pango should be the same.

To know more about exposing C APIs to JavaScript, please check this:

https://emscripten.org/docs/porting/connecting_cpp_and_javascript/Interacting-with-code.html?highlight=exported_functions#calling-compiled-c-functions-from-javascript-using-ccall-cwrap

I hope this could help.

jlarmstrongiv commented 1 year ago

Thank you @VitoVan ! I really appreciate the examples 😄 I’ll close this issue while I try that out

VitoVan commented 1 year ago

Thank you @VitoVan ! I really appreciate the examples 😄 I’ll close this issue while I try that out

I'm glad it helped.

Feel free to let me know if you encountered any problem.