1
0
mirror of https://github.com/borgesdan/xn65 synced 2024-12-29 21:54:47 +01:00

Corrige SpriteFont kerning

This commit is contained in:
Danilo 2024-06-01 12:43:11 -03:00
parent 4be6f4abcc
commit bc74e431a4
3 changed files with 25 additions and 4 deletions

View File

@ -43,11 +43,11 @@ namespace xna {
DxGlyph g;
g.Subrect.left = glyphs[i].Left();
g.Subrect.right = glyphs[i].Right();
g.Subrect.bottom = glyphs[i].Bottom();
g.Subrect.top = glyphs[i].Top();
g.Subrect.bottom = glyphs[i].Bottom();
g.Character = static_cast<Uint>(charMap[i]);
g.XOffset = kerning[i].X;
g.YOffset = kerning[i].Y;
g.YOffset = cropping[i].Y;
g.XAdvance = kerning[i].Z;
dxGlyps[i] = g;
}
@ -90,6 +90,19 @@ namespace xna {
return vec2;
}
Vector2 SpriteFont::MeasureString(WString const& text, bool ignoreWhiteSpace)
{
if (!impl->_dxSpriteFont)
return Vector2();
const auto size = impl->_dxSpriteFont->MeasureString(text.c_str(), ignoreWhiteSpace);
Vector2 vec2{};
vec2.X = size.m128_f32[0];
vec2.Y = size.m128_f32[1];
return vec2;
}
static constexpr void ConvertSpriteSort(SpriteSortMode value, DirectX::SpriteSortMode& target) {
target = static_cast<DirectX::SpriteSortMode>(static_cast<int>(value));
}

View File

@ -93,8 +93,8 @@ namespace xna {
std::vector<Vector3> const& kerning,
std::optional<Char> defaultCharacter);
~SpriteFont();
Vector2 MeasureString(String const& text, bool ignoreWhiteSpace = false);
Vector2 MeasureString(WString const& text, bool ignoreWhiteSpace = false);
Vector2 MeasureString(String const& text, bool ignoreWhiteSpace = true);
Vector2 MeasureString(WString const& text, bool ignoreWhiteSpace = true);
private:
sptr<Texture2D> textureValue = nullptr;

View File

@ -62,6 +62,14 @@ namespace PlatformerStarterKit {
DrawHud();
/*auto b = graphicsDevice->Viewport().Bounds();
auto p = Vector2(0, 0);
spriteBatch->DrawString(hudFont, " !\"#$%&'()*+,-./0123456789:;<=>?@", p, Colors::Black);
p.Y += 50;
spriteBatch->DrawString(hudFont, "ABCDEFGHIJKLMNOPQRSTUVWXYZ[\\]^_`", p, Colors::Black);
p.Y += 50;
spriteBatch->DrawString(hudFont, "abcdefghijklmnopqrstuvwxyz{|}~", p, Colors::Black);*/
spriteBatch->End();
Game::Draw(gameTime);