mirror of
https://github.com/daveallie/crosspoint-reader.git
synced 2025-12-18 15:17:42 +03:00
Added setting for extra paragraph spacing.
This commit is contained in:
parent
2f46a0e651
commit
122e961e8a
@ -24,7 +24,8 @@ void Section::onPageComplete(std::unique_ptr<Page> page) {
|
|||||||
}
|
}
|
||||||
|
|
||||||
void Section::writeCacheMetadata(const int fontId, const float lineCompression, const int marginTop,
|
void Section::writeCacheMetadata(const int fontId, const float lineCompression, const int marginTop,
|
||||||
const int marginRight, const int marginBottom, const int marginLeft) const {
|
const int marginRight, const int marginBottom, const int marginLeft,
|
||||||
|
const bool extraParagraphSpacing) const {
|
||||||
std::ofstream outputFile(("/sd" + cachePath + "/section.bin").c_str());
|
std::ofstream outputFile(("/sd" + cachePath + "/section.bin").c_str());
|
||||||
serialization::writePod(outputFile, SECTION_FILE_VERSION);
|
serialization::writePod(outputFile, SECTION_FILE_VERSION);
|
||||||
serialization::writePod(outputFile, fontId);
|
serialization::writePod(outputFile, fontId);
|
||||||
@ -33,12 +34,14 @@ void Section::writeCacheMetadata(const int fontId, const float lineCompression,
|
|||||||
serialization::writePod(outputFile, marginRight);
|
serialization::writePod(outputFile, marginRight);
|
||||||
serialization::writePod(outputFile, marginBottom);
|
serialization::writePod(outputFile, marginBottom);
|
||||||
serialization::writePod(outputFile, marginLeft);
|
serialization::writePod(outputFile, marginLeft);
|
||||||
|
serialization::writePod(outputFile, extraParagraphSpacing);
|
||||||
serialization::writePod(outputFile, pageCount);
|
serialization::writePod(outputFile, pageCount);
|
||||||
outputFile.close();
|
outputFile.close();
|
||||||
}
|
}
|
||||||
|
|
||||||
bool Section::loadCacheMetadata(const int fontId, const float lineCompression, const int marginTop,
|
bool Section::loadCacheMetadata(const int fontId, const float lineCompression, const int marginTop,
|
||||||
const int marginRight, const int marginBottom, const int marginLeft) {
|
const int marginRight, const int marginBottom, const int marginLeft,
|
||||||
|
const bool extraParagraphSpacing) {
|
||||||
if (!SD.exists(cachePath.c_str())) {
|
if (!SD.exists(cachePath.c_str())) {
|
||||||
return false;
|
return false;
|
||||||
}
|
}
|
||||||
@ -63,15 +66,18 @@ bool Section::loadCacheMetadata(const int fontId, const float lineCompression, c
|
|||||||
|
|
||||||
int fileFontId, fileMarginTop, fileMarginRight, fileMarginBottom, fileMarginLeft;
|
int fileFontId, fileMarginTop, fileMarginRight, fileMarginBottom, fileMarginLeft;
|
||||||
float fileLineCompression;
|
float fileLineCompression;
|
||||||
|
bool fileExtraParagraphSpacing;
|
||||||
serialization::readPod(inputFile, fileFontId);
|
serialization::readPod(inputFile, fileFontId);
|
||||||
serialization::readPod(inputFile, fileLineCompression);
|
serialization::readPod(inputFile, fileLineCompression);
|
||||||
serialization::readPod(inputFile, fileMarginTop);
|
serialization::readPod(inputFile, fileMarginTop);
|
||||||
serialization::readPod(inputFile, fileMarginRight);
|
serialization::readPod(inputFile, fileMarginRight);
|
||||||
serialization::readPod(inputFile, fileMarginBottom);
|
serialization::readPod(inputFile, fileMarginBottom);
|
||||||
serialization::readPod(inputFile, fileMarginLeft);
|
serialization::readPod(inputFile, fileMarginLeft);
|
||||||
|
serialization::readPod(inputFile, fileExtraParagraphSpacing);
|
||||||
|
|
||||||
if (fontId != fileFontId || lineCompression != fileLineCompression || marginTop != fileMarginTop ||
|
if (fontId != fileFontId || lineCompression != fileLineCompression || marginTop != fileMarginTop ||
|
||||||
marginRight != fileMarginRight || marginBottom != fileMarginBottom || marginLeft != fileMarginLeft) {
|
marginRight != fileMarginRight || marginBottom != fileMarginBottom || marginLeft != fileMarginLeft ||
|
||||||
|
extraParagraphSpacing != fileExtraParagraphSpacing) {
|
||||||
inputFile.close();
|
inputFile.close();
|
||||||
Serial.printf("[%lu] [SCT] Deserialization failed: Parameters do not match\n", millis());
|
Serial.printf("[%lu] [SCT] Deserialization failed: Parameters do not match\n", millis());
|
||||||
clearCache();
|
clearCache();
|
||||||
@ -107,7 +113,8 @@ bool Section::clearCache() const {
|
|||||||
}
|
}
|
||||||
|
|
||||||
bool Section::persistPageDataToSD(const int fontId, const float lineCompression, const int marginTop,
|
bool Section::persistPageDataToSD(const int fontId, const float lineCompression, const int marginTop,
|
||||||
const int marginRight, const int marginBottom, const int marginLeft) {
|
const int marginRight, const int marginBottom, const int marginLeft,
|
||||||
|
const bool extraParagraphSpacing) {
|
||||||
const auto localPath = epub->getSpineItem(spineIndex);
|
const auto localPath = epub->getSpineItem(spineIndex);
|
||||||
|
|
||||||
// TODO: Should we get rid of this file all together?
|
// TODO: Should we get rid of this file all together?
|
||||||
@ -128,7 +135,7 @@ bool Section::persistPageDataToSD(const int fontId, const float lineCompression,
|
|||||||
const auto sdTmpHtmlPath = "/sd" + tmpHtmlPath;
|
const auto sdTmpHtmlPath = "/sd" + tmpHtmlPath;
|
||||||
|
|
||||||
ChapterHtmlSlimParser visitor(sdTmpHtmlPath.c_str(), renderer, fontId, lineCompression, marginTop, marginRight,
|
ChapterHtmlSlimParser visitor(sdTmpHtmlPath.c_str(), renderer, fontId, lineCompression, marginTop, marginRight,
|
||||||
marginBottom, marginLeft,
|
marginBottom, marginLeft, extraParagraphSpacing,
|
||||||
[this](std::unique_ptr<Page> page) { this->onPageComplete(std::move(page)); });
|
[this](std::unique_ptr<Page> page) { this->onPageComplete(std::move(page)); });
|
||||||
success = visitor.parseAndBuildPages();
|
success = visitor.parseAndBuildPages();
|
||||||
|
|
||||||
@ -138,7 +145,7 @@ bool Section::persistPageDataToSD(const int fontId, const float lineCompression,
|
|||||||
return false;
|
return false;
|
||||||
}
|
}
|
||||||
|
|
||||||
writeCacheMetadata(fontId, lineCompression, marginTop, marginRight, marginBottom, marginLeft);
|
writeCacheMetadata(fontId, lineCompression, marginTop, marginRight, marginBottom, marginLeft, extraParagraphSpacing);
|
||||||
|
|
||||||
return true;
|
return true;
|
||||||
}
|
}
|
||||||
|
|||||||
@ -13,7 +13,7 @@ class Section {
|
|||||||
std::string cachePath;
|
std::string cachePath;
|
||||||
|
|
||||||
void writeCacheMetadata(int fontId, float lineCompression, int marginTop, int marginRight, int marginBottom,
|
void writeCacheMetadata(int fontId, float lineCompression, int marginTop, int marginRight, int marginBottom,
|
||||||
int marginLeft) const;
|
int marginLeft, bool extraParagraphSpacing) const;
|
||||||
void onPageComplete(std::unique_ptr<Page> page);
|
void onPageComplete(std::unique_ptr<Page> page);
|
||||||
|
|
||||||
public:
|
public:
|
||||||
@ -26,10 +26,10 @@ class Section {
|
|||||||
}
|
}
|
||||||
~Section() = default;
|
~Section() = default;
|
||||||
bool loadCacheMetadata(int fontId, float lineCompression, int marginTop, int marginRight, int marginBottom,
|
bool loadCacheMetadata(int fontId, float lineCompression, int marginTop, int marginRight, int marginBottom,
|
||||||
int marginLeft);
|
int marginLeft, bool extraParagraphSpacing);
|
||||||
void setupCacheDir() const;
|
void setupCacheDir() const;
|
||||||
bool clearCache() const;
|
bool clearCache() const;
|
||||||
bool persistPageDataToSD(int fontId, float lineCompression, int marginTop, int marginRight, int marginBottom,
|
bool persistPageDataToSD(int fontId, float lineCompression, int marginTop, int marginRight, int marginBottom,
|
||||||
int marginLeft);
|
int marginLeft, bool extraParagraphSpacing);
|
||||||
std::unique_ptr<Page> loadPageFromSD() const;
|
std::unique_ptr<Page> loadPageFromSD() const;
|
||||||
};
|
};
|
||||||
|
|||||||
@ -274,6 +274,8 @@ void ChapterHtmlSlimParser::makePages() {
|
|||||||
currentTextBlock->layoutAndExtractLines(
|
currentTextBlock->layoutAndExtractLines(
|
||||||
renderer, fontId, marginLeft + marginRight,
|
renderer, fontId, marginLeft + marginRight,
|
||||||
[this](const std::shared_ptr<TextBlock>& textBlock) { addLineToPage(textBlock); });
|
[this](const std::shared_ptr<TextBlock>& textBlock) { addLineToPage(textBlock); });
|
||||||
// Extra paragrpah spacing
|
// Extra paragraph spacing if enabled
|
||||||
//currentPageNextY += lineHeight / 2;
|
if (extraParagraphSpacing) {
|
||||||
|
currentPageNextY += lineHeight / 2;
|
||||||
|
}
|
||||||
}
|
}
|
||||||
|
|||||||
@ -35,6 +35,7 @@ class ChapterHtmlSlimParser {
|
|||||||
int marginRight;
|
int marginRight;
|
||||||
int marginBottom;
|
int marginBottom;
|
||||||
int marginLeft;
|
int marginLeft;
|
||||||
|
bool extraParagraphSpacing;
|
||||||
|
|
||||||
void startNewTextBlock(TextBlock::BLOCK_STYLE style);
|
void startNewTextBlock(TextBlock::BLOCK_STYLE style);
|
||||||
void makePages();
|
void makePages();
|
||||||
@ -46,7 +47,8 @@ class ChapterHtmlSlimParser {
|
|||||||
public:
|
public:
|
||||||
explicit ChapterHtmlSlimParser(const char* filepath, GfxRenderer& renderer, const int fontId,
|
explicit ChapterHtmlSlimParser(const char* filepath, GfxRenderer& renderer, const int fontId,
|
||||||
const float lineCompression, const int marginTop, const int marginRight,
|
const float lineCompression, const int marginTop, const int marginRight,
|
||||||
const int marginBottom, const int marginLeft,
|
const int marginBottom, const int marginLeft,
|
||||||
|
const bool extraParagraphSpacing,
|
||||||
const std::function<void(std::unique_ptr<Page>)>& completePageFn)
|
const std::function<void(std::unique_ptr<Page>)>& completePageFn)
|
||||||
: filepath(filepath),
|
: filepath(filepath),
|
||||||
renderer(renderer),
|
renderer(renderer),
|
||||||
@ -56,6 +58,7 @@ class ChapterHtmlSlimParser {
|
|||||||
marginRight(marginRight),
|
marginRight(marginRight),
|
||||||
marginBottom(marginBottom),
|
marginBottom(marginBottom),
|
||||||
marginLeft(marginLeft),
|
marginLeft(marginLeft),
|
||||||
|
extraParagraphSpacing(extraParagraphSpacing),
|
||||||
completePageFn(completePageFn) {}
|
completePageFn(completePageFn) {}
|
||||||
~ChapterHtmlSlimParser() = default;
|
~ChapterHtmlSlimParser() = default;
|
||||||
bool parseAndBuildPages();
|
bool parseAndBuildPages();
|
||||||
|
|||||||
@ -19,6 +19,7 @@ bool CrossPointSettings::saveToFile() const {
|
|||||||
std::ofstream outputFile(SETTINGS_FILE);
|
std::ofstream outputFile(SETTINGS_FILE);
|
||||||
serialization::writePod(outputFile, SETTINGS_FILE_VERSION);
|
serialization::writePod(outputFile, SETTINGS_FILE_VERSION);
|
||||||
serialization::writePod(outputFile, whiteSleepScreen);
|
serialization::writePod(outputFile, whiteSleepScreen);
|
||||||
|
serialization::writePod(outputFile, extraParagraphSpacing);
|
||||||
outputFile.close();
|
outputFile.close();
|
||||||
|
|
||||||
Serial.printf("[%lu] [CPS] Settings saved to file\n", millis());
|
Serial.printf("[%lu] [CPS] Settings saved to file\n", millis());
|
||||||
@ -42,6 +43,7 @@ bool CrossPointSettings::loadFromFile() {
|
|||||||
}
|
}
|
||||||
|
|
||||||
serialization::readPod(inputFile, whiteSleepScreen);
|
serialization::readPod(inputFile, whiteSleepScreen);
|
||||||
|
serialization::readPod(inputFile, extraParagraphSpacing);
|
||||||
|
|
||||||
inputFile.close();
|
inputFile.close();
|
||||||
Serial.printf("[%lu] [CPS] Settings loaded from file\n", millis());
|
Serial.printf("[%lu] [CPS] Settings loaded from file\n", millis());
|
||||||
|
|||||||
@ -17,6 +17,9 @@ class CrossPointSettings {
|
|||||||
// Sleep screen settings
|
// Sleep screen settings
|
||||||
bool whiteSleepScreen = false;
|
bool whiteSleepScreen = false;
|
||||||
|
|
||||||
|
// Text rendering settings
|
||||||
|
bool extraParagraphSpacing = false;
|
||||||
|
|
||||||
~CrossPointSettings() = default;
|
~CrossPointSettings() = default;
|
||||||
|
|
||||||
// Get singleton instance
|
// Get singleton instance
|
||||||
|
|||||||
@ -5,6 +5,7 @@
|
|||||||
#include <SD.h>
|
#include <SD.h>
|
||||||
|
|
||||||
#include "Battery.h"
|
#include "Battery.h"
|
||||||
|
#include "CrossPointSettings.h"
|
||||||
#include "EpubReaderChapterSelectionScreen.h"
|
#include "EpubReaderChapterSelectionScreen.h"
|
||||||
#include "config.h"
|
#include "config.h"
|
||||||
|
|
||||||
@ -205,7 +206,7 @@ void EpubReaderScreen::renderScreen() {
|
|||||||
Serial.printf("[%lu] [ERS] Loading file: %s, index: %d\n", millis(), filepath.c_str(), currentSpineIndex);
|
Serial.printf("[%lu] [ERS] Loading file: %s, index: %d\n", millis(), filepath.c_str(), currentSpineIndex);
|
||||||
section = std::unique_ptr<Section>(new Section(epub, currentSpineIndex, renderer));
|
section = std::unique_ptr<Section>(new Section(epub, currentSpineIndex, renderer));
|
||||||
if (!section->loadCacheMetadata(READER_FONT_ID, lineCompression, marginTop, marginRight, marginBottom,
|
if (!section->loadCacheMetadata(READER_FONT_ID, lineCompression, marginTop, marginRight, marginBottom,
|
||||||
marginLeft)) {
|
marginLeft, SETTINGS.extraParagraphSpacing)) {
|
||||||
Serial.printf("[%lu] [ERS] Cache not found, building...\n", millis());
|
Serial.printf("[%lu] [ERS] Cache not found, building...\n", millis());
|
||||||
|
|
||||||
{
|
{
|
||||||
@ -228,7 +229,7 @@ void EpubReaderScreen::renderScreen() {
|
|||||||
|
|
||||||
section->setupCacheDir();
|
section->setupCacheDir();
|
||||||
if (!section->persistPageDataToSD(READER_FONT_ID, lineCompression, marginTop, marginRight, marginBottom,
|
if (!section->persistPageDataToSD(READER_FONT_ID, lineCompression, marginTop, marginRight, marginBottom,
|
||||||
marginLeft)) {
|
marginLeft, SETTINGS.extraParagraphSpacing)) {
|
||||||
Serial.printf("[%lu] [ERS] Failed to persist page data to SD\n", millis());
|
Serial.printf("[%lu] [ERS] Failed to persist page data to SD\n", millis());
|
||||||
section.reset();
|
section.reset();
|
||||||
return;
|
return;
|
||||||
|
|||||||
@ -7,7 +7,8 @@
|
|||||||
|
|
||||||
// Define the static settings list
|
// Define the static settings list
|
||||||
const SettingInfo SettingsScreen::settingsList[SettingsScreen::settingsCount] = {
|
const SettingInfo SettingsScreen::settingsList[SettingsScreen::settingsCount] = {
|
||||||
{"White Splash Screen", &CrossPointSettings::whiteSleepScreen}
|
{"White Splash Screen", &CrossPointSettings::whiteSleepScreen},
|
||||||
|
{"Extra Paragraph Spacing", &CrossPointSettings::extraParagraphSpacing}
|
||||||
};
|
};
|
||||||
|
|
||||||
void SettingsScreen::taskTrampoline(void* param) {
|
void SettingsScreen::taskTrampoline(void* param) {
|
||||||
|
|||||||
@ -24,7 +24,7 @@ class SettingsScreen final : public Screen {
|
|||||||
const std::function<void()> onGoHome;
|
const std::function<void()> onGoHome;
|
||||||
|
|
||||||
// Static settings list
|
// Static settings list
|
||||||
static constexpr int settingsCount = 1; // Number of settings
|
static constexpr int settingsCount = 2; // Number of settings
|
||||||
static const SettingInfo settingsList[settingsCount];
|
static const SettingInfo settingsList[settingsCount];
|
||||||
|
|
||||||
static void taskTrampoline(void* param);
|
static void taskTrampoline(void* param);
|
||||||
|
|||||||
Loading…
Reference in New Issue
Block a user