More fixes
This commit is contained in:
@@ -587,11 +587,18 @@ bool MdReaderActivity::loadPageAtOffset(size_t offset, bool startInCodeBlock, st
|
|||||||
void MdReaderActivity::buildPageIndex() {
|
void MdReaderActivity::buildPageIndex() {
|
||||||
pageOffsets.clear();
|
pageOffsets.clear();
|
||||||
pageCodeBlockState.clear();
|
pageCodeBlockState.clear();
|
||||||
|
|
||||||
|
const size_t fileSize = txt->getFileSize();
|
||||||
|
if (fileSize == 0) {
|
||||||
|
totalPages = 0;
|
||||||
|
LOG_DBG("MDR", "Empty markdown file, no pages");
|
||||||
|
return;
|
||||||
|
}
|
||||||
|
|
||||||
pageOffsets.push_back(0);
|
pageOffsets.push_back(0);
|
||||||
pageCodeBlockState.push_back(0);
|
pageCodeBlockState.push_back(0);
|
||||||
|
|
||||||
size_t offset = 0;
|
size_t offset = 0;
|
||||||
const size_t fileSize = txt->getFileSize();
|
|
||||||
bool inCodeBlock = false;
|
bool inCodeBlock = false;
|
||||||
|
|
||||||
LOG_DBG("MDR", "Building page index for %zu bytes...", fileSize);
|
LOG_DBG("MDR", "Building page index for %zu bytes...", fileSize);
|
||||||
@@ -672,6 +679,7 @@ void MdReaderActivity::renderPage() {
|
|||||||
// Draw horizontal rule as a thin line
|
// Draw horizontal rule as a thin line
|
||||||
int hrY = y + lineHeight / 2;
|
int hrY = y + lineHeight / 2;
|
||||||
renderer.drawLine(cachedOrientedMarginLeft + line.indent, hrY, cachedOrientedMarginLeft + viewportWidth, hrY);
|
renderer.drawLine(cachedOrientedMarginLeft + line.indent, hrY, cachedOrientedMarginLeft + viewportWidth, hrY);
|
||||||
|
y += lineHeight;
|
||||||
} else {
|
} else {
|
||||||
if (line.isCodeBlock) {
|
if (line.isCodeBlock) {
|
||||||
const int barX = cachedOrientedMarginLeft + std::max(line.indent - 6, 0);
|
const int barX = cachedOrientedMarginLeft + std::max(line.indent - 6, 0);
|
||||||
@@ -739,11 +747,12 @@ void MdReaderActivity::renderStatusBar() const {
|
|||||||
void MdReaderActivity::saveProgress() const {
|
void MdReaderActivity::saveProgress() const {
|
||||||
FsFile f;
|
FsFile f;
|
||||||
if (Storage.openFileForWrite("MDR", txt->getCachePath() + "/progress.bin", f)) {
|
if (Storage.openFileForWrite("MDR", txt->getCachePath() + "/progress.bin", f)) {
|
||||||
|
uint32_t page = static_cast<uint32_t>(currentPage < 0 ? 0 : currentPage);
|
||||||
uint8_t data[4];
|
uint8_t data[4];
|
||||||
data[0] = currentPage & 0xFF;
|
data[0] = page & 0xFF;
|
||||||
data[1] = (currentPage >> 8) & 0xFF;
|
data[1] = (page >> 8) & 0xFF;
|
||||||
data[2] = 0;
|
data[2] = (page >> 16) & 0xFF;
|
||||||
data[3] = 0;
|
data[3] = (page >> 24) & 0xFF;
|
||||||
f.write(data, 4);
|
f.write(data, 4);
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
@@ -753,12 +762,14 @@ void MdReaderActivity::loadProgress() {
|
|||||||
if (Storage.openFileForRead("MDR", txt->getCachePath() + "/progress.bin", f)) {
|
if (Storage.openFileForRead("MDR", txt->getCachePath() + "/progress.bin", f)) {
|
||||||
uint8_t data[4];
|
uint8_t data[4];
|
||||||
if (f.read(data, 4) == 4) {
|
if (f.read(data, 4) == 4) {
|
||||||
currentPage = data[0] + (data[1] << 8);
|
uint32_t loadedPage = static_cast<uint32_t>(data[0]) | (static_cast<uint32_t>(data[1]) << 8) |
|
||||||
if (currentPage >= totalPages) {
|
(static_cast<uint32_t>(data[2]) << 16) | (static_cast<uint32_t>(data[3]) << 24);
|
||||||
currentPage = totalPages - 1;
|
if (totalPages == 0) {
|
||||||
}
|
|
||||||
if (currentPage < 0) {
|
|
||||||
currentPage = 0;
|
currentPage = 0;
|
||||||
|
} else if (loadedPage >= static_cast<uint32_t>(totalPages)) {
|
||||||
|
currentPage = totalPages - 1;
|
||||||
|
} else {
|
||||||
|
currentPage = static_cast<int>(loadedPage);
|
||||||
}
|
}
|
||||||
LOG_DBG("MDR", "Loaded progress: page %d/%d", currentPage, totalPages);
|
LOG_DBG("MDR", "Loaded progress: page %d/%d", currentPage, totalPages);
|
||||||
}
|
}
|
||||||
|
|||||||
@@ -98,10 +98,11 @@ void MdReaderTocSelectionActivity::render(RenderLock&&) {
|
|||||||
const bool isSelected = (itemIndex == selectorIndex);
|
const bool isSelected = (itemIndex == selectorIndex);
|
||||||
|
|
||||||
const auto& heading = headings[itemIndex];
|
const auto& heading = headings[itemIndex];
|
||||||
const int indentSize = contentRect.x + 20 + (heading.level - 1) * 10;
|
const int indentRelative = 20 + (heading.level - 1) * 10;
|
||||||
|
const int drawX = contentRect.x + indentRelative;
|
||||||
const std::string title =
|
const std::string title =
|
||||||
renderer.truncatedText(UI_10_FONT_ID, heading.title.c_str(), contentRect.width - 40 - indentSize);
|
renderer.truncatedText(UI_10_FONT_ID, heading.title.c_str(), contentRect.width - 40 - indentRelative);
|
||||||
renderer.drawText(UI_10_FONT_ID, indentSize, displayY, title.c_str(), !isSelected);
|
renderer.drawText(UI_10_FONT_ID, drawX, displayY, title.c_str(), !isSelected);
|
||||||
}
|
}
|
||||||
|
|
||||||
const auto labels = mappedInput.mapLabels(tr(STR_BACK), tr(STR_SELECT), tr(STR_DIR_UP), tr(STR_DIR_DOWN));
|
const auto labels = mappedInput.mapLabels(tr(STR_BACK), tr(STR_SELECT), tr(STR_DIR_UP), tr(STR_DIR_DOWN));
|
||||||
|
|||||||
@@ -56,7 +56,7 @@ void testUnderscoreEmphasisStillWorks() {
|
|||||||
auto spans = MdParser::parseInline("foo _bar_ baz");
|
auto spans = MdParser::parseInline("foo _bar_ baz");
|
||||||
ASSERT_EQ(flattenText(spans), "foo bar baz");
|
ASSERT_EQ(flattenText(spans), "foo bar baz");
|
||||||
ASSERT_EQ(spans.size(), 3);
|
ASSERT_EQ(spans.size(), 3);
|
||||||
ASSERT_EQ(spans[1].style == EpdFontFamily::ITALIC || spans[1].style == EpdFontFamily::BOLD_ITALIC, true);
|
ASSERT_EQ(spans[1].style, EpdFontFamily::ITALIC);
|
||||||
PASS();
|
PASS();
|
||||||
}
|
}
|
||||||
|
|
||||||
@@ -65,7 +65,7 @@ void testAsteriskEmphasisStillWorks() {
|
|||||||
auto spans = MdParser::parseInline("foo *bar* baz");
|
auto spans = MdParser::parseInline("foo *bar* baz");
|
||||||
ASSERT_EQ(flattenText(spans), "foo bar baz");
|
ASSERT_EQ(flattenText(spans), "foo bar baz");
|
||||||
ASSERT_EQ(spans.size(), 3);
|
ASSERT_EQ(spans.size(), 3);
|
||||||
ASSERT_EQ(spans[1].style == EpdFontFamily::ITALIC || spans[1].style == EpdFontFamily::BOLD_ITALIC, true);
|
ASSERT_EQ(spans[1].style, EpdFontFamily::ITALIC);
|
||||||
PASS();
|
PASS();
|
||||||
}
|
}
|
||||||
|
|
||||||
@@ -74,7 +74,7 @@ void testUnderscoreBoldWorks() {
|
|||||||
auto spans = MdParser::parseInline("foo __bar__ baz");
|
auto spans = MdParser::parseInline("foo __bar__ baz");
|
||||||
ASSERT_EQ(flattenText(spans), "foo bar baz");
|
ASSERT_EQ(flattenText(spans), "foo bar baz");
|
||||||
ASSERT_EQ(spans.size(), 3);
|
ASSERT_EQ(spans.size(), 3);
|
||||||
ASSERT_EQ(spans[1].style == EpdFontFamily::BOLD || spans[1].style == EpdFontFamily::BOLD_ITALIC, true);
|
ASSERT_EQ(spans[1].style, EpdFontFamily::BOLD);
|
||||||
PASS();
|
PASS();
|
||||||
}
|
}
|
||||||
|
|
||||||
|
|||||||
Reference in New Issue
Block a user