Switch KOReader sync progress mapping from chapter matching to XPath-based mapping. - resolves KOReader positions using real XHTML ancestry paths - supports paragraph-based upload mapping with text offsets where needed - passes the current paragraph index into sync so uploads map back to KOReader more accurately No HTTP client changes are included. No reader-state or resume-flow changes are included. --------- Co-authored-by: jpirnay <jens@pirnay.com>
52 lines
2.1 KiB
C++
52 lines
2.1 KiB
C++
#pragma once
|
|
#include <functional>
|
|
#include <memory>
|
|
#include <optional>
|
|
#include <string>
|
|
|
|
#include "Epub.h"
|
|
|
|
class Page;
|
|
class GfxRenderer;
|
|
|
|
class Section {
|
|
std::shared_ptr<Epub> epub;
|
|
const int spineIndex;
|
|
GfxRenderer& renderer;
|
|
std::string filePath;
|
|
FsFile file;
|
|
|
|
void writeSectionFileHeader(int fontId, float lineCompression, bool extraParagraphSpacing, uint8_t paragraphAlignment,
|
|
uint16_t viewportWidth, uint16_t viewportHeight, bool hyphenationEnabled,
|
|
bool embeddedStyle, uint8_t imageRendering);
|
|
uint32_t onPageComplete(std::unique_ptr<Page> page);
|
|
|
|
public:
|
|
uint16_t pageCount = 0;
|
|
int currentPage = 0;
|
|
|
|
explicit Section(const std::shared_ptr<Epub>& epub, const int spineIndex, GfxRenderer& renderer)
|
|
: epub(epub),
|
|
spineIndex(spineIndex),
|
|
renderer(renderer),
|
|
filePath(epub->getCachePath() + "/sections/" + std::to_string(spineIndex) + ".bin") {}
|
|
~Section() = default;
|
|
bool loadSectionFile(int fontId, float lineCompression, bool extraParagraphSpacing, uint8_t paragraphAlignment,
|
|
uint16_t viewportWidth, uint16_t viewportHeight, bool hyphenationEnabled, bool embeddedStyle,
|
|
uint8_t imageRendering);
|
|
bool clearCache() const;
|
|
bool createSectionFile(int fontId, float lineCompression, bool extraParagraphSpacing, uint8_t paragraphAlignment,
|
|
uint16_t viewportWidth, uint16_t viewportHeight, bool hyphenationEnabled, bool embeddedStyle,
|
|
uint8_t imageRendering, const std::function<void()>& popupFn = nullptr);
|
|
std::unique_ptr<Page> loadPageFromSectionFile();
|
|
|
|
// Look up the page number for an anchor id from the section cache file.
|
|
std::optional<uint16_t> getPageForAnchor(const std::string& anchor) const;
|
|
|
|
// Look up the page number for a synthetic paragraph index from XPath p[N].
|
|
std::optional<uint16_t> getPageForParagraphIndex(uint16_t pIndex) const;
|
|
|
|
// Look up the synthetic paragraph index for the given rendered page.
|
|
std::optional<uint16_t> getParagraphIndexForPage(uint16_t page) const;
|
|
};
|