PR #1311: Replace separate spaceWidth + getSpaceKernAdjust() with a single getSpaceAdvance() that combines space glyph advance and kerning in fixed-point before snapping to pixels, eliminating +/-1 px rounding drift in text layout. PR #1322: Add early exit to fillUncompressedSizes() once all target entries are matched, avoiding unnecessary central directory traversal. Also updates tracking docs and verifies PR #1329 (reader utils refactor) matches upstream after merge. Made-with: Cursor
51 lines
2.5 KiB
C++
51 lines
2.5 KiB
C++
#pragma once
|
|
|
|
#include <EpdFontFamily.h>
|
|
|
|
#include <functional>
|
|
#include <memory>
|
|
#include <string>
|
|
#include <vector>
|
|
|
|
#include "blocks/BlockStyle.h"
|
|
#include "blocks/TextBlock.h"
|
|
|
|
class GfxRenderer;
|
|
|
|
class ParsedText {
|
|
std::vector<std::string> words;
|
|
std::vector<EpdFontFamily::Style> wordStyles;
|
|
std::vector<bool> wordContinues; // true = word attaches to previous (no space before it)
|
|
BlockStyle blockStyle;
|
|
bool extraParagraphSpacing;
|
|
bool hyphenationEnabled;
|
|
|
|
void applyParagraphIndent();
|
|
std::vector<size_t> computeLineBreaks(const GfxRenderer& renderer, int fontId, int pageWidth,
|
|
std::vector<uint16_t>& wordWidths, std::vector<bool>& continuesVec);
|
|
std::vector<size_t> computeHyphenatedLineBreaks(const GfxRenderer& renderer, int fontId, int pageWidth,
|
|
std::vector<uint16_t>& wordWidths,
|
|
std::vector<bool>& continuesVec);
|
|
bool hyphenateWordAtIndex(size_t wordIndex, int availableWidth, const GfxRenderer& renderer, int fontId,
|
|
std::vector<uint16_t>& wordWidths, bool allowFallbackBreaks);
|
|
void extractLine(size_t breakIndex, int pageWidth, const std::vector<uint16_t>& wordWidths,
|
|
const std::vector<bool>& continuesVec, const std::vector<size_t>& lineBreakIndices,
|
|
const std::function<void(std::shared_ptr<TextBlock>)>& processLine, const GfxRenderer& renderer,
|
|
int fontId);
|
|
std::vector<uint16_t> calculateWordWidths(const GfxRenderer& renderer, int fontId);
|
|
|
|
public:
|
|
explicit ParsedText(const bool extraParagraphSpacing, const bool hyphenationEnabled = false,
|
|
const BlockStyle& blockStyle = BlockStyle())
|
|
: blockStyle(blockStyle), extraParagraphSpacing(extraParagraphSpacing), hyphenationEnabled(hyphenationEnabled) {}
|
|
~ParsedText() = default;
|
|
|
|
void addWord(std::string word, EpdFontFamily::Style fontStyle, bool underline = false, bool attachToPrevious = false);
|
|
void setBlockStyle(const BlockStyle& blockStyle) { this->blockStyle = blockStyle; }
|
|
BlockStyle& getBlockStyle() { return blockStyle; }
|
|
size_t size() const { return words.size(); }
|
|
bool isEmpty() const { return words.empty(); }
|
|
void layoutAndExtractLines(const GfxRenderer& renderer, int fontId, uint16_t viewportWidth,
|
|
const std::function<void(std::shared_ptr<TextBlock>)>& processLine,
|
|
bool includeLastLine = true);
|
|
}; |