From fe97ecf408da60931fc49b502a223d59b5f93f99 Mon Sep 17 00:00:00 2001 From: Eskil Abrahamsen Blomfeldt Date: Thu, 9 Jun 2016 14:03:22 +0200 Subject: Make it possible to create distance fields with any height Assuming a certain max height for glyphs would make it impossible to render certain fonts. The follow up to this change is in Qt Quick, where the code must also be adapted to make it work. Task-number: QTBUG-52389 Change-Id: Iabebb2de21a92d1537b2965aa6603529c1d5d587 Reviewed-by: Yoann Lopes --- src/gui/text/qdistancefield.cpp | 3 ++- 1 file changed, 2 insertions(+), 1 deletion(-) (limited to 'src/gui/text/qdistancefield.cpp') diff --git a/src/gui/text/qdistancefield.cpp b/src/gui/text/qdistancefield.cpp index 6a7019bc3c..c493ca1dad 100644 --- a/src/gui/text/qdistancefield.cpp +++ b/src/gui/text/qdistancefield.cpp @@ -799,8 +799,9 @@ QDistanceFieldData *QDistanceFieldData::create(const QPainterPath &path, bool do { int dfMargin = QT_DISTANCEFIELD_RADIUS(doubleResolution) / QT_DISTANCEFIELD_SCALE(doubleResolution); int glyphWidth = qCeil(path.boundingRect().width() / QT_DISTANCEFIELD_SCALE(doubleResolution)) + dfMargin * 2; + int glyphHeight = qCeil(path.boundingRect().height() / QT_DISTANCEFIELD_SCALE(doubleResolution)) + dfMargin * 2; - QDistanceFieldData *data = create(QSize(glyphWidth, QT_DISTANCEFIELD_TILESIZE(doubleResolution))); + QDistanceFieldData *data = create(QSize(glyphWidth, glyphHeight)); makeDistanceField(data, path, -- cgit v1.2.3 From c2d3c2b9f97cd842f2cbcc28acbc7a140b45222f Mon Sep 17 00:00:00 2001 From: Eskil Abrahamsen Blomfeldt Date: Fri, 10 Jun 2016 13:38:31 +0200 Subject: Fix crash when creating distance field for large glyph Do the multiplication of the normal components in floating point to avoid integer overflows. Also add an assert, since a scale of 0 here will cause a normal of (0, 0) which will assert further into the drawRectangle() function, and the cause is not immediately clear. Task-number: QTBUG-51956 Change-Id: If7187d56af28eaa149f8f362050a587da5adb262 Reviewed-by: Yoann Lopes --- src/gui/text/qdistancefield.cpp | 4 +++- 1 file changed, 3 insertions(+), 1 deletion(-) (limited to 'src/gui/text/qdistancefield.cpp') diff --git a/src/gui/text/qdistancefield.cpp b/src/gui/text/qdistancefield.cpp index c493ca1dad..efe4cc9928 100644 --- a/src/gui/text/qdistancefield.cpp +++ b/src/gui/text/qdistancefield.cpp @@ -544,7 +544,9 @@ static void makeDistanceField(QDistanceFieldData *data, const QPainterPath &path QPoint n(to.y() - from.y(), from.x() - to.x()); if (n.x() == 0 && n.y() == 0) continue; - int scale = qRound((offs << 16) / qSqrt(qreal(n.x() * n.x() + n.y() * n.y()))); // 8:16 + int scale = qRound((offs << 16) / qSqrt(qreal(n.x()) * n.x() + qreal(n.y()) * n.y())); // 8:16 + Q_ASSERT(scale != 0); + n.rx() = n.x() * scale >> 8; n.ry() = n.y() * scale >> 8; normals.append(n); -- cgit v1.2.3