Implements StarDict-based dictionary lookup from the reader menu, adapted from upstream PR #857 with /.dictionary/ folder path, std::vector compatibility (PR #802), HTML definition rendering, orientation-aware button hints, side button hints with CCW text rotation, sparse index caching to SD card, pronunciation line filtering, and reorganized reader menu with bookmark stubs. Co-authored-by: Cursor <cursoragent@cursor.com>
41 lines
1.5 KiB
C++
41 lines
1.5 KiB
C++
#pragma once
|
|
#include <EpdFontFamily.h>
|
|
#include <HalStorage.h>
|
|
|
|
#include <memory>
|
|
#include <string>
|
|
#include <vector>
|
|
|
|
#include "Block.h"
|
|
#include "BlockStyle.h"
|
|
|
|
// Represents a line of text on a page
|
|
class TextBlock final : public Block {
|
|
private:
|
|
std::vector<std::string> words;
|
|
std::vector<uint16_t> wordXpos;
|
|
std::vector<EpdFontFamily::Style> wordStyles;
|
|
BlockStyle blockStyle;
|
|
|
|
public:
|
|
explicit TextBlock(std::vector<std::string> words, std::vector<uint16_t> word_xpos,
|
|
std::vector<EpdFontFamily::Style> word_styles, const BlockStyle& blockStyle = BlockStyle())
|
|
: words(std::move(words)),
|
|
wordXpos(std::move(word_xpos)),
|
|
wordStyles(std::move(word_styles)),
|
|
blockStyle(blockStyle) {}
|
|
~TextBlock() override = default;
|
|
void setBlockStyle(const BlockStyle& blockStyle) { this->blockStyle = blockStyle; }
|
|
const BlockStyle& getBlockStyle() const { return blockStyle; }
|
|
const std::vector<std::string>& getWords() const { return words; }
|
|
const std::vector<uint16_t>& getWordXpos() const { return wordXpos; }
|
|
const std::vector<EpdFontFamily::Style>& getWordStyles() const { return wordStyles; }
|
|
bool isEmpty() override { return words.empty(); }
|
|
void layout(GfxRenderer& renderer) override {};
|
|
// given a renderer works out where to break the words into lines
|
|
void render(const GfxRenderer& renderer, int fontId, int x, int y) const;
|
|
BlockType getType() override { return TEXT_BLOCK; }
|
|
bool serialize(FsFile& file) const;
|
|
static std::unique_ptr<TextBlock> deserialize(FsFile& file);
|
|
};
|