52 std::span<const GlyphID>
GetGlyphs()
const override {
return this->glyphs; }
53 std::span<const Position>
GetPositions()
const override {
return this->positions; }
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);
115 const bool isbuiltin =
font->fc->IsBuiltInFont();
117 this->
glyphs.reserve(char_count);
122 for (
int i = 0; i < char_count; i++) {
123 const GlyphID &glyph_id = this->
glyphs.emplace_back(
font->fc->MapCharToGlyph(chars[i]));
124 int x_advance =
font->fc->GetGlyphWidth(glyph_id);
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) {
128 this->
positions.emplace_back(advance, advance + x_advance - 1, (
font->fc->GetHeight() -
ScaleSpriteTrad(FontCache::GetDefaultFontHeight(
font->fc->GetSize()))) / 2);
130 this->
positions.emplace_back(advance, advance + x_advance - 1, 0);
132 advance += x_advance;
140 for (
const auto &run : *
this) {
141 leading = std::max(leading, run.GetLeading());
149 if (this->empty())
return 0;
157 const auto &positions = run.GetPositions();
158 if (positions.empty())
return 0;
159 return positions.back().right + 1;
169 return this->at(run);
180 assert(
runs.rbegin()->first == length);
194 if (this->
buffer ==
nullptr)
return nullptr;
196 std::unique_ptr<FallbackLine> l = std::make_unique<FallbackLine>();
198 if (*this->
buffer ==
'\0') {
201 l->emplace_back(this->
runs.begin()->second, this->buffer, 0, 0, 0);
206 FontMap::iterator iter = this->
runs.begin();
207 while (iter->first <= offset) {
209 assert(iter != this->
runs.end());
213 const char32_t *next_run = this->buffer_begin + iter->first;
215 const char32_t *begin = this->
buffer;
216 const char32_t *last_space =
nullptr;
217 const char32_t *last_char;
220 char32_t c = *this->
buffer;
228 if (this->
buffer == next_run) {
229 int w = l->GetWidth();
230 l->emplace_back(iter->second, begin, this->buffer - begin, begin - this->buffer_begin, w);
232 assert(iter != this->
runs.end());
234 next_run = this->buffer_begin + iter->first;
240 last_space = begin - 1;
248 if (width > max_width) {
251 if (width == char_width) {
258 if (last_space ==
nullptr) {
268 this->
buffer = last_space + 1;
269 last_char = last_space;
278 if (l->empty() || last_char - begin > 0) {
279 int w = l->GetWidth();
280 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 GetInternalCharLength(char32_t) const override
Get the number of elements the given character occupies in the underlying text buffer of the Layouter...
const ParagraphLayouter::VisualRun & GetVisualRun(size_t run) const override
Get a reference to the given run.
int GetLeading() const override
Get the font leading, or distance between the baselines of consecutive lines.
size_t CountRuns() const override
Get the number of runs in this line.
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.
int GetLeading() const override
Get the font leading, or distance between the baselines of consecutive lines.
std::vector< GlyphID > glyphs
The glyphs we're drawing.
std::span< const GlyphID > GetGlyphs() const override
Get the glyphs to draw.
size_t GetGlyphCount() const override
Get the number of glyphs.
const Font * GetFont() const override
Get the font.
std::span< const Position > GetPositions() const override
Get the positions for each of the glyphs.
std::vector< Position > positions
The positions of the glyphs.
std::span< const int > GetGlyphToCharMap() const override
The offset for each of the glyphs to the character run that was passed to the Layouter.
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.
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.
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.