|
ra8-firmware 0.1.0
Bare-metal firmware for the Renesas RA8 family (RA8D2 / RA8P1)
|
Minimal SVG handling for the reflow ereader (#112). More...
Go to the source code of this file.
Functions | |
| bool | ra8_svg_is_svg (const uint8_t *bytes, size_t len) |
Heuristically decide whether bytes are an SVG document. | |
| ra8_err_t | ra8_svg_image_href (const uint8_t *svg, size_t len, size_t *out_off, size_t *out_len) |
| Extract the href of a cover-wrapper <svg><image .../></svg>. | |
| ra8_err_t | ra8_svg_size (const uint8_t *svg, size_t len, int32_t *out_w, int32_t *out_h) |
| Report an SVG's intrinsic size (width/height, else viewBox dimensions). | |
| ra8_err_t | ra8_svg_render (const uint8_t *svg, size_t len, int32_t x, int32_t y, int32_t w, int32_t h) |
| Render an SVG's vector shapes into a box. | |
Minimal SVG handling for the reflow ereader (#112).
A small, hand-written, zero-allocation SVG subset for the two forms that actually appear in EPUBs:
Out of scope (documented limitations, tracked as follow-ups): gradient fills (linearGradient / radialGradient), opacity, CSS styling, stroke width, and fractional coordinates (truncated to integers).
The parser is pure string scanning over the caller's byte buffer (no DOM, no heap); ra8_svg_render's only side effect is drawing through ra8_gfx.
[Ring 4 / Reflow] {World: NS}
Definition in file reflow_svg.h.
|
nodiscard |
Extract the href of a cover-wrapper <svg><image .../></svg>.
Scans for the first <image> element and returns its xlink:href / href attribute value as a slice into svg. The caller resolves + decodes that raster through its normal image path.
| [in] | svg | SVG document bytes. |
| [in] | len | Length of svg. |
| [out] | out_off | Receives the href slice offset into svg. |
| [out] | out_len | Receives the href slice length, bytes. |
| k_ra8_ok | An <image> href was found. |
| k_ra8_err_null_ptr | A required pointer is NULL. |
| k_ra8_err_not_found | No <image> with an href was present. |
svg, out_off, out_len non-NULL. svg. Definition at line 741 of file reflow_svg_doc.c.
References internal_tag_span(), k_ra8_err_not_found, k_ra8_err_null_ptr, k_ra8_ok, and priv_ra8_svgp_attr().
Referenced by internal_render_svg().
|
nodiscard |
Heuristically decide whether bytes are an SVG document.
Skips a leading UTF-8 BOM + whitespace and checks for <?xml or a <svg element start (case-insensitive). Used by the image path to route SVG bytes here instead of to the raster decoder.
| [in] | bytes | Candidate image bytes. |
| [in] | len | Length of bytes. |
bytes look like SVG. | false | bytes is NULL/empty or does not begin like SVG. |
Definition at line 723 of file reflow_svg_doc.c.
References k_svg_bom0, k_svg_bom1, k_svg_bom2, k_svg_bom_len, priv_ra8_svgp_starts_ci(), and priv_ra8_svgp_ws().
Referenced by internal_render_one_image(), and ra8_img_probe_size().
|
nodiscard |
Render an SVG's vector shapes into a box.
Establishes a coordinate transform from the SVG viewBox (or its width/height, defaulting to the box) onto the caller box (x,y,w,h), then walks the supported shapes (<rect> / <circle> / <polygon> filled, <line> / <polyline> stroked) and draws each through the bound ra8_gfx framebuffer with its fill or stroke colour. fill="none" shapes are skipped. Coordinates outside the box are clipped by ra8_gfx.
| [in] | svg | SVG document bytes. |
| [in] | len | Length of svg. |
| [in] | x | Box left, framebuffer pixels. |
| [in] | y | Box top, framebuffer pixels. |
| [in] | w | Box width, pixels (> 0). |
| [in] | h | Box height, pixels (> 0). |
| k_ra8_ok | Rendered (possibly zero shapes). |
| k_ra8_err_null_ptr | svg is NULL. |
| k_ra8_err_invalid_arg | w or h is non-positive. |
svg non-NULL; ra8_gfx_init() has bound a framebuffer. w > 0 and h > 0. (x,y,w,h). Definition at line 799 of file reflow_svg_doc.c.
References svg_xform_t::grads, internal_draw_shapes(), internal_read_viewbox(), internal_scan_grads(), k_ra8_err_invalid_arg, k_ra8_err_null_ptr, and k_ra8_ok.
Referenced by es_render_svg_or_halt(), and internal_render_svg().
|
nodiscard |
Report an SVG's intrinsic size (width/height, else viewBox dimensions).
Lets the layout reserve an <img src="*.svg"> box without a raster decode. Prefers the <svg> width/height attributes (units ignored), and falls back to the viewBox width/height.
| [in] | svg | SVG document bytes. |
| [in] | len | Length of svg. |
| [out] | out_w | Receives the intrinsic width, pixels. |
| [out] | out_h | Receives the intrinsic height, pixels. |
| k_ra8_ok | A positive size was determined. |
| k_ra8_err_null_ptr | A required pointer is NULL. |
| k_ra8_err_not_found | No <svg> or no positive size present. |
svg, out_w, out_h non-NULL. *out_w > 0 and *out_h > 0. Definition at line 764 of file reflow_svg_doc.c.
References internal_tag_span(), k_ra8_err_not_found, k_ra8_err_null_ptr, k_ra8_ok, k_svg_viewbox_n, priv_ra8_svgp_attr(), priv_ra8_svgp_attr_num(), and priv_ra8_svgp_num().
Referenced by es_render_svg_or_halt(), and ra8_img_probe_size().