From 984ad6124992c9831f57c2776aa2ed0a760149e6 Mon Sep 17 00:00:00 2001 From: Simon Hausmann Date: Tue, 10 Oct 2017 09:42:41 +0200 Subject: Improve readability of code that uses the Qt signed size type During the container BoF session at the Qt Contributor Summit 2017 the name of the signed size type became a subject of discussion in the context of readability of code using this type and the intention of using it for all length, size and count properties throughout the entire framework in future versions of Qt. This change proposes qsizetype as new name for qssize_t to emphasize the readability of code over POSIX compatibility, the former being potentially more relevant than the latter to the majority of users of Qt. Change-Id: Idb99cb4a8782703c054fa463a9e5af23a918e7f3 Reviewed-by: Samuel Gaist Reviewed-by: David Faure --- src/gui/painting/qdrawhelper.cpp | 4 ++-- src/gui/painting/qdrawhelper_avx2.cpp | 2 +- src/gui/painting/qdrawhelper_p.h | 4 ++-- src/gui/painting/qpaintengine_raster.cpp | 10 +++++----- 4 files changed, 10 insertions(+), 10 deletions(-) (limited to 'src/gui/painting') diff --git a/src/gui/painting/qdrawhelper.cpp b/src/gui/painting/qdrawhelper.cpp index 5ec570a5db..6a24c02aaa 100644 --- a/src/gui/painting/qdrawhelper.cpp +++ b/src/gui/painting/qdrawhelper.cpp @@ -2383,7 +2383,7 @@ static void QT_FASTCALL fetchTransformedBilinearARGB32PM_fast_rotate_helper(uint __m128i v_fy = _mm_setr_epi32(fy, fy + fdy, fy + fdy + fdy, fy + fdy + fdy + fdy); const uchar *textureData = image.imageData; - const qssize_t bytesPerLine = image.bytesPerLine; + const qsizetype bytesPerLine = image.bytesPerLine; const __m128i vbpl = _mm_shufflelo_epi16(_mm_cvtsi32_si128(bytesPerLine/4), _MM_SHUFFLE(0, 0, 0, 0)); while (b < boundedEnd - 3) { @@ -4959,7 +4959,7 @@ static void blend_transformed_tiled_argb(int count, const QSpan *spans, void *us int image_width = data->texture.width; int image_height = data->texture.height; - const qssize_t scanline_offset = data->texture.bytesPerLine / 4; + const qsizetype scanline_offset = data->texture.bytesPerLine / 4; if (data->fast_matrix) { // The increment pr x in the scanline diff --git a/src/gui/painting/qdrawhelper_avx2.cpp b/src/gui/painting/qdrawhelper_avx2.cpp index d6c3319c76..2619539788 100644 --- a/src/gui/painting/qdrawhelper_avx2.cpp +++ b/src/gui/painting/qdrawhelper_avx2.cpp @@ -685,7 +685,7 @@ void QT_FASTCALL fetchTransformedBilinearARGB32PM_fast_rotate_helper_avx2(uint * v_fy = _mm256_add_epi32(v_fy, _mm256_mullo_epi32(_mm256_set1_epi32(fdy), v_index)); const uchar *textureData = image.imageData; - const qssize_t bytesPerLine = image.bytesPerLine; + const qsizetype bytesPerLine = image.bytesPerLine; const __m256i vbpl = _mm256_set1_epi16(bytesPerLine/4); while (b < boundedEnd - 7) { diff --git a/src/gui/painting/qdrawhelper_p.h b/src/gui/painting/qdrawhelper_p.h index 2be10d2cfb..df9f762314 100644 --- a/src/gui/painting/qdrawhelper_p.h +++ b/src/gui/painting/qdrawhelper_p.h @@ -293,7 +293,7 @@ struct QTextureData int y1; int x2; int y2; - qssize_t bytesPerLine; + qsizetype bytesPerLine; QImage::Format format; const QVector *colorTable; bool hasAlpha; @@ -847,7 +847,7 @@ inline void qt_memfill(T *dest, T value, int count) template Q_STATIC_TEMPLATE_FUNCTION inline void qt_rectfill(T *dest, T value, - int x, int y, int width, int height, qssize_t stride) + int x, int y, int width, int height, qsizetype stride) { char *d = reinterpret_cast(dest + x) + y * stride; if (uint(stride) == (width * sizeof(T))) { diff --git a/src/gui/painting/qpaintengine_raster.cpp b/src/gui/painting/qpaintengine_raster.cpp index d0d948bbb7..1637a933b1 100644 --- a/src/gui/painting/qpaintengine_raster.cpp +++ b/src/gui/painting/qpaintengine_raster.cpp @@ -994,7 +994,7 @@ void QRasterPaintEnginePrivate::drawImage(const QPointF &pt, Q_ASSERT(img.depth() >= 8); - qssize_t srcBPL = img.bytesPerLine(); + qsizetype srcBPL = img.bytesPerLine(); const uchar *srcBits = img.bits(); int srcSize = img.depth() >> 3; // This is the part that is incompatible with lower than 8-bit.. int iw = img.width(); @@ -1043,7 +1043,7 @@ void QRasterPaintEnginePrivate::drawImage(const QPointF &pt, // call the blend function... int dstSize = rasterBuffer->bytesPerPixel(); - qssize_t dstBPL = rasterBuffer->bytesPerLine(); + qsizetype dstBPL = rasterBuffer->bytesPerLine(); func(rasterBuffer->buffer() + x * dstSize + y * dstBPL, dstBPL, srcBits, srcBPL, iw, ih, @@ -2318,8 +2318,8 @@ void QRasterPaintEngine::drawImage(const QRectF &r, const QImage &img, const QRe clippedSourceRect = clippedSourceRect.intersected(img.rect()); - const qssize_t dbpl = d->rasterBuffer->bytesPerLine(); - const qssize_t sbpl = img.bytesPerLine(); + const qsizetype dbpl = d->rasterBuffer->bytesPerLine(); + const qsizetype sbpl = img.bytesPerLine(); uchar *dst = d->rasterBuffer->buffer(); uint bpp = img.depth() >> 3; @@ -2828,7 +2828,7 @@ bool QRasterPaintEngine::drawCachedGlyphs(int numGlyphs, const glyph_t *glyphs, cache->fillInPendingGlyphs(); const QImage &image = cache->image(); - qssize_t bpl = image.bytesPerLine(); + qsizetype bpl = image.bytesPerLine(); int depth = image.depth(); int rightShift = 0; -- cgit v1.2.3 From b8a6e2b6e8e4b5ea0734285f485c03c22022c30e Mon Sep 17 00:00:00 2001 From: Dongmei Wang Date: Fri, 18 Aug 2017 11:24:13 -0700 Subject: QColor: write signed 64-bit integer in a platform-independent way MIME-Version: 1.0 Content-Type: text/plain; charset=UTF-8 Content-Transfer-Encoding: 8bit When building Qt 5.6.2 with gcc 4.1.2 on Fedora 8, a compilation error happened when compiling the code below QColor::name() { ... case HexArgb: return QLatin1Char('#') + QString::number(rgba() | 0x100000000, 16).rightRef(8); ... } qtbase/src/gui/painting/qcolor.cpp:527: error: integer constant is too large for ‘long’ type gcc 4.1.2 was unable to handle 0x100000000. The patch is to use Q_INT64_C to append "LL" to 0x100000000 to avoid the compilation error. Change-Id: I000e65a5c897ef2d78fcfe4e212d832eb488a762 Reviewed-by: Gabriel de Dietrich --- src/gui/painting/qcolor.cpp | 2 +- 1 file changed, 1 insertion(+), 1 deletion(-) (limited to 'src/gui/painting') diff --git a/src/gui/painting/qcolor.cpp b/src/gui/painting/qcolor.cpp index 9e1785c11d..6e0e348a67 100644 --- a/src/gui/painting/qcolor.cpp +++ b/src/gui/painting/qcolor.cpp @@ -853,7 +853,7 @@ QString QColor::name(NameFormat format) const return QLatin1Char('#') + QString::number(rgba() | 0x1000000, 16).rightRef(6); case HexArgb: // it's called rgba() but it does return AARRGGBB - return QLatin1Char('#') + QString::number(rgba() | 0x100000000, 16).rightRef(8); + return QLatin1Char('#') + QString::number(rgba() | Q_INT64_C(0x100000000), 16).rightRef(8); } return QString(); } -- cgit v1.2.3 From ae55e75b1b6c2c07f4ef084ee27448fc0262c7c0 Mon Sep 17 00:00:00 2001 From: Allan Sandfeld Jensen Date: Mon, 11 Dec 2017 15:48:41 +0100 Subject: Paint text decoration where the text is For multi text-item texts we should render the text decoration at the same position as the text-item part is, and not always from the beginning of the line. Task-number: QTBUG-60422 Change-Id: I9aa58fc164122ad1fae9716b8b18bdfbbbd778a9 Reviewed-by: Konstantin Ritt Reviewed-by: Eskil Abrahamsen Blomfeldt --- src/gui/painting/qpainter.cpp | 4 ++-- 1 file changed, 2 insertions(+), 2 deletions(-) (limited to 'src/gui/painting') diff --git a/src/gui/painting/qpainter.cpp b/src/gui/painting/qpainter.cpp index b95f9b18aa..6e84a3f384 100644 --- a/src/gui/painting/qpainter.cpp +++ b/src/gui/painting/qpainter.cpp @@ -6482,7 +6482,7 @@ void QPainterPrivate::drawTextItem(const QPointF &p, const QTextItem &_ti, QText extended->drawTextItem(QPointF(x, y), ti2); else engine->drawTextItem(QPointF(x, y), ti2); - drawTextItemDecoration(q, p, ti2.fontEngine, textEngine, ti2.underlineStyle, + drawTextItemDecoration(q, QPointF(x, y), ti2.fontEngine, textEngine, ti2.underlineStyle, ti2.flags, ti2.width.toReal(), ti2.charFormat); if (!rtl) @@ -6515,7 +6515,7 @@ void QPainterPrivate::drawTextItem(const QPointF &p, const QTextItem &_ti, QText extended->drawTextItem(QPointF(x, y), ti2); else engine->drawTextItem(QPointF(x,y), ti2); - drawTextItemDecoration(q, p, ti2.fontEngine, textEngine, ti2.underlineStyle, + drawTextItemDecoration(q, QPointF(x, y), ti2.fontEngine, textEngine, ti2.underlineStyle, ti2.flags, ti2.width.toReal(), ti2.charFormat); // reset the high byte for all glyphs -- cgit v1.2.3 From fddc5a27b180d7afde37e2c004cee95302e907ed Mon Sep 17 00:00:00 2001 From: =?UTF-8?q?Tor=20Arne=20Vestb=C3=B8?= Date: Thu, 14 Dec 2017 12:32:35 +0100 Subject: macOS: Enable using CoreGraphics helper functions from C++ sources MIME-Version: 1.0 Content-Type: text/plain; charset=UTF-8 Content-Transfer-Encoding: 8bit Change-Id: If32c96d224bfb90ba22661b6f5ac3c920acb39d2 Reviewed-by: Morten Johan Sørvig --- src/gui/painting/qcoregraphics_p.h | 10 +++++++--- 1 file changed, 7 insertions(+), 3 deletions(-) (limited to 'src/gui/painting') diff --git a/src/gui/painting/qcoregraphics_p.h b/src/gui/painting/qcoregraphics_p.h index d74c4d0711..6b6a1e800e 100644 --- a/src/gui/painting/qcoregraphics_p.h +++ b/src/gui/painting/qcoregraphics_p.h @@ -56,13 +56,15 @@ #include #include -#ifdef Q_OS_MACOS + +#if defined(__OBJC__) && defined(Q_OS_MACOS) #include +#define HAVE_APPKIT #endif QT_BEGIN_NAMESPACE -#ifdef Q_OS_MACOS +#ifdef HAVE_APPKIT Q_GUI_EXPORT NSImage *qt_mac_create_nsimage(const QPixmap &pm); Q_GUI_EXPORT NSImage *qt_mac_create_nsimage(const QIcon &icon, int defaultSize = 0); Q_GUI_EXPORT QPixmap qt_mac_toQPixmap(const NSImage *image, const QSizeF &size); @@ -78,7 +80,7 @@ Q_GUI_EXPORT CGColorSpaceRef qt_mac_colorSpaceForDeviceType(const QPaintDevice * Q_GUI_EXPORT void qt_mac_clip_cg(CGContextRef hd, const QRegion &rgn, CGAffineTransform *orig_xform); -#ifdef Q_OS_MACOS +#ifdef HAVE_APPKIT Q_GUI_EXPORT QColor qt_mac_toQColor(const NSColor *color); Q_GUI_EXPORT QBrush qt_mac_toQBrush(const NSColor *color, QPalette::ColorGroup colorGroup = QPalette::Normal); #endif @@ -124,4 +126,6 @@ private: QT_END_NAMESPACE +#undef HAVE_APPKIT + #endif // QCOREGRAPHICS_P_H -- cgit v1.2.3 From 3dd030863435e058468df66c696e1608b71e1fd2 Mon Sep 17 00:00:00 2001 From: Allan Sandfeld Jensen Date: Tue, 12 Dec 2017 11:35:25 +0100 Subject: Mask potentially undefined alpha in blend_transformed_argb Makes sure the ARGB32PM that is painted on always have a defined alpha. Task-number: QTBUG-55645 Change-Id: Ifcf5fcc2127d255518eca4763845a197da6c7914 Reviewed-by: Olivier Goffart (Woboq GmbH) --- src/gui/painting/qdrawhelper.cpp | 5 +++-- 1 file changed, 3 insertions(+), 2 deletions(-) (limited to 'src/gui/painting') diff --git a/src/gui/painting/qdrawhelper.cpp b/src/gui/painting/qdrawhelper.cpp index 6a24c02aaa..6bfdc940ac 100644 --- a/src/gui/painting/qdrawhelper.cpp +++ b/src/gui/painting/qdrawhelper.cpp @@ -4719,6 +4719,7 @@ static void blend_transformed_argb(int count, const QSpan *spans, void *userData CompositionFunction func = functionForMode[data->rasterBuffer->compositionMode]; uint buffer[buffer_size]; + quint32 mask = (data->texture.format == QImage::Format_RGB32) ? 0xff000000 : 0; const int image_x1 = data->texture.x1; const int image_y1 = data->texture.y1; @@ -4752,7 +4753,7 @@ static void blend_transformed_argb(int count, const QSpan *spans, void *userData while (b < end) { int px = qBound(image_x1, x >> 16, image_x2); int py = qBound(image_y1, y >> 16, image_y2); - *b = reinterpret_cast(data->texture.scanLine(py))[px]; + *b = reinterpret_cast(data->texture.scanLine(py))[px] | mask; x += fdx; y += fdy; @@ -4793,7 +4794,7 @@ static void blend_transformed_argb(int count, const QSpan *spans, void *userData const int px = qBound(image_x1, int(tx) - (tx < 0), image_x2); const int py = qBound(image_y1, int(ty) - (ty < 0), image_y2); - *b = reinterpret_cast(data->texture.scanLine(py))[px]; + *b = reinterpret_cast(data->texture.scanLine(py))[px] | mask; x += fdx; y += fdy; w += fdw; -- cgit v1.2.3 From d6473eb1865cca088ebc97bafdca17dac75c5a2e Mon Sep 17 00:00:00 2001 From: Allan Sandfeld Jensen Date: Fri, 24 Nov 2017 15:52:09 +0100 Subject: Fix drawing color fonts with shear and perspective transforms Fixes the fallback painting used with complex transforms to be able to handle color bitmap fonts which can't be converted to a path. Change-Id: Id2851607f673b8fc1aea63f92043d0cdebc0fb9d Reviewed-by: Konstantin Ritt Reviewed-by: Eskil Abrahamsen Blomfeldt --- src/gui/painting/qpaintengine.cpp | 22 ++++++++++++++++++++-- 1 file changed, 20 insertions(+), 2 deletions(-) (limited to 'src/gui/painting') diff --git a/src/gui/painting/qpaintengine.cpp b/src/gui/painting/qpaintengine.cpp index f42fd4ff87..1aee7d5f74 100644 --- a/src/gui/painting/qpaintengine.cpp +++ b/src/gui/painting/qpaintengine.cpp @@ -751,11 +751,29 @@ void QPaintEngine::drawPath(const QPainterPath &) void QPaintEngine::drawTextItem(const QPointF &p, const QTextItem &textItem) { const QTextItemInt &ti = static_cast(textItem); + if (ti.glyphs.numGlyphs == 0) + return; + + if (ti.fontEngine->glyphFormat == QFontEngine::Format_ARGB) { + QVarLengthArray positions; + QVarLengthArray glyphs; + QTransform matrix = QTransform::fromTranslate(p.x(), p.y() - ti.fontEngine->ascent().toReal()); + ti.fontEngine->getGlyphPositions(ti.glyphs, matrix, ti.flags, glyphs, positions); + painter()->save(); + painter()->setRenderHint(QPainter::SmoothPixmapTransform, + bool((painter()->renderHints() & QPainter::TextAntialiasing) + && !(painter()->font().styleStrategy() & QFont::NoAntialias))); + for (int i = 0; i < ti.glyphs.numGlyphs; ++i) { + QImage glyph = ti.fontEngine->bitmapForGlyph(glyphs[i], QFixed(), QTransform()); + painter()->drawImage(positions[i].x.toReal(), positions[i].y.toReal(), glyph); + } + painter()->restore(); + return; + } QPainterPath path; path.setFillRule(Qt::WindingFill); - if (ti.glyphs.numGlyphs) - ti.fontEngine->addOutlineToPath(0, 0, ti.glyphs, &path, ti.flags); + ti.fontEngine->addOutlineToPath(0, 0, ti.glyphs, &path, ti.flags); if (!path.isEmpty()) { painter()->save(); painter()->setRenderHint(QPainter::Antialiasing, -- cgit v1.2.3