forked from Piraterna/aurix
Added font renderer and terminal emulator
This commit is contained in:
parent
bc4ec556e2
commit
dd4fda27bb
22 changed files with 1921 additions and 5151 deletions
|
@ -17,62 +17,75 @@
|
|||
/* SOFTWARE. */
|
||||
/*********************************************************************************/
|
||||
|
||||
// TODO: Remove this if statement once I fix stb_truetype compilation
|
||||
#if 0
|
||||
|
||||
#include <mm/mman.h>
|
||||
#include <arch/lib/math.h>
|
||||
#include <lib/string.h>
|
||||
#include <lib/assert.h>
|
||||
#include <vfs/vfs.h>
|
||||
#define FONT_IMPLEMENTATION
|
||||
#include <ui/ui.h>
|
||||
#include <ui/font.h>
|
||||
#include <print.h>
|
||||
#include <stdint.h>
|
||||
#include <stdbool.h>
|
||||
#include <stdint.h>
|
||||
|
||||
__attribute__((used)) static volatile int _fltused = 0;
|
||||
|
||||
#define STB_TRUETYPE_IMPLEMENTATION
|
||||
|
||||
#define STBTT_ifloor(x) _ifloor(x)
|
||||
#define STBTT_iceil(x) _iceil(x)
|
||||
#define STBTT_sqrt(x) _sqrt(x)
|
||||
#define STBTT_pow(x, y) _pow(x, y)
|
||||
#define STBTT_fmod(x, y) _fmod(x, y)
|
||||
#define STBTT_cos(x) _cos(x)
|
||||
#define STBTT_acos(x) _acos(x)
|
||||
#define STBTT_fabs(x) __builtin_fabs(x)
|
||||
|
||||
#define STBTT_malloc(x, u) ((void)(u), mem_alloc(x))
|
||||
#define STBTT_free(x, u) ((void)(u), mem_free(x))
|
||||
|
||||
#define STBTT_assert(x) assert(x, #x)
|
||||
#define STBTT_strlen(x) strlen(x)
|
||||
|
||||
#define STBTT_memcpy memcpy
|
||||
#define STBTT_memset memset
|
||||
|
||||
#include "stb_truetype.h"
|
||||
|
||||
unsigned char *font_buf = NULL;
|
||||
stbtt_fontinfo font_info;
|
||||
float font_scale;
|
||||
int font_ascent, font_descent;
|
||||
int font_linegap;
|
||||
int font_size;
|
||||
|
||||
void font_init(char *font_path, int initial_size)
|
||||
bool font_init(struct ui_context *ctx, char *font_path, int size)
|
||||
{
|
||||
vfs_read(font_path, &font_buf);
|
||||
vfs_read(font_path, &(ctx->font_file));
|
||||
if (!ctx->font_file) {
|
||||
return false;
|
||||
}
|
||||
|
||||
int ssfn_status;
|
||||
|
||||
ssfn_status = ssfn_load(&(ctx->font), (void *)(ctx->font_file));
|
||||
if (ssfn_status != SSFN_OK) {
|
||||
debug("font_init(): SSFN failed to load font: %s!\n", ssfn_error(ssfn_status));
|
||||
goto error;
|
||||
}
|
||||
|
||||
ssfn_status = ssfn_select(&(ctx->font), SSFN_FAMILY_ANY, NULL, SSFN_STYLE_REGULAR, size);
|
||||
if (ssfn_status != SSFN_OK) {
|
||||
debug("font_init(): SSFN failed to select font: %s!\n", ssfn_error(ssfn_status));
|
||||
goto error;
|
||||
}
|
||||
|
||||
// initialize terminal
|
||||
ctx->terminal.font_size = size;
|
||||
ctx->terminal.cx = 0;
|
||||
ctx->terminal.cy = size;
|
||||
|
||||
return true;
|
||||
|
||||
error:
|
||||
mem_free(ctx->font_file);
|
||||
return false;
|
||||
}
|
||||
|
||||
void font_write(struct ui_context *ctx, char *s, uint32_t cx, uint32_t cy)
|
||||
{
|
||||
ctx->font_buf.x = cx;
|
||||
ctx->font_buf.y = cy;
|
||||
ssfn_render(&(ctx->font), &(ctx->font_buf), s);
|
||||
}
|
||||
|
||||
void font_free(struct ui_context *ctx)
|
||||
{
|
||||
ssfn_free(&(ctx->font));
|
||||
mem_free(ctx->font_file);
|
||||
}
|
||||
|
||||
/*
|
||||
void font_ttf_init(char *font_path, int initial_size)
|
||||
{
|
||||
vfs_read(font_path, (char **)&font_buf);
|
||||
if (!font_buf) {
|
||||
debug("Font not loaded, returning...\n");
|
||||
return;
|
||||
}
|
||||
|
||||
font_size = initial_size;
|
||||
|
||||
stbtt_InitFont(&font_info, &font_buf, 0);
|
||||
font_scale = stbtt_ScaleForPixelHeight(&font_info, font_size);
|
||||
stbtt_GetFontVMetrics(&font_info, &font_ascent, &font_descent, &font_linegap);
|
||||
font_ascent *= font_scale;
|
||||
font_descent *= font_scale;
|
||||
}
|
||||
|
||||
#endif
|
||||
void font_psf2_init()
|
||||
{
|
||||
}
|
||||
*/
|
Loading…
Add table
Add a link
Reference in a new issue