summaryrefslogtreecommitdiffstats
diff options
context:
space:
mode:
authorKaj Grönholm <kaj.gronholm@qt.io>2019-08-08 11:47:12 +0300
committerKaj Grönholm <kaj.gronholm@qt.io>2019-09-05 12:27:32 +0300
commit3ca369a6ab81151b46898e34c8ddf6c5f429cde3 (patch)
tree30bbaca25362ab88b9fdb994dbf332f745db6dbd
parentef4e6f929dd8101ba3e939776e9abc10ffa6d07a (diff)
Fix eliding when text is aligned
When text element is aligned to left/right/top/bottom, text string maximum width/height shall be half of the text area size. Task-number: QT3DS-3776 Change-Id: I173375c09a4e29274f0882f1b067079288336e88 Reviewed-by: Tomi Korpipää <tomi.korpipaa@qt.io>
-rw-r--r--src/runtimerender/Qt3DSDistanceFieldRenderer.cpp11
1 files changed, 9 insertions, 2 deletions
diff --git a/src/runtimerender/Qt3DSDistanceFieldRenderer.cpp b/src/runtimerender/Qt3DSDistanceFieldRenderer.cpp
index 602ca60..cf80617 100644
--- a/src/runtimerender/Qt3DSDistanceFieldRenderer.cpp
+++ b/src/runtimerender/Qt3DSDistanceFieldRenderer.cpp
@@ -139,10 +139,17 @@ Q3DSDistanceFieldRenderer::buildGlyphsPerTexture(const SText &textInfo)
QRawFont font = m_fontDatabase.findFont(textInfo.m_Font.c_str());
qreal scaleFactor = font.pixelSize() / qreal(textInfo.m_FontSize);
+ const float boundingWidth = (textInfo.m_HorizontalAlignment == TextHorizontalAlignment::Left
+ || textInfo.m_HorizontalAlignment == TextHorizontalAlignment::Right)
+ ? halfWidth : boundingBox.x();
+ const float boundingHeight = (textInfo.m_VerticalAlignment == TextVerticalAlignment::Top
+ || textInfo.m_VerticalAlignment == TextVerticalAlignment::Bottom)
+ ? halfHeight : boundingBox.y();
+
const qreal maximumWidth = boundingBox.isNull() ? qreal(0x01000000)
- : qreal(boundingBox.x()) * scaleFactor;
+ : qreal(boundingWidth) * scaleFactor;
const qreal maximumHeight = boundingBox.isNull() ? qreal(0x01000000)
- : qreal(boundingBox.y()) * scaleFactor;
+ : qreal(boundingHeight) * scaleFactor;
QTextLayout layout;
QTextOption option = layout.textOption();