Skip to content

Commit

Permalink
Persistent text position when using smaller or bigger scales
Browse files Browse the repository at this point in the history
  • Loading branch information
inanevin committed Nov 26, 2022
1 parent e537172 commit 6a02fc6
Showing 1 changed file with 9 additions and 0 deletions.
9 changes: 9 additions & 0 deletions src/Core/Drawer.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -3123,10 +3123,19 @@ namespace LinaVG
Vec4 lastMinGrad = color.start;
Vec2 pos = position;
int characterCount = 0;
bool first = true;

auto drawChar = [&](TextCharacter& ch) {
const int startIndex = buf->m_vertexBuffer.m_size;

if (first && scale != 1.0f)
{
const float desiredY = pos.y - ch.m_bearing.y;
const float actualY = pos.y - ch.m_bearing.y * scale;
pos.y += Math::Abs(actualY - desiredY) * (scale > 1.0f ? 1.0f : -1.0f);
first = false;
}

float x2 = pos.x + ch.m_bearing.x * scale;
float y2 = pos.y - ch.m_bearing.y * scale;
float w = ch.m_size.x * scale;
Expand Down

0 comments on commit 6a02fc6

Please sign in to comment.