mirror of
https://github.com/daveallie/crosspoint-reader.git
synced 2026-02-04 14:47:37 +03:00
Some checks are pending
CI / build (push) Waiting to run
## Summary * Update EpdFontFamily::Style to be u8 instead of u32 (saving 3 bytes per word) * Update layout width/height to be u16 from int * Update page element count to be u16 from u32 * Update text block element count to be u16 from u32 * Bumped section bin version to version 8
70 lines
1.8 KiB
C++
70 lines
1.8 KiB
C++
#include "Page.h"
|
|
|
|
#include <HardwareSerial.h>
|
|
#include <Serialization.h>
|
|
|
|
void PageLine::render(GfxRenderer& renderer, const int fontId, const int xOffset, const int yOffset) {
|
|
block->render(renderer, fontId, xPos + xOffset, yPos + yOffset);
|
|
}
|
|
|
|
bool PageLine::serialize(FsFile& file) {
|
|
serialization::writePod(file, xPos);
|
|
serialization::writePod(file, yPos);
|
|
|
|
// serialize TextBlock pointed to by PageLine
|
|
return block->serialize(file);
|
|
}
|
|
|
|
std::unique_ptr<PageLine> PageLine::deserialize(FsFile& file) {
|
|
int16_t xPos;
|
|
int16_t yPos;
|
|
serialization::readPod(file, xPos);
|
|
serialization::readPod(file, yPos);
|
|
|
|
auto tb = TextBlock::deserialize(file);
|
|
return std::unique_ptr<PageLine>(new PageLine(std::move(tb), xPos, yPos));
|
|
}
|
|
|
|
void Page::render(GfxRenderer& renderer, const int fontId, const int xOffset, const int yOffset) const {
|
|
for (auto& element : elements) {
|
|
element->render(renderer, fontId, xOffset, yOffset);
|
|
}
|
|
}
|
|
|
|
bool Page::serialize(FsFile& file) const {
|
|
const uint16_t count = elements.size();
|
|
serialization::writePod(file, count);
|
|
|
|
for (const auto& el : elements) {
|
|
// Only PageLine exists currently
|
|
serialization::writePod(file, static_cast<uint8_t>(TAG_PageLine));
|
|
if (!el->serialize(file)) {
|
|
return false;
|
|
}
|
|
}
|
|
|
|
return true;
|
|
}
|
|
|
|
std::unique_ptr<Page> Page::deserialize(FsFile& file) {
|
|
auto page = std::unique_ptr<Page>(new Page());
|
|
|
|
uint16_t count;
|
|
serialization::readPod(file, count);
|
|
|
|
for (uint16_t i = 0; i < count; i++) {
|
|
uint8_t tag;
|
|
serialization::readPod(file, tag);
|
|
|
|
if (tag == TAG_PageLine) {
|
|
auto pl = PageLine::deserialize(file);
|
|
page->elements.push_back(std::move(pl));
|
|
} else {
|
|
Serial.printf("[%lu] [PGE] Deserialization failed: Unknown tag %u\n", millis(), tag);
|
|
return nullptr;
|
|
}
|
|
}
|
|
|
|
return page;
|
|
}
|