mirror of https://github.com/Chlumsky/msdfgen.git
87 lines
3.6 KiB
C
87 lines
3.6 KiB
C
#pragma once
|
|
|
|
/*
|
|
* MULTI-CHANNEL SIGNED DISTANCE FIELD GENERATOR
|
|
* ---------------------------------------------
|
|
* A utility by Viktor Chlumsky, (c) 2014 - 2024
|
|
*
|
|
* The technique used to generate multi-channel distance fields in this code
|
|
* has been developed by Viktor Chlumsky in 2014 for his master's thesis,
|
|
* "Shape Decomposition for Multi-Channel Distance Fields". It provides improved
|
|
* quality of sharp corners in glyphs and other 2D shapes compared to monochrome
|
|
* distance fields. To reconstruct an image of the shape, apply the median of three
|
|
* operation on the triplet of sampled signed distance values.
|
|
*/
|
|
|
|
#include "msdfgen-c.h"
|
|
|
|
/*
|
|
* A C-API modeled closely after the msdfgen C++ API
|
|
* to allow C-programs and other language runtimes to
|
|
* use the msdfgen library. Originally written for LWJGL.
|
|
*
|
|
* @since 11/05/2024
|
|
* @author Alexander Hinze
|
|
*/
|
|
|
|
MSDF_DEFINE_HANDLE_TYPE(msdf_ft);
|
|
MSDF_DEFINE_HANDLE_TYPE(msdf_ft_font);
|
|
|
|
#ifdef __cplusplus
|
|
extern "C" {
|
|
#endif
|
|
|
|
/**
|
|
* Initializes a new FreeType instance to be used with msdfgen.
|
|
* @param handle A pointer to a handle to be populated with a new FreeType context.
|
|
* @returns @code MSDF_SUCCESS@endcode on success, otherwise one of the constants prefixed with @code MSDF_ERR_@endcode.
|
|
*/
|
|
MSDF_API int msdf_ft_init(msdf_ft_handle* handle);
|
|
|
|
/**
|
|
* Loads a TrueType font from the given file(path) and populates
|
|
* the given font handle with the address of the newly loaded font.
|
|
* @param handle The handle to the FreeType context to use for loading the font.
|
|
* @param filename The name or path of/to the font file to load.
|
|
* @param font A pointer to a font handle to be populated with the address of the newly loaded font.
|
|
* @returns @code MSDF_SUCCESS@endcode on success, otherwise one of the constants prefixed with @code MSDF_ERR_@endcode.
|
|
*/
|
|
MSDF_API int msdf_ft_load_font(msdf_ft_handle handle, const char* filename, msdf_ft_font_handle* font);
|
|
|
|
/**
|
|
* Loads a TrueType font from the given buffer and populates
|
|
* the given font handle with the address of the newly loaded font.
|
|
* @param handle The handle to the FreeType context to use for loading the font.
|
|
* @param data A pointer to the raw data of the TrueType font to load.
|
|
* @param size The size of the data buffer in bytes.
|
|
* @param font A pointer to a font handle to be populated with the address of the newly loaded font.
|
|
* @returns @code MSDF_SUCCESS@endcode on success, otherwise one of the constants prefixed with @code MSDF_ERR_@endcode.
|
|
*/
|
|
MSDF_API int msdf_ft_load_font_data(msdf_ft_handle handle, const void* data, size_t size, msdf_ft_font_handle* font);
|
|
|
|
/**
|
|
* Loads a single glyph from the given font and converts it into a vector shape
|
|
* for rendering glyph sprites.
|
|
* @param font A handle to the font to use for generating the glyph shape.
|
|
* @param cp The codepoint to generate a shape for.
|
|
* @param shape A pointer to a handle to be populated with the address of the newly created shape.
|
|
* This shape must later be freed using msdf_shape_free!
|
|
* @returns @code MSDF_SUCCESS@endcode on success, otherwise one of the constants prefixed with @code MSDF_ERR_@endcode.
|
|
*/
|
|
MSDF_API int msdf_ft_font_load_glyph(msdf_ft_font_handle font, unsigned cp, msdf_shape_handle* shape);
|
|
|
|
/**
|
|
* Frees the underlying instance of the given FreeType font.
|
|
* @param handle The handle to the font to free.
|
|
*/
|
|
MSDF_API void msdf_ft_font_destroy(msdf_ft_font_handle handle);
|
|
|
|
/**
|
|
* Frees the underlying FreeType instance of the given context.
|
|
* @param handle The handle to the FreeType context to free.
|
|
*/
|
|
MSDF_API void msdf_ft_deinit(msdf_ft_handle handle);
|
|
|
|
#ifdef __cplusplus
|
|
}
|
|
#endif |