2018-01-22 16:28:33 +00:00
|
|
|
#include "data/rasterizer.h"
|
2019-04-05 11:58:29 +00:00
|
|
|
#include "types.h"
|
2017-03-11 10:19:33 +00:00
|
|
|
#include "lib/map/map.h"
|
2017-02-03 23:16:30 +00:00
|
|
|
#include <stdint.h>
|
2019-01-30 05:49:49 +00:00
|
|
|
#include <stdbool.h>
|
2017-02-03 23:16:30 +00:00
|
|
|
|
2017-01-30 02:37:56 +00:00
|
|
|
#pragma once
|
|
|
|
|
2019-04-05 11:58:29 +00:00
|
|
|
struct Rasterizer;
|
|
|
|
struct Texture;
|
|
|
|
|
2019-04-05 11:27:48 +00:00
|
|
|
typedef map_t(Glyph) map_glyph_t;
|
|
|
|
|
2017-03-16 03:12:56 +00:00
|
|
|
typedef enum {
|
|
|
|
ALIGN_LEFT,
|
2018-12-27 21:50:42 +00:00
|
|
|
ALIGN_CENTER,
|
|
|
|
ALIGN_RIGHT
|
2017-03-16 03:12:56 +00:00
|
|
|
} HorizontalAlign;
|
|
|
|
|
|
|
|
typedef enum {
|
|
|
|
ALIGN_TOP,
|
2018-12-27 21:50:42 +00:00
|
|
|
ALIGN_MIDDLE,
|
|
|
|
ALIGN_BOTTOM
|
2017-03-16 03:12:56 +00:00
|
|
|
} VerticalAlign;
|
|
|
|
|
2017-02-03 23:16:30 +00:00
|
|
|
typedef struct {
|
2017-02-05 06:21:41 +00:00
|
|
|
int x;
|
|
|
|
int y;
|
|
|
|
int width;
|
|
|
|
int height;
|
|
|
|
int rowHeight;
|
|
|
|
int padding;
|
2017-02-19 09:54:58 +00:00
|
|
|
map_glyph_t glyphs;
|
2017-02-05 06:21:41 +00:00
|
|
|
} FontAtlas;
|
2017-02-03 23:16:30 +00:00
|
|
|
|
2019-04-05 11:58:29 +00:00
|
|
|
typedef struct Font {
|
2017-02-03 23:16:30 +00:00
|
|
|
Ref ref;
|
2019-04-05 11:58:29 +00:00
|
|
|
struct Rasterizer* rasterizer;
|
|
|
|
struct Texture* texture;
|
2017-02-05 06:21:41 +00:00
|
|
|
FontAtlas atlas;
|
2017-02-08 06:11:20 +00:00
|
|
|
map_int_t kerning;
|
2017-03-16 03:12:56 +00:00
|
|
|
float lineHeight;
|
2017-03-16 03:51:16 +00:00
|
|
|
float pixelDensity;
|
2019-01-30 05:49:49 +00:00
|
|
|
bool flip;
|
2017-01-30 02:37:56 +00:00
|
|
|
} Font;
|
2017-02-03 23:16:30 +00:00
|
|
|
|
2019-04-05 11:58:29 +00:00
|
|
|
Font* lovrFontInit(Font* font, struct Rasterizer* rasterizer);
|
2018-12-19 08:25:20 +00:00
|
|
|
#define lovrFontCreate(...) lovrFontInit(lovrAlloc(Font), __VA_ARGS__)
|
2018-02-26 08:59:03 +00:00
|
|
|
void lovrFontDestroy(void* ref);
|
2019-04-05 11:58:29 +00:00
|
|
|
struct Rasterizer* lovrFontGetRasterizer(Font* font);
|
2018-12-27 21:50:42 +00:00
|
|
|
void lovrFontRender(Font* font, const char* str, size_t length, float wrap, HorizontalAlign halign, float* vertices, uint16_t* indices, uint16_t baseVertex);
|
|
|
|
void lovrFontMeasure(Font* font, const char* string, size_t length, float wrap, float* width, uint32_t* lineCount, uint32_t* glyphCount);
|
2017-03-16 08:12:32 +00:00
|
|
|
float lovrFontGetHeight(Font* font);
|
|
|
|
float lovrFontGetAscent(Font* font);
|
|
|
|
float lovrFontGetDescent(Font* font);
|
|
|
|
float lovrFontGetBaseline(Font* font);
|
2017-02-12 11:14:10 +00:00
|
|
|
float lovrFontGetLineHeight(Font* font);
|
|
|
|
void lovrFontSetLineHeight(Font* font, float lineHeight);
|
2019-01-30 05:49:49 +00:00
|
|
|
bool lovrFontIsFlipEnabled(Font* font);
|
|
|
|
void lovrFontSetFlipEnabled(Font* font, bool flip);
|
2017-02-08 06:11:20 +00:00
|
|
|
int lovrFontGetKerning(Font* font, unsigned int a, unsigned int b);
|
2017-03-16 03:51:16 +00:00
|
|
|
float lovrFontGetPixelDensity(Font* font);
|
|
|
|
void lovrFontSetPixelDensity(Font* font, float pixelDensity);
|
2017-02-06 09:54:11 +00:00
|
|
|
Glyph* lovrFontGetGlyph(Font* font, uint32_t codepoint);
|
2017-02-06 04:30:17 +00:00
|
|
|
void lovrFontAddGlyph(Font* font, Glyph* glyph);
|
|
|
|
void lovrFontExpandTexture(Font* font);
|
2017-11-24 22:13:07 +00:00
|
|
|
void lovrFontCreateTexture(Font* font);
|