MCPcopy Create free account
hub / github.com/davideberly/GeometricTools / GetWidth

Method GetWidth

GTE/Graphics/Font.cpp:101–121  ·  view source on GitHub ↗

Source from the content-addressed store, hash-verified

99}
100
101int32_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
123void Font::Typeset(int32_t viewportWidth, int32_t viewportHeight, int32_t x, int32_t y,
124 Vector4<float> const& color, std::string const& message) const

Callers 12

TypesetMethod · 0.45
EnableMethod · 0.45
DX11Texture2Method · 0.45
DX11Texture2ArrayMethod · 0.45
DX11TextureRTMethod · 0.45
CopyBackBufferMethod · 0.45
DX11Texture3Method · 0.45
EnableMethod · 0.45
DX11TextureDSMethod · 0.45
SaveToPNGMethod · 0.45
SaveToPNGMethod · 0.45
SaveToJPEGMethod · 0.45

Calls 1

ceilFunction · 0.50

Tested by

no test coverage detected