Implement hyphenation support in text layout by enhancing word splitting and line breaking logic

This commit is contained in:
Arthur Tazhitdinov
2025-12-26 00:39:09 +05:00
parent 54d7a9437e
commit e7edcb6467
4 changed files with 255 additions and 131 deletions

View File

@@ -1,20 +1,12 @@
#pragma once
#include <EpdFontFamily.h>
#include <cstddef>
#include <string>
class GfxRenderer;
// Holds the split portions of a hyphenated word.
struct HyphenationResult {
std::string head;
std::string tail;
};
#include <vector>
class Hyphenator {
public:
// Splits a word so it fits within availableWidth, appending a hyphen to the head when needed.
static bool splitWord(const GfxRenderer& renderer, int fontId, const std::string& word, EpdFontStyle style,
int availableWidth, HyphenationResult* result, bool force);
// Returns byte offsets where the word may be hyphenated. When includeFallback is true, all positions obeying the
// minimum prefix/suffix constraints are returned even if no language-specific rule matches.
static std::vector<size_t> breakOffsets(const std::string& word, bool includeFallback);
};