2025-12-17 23:32:18 +11:00
|
|
|
#include "SleepActivity.h"
|
2025-12-06 04:20:03 +11:00
|
|
|
|
2025-12-21 18:42:06 +11:00
|
|
|
#include <Epub.h>
|
2025-12-08 22:06:09 +11:00
|
|
|
#include <GfxRenderer.h>
|
2026-02-08 21:29:14 +01:00
|
|
|
#include <HalStorage.h>
|
feat: User-Interface I18n System (#728)
## Summary
**What is the goal of this PR?**
This PR introduces Internationalization (i18n) support, enabling users
to switch the UI language dynamically.
**What changes are included?**
- Core Logic: Added I18n class (`lib/I18n/I18n.h/cpp`) to manage
language state and string retrieval.
- Data Structures:
- `lib/I18n/I18nStrings.h/cpp`: Static string arrays for each supported
language.
- `lib/I18n/I18nKeys.h`: Enum definitions for type-safe string access.
- `lib/I18n/translations.csv`: single source of truth.
- Documentation: Added `docs/i18n.md` detailing the workflow for
developers and translators.
- New Settings activity:
`src/activities/settings/LanguageSelectActivity.h/cpp`
## Additional Context
This implementation (building on concepts from #505) prioritizes
performance and memory efficiency.
The core approach is to store all localized strings for each language in
dedicated arrays and access them via enums. This provides O(1) access
with zero runtime overhead, and avoids the heap allocations, hashing,
and collision handling required by `std::map` or `std::unordered_map`.
The main trade-off is that enums and string arrays must remain perfectly
synchronized—any mismatch would result in incorrect strings being
displayed in the UI.
To eliminate this risk, I added a Python script that automatically
generates `I18nStrings.h/.cpp` and `I18nKeys.h` from a CSV file, which
will serve as the single source of truth for all translations. The full
design and workflow are documented in `docs/i18n.md`.
### Next Steps
- [x] Python script `generate_i18n.py` to auto-generate C++ files from
CSV
- [x] Populate translations.csv with initial translations.
Currently available translations: English, Español, Français, Deutsch,
Čeština, Português (Brasil), Русский, Svenska.
Thanks, community!
**Status:** EDIT: ready to be merged.
As a proof of concept, the SPANISH strings currently mirror the English
ones, but are fully uppercased.
---
### AI Usage
Did you use AI tools to help write this code? _**< PARTIALLY >**_
I used AI for the black work of replacing strings with I18n references
across the project, and for generating the documentation. EDIT: also
some help with merging changes from master.
---------
Co-authored-by: google-labs-jules[bot] <161369871+google-labs-jules[bot]@users.noreply.github.com>
Co-authored-by: yeyeto2788 <juanernestobiondi@gmail.com>
2026-02-16 15:28:42 +02:00
|
|
|
#include <I18n.h>
|
2026-01-14 19:36:40 +09:00
|
|
|
#include <Txt.h>
|
2025-12-28 23:56:05 +09:00
|
|
|
#include <Xtc.h>
|
2025-12-06 04:20:03 +11:00
|
|
|
|
2025-12-15 23:17:23 +11:00
|
|
|
#include "CrossPointSettings.h"
|
2025-12-21 18:42:06 +11:00
|
|
|
#include "CrossPointState.h"
|
feat: UI themes, Lyra (#528)
## Summary
### What is the goal of this PR?
- Visual UI overhaul
- UI theme selection
### What changes are included?
- Added a setting "UI Theme": Classic, Lyra
- The classic theme is the current Crosspoint theme
- The Lyra theme implements these mockups:
https://www.figma.com/design/UhxoV4DgUnfrDQgMPPTXog/Lyra-Theme?node-id=2003-7596&t=4CSOZqf0n9uQMxDt-0
by Discord users yagofarias, ruby and gan_shu
- New functions in GFXRenderer to render rounded rectangles, greyscale
fills (using dithering) and thick lines
- Basic UI components are factored into BaseTheme methods which can be
overridden by each additional theme. Methods that are not overridden
will fallback to BaseTheme behavior. This means any new
features/components in CrossPoint only need to be developed for the
"Classic" BaseTheme.
- Additional themes can easily be developed by the community using this
foundation



## Additional Context
- Only the Home, Library and main Settings screens have been implemented
so far, this will be extended to the transfer screens and chapter
selection screen later on, but we need to get the ball rolling somehow
:)
- Loading extra covers on the home screen in the Lyra theme takes a
little more time (about 2 seconds), I added a loading bar popup (reusing
the Indexing progress bar from the reader view, factored into a neat UI
component) but the popup adds ~400ms to the loading time.
- ~~Home screen thumbnails will need to be generated separately for each
theme, because they are displayed in different sizes. Because we're
using dithering, displaying a thumb with the wrong size causes the
picture to look janky or dark as it does on the screenshots above. No
worries this will be fixed in a future PR.~~ Thumbs are now generated
with a size parameter
- UI Icons will need to be implemented in a future PR.
---
### AI Usage
While CrossPoint doesn't have restrictions on AI tools in contributing,
please be transparent about their usage as it
helps set the right context for reviewers.
Did you use AI tools to help write this code? _**PARTIALLY**_
This is not a vibe coded PR. Copilot was used for autocompletion to save
time but I reviewed, understood and edited all generated code.
---------
Co-authored-by: Dave Allie <dave@daveallie.com>
2026-02-05 17:50:11 +07:00
|
|
|
#include "components/UITheme.h"
|
Aleo, Noto Sans, Open Dyslexic fonts (#163)
## Summary
* Swap out Bookerly font due to licensing issues, replace default font
with Aleo
* I did a bunch of searching around for a nice replacement font, and
this trumped several other like Literata, Merriwether, Vollkorn, etc
* Add Noto Sans, and Open Dyslexic as font options
* They can be selected in the settings screen
* Add font size options (Small, Medium, Large, Extra Large)
* Adjustable in settings
* Swap out uses of reader font in headings and replaced with slightly
larger Ubuntu font
* Replaced PixelArial14 font as it was difficult to track down, replace
with Space Grotesk
* Remove auto formatting on generated font files
* Massively speeds up formatting step now that there is a lot more CPP
font source
* Include fonts with their licenses in the repo
## Additional Context
Line compression setting will follow
| Font | Small | Medium | Large | X Large |
| --- | --- | --- | --- | --- |
| Aleo |

|

|

|

|
| Noto Sans |

|

|

|

|
| Open Dyslexic |

|

|

|

|
2025-12-30 18:21:47 +10:00
|
|
|
#include "fontIds.h"
|
2026-02-06 02:50:01 +11:00
|
|
|
#include "images/Logo120.h"
|
2026-01-07 20:07:23 +10:00
|
|
|
#include "util/StringUtils.h"
|
2025-12-28 23:56:05 +09:00
|
|
|
|
2025-12-17 23:32:18 +11:00
|
|
|
void SleepActivity::onEnter() {
|
2025-12-21 21:17:00 +11:00
|
|
|
Activity::onEnter();
|
feat: User-Interface I18n System (#728)
## Summary
**What is the goal of this PR?**
This PR introduces Internationalization (i18n) support, enabling users
to switch the UI language dynamically.
**What changes are included?**
- Core Logic: Added I18n class (`lib/I18n/I18n.h/cpp`) to manage
language state and string retrieval.
- Data Structures:
- `lib/I18n/I18nStrings.h/cpp`: Static string arrays for each supported
language.
- `lib/I18n/I18nKeys.h`: Enum definitions for type-safe string access.
- `lib/I18n/translations.csv`: single source of truth.
- Documentation: Added `docs/i18n.md` detailing the workflow for
developers and translators.
- New Settings activity:
`src/activities/settings/LanguageSelectActivity.h/cpp`
## Additional Context
This implementation (building on concepts from #505) prioritizes
performance and memory efficiency.
The core approach is to store all localized strings for each language in
dedicated arrays and access them via enums. This provides O(1) access
with zero runtime overhead, and avoids the heap allocations, hashing,
and collision handling required by `std::map` or `std::unordered_map`.
The main trade-off is that enums and string arrays must remain perfectly
synchronized—any mismatch would result in incorrect strings being
displayed in the UI.
To eliminate this risk, I added a Python script that automatically
generates `I18nStrings.h/.cpp` and `I18nKeys.h` from a CSV file, which
will serve as the single source of truth for all translations. The full
design and workflow are documented in `docs/i18n.md`.
### Next Steps
- [x] Python script `generate_i18n.py` to auto-generate C++ files from
CSV
- [x] Populate translations.csv with initial translations.
Currently available translations: English, Español, Français, Deutsch,
Čeština, Português (Brasil), Русский, Svenska.
Thanks, community!
**Status:** EDIT: ready to be merged.
As a proof of concept, the SPANISH strings currently mirror the English
ones, but are fully uppercased.
---
### AI Usage
Did you use AI tools to help write this code? _**< PARTIALLY >**_
I used AI for the black work of replacing strings with I18n references
across the project, and for generating the documentation. EDIT: also
some help with merging changes from master.
---------
Co-authored-by: google-labs-jules[bot] <161369871+google-labs-jules[bot]@users.noreply.github.com>
Co-authored-by: yeyeto2788 <juanernestobiondi@gmail.com>
2026-02-16 15:28:42 +02:00
|
|
|
GUI.drawPopup(renderer, tr(STR_ENTERING_SLEEP));
|
2025-12-21 18:42:06 +11:00
|
|
|
|
2026-02-05 18:46:14 +07:00
|
|
|
switch (SETTINGS.sleepScreen) {
|
|
|
|
|
case (CrossPointSettings::SLEEP_SCREEN_MODE::BLANK):
|
|
|
|
|
return renderBlankSleepScreen();
|
|
|
|
|
case (CrossPointSettings::SLEEP_SCREEN_MODE::CUSTOM):
|
|
|
|
|
return renderCustomSleepScreen();
|
|
|
|
|
case (CrossPointSettings::SLEEP_SCREEN_MODE::COVER):
|
|
|
|
|
case (CrossPointSettings::SLEEP_SCREEN_MODE::COVER_CUSTOM):
|
|
|
|
|
return renderCoverSleepScreen();
|
|
|
|
|
default:
|
|
|
|
|
return renderDefaultSleepScreen();
|
2025-12-21 18:42:06 +11:00
|
|
|
}
|
|
|
|
|
}
|
|
|
|
|
|
|
|
|
|
void SleepActivity::renderCustomSleepScreen() const {
|
2025-12-19 14:17:26 +01:00
|
|
|
// Check if we have a /sleep directory
|
2026-02-08 21:29:14 +01:00
|
|
|
auto dir = Storage.open("/sleep");
|
2025-12-19 14:17:26 +01:00
|
|
|
if (dir && dir.isDirectory()) {
|
|
|
|
|
std::vector<std::string> files;
|
2026-01-07 22:43:19 +10:00
|
|
|
char name[500];
|
2025-12-19 14:17:26 +01:00
|
|
|
// collect all valid BMP files
|
2025-12-30 15:09:30 +10:00
|
|
|
for (auto file = dir.openNextFile(); file; file = dir.openNextFile()) {
|
2025-12-19 14:17:26 +01:00
|
|
|
if (file.isDirectory()) {
|
|
|
|
|
file.close();
|
|
|
|
|
continue;
|
|
|
|
|
}
|
2025-12-30 15:09:30 +10:00
|
|
|
file.getName(name, sizeof(name));
|
|
|
|
|
auto filename = std::string(name);
|
2025-12-19 14:17:26 +01:00
|
|
|
if (filename[0] == '.') {
|
|
|
|
|
file.close();
|
|
|
|
|
continue;
|
|
|
|
|
}
|
|
|
|
|
|
|
|
|
|
if (filename.substr(filename.length() - 4) != ".bmp") {
|
2026-02-13 12:16:39 +01:00
|
|
|
LOG_DBG("SLP", "Skipping non-.bmp file name: %s", name);
|
2025-12-19 14:17:26 +01:00
|
|
|
file.close();
|
|
|
|
|
continue;
|
|
|
|
|
}
|
|
|
|
|
Bitmap bitmap(file);
|
|
|
|
|
if (bitmap.parseHeaders() != BmpReaderError::Ok) {
|
2026-02-13 12:16:39 +01:00
|
|
|
LOG_DBG("SLP", "Skipping invalid BMP file: %s", name);
|
2025-12-19 14:17:26 +01:00
|
|
|
file.close();
|
|
|
|
|
continue;
|
|
|
|
|
}
|
|
|
|
|
files.emplace_back(filename);
|
|
|
|
|
file.close();
|
|
|
|
|
}
|
2025-12-21 18:42:06 +11:00
|
|
|
const auto numFiles = files.size();
|
2025-12-19 14:17:26 +01:00
|
|
|
if (numFiles > 0) {
|
|
|
|
|
// Generate a random number between 1 and numFiles
|
2026-01-14 05:05:08 -05:00
|
|
|
auto randomFileIndex = random(numFiles);
|
|
|
|
|
// If we picked the same image as last time, reroll
|
|
|
|
|
while (numFiles > 1 && randomFileIndex == APP_STATE.lastSleepImage) {
|
|
|
|
|
randomFileIndex = random(numFiles);
|
|
|
|
|
}
|
|
|
|
|
APP_STATE.lastSleepImage = randomFileIndex;
|
|
|
|
|
APP_STATE.saveToFile();
|
2025-12-21 18:42:06 +11:00
|
|
|
const auto filename = "/sleep/" + files[randomFileIndex];
|
2025-12-30 15:09:30 +10:00
|
|
|
FsFile file;
|
2026-02-08 21:29:14 +01:00
|
|
|
if (Storage.openFileForRead("SLP", filename, file)) {
|
2026-02-13 12:16:39 +01:00
|
|
|
LOG_DBG("SLP", "Randomly loading: /sleep/%s", files[randomFileIndex].c_str());
|
2025-12-19 14:17:26 +01:00
|
|
|
delay(100);
|
2026-01-12 12:36:19 +01:00
|
|
|
Bitmap bitmap(file, true);
|
2025-12-19 14:17:26 +01:00
|
|
|
if (bitmap.parseHeaders() == BmpReaderError::Ok) {
|
2025-12-21 18:42:06 +11:00
|
|
|
renderBitmapSleepScreen(bitmap);
|
2025-12-19 14:17:26 +01:00
|
|
|
dir.close();
|
|
|
|
|
return;
|
|
|
|
|
}
|
|
|
|
|
}
|
|
|
|
|
}
|
|
|
|
|
}
|
|
|
|
|
if (dir) dir.close();
|
|
|
|
|
|
2025-12-19 08:45:14 +11:00
|
|
|
// Look for sleep.bmp on the root of the sd card to determine if we should
|
|
|
|
|
// render a custom sleep screen instead of the default.
|
2025-12-30 15:09:30 +10:00
|
|
|
FsFile file;
|
2026-02-08 21:29:14 +01:00
|
|
|
if (Storage.openFileForRead("SLP", "/sleep.bmp", file)) {
|
2026-01-12 12:36:19 +01:00
|
|
|
Bitmap bitmap(file, true);
|
2025-12-19 08:45:14 +11:00
|
|
|
if (bitmap.parseHeaders() == BmpReaderError::Ok) {
|
2026-02-13 12:16:39 +01:00
|
|
|
LOG_DBG("SLP", "Loading: /sleep.bmp");
|
2025-12-21 18:42:06 +11:00
|
|
|
renderBitmapSleepScreen(bitmap);
|
2025-12-19 08:45:14 +11:00
|
|
|
return;
|
|
|
|
|
}
|
|
|
|
|
}
|
|
|
|
|
|
|
|
|
|
renderDefaultSleepScreen();
|
|
|
|
|
}
|
|
|
|
|
|
|
|
|
|
void SleepActivity::renderDefaultSleepScreen() const {
|
2025-12-21 18:42:06 +11:00
|
|
|
const auto pageWidth = renderer.getScreenWidth();
|
|
|
|
|
const auto pageHeight = renderer.getScreenHeight();
|
2025-12-08 19:48:49 +11:00
|
|
|
|
|
|
|
|
renderer.clearScreen();
|
2026-02-06 02:50:01 +11:00
|
|
|
renderer.drawImage(Logo120, (pageWidth - 120) / 2, (pageHeight - 120) / 2, 120, 120);
|
feat: User-Interface I18n System (#728)
## Summary
**What is the goal of this PR?**
This PR introduces Internationalization (i18n) support, enabling users
to switch the UI language dynamically.
**What changes are included?**
- Core Logic: Added I18n class (`lib/I18n/I18n.h/cpp`) to manage
language state and string retrieval.
- Data Structures:
- `lib/I18n/I18nStrings.h/cpp`: Static string arrays for each supported
language.
- `lib/I18n/I18nKeys.h`: Enum definitions for type-safe string access.
- `lib/I18n/translations.csv`: single source of truth.
- Documentation: Added `docs/i18n.md` detailing the workflow for
developers and translators.
- New Settings activity:
`src/activities/settings/LanguageSelectActivity.h/cpp`
## Additional Context
This implementation (building on concepts from #505) prioritizes
performance and memory efficiency.
The core approach is to store all localized strings for each language in
dedicated arrays and access them via enums. This provides O(1) access
with zero runtime overhead, and avoids the heap allocations, hashing,
and collision handling required by `std::map` or `std::unordered_map`.
The main trade-off is that enums and string arrays must remain perfectly
synchronized—any mismatch would result in incorrect strings being
displayed in the UI.
To eliminate this risk, I added a Python script that automatically
generates `I18nStrings.h/.cpp` and `I18nKeys.h` from a CSV file, which
will serve as the single source of truth for all translations. The full
design and workflow are documented in `docs/i18n.md`.
### Next Steps
- [x] Python script `generate_i18n.py` to auto-generate C++ files from
CSV
- [x] Populate translations.csv with initial translations.
Currently available translations: English, Español, Français, Deutsch,
Čeština, Português (Brasil), Русский, Svenska.
Thanks, community!
**Status:** EDIT: ready to be merged.
As a proof of concept, the SPANISH strings currently mirror the English
ones, but are fully uppercased.
---
### AI Usage
Did you use AI tools to help write this code? _**< PARTIALLY >**_
I used AI for the black work of replacing strings with I18n references
across the project, and for generating the documentation. EDIT: also
some help with merging changes from master.
---------
Co-authored-by: google-labs-jules[bot] <161369871+google-labs-jules[bot]@users.noreply.github.com>
Co-authored-by: yeyeto2788 <juanernestobiondi@gmail.com>
2026-02-16 15:28:42 +02:00
|
|
|
renderer.drawCenteredText(UI_10_FONT_ID, pageHeight / 2 + 70, tr(STR_CROSSPOINT), true, EpdFontFamily::BOLD);
|
|
|
|
|
renderer.drawCenteredText(SMALL_FONT_ID, pageHeight / 2 + 95, tr(STR_SLEEPING));
|
2025-12-15 13:16:46 +01:00
|
|
|
|
2025-12-21 18:42:06 +11:00
|
|
|
// Make sleep screen dark unless light is selected in settings
|
|
|
|
|
if (SETTINGS.sleepScreen != CrossPointSettings::SLEEP_SCREEN_MODE::LIGHT) {
|
2025-12-15 13:16:46 +01:00
|
|
|
renderer.invertScreen();
|
|
|
|
|
}
|
|
|
|
|
|
2026-01-27 18:50:15 +01:00
|
|
|
renderer.displayBuffer(HalDisplay::HALF_REFRESH);
|
2025-12-08 19:48:49 +11:00
|
|
|
}
|
2025-12-19 08:45:14 +11:00
|
|
|
|
2025-12-21 18:42:06 +11:00
|
|
|
void SleepActivity::renderBitmapSleepScreen(const Bitmap& bitmap) const {
|
2025-12-19 08:45:14 +11:00
|
|
|
int x, y;
|
2025-12-21 18:42:06 +11:00
|
|
|
const auto pageWidth = renderer.getScreenWidth();
|
|
|
|
|
const auto pageHeight = renderer.getScreenHeight();
|
2026-01-05 11:07:27 +01:00
|
|
|
float cropX = 0, cropY = 0;
|
2025-12-19 08:45:14 +11:00
|
|
|
|
2026-02-13 12:16:39 +01:00
|
|
|
LOG_DBG("SLP", "bitmap %d x %d, screen %d x %d", bitmap.getWidth(), bitmap.getHeight(), pageWidth, pageHeight);
|
2025-12-19 08:45:14 +11:00
|
|
|
if (bitmap.getWidth() > pageWidth || bitmap.getHeight() > pageHeight) {
|
|
|
|
|
// image will scale, make sure placement is right
|
2026-01-05 11:07:27 +01:00
|
|
|
float ratio = static_cast<float>(bitmap.getWidth()) / static_cast<float>(bitmap.getHeight());
|
2025-12-19 08:45:14 +11:00
|
|
|
const float screenRatio = static_cast<float>(pageWidth) / static_cast<float>(pageHeight);
|
|
|
|
|
|
2026-02-13 12:16:39 +01:00
|
|
|
LOG_DBG("SLP", "bitmap ratio: %f, screen ratio: %f", ratio, screenRatio);
|
2025-12-19 08:45:14 +11:00
|
|
|
if (ratio > screenRatio) {
|
|
|
|
|
// image wider than viewport ratio, scaled down image needs to be centered vertically
|
2026-01-05 11:07:27 +01:00
|
|
|
if (SETTINGS.sleepScreenCoverMode == CrossPointSettings::SLEEP_SCREEN_COVER_MODE::CROP) {
|
|
|
|
|
cropX = 1.0f - (screenRatio / ratio);
|
2026-02-13 12:16:39 +01:00
|
|
|
LOG_DBG("SLP", "Cropping bitmap x: %f", cropX);
|
2026-01-05 11:07:27 +01:00
|
|
|
ratio = (1.0f - cropX) * static_cast<float>(bitmap.getWidth()) / static_cast<float>(bitmap.getHeight());
|
|
|
|
|
}
|
2025-12-19 08:45:14 +11:00
|
|
|
x = 0;
|
2026-01-05 11:07:27 +01:00
|
|
|
y = std::round((static_cast<float>(pageHeight) - static_cast<float>(pageWidth) / ratio) / 2);
|
2026-02-13 12:16:39 +01:00
|
|
|
LOG_DBG("SLP", "Centering with ratio %f to y=%d", ratio, y);
|
2025-12-19 08:45:14 +11:00
|
|
|
} else {
|
|
|
|
|
// image taller than viewport ratio, scaled down image needs to be centered horizontally
|
2026-01-05 11:07:27 +01:00
|
|
|
if (SETTINGS.sleepScreenCoverMode == CrossPointSettings::SLEEP_SCREEN_COVER_MODE::CROP) {
|
|
|
|
|
cropY = 1.0f - (ratio / screenRatio);
|
2026-02-13 12:16:39 +01:00
|
|
|
LOG_DBG("SLP", "Cropping bitmap y: %f", cropY);
|
2026-01-05 11:07:27 +01:00
|
|
|
ratio = static_cast<float>(bitmap.getWidth()) / ((1.0f - cropY) * static_cast<float>(bitmap.getHeight()));
|
|
|
|
|
}
|
2026-01-21 13:27:41 +01:00
|
|
|
x = std::round((static_cast<float>(pageWidth) - static_cast<float>(pageHeight) * ratio) / 2);
|
2025-12-19 08:45:14 +11:00
|
|
|
y = 0;
|
2026-02-13 12:16:39 +01:00
|
|
|
LOG_DBG("SLP", "Centering with ratio %f to x=%d", ratio, x);
|
2025-12-19 08:45:14 +11:00
|
|
|
}
|
|
|
|
|
} else {
|
|
|
|
|
// center the image
|
|
|
|
|
x = (pageWidth - bitmap.getWidth()) / 2;
|
|
|
|
|
y = (pageHeight - bitmap.getHeight()) / 2;
|
|
|
|
|
}
|
|
|
|
|
|
2026-02-13 12:16:39 +01:00
|
|
|
LOG_DBG("SLP", "drawing to %d x %d", x, y);
|
2025-12-19 08:45:14 +11:00
|
|
|
renderer.clearScreen();
|
2026-01-27 13:21:59 +00:00
|
|
|
|
|
|
|
|
const bool hasGreyscale = bitmap.hasGreyscale() &&
|
|
|
|
|
SETTINGS.sleepScreenCoverFilter == CrossPointSettings::SLEEP_SCREEN_COVER_FILTER::NO_FILTER;
|
|
|
|
|
|
2026-01-05 11:07:27 +01:00
|
|
|
renderer.drawBitmap(bitmap, x, y, pageWidth, pageHeight, cropX, cropY);
|
2026-01-27 13:21:59 +00:00
|
|
|
|
|
|
|
|
if (SETTINGS.sleepScreenCoverFilter == CrossPointSettings::SLEEP_SCREEN_COVER_FILTER::INVERTED_BLACK_AND_WHITE) {
|
|
|
|
|
renderer.invertScreen();
|
|
|
|
|
}
|
|
|
|
|
|
2026-01-27 18:50:15 +01:00
|
|
|
renderer.displayBuffer(HalDisplay::HALF_REFRESH);
|
2025-12-19 08:45:14 +11:00
|
|
|
|
2026-01-27 13:21:59 +00:00
|
|
|
if (hasGreyscale) {
|
2025-12-19 08:45:14 +11:00
|
|
|
bitmap.rewindToData();
|
|
|
|
|
renderer.clearScreen(0x00);
|
|
|
|
|
renderer.setRenderMode(GfxRenderer::GRAYSCALE_LSB);
|
2026-01-05 11:07:27 +01:00
|
|
|
renderer.drawBitmap(bitmap, x, y, pageWidth, pageHeight, cropX, cropY);
|
2025-12-19 08:45:14 +11:00
|
|
|
renderer.copyGrayscaleLsbBuffers();
|
|
|
|
|
|
|
|
|
|
bitmap.rewindToData();
|
|
|
|
|
renderer.clearScreen(0x00);
|
|
|
|
|
renderer.setRenderMode(GfxRenderer::GRAYSCALE_MSB);
|
2026-01-05 11:07:27 +01:00
|
|
|
renderer.drawBitmap(bitmap, x, y, pageWidth, pageHeight, cropX, cropY);
|
2025-12-19 08:45:14 +11:00
|
|
|
renderer.copyGrayscaleMsbBuffers();
|
|
|
|
|
|
|
|
|
|
renderer.displayGrayBuffer();
|
|
|
|
|
renderer.setRenderMode(GfxRenderer::BW);
|
|
|
|
|
}
|
|
|
|
|
}
|
2025-12-21 18:42:06 +11:00
|
|
|
|
|
|
|
|
void SleepActivity::renderCoverSleepScreen() const {
|
2026-02-05 18:46:14 +07:00
|
|
|
void (SleepActivity::*renderNoCoverSleepScreen)() const;
|
|
|
|
|
switch (SETTINGS.sleepScreen) {
|
|
|
|
|
case (CrossPointSettings::SLEEP_SCREEN_MODE::COVER_CUSTOM):
|
|
|
|
|
renderNoCoverSleepScreen = &SleepActivity::renderCustomSleepScreen;
|
|
|
|
|
break;
|
|
|
|
|
default:
|
|
|
|
|
renderNoCoverSleepScreen = &SleepActivity::renderDefaultSleepScreen;
|
|
|
|
|
break;
|
|
|
|
|
}
|
|
|
|
|
|
2025-12-21 21:17:00 +11:00
|
|
|
if (APP_STATE.openEpubPath.empty()) {
|
2026-02-05 18:46:14 +07:00
|
|
|
return (this->*renderNoCoverSleepScreen)();
|
2025-12-21 21:17:00 +11:00
|
|
|
}
|
|
|
|
|
|
2025-12-28 23:56:05 +09:00
|
|
|
std::string coverBmpPath;
|
2026-01-12 10:55:47 +01:00
|
|
|
bool cropped = SETTINGS.sleepScreenCoverMode == CrossPointSettings::SLEEP_SCREEN_COVER_MODE::CROP;
|
2025-12-21 21:17:00 +11:00
|
|
|
|
2026-01-14 19:36:40 +09:00
|
|
|
// Check if the current book is XTC, TXT, or EPUB
|
2026-01-07 20:07:23 +10:00
|
|
|
if (StringUtils::checkFileExtension(APP_STATE.openEpubPath, ".xtc") ||
|
|
|
|
|
StringUtils::checkFileExtension(APP_STATE.openEpubPath, ".xtch")) {
|
2025-12-28 23:56:05 +09:00
|
|
|
// Handle XTC file
|
|
|
|
|
Xtc lastXtc(APP_STATE.openEpubPath, "/.crosspoint");
|
|
|
|
|
if (!lastXtc.load()) {
|
2026-02-13 12:16:39 +01:00
|
|
|
LOG_ERR("SLP", "Failed to load last XTC");
|
2026-02-05 18:46:14 +07:00
|
|
|
return (this->*renderNoCoverSleepScreen)();
|
2025-12-28 23:56:05 +09:00
|
|
|
}
|
|
|
|
|
|
|
|
|
|
if (!lastXtc.generateCoverBmp()) {
|
2026-02-13 12:16:39 +01:00
|
|
|
LOG_ERR("SLP", "Failed to generate XTC cover bmp");
|
2026-02-05 18:46:14 +07:00
|
|
|
return (this->*renderNoCoverSleepScreen)();
|
2025-12-28 23:56:05 +09:00
|
|
|
}
|
|
|
|
|
|
|
|
|
|
coverBmpPath = lastXtc.getCoverBmpPath();
|
2026-01-14 19:36:40 +09:00
|
|
|
} else if (StringUtils::checkFileExtension(APP_STATE.openEpubPath, ".txt")) {
|
|
|
|
|
// Handle TXT file - looks for cover image in the same folder
|
|
|
|
|
Txt lastTxt(APP_STATE.openEpubPath, "/.crosspoint");
|
|
|
|
|
if (!lastTxt.load()) {
|
2026-02-13 12:16:39 +01:00
|
|
|
LOG_ERR("SLP", "Failed to load last TXT");
|
2026-02-05 18:46:14 +07:00
|
|
|
return (this->*renderNoCoverSleepScreen)();
|
2026-01-14 19:36:40 +09:00
|
|
|
}
|
|
|
|
|
|
|
|
|
|
if (!lastTxt.generateCoverBmp()) {
|
2026-02-13 12:16:39 +01:00
|
|
|
LOG_ERR("SLP", "No cover image found for TXT file");
|
2026-02-05 18:46:14 +07:00
|
|
|
return (this->*renderNoCoverSleepScreen)();
|
2026-01-14 19:36:40 +09:00
|
|
|
}
|
|
|
|
|
|
|
|
|
|
coverBmpPath = lastTxt.getCoverBmpPath();
|
2026-01-07 20:07:23 +10:00
|
|
|
} else if (StringUtils::checkFileExtension(APP_STATE.openEpubPath, ".epub")) {
|
2025-12-28 23:56:05 +09:00
|
|
|
// Handle EPUB file
|
|
|
|
|
Epub lastEpub(APP_STATE.openEpubPath, "/.crosspoint");
|
feat: Add CSS parsing and CSS support in EPUBs (#411)
## Summary
* **What is the goal of this PR?**
- Adds basic CSS parsing to EPUBs and determine the CSS rules when
rendering to the screen so that text is styled correctly. Currently
supports bold, underline, italics, margin, padding, and text alignment
## Additional Context
- My main reason for wanting this is that the book I'm currently
reading, Carl's Doomsday Scenario (2nd in the Dungeon Crawler Carl
series), relies _a lot_ on styled text for telling parts of the story.
When text is bolded, it's supposed to be a message that's rendered
"on-screen" in the story. When characters are "chatting" with each
other, the text is bolded and their names are underlined. Plus, normal
emphasis is provided with italicizing words here and there. So, this
greatly improves my experience reading this book on the Xteink, and I
figured it was useful enough for others too.
- For transparency: I'm a software engineer, but I'm mostly frontend and
TypeScript/JavaScript. It's been _years_ since I did any C/C++, so I
would not be surprised if I'm doing something dumb along the way in this
code. Please don't hesitate to ask for changes if something looks off. I
heavily relied on Claude Code for help, and I had a lot of inspiration
from how [microreader](https://github.com/CidVonHighwind/microreader)
achieves their CSS parsing and styling. I did give this as good of a
code review as I could and went through everything, and _it works on my
machine_ 😄
### Before


### After


---
### AI Usage
Did you use AI tools to help write this code? **YES**, Claude Code
2026-02-05 05:28:10 -05:00
|
|
|
// Skip loading css since we only need metadata here
|
|
|
|
|
if (!lastEpub.load(true, true)) {
|
2026-02-13 12:16:39 +01:00
|
|
|
LOG_ERR("SLP", "Failed to load last epub");
|
2026-02-05 18:46:14 +07:00
|
|
|
return (this->*renderNoCoverSleepScreen)();
|
2025-12-28 23:56:05 +09:00
|
|
|
}
|
|
|
|
|
|
2026-01-12 10:55:47 +01:00
|
|
|
if (!lastEpub.generateCoverBmp(cropped)) {
|
2026-02-13 12:16:39 +01:00
|
|
|
LOG_ERR("SLP", "Failed to generate cover bmp");
|
2026-02-05 18:46:14 +07:00
|
|
|
return (this->*renderNoCoverSleepScreen)();
|
2025-12-28 23:56:05 +09:00
|
|
|
}
|
|
|
|
|
|
2026-01-12 10:55:47 +01:00
|
|
|
coverBmpPath = lastEpub.getCoverBmpPath(cropped);
|
2026-01-07 20:07:23 +10:00
|
|
|
} else {
|
2026-02-05 18:46:14 +07:00
|
|
|
return (this->*renderNoCoverSleepScreen)();
|
2025-12-21 18:42:06 +11:00
|
|
|
}
|
|
|
|
|
|
2025-12-30 15:09:30 +10:00
|
|
|
FsFile file;
|
2026-02-08 21:29:14 +01:00
|
|
|
if (Storage.openFileForRead("SLP", coverBmpPath, file)) {
|
2025-12-21 18:42:06 +11:00
|
|
|
Bitmap bitmap(file);
|
|
|
|
|
if (bitmap.parseHeaders() == BmpReaderError::Ok) {
|
2026-02-13 12:16:39 +01:00
|
|
|
LOG_DBG("SLP", "Rendering sleep cover: %s", coverBmpPath.c_str());
|
2025-12-21 18:42:06 +11:00
|
|
|
renderBitmapSleepScreen(bitmap);
|
|
|
|
|
return;
|
|
|
|
|
}
|
|
|
|
|
}
|
|
|
|
|
|
2026-02-05 18:46:14 +07:00
|
|
|
return (this->*renderNoCoverSleepScreen)();
|
2025-12-21 18:42:06 +11:00
|
|
|
}
|
2026-01-05 10:08:39 +01:00
|
|
|
|
|
|
|
|
void SleepActivity::renderBlankSleepScreen() const {
|
|
|
|
|
renderer.clearScreen();
|
2026-01-27 18:50:15 +01:00
|
|
|
renderer.displayBuffer(HalDisplay::HALF_REFRESH);
|
2026-01-05 10:08:39 +01:00
|
|
|
}
|