ra8-firmware 0.1.0
Bare-metal firmware for the Renesas RA8 family (RA8D2 / RA8P1)
Loading...
Searching...
No Matches
reflow_link.c
Go to the documentation of this file.
1
23
24#include <stddef.h>
25#include <stdint.h>
26#include <string.h>
27
28#include "ra8_attributes.h"
29#include "ra8_check.h"
30#include "ra8_err.h"
31#include "reflow.h"
32
34static const char* const s_tag_link = "ra8_link";
35
37 uint32_t page_idx,
38 int32_t x,
39 int32_t y,
40 uint32_t* out_href_off,
41 uint32_t* out_href_len)
42{
43 RA8_CHECK_NULL_PTR(engine, s_tag_link, "hit: null engine");
44 RA8_CHECK_NULL_PTR(out_href_off, s_tag_link, "hit: null out_href_off");
45 RA8_CHECK_NULL_PTR(out_href_len, s_tag_link, "hit: null out_href_len");
46
47 for (uint32_t i = 0U; i < engine->link_rect_count; ++i) {
48 const reflow_link_rect_t* rect = &engine->link_rects[i];
49 if (rect->page_index != page_idx) {
50 continue;
51 }
52 if ((x >= rect->x) && (x < (rect->x + rect->w)) && (y >= rect->y) &&
53 (y < (rect->y + rect->h))) {
54 const reflow_link_target_t* target = &engine->link_targets[rect->target];
55 *out_href_off = target->href_off;
56 *out_href_len = target->href_len;
57 return k_ra8_ok;
58 }
59 }
61}
62
64 uint32_t page_idx,
65 int32_t x,
66 int32_t y,
67 uint32_t* out_index)
68{
69 RA8_CHECK_NULL_PTR(engine, s_tag_link, "img hit: null engine");
70 RA8_CHECK_NULL_PTR(out_index, s_tag_link, "img hit: null out_index");
71
72 for (uint32_t i = 0U; i < engine->image_box_count; ++i) {
73 const reflow_image_box_t* box = &engine->image_boxes[i];
74 if (box->page_index != page_idx) {
75 continue;
76 }
77 /* Decision: the point is inside the box (4 conditions, half-open on the
78 * right/bottom edges so abutting figures never both claim a tap). */
79 if ((x >= box->x) && (x < (box->x + box->w)) && (y >= box->y) && (y < (box->y + box->h))) {
80 *out_index = i;
81 return k_ra8_ok;
82 }
83 }
85}
86
88reflow_find_anchor(const reflow_t* engine, const char* id, uint32_t id_len, uint32_t* out_page)
89{
90 RA8_CHECK_NULL_PTR(engine, s_tag_link, "anchor: null engine");
91 RA8_CHECK_NULL_PTR(id, s_tag_link, "anchor: null id");
92 RA8_CHECK_NULL_PTR(out_page, s_tag_link, "anchor: null out_page");
93 if (id_len == 0U) {
95 }
96
97 for (uint32_t i = 0U; i < engine->anchor_count; ++i) {
98 const reflow_anchor_t* anchor = &engine->anchors[i];
99 bool equal = anchor->id_len == id_len;
100 for (uint32_t j = 0U; equal && (j < id_len); ++j) {
101 if (engine->text_pool[anchor->id_off + j] != (uint8_t)id[j]) {
102 equal = false;
103 }
104 }
105 if (equal) {
106 *out_page = anchor->page_index;
107 return k_ra8_ok;
108 }
109 }
110 return k_ra8_err_not_found;
111}
112
140static bool internal_has_scheme(const char* href, uint32_t end)
141{
142 for (uint32_t i = 0U; i < end; ++i) {
143 if (href[i] == '/') {
144 return false;
145 }
146 if (href[i] == ':') {
147 return true;
148 }
149 }
150 return false;
151}
152
186static void internal_href_classify(const char* href,
187 uint32_t len,
188 reflow_href_kind_t* out_kind,
189 uint32_t* out_path_len,
190 uint32_t* out_frag_off,
191 uint32_t* out_frag_len)
192{
193 uint32_t hash = len;
194 for (uint32_t i = 0U; i < len; ++i) {
195 if (href[i] == '#') {
196 hash = i;
197 break;
198 }
199 }
200 if (internal_has_scheme(href, hash)) {
201 *out_kind = k_reflow_href_external;
202 *out_path_len = len;
203 return;
204 }
205 const bool has_frag = (hash < len);
206 *out_path_len = hash;
207 if (has_frag) {
208 *out_frag_off = hash + 1U;
209 *out_frag_len = len - hash - 1U;
210 }
211 if (hash == 0U) {
212 *out_kind = has_frag ? k_reflow_href_fragment : k_reflow_href_empty;
213 } else {
215 }
216}
217
219 uint32_t len,
220 reflow_href_kind_t* out_kind,
221 uint32_t* out_path_len,
222 uint32_t* out_frag_off,
223 uint32_t* out_frag_len)
224{
225 RA8_CHECK_NULL_PTR(href, s_tag_link, "split: null href");
226 RA8_CHECK_NULL_PTR(out_kind, s_tag_link, "split: null out_kind");
227 RA8_CHECK_NULL_PTR(out_path_len, s_tag_link, "split: null out_path_len");
228 RA8_CHECK_NULL_PTR(out_frag_off, s_tag_link, "split: null out_frag_off");
229 RA8_CHECK_NULL_PTR(out_frag_len, s_tag_link, "split: null out_frag_len");
230
231 *out_path_len = 0U;
232 *out_frag_off = 0U;
233 *out_frag_len = 0U;
234 if (len == 0U) {
235 *out_kind = k_reflow_href_empty;
236 return k_ra8_ok;
237 }
238 internal_href_classify(href, len, out_kind, out_path_len, out_frag_off, out_frag_len);
239 return k_ra8_ok;
240}
Annotation-attribute framework macros for ra8-firmware.
#define RA8_INTERNAL
Marker that a function is intended to be static (file-local).
Validation and Error-Checking Macros for ra8-firmware.
#define RA8_CHECK_NULL_PTR(ptr, tag, message)
Reject nullptr pointer, returning k_ra8_err_null_ptr.
Definition ra8_check.h:243
Error Code Definitions for ra8-firmware.
@ k_ra8_err_invalid_arg
Invalid function argument.
Definition ra8_err.h:152
@ k_ra8_ok
Success – operation completed with all postconditions satisfied.
Definition ra8_err.h:119
@ k_ra8_err_not_found
Requested item not found (lookup / search missed).
Definition ra8_err.h:173
ra8_err_codes_t ra8_err_t
Canonical error-return type used by every ra8-firmware API.
Definition ra8_err.h:546
HTML / CSS reflow + paginate engine for the ra8d2 ereader.
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 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.
One laid-out <img> rectangle (decoded + blitted at render time).
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.
int32_t w
Scaled box width, pixels.
int32_t h
Scaled box height, pixels.
Reflow / pagination engine state.
reflow_link_rect_t link_rects[k_reflow_max_link_rects]
Tappable rects.
uint8_t text_pool[k_reflow_text_pool_bytes]
Text bytes.
reflow_anchor_t anchors[k_reflow_max_anchors]
id= anchor positions.
uint32_t anchor_count
Anchor positions used.
reflow_link_target_t link_targets[k_reflow_max_links]
Distinct hrefs.
reflow_image_box_t image_boxes[k_reflow_max_images]
Laid-out images.
uint32_t image_box_count
Image boxes used.
uint32_t link_rect_count
Link rects used.