133 const size_t inner = *pi +
strlen(
"<![CDATA[");
134 size_t close = inner;
135 while (((close + 3U) <= len) &&
136 !((buf[close] == (uint8_t)
']') && (buf[close + 1U] == (uint8_t)
']') &&
137 (buf[close + 2U] == (uint8_t)
'>'))) {
143 for (
size_t k = inner; k < close; ++k) {
161 *pi = ((close + 3U) <= len) ? (close + 3U) : len;
188 while ((i < len) && (buf[i] != (uint8_t)
'>')) {
191 *pi = (i < len) ? (i + 1U) : len;
239 const size_t nstart = i;
240 while ((i < len) && (buf[i] != (uint8_t)
'>') && (buf[i] != (uint8_t)
'/') &&
246 while ((i < len) && (buf[i] != (uint8_t)
'>')) {
247 const char c = (char)buf[i];
248 if ((c ==
'"') || (c ==
'\'')) {
250 while ((i < len) && (buf[i] != (uint8_t)c)) {
253 }
else if ((c ==
'/') && ((i + 1U) < len) && (buf[i + 1U] == (uint8_t)
'>')) {
260 *pi = (i < len) ? (i + 1U) : len;
294 uint16_t css_font_px)
300 uint32_t id_off = 0U;
301 uint32_t id_len = 0U;
322 uint32_t href_off = 0U;
323 uint32_t href_len = 0U;
363 const uint8_t* tagbuf = &buf[tag_lt];
364 const size_t span = (end > tag_lt) ? (end - tag_lt) : 0U;
367 size_t href_off = 0U;
368 size_t href_len = 0U;
374 const uint8_t* css_bytes =
nullptr;
377 (
const char*)&tagbuf[href_off],
381 (css_bytes !=
nullptr) && (css_len > 0U)) {
443 uint32_t src_off = 0U;
444 uint32_t src_len = 0U;
445 const size_t span = (end > tag_lt) ? (end - tag_lt) : 0U;
529 const uint8_t* tagbuf,
550 const uint8_t n_anc = (uint8_t)(ctx->
sp - 1U);
606 const size_t tag_lt = *pi;
607 bool selfclose =
false;
632 const size_t span = (*pi > tag_lt) ? (*pi - tag_lt) : 0U;
669static bool internal_tag_is(
const uint8_t* buf,
size_t i,
size_t len,
const char* name)
674 const size_t n =
strlen(name);
675 if ((i + n) >= len) {
678 const char c = (char)buf[i + n];
709 const char* close_lit,
715 if (is_style && (close_at > open_end)) {
717 (
const char*)&buf[open_end],
718 (uint32_t)(close_at - open_end));
720 *pi = (close_at < len) ? (close_at +
strlen(close_lit)) : len;
768 if (((*pi + 1U) < len) && (buf[*pi + 1U] == (uint8_t)
'/')) {
829 if ((engine ==
nullptr) || (xhtml_buf ==
nullptr)) {
832 if (xhtml_len == 0U) {
851 while (i < xhtml_len) {
852 if (xhtml_buf[i] == (uint8_t)
'<') {
859 const size_t run = i;
860 while ((i < xhtml_len) && (xhtml_buf[i] != (uint8_t)
'<')) {
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_no_mem
Static buffer exhausted (no dynamic memory on this project).
@ k_ra8_err_validation_failed
Validation rule failed (caller-supplied invariant not satisfied).
@ 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.
size_t strlen(const char *s)
Calculate string length.
HTML / CSS reflow + paginate engine for the ra8d2 ereader.
ra8_css_style_t ra8_css_cascade_ctx(const ra8_css_sheet_t *sheet, const ra8_css_element_t *el, ra8_css_style_t inherited, ra8_css_style_t inline_decl, const ra8_css_element_t *ancestors, uint8_t n_anc)
Compute an element's cascaded style with descendant-selector context.
@ k_ra8_css_set_fontsize
font-size was declared.
@ k_ra8_css_set_align
text-align was declared.
@ k_ra8_css_set_display
display was declared.
@ k_ra8_css_set_color
color was declared.
@ k_ra8_css_set_family
font-family was declared.
ra8_err_t ra8_css_sheet_reset(ra8_css_sheet_t *sheet)
Reset a stylesheet to empty (no rules, no names, order 0).
ra8_err_t ra8_css_parse(ra8_css_sheet_t *sheet, const char *css, uint32_t len)
Parse one <style> block's CSS text, appending rules to sheet.
ra8_css_font_unit_t
How a declared font-size value is interpreted.
@ k_ra8_css_font_pct
Value is a percentage of inherited px.
static ra8_err_t internal_handle_lt(tok_ctx_t *ctx, const uint8_t *buf, size_t *pi, size_t len)
Dispatch the markup construct beginning at buf[*pi] == '<'.
ra8_err_t priv_reflow_xml_walk(reflow_t *engine, const uint8_t *xhtml_buf, size_t xhtml_len)
Tokenize the XHTML buffer and populate engine->tokens[].
static bool internal_suppressed(const tok_ctx_t *ctx)
Test whether the tokenizer is inside a display:none subtree.
static ra8_err_t internal_handle_start(tok_ctx_t *ctx, const uint8_t *buf, size_t *pi, size_t len)
Handle an opening, void, or self-closing start tag.
static ra8_err_t internal_open_styled(tok_ctx_t *ctx, const uint8_t *tagbuf, size_t span, reflow_html_tag_t tag, bool block)
Run the CSS cascade for a just-pushed element and apply the result.
static bool internal_tag_is(const uint8_t *buf, size_t i, size_t len, const char *name)
True iff <name starts at buf[i] and is followed by a tag delimiter.
static ra8_err_t internal_open_attrs(tok_ctx_t *ctx, const uint8_t *tag, size_t span, reflow_html_tag_t kind, bool block, const ra8_css_style_t *comp, uint16_t css_font_px)
Capture a just-opened tag's id (block) or href (<a>).
static uint16_t internal_css_font_px(const tok_ctx_t *ctx, const ra8_css_style_t *comp)
Resolve an element's effective CSS font px from the cascade + inherited.
static ra8_err_t internal_handle_end(tok_ctx_t *ctx, const uint8_t *buf, size_t *pi, size_t len)
Handle a closing tag, popping the stack and emitting block-end.
static reflow_html_tag_t internal_parse_start(const uint8_t *buf, size_t *pi, size_t len, bool *selfclose)
Parse a start tag's name and self-close flag, advancing past '>'.
static ra8_err_t internal_handle_cdata(tok_ctx_t *ctx, const uint8_t *buf, size_t *pi, size_t len)
Handle a CDATA section, emitting its inner text verbatim.
static void internal_handle_raw_text(tok_ctx_t *ctx, const uint8_t *buf, size_t *pi, size_t len, const char *close_lit, bool is_style)
Consume a raw-text element (<style> / <script>) without emitting.
static void internal_handle_link(tok_ctx_t *ctx, const uint8_t *buf, size_t tag_lt, size_t end)
Resolve a <link rel="stylesheet" href> via the bound CSS loader.
static bool internal_emit_text_run(tok_ctx_t *ctx, const uint8_t *buf, size_t run, size_t end)
Stash + emit a character-data run, tagging it with the active link id.
static bool internal_handle_void(tok_ctx_t *ctx, const uint8_t *buf, size_t tag_lt, size_t end, reflow_html_tag_t tag, ra8_err_t *out_err)
Emit the single token for a void tag (<br> / <hr> / <img>), or resolve a <link> stylesheet.
ra8_css_style_t priv_reflow_tok_css_inline(const uint8_t *tag, size_t span)
Parse a just-opened tag's inline style="..." into a CSS declaration.
ra8_css_element_t priv_reflow_tok_css_element(reflow_html_tag_t kind, const uint8_t *tag, size_t span)
Build a CSS element identity from a just-opened tag's attributes.
bool priv_reflow_tok_find_attr(const uint8_t *tag, size_t tag_len, const char *name, size_t name_len, size_t *out_voff, size_t *out_vlen)
Locate a named attribute's quoted value span within a tag (no copy).
void priv_reflow_tok_capture_attr(reflow_t *engine, const uint8_t *tag, size_t tag_len, const char *name, size_t name_len, uint32_t *out_off, uint32_t *out_len)
Copy a named attribute's quoted value from a tag span into the text pool.
bool priv_reflow_tok_rel_is_stylesheet(const uint8_t *rel, size_t len)
True if a rel attribute value contains the stylesheet token.
uint8_t priv_reflow_tok_resolve_face_slot(const reflow_t *engine, const ra8_css_style_t *comp)
Map a cascaded run's (font-family + emphasis) to an embedded face slot.
uint8_t priv_reflow_tok_intern_link(reflow_t *engine, uint32_t href_off, uint32_t href_len)
Intern an <a> href slice into the link-target table.
Test-access surface for reflow_tokenize.c internal helpers.
bool priv_reflow_tok_starts_with(const uint8_t *buf, size_t i, size_t len, const char *lit)
Test whether buf at i begins with the literal lit.
bool priv_reflow_tok_stash_run(reflow_t *engine, const uint8_t *buf, size_t start, size_t end, uint32_t *out_off, uint32_t *out_len)
Entity-decode and whitespace-collapse a text run into the pool.
size_t priv_reflow_tok_find_lit(const uint8_t *buf, size_t i, size_t len, const char *lit)
Return the index of the first occurrence of lit (its start), or len.
bool priv_reflow_tok_emit(reflow_t *engine, reflow_token_kind_t kind, reflow_html_tag_t tag, uint8_t style, uint32_t off, uint32_t len)
Append one token to the engine's token pool.
bool priv_reflow_tok_is_block(reflow_html_tag_t tag)
Test whether a tag is a block-flow container in the v1 subset.
@ k_priv_max_depth
Max element nesting (matches old shim).
@ k_priv_style_mask
Run-style bits.
reflow_html_tag_t priv_reflow_tok_classify(const char *name, size_t len)
Map a (possibly namespace-prefixed) tag name to its enum.
size_t priv_reflow_tok_skip_past(const uint8_t *buf, size_t i, size_t len, const char *lit)
Return the index just past the first occurrence of lit.
uint8_t priv_reflow_tok_style_for(reflow_html_tag_t tag)
Return the style bit an inline tag contributes to its subtree.
bool priv_reflow_tok_is_xml_whitespace(char c)
True for the ASCII characters XHTML treats as whitespace.
bool priv_reflow_tok_feed(reflow_t *engine, char ch, bool *last_ws)
Write one byte through the whitespace-collapse state machine.
reflow_html_tag_t
Recognised HTML element kinds.
@ k_reflow_tag_hr
Horizontal rule (void).
@ k_reflow_tag_link
<link> (void; stylesheet ref).
@ k_reflow_tag_br
Line break (void).
@ k_reflow_tag_img
Image (placeholder rect).
@ k_reflow_tag_a
Anchor (renders underlined).
@ k_reflow_tag_unknown
Anything not in this enum.
@ k_reflow_color_inherit
No per-run CSS colour.
@ k_reflow_min_font_px
Smallest accepted font size.
@ k_reflow_max_font_px
Largest accepted font size.
@ k_reflow_pct_full
Percentage denominator.
@ k_reflow_align_left
Left (default, ragged right).
@ 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>).
@ k_reflow_style_normal
No emphasis.
The identity of one element, used to match selectors.
uint8_t tag
reflow_html_tag_t of the element.
A declared or computed style: a presence mask plus property values.
uint16_t font_val
font-size number: px or % (valid iff set & fontsize).
uint16_t family_len
font-family name slice length (0 = none).
uint8_t font_unit
ra8_css_font_unit_t (valid iff set & fontsize).
uint8_t display
1 = display:none (valid iff set & display).
uint8_t style
reflow_font_style_t bit VALUES (bold/italic/ul).
uint8_t set
ra8_css_set_t bitmask: which properties are present.
uint16_t family_off
font-family name slice offset (valid iff set&family).
uint32_t color
0xRRGGBB text colour (valid iff set & color).
uint8_t align
reflow_align_t (valid iff set & align).
Reflow / pagination engine state.
reflow_css_loader_fn css_loader
<link> CSS loader (NULL = off).
ra8_css_sheet_t css
Parsed <style> rules for the chapter.
uint32_t text_pool_used
Bytes consumed in text_pool.
uint32_t token_count
Tokens used.
uint16_t font_px
Body font size in pixels.
reflow_token_t tokens[k_reflow_max_tokens]
Parsed tokens.
void * css_loader_ctx
Opaque context for css_loader.
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 color
0xRRGGBB CSS colour, or k_reflow_color_inherit.
uint16_t reserved16
Padding to 4-byte stride.
uint8_t reserved
Block align / <a> link id.
Mutable tokenizer state threaded through the scan helpers.
uint16_t family_len
Inherited font-family len (0=none).
uint16_t css_font_px
Inherited CSS font px (0=none).
bool saw_element
At least one element seen.
uint16_t stack_fam_off[k_priv_max_depth]
font-family off to restore.
reflow_t * engine
Target engine pools.
uint32_t color
Current CSS colour / inherit.
uint8_t style
Current inline-style bits.
uint16_t stack_font[k_priv_max_depth]
CSS font px to restore on pop.
uint8_t stack_style[k_priv_max_depth]
Style to restore on pop.
uint32_t suppress_sp
display:none subtree depth (0=off).
uint32_t stack_color[k_priv_max_depth]
Colour to restore on pop.
uint8_t stack_link[k_priv_max_depth]
Link id to restore on pop.
uint8_t stack_face[k_priv_max_depth]
Face slot to restore on pop.
uint8_t face_slot
Resolved embedded face (0=default).
uint16_t family_off
Inherited font-family slice off.
uint8_t active_link
1-based link id (0 = none).
uint16_t stack_fam_len[k_priv_max_depth]
font-family len to restore.
ra8_css_element_t stack_el[k_priv_max_depth]
Open-element identities (tag+id+class) for the cascade + descendant match.