2022-04-13 03:00:50 +00:00
|
|
|
/* Wellspring - An immediate mode font rendering system in C
|
2022-04-12 01:42:22 +00:00
|
|
|
*
|
|
|
|
* Copyright (c) 2022 Evan Hemsley
|
|
|
|
*
|
|
|
|
* This software is provided 'as-is', without any express or implied warranty.
|
|
|
|
* In no event will the authors be held liable for any damages arising from
|
|
|
|
* the use of this software.
|
|
|
|
*
|
|
|
|
* Permission is granted to anyone to use this software for any purpose,
|
|
|
|
* including commercial applications, and to alter it and redistribute it
|
|
|
|
* freely, subject to the following restrictions:
|
|
|
|
*
|
|
|
|
* 1. The origin of this software must not be misrepresented; you must not
|
|
|
|
* claim that you wrote the original software. If you use this software in a
|
|
|
|
* product, an acknowledgment in the product documentation would be
|
|
|
|
* appreciated but is not required.
|
|
|
|
*
|
|
|
|
* 2. Altered source versions must be plainly marked as such, and must not be
|
|
|
|
* misrepresented as being the original software.
|
|
|
|
*
|
|
|
|
* 3. This notice may not be removed or altered from any source distribution.
|
|
|
|
*
|
|
|
|
* Evan "cosmonaut" Hemsley <evan@moonside.games>
|
|
|
|
*
|
|
|
|
*/
|
|
|
|
|
|
|
|
#ifndef WELLSPRING_H
|
|
|
|
#define WELLSPRING_H
|
|
|
|
|
|
|
|
#ifdef _WIN32
|
|
|
|
#define WELLSPRINGAPI __declspec(dllexport)
|
|
|
|
#define WELLSPRINGCALL __cdecl
|
|
|
|
#else
|
|
|
|
#define WELLSPRINGAPI
|
|
|
|
#define WELLSPRINGCALL
|
|
|
|
#endif
|
|
|
|
|
|
|
|
#include <stdint.h>
|
|
|
|
|
|
|
|
#ifdef USE_SDL2
|
|
|
|
#include <SDL.h>
|
|
|
|
#endif
|
|
|
|
|
|
|
|
#ifdef __cplusplus
|
|
|
|
extern "C"
|
|
|
|
{
|
|
|
|
#endif /* __cplusplus */
|
|
|
|
|
|
|
|
/* Version API */
|
|
|
|
|
|
|
|
#define WELLSPRING_MAJOR_VERSION 0
|
2022-06-30 23:19:02 +00:00
|
|
|
#define WELLSPRING_MINOR_VERSION 3
|
2022-04-12 01:42:22 +00:00
|
|
|
#define WELLSPRING_PATCH_VERSION 0
|
|
|
|
|
|
|
|
#define WELLSPRING_COMPILED_VERSION ( \
|
|
|
|
(WELLSPRING_MAJOR_VERSION * 100 * 100) + \
|
|
|
|
(WELLSPRING_MINOR_VERSION * 100) + \
|
|
|
|
(WELLSPRING_PATCH_VERSION) \
|
|
|
|
)
|
|
|
|
|
|
|
|
WELLSPRINGAPI uint32_t Wellspring_LinkedVersion(void);
|
|
|
|
|
|
|
|
/* Type definitions */
|
|
|
|
|
2022-04-13 21:31:06 +00:00
|
|
|
typedef struct Wellspring_Font Wellspring_Font;
|
2022-04-12 19:08:37 +00:00
|
|
|
typedef struct Wellspring_TextBatch Wellspring_TextBatch;
|
2022-04-12 01:42:22 +00:00
|
|
|
|
|
|
|
typedef struct Wellspring_FontRange
|
|
|
|
{
|
|
|
|
uint32_t firstCodepoint;
|
|
|
|
uint32_t numChars;
|
|
|
|
uint8_t oversampleH;
|
|
|
|
uint8_t oversampleV;
|
|
|
|
} Wellspring_FontRange;
|
|
|
|
|
2022-04-12 19:08:37 +00:00
|
|
|
typedef struct Wellspring_Color
|
|
|
|
{
|
|
|
|
uint8_t r, g, b, a;
|
|
|
|
} Wellspring_Color;
|
2022-04-12 01:42:22 +00:00
|
|
|
|
2022-04-12 19:08:37 +00:00
|
|
|
typedef struct Wellspring_Vertex
|
|
|
|
{
|
|
|
|
float x, y, z;
|
|
|
|
float u, v;
|
|
|
|
uint8_t r, g, b, a;
|
|
|
|
} Wellspring_Vertex;
|
2022-04-12 01:42:22 +00:00
|
|
|
|
2022-04-13 21:31:06 +00:00
|
|
|
typedef struct Wellspring_Rectangle
|
|
|
|
{
|
|
|
|
float x;
|
|
|
|
float y;
|
|
|
|
float w;
|
|
|
|
float h;
|
|
|
|
} Wellspring_Rectangle;
|
|
|
|
|
|
|
|
typedef enum Wellspring_HorizontalAlignment
|
|
|
|
{
|
|
|
|
WELLSPRING_HORIZONTALALIGNMENT_LEFT,
|
|
|
|
WELLSPRING_HORIZONTALALIGNMENT_CENTER,
|
|
|
|
WELLSPRING_HORIZONTALALIGNMENT_RIGHT
|
|
|
|
} Wellspring_HorizontalAlignment;
|
|
|
|
|
|
|
|
typedef enum Wellspring_VerticalAlignment
|
|
|
|
{
|
2022-04-13 22:09:45 +00:00
|
|
|
WELLSPRING_VERTICALALIGNMENT_BASELINE,
|
2022-04-13 21:31:06 +00:00
|
|
|
WELLSPRING_VERTICALALIGNMENT_TOP,
|
|
|
|
WELLSPRING_VERTICALALIGNMENT_MIDDLE,
|
|
|
|
WELLSPRING_VERTICALALIGNMENT_BOTTOM
|
|
|
|
} Wellspring_VerticalAlignment;
|
|
|
|
|
2022-04-12 19:08:37 +00:00
|
|
|
/* API definition */
|
2022-04-12 01:42:22 +00:00
|
|
|
|
2022-04-13 21:31:06 +00:00
|
|
|
WELLSPRINGAPI Wellspring_Font* Wellspring_CreateFont(
|
2022-04-12 22:15:51 +00:00
|
|
|
const uint8_t *fontBytes,
|
2023-12-06 23:45:42 +00:00
|
|
|
uint32_t fontBytesLength,
|
|
|
|
const uint8_t *atlasJsonBytes,
|
2023-12-08 06:53:24 +00:00
|
|
|
uint32_t atlasJsonBytesLength,
|
2023-12-08 08:06:36 +00:00
|
|
|
float *pPixelsPerEm,
|
|
|
|
float *pDistanceRange
|
2022-04-12 01:42:22 +00:00
|
|
|
);
|
|
|
|
|
2022-04-12 19:08:37 +00:00
|
|
|
/* Batches are not thread-safe, recommend one batch per thread. */
|
2023-12-06 23:45:42 +00:00
|
|
|
WELLSPRINGAPI Wellspring_TextBatch* Wellspring_CreateTextBatch(void);
|
2022-04-12 19:08:37 +00:00
|
|
|
|
|
|
|
/* Also restarts the batch */
|
2022-04-13 00:03:59 +00:00
|
|
|
WELLSPRINGAPI void Wellspring_StartTextBatch(
|
|
|
|
Wellspring_TextBatch *textBatch,
|
2023-12-06 23:45:42 +00:00
|
|
|
Wellspring_Font *font
|
2022-04-13 00:03:59 +00:00
|
|
|
);
|
2022-04-12 19:08:37 +00:00
|
|
|
|
2022-04-13 21:31:06 +00:00
|
|
|
WELLSPRINGAPI uint8_t Wellspring_TextBounds(
|
2023-12-06 23:45:42 +00:00
|
|
|
Wellspring_Font *font,
|
2023-12-08 06:53:24 +00:00
|
|
|
int pixelSize,
|
2022-04-13 21:31:06 +00:00
|
|
|
Wellspring_HorizontalAlignment horizontalAlignment,
|
|
|
|
Wellspring_VerticalAlignment verticalAlignment,
|
|
|
|
const uint8_t *strBytes,
|
|
|
|
uint32_t strLengthInBytes,
|
|
|
|
Wellspring_Rectangle *pRectangle
|
|
|
|
);
|
|
|
|
|
2023-12-10 01:40:02 +00:00
|
|
|
WELLSPRINGAPI uint8_t Wellspring_AddToTextBatch(
|
2022-04-12 19:08:37 +00:00
|
|
|
Wellspring_TextBatch *textBatch,
|
2023-12-08 06:53:24 +00:00
|
|
|
int pixelSize,
|
2022-04-12 19:08:37 +00:00
|
|
|
Wellspring_Color *color,
|
2022-04-13 21:31:06 +00:00
|
|
|
Wellspring_HorizontalAlignment horizontalAlignment,
|
|
|
|
Wellspring_VerticalAlignment verticalAlignment,
|
2022-04-12 19:08:37 +00:00
|
|
|
const uint8_t *strBytes,
|
|
|
|
uint32_t strLengthInBytes
|
2022-04-12 01:42:22 +00:00
|
|
|
);
|
|
|
|
|
2022-04-12 22:15:51 +00:00
|
|
|
WELLSPRINGAPI void Wellspring_GetBufferData(
|
2022-04-12 19:08:37 +00:00
|
|
|
Wellspring_TextBatch *textBatch,
|
2022-06-30 20:18:17 +00:00
|
|
|
uint32_t* pVertexCount,
|
2022-04-12 23:38:09 +00:00
|
|
|
Wellspring_Vertex **pVertexBuffer,
|
|
|
|
uint32_t *pVertexBufferLengthInBytes,
|
|
|
|
uint32_t **pIndexBuffer,
|
|
|
|
uint32_t *pIndexBufferLengthInBytes
|
2022-04-12 19:08:37 +00:00
|
|
|
);
|
|
|
|
|
2022-04-12 22:15:51 +00:00
|
|
|
WELLSPRINGAPI void Wellspring_DestroyTextBatch(Wellspring_TextBatch *textBatch);
|
2022-04-13 21:31:06 +00:00
|
|
|
WELLSPRINGAPI void Wellspring_DestroyFont(Wellspring_Font *font);
|
2022-04-12 01:42:22 +00:00
|
|
|
|
|
|
|
#ifdef __cplusplus
|
|
|
|
}
|
|
|
|
#endif /* __cplusplus */
|
|
|
|
|
|
|
|
#endif /* WELLSPRING_H */
|