35#include "stb_truetype.h"
61 .active_font_px = engine->
font_px,
64 .page_first_glyph = 0U,
65 .page_first_image = 0U,
66 .line_first_glyph = 0U,
67 .line_has_content = 0U,
69 .reserved8 = {0U, 0U},
73 while (i < engine->token_count) {
107 if (engine ==
nullptr) {
110 if (engine->
in_use == 0U) {
151 const uint8_t* font_data,
158 if ((font_data ==
nullptr) || (out_engine ==
nullptr)) {
161 if ((viewport_w == 0U) || (viewport_h == 0U)) {
167 if (font_len < 16U) {
186 if (engine ==
nullptr) {
189 if (engine->
in_use == 0U) {
208 if (engine ==
nullptr) {
211 if (engine->
in_use == 0U) {
222 if (engine ==
nullptr) {
225 if (engine->
in_use == 0U) {
234 const uint8_t* xhtml_buf,
236 uint32_t* out_total_pages)
238 if ((engine ==
nullptr) || (xhtml_buf ==
nullptr) || (out_total_pages ==
nullptr)) {
241 if (engine->
in_use == 0U) {
244 if (xhtml_len == 0U) {
248 *out_total_pages = 0U;
269 if ((engine ==
nullptr) || (out_count ==
nullptr)) {
272 if (engine->
in_use == 0U) {
281 if (engine ==
nullptr) {
284 if (engine->
in_use == 0U) {
303 if ((engine ==
nullptr) || (font_data ==
nullptr)) {
306 if (engine->
in_use == 0U) {
316 const int32_t offset = stbtt_GetFontOffsetForIndex(font_data, 0);
326 stbtt_fontinfo probe;
327 if ((offset < 0) || (stbtt_InitFont(&probe, font_data, (
int)font_len, offset) == 0)) {
348 if ((engine ==
nullptr) || (blob ==
nullptr)) {
351 if (engine->
in_use == 0U) {
363 const int32_t offset = stbtt_GetFontOffsetForIndex(blob, 0);
373 stbtt_fontinfo probe;
374 if ((offset < 0) || (stbtt_InitFont(&probe, blob, (
int)len, offset) == 0)) {
Annotation-attribute framework macros for ra8-firmware.
#define RA8_INTERNAL
Marker that a function is intended to be static (file-local).
Error Code Definitions for ra8-firmware.
@ k_ra8_err_not_supported
Requested feature not compiled in, not wired, or not supported by this MCU variant.
@ k_ra8_err_no_mem
Static buffer exhausted (no dynamic memory on this project).
@ k_ra8_err_invalid_arg
Invalid function argument.
@ k_ra8_err_invalid_state
Module in wrong state for requested operation.
@ k_ra8_err_not_initialized
Module not initialized – _init() not yet called successfully.
@ k_ra8_ok
Success – operation completed with all postconditions satisfied.
@ k_ra8_err_null_ptr
Pointer was NULL where a valid pointer was required.
@ k_ra8_err_invalid_size
Invalid size parameter (too large, too small, or misaligned).
ra8_err_codes_t ra8_err_t
Canonical error-return type used by every ra8-firmware API.
sfnt (TrueType/OpenType) table-directory bounds guard for stb_truetype.
bool ra8_stbtt_sfnt_dir_in_bounds(const uint8_t *data, size_t len, uint32_t fontstart)
Verify that a font's sfnt table directory lies within its buffer.
HTML / CSS reflow + paginate engine for the ra8d2 ereader.
ra8_err_t reflow_parse_xhtml(reflow_t *engine, const uint8_t *xhtml_buf, size_t xhtml_len)
Parse the XHTML buffer into the engine's token stream.
Test-access surface for reflow internal helpers (MC/DC).
bool priv_reflow_internal_final_page_needed(uint32_t page_count, uint32_t token_count)
Decide whether the layout pass produced zero pages but the token stream was non-empty (must synthesis...
bool priv_reflow_internal_xhtml_invalid(const void *xhtml_buf, size_t xhtml_len)
Decide whether the cached XHTML buffer pointer/length pair is unusable for a re-flow (NULL pointer OR...
void priv_reflow_layout_build_link_rects(reflow_t *engine, const stbtt_fontinfo *font)
Implementation of priv_reflow_layout_build_link_rects() – per-page link runs.
ra8_err_t priv_reflow_layout_apply_token(reflow_t *engine, priv_cursor_t *cur, const stbtt_fontinfo *font, const reflow_token_t *tok)
Implementation of priv_reflow_layout_apply_token() – per-token switch.
bool priv_reflow_layout_finish_page(reflow_t *engine, priv_cursor_t *cur)
Implementation of priv_reflow_layout_finish_page() – flush + reset cursor.
void priv_reflow_layout_byte_zero(uint8_t *dst, size_t n)
Implementation of priv_reflow_layout_byte_zero() – bounded byte-walk.
ra8_err_t priv_reflow_layout_init_font(const reflow_t *engine, stbtt_fontinfo *out_font)
Implementation of priv_reflow_layout_init_font() – parse the TTF blob.
uint16_t priv_reflow_layout_line_height(uint16_t font_px)
Implementation of priv_reflow_layout_line_height() – scaled integer ratio.
ra8_err_t reflow_run_layout(reflow_t *engine)
Run the line-break + page-break pass over engine->tokens[].
ra8_err_t reflow_layout_chapter(reflow_t *engine, const uint8_t *xhtml_buf, size_t xhtml_len, uint32_t *out_total_pages)
Parse + lay out one chapter of XHTML.
ra8_err_t reflow_set_css_loader(reflow_t *engine, reflow_css_loader_fn loader, void *ctx)
Bind the external-stylesheet loader for <link rel="stylesheet">.
static ra8_err_t internal_layout_tokens(reflow_t *engine, const stbtt_fontinfo *font)
Run one pass over the token stream populating engine->glyphs[] and engine->pages[].
ra8_err_t reflow_bind_font(reflow_t *engine, const uint8_t *font_data, size_t font_len)
Implementation of reflow_bind_font() – validate then swap.
ra8_err_t reflow_set_font_size(reflow_t *engine, uint16_t new_font_px)
Change the body font size and re-flow the cached chapter.
ra8_err_t reflow_init(uint16_t viewport_w, uint16_t viewport_h, const uint8_t *font_data, size_t font_len, uint16_t font_px, uint32_t body_color, uint32_t link_color, reflow_t *out_engine)
Initialise a reflow engine for a given viewport / font.
ra8_err_t reflow_get_page_count(const reflow_t *engine, uint32_t *out_count)
Report the laid-out page count.
ra8_err_t reflow_set_image_loader(reflow_t *engine, reflow_image_loader_fn loader, void *ctx, ra8_img_arena_t *arena)
Bind an <img> byte loader + decode arena to enable image rendering.
ra8_err_t reflow_register_face(reflow_t *engine, uint8_t css_face_idx, const uint8_t *blob, size_t len)
Implementation of reflow_register_face() – validate then append.
ra8_err_t reflow_close(reflow_t *engine)
Release a previously initialized engine.
Cross-TU shared declarations for the reflow layout engine.
@ k_priv_min_chapter_pages
Floor for non-empty input.
ra8_err_t priv_reflow_layout_table(reflow_t *engine, priv_cursor_t *cur, const stbtt_fontinfo *font, uint32_t start, uint32_t *out_next)
Lay out a <table> token range as an equal-column grid.
@ k_reflow_tag_table
Table (grid layout).
ra8_err_t(* reflow_css_loader_fn)(void *ctx, const char *href, uint32_t href_len, const uint8_t **out_bytes, size_t *out_len)
External-stylesheet byte loader for <link rel="stylesheet" href>.
@ k_reflow_max_faces
Max embedded @font-face typefaces.
@ k_reflow_max_pages
Max paginated pages.
ra8_err_t(* reflow_image_loader_fn)(void *ctx, const char *href, uint32_t href_len, const uint8_t **out_bytes, size_t *out_len)
Resolve an <img src> href to its encoded image bytes.
@ k_reflow_margin_px
Page edge inset, pixels.
@ k_reflow_min_font_px
Smallest accepted font size.
@ k_reflow_max_font_px
Largest accepted font size.
@ k_reflow_min_font_bytes
Smallest plausible font blob.
@ k_reflow_align_left
Left (default, ragged right).
@ k_reflow_tok_block_start
Open of a block-flow element.
@ k_reflow_style_normal
No emphasis.
Mutable state carried through the layout loop.
uint32_t page_first_image
First image-box index of the active page.
uint32_t page_first_glyph
First glyph index of the active page.
Caller-owned bump arena backing a single image decode.
One registered embedded @font-face typeface (#109).
uint8_t css_face_idx
@font-face table index this blob satisfies.
const uint8_t * blob
TTF/OTF bytes; caller-owned, outlives engine.
size_t len
Length of blob, bytes.
uint32_t glyph_count
Number of glyphs in this page.
uint32_t glyph_first
Index of first glyph in this page.
Reflow / pagination engine state.
uint32_t page_count
Pages used.
reflow_image_loader_fn img_loader
<img> byte loader (NULL = off).
reflow_css_loader_fn css_loader
<link> CSS loader (NULL = off).
const uint8_t * font_data
TTF blob; outlives the engine.
ra8_img_arena_t * img_arena
Decode scratch (NULL = off).
uint32_t link_color
Anchor text colour (0xRRGGBB).
uint32_t glyph_count
Glyphs used.
reflow_page_t pages[k_reflow_max_pages]
Page index ranges.
uint32_t text_pool_used
Bytes consumed in text_pool.
uint32_t token_count
Tokens used.
reflow_face_t faces[k_reflow_max_faces]
Embedded @font-face set.
uint8_t in_use
1 = initialized, 0 = closed.
size_t font_len
Length of font_data, bytes.
void * img_loader_ctx
Opaque context for img_loader.
uint16_t font_px
Body font size in pixels.
uint16_t viewport_w
Viewport width, pixels.
reflow_token_t tokens[k_reflow_max_tokens]
Parsed tokens.
const uint8_t * xhtml_buf
Last layout_chapter input.
uint32_t anchor_count
Anchor positions used.
uint16_t viewport_h
Viewport height, pixels.
size_t xhtml_len
Length of xhtml_buf.
uint32_t body_color
Body text colour (0xRRGGBB).
uint32_t image_box_count
Image boxes used.
void * css_loader_ctx
Opaque context for css_loader.
uint32_t link_rect_count
Link rects used.
uint8_t face_count
Embedded face count (0 = single-face).
One parsed token in the engine's token stream.
uint8_t kind
reflow_token_kind_t.
uint8_t tag
reflow_html_tag_t (0 if N/A).