51 const Font &GetFont()
const override {
return this->
font; }
52 int GetGlyphCount()
const override {
return static_cast<int>(this->glyphs.size()); }
53 std::span<const GlyphID> GetGlyphs()
const override {
return this->
glyphs; }
54 std::span<const Position> GetPositions()
const override {
return this->
positions; }
55 int GetLeading()
const override {
return GetCharacterHeight(this->GetFont().GetFontCache().GetSize()); }
56 std::span<const int> GetGlyphToCharMap()
const override {
return this->
glyph_to_char; }
67 int GetInternalCharLength(
char32_t)
const override {
return 1; }
76 std::unique_ptr<const Line>
NextLine(
int max_width)
override;
88 return std::make_unique<FallbackParagraphLayout>(buff, buff_end - buff, font_mapping);
100 assert(buff < buffer_last);
116 this->glyphs.reserve(char_count);
117 this->glyph_to_char.reserve(char_count);
118 this->positions.reserve(char_count);
120 FontCache &fc = this->font.GetFontCache();
121 int y_offset = fc.GetGlyphYOffset();;
123 for (
int i = 0; i < char_count; i++) {
126 this->positions.emplace_back(advance, advance + x_advance - 1, y_offset);
127 advance += x_advance;
128 this->glyph_to_char.push_back(char_offset + i);
139 for (
const auto &run : *
this) {
140 leading = std::max(leading, run.GetLeading());
152 if (this->empty())
return 0;
159 const auto &run = this->GetVisualRun(this->CountRuns() - 1);
160 const auto &positions = run.GetPositions();
161 if (positions.empty())
return 0;
162 return positions.back().right + 1;
171 return (uint)this->size();
180 return this->at(run);
191 assert(
runs.rbegin()->first == length);
213 if (this->
buffer ==
nullptr)
return nullptr;
215 std::unique_ptr<FallbackLine> l = std::make_unique<FallbackLine>();
217 if (*this->
buffer ==
'\0') {
220 l->emplace_back(this->
runs.begin()->second, this->buffer, 0, 0, 0);
225 FontMap::iterator iter = this->
runs.begin();
226 while (iter->first <= offset) {
228 assert(iter != this->
runs.end());
231 const FontCache *fc = &iter->second.GetFontCache();
232 assert(fc !=
nullptr);
233 const char32_t *next_run = this->buffer_begin + iter->first;
235 const char32_t *begin = this->
buffer;
236 const char32_t *last_space =
nullptr;
237 const char32_t *last_char;
240 char32_t c = *this->
buffer;
248 if (this->
buffer == next_run) {
249 int w = l->GetWidth();
250 assert(iter->second.font_index != INVALID_FONT_INDEX);
251 l->emplace_back(iter->second, begin, this->buffer - begin, begin - this->buffer_begin, w);
253 assert(iter != this->
runs.end());
255 next_run = this->buffer_begin + iter->first;
261 last_space = begin - 1;
269 if (width > max_width) {
272 if (width == char_width) {
279 if (last_space ==
nullptr) {
289 this->
buffer = last_space + 1;
290 last_char = last_space;
299 if (l->empty() || last_char - begin > 0) {
300 int w = l->GetWidth();
301 l->emplace_back(iter->second, begin, last_char - begin, begin - this->buffer_begin, w);
static std::unique_ptr< ParagraphLayouter > GetParagraphLayout(char32_t *buff, char32_t *buff_end, FontMap &font_mapping)
Get the actual ParagraphLayout for the given buffer.
static size_t AppendToBuffer(char32_t *buff, const char32_t *buffer_last, char32_t c)
Append a wide character to the internal buffer.
A single line worth of VisualRuns.
int GetWidth() const override
Get the width of this line.
int GetLeading() const override
Get the height of the line.
const ParagraphLayouter::VisualRun & GetVisualRun(int run) const override
Get a specific visual run.
int CountRuns() const override
Get the number of runs in this line.
Visual run contains data about the bit of text with the same font.
FallbackVisualRun(const Font &font, const char32_t *chars, int glyph_count, int char_offset, int x)
Create the visual run.
std::vector< int > glyph_to_char
The char index of the glyphs.
std::vector< GlyphID > glyphs
The glyphs we're drawing.
Font font
The font used to layout these.
std::vector< Position > positions
The positions of the glyphs.
Class handling the splitting of a paragraph of text into lines and visual runs.
const char32_t * buffer_begin
Begin of the buffer.
std::unique_ptr< const Line > NextLine(int max_width) override
Construct a new line with a maximum width.
const char32_t * buffer
The current location in the buffer.
FontMap & runs
The fonts we have to use for this paragraph.
FallbackParagraphLayout(char32_t *buffer, int length, FontMap &runs)
Create a new paragraph layouter.
void Reflow() override
Reset the position to the start of the paragraph.
Font cache for basic fonts.
virtual uint GetGlyphWidth(GlyphID key)=0
Get the width of the glyph with the given key.
virtual GlyphID MapCharToGlyph(char32_t key)=0
Map a character into a glyph.
FontSize GetSize() const
Get the FontSize of the font.
Container with information about a font.
A single line worth of VisualRuns.
Visual run contains data about the bit of text with the same font.
Interface to glue fallback and normal layouter into one.
Control codes that are embedded in the translation strings.
int GetCharacterHeight(FontSize size)
Get height of a character for a given font size.
uint32_t GlyphID
Glyphs are characters from a font.
uint8_t GetCharacterWidth(FontSize size, char32_t key)
Return width of character glyph.
Functions related to the gfx engine.
std::vector< std::pair< int, Font > > FontMap
Mapping from index to font.
Functions related to laying out the texts as fallback.
A number of safeguards to prevent using unsafe methods.
Definition of base types and functions in a cross-platform compatible way.
Functions related to low-level strings.
bool IsWhitespace(char32_t c)
Check whether UNICODE character is whitespace or not, i.e.
bool IsTextDirectionChar(char32_t c)
Is the given character a text direction character.
Functions related to zooming.