MCPcopy Create free account
hub / github.com/OpenTTD/OpenTTD / FallbackVisualRun

Method FallbackVisualRun

src/gfx_layout_fallback.cpp:112–135  ·  view source on GitHub ↗

* Create the visual run. * @param font The font to use for this run. * @param chars The characters to use for this run. * @param char_count The number of characters in this run. * @param char_offset This run's offset from the start of the layout input string. * @param x The initial x position for this run. */

Source from the content-addressed store, hash-verified

110 * @param x The initial x position for this run.
111 */
112FallbackParagraphLayout::FallbackVisualRun::FallbackVisualRun(Font *font, const char32_t *chars, int char_count, int char_offset, int x) :
113 font(font)
114{
115 const bool isbuiltin = font->fc->IsBuiltInFont();
116
117 this->glyphs.reserve(char_count);
118 this->glyph_to_char.reserve(char_count);
119 this->positions.reserve(char_count);
120
121 int advance = x;
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);
125 if (isbuiltin) {
126 this->positions.emplace_back(advance, advance + x_advance - 1, font->fc->GetAscender()); // Apply sprite font's ascender.
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); // Align sprite font to centre
129 } else {
130 this->positions.emplace_back(advance, advance + x_advance - 1, 0); // No ascender adjustment.
131 }
132 advance += x_advance;
133 this->glyph_to_char.push_back(char_offset + i);
134 }
135}
136
137/**
138 * Get the height of the line.

Callers

nothing calls this directly

Calls 9

ScaleSpriteTradFunction · 0.85
reserveMethod · 0.80
GetAscenderMethod · 0.80
push_backMethod · 0.80
IsBuiltInFontMethod · 0.45
MapCharToGlyphMethod · 0.45
GetGlyphWidthMethod · 0.45
GetHeightMethod · 0.45
GetSizeMethod · 0.45

Tested by

no test coverage detected