OpenTTD Source
20240919-master-gdf0233f4c2
|
Go to the documentation of this file.
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;
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);
FontSize GetSize() const
Get the FontSize of the font.
FontCache * fc
The font we are using.
int GetHeight() const
Get the height of the font.
FallbackParagraphLayout(char32_t *buffer, int length, FontMap &runs)
Create a new paragraph layouter.
int GetAscender() const
Get the ascender value of the font.
FontMap & runs
The fonts we have to use for this paragraph.
Interface to glue fallback and normal layouter into one.
FallbackVisualRun(Font *font, const char32_t *chars, int glyph_count, int char_offset, int x)
Create the visual run.
A single line worth of VisualRuns.
virtual bool IsBuiltInFont()=0
Is this a built-in sprite font?
int GetWidth() const override
Get the width of this line.
void Reflow() override
Reset the position to the start of the paragraph.
Visual run contains data about the bit of text with the same font.
std::vector< GlyphID > glyphs
The glyphs we're drawing.
bool IsTextDirectionChar(char32_t c)
Is the given character a text direction character.
int CountRuns() const override
Get the number of runs in this line.
uint32_t GlyphID
Glyphs are characters from a font.
const ParagraphLayouter::VisualRun & GetVisualRun(int run) const override
Get a specific visual run.
virtual uint GetGlyphWidth(GlyphID key)=0
Get the width of the glyph with the given key.
std::vector< int > glyph_to_char
The char index of the glyphs.
Class handling the splitting of a paragraph of text into lines and visual runs.
Container with information about a font.
Visual run contains data about the bit of text with the same font.
const char32_t * buffer_begin
Begin of the buffer.
static size_t AppendToBuffer(char32_t *buff, const char32_t *buffer_last, char32_t c)
Append a wide character to the internal buffer.
virtual GlyphID MapCharToGlyph(char32_t key, bool fallback=true)=0
Map a character into a glyph.
Font cache for basic fonts.
int GetLeading() const override
Get the height of the line.
static ParagraphLayouter * GetParagraphLayout(char32_t *buff, char32_t *buff_end, FontMap &fontMapping)
Get the actual ParagraphLayout for the given buffer.
int ScaleSpriteTrad(int value)
Scale traditional pixel dimensions to GUI zoom level, for drawing sprites.
bool IsWhitespace(char32_t c)
Check whether UNICODE character is whitespace or not, i.e.
A single line worth of VisualRuns.
uint8_t GetCharacterWidth(FontSize size, char32_t key)
Return width of character glyph.
const char32_t * buffer
The current location in the buffer.
std::map< int, Font * > FontMap
Mapping from index to font.
Font * font
The font used to layout these.
std::unique_ptr< const Line > NextLine(int max_width) override
Construct a new line with a maximum width.
std::vector< Position > positions
The positions of the glyphs.