41typedef enum : uint8_t {
75 return ((c >=
'a') && (c <=
'z')) || ((c >=
'A') && (c <=
'Z')) || ((c >=
'0') && (c <=
'9')) ||
76 (c ==
'-') || (c ==
'_');
207 const char kind = s[*i];
209 const size_t start = *i;
213 const size_t nlen = *i - start;
230 rule->
id_len = (uint16_t)nlen;
333 const size_t start = i;
337 part_p[nparts] = &s[start];
338 part_n[nparts] = i - start;
341 return (int32_t)nparts;
384 const size_t np = (size_t)nparts;
391 for (
size_t a = 0U; (a + 1U) < np; ++a) {
473 while (i < sel_len) {
475 while ((comma < sel_len) && (sel[comma] !=
',')) {
478 size_t one_len = comma - i;
498 if ((*len >= 2U) && ((s[0] ==
'"') || (s[0] ==
'\'')) && (s[*len - 1U] == s[0])) {
542 while ((b < vlen) && (val[b] !=
')')) {
666 const char* url =
nullptr;
672 face->
src_len = (uint16_t)ulen;
681 *
priv_decl_fn)(
void* ctx,
const char* prop,
size_t plen,
const char* val,
size_t vlen);
714 while ((semi < len) && (s[semi] !=
';')) {
718 while ((colon < semi) && (s[colon] !=
':')) {
722 size_t plen = colon - i;
724 size_t vlen = semi - (colon + 1U);
726 if ((plen > 0U) && (vlen > 0U)) {
727 cb(ctx, prop, plen, val, vlen);
765static void internal_face_cb(
void* ctx,
const char* prop,
size_t plen,
const char* val,
size_t vlen)
964 size_t tlen = sel_len;
966 if ((tlen > 0U) && (tsel[0] ==
'@')) {
Annotation-attribute framework macros for ra8-firmware.
#define RA8_INTERNAL
Marker that a function is intended to be static (file-local).
void * memcpy(void *dst, const void *src, size_t n)
Copy memory area between non-overlapping regions.
HTML / CSS reflow + paginate engine for the ra8d2 ereader.
void priv_reflow_css_parse_decls(const char *s, size_t len, ra8_css_style_t *out)
Parse a prop:value; ... declaration body (no braces) into out.
const char * priv_reflow_css_trim(const char *s, size_t *len)
Trim leading + trailing whitespace from s[0..*len); returns start.
bool priv_reflow_css_ci_eq(const char *s, size_t len, const char *lit)
Case-insensitive compare of span s[0..len) against NUL literal lit.
bool priv_reflow_css_is_ws(char c)
True for CSS whitespace (space / tab / newline / CR / FF).
Minimal content-CSS cascade for the reflow ereader engine (#111).
@ k_ra8_css_set_family
font-family was declared.
@ k_ra8_css_name_pool
Bytes of class / id / font name storage.
@ k_ra8_css_name_max
Max bytes of one class / id / font name.
@ k_ra8_css_max_anc
Max descendant-ancestor parts per selector.
@ k_ra8_css_max_faces
Max @font-face rules kept per sheet.
@ k_ra8_css_max_rules
Max rules kept across all <style> blocks.
Cross-TU surface for the split content-CSS cascade (#111).
static bool internal_parse_complex_selector(ra8_css_sheet_t *sheet, const char *s, size_t len, ra8_css_rule_t *rule)
Parse a (possibly descendant) selector string into rule.
static bool internal_parse_selector(ra8_css_sheet_t *sheet, const char *s, size_t len, ra8_css_rule_t *rule)
Parse ONE trimmed compound selector into rule; false if unsupported.
void priv_reflow_css_parse_one_block(ra8_css_sheet_t *sheet, const char *sel, size_t sel_len, const char *block, size_t block_len)
Dispatch one selector|@rule { block }: at-rule vs.
static void internal_parse_at_rule(ra8_css_sheet_t *sheet, const char *sel, size_t sel_len, const char *block, size_t block_len)
Route an at-rule: parse @font-face; skip every other @-rule.
static void internal_for_each_decl(const char *s, size_t len, priv_decl_fn cb, void *ctx)
Iterate prop:value; pairs in a declaration block (no braces).
static bool internal_parse_sel_part(ra8_css_sheet_t *sheet, const char *s, size_t len, size_t *i, ra8_css_rule_t *rule)
Parse one .class / #id part at s[*i] into rule; advance i.
priv_css_face_t
@font-face parsing constants.
@ k_priv_url_len
Length of the url( token prefix.
static bool internal_intern_name(ra8_css_sheet_t *sheet, const char *s, size_t len, uint16_t *off)
Intern a class/id name into the sheet pool; false if it does not fit.
static bool internal_is_italic_kw(const char *val, size_t vlen)
True for a font-style keyword that selects the italic face.
static void internal_extract_family(ra8_css_sheet_t *sheet, const char *block, size_t len, ra8_css_style_t *decl)
Scan a rule's declaration block for font-family, interning it.
static const char * internal_strip_quotes(const char *s, size_t *len)
Strip one layer of matching '/" quotes from span s[0..*len).
static bool internal_is_bold_kw(const char *val, size_t vlen)
True for a font-weight keyword that selects the bold face.
static bool internal_is_name_char(char c)
True if c can appear inside a bare type / class / id name.
static int32_t internal_split_compounds(const char *s, size_t len, const char **part_p, size_t *part_n)
Split s into whitespace-separated compound spans.
void(* priv_decl_fn)(void *ctx, const char *prop, size_t plen, const char *val, size_t vlen)
Callback invoked by internal_for_each_decl on each prop:value pair.
static void internal_push_rule(ra8_css_sheet_t *sheet, const ra8_css_rule_t *rule)
Append one fully-built rule to the sheet; drop silently if full.
static bool internal_parse_sel_type(const char *s, size_t len, size_t *i, ra8_css_rule_t *rule)
Parse the optional leading type / * of a compound selector.
static void internal_face_apply(ra8_css_sheet_t *sheet, const char *prop, size_t plen, const char *val, size_t vlen, ra8_css_fontface_t *face)
Apply one @font-face declaration to the face being built.
static bool internal_extract_url(const char *val, size_t vlen, const char **url, size_t *ulen)
Extract the path inside the first url(...) of a src value.
static void internal_parse_selector_list(ra8_css_sheet_t *sheet, const char *sel, size_t sel_len, ra8_css_style_t decl)
Parse a comma-grouped selector list sharing declaration decl.
static void internal_parse_fontface(ra8_css_sheet_t *sheet, const char *block, size_t len)
Parse one @font-face { ... } block; append it if family + src set.
static void internal_family_cb(void *ctx, const char *prop, size_t plen, const char *val, size_t vlen)
priv_decl_fn adapter that interns a rule's font-family value.
static void internal_face_cb(void *ctx, const char *prop, size_t plen, const char *val, size_t vlen)
priv_decl_fn adapter that routes one descriptor to internal_face_apply().
Test-access surface for reflow_tokenize.c internal helpers.
reflow_html_tag_t priv_reflow_tok_classify(const char *name, size_t len)
Map a (possibly namespace-prefixed) tag name to its enum.
reflow_html_tag_t
Recognised HTML element kinds.
@ k_reflow_tag_unknown
Anything not in this enum.
Context threading a sheet + the face being built through the loop.
ra8_css_sheet_t * sheet
Sheet receiving interned name bytes.
ra8_css_fontface_t * face
Face accumulating descriptors.
Context threading a sheet + the rule declaration through the loop.
ra8_css_style_t * decl
Declaration receiving the family slice.
ra8_css_sheet_t * sheet
Sheet receiving the interned family name.
uint16_t id_off
Id name slice offset (id_len 0 = none).
uint16_t class_len
Class name slice length, bytes.
uint16_t id_len
Id name slice length, bytes.
uint16_t class_off
Class name slice offset (class_len 0 = none).
uint8_t tag
Type tag, or k_reflow_tag_unknown = no type.
One parsed @font-face rule: family + weight/style + src href.
uint16_t src_len
src href slice length.
uint8_t weight_bold
1 = this face is the bold weight.
uint16_t family_len
font-family name slice length.
uint8_t style_italic
1 = this face is italic / oblique.
uint16_t src_off
src href slice offset.
uint16_t family_off
font-family name slice offset.
One selector { ... } rule: a (possibly descendant) selector plus its declarations.
uint16_t class_off
Class name slice offset (class_len 0 = none).
uint16_t id_off
Id name slice offset (id_len 0 = none).
ra8_css_style_t decl
Declared properties.
ra8_css_anc_t anc[k_ra8_css_max_anc]
Descendant ancestor parts.
uint16_t class_len
Class name slice length, bytes.
uint16_t order
Source order (lower = earlier; ties to later).
uint8_t anc_count
Ancestor parts in anc (0 = simple).
uint16_t id_len
Id name slice length, bytes.
uint8_t sel_tag
Type tag, or k_reflow_tag_unknown = no type.
A parsed stylesheet: rule + @font-face arrays and a name byte pool.
uint16_t face_count
@font-face rules in use.
uint16_t rule_count
Rules in use.
ra8_css_rule_t rules[k_ra8_css_max_rules]
Parsed rules.
uint16_t next_order
Running source-order ctr.
uint16_t names_used
Bytes used in names.
ra8_css_fontface_t faces[k_ra8_css_max_faces]
Parsed @font-face rules.
uint8_t names[k_ra8_css_name_pool]
class/id/font name bytes.
A declared or computed style: a presence mask plus property values.
uint16_t family_len
font-family name slice length (0 = none).
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).