| 99 | } |
| 100 | |
| 101 | int32_t Font::GetWidth(std::string const& message) const |
| 102 | { |
| 103 | // Get texture information. |
| 104 | float const tw = static_cast<float>(mTexture->GetWidth()); |
| 105 | |
| 106 | float width = 0.0f; |
| 107 | uint32_t const length = std::min( |
| 108 | static_cast<uint32_t>(message.length()), mMaxMessageLength); |
| 109 | for (uint32_t i = 0; i < length; ++i) |
| 110 | { |
| 111 | // Get character data. |
| 112 | int32_t const c = static_cast<int32_t>(message[i]); |
| 113 | float const tx0 = mCharacterData[c]; |
| 114 | float const tx1 = mCharacterData[c + 1]; |
| 115 | float const charWidthM1 = (tx1 - tx0) * tw - 1.0f; // in pixels |
| 116 | |
| 117 | width += charWidthM1; |
| 118 | } |
| 119 | |
| 120 | return static_cast<int32_t>(std::ceil(width)); |
| 121 | } |
| 122 | |
| 123 | void Font::Typeset(int32_t viewportWidth, int32_t viewportHeight, int32_t x, int32_t y, |
| 124 | Vector4<float> const& color, std::string const& message) const |
no test coverage detected