typst-cffi 0.4.0

FFI to Typst
Documentation
// Copyright ©2025 The typst-cffi Authors. All rights reserved.
// Use of this source code is governed by a BSD-style
// license that can be found in the LICENSE file.


#include <stdarg.h>
#include <stdbool.h>
#include <stdint.h>
#include <stdlib.h>

typedef struct Context Context;

/**
 * # Safety
 *
 * typst_cffi_version returns the typst-cffi version "MAJOR.MINOR.PATCH".
 * The returned data is owned by Typst.
 */
const char *typst_cffi_version(void);

/**
 * # Safety
 *
 * typst_free drops all typst-managed memory for this Context.
 */
void typst_free(struct Context *ptr);

/**
 * # Safety
 *
 * typst_get_err returns the error message from Typst compilation, if any.
 * The returned message is owned by Typst.
 */
const char *typst_get_err(const struct Context *ptr);

/**
 * # Safety
 *
 * typst_get_buf returns the document produced by Typst compilation, if any.
 * The returned data is owned by Typst.
 */
const uint8_t *typst_get_buf(const struct Context *ptr, size_t *len);

/**
 * # Safety
 *
 * typst_get_npages returns the number of pages in the document produced by Typst compilation, if any.
 */
size_t typst_get_npages(const struct Context *ptr);

/**
 * # Safety
 *
 * typst_compile compiles the provided Typst document.
 * The returned Context is owned by Typst.
 */
struct Context *typst_compile(const char *src);

/**
 * # Safety
 *
 * typst_compile_pdf compiles the provided Typst document to PDF.
 * The returned Context is owned by Typst.
 */
void typst_compile_pdf(struct Context *ptr);

/**
 * # Safety
 *
 * typst_compile_png compiles the provided Typst document to PNG.
 * The returned Context is owned by Typst.
 */
void typst_compile_png(struct Context *ptr, size_t page, float ppi);

/**
 * # Safety
 *
 * typst_compile_svg compiles the provided Typst document to SVG.
 * The returned Context is owned by Typst.
 */
void typst_compile_svg(struct Context *ptr);