46typedef enum : uint32_t {
59typedef enum :
size_t {
167 uint32_t word = (uint32_t)buf[*off];
200 uint16_t half = (uint16_t)buf[*off];
202 half = (uint16_t)(half | ((uint16_t)buf[*off] << (uint32_t)
k_priv_shift_8));
236 for (
size_t i = 0U; i < len; ++i) {
237 hash ^= (uint32_t)data[i];
270 buf[*off] = glyph->
style;
302 glyph->
style = buf[*off];
522 const uint8_t* content,
624 if ((engine ==
nullptr) || (out_bytes ==
nullptr)) {
627 if (engine->
in_use == 0U) {
667 if (engine->
in_use == 0U) {
670 if ((content ==
nullptr) && (content_len != 0U)) {
680 const uint8_t* content,
686 if ((engine ==
nullptr) || (out_buf ==
nullptr) || (out_len ==
nullptr)) {
694 if (out_cap < need) {
701 for (uint32_t i = 0U; i < engine->
glyph_count; ++i) {
704 for (uint32_t i = 0U; i < engine->
page_count; ++i) {
717 const uint8_t* content,
722 if ((engine ==
nullptr) || (buf ==
nullptr)) {
750 for (uint32_t i = 0U; i < key.
page_count; ++i) {
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_checksum_mismatch
Stored / transmitted checksum does not match computed value.
@ 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_not_found
Requested item not found (lookup / search missed).
@ 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.
static uint32_t internal_fnv1a(const void *key, uint32_t key_bytes)
FNV-1a hash of a key blob (the built-in default hash).
HTML / CSS reflow + paginate engine for the ra8d2 ereader.
ra8_err_t reflow_cache_size(const reflow_t *engine, size_t *out_bytes)
Report the exact serialised size of an engine's current layout.
static void internal_get_glyph(const uint8_t *buf, size_t *off, reflow_glyph_t *glyph)
Deserialise one glyph (20 bytes) and advance the cursor.
static void internal_get_header(const uint8_t *buf, priv_cache_key_t *key)
Parse the fixed-size header into a key struct.
static void internal_get_page(const uint8_t *buf, size_t *off, reflow_page_t *page)
Deserialise one page record (8 bytes) and advance the cursor.
static bool internal_key_matches(const reflow_t *engine, const priv_cache_key_t *key, const uint8_t *content, size_t content_len)
True when the blob's key matches the engine + supplied content.
static uint32_t internal_font_hash(const reflow_t *engine)
Hash the engine's font blob (0 when no font is bound).
ra8_err_t reflow_cache_serialize(const reflow_t *engine, const uint8_t *content, size_t content_len, uint8_t *out_buf, size_t out_cap, size_t *out_len)
Serialise the laid-out pages of engine into a keyed byte blob.
static void internal_put_u32(uint8_t *buf, size_t *off, uint32_t word)
Append a little-endian uint32_t and advance the cursor.
ra8_err_t reflow_cache_load(reflow_t *engine, const uint8_t *content, size_t content_len, const uint8_t *buf, size_t len)
Validate a cache blob and, if it matches, restore the layout.
static void internal_put_glyph(uint8_t *buf, size_t *off, const reflow_glyph_t *glyph)
Serialise one glyph (20 bytes) and advance the cursor.
static uint32_t internal_fnv1a(const uint8_t *data, size_t len)
32-bit FNV-1a hash over a byte range.
static size_t internal_blob_size(uint32_t glyph_count, uint32_t page_count)
Total serialised size for the given record counts.
static void internal_put_page(uint8_t *buf, size_t *off, const reflow_page_t *page)
Serialise one page record (8 bytes) and advance the cursor.
static uint32_t internal_get_u32(const uint8_t *buf, size_t *off)
Read a little-endian uint32_t and advance the cursor.
priv_cache_const_t
FNV-1a parameters and byte-extraction shifts / mask.
@ k_priv_shift_24
Shift to byte 3.
@ k_priv_fnv_offset
FNV-1a 32-bit offset basis.
@ k_priv_fnv_prime
FNV-1a 32-bit prime.
@ k_priv_byte_mask
Low-byte mask.
@ k_priv_shift_8
Shift to byte 1.
@ k_priv_shift_16
Shift to byte 2.
static void internal_put_header(uint8_t *buf, const reflow_t *engine, size_t content_len, uint32_t content_hash)
Write the fixed-size header (checksum left as a zero placeholder).
static ra8_err_t internal_parse_header(const uint8_t *buf, size_t len, priv_cache_key_t *key, size_t *need)
Validate a blob's header structure and report its total size.
static uint16_t internal_get_u16(const uint8_t *buf, size_t *off)
Read a little-endian uint16_t and advance the cursor.
static void internal_put_u16(uint8_t *buf, size_t *off, uint16_t half)
Append a little-endian uint16_t and advance the cursor.
priv_cache_off_t
Fixed byte offsets within the serialised header.
@ k_priv_checksum_off
Body-checksum field offset.
static ra8_err_t internal_cache_precheck(const reflow_t *engine, const uint8_t *content, size_t content_len)
Shared serialize/load precheck: init state, content args, and the #109 multi-face cache-bypass invari...
Import-time pagination cache for reflow (#79).
@ k_reflow_cache_page_bytes
Serialised bytes per page.
@ k_reflow_cache_glyph_bytes
Serialised bytes per glyph.
@ k_reflow_cache_header_bytes
Fixed header size, bytes.
@ k_reflow_cache_magic
Blob magic ('R''F''C''1').
@ k_reflow_cache_version
Serialised format version.
@ k_reflow_max_glyphs
Total positioned glyphs.
@ k_reflow_max_pages
Max paginated pages.
Parsed header / invalidation key of a cache blob.
uint16_t font_px
Body font size, pixels.
uint32_t body_checksum
FNV-1a of the record payload.
uint16_t viewport_h
Viewport height, pixels.
uint32_t glyph_count
Serialised glyph count.
uint32_t font_hash
FNV-1a of the font blob.
uint32_t version
Format version.
uint16_t viewport_w
Viewport width, pixels.
uint32_t link_color
Anchor text colour.
uint32_t body_color
Body text colour.
uint32_t content_hash
FNV-1a of the chapter bytes.
uint32_t magic
Format magic.
uint32_t font_len
Font blob length.
uint32_t content_len
Chapter byte length.
uint32_t page_count
Serialised page count.
One positioned glyph after layout.
uint8_t style
Font-style bitmask.
int32_t cp
Unicode code point.
uint32_t color
32-bit RGB colour.
int32_t x
Pixel column of glyph baseline-left.
uint16_t font_px
Pixel size used for this glyph.
int32_t y
Pixel row of glyph baseline.
Index range of glyphs that belong to one page.
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.
const uint8_t * font_data
TTF blob; outlives the engine.
uint32_t link_color
Anchor text colour (0xRRGGBB).
reflow_glyph_t glyphs[k_reflow_max_glyphs]
Positioned glyphs.
uint32_t glyph_count
Glyphs used.
reflow_page_t pages[k_reflow_max_pages]
Page index ranges.
uint8_t in_use
1 = initialized, 0 = closed.
size_t font_len
Length of font_data, bytes.
uint16_t font_px
Body font size in pixels.
uint16_t viewport_w
Viewport width, pixels.
const uint8_t * xhtml_buf
Last layout_chapter input.
uint16_t viewport_h
Viewport height, pixels.
size_t xhtml_len
Length of xhtml_buf.
uint32_t body_color
Body text colour (0xRRGGBB).
uint8_t face_count
Embedded face count (0 = single-face).