mirror of
https://github.com/daveallie/crosspoint-reader.git
synced 2025-12-18 15:17:42 +03:00
Merge a20f861e3c into 67da8139b3
This commit is contained in:
commit
b5a6d7a35e
@ -150,6 +150,18 @@ bool Epub::load() {
|
|||||||
return false;
|
return false;
|
||||||
}
|
}
|
||||||
|
|
||||||
|
// determine size of spine items
|
||||||
|
size_t spineItemsCount = getSpineItemsCount();
|
||||||
|
size_t spineItemsSize = 0;
|
||||||
|
for (size_t i = 0; i < spineItemsCount; i++) {
|
||||||
|
std::string spineItem = getSpineItem(i);
|
||||||
|
size_t s = 0;
|
||||||
|
getItemSize(spineItem, &s);
|
||||||
|
spineItemsSize += s;
|
||||||
|
cumulativeSpineItemSize.emplace_back(spineItemsSize);
|
||||||
|
}
|
||||||
|
Serial.printf("[%lu] [EBP] Book size: %u\n", millis(), spineItemsSize);
|
||||||
|
|
||||||
Serial.printf("[%lu] [EBP] Loaded ePub: %s\n", millis(), filepath.c_str());
|
Serial.printf("[%lu] [EBP] Loaded ePub: %s\n", millis(), filepath.c_str());
|
||||||
|
|
||||||
return true;
|
return true;
|
||||||
@ -257,6 +269,8 @@ bool Epub::getItemSize(const std::string& itemHref, size_t* size) const {
|
|||||||
|
|
||||||
int Epub::getSpineItemsCount() const { return spine.size(); }
|
int Epub::getSpineItemsCount() const { return spine.size(); }
|
||||||
|
|
||||||
|
size_t Epub::getCumulativeSpineItemSize(const int spineIndex) const { return cumulativeSpineItemSize.at(spineIndex); }
|
||||||
|
|
||||||
std::string& Epub::getSpineItem(const int spineIndex) {
|
std::string& Epub::getSpineItem(const int spineIndex) {
|
||||||
if (spineIndex < 0 || spineIndex >= spine.size()) {
|
if (spineIndex < 0 || spineIndex >= spine.size()) {
|
||||||
Serial.printf("[%lu] [EBP] getSpineItem index:%d is out of range\n", millis(), spineIndex);
|
Serial.printf("[%lu] [EBP] getSpineItem index:%d is out of range\n", millis(), spineIndex);
|
||||||
|
|||||||
@ -20,6 +20,8 @@ class Epub {
|
|||||||
std::string filepath;
|
std::string filepath;
|
||||||
// the spine of the EPUB file
|
// the spine of the EPUB file
|
||||||
std::vector<std::pair<std::string, std::string>> spine;
|
std::vector<std::pair<std::string, std::string>> spine;
|
||||||
|
// the file size of the spine items (proxy to book progress)
|
||||||
|
std::vector<size_t> cumulativeSpineItemSize;
|
||||||
// the toc of the EPUB file
|
// the toc of the EPUB file
|
||||||
std::vector<EpubTocEntry> toc;
|
std::vector<EpubTocEntry> toc;
|
||||||
// the base path for items in the EPUB file
|
// the base path for items in the EPUB file
|
||||||
@ -51,7 +53,8 @@ class Epub {
|
|||||||
bool getItemSize(const std::string& itemHref, size_t* size) const;
|
bool getItemSize(const std::string& itemHref, size_t* size) const;
|
||||||
std::string& getSpineItem(int spineIndex);
|
std::string& getSpineItem(int spineIndex);
|
||||||
int getSpineItemsCount() const;
|
int getSpineItemsCount() const;
|
||||||
EpubTocEntry& getTocItem(int tocTndex);
|
size_t getCumulativeSpineItemSize(const int spineIndex) const;
|
||||||
|
EpubTocEntry& getTocItem(int tocIndex);
|
||||||
int getTocItemsCount() const;
|
int getTocItemsCount() const;
|
||||||
int getSpineIndexForTocIndex(int tocIndex) const;
|
int getSpineIndexForTocIndex(int tocIndex) const;
|
||||||
int getTocIndexForSpineIndex(int spineIndex) const;
|
int getTocIndexForSpineIndex(int spineIndex) const;
|
||||||
|
|||||||
@ -324,8 +324,24 @@ void EpubReaderScreen::renderContents(std::unique_ptr<Page> page) {
|
|||||||
|
|
||||||
void EpubReaderScreen::renderStatusBar() const {
|
void EpubReaderScreen::renderStatusBar() const {
|
||||||
constexpr auto textY = 776;
|
constexpr auto textY = 776;
|
||||||
|
|
||||||
|
// Calculate progress in book
|
||||||
|
size_t prevChapterSize = epub->getCumulativeSpineItemSize(currentSpineIndex - 1);
|
||||||
|
size_t curChapterSize = epub->getCumulativeSpineItemSize(currentSpineIndex) - prevChapterSize;
|
||||||
|
size_t bookSize = epub->getCumulativeSpineItemSize(epub->getSpineItemsCount() - 1);
|
||||||
|
size_t sectionProgSize =
|
||||||
|
static_cast<size_t>(static_cast<float>(section->currentPage) / section->pageCount * curChapterSize);
|
||||||
|
float bookProgress = static_cast<float>(prevChapterSize + sectionProgSize) / bookSize * 100.0;
|
||||||
|
char bookProgressStr[6] = "--.-";
|
||||||
|
std:
|
||||||
|
snprintf(bookProgressStr, 6, "%.1f", bookProgress);
|
||||||
|
// Serial.printf("[%lu] [EBP] prevChapterSize: %u bookSize: %u sectionProgSize: %u bookSize:%u Book progress: %s
|
||||||
|
// %%\n", millis(),
|
||||||
|
// prevChapterSize, bookSize, sectionProgSize, bookSize, bookProgressStr);
|
||||||
|
|
||||||
// Right aligned text for progress counter
|
// Right aligned text for progress counter
|
||||||
const std::string progress = std::to_string(section->currentPage + 1) + " / " + std::to_string(section->pageCount);
|
const std::string progress = std::to_string(section->currentPage + 1) + "/" + std::to_string(section->pageCount) +
|
||||||
|
" " + bookProgressStr + "%";
|
||||||
const auto progressTextWidth = renderer.getTextWidth(SMALL_FONT_ID, progress.c_str());
|
const auto progressTextWidth = renderer.getTextWidth(SMALL_FONT_ID, progress.c_str());
|
||||||
renderer.drawText(SMALL_FONT_ID, GfxRenderer::getScreenWidth() - marginRight - progressTextWidth, textY,
|
renderer.drawText(SMALL_FONT_ID, GfxRenderer::getScreenWidth() - marginRight - progressTextWidth, textY,
|
||||||
progress.c_str());
|
progress.c_str());
|
||||||
|
|||||||
Loading…
Reference in New Issue
Block a user