| 200 | } |
| 201 | |
| 202 | Vector2f Font::MeasureStringEx(StringView text, float scale, float charSpacing, float maxWidth, std::int32_t* charFit, float* charFitWidths) |
| 203 | { |
| 204 | if (charFit != nullptr) { |
| 205 | *charFit = 0; |
| 206 | } |
| 207 | |
| 208 | std::size_t textLength = text.size(); |
| 209 | if (textLength == 0 || _charSize.Y <= 0) { |
| 210 | return Vector2f::Zero; |
| 211 | } |
| 212 | |
| 213 | float totalWidth = 0.0f, totalHeight = 0.0f; |
| 214 | std::size_t idx = 0;; |
| 215 | std::size_t lastCharFit = 0; |
| 216 | |
| 217 | do { |
| 218 | auto [c, next] = Utf8::NextChar(text, idx); |
| 219 | |
| 220 | Vector2f charSize = MeasureChar(c); |
| 221 | if (charSize.X > 0 && charSize.Y > 0) { |
| 222 | float totalWidthNew = totalWidth + (charSize.X + _baseSpacing) * charSpacing * scale; |
| 223 | if (charFitWidths != nullptr) { |
| 224 | do { |
| 225 | charFitWidths[lastCharFit++] = totalWidthNew; |
| 226 | } while (lastCharFit < next); |
| 227 | } |
| 228 | if (totalWidthNew > maxWidth) { |
| 229 | break; |
| 230 | } |
| 231 | totalWidth = totalWidthNew; |
| 232 | } |
| 233 | |
| 234 | idx = next; |
| 235 | } while (idx < textLength); |
| 236 | |
| 237 | if (charFit != nullptr) { |
| 238 | *charFit = static_cast<std::int32_t>(idx); |
| 239 | } |
| 240 | |
| 241 | totalHeight += (_charSize.Y * scale); |
| 242 | |
| 243 | return Vector2f(ceilf(totalWidth), ceilf(totalHeight)); |
| 244 | } |
| 245 | |
| 246 | void Font::DrawString(Canvas* canvas, StringView text, std::int32_t& charOffset, float x, float y, std::uint16_t z, Alignment align, Colorf color, float scale, float angleOffset, float varianceX, float varianceY, float speed, float charSpacing, float lineSpacing) |
| 247 | { |
no test coverage detected