A fork of https://github.com/crosspoint-reader/crosspoint-reader
0
fork

Configure Feed

Select the types of activity you want to include in your feed.

Return -1 from getTocIndexForSpineIndex if TOC item does not exist

+15 -7
+1 -2
lib/Epub/Epub.cpp
··· 299 299 } 300 300 301 301 Serial.printf("[%lu] [EBP] TOC item not found\n", millis()); 302 - // not found - default to first item 303 - return 0; 302 + return -1; 304 303 }
+14 -5
src/screens/EpubReaderScreen.cpp
··· 328 328 const int titleMarginLeft = 20 + percentageTextWidth + 30 + marginLeft; 329 329 const int titleMarginRight = progressTextWidth + 30 + marginRight; 330 330 const int availableTextWidth = GfxRenderer::getScreenWidth() - titleMarginLeft - titleMarginRight; 331 - const auto tocItem = epub->getTocItem(epub->getTocIndexForSpineIndex(currentSpineIndex)); 332 - auto title = tocItem.title; 333 - int titleWidth = renderer.getTextWidth(SMALL_FONT_ID, title.c_str()); 334 - while (titleWidth > availableTextWidth) { 335 - title = title.substr(0, title.length() - 8) + "..."; 331 + const int tocIndex = epub->getTocIndexForSpineIndex(currentSpineIndex); 332 + 333 + std::string title; 334 + int titleWidth; 335 + if (tocIndex == -1) { 336 + title = "Unnamed"; 337 + titleWidth = renderer.getTextWidth(SMALL_FONT_ID, "Unnamed"); 338 + } else { 339 + const auto tocItem = epub->getTocItem(tocIndex); 340 + title = tocItem.title; 336 341 titleWidth = renderer.getTextWidth(SMALL_FONT_ID, title.c_str()); 342 + while (titleWidth > availableTextWidth) { 343 + title = title.substr(0, title.length() - 8) + "..."; 344 + titleWidth = renderer.getTextWidth(SMALL_FONT_ID, title.c_str()); 345 + } 337 346 } 338 347 339 348 renderer.drawText(SMALL_FONT_ID, titleMarginLeft + (availableTextWidth - titleWidth) / 2, textY, title.c_str());