## 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
41 lines
1.5 KiB
C++
41 lines
1.5 KiB
C++
#pragma once
|
|
|
|
#include <EpdFontFamily.h>
|
|
|
|
#include <functional>
|
|
#include <list>
|
|
#include <memory>
|
|
#include <string>
|
|
#include <vector>
|
|
|
|
#include "blocks/TextBlock.h"
|
|
|
|
class GfxRenderer;
|
|
|
|
class ParsedText {
|
|
std::list<std::string> words;
|
|
std::list<EpdFontFamily::Style> wordStyles;
|
|
TextBlock::Style style;
|
|
bool extraParagraphSpacing;
|
|
|
|
std::vector<size_t> computeLineBreaks(int pageWidth, int spaceWidth, const std::vector<uint16_t>& wordWidths) const;
|
|
void extractLine(size_t breakIndex, int pageWidth, int spaceWidth, const std::vector<uint16_t>& wordWidths,
|
|
const std::vector<size_t>& lineBreakIndices,
|
|
const std::function<void(std::shared_ptr<TextBlock>)>& processLine);
|
|
std::vector<uint16_t> calculateWordWidths(const GfxRenderer& renderer, int fontId);
|
|
|
|
public:
|
|
explicit ParsedText(const TextBlock::Style style, const bool extraParagraphSpacing)
|
|
: style(style), extraParagraphSpacing(extraParagraphSpacing) {}
|
|
~ParsedText() = default;
|
|
|
|
void addWord(std::string word, EpdFontFamily::Style fontStyle);
|
|
void setStyle(const TextBlock::Style style) { this->style = style; }
|
|
TextBlock::Style getStyle() const { return style; }
|
|
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);
|
|
};
|