Allowed font to set glyph border
Former-commit-id: f410fb83ecd0e1ace639e32fd809d00caa4145bc
This commit is contained in:
parent
703ea6e9c8
commit
1b266e7d7c
|
|
@ -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<NzAbstractFontAtlas> 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<nzUInt64, std::unordered_map<nzUInt64, int>> m_kerningCache;
|
||||
mutable std::unordered_map<nzUInt64, GlyphMap> m_glyphes;
|
||||
mutable std::unordered_map<nzUInt64, SizeInfo> m_sizeInfoCache;
|
||||
unsigned int m_glyphBorder;
|
||||
unsigned int m_minimumSizeStep;
|
||||
|
||||
static NzFontLoader::LoaderList s_loaders;
|
||||
|
|
|
|||
|
|
@ -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<NzAbstractFontAtlas> 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;
|
||||
|
|
|
|||
Loading…
Reference in New Issue