# Port Upstream PRs #997, #1003, #1005, #1010 ## Task Cherry-pick / port four upstream PRs from crosspoint-reader/crosspoint-reader into the mod fork. ## Changes Made ### PR #997 -- Already Ported (no changes) Glyph null-safety in `getSpaceWidth`/`getTextAdvanceX` was already present via commit `c1b8e53`. ### PR #1010 -- Fix Dangling Pointer - **src/main.cpp**: `onGoToReader()` now copies the `initialEpubPath` string before calling `exitActivity()`, preventing a dangling reference when the owning activity is destroyed. ### PR #1005 -- Use HalPowerManager for Battery Percentage - **lib/hal/HalPowerManager.h**: Changed `getBatteryPercentage()` return type from `int` to `uint16_t`. - **lib/hal/HalPowerManager.cpp**: Same return type change. - **src/Battery.h**: Emptied contents (was `static BatteryMonitor battery(BAT_GPIO0)`). - **src/main.cpp**: Removed `#include "Battery.h"`. - **src/activities/home/HomeActivity.cpp**: Removed `#include "Battery.h"`. - **src/components/themes/BaseTheme.cpp**: Replaced `Battery.h` include with `HalPowerManager.h`, replaced `battery.readPercentage()` with `powerManager.getBatteryPercentage()` (2 occurrences). - **src/components/themes/lyra/LyraTheme.cpp**: Same replacements (2 occurrences). ### PR #1003 -- Render Image Placeholders While Waiting for Decode - **lib/Epub/Epub/blocks/ImageBlock.h/.cpp**: Added `isCached()` method that checks if the `.pxc` cache file exists. - **lib/Epub/Epub/Page.h/.cpp**: Added `PageImage::isCached()`, `PageImage::renderPlaceholder()`, `Page::renderTextOnly()`, `Page::countUncachedImages()`, `Page::renderImagePlaceholders()`. Added `#include ` to Page.h. - **src/activities/reader/EpubReaderActivity.cpp**: Modified `renderContents()` to check for uncached images and display text + placeholder rectangles immediately (Phase 1 with HALF_REFRESH), then proceed with full image decode and display (Phase 2 with fast refresh). Existing mod-specific double FAST_REFRESH logic for anti-aliased image pages is preserved for the cached-image path. ## Build Result SUCCESS -- RAM: 31.5%, Flash: 70.4%. No linter errors. ## Follow-up Items - PR #1003 is still open upstream (not merged); may need to rebase if upstream changes before merge. - The phased rendering for uncached images skips the mod's double FAST_REFRESH technique (relies on Phase 1's HALF_REFRESH instead). If grayscale quality on first-decode image pages is suboptimal, this could be revisited.