| 1523 | } |
| 1524 | |
| 1525 | static void setBitmapForTTF( |
| 1526 | std::string_view text, int32_t scroll, PaletteIndex* bitmap, const int16_t* scrollPositionOffsets, PaletteIndex colour) |
| 1527 | { |
| 1528 | #ifndef DISABLE_TTF |
| 1529 | auto fontDesc = TTFGetFontFromSpriteBase(FontStyle::tiny); |
| 1530 | if (fontDesc->font == nullptr) |
| 1531 | { |
| 1532 | setBitmapForSprite(text, scroll, bitmap, scrollPositionOffsets, colour); |
| 1533 | return; |
| 1534 | } |
| 1535 | |
| 1536 | thread_local std::string ttfBuffer; |
| 1537 | ttfBuffer.clear(); |
| 1538 | |
| 1539 | auto fmt = FmtString(text); |
| 1540 | for (const auto& token : fmt) |
| 1541 | { |
| 1542 | if (token.IsLiteral()) |
| 1543 | { |
| 1544 | ttfBuffer.append(token.text); |
| 1545 | } |
| 1546 | else if (FormatTokenIsColour(token.kind)) |
| 1547 | { |
| 1548 | auto colourIndex = FormatTokenToTextColour(token.kind); |
| 1549 | colour = getTextColourMapping(colourIndex).fill; |
| 1550 | } |
| 1551 | } |
| 1552 | |
| 1553 | auto surface = TTFSurfaceCacheGetOrAdd(fontDesc->font, ttfBuffer.c_str()); |
| 1554 | if (surface == nullptr) |
| 1555 | { |
| 1556 | return; |
| 1557 | } |
| 1558 | |
| 1559 | int32_t width = surface->w; |
| 1560 | auto src = static_cast<const uint8_t*>(surface->pixels); |
| 1561 | |
| 1562 | // Pitch offset |
| 1563 | src += 2 * width; |
| 1564 | |
| 1565 | // Line height offset |
| 1566 | int32_t min_vpos = -fontDesc->offset_y; |
| 1567 | int32_t max_vpos = std::min(surface->h - 2, min_vpos + 7); |
| 1568 | |
| 1569 | bool use_hinting = Config::Get().fonts.enableHinting && fontDesc->hinting_threshold > 0; |
| 1570 | |
| 1571 | for (int32_t x = 0;; x++) |
| 1572 | { |
| 1573 | if (x >= width) |
| 1574 | x = 0; |
| 1575 | |
| 1576 | // Skip any non-displayed columns |
| 1577 | if (scroll == 0) |
| 1578 | { |
| 1579 | int16_t scrollPosition = *scrollPositionOffsets; |
| 1580 | if (scrollPosition == -1) |
| 1581 | return; |
| 1582 |
no test coverage detected