From 152e496cdac8529fea53ed1006851546203a60b7 Mon Sep 17 00:00:00 2001 From: Allan Sandfeld Jensen Date: Wed, 13 Apr 2016 16:33:25 +0200 Subject: Avoid conversion warnings in qrgba64.h Make implicit down conversions explicit to silence the most pedantic of compiler warnings. Task-number: QTBUG-52545 Change-Id: Id8f9574b47c8b4ee43023c80a3e009fab0e85008 Reviewed-by: Friedemann Kleint --- src/gui/painting/qrgba64.h | 38 +++++++++++++++++++------------------- 1 file changed, 19 insertions(+), 19 deletions(-) (limited to 'src/gui/painting') diff --git a/src/gui/painting/qrgba64.h b/src/gui/painting/qrgba64.h index fab9506ff2..413315f12a 100644 --- a/src/gui/painting/qrgba64.h +++ b/src/gui/painting/qrgba64.h @@ -97,7 +97,7 @@ public: Q_DECL_RELAXED_CONSTEXPR static QRgba64 fromArgb32(uint rgb) { - return fromRgba(rgb >> 16, rgb >> 8, rgb, rgb >> 24); + return fromRgba(quint8(rgb >> 16), quint8(rgb >> 8), quint8(rgb), quint8(rgb >> 24)); } Q_DECL_CONSTEXPR bool isOpaque() const @@ -109,10 +109,10 @@ public: return (rgba & alphaMask()) == 0; } - Q_DECL_CONSTEXPR quint16 red() const { return rgba >> RedShift; } - Q_DECL_CONSTEXPR quint16 green() const { return rgba >> GreenShift; } - Q_DECL_CONSTEXPR quint16 blue() const { return rgba >> BlueShift; } - Q_DECL_CONSTEXPR quint16 alpha() const { return rgba >> AlphaShift; } + Q_DECL_CONSTEXPR quint16 red() const { return quint16(rgba >> RedShift); } + Q_DECL_CONSTEXPR quint16 green() const { return quint16(rgba >> GreenShift); } + Q_DECL_CONSTEXPR quint16 blue() const { return quint16(rgba >> BlueShift); } + Q_DECL_CONSTEXPR quint16 alpha() const { return quint16(rgba >> AlphaShift); } void setRed(quint16 _red) { rgba = (rgba & ~(Q_UINT64_C(0xffff) << RedShift)) | (quint64(_red) << RedShift); } void setGreen(quint16 _green) { rgba = (rgba & ~(Q_UINT64_C(0xffff) << GreenShift)) | (quint64(_green) << GreenShift); } void setBlue(quint16 _blue) { rgba = (rgba & ~(Q_UINT64_C(0xffff) << BlueShift)) | (quint64(_blue) << BlueShift); } @@ -124,11 +124,11 @@ public: Q_DECL_CONSTEXPR quint8 alpha8() const { return div_257(alpha()); } Q_DECL_CONSTEXPR uint toArgb32() const { - return (alpha8() << 24) | (red8() << 16) | (green8() << 8) | blue8(); + return uint((alpha8() << 24) | (red8() << 16) | (green8() << 8) | blue8()); } Q_DECL_CONSTEXPR ushort toRgb16() const { - return (red() & 0xf800) | ((green() >> 10) << 5) | (blue() >> 11); + return ushort((red() & 0xf800) | ((green() >> 10) << 5) | (blue() >> 11)); } Q_DECL_RELAXED_CONSTEXPR QRgba64 premultiplied() const @@ -137,7 +137,7 @@ public: const quint16 r = div_65535(red() * a); const quint16 g = div_65535(green() * a); const quint16 b = div_65535(blue() * a); - return fromRgba64(r, g, b, a); + return fromRgba64(r, g, b, quint16(a)); } Q_DECL_RELAXED_CONSTEXPR QRgba64 unpremultiplied() const @@ -163,18 +163,18 @@ public: private: static Q_DECL_CONSTEXPR Q_ALWAYS_INLINE quint64 alphaMask() { return Q_UINT64_C(0xffff) << AlphaShift; } - static Q_DECL_CONSTEXPR Q_ALWAYS_INLINE uint div_257_floor(uint x) { return (x - (x >> 8)) >> 8; } - static Q_DECL_CONSTEXPR Q_ALWAYS_INLINE uint div_257(uint x) { return div_257_floor(x + 128); } - static Q_DECL_CONSTEXPR Q_ALWAYS_INLINE uint div_65535(uint x) { return (x + (x>>16) + 0x8000U) >> 16; } + static Q_DECL_CONSTEXPR Q_ALWAYS_INLINE quint8 div_257_floor(uint x) { return quint8((x - (x >> 8)) >> 8); } + static Q_DECL_CONSTEXPR Q_ALWAYS_INLINE quint8 div_257(quint16 x) { return div_257_floor(x + 128U); } + static Q_DECL_CONSTEXPR Q_ALWAYS_INLINE quint16 div_65535(uint x) { return quint16((x + (x>>16) + 0x8000U) >> 16); } Q_DECL_RELAXED_CONSTEXPR Q_ALWAYS_INLINE QRgba64 unpremultiplied_32bit() const { if (isOpaque() || isTransparent()) return *this; const quint32 a = alpha(); - const quint16 r = (quint32(red()) * 0xffff + a/2) / a; - const quint16 g = (quint32(green()) * 0xffff + a/2) / a; - const quint16 b = (quint32(blue()) * 0xffff + a/2) / a; - return fromRgba64(r, g, b, a); + const quint16 r = quint16((red() * 0xffff + a/2) / a); + const quint16 g = quint16((green() * 0xffff + a/2) / a); + const quint16 b = quint16((blue() * 0xffff + a/2) / a); + return fromRgba64(r, g, b, quint16(a)); } Q_DECL_RELAXED_CONSTEXPR Q_ALWAYS_INLINE QRgba64 unpremultiplied_64bit() const { @@ -182,10 +182,10 @@ private: return *this; const quint64 a = alpha(); const quint64 fa = (Q_UINT64_C(0xffff00008000) + a/2) / a; - const quint16 r = (red() * fa + 0x80000000) >> 32; - const quint16 g = (green() * fa + 0x80000000) >> 32; - const quint16 b = (blue() * fa + 0x80000000) >> 32; - return fromRgba64(r, g, b, a); + const quint16 r = quint16((red() * fa + 0x80000000) >> 32); + const quint16 g = quint16((green() * fa + 0x80000000) >> 32); + const quint16 b = quint16((blue() * fa + 0x80000000) >> 32); + return fromRgba64(r, g, b, quint16(a)); } }; -- cgit v1.2.3 From ebbfc556678f1c780e0bd1efde23835d023f95ad Mon Sep 17 00:00:00 2001 From: Marc Mutz Date: Sun, 24 Apr 2016 00:07:28 +0200 Subject: QtGui: mark more types as primitive/movable These types are held in QVarLengthArrays, so benefit from being trivially relocatable. They are also part of the private API, so there's no BC issues with potential uses of these types in QList, except for QPainter::PixmapFragment, which consequently has been marked as relocatable only. Change-Id: I90fb9a19231c6f5c71c593602fc997ffafe8f047 Reviewed-by: Lars Knoll --- src/gui/painting/qpaintengine.cpp | 3 +++ src/gui/painting/qpainter.h | 1 + src/gui/painting/qregion.cpp | 10 +++++++++- 3 files changed, 13 insertions(+), 1 deletion(-) (limited to 'src/gui/painting') diff --git a/src/gui/painting/qpaintengine.cpp b/src/gui/painting/qpaintengine.cpp index d59d843f8a..020392409d 100644 --- a/src/gui/painting/qpaintengine.cpp +++ b/src/gui/painting/qpaintengine.cpp @@ -310,6 +310,7 @@ struct QT_Point { int x; int y; }; +Q_DECLARE_TYPEINFO(QT_Point, Q_PRIMITIVE_TYPE); /*! \fn void QPaintEngine::drawPolygon(const QPointF *points, int pointCount, @@ -340,6 +341,8 @@ struct QT_PointF { qreal x; qreal y; }; +Q_DECLARE_TYPEINFO(QT_PointF, Q_PRIMITIVE_TYPE); + /*! \overload diff --git a/src/gui/painting/qpainter.h b/src/gui/painting/qpainter.h index bd745e41ba..5743d97405 100644 --- a/src/gui/painting/qpainter.h +++ b/src/gui/painting/qpainter.h @@ -486,6 +486,7 @@ private: friend class QPreviewPaintEngine; friend class QTextEngine; }; +Q_DECLARE_TYPEINFO(QPainter::PixmapFragment, Q_RELOCATABLE_TYPE); Q_DECLARE_OPERATORS_FOR_FLAGS(QPainter::RenderHints) diff --git a/src/gui/painting/qregion.cpp b/src/gui/painting/qregion.cpp index 35c4abb3ac..d38479c4b1 100644 --- a/src/gui/painting/qregion.cpp +++ b/src/gui/painting/qregion.cpp @@ -1047,7 +1047,15 @@ void addSegmentsToPath(Segment *segment, QPainterPath &path) } } -} +} // unnamed namespace + +// the following is really a lie, because Segments cannot be relocated, as they +// reference each other by address. For the same reason, they aren't even copyable, +// but the code works with the compiler-generated (wrong) copy and move special +// members, so use this as an optimization. The only container these are used in +// (a QVarLengthArray in qt_regionToPath()) is resized once up-front, so doesn't +// have a problem with this, but benefits from not having to run Segment ctors: +Q_DECLARE_TYPEINFO(Segment, Q_PRIMITIVE_TYPE); Q_GUI_EXPORT QPainterPath qt_regionToPath(const QRegion ®ion) { -- cgit v1.2.3 From cd964c04421042d430ef067608956e30ea5a5b74 Mon Sep 17 00:00:00 2001 From: Marc Mutz Date: Fri, 4 Mar 2016 11:41:36 +0100 Subject: QPdf: replace a hand-written qWarning with Q_UNIMPLEMENTED But keep the 'Implement me' as a comment. Remove default label from the switch to indicate that the warning is only for the conical gradient case, and not for the NoGradient case. Also enables compiler warnings should we ever decide to add another gradient type. Change-Id: I891e652ff0293b4b4c254c7a55ebc6120b4fbcb6 Reviewed-by: Kai Koehne Reviewed-by: Giuseppe D'Angelo --- src/gui/painting/qpdf.cpp | 6 ++++-- 1 file changed, 4 insertions(+), 2 deletions(-) (limited to 'src/gui/painting') diff --git a/src/gui/painting/qpdf.cpp b/src/gui/painting/qpdf.cpp index 10f0fcc21d..8189351bd8 100644 --- a/src/gui/painting/qpdf.cpp +++ b/src/gui/painting/qpdf.cpp @@ -2215,8 +2215,10 @@ int QPdfEnginePrivate::generateGradientShader(const QGradient *gradient, const Q case QGradient::RadialGradient: return generateRadialGradientShader(static_cast(gradient), matrix, alpha); case QGradient::ConicalGradient: - default: - qWarning("Implement me!"); + Q_UNIMPLEMENTED(); // ### Implement me! + break; + case QGradient::NoGradient: + break; } return 0; } -- cgit v1.2.3 From 4077e28daa55652d7ada776b2702341125516caf Mon Sep 17 00:00:00 2001 From: Allan Sandfeld Jensen Date: Wed, 13 Apr 2016 15:33:03 +0200 Subject: Avoid processing bezier curves that will be clipped anyway Simplify curves ourside the clipped area with a straight line that closes the path, but saves us a lot of time and memory when zooming in on a path. Change-Id: I437f7eab564b805ebbefccd6755060156227c88d Reviewed-by: Gunnar Sletta --- src/gui/painting/qoutlinemapper.cpp | 21 +++++++++++++++++---- 1 file changed, 17 insertions(+), 4 deletions(-) (limited to 'src/gui/painting') diff --git a/src/gui/painting/qoutlinemapper.cpp b/src/gui/painting/qoutlinemapper.cpp index 7245b44fc7..f1e4ce5820 100644 --- a/src/gui/painting/qoutlinemapper.cpp +++ b/src/gui/painting/qoutlinemapper.cpp @@ -78,10 +78,23 @@ void QOutlineMapper::curveTo(const QPointF &cp1, const QPointF &cp2, const QPoin #endif QBezier bezier = QBezier::fromPoints(m_elements.last(), cp1, cp2, ep); - bezier.addToPolygon(m_elements, m_curve_threshold); - m_element_types.reserve(m_elements.size()); - for (int i = m_elements.size() - m_element_types.size(); i; --i) - m_element_types << QPainterPath::LineToElement; + + bool outsideClip = false; + // Test one point first before doing a full intersection test. + if (!QRectF(m_clip_rect).contains(m_transform.map(ep))) { + QRectF potentialCurveArea = m_transform.mapRect(bezier.bounds()); + outsideClip = !potentialCurveArea.intersects(m_clip_rect); + } + if (outsideClip) { + // The curve is entirely outside the clip rect, so just + // approximate it with a line that closes the path. + lineTo(ep); + } else { + bezier.addToPolygon(m_elements, m_curve_threshold); + m_element_types.reserve(m_elements.size()); + for (int i = m_elements.size() - m_element_types.size(); i; --i) + m_element_types << QPainterPath::LineToElement; + } Q_ASSERT(m_elements.size() == m_element_types.size()); } -- cgit v1.2.3 From ab06266e15265737039cec2129fdf44848ed95a8 Mon Sep 17 00:00:00 2001 From: Allan Sandfeld Jensen Date: Mon, 25 Apr 2016 15:19:53 +0200 Subject: Fix clipping of wave underline decoration on certain fonts Limit the height of the the wave-pixmap so that fillRect doesn't clip it. At the same time the precision of the generated wave-pixmap is improved so it better fits the requested radius. Task-number: QTCREATORBUG-15851 Change-Id: If754387b20ab7b015857ecb0a0e8fe16de1d728a Reviewed-by: Konstantin Ritt Reviewed-by: Eskil Abrahamsen Blomfeldt --- src/gui/painting/qpainter.cpp | 12 +++++++----- 1 file changed, 7 insertions(+), 5 deletions(-) (limited to 'src/gui/painting') diff --git a/src/gui/painting/qpainter.cpp b/src/gui/painting/qpainter.cpp index 5dcab11f0a..baeee4dbfa 100644 --- a/src/gui/painting/qpainter.cpp +++ b/src/gui/painting/qpainter.cpp @@ -6179,7 +6179,8 @@ static QPixmap generateWavyPixmap(qreal maxRadius, const QPen &pen) QString key = QLatin1String("WaveUnderline-") % pen.color().name() - % HexString(radiusBase); + % HexString(radiusBase) + % HexString(pen.widthF()); QPixmap pixmap; if (QPixmapCache::find(key, pixmap)) @@ -6187,7 +6188,7 @@ static QPixmap generateWavyPixmap(qreal maxRadius, const QPen &pen) const qreal halfPeriod = qMax(qreal(2), qreal(radiusBase * 1.61803399)); // the golden ratio const int width = qCeil(100 / (2 * halfPeriod)) * (2 * halfPeriod); - const int radius = qFloor(radiusBase); + const qreal radius = qFloor(radiusBase * 2) / 2.; QPainterPath path; @@ -6210,7 +6211,7 @@ static QPixmap generateWavyPixmap(qreal maxRadius, const QPen &pen) // due to it having a rather thick width for the regular underline. const qreal maxPenWidth = .8 * radius; if (wavePen.widthF() > maxPenWidth) - wavePen.setWidth(maxPenWidth); + wavePen.setWidthF(maxPenWidth); QPainter imgPainter(&pixmap); imgPainter.setPen(wavePen); @@ -6263,14 +6264,15 @@ static void drawTextItemDecoration(QPainter *painter, const QPointF &pos, const if (underlineStyle == QTextCharFormat::WaveUnderline) { painter->save(); painter->translate(0, pos.y() + 1); + qreal maxHeight = fe->descent().toReal() - qreal(1); QColor uc = charFormat.underlineColor(); if (uc.isValid()) pen.setColor(uc); // Adapt wave to underlineOffset or pen width, whatever is larger, to make it work on all platforms - const QPixmap wave = generateWavyPixmap(qMax(underlineOffset, pen.widthF()), pen); - const int descent = (int) fe->descent().toReal(); + const QPixmap wave = generateWavyPixmap(qMin(qMax(underlineOffset, pen.widthF()), maxHeight / 2.), pen); + const int descent = qFloor(maxHeight); painter->setBrushOrigin(painter->brushOrigin().x(), 0); painter->fillRect(pos.x(), 0, qCeil(width), qMin(wave.height(), descent), wave); -- cgit v1.2.3 From 8c2b7405b4a5f7d0fee62b78a17100529e611a5c Mon Sep 17 00:00:00 2001 From: Kai Pastor Date: Sun, 24 Apr 2016 19:52:37 +0200 Subject: QPdf: Force miter limit into valid range Miter limits below 1.0 are not valid in PDF and trigger an error in the Reader. This change enforces a minimum miter limit of 1.0, and it adds a manual test for producing a PDF file demonstrating this issue. Task-number: QTBUG-52641 Change-Id: I1c78b1c4a44579e95e1cddfb459926d304e60165 Reviewed-by: Lars Knoll --- src/gui/painting/qpdf.cpp | 2 +- 1 file changed, 1 insertion(+), 1 deletion(-) (limited to 'src/gui/painting') diff --git a/src/gui/painting/qpdf.cpp b/src/gui/painting/qpdf.cpp index 22a387bd28..0df5fd8b8a 100644 --- a/src/gui/painting/qpdf.cpp +++ b/src/gui/painting/qpdf.cpp @@ -1196,7 +1196,7 @@ void QPdfEngine::setPen() switch(d->pen.joinStyle()) { case Qt::MiterJoin: case Qt::SvgMiterJoin: - *d->currentPage << d->pen.miterLimit() << "M "; + *d->currentPage << qMax(qreal(1.0), d->pen.miterLimit()) << "M "; pdfJoinStyle = 0; break; case Qt::BevelJoin: -- cgit v1.2.3 From 63169fc893973437696ad49c4e3dfdd28e356f37 Mon Sep 17 00:00:00 2001 From: Allan Sandfeld Jensen Date: Thu, 28 Apr 2016 13:28:51 +0200 Subject: Fix underline position on Liberation Mono Ensure we don't round a underline position beyond the descent in our eagerness to avoid underlines too close to baseline. Task-number: QTCREATORBUG-15851 Change-Id: I9a29447bbcb938b7e9fb29d52fd392a1340d07c5 Reviewed-by: Konstantin Ritt Reviewed-by: Eskil Abrahamsen Blomfeldt --- src/gui/painting/qpainter.cpp | 9 ++++++--- 1 file changed, 6 insertions(+), 3 deletions(-) (limited to 'src/gui/painting') diff --git a/src/gui/painting/qpainter.cpp b/src/gui/painting/qpainter.cpp index baeee4dbfa..62254213f3 100644 --- a/src/gui/painting/qpainter.cpp +++ b/src/gui/painting/qpainter.cpp @@ -6251,9 +6251,6 @@ static void drawTextItemDecoration(QPainter *painter, const QPointF &pos, const painter->setRenderHint(QPainter::Qt4CompatiblePainting, false); const qreal underlineOffset = fe->underlinePosition().toReal(); - // deliberately ceil the offset to avoid the underline coming too close to - // the text above it. - const qreal underlinePos = pos.y() + qCeil(underlineOffset) + 0.5; if (underlineStyle == QTextCharFormat::SpellCheckUnderline) { QPlatformTheme *theme = QGuiApplicationPrivate::platformTheme(); @@ -6278,6 +6275,12 @@ static void drawTextItemDecoration(QPainter *painter, const QPointF &pos, const painter->fillRect(pos.x(), 0, qCeil(width), qMin(wave.height(), descent), wave); painter->restore(); } else if (underlineStyle != QTextCharFormat::NoUnderline) { + // Deliberately ceil the offset to avoid the underline coming too close to + // the text above it, but limit it to stay within descent. + qreal adjustedUnderlineOffset = std::ceil(underlineOffset) + 0.5; + if (underlineOffset <= fe->descent().toReal()) + adjustedUnderlineOffset = qMin(adjustedUnderlineOffset, fe->descent().toReal() - 0.5); + const qreal underlinePos = pos.y() + adjustedUnderlineOffset; QColor uc = charFormat.underlineColor(); if (uc.isValid()) pen.setColor(uc); -- cgit v1.2.3