Mercurial > molko
view libcore/core/font.h @ 146:7d7ea7a9cf50
core: add theme_shallow function
author | David Demelier <markand@malikania.fr> |
---|---|
date | Wed, 14 Oct 2020 18:20:58 +0200 |
parents | 28d9bb62fcb1 |
children | b386d25832c8 |
line wrap: on
line source
/* * font.h -- basic font management * * Copyright (c) 2020 David Demelier <markand@malikania.fr> * * Permission to use, copy, modify, and/or distribute this software for any * purpose with or without fee is hereby granted, provided that the above * copyright notice and this permission notice appear in all copies. * * THE SOFTWARE IS PROVIDED "AS IS" AND THE AUTHOR DISCLAIMS ALL WARRANTIES * WITH REGARD TO THIS SOFTWARE INCLUDING ALL IMPLIED WARRANTIES OF * MERCHANTABILITY AND FITNESS. IN NO EVENT SHALL THE AUTHOR BE LIABLE FOR * ANY SPECIAL, DIRECT, INDIRECT, OR CONSEQUENTIAL DAMAGES OR ANY DAMAGES * WHATSOEVER RESULTING FROM LOSS OF USE, DATA OR PROFITS, WHETHER IN AN * ACTION OF CONTRACT, NEGLIGENCE OR OTHER TORTIOUS ACTION, ARISING OUT OF * OR IN CONNECTION WITH THE USE OR PERFORMANCE OF THIS SOFTWARE. */ #ifndef MOLKO_FONT_H #define MOLKO_FONT_H /** * \file font.h * \brief Basic font management. * \ingroup drawing */ #include <stdbool.h> #include <stddef.h> struct texture; /** * \brief Font style for rendering. */ enum font_style { FONT_STYLE_ANTIALIASED, /*!< Pretty antialiasing looking. */ FONT_STYLE_NONE /*!< No antialiasing. */ }; /** * \brief Font object. */ struct font { enum font_style style; /*!< (RW) Style for rendering. */ unsigned long color; /*!< (RW) Color for rendering. */ void *handle; /*!< (PV) Native handle. */ }; /** * Open font from path file. * * \pre font != NULL * \pre path != NULL * \param font the font to initialize * \param path the path to the font * \param size the desired size * \return False on errors. */ bool font_open(struct font *font, const char *path, unsigned int size); /** * Open font from memory buffer. * * \pre font != NULL * \pre buffer != NULL * \param font the font to initialize * \param buffer the memory buffer * \param buflen the memory buffer length * \param size the desired size * \warning The buffer must remain valid until font is closed * \return False on errors. */ bool font_openmem(struct font *font, const void *buffer, size_t buflen, unsigned int size); /** * Tells if the font was properly opened. * * \pre font != NULL * \param font the font to check * \return True if the native handle was opened. */ bool font_ok(const struct font *font); /** * Render some text into the texture. * * This function use the current color/style and other properties in the font * to render the texture. * * \pre font_ok(font) * \pre tex != NULL * \param font the font to use * \param tex the texture to generate * \param text the UTF-8 text * \return False on errors. */ bool font_render(struct font *font, struct texture *tex, const char *text); /** * Get the maximum height for all glyphs. * * \pre font_ok(font) * \param font the font handle * \return the height in pixels */ unsigned int font_height(const struct font *font); /** * Compute the text size required with this font. * * \pre font_ok(font) * \pre text != NULL * \param font the font object * \param text the UTF-8 text * \param w pointer to width (may be NULL) * \param h pointer to height (may be NULL) * \return false in case of error and pointers to w and h are left unmodified */ bool font_box(const struct font *font, const char *text, unsigned int *w, unsigned int *h); /** * Close the font. * * \pre font != NULL * \param font the font handle */ void font_finish(struct font *font); #endif /* !MOLKO_FONT_H */