summaryrefslogtreecommitdiffstats
diff options
context:
space:
mode:
authorEskil Abrahamsen Blomfeldt <eskil.abrahamsen-blomfeldt@qt.io>2019-03-20 14:47:18 +0100
committerTomi Korpipää <tomi.korpipaa@qt.io>2019-03-21 05:50:32 +0000
commit78f9adbfd2e1fb7803b48c1746e2a30204eb07c9 (patch)
tree1547fcec6dc088cf1ad43cde98c1d1a27d8e1fd1
parentf98fbe77e3f4199f35383a90d438f6cf59d34354 (diff)
Fix cropped drop shadow on distance field text
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 <miikka.heikkinen@qt.io> Reviewed-by: Tomi Korpipää <tomi.korpipaa@qt.io>
-rw-r--r--src/runtime/q3dsscenemanager.cpp41
1 files 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);
}