From 78f9adbfd2e1fb7803b48c1746e2a30204eb07c9 Mon Sep 17 00:00:00 2001 From: Eskil Abrahamsen Blomfeldt Date: Wed, 20 Mar 2019 14:47:18 +0100 Subject: Fix cropped drop shadow on distance field text MIME-Version: 1.0 Content-Type: text/plain; charset=UTF-8 Content-Transfer-Encoding: 8bit The drop shadows would sometimes be cropped, either when the offset was negative or when the font size was larger than the font size in the cache. The fix is two-fold: First of all we need to expand the rendered area in the direction of the offset (so expand to the left for offsetX < 0.0). Secondly, we need to scale it by the font scale to convert to the actual rendered font size. Task-number: QT3DS-3139 Change-Id: I46e61a13baed43b313c0a90880bea519d8afcfba Reviewed-by: Miikka Heikkinen Reviewed-by: Tomi Korpipää --- src/runtime/q3dsscenemanager.cpp | 41 ++++++++++++++++++++++++++++------------ 1 file changed, 29 insertions(+), 12 deletions(-) diff --git a/src/runtime/q3dsscenemanager.cpp b/src/runtime/q3dsscenemanager.cpp index d7df8ac..08b2fed 100644 --- a/src/runtime/q3dsscenemanager.cpp +++ b/src/runtime/q3dsscenemanager.cpp @@ -5186,8 +5186,15 @@ Qt3DCore::QEntity *Q3DSSceneManager::buildText(Q3DSTextNode *text3DS, Q3DSLayerN float cy2 = cy1 + float(metrics.height); if (text3DS->shadow()) { - cx2 += shadowOffsetX; - cy2 += shadowOffsetY; + if (shadowOffsetX < 0.0) + cx1 += shadowOffsetX * fontScale; + else + cx2 += shadowOffsetX * fontScale; + + if (shadowOffsetY < 0.0) + cy1 += shadowOffsetY * fontScale; + else + cy2 += shadowOffsetY * fontScale; } float tx1 = float(c.x + c.xMargin); @@ -5195,12 +5202,22 @@ Qt3DCore::QEntity *Q3DSSceneManager::buildText(Q3DSTextNode *text3DS, Q3DSLayerN float ty1 = float(c.y + c.yMargin); float ty2 = ty1 + float(c.height); + // Preserve original bounds of glyphs + float ttx1 = tx1; + float tty1 = ty1; float ttx2 = tx2; float tty2 = ty2; if (text3DS->shadow()) { - tx2 += float(c.width) * shadowOffsetX / float(metrics.width); - ty2 += float(c.height) * shadowOffsetY / float(metrics.height); + if (shadowOffsetX < 0.0) + tx1 += float(c.width) * shadowOffsetX * fontScale / float(metrics.width); + else + tx2 += float(c.width) * shadowOffsetX * fontScale / float(metrics.width); + + if (shadowOffsetY < 0.0) + ty1 += float(c.height) * shadowOffsetY * fontScale / float(metrics.height); + else + ty2 += float(c.height) * shadowOffsetY * fontScale / float(metrics.height); } const QSGDistanceFieldGlyphCache::Texture *texture = cache->glyphTexture(glyphIndex); @@ -5226,8 +5243,8 @@ Qt3DCore::QEntity *Q3DSSceneManager::buildText(Q3DSTextNode *text3DS, Q3DSLayerN vertexes.append(ty1); if (text3DS->shadow()) { - vertexes.append(tx1); - vertexes.append(ty1); + vertexes.append(ttx1); + vertexes.append(tty1); vertexes.append(ttx2); vertexes.append(tty2); } @@ -5239,8 +5256,8 @@ Qt3DCore::QEntity *Q3DSSceneManager::buildText(Q3DSTextNode *text3DS, Q3DSLayerN vertexes.append(ty1); if (text3DS->shadow()) { - vertexes.append(tx1); - vertexes.append(ty1); + vertexes.append(ttx1); + vertexes.append(tty1); vertexes.append(ttx2); vertexes.append(tty2); } @@ -5252,8 +5269,8 @@ Qt3DCore::QEntity *Q3DSSceneManager::buildText(Q3DSTextNode *text3DS, Q3DSLayerN vertexes.append(ty2); if (text3DS->shadow()) { - vertexes.append(tx1); - vertexes.append(ty1); + vertexes.append(ttx1); + vertexes.append(tty1); vertexes.append(ttx2); vertexes.append(tty2); } @@ -5265,8 +5282,8 @@ Qt3DCore::QEntity *Q3DSSceneManager::buildText(Q3DSTextNode *text3DS, Q3DSLayerN vertexes.append(ty2); if (text3DS->shadow()) { - vertexes.append(tx1); - vertexes.append(ty1); + vertexes.append(ttx1); + vertexes.append(tty1); vertexes.append(ttx2); vertexes.append(tty2); } -- cgit v1.2.3