text with smallest possible spacing between glyphs
This commit is contained in:
@@ -96,12 +96,14 @@ namespace OpenVulkano::Scene
|
||||
const double lineHeight = m_atlasData->GetLineHeight();
|
||||
double posY = pos.y;
|
||||
Math::Vector2f bmin(pos), bmax(pos);
|
||||
float prevGlyphXBound = -INFINITY;
|
||||
for (auto begin = text.begin(), end = text.end(); begin != end;)
|
||||
{
|
||||
uint32_t c = utf8::next(begin, end);
|
||||
if (c == '\n')
|
||||
{
|
||||
posY -= lineHeight;
|
||||
prevGlyphXBound = -INFINITY;
|
||||
cursorX = pos.x;
|
||||
continue;
|
||||
}
|
||||
@@ -115,19 +117,26 @@ namespace OpenVulkano::Scene
|
||||
|
||||
const GlyphInfo& info = symbols.at(c);
|
||||
|
||||
float offset = 0;
|
||||
const bool isZeroLenGlyph = info.pos[1].x == 0;
|
||||
const bool isBitmap = m_atlasData->GetAtlasType().IsBitmap();
|
||||
if (prevGlyphXBound != -INFINITY && !isZeroLenGlyph && !isBitmap)
|
||||
{
|
||||
offset = prevGlyphXBound - (info.pos[0].x + cursorX);
|
||||
}
|
||||
|
||||
for (int i = 0; i < 4; i++)
|
||||
{
|
||||
vertices->position[i].x = info.pos[i].x + cursorX;
|
||||
vertices->position[i].x = info.pos[i].x + cursorX + offset;
|
||||
vertices->uv[i] = info.uv[i];
|
||||
if (i < 2) vertices->position[i].y = posY - info.pos[i].y;
|
||||
else vertices->position[i].y = posY + info.pos[i].y;
|
||||
vertices->color = m_cfg.textColor;
|
||||
vertices->background = m_cfg.backgroundColor;
|
||||
}
|
||||
|
||||
// TODO: change to lower value(or ideally remove completely) to avoid overlapping and make less space between symbols
|
||||
// when setting for depth comparison operator will be available( <= )
|
||||
cursorX += info.advance + 0.08;
|
||||
// slight offset for bitmap atlas since it's tightly packed without any extra padding, while sdf has additional padding
|
||||
cursorX += info.advance + (isBitmap ? 0.05 : 0);
|
||||
prevGlyphXBound = isZeroLenGlyph ? cursorX : vertices->position[2].x;
|
||||
|
||||
if (!m_symbolCount) bmin.x = vertices->position[0].x;
|
||||
bmax.x = std::max(bmax.x, vertices->position[1].x);
|
||||
|
||||
Reference in New Issue
Block a user