#pragma once

#include <efi.h>
#include <common.h>
#include <graphics/context.h>

// Opaque font face. Created by ttf_open() over a memory-mapped TTF blob.
typedef struct ttf_face ttf_face_t;

// Open a TrueType font from a memory buffer. Buffer must remain valid
// for the lifetime of the face. Returns NULL on parse failure.
ttf_face_t* ttf_open(const void* data, UINTN size);

// Free face. Does NOT free the source buffer.
void ttf_close(ttf_face_t* face);

// Vertical metrics in 26.6 fixed point, scaled to pixel_size.
SSINT32 ttf_ascender (ttf_face_t* face, SUINT32 pixel_size);
SSINT32 ttf_descender(ttf_face_t* face, SUINT32 pixel_size);
SSINT32 ttf_line_gap (ttf_face_t* face, SUINT32 pixel_size);

// Measure total advance width of a UTF-8 string at pixel_size (26.6 fp).
SSINT32 ttf_text_width(ttf_face_t* face, const char* utf8, SUINT32 pixel_size);

// Render a UTF-8 string onto the current draw target.
//   (x, y) = baseline origin in TARGET coordinates
//   pixel_size = nominal glyph height in pixels (e.g. 16, 24, 48)
//   color = foreground; alpha-blended over the current buffer
// Returns the total pen advance (26.6 fp) consumed.
SSINT32 ttf_draw_text(ttf_face_t* face, const char* utf8,
    SSINT32 x, SSINT32 y, SUINT32 pixel_size, EFI_GRAPHICS_OUTPUT_BLT_PIXEL color);
