FastLED 3.9.15
Loading...
Searching...
No Matches

◆ measureString() [2/2]

float fl::FontRenderer::measureString ( fl::span< const char > str) const

Definition at line 241 of file truetype.cpp.hpp.

241 {
242 if (str.empty() || !mFont) return 0.0f;
243
244 float width = 0.0f;
245 i32 prevCodepoint = 0;
246
247 for (size_t i = 0; i < str.size(); ++i) {
248 i32 codepoint = static_cast<i32>(static_cast<unsigned char>(str[i]));
249
250 // Add kerning adjustment if this isn't the first character
251 if (prevCodepoint != 0) {
252 width += getKerning(prevCodepoint, codepoint);
253 }
254
255 // Add character advance
256 width += getAdvance(codepoint);
257 prevCodepoint = codepoint;
258 }
259
260 return width;
261}
float getKerning(i32 codepoint1, i32 codepoint2) const
float getAdvance(i32 codepoint) const
constexpr bool empty() const FL_NOEXCEPT
Definition span.h:510
constexpr fl::size size() const FL_NOEXCEPT
Definition span.h:458
u8 width
Definition blur.h:186

References fl::span< T, Extent >::empty(), getAdvance(), getKerning(), mFont, fl::span< T, Extent >::size(), and fl::width.

+ Here is the call graph for this function: