50 const Font *GetFont()
const override {
return this->
font; }
51 int GetGlyphCount()
const override {
return static_cast<int>(this->glyphs.size()); }
52 std::span<const GlyphID> GetGlyphs()
const override {
return this->
glyphs; }
53 std::span<const Position> GetPositions()
const override {
return this->
positions; }
54 int GetLeading()
const override {
return this->GetFont()->
fc->
GetHeight(); }
55 std::span<const int> GetGlyphToCharMap()
const override {
return this->
glyph_to_char; }
66 int GetInternalCharLength(
char32_t)
const override {
return 1; }
75 std::unique_ptr<const Line>
NextLine(
int max_width)
override;
87 return std::make_unique<FallbackParagraphLayout>(buff, buff_end - buff, font_mapping);
99 assert(buff < buffer_last);
117 this->glyphs.reserve(char_count);
118 this->glyph_to_char.reserve(char_count);
119 this->positions.reserve(char_count);
122 for (
int i = 0; i < char_count; i++) {
126 this->positions.emplace_back(advance, advance + x_advance - 1,
font->
fc->
GetAscender());
127 }
else if (chars[i] >= SCC_SPRITE_START && chars[i] <= SCC_SPRITE_END) {
130 this->positions.emplace_back(advance, advance + x_advance - 1, 0);
132 advance += x_advance;
133 this->glyph_to_char.push_back(char_offset + i);
144 for (
const auto &run : *
this) {
145 leading = std::max(leading, run.GetLeading());
157 if (this->empty())
return 0;
164 const auto &run = this->GetVisualRun(this->CountRuns() - 1);
165 const auto &positions = run.GetPositions();
166 if (positions.empty())
return 0;
167 return positions.back().right + 1;
176 return (uint)this->size();
185 return this->at(run);
196 assert(
runs.rbegin()->first == length);
218 if (this->
buffer ==
nullptr)
return nullptr;
220 std::unique_ptr<FallbackLine> l = std::make_unique<FallbackLine>();
222 if (*this->
buffer ==
'\0') {
225 l->emplace_back(this->
runs.begin()->second, this->buffer, 0, 0, 0);
230 FontMap::iterator iter = this->
runs.begin();
231 while (iter->first <= offset) {
233 assert(iter != this->
runs.end());
237 const char32_t *next_run = this->buffer_begin + iter->first;
239 const char32_t *begin = this->
buffer;
240 const char32_t *last_space =
nullptr;
241 const char32_t *last_char;
244 char32_t c = *this->
buffer;
252 if (this->
buffer == next_run) {
253 int w = l->GetWidth();
254 l->emplace_back(iter->second, begin, this->buffer - begin, begin - this->buffer_begin, w);
256 assert(iter != this->
runs.end());
258 next_run = this->buffer_begin + iter->first;
264 last_space = begin - 1;
272 if (width > max_width) {
275 if (width == char_width) {
282 if (last_space ==
nullptr) {
292 this->
buffer = last_space + 1;
293 last_char = last_space;
302 if (l->empty() || last_char - begin > 0) {
303 int w = l->GetWidth();
304 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.
std::vector< int > glyph_to_char
The char index of the glyphs.
Font * font
The font used to layout these.
FallbackVisualRun(Font *font, const char32_t *chars, int glyph_count, int char_offset, int x)
Create the visual run.
std::vector< GlyphID > glyphs
The glyphs we're drawing.
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.
int GetHeight() const
Get the height of the font.
virtual GlyphID MapCharToGlyph(char32_t key, bool fallback=true)=0
Map a character into a glyph.
virtual bool IsBuiltInFont()=0
Is this a built-in sprite font?
virtual uint GetGlyphWidth(GlyphID key)=0
Get the width of the glyph with the given key.
int GetAscender() const
Get the ascender value of the font.
FontSize GetSize() const
Get the FontSize of the font.
Container with information about a font.
FontCache * fc
The font we are using.
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.
uint32_t GlyphID
Glyphs are characters from a font.
uint8_t GetCharacterWidth(FontSize size, char32_t key)
Return width of character glyph.
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.
int ScaleSpriteTrad(int value)
Scale traditional pixel dimensions to GUI zoom level, for drawing sprites.