about summary refs log tree commit diff stats
path: root/src/bindings
diff options
context:
space:
mode:
authorbptato <nincsnevem662@gmail.com>2023-06-02 00:36:54 +0200
committerbptato <nincsnevem662@gmail.com>2023-06-05 03:58:21 +0200
commit8027e52cb221c432bed64517015ebf3182e6166d (patch)
tree18991f9e74c8dcfc0ed7439f3bc78a0cfec9b2d6 /src/bindings
parentb3b97465805b7367df461a4b7b830fabaccf3a89 (diff)
downloadchawan-8027e52cb221c432bed64517015ebf3182e6166d.tar.gz
Add support for canvas and multipart
Quite incomplete canvas implementation. Crucially, the layout engine
can't do much with whatever is drawn because it doesn't support images
yet.

I've re-introduced multipart as well, with the FormData API. For the
append function I've also introduced a hack to the JS binding generator
that allows requesting the JSContext pointer in nim procs. Really I
should just fix the union generator thing and add support for overloading.

In conclusion, for now the only thing canvas can be used for is exporting
it as PNG and uploading it somewhere. Also, we now have PNG encoding and
decoding too. (Now if only we had sixels as well...)
Diffstat (limited to 'src/bindings')
-rw-r--r--src/bindings/curl.nim2
-rw-r--r--src/bindings/zlib.nim79
2 files changed, 80 insertions, 1 deletions
diff --git a/src/bindings/curl.nim b/src/bindings/curl.nim
index ca31e4f2..169314fd 100644
--- a/src/bindings/curl.nim
+++ b/src/bindings/curl.nim
@@ -303,7 +303,7 @@ proc curl_mime_init*(handle: CURL): curl_mime
 proc curl_mime_free*(mime: curl_mime)
 proc curl_mime_addpart*(mime: curl_mime): curl_mimepart
 proc curl_mime_name*(part: curl_mimepart, name: cstring)
-proc curl_mime_data*(part: curl_mimepart, data: cstring, datasize: csize_t)
+proc curl_mime_data*(part: curl_mimepart, data: pointer, datasize: csize_t)
 proc curl_mime_filename*(part: curl_mimepart, name: cstring)
 proc curl_mime_filedata*(part: curl_mimepart, filename: cstring)
 
diff --git a/src/bindings/zlib.nim b/src/bindings/zlib.nim
new file mode 100644
index 00000000..00acb1ca
--- /dev/null
+++ b/src/bindings/zlib.nim
@@ -0,0 +1,79 @@
+const zlib = (func(): string =
+  let res = staticExec("pkg-config --libs --silence-errors zlib")
+  if res != "":
+    return res
+)()
+when zlib == "":
+  error("zlib not found")
+
+{.passL: zlib.}
+
+const
+  Z_NO_FLUSH* = cint(0)
+  Z_PARTIAL_FLUSH* = cint(1)
+  Z_SYNC_FLUSH* = cint(2)
+  Z_FULL_FLUSH* = cint(3)
+  Z_FINISH* = cint(4)
+  Z_BLOCK* = cint(5)
+  Z_TREES* = cint(6)
+
+const
+  Z_OK* = cint(0)
+  Z_STREAM_END* = cint(1)
+  Z_NEED_DICT* = cint(2)
+  Z_ERRNO* = cint(-1)
+  Z_STREAM_ERROR* = cint(-2)
+  Z_DATA_ERROR* = cint(-3)
+  Z_MEM_ERROR* = cint(-4)
+  Z_BUF_ERROR* = cint(-5)
+  Z_VERSION_ERROR* = cint(-6)
+
+const
+  Z_BINARY* = cint(0)
+  Z_TEXT* = cint(1)
+  Z_ASCII* = Z_TEXT
+  Z_UNKNOWN* = cint(2)
+
+type
+  alloc_func* {.importc, header: "zlib.h".} = proc (opaque: pointer,
+    items: cuint, size: cuint): pointer {.cdecl.}
+
+  free_func* {.importc, header: "zlib.h".} = proc (opaque: pointer,
+    address: pointer) {.cdecl.}
+
+  internal_state* {.importc, header: "zlib.h".} = object
+
+  z_stream* {.importc, header: "zlib.h".} = object
+    next_in*: ptr uint8 # next input byte
+    avail_in*: cuint # number of bytes available in next_in
+    total_in*: culong # total number of input bytes read so far
+
+    next_out*: ptr uint8 # next output byte will go here
+    avail_out*: cuint # remaining free space at next_out
+    total_out*: culong # total number of bytes output so far
+
+    msg*: cstring # last error message, NULL if no error
+    state*: ptr internal_state # not visible by applications
+
+    zalloc*: alloc_func # used to allocate the internal state
+    zfree*: free_func # used to free the internal state 
+    opaque*: pointer # private data object passed to zalloc and zfree 
+
+    data_type*: cint # best guess about the data type: binary or text
+                     # for deflate, or the decoding state for inflate 
+    adler*: culong # Adler-32 or CRC-32 value of the uncompressed data 
+    reserved*: culong # reserved for future use 
+
+  z_streamp* = ptr z_stream
+
+{.push header: "zlib.h", importc, cdecl.}
+proc inflateInit*(strm: z_streamp): cint
+proc inflate*(strm: z_streamp, flush: cint): cint
+proc inflateEnd*(strm: z_streamp): cint
+proc compress*(dest: ptr uint8, destLen: ptr culong, source: ptr uint8,
+  sourceLen: culong): cint
+proc compressBound*(sourceLen: culong): culong
+proc uncompress*(dest: ptr uint8, destLen: ptr culong, source: ptr uint8,
+  sourceLen: culong): cint
+proc crc32*(crc: culong, buf: ptr uint8, len: cuint): culong
+{.pop.}