Utility/SimpleTextDrawer: Fix handling of whitespace glyphs
This commit is contained in:
parent
fd196cf0ae
commit
1794c83a32
|
|
@ -292,20 +292,8 @@ namespace Nz
|
|||
switch (character)
|
||||
{
|
||||
case ' ':
|
||||
advance = sizeInfo.spaceAdvance;
|
||||
break;
|
||||
|
||||
case '\n':
|
||||
if (!m_glyphs.empty())
|
||||
{
|
||||
Glyph& glyph = m_glyphs.back();
|
||||
m_lines.back().bounds.ExtendTo(glyph.bounds);
|
||||
}
|
||||
m_lines.emplace_back(Line{Rectf(0.f, m_drawPos.y, 0.f, sizeInfo.lineHeight), m_glyphs.size()});
|
||||
|
||||
advance = 0;
|
||||
m_drawPos.x = 0;
|
||||
m_drawPos.y += sizeInfo.lineHeight;
|
||||
advance = sizeInfo.spaceAdvance;
|
||||
break;
|
||||
|
||||
case '\t':
|
||||
|
|
@ -318,8 +306,6 @@ namespace Nz
|
|||
}
|
||||
|
||||
Glyph glyph;
|
||||
glyph.color = m_color;
|
||||
|
||||
if (!whitespace)
|
||||
{
|
||||
const Font::Glyph& fontGlyph = m_font->GetGlyph(m_characterSize, m_style, character);
|
||||
|
|
@ -330,6 +316,7 @@ namespace Nz
|
|||
|
||||
glyph.atlas = m_font->GetAtlas()->GetLayer(fontGlyph.layerIndex);
|
||||
glyph.atlasRect = fontGlyph.atlasRect;
|
||||
glyph.color = m_color;
|
||||
glyph.flipped = fontGlyph.flipped;
|
||||
|
||||
if (fontGlyph.requireFauxBold)
|
||||
|
|
@ -367,12 +354,31 @@ namespace Nz
|
|||
{
|
||||
glyph.atlas = nullptr;
|
||||
|
||||
glyph.bounds.Set(m_drawPos.x - advance, m_drawPos.y - sizeInfo.lineHeight, float(advance), sizeInfo.lineHeight);
|
||||
glyph.bounds.Set(m_drawPos.x, m_drawPos.y, float(advance), sizeInfo.lineHeight);
|
||||
|
||||
glyph.corners[0].Set(glyph.bounds.GetCorner(RectCorner_LeftTop));
|
||||
glyph.corners[1].Set(glyph.bounds.GetCorner(RectCorner_RightTop));
|
||||
glyph.corners[2].Set(glyph.bounds.GetCorner(RectCorner_LeftBottom));
|
||||
glyph.corners[3].Set(glyph.bounds.GetCorner(RectCorner_RightBottom));
|
||||
|
||||
switch (character)
|
||||
{
|
||||
case '\n':
|
||||
{
|
||||
if (!m_glyphs.empty())
|
||||
{
|
||||
Glyph& glyph = m_glyphs.back();
|
||||
m_lines.back().bounds.ExtendTo(glyph.bounds);
|
||||
}
|
||||
|
||||
advance = 0;
|
||||
m_drawPos.x = 0;
|
||||
m_drawPos.y += sizeInfo.lineHeight;
|
||||
|
||||
m_lines.emplace_back(Line{Rectf(0.f, sizeInfo.lineHeight * m_lines.size(), 0.f, sizeInfo.lineHeight), m_glyphs.size() + 1});
|
||||
break;
|
||||
}
|
||||
}
|
||||
}
|
||||
|
||||
m_lines.back().bounds.ExtendTo(glyph.bounds);
|
||||
|
|
@ -385,6 +391,7 @@ namespace Nz
|
|||
m_drawPos.x += advance;
|
||||
m_glyphs.push_back(glyph);
|
||||
}
|
||||
m_lines.back().bounds.ExtendTo(m_glyphs.back().bounds);
|
||||
|
||||
m_bounds.Set(Rectf(std::floor(m_workingBounds.x), std::floor(m_workingBounds.y), std::ceil(m_workingBounds.width), std::ceil(m_workingBounds.height)));
|
||||
}
|
||||
|
|
|
|||
Loading…
Reference in New Issue