Skip to content
Merged
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
4 changes: 3 additions & 1 deletion Inc/SpriteFont.h
Original file line number Diff line number Diff line change
Expand Up @@ -144,7 +144,9 @@ namespace DirectX

// Spacing properties
DIRECTX_TOOLKIT_API float __cdecl GetLineSpacing() const noexcept;
DIRECTX_TOOLKIT_API void __cdecl SetLineSpacing(float spacing);
DIRECTX_TOOLKIT_API void __cdecl SetLineSpacing(float spacing) noexcept;

DIRECTX_TOOLKIT_API void __cdecl SetPixelAlignment(bool enable) noexcept;

// Font properties
DIRECTX_TOOLKIT_API wchar_t __cdecl GetDefaultCharacter() const noexcept;
Expand Down
16 changes: 15 additions & 1 deletion Src/SpriteFont.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -54,6 +54,7 @@ class SpriteFont::Impl
std::vector<uint32_t> glyphsIndex;
Glyph const* defaultGlyph;
float lineSpacing;
bool pixelAlignment;

private:
void CreateTextureResource(_In_ ID3D11Device* device,
Expand Down Expand Up @@ -101,6 +102,7 @@ SpriteFont::Impl::Impl(
bool forceSRGB) noexcept(false) :
defaultGlyph(nullptr),
lineSpacing(0),
pixelAlignment(false),
utfBufferSize(0)
{
if (!device || !reader)
Expand Down Expand Up @@ -175,6 +177,7 @@ SpriteFont::Impl::Impl(
glyphs(iglyphs, iglyphs + glyphCount),
defaultGlyph(nullptr),
lineSpacing(ilineSpacing),
pixelAlignment(false),
utfBufferSize(0)
{
if (!itexture || !iglyphs)
Expand Down Expand Up @@ -480,6 +483,11 @@ void XM_CALLCONV SpriteFont::DrawString(_In_ SpriteBatch* spriteBatch, _In_z_ wc
offset = XMVectorMultiplyAdd(glyphRect, axisIsMirroredTable[effects & 3], offset);
}

if (pImpl->pixelAlignment)
{
offset = XMVectorRound(offset);
}

spriteBatch->Draw(pImpl->texture.Get(), position, &glyph->Subrect, color, rotation, offset, scale, effects, layerDepth);
}, true);
}
Expand Down Expand Up @@ -610,12 +618,18 @@ float SpriteFont::GetLineSpacing() const noexcept
}


void SpriteFont::SetLineSpacing(float spacing)
void SpriteFont::SetLineSpacing(float spacing) noexcept
{
pImpl->lineSpacing = spacing;
}


void SpriteFont::SetPixelAlignment(bool enable) noexcept
{
pImpl->pixelAlignment = enable;
}


// Font properties
wchar_t SpriteFont::GetDefaultCharacter() const noexcept
{
Expand Down
Loading