ra8-firmware 0.1.0
Bare-metal firmware for the Renesas RA8 family (RA8D2 / RA8P1)
Loading...
Searching...
No Matches
reflow_types.h
Go to the documentation of this file.
1
22
23#pragma once
24
25#include <stddef.h>
26#include <stdint.h>
27
28#include "ra8_err.h"
29#include "ra8_glyph_atlas.h" /* ra8_glyph_atlas_t for the Layer-3 glyph cache (#164) */
30#include "reflow_css.h" /* ra8_css_sheet_t for the content-CSS cascade (#111) */
31#include "reflow_image.h" /* ra8_img_arena_t for the decode scratch */
32
33/* ===========================================================================
34 * Compile-time limits
35 * ===========================================================================
36 */
37
59
87
124
141
153typedef enum : uint8_t {
157
174
193
194/* ===========================================================================
195 * Forward declarations (opaque payloads)
196 * ===========================================================================
197 */
198
208typedef enum : uint32_t {
211
220typedef struct {
221 uint8_t kind;
222 uint8_t tag;
223 uint8_t style;
224 uint8_t reserved;
225 uint32_t text_off;
226 uint32_t text_len;
227 uint32_t color;
228 uint16_t css_font_px;
229 uint16_t reserved16;
231
241typedef struct {
242 int32_t x;
243 int32_t y;
244 int32_t cp;
245 uint32_t color;
246 uint16_t font_px;
247 uint8_t style;
248 uint8_t reserved;
250
255typedef struct {
256 uint32_t glyph_first;
257 uint32_t glyph_count;
259
272typedef struct {
273 int32_t x;
274 int32_t y;
275 int32_t w;
276 int32_t h;
277 uint32_t src_off;
278 uint32_t src_len;
279 uint32_t page_index;
280 uint32_t reserved;
282
305 const char* href,
306 uint32_t href_len,
307 const uint8_t** out_bytes,
308 size_t* out_len);
309
334typedef ra8_err_t (*reflow_css_loader_fn)(void* ctx,
335 const char* href,
336 uint32_t href_len,
337 const uint8_t** out_bytes,
338 size_t* out_len);
339
348typedef struct {
349 uint32_t href_off;
350 uint32_t href_len;
352
361typedef struct {
362 int32_t x;
363 int32_t y;
364 int32_t w;
365 int32_t h;
366 uint32_t target;
367 uint32_t page_index;
369
377typedef struct {
378 uint32_t id_off;
379 uint32_t id_len;
380 uint32_t page_index;
381 int32_t y;
383
395
396/* ===========================================================================
397 * Engine handle
398 * ===========================================================================
399 */
400
411typedef enum : uint8_t {
414
427typedef struct {
428 const uint8_t* blob;
429 size_t len;
430 uint8_t css_face_idx;
433
448typedef struct {
449 /* --- viewport + style ------------------------------------------------ */
450 uint16_t viewport_w;
451 uint16_t viewport_h;
452 uint16_t font_px;
453 uint16_t reserved16;
454 uint32_t body_color;
455 uint32_t link_color;
456
457 /* --- font (caller-owned TTF blob) ------------------------------------ */
458 const uint8_t* font_data;
459 size_t font_len;
461 uint8_t face_count;
462
463 /* --- cached chapter input ------------------------------------------- */
464 const uint8_t* xhtml_buf;
465 size_t xhtml_len;
466
467 /* --- token stream --------------------------------------------------- */
469 uint32_t token_count;
471 uint32_t text_pool_used;
472
473 /* --- laid-out glyphs ------------------------------------------------ */
475 uint32_t glyph_count;
477 uint32_t page_count;
478
479 /* --- image rendering (#106) ---------------------------------------- */
489
490 /* --- hyperlinks + anchors (#110) ----------------------------------- */
496 uint32_t anchor_count;
497
498 /* --- content CSS cascade (#111) ------------------------------------ */
500
501 /* --- glyph atlas (Layer-3 cache, #164) ----------------------------- */
503
504 /* --- lifecycle ------------------------------------------------------ */
505 uint8_t in_use;
506 uint8_t reserved8[3];
507} reflow_t;
Error Code Definitions for ra8-firmware.
ra8_err_codes_t ra8_err_t
Canonical error-return type used by every ra8-firmware API.
Definition ra8_err.h:546
Fixed-RAM-budget glyph cache with LRU eviction (Layer 3, #147).
Minimal content-CSS cascade for the reflow ereader engine (#111).
Zero-heap raster image decode + scale + blit for reflow (#106).
reflow_html_tag_t
Recognised HTML element kinds.
@ k_reflow_tag_i
Italic (inline).
@ k_reflow_tag_th
Table header cell.
@ k_reflow_tag_td
Table cell.
@ k_reflow_tag_blockquote
Blockquote indent.
@ k_reflow_tag_p
Paragraph block.
@ k_reflow_tag_h5
Heading level 5.
@ k_reflow_tag_h1
Heading level 1.
@ k_reflow_tag_strong
Bold emphasis (inline).
@ k_reflow_tag_hr
Horizontal rule (void).
@ k_reflow_tag_link
<link> (void; stylesheet ref).
@ k_reflow_tag_h4
Heading level 4.
@ k_reflow_tag_tr
Table row.
@ k_reflow_tag_ul
Unordered list block.
@ k_reflow_tag_li
List item.
@ k_reflow_tag_table
Table (grid layout).
@ k_reflow_tag_em
Italic emphasis (inline).
@ k_reflow_tag_b
Bold (inline).
@ k_reflow_tag_h2
Heading level 2.
@ k_reflow_tag_h6
Heading level 6.
@ k_reflow_tag_br
Line break (void).
@ k_reflow_tag_img
Image (placeholder rect).
@ k_reflow_tag_h3
Heading level 3.
@ k_reflow_tag_ol
Ordered list block.
@ k_reflow_tag_a
Anchor (renders underlined).
@ k_reflow_tag_unknown
Anything not in this enum.
reflow_color_t
Sentinel marking a token / run with no CSS colour.
@ k_reflow_color_inherit
No per-run CSS colour.
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>.
reflow_limits_t
Static-allocation caps for the reflow engine.
@ k_reflow_max_tokens
Max parsed token count.
@ k_reflow_max_anchors
Max id= anchor positions.
@ k_reflow_max_link_rects
Max positioned link rectangles.
@ k_reflow_max_faces
Max embedded @font-face typefaces.
@ k_reflow_max_images
Max laid-out <img> boxes.
@ k_reflow_max_links
Max distinct <a href> per chapter.
@ k_reflow_max_glyphs
Total positioned glyphs.
@ k_reflow_text_pool_bytes
Bytes of text pool.
@ k_reflow_max_lines_per_page
Lines per page upper bound.
@ 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.
reflow_layout_t
Layout-axis named constants used by the line-break engine.
@ k_reflow_paragraph_gap_px
Vertical gap after a block.
@ k_reflow_margin_px
Page edge inset, pixels.
@ k_reflow_h6_scale_pct
H6 size = 100 % of body.
@ k_reflow_h2_scale_pct
H2 size = 175 % of body.
@ k_reflow_h5_scale_pct
H5 size = 110 % of body.
@ k_reflow_h1_scale_pct
H1 size = 200 % of body.
@ k_reflow_min_font_px
Smallest accepted font size.
@ k_reflow_h4_scale_pct
H4 size = 125 % of body.
@ k_reflow_h3_scale_pct
H3 size = 150 % of body.
@ k_reflow_default_font_px
Default body font size.
@ k_reflow_line_spacing_den
Line height denominator.
@ k_reflow_line_spacing_num
Line height numerator (= 1.2x).
@ k_reflow_max_font_px
Largest accepted font size.
@ k_reflow_indent_px
Indent for blockquote / li.
@ k_reflow_min_font_bytes
Smallest plausible font blob.
@ k_reflow_pct_full
Percentage denominator.
reflow_face_pad_t
Padding geometry for reflow_face_t.
@ k_reflow_face_pad8
Pad bytes to reach an 8-byte struct stride.
reflow_align_t
Block text alignment (from an inline style="text-align:...").
@ k_reflow_align_center
Centred.
@ k_reflow_align_justify
Justified (last line left-aligned).
@ k_reflow_align_right
Right-aligned.
@ k_reflow_align_left
Left (default, ragged right).
reflow_token_kind_t
Parsed token classification.
@ k_reflow_tok_block_end
Close of a block-flow element.
@ k_reflow_tok_break
Forced line break (<br>).
@ k_reflow_tok_image
Image placeholder (<img>).
@ k_reflow_tok_text
Text run (slice into pool).
@ k_reflow_tok_block_start
Open of a block-flow element.
@ k_reflow_tok_rule
Horizontal rule (<hr>).
reflow_font_style_t
Inline font-style flags (bitfield).
@ k_reflow_style_italic
Italic face.
@ k_reflow_style_normal
No emphasis.
@ k_reflow_style_bold
Bold face.
@ k_reflow_style_underline
Underlined run.
reflow_face_pack_t
How a per-run embedded-face index is packed into a glyph/token style.
@ k_reflow_face_shift
Bit position of the face index in style.
@ k_reflow_face_mask
Face-index mask once shifted down.
reflow_href_kind_t
Classification of an in-content <a href> target.
@ k_reflow_href_fragment
"#id" – same-chapter anchor.
@ k_reflow_href_chapter_fragment
"path#id" – chapter + anchor.
@ k_reflow_href_empty
Empty / whitespace-only href.
@ k_reflow_href_chapter
"path" – another chapter, no frag.
@ k_reflow_href_external
Has a URI scheme (http:, mailto:).
A parsed stylesheet: rule + @font-face arrays and a name byte pool.
Definition reflow_css.h:212
Glyph-cache state (caller-owned; treat as private).
Caller-owned bump arena backing a single image decode.
A laid-out element id, for same-chapter #fragment jumps.
uint32_t page_index
Page the id landed on.
uint32_t id_len
Id slice length, bytes.
uint32_t id_off
Id slice offset into the text pool.
int32_t y
Page-local top y of the element.
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.
uint8_t pad8[k_reflow_face_pad8]
Padding to an 8-byte stride.
size_t len
Length of blob, bytes.
One positioned glyph after layout.
uint8_t style
Font-style bitmask.
uint8_t reserved
Padding.
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.
One laid-out <img> rectangle (decoded + blitted at render time).
uint32_t src_len
Href slice length, bytes.
int32_t y
Page-local top edge, pixels.
int32_t x
Page-local left edge, pixels.
uint32_t page_index
Page this image belongs to.
uint32_t reserved
Padding to 32-byte stride.
int32_t w
Scaled box width, pixels.
uint32_t src_off
Href slice offset into text pool.
int32_t h
Scaled box height, pixels.
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.
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).
reflow_glyph_t glyphs[k_reflow_max_glyphs]
Positioned glyphs.
uint32_t glyph_count
Glyphs used.
reflow_link_rect_t link_rects[k_reflow_max_link_rects]
Tappable rects.
reflow_page_t pages[k_reflow_max_pages]
Page index ranges.
uint8_t text_pool[k_reflow_text_pool_bytes]
Text bytes.
ra8_css_sheet_t css
Parsed <style> rules for the chapter.
uint32_t text_pool_used
Bytes consumed in text_pool.
uint32_t link_target_count
Interned link targets.
uint32_t token_count
Tokens used.
reflow_face_t faces[k_reflow_max_faces]
Embedded @font-face set.
reflow_anchor_t anchors[k_reflow_max_anchors]
id= anchor positions.
ra8_glyph_atlas_t * glyph_atlas
Glyph bitmap cache, or NULL for direct raster.
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 reserved16
Padding.
reflow_link_target_t link_targets[k_reflow_max_links]
Distinct hrefs.
uint16_t viewport_h
Viewport height, pixels.
size_t xhtml_len
Length of xhtml_buf.
uint8_t reserved8[3]
Padding.
reflow_image_box_t image_boxes[k_reflow_max_images]
Laid-out images.
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.
uint16_t css_font_px
Block-start CSS font px (0 = none -> UA default).
uint32_t text_off
Byte offset into the text pool.
uint32_t text_len
Byte length within the text pool.
uint32_t color
0xRRGGBB CSS colour, or k_reflow_color_inherit.
uint8_t kind
reflow_token_kind_t.
uint8_t tag
reflow_html_tag_t (0 if N/A).
uint8_t style
Font-style bitmask.
uint16_t reserved16
Padding to 4-byte stride.
uint8_t reserved
Block align / <a> link id.