Utility/RichTextDrawer: Add character & line spacing offsets

This commit is contained in:
Lynix
2020-01-26 16:57:56 +01:00
parent 977044f59e
commit 8c7301f649
4 changed files with 162 additions and 33 deletions

View File

@@ -57,6 +57,12 @@ namespace Nz
return m_blocks[index].characterSize;
}
inline float RichTextDrawer::GetBlockCharacterSpacingOffset(std::size_t index) const
{
NazaraAssert(index < m_blocks.size(), "Invalid block index");
return m_blocks[index].characterSpacingOffset;
}
inline const Color& RichTextDrawer::GetBlockColor(std::size_t index) const
{
NazaraAssert(index < m_blocks.size(), "Invalid block index");
@@ -82,6 +88,18 @@ namespace Nz
return m_fonts[fontIndex].font;
}
inline float RichTextDrawer::GetBlockLineHeight(std::size_t index) const
{
NazaraAssert(index < m_blocks.size(), "Invalid block index");
return m_blocks[index].lineSpacingOffset;
}
inline float RichTextDrawer::GetBlockLineSpacingOffset(std::size_t index) const
{
NazaraAssert(index < m_blocks.size(), "Invalid block index");
return m_blocks[index].lineSpacingOffset;
}
inline const Color& RichTextDrawer::GetBlockOutlineColor(std::size_t index) const
{
NazaraAssert(index < m_blocks.size(), "Invalid block index");
@@ -111,6 +129,11 @@ namespace Nz
return m_defaultCharacterSize;
}
inline float RichTextDrawer::GetDefaultCharacterSpacingOffset() const
{
return m_defaultCharacterSpacingOffset;
}
inline const Color& RichTextDrawer::GetDefaultColor() const
{
return m_defaultColor;
@@ -121,6 +144,11 @@ namespace Nz
return m_defaultFont;
}
inline float RichTextDrawer::GetDefaultLineSpacingOffset() const
{
return m_defaultLineSpacingOffset;
}
inline const Color& RichTextDrawer::GetDefaultOutlineColor() const
{
return m_defaultOutlineColor;
@@ -136,9 +164,9 @@ namespace Nz
return m_defaultStyle;
}
inline void RichTextDrawer::AppendNewLine(const Font* font, unsigned int characterSize) const
inline void RichTextDrawer::AppendNewLine(const Font* font, unsigned int characterSize, float lineSpacingOffset) const
{
AppendNewLine(font, characterSize, InvalidGlyph, 0);
AppendNewLine(font, characterSize, lineSpacingOffset, InvalidGlyph, 0);
}
inline void RichTextDrawer::ClearGlyphs() const
@@ -173,6 +201,19 @@ namespace Nz
}
}
inline float RichTextDrawer::GetLineHeight(const Block& block) const
{
assert(block.fontIndex < m_fonts.size());
const FontData& fontData = m_fonts[block.fontIndex];
return GetLineHeight(block.lineSpacingOffset, fontData.font->GetSizeInfo(block.characterSize));
}
inline float RichTextDrawer::GetLineHeight(float lineSpacingOffset, const Font::SizeInfo& sizeInfo) const
{
return float(sizeInfo.lineHeight) + lineSpacingOffset;
}
inline std::size_t RichTextDrawer::HandleFontAddition(const FontRef& font)
{
auto it = m_fontIndexes.find(font);
@@ -204,10 +245,10 @@ namespace Nz
{
// Shift font indexes
m_fontIndexes.erase(fontData.font);
for (auto it = m_fontIndexes.begin(); it != m_fontIndexes.end(); ++it)
for (auto& fontIndexe : m_fontIndexes)
{
if (it->second > fontIndex)
it->second--;
if (fontIndexe.second > fontIndex)
fontIndexe.second--;
}
m_fonts.erase(m_fonts.begin() + fontIndex);
@@ -235,6 +276,14 @@ namespace Nz
InvalidateGlyphs();
}
inline void RichTextDrawer::SetBlockCharacterSpacingOffset(std::size_t index, float offset)
{
NazaraAssert(index < m_blocks.size(), "Invalid block index");
m_blocks[index].characterSpacingOffset = offset;
InvalidateGlyphs();
}
inline void RichTextDrawer::SetBlockColor(std::size_t index, const Color& color)
{
NazaraAssert(index < m_blocks.size(), "Invalid block index");
@@ -260,6 +309,14 @@ namespace Nz
InvalidateGlyphs();
}
inline void RichTextDrawer::SetBlockLineSpacingOffset(std::size_t index, float offset)
{
NazaraAssert(index < m_blocks.size(), "Invalid block index");
m_blocks[index].lineSpacingOffset = offset;
InvalidateGlyphs();
}
inline void RichTextDrawer::SetBlockOutlineColor(std::size_t index, const Color& color)
{
NazaraAssert(index < m_blocks.size(), "Invalid block index");
@@ -308,6 +365,11 @@ namespace Nz
m_defaultCharacterSize = characterSize;
}
inline void RichTextDrawer::SetDefaultCharacterSpacingOffset(float offset)
{
m_defaultCharacterSpacingOffset = offset;
}
inline void RichTextDrawer::SetDefaultColor(const Color& color)
{
m_defaultColor = color;
@@ -318,6 +380,11 @@ namespace Nz
m_defaultFont = font;
}
inline void RichTextDrawer::SetDefaultLineSpacingOffset(float offset)
{
m_defaultLineSpacingOffset = offset;
}
inline void RichTextDrawer::SetDefaultOutlineColor(const Color& color)
{
m_defaultOutlineColor = color;
@@ -351,6 +418,17 @@ namespace Nz
{
}
/*!
* Returns the character spacing offset used for the characters of the referenced block
* \return The referenced block character size
*
* \see GetColor, GetFont, GetStyle, GetText, SetCharacterSize
*/
inline float RichTextDrawer::BlockRef::GetCharacterSpacingOffset() const
{
return m_drawer.GetBlockCharacterSpacingOffset(m_blockIndex);
}
/*!
* Returns the character size used for the characters of the referenced block
* \return The referenced block character size
@@ -384,6 +462,17 @@ namespace Nz
return m_drawer.GetBlockFont(m_blockIndex);
}
/*!
* Returns the line spacing offset used for the characters of the referenced block
* \return The referenced block character size
*
* \see GetColor, GetFont, GetStyle, GetText, SetCharacterSize
*/
inline float RichTextDrawer::BlockRef::GetLineSpacingOffset() const
{
return m_drawer.GetBlockLineSpacingOffset(m_blockIndex);
}
/*!
* Returns the outline color used for the characters of the referenced block
* \return The referenced block outline color
@@ -439,6 +528,17 @@ namespace Nz
return m_drawer.GetBlockText(m_blockIndex);
}
/*!
* Changes the character spacing offset of the referenced block characters
* \remark This invalidates the drawer and will force a (complete or partial, depending on the block index) glyph regeneration to occur.
*
* \see GetCharacterSpacingOffset, SetColor, SetFont, SetStyle, SetText
*/
inline void RichTextDrawer::BlockRef::SetCharacterSpacingOffset(float offset)
{
m_drawer.SetBlockCharacterSpacingOffset(m_blockIndex, offset);
}
/*!
* Changes the character size of the referenced block characters
* \remark This invalidates the drawer and will force a (complete or partial, depending on the block index) glyph regeneration to occur.
@@ -472,6 +572,17 @@ namespace Nz
m_drawer.SetBlockFont(m_blockIndex, std::move(font));
}
/*!
* Changes the line spacing offset of the referenced block characters
* \remark This invalidates the drawer and will force a (complete or partial, depending on the block index) glyph regeneration to occur.
*
* \see GetLineSpacingOffset, SetColor, SetFont, SetStyle, SetText
*/
inline void RichTextDrawer::BlockRef::SetLineSpacingOffset(float offset)
{
m_drawer.SetBlockLineSpacingOffset(m_blockIndex, offset);
}
/*!
* Changes the outline color of the referenced block characters
* \remark This invalidates the drawer and will force a (complete or partial, depending on the block index) glyph regeneration to occur.