| 259 | } |
| 260 | |
| 261 | void Label::updateCharacters(const std::vector<uint32_t>& chars) { |
| 262 | if (!_font) return; |
| 263 | float nextFontPositionX = 0; |
| 264 | float nextFontPositionY = 0; |
| 265 | uint32_t prev = 0; |
| 266 | float kerningAmount = 0; |
| 267 | Size finalSize; |
| 268 | float longestLine = 0; |
| 269 | float totalHeight = 0; |
| 270 | uint32_t quantityOfLines = 1; |
| 271 | |
| 272 | for (size_t i = 0; i < _characters.size(); i++) { |
| 273 | if (_characters[i] && _characters[i]->sprite) { |
| 274 | _characters[i]->sprite->setVisible(false); |
| 275 | } |
| 276 | } |
| 277 | |
| 278 | if (_characters.size() < chars.size()) { |
| 279 | _characters.resize(chars.size()); |
| 280 | } |
| 281 | |
| 282 | for (uint32_t ch : chars) { |
| 283 | if (ch == '\n') { |
| 284 | quantityOfLines++; |
| 285 | } |
| 286 | } |
| 287 | |
| 288 | const bgfx::FontInfo& fontInfo = _font->getInfo(); |
| 289 | float lineHeight = (fontInfo.ascender - fontInfo.descender) * _fontScale + _lineGap; |
| 290 | totalHeight = lineHeight * quantityOfLines - (quantityOfLines > 0 ? _lineGap : 0); |
| 291 | nextFontPositionY = lineHeight * quantityOfLines - lineHeight; |
| 292 | |
| 293 | float padding = fontInfo.sdf ? fontInfo.pixelSize * SDF_FONT_BUFFER_PADDING_RATIO * _fontScale : 0; |
| 294 | |
| 295 | const bgfx::GlyphInfo* fontDef = nullptr; |
| 296 | for (size_t i = 0; i < chars.size(); i++) { |
| 297 | uint32_t ch = chars[i]; |
| 298 | CharItem* fontChar = _characters[i].get(); |
| 299 | |
| 300 | bool isTab = ch == '\t'; |
| 301 | if (isTab) { |
| 302 | ch = ' '; |
| 303 | } |
| 304 | |
| 305 | if (ch == '\n') { |
| 306 | nextFontPositionX = 0; |
| 307 | nextFontPositionY -= lineHeight; |
| 308 | if (fontChar) { |
| 309 | fontChar->code = ch; |
| 310 | if (fontChar->sprite) { |
| 311 | fontChar->sprite->setVisible(false); |
| 312 | } |
| 313 | } |
| 314 | continue; |
| 315 | } |
| 316 | |
| 317 | kerningAmount = s_cast<float>(SharedFontManager.getKerning(_font->getHandle(), prev, ch)) * _fontScale + _spacing; |
| 318 |
nothing calls this directly
no test coverage detected