45typedef enum : uint16_t {
63typedef enum : uint8_t {
74 if (sheet ==
nullptr) {
108 const char open_a =
'/';
109 const char open_b =
'*';
112 while (((j + 1U) < len) && !((css[j] == open_b) && (css[j + 1U] == open_a))) {
116 return (past <= len) ? past : len;
147 const char open_c =
'{';
148 const char close_c =
'}';
151 while ((brace < len) && (css[brace] != open_c)) {
157 size_t close = brace + 1U;
159 while ((close < len) && (css[close] != close_c)) {
169 if ((sheet ==
nullptr) || (css ==
nullptr)) {
172 const char open_a =
'/';
173 const char open_b =
'*';
176 while (i < (
size_t)len) {
177 if (((i + 1U) < (
size_t)len) && (css[i] == open_a) && (css[i + 1U] == open_b)) {
194 close - (brace + 1U));
195 i = (close < (size_t)len) ? (close + 1U) : (size_t)len;
237 while (i < list_len) {
245 const size_t tlen = i - start;
246 bool equal = tlen == nlen;
247 for (
size_t j = 0U; equal && (j < nlen); ++j) {
248 if (list[start + j] != name[j]) {
263 if ((rule ==
nullptr) || (el ==
nullptr) || (sheet ==
nullptr)) {
278 const char* nm = (
const char*)&sheet->
names[rule->
id_off];
280 for (uint16_t i = 0U; equal && (i < rule->
id_len); ++i) {
281 if (el->
id[i] != nm[i]) {
335 const char* nm = (
const char*)&sheet->
names[anc->
id_off];
337 for (uint16_t i = 0U; equal && (i < anc->
id_len); ++i) {
338 if (el->
id[i] != nm[i]) {
395 int32_t ai = (int32_t)rule->
anc_count - 1;
396 int32_t si = (int32_t)n_anc - 1;
398 while ((ai >= 0) && (si >= 0)) {
446 for (uint8_t a = 0U; a < rule->
anc_count; ++a) {
474 uint16_t best_rank = 0U;
475 uint16_t best_order = 0U;
477 if ((inherited->
set & setbit) != 0U) {
483 for (uint16_t i = 0U; i < sheet->
rule_count; ++i) {
484 if (!matched[i] || ((sheet->
rules[i].
decl.
set & setbit) == 0U)) {
489 if ((!have) || (rank > best_rank) ||
490 ((rank == best_rank) && (sheet->
rules[i].
order >= best_order))) {
497 if ((inl->
set & setbit) != 0U) {
537 static const struct {
545 for (
size_t p = 0U; p < (
sizeof(k_props) /
sizeof(k_props[0])); ++p) {
548 if (win !=
nullptr) {
549 out->
set = (uint8_t)(out->
set | k_props[p].setbit);
550 if ((win->
style & k_props[p].stylebit) != 0U) {
551 out->
style = (uint8_t)(out->
style | k_props[p].stylebit);
593 if (awin !=
nullptr) {
599 if (cwin !=
nullptr) {
608 if (fwin !=
nullptr) {
615 if (dwin !=
nullptr) {
657 if (win !=
nullptr) {
671 if ((sheet ==
nullptr) || (el ==
nullptr)) {
676 for (uint16_t i = 0U; i < sheet->
rule_count; ++i) {
723 if ((a ==
nullptr) || (b ==
nullptr) || (alen != blen)) {
727 for (
size_t k = 0U; k < alen; ++k) {
777 if ((sheet ==
nullptr) || (family ==
nullptr) || (family_len == 0U)) {
782 for (uint16_t i = 0U; i < sheet->
face_count; ++i) {
789 if ((face_bold == want_bold) && (face_italic == want_italic)) {
793 fallback = (int16_t)i;
801 const char** out_src,
804 if ((sheet ==
nullptr) || (out_src ==
nullptr) || (out_len ==
nullptr) ||
Annotation-attribute framework macros for ra8-firmware.
#define RA8_INTERNAL
Marker that a function is intended to be static (file-local).
@ k_ra8_ok
Success – operation completed with all postconditions satisfied.
@ k_ra8_err_null_ptr
Pointer was NULL where a valid pointer was required.
ra8_err_codes_t ra8_err_t
Canonical error-return type used by every ra8-firmware API.
HTML / CSS reflow + paginate engine for the ra8d2 ereader.
char priv_reflow_css_lower(char c)
ASCII-fold one byte to lower case.
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_fontsize
font-size was declared.
@ k_ra8_css_set_underline
text-decoration was declared.
@ k_ra8_css_set_align
text-align was declared.
@ k_ra8_css_set_display
display was declared.
@ k_ra8_css_set_bold
font-weight was declared.
@ k_ra8_css_set_italic
font-style was declared.
@ k_ra8_css_set_color
color was declared.
@ k_ra8_css_set_family
font-family was declared.
@ k_ra8_css_no_face
No @font-face matched the requested family.
@ k_ra8_css_max_rules
Max rules kept across all <style> blocks.
bool ra8_css_rule_matches(const ra8_css_rule_t *rule, const ra8_css_element_t *el, const ra8_css_sheet_t *sheet)
Test whether rule rule's selector matches element el.
static bool internal_find_block(const char *css, size_t len, size_t i, size_t *out_open, size_t *out_close)
Locate the { ... } block beginning at selector offset i.
static bool internal_family_eq(const ra8_css_sheet_t *sheet, const ra8_css_fontface_t *f, const char *family, size_t family_len)
True iff face f's family equals family (case-insensitive).
static size_t internal_skip_comment(const char *css, size_t len, size_t start)
Step over a C-style comment starting at start.
static void internal_cascade_family(ra8_css_style_t *out, const ra8_css_sheet_t *sheet, const bool *matched, const ra8_css_style_t *inherited, const ra8_css_style_t *inl)
Resolve the inherited font-family slice into out.
static void internal_cascade_scalars(ra8_css_style_t *out, const ra8_css_sheet_t *sheet, const bool *matched, const ra8_css_style_t *inherited, const ra8_css_style_t *inl)
Resolve the scalar properties (align / colour / font-size / display).
static bool internal_anc_matches(const ra8_css_anc_t *anc, const ra8_css_element_t *el, const ra8_css_sheet_t *sheet)
True if descendant ancestor part anc matches element el.
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.
ra8_err_t ra8_css_sheet_reset(ra8_css_sheet_t *sheet)
Reset a stylesheet to empty (no rules, no names, order 0).
static bool internal_ci_eq_span(const char *a, size_t alen, const char *b, size_t blen)
Case-insensitive equality of two byte spans.
static bool internal_class_list_has(const char *list, size_t list_len, const char *name, size_t nlen)
True iff a space-separated class list contains name exactly.
static void internal_cascade_emphasis(ra8_css_style_t *out, const ra8_css_sheet_t *sheet, const bool *matched, const ra8_css_style_t *inherited, const ra8_css_style_t *inl)
Resolve the bold / italic / underline emphasis bits into out.
bool ra8_css_face_src(const ra8_css_sheet_t *sheet, uint16_t idx, const char **out_src, uint16_t *out_len)
Read a parsed @font-face entry's src href bytes.
priv_css_scan_t
Token lengths used by the top-level stylesheet scanner.
@ k_priv_cmt_marker
Byte length of a CSS comment delimiter pair.
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.
int16_t ra8_css_match_face(const ra8_css_sheet_t *sheet, const char *family, uint16_t family_len, bool want_bold, bool want_italic)
Pick the @font-face whose family + emphasis best fits a run.
ra8_css_style_t ra8_css_cascade(const ra8_css_sheet_t *sheet, const ra8_css_element_t *el, ra8_css_style_t inherited, ra8_css_style_t inline_decl)
Compute an element's cascaded style.
static uint16_t internal_rule_rank(const ra8_css_rule_t *rule)
Packed specificity (id*10000 + class*100 + type), summing all parts.
static const ra8_css_style_t * internal_resolve(uint8_t setbit, const ra8_css_style_t *inherited, const ra8_css_sheet_t *sheet, const bool *matched, const ra8_css_style_t *inl)
Resolve the winning declaration for one property across all sources.
priv_css_consts_t
Cascade specificity weights (packed id > class > type > universal).
@ k_priv_spec_class
A class constraint adds this.
@ k_priv_spec_id
An id constraint adds this.
@ k_priv_spec_type
A type constraint adds this.
@ k_priv_rank_inherited
Inheritance / universal weight.
static bool internal_rule_matches_ctx(const ra8_css_rule_t *rule, const ra8_css_element_t *el, const ra8_css_element_t *ancestors, uint8_t n_anc, const ra8_css_sheet_t *sheet)
Full match of a (possibly descendant) rule against el + ancestors.
Cross-TU surface for the split content-CSS cascade (#111).
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.
@ k_reflow_tag_unknown
Anything not in this enum.
@ k_reflow_style_italic
Italic face.
@ k_reflow_style_bold
Bold face.
@ k_reflow_style_underline
Underlined run.
One ancestor part of a descendant selector (e.g.
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.
The identity of one element, used to match selectors.
uint16_t class_len
Length of class_str, bytes.
const char * id
id attribute bytes (NULL = none).
const char * class_str
class attribute bytes (NULL = none).
uint16_t id_len
Length of id, bytes.
uint8_t tag
reflow_html_tag_t of the element.
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 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).