diff --git a/include/Nazara/Utility/Font.hpp b/include/Nazara/Utility/Font.hpp index 4ebef9d3d..c2a5f1412 100644 --- a/include/Nazara/Utility/Font.hpp +++ b/include/Nazara/Utility/Font.hpp @@ -57,6 +57,7 @@ class NAZARA_API NzFont : public NzResource, NzNonCopyable NzString GetFamilyName() const; int GetKerning(unsigned int characterSize, char32_t first, char32_t second) const; const Glyph& GetGlyph(unsigned int characterSize, nzUInt32 style, char32_t character) const; + unsigned int GetGlyphBorder() const; unsigned int GetMinimumStepSize() const; const SizeInfo& GetSizeInfo(unsigned int characterSize) const; NzString GetStyleName() const; @@ -72,6 +73,7 @@ class NAZARA_API NzFont : public NzResource, NzNonCopyable bool OpenFromStream(NzInputStream& stream, const NzFontParams& params = NzFontParams()); void SetAtlas(std::shared_ptr atlas); + void SetGlyphBorder(unsigned int borderSize); void SetMinimumStepSize(unsigned int minimumSizeStep); NzFont& operator=(NzFont&& font) = default; @@ -114,6 +116,7 @@ class NAZARA_API NzFont : public NzResource, NzNonCopyable mutable std::unordered_map> m_kerningCache; mutable std::unordered_map m_glyphes; mutable std::unordered_map m_sizeInfoCache; + unsigned int m_glyphBorder; unsigned int m_minimumSizeStep; static NzFontLoader::LoaderList s_loaders; diff --git a/src/Nazara/Utility/Font.cpp b/src/Nazara/Utility/Font.cpp index 65909fe05..81def3c1e 100644 --- a/src/Nazara/Utility/Font.cpp +++ b/src/Nazara/Utility/Font.cpp @@ -14,6 +14,7 @@ bool NzFontParams::IsValid() const } NzFont::NzFont() : +m_glyphBorder(1), m_minimumSizeStep(1) { } @@ -170,6 +171,11 @@ const NzFont::Glyph& NzFont::GetGlyph(unsigned int characterSize, nzUInt32 style return PrecacheGlyph(m_glyphes[key], characterSize, style, character); } +unsigned int NzFont::GetGlyphBorder() const +{ + return m_glyphBorder; +} + unsigned int NzFont::GetMinimumStepSize() const { return m_minimumSizeStep; @@ -265,6 +271,12 @@ void NzFont::SetAtlas(std::shared_ptr atlas) m_atlas = atlas; } +void NzFont::SetGlyphBorder(unsigned int borderSize) +{ + m_glyphBorder = borderSize; + ClearGlyphCache(); +} + void NzFont::SetMinimumStepSize(unsigned int minimumStepSize) { #if NAZARA_UTILITY_SAFE @@ -339,11 +351,9 @@ const NzFont::Glyph& NzFont::PrecacheGlyph(GlyphMap& glyphMap, unsigned int char // Insertion du rectangle dans l'un des atlas if (glyph.atlasRect.width > 0 && glyph.atlasRect.height > 0) // Si l'image contient quelque chose { - // Padding (pour éviter le débordement lors du filtrage) - const unsigned int padding = 1; // Un pixel de contour - - glyph.atlasRect.width += padding*2; - glyph.atlasRect.height += padding*2; + // Bordure (pour éviter le débordement lors du filtrage) + glyph.atlasRect.width += m_glyphBorder*2; + glyph.atlasRect.height += m_glyphBorder*2; // Insertion du rectangle dans l'atlas virtuel if (!m_atlas->Insert(fontGlyph.image, &glyph.atlasRect, &glyph.flipped, &glyph.layerIndex)) @@ -352,11 +362,11 @@ const NzFont::Glyph& NzFont::PrecacheGlyph(GlyphMap& glyphMap, unsigned int char return glyph; } - // Compensation du contour (centrage du glyphe) - glyph.atlasRect.x += padding; - glyph.atlasRect.y += padding; - glyph.atlasRect.width -= padding*2; - glyph.atlasRect.height -= padding*2; + // Compensation de la bordure (centrage du glyphe) + glyph.atlasRect.x += m_glyphBorder; + glyph.atlasRect.y += m_glyphBorder; + glyph.atlasRect.width -= m_glyphBorder*2; + glyph.atlasRect.height -= m_glyphBorder*2; } glyph.aabb = fontGlyph.aabb;