mirror of
https://github.com/crosspoint-reader/crosspoint-reader.git
synced 2026-04-29 10:26:52 -07:00
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>
71 lines
2.4 KiB
C++
71 lines
2.4 KiB
C++
#pragma once
|
|
#include <Epub.h>
|
|
|
|
#include <memory>
|
|
#include <string>
|
|
|
|
/**
|
|
* CrossPoint position representation.
|
|
*/
|
|
struct CrossPointPosition {
|
|
int spineIndex; // Current spine item (chapter) index
|
|
int pageNumber; // Current page within the spine item
|
|
int totalPages; // Total pages in the current spine item
|
|
uint16_t paragraphIndex = 0; // 1-based synthetic paragraph index from XPath p[N]
|
|
bool hasParagraphIndex = false; // True when paragraphIndex was resolved from XPath
|
|
};
|
|
|
|
/**
|
|
* KOReader position representation.
|
|
*/
|
|
struct KOReaderPosition {
|
|
std::string xpath; // XPath-like progress string
|
|
float percentage; // Progress percentage (0.0 to 1.0)
|
|
};
|
|
|
|
/**
|
|
* Maps between CrossPoint and KOReader position formats.
|
|
*
|
|
* CrossPoint tracks position as (spineIndex, pageNumber).
|
|
* KOReader uses XPath-like strings + percentage.
|
|
*
|
|
* Since CrossPoint discards HTML structure during parsing, we generate
|
|
* synthetic XPath strings based on spine index, using percentage as the
|
|
* primary sync mechanism.
|
|
*/
|
|
class ProgressMapper {
|
|
public:
|
|
/**
|
|
* Convert CrossPoint position to KOReader format.
|
|
*
|
|
* @param epub The EPUB book
|
|
* @param pos CrossPoint position
|
|
* @return KOReader position
|
|
*/
|
|
static KOReaderPosition toKOReader(const std::shared_ptr<Epub>& epub, const CrossPointPosition& pos);
|
|
|
|
/**
|
|
* Convert KOReader position to CrossPoint format.
|
|
*
|
|
* Note: The returned pageNumber may be approximate since different
|
|
* rendering settings produce different page counts.
|
|
*
|
|
* @param epub The EPUB book
|
|
* @param koPos KOReader position
|
|
* @param currentSpineIndex Index of the currently open spine item (for density estimation)
|
|
* @param totalPagesInCurrentSpine Total pages in the current spine item (for density estimation)
|
|
* @return CrossPoint position
|
|
*/
|
|
static CrossPointPosition toCrossPoint(const std::shared_ptr<Epub>& epub, const KOReaderPosition& koPos,
|
|
int currentSpineIndex = -1, int totalPagesInCurrentSpine = 0);
|
|
|
|
private:
|
|
/**
|
|
* Generate a fallback XPath by streaming the spine item's XHTML and resolving
|
|
* a paragraph/text position from intra-spine progress.
|
|
* Produces a full ancestry path such as
|
|
* /body/DocFragment[3]/body/p[42]/text().17.
|
|
*/
|
|
static std::string generateXPath(const std::shared_ptr<Epub>& epub, int spineIndex, float intraSpineProgress);
|
|
};
|