| 92 | } |
| 93 | |
| 94 | int TextPainter::stringWidth(StringView s, unsigned charLimit) { |
| 95 | if (s.empty()) |
| 96 | return 0; |
| 97 | |
| 98 | String font = m_renderSettings.font, setFont = font; |
| 99 | m_fontTextureGroup.switchFont(font); |
| 100 | |
| 101 | Text::CommandsCallback commandsCallback = [&](StringView commands) { |
| 102 | commands.forEachSplitView(",", [&](StringView command, size_t, size_t) { |
| 103 | if (command == "reset") { |
| 104 | m_fontTextureGroup.switchFont(font = setFont); |
| 105 | } else if (command == "set") { |
| 106 | setFont = font; |
| 107 | } else if (command.beginsWith("font=")) { |
| 108 | m_fontTextureGroup.switchFont(font = command.substr(5)); |
| 109 | } |
| 110 | }); |
| 111 | return true; |
| 112 | }; |
| 113 | |
| 114 | int width = 0; |
| 115 | Text::TextCallback textCallback = [&](StringView text) { |
| 116 | for (String::Char c : text) { |
| 117 | width += glyphWidth(c); |
| 118 | if (charLimit && --charLimit == 0) |
| 119 | return false; |
| 120 | } |
| 121 | return true; |
| 122 | }; |
| 123 | |
| 124 | Text::processText(s, textCallback, commandsCallback); |
| 125 | |
| 126 | return width; |
| 127 | } |
| 128 | |
| 129 | bool TextPainter::processWrapText(StringView text, unsigned* wrapWidth, WrapTextCallback textFunc) { |
| 130 | String font = m_renderSettings.font, setFont = font; |
nothing calls this directly
no test coverage detected