Introduce selective font loading and a SharedBytes abstraction with mmap support to reduce memory and IO overhead when handling fonts.
Key changes:
- Add SharedBytes (with MappedBytes using memmap2) and stats; switch FontData to SharedBytes and update loader/loader tests.
- Platform: add memmap2 dependency (non-wasm), new platform API helpers get_resource_abs_path and get_resource_font_bytes to prefer mmap'ed files and fall back to owned bytes.
- Font family/load changes: ensure_fonts_loaded_for_text and update_font_definitions now accept optional text to load only needed fallback fonts (CJK/emoji) based on text content and resource basename heuristics.
- Avoid eager loading of heavy bundled fallback fonts (LXGWWenKai*, NotoColorEmoji.ttf) when loading all script resources.
- Add env override MAKEPAD_TEXT_ATLAS_SIZE for text atlas size parsing and tests; add related parsing helpers and tests.
- Minor fixes: safer transmute for font_face data slice and several unit tests to validate behavior.
Overall this reduces unnecessary font resource reads/mmap usage and allows tuning text atlas size via environment.
Replace broad cx.load_all_script_resources() calls with a targeted cx.load_script_resource(handle) to only request the specific resource needed. Refactor script resource loading (platform/src/script/res.rs) by extracting load_script_resource_impl(handle, crate_manifests) and exposing load_script_resource(handle); keep load_all_script_resources() by iterating per-handle. Improve wasm handling: resolve web_url per-resource, set explicit error states when missing, and fire async HTTP requests safely. Remove an early call to load_all_script_resources() from web startup. Additional changes: serve precompressed .br files in the local wasm dev server (with COOP/COEP headers when threaded), add wasm-specific font/theme script entries for widgets, and update various callers (draw shaders, widgets, math_view, gltf/view_splat, image) to use the per-handle loader. These changes reduce unnecessary global loads and limit network/file operations to only required resources.
Rename AlignEntry::BeginTurtle/EndTurtle to BeginClip/EndClip — these
entries control GPU clip rect stacking, not turtle lifecycle.
Add push_clip_rect/pop_clip_rect to Cx2d: lightweight API for manual
clip rect control without creating a full turtle. The existing
clip_and_shift_align_list pass intersects nested clip rects and writes
draw_clip into draw call instances.
Co-authored-by: ant <ant@offline.click>
Move font family registration out of on_custom_apply (script apply time)
and into ensure_fonts_loaded (draw time). This avoids redundant work when
the same FontFamily is applied to hundreds of widgets during a frame.
ensure_fonts_loaded now has a fast path that checks is_font_family_complete()
and returns immediately when all expected members are already registered.
The slow path calls load_all_script_resources() to progress pending loads
before falling back to update_font_definitions().
Other changes:
- FontFamilyDefinition gains expected_member_count to distinguish partial
from complete registrations.
- set_font_family_definition skips cache eviction when the definition or
cached family is already equivalent.
- load_font_family now clones the definition instead of removing it,
allowing re-loads after cache eviction without losing the definition.
- Loader::font_family_definitions and Layouter::loader are now pub(crate)
to support the completeness query from Fonts.
---
Review observations (not yet addressed):
1. STALE FAMILY ON RE-APPLY (medium risk): If a FontFamily is re-applied
with different members but the same object index (same family_id), the
fast path in ensure_fonts_loaded will see the old definition as
"complete" and never call update_font_definitions with the new members.
Fix: compare current member handles against stored definition, or set a
dirty flag in on_custom_apply that forces one refresh.
2. UNNECESSARY LAYOUT CACHE FLUSH (medium risk): Layouter::set_font_family_definition
unconditionally clears cached_params and cached_results even when
Loader::set_font_family_definition short-circuits as unchanged. During
partial-load states ensure_fonts_loaded may call update repeatedly with
identical partial definitions, flushing the text layout cache each time.
Fix: propagate a changed bool from Loader and only clear when true.
3. COMPLETENESS IGNORES CACHE-ONLY STATE (low risk): is_font_family_complete
only checks font_family_definitions, not font_family_cache. If a family
was already loaded into cache and its definition consumed, completeness
returns false. The new early-return in set_font_family_definition for
cache-match mitigates this in practice but the invariant is fragile.
Fix: also check font_family_cache in is_font_family_complete, or ensure
definitions are always retained (which this diff partly does by switching
from remove to get+clone in load_font_family).
Co-authored-by: ant <ant@offline.click>
* Fix draw_svg to support a rotated Icon. Add `IconRotated` widget.
Fix icon resource paths in `splash` example
* Expose geometry in draw_svg to make icon/svg rotation more efficient
simplifies the code too