From b6557e4be8ed97b3d05061e782a0517c5d8c3fd0 Mon Sep 17 00:00:00 2001 From: Eskil Abrahamsen Blomfeldt Date: Thu, 30 Jan 2025 11:13:55 +0100 Subject: [PATCH] Fix compilation with unofficial DirectWrite headers Reportedly, some unofficial DirectWrite ports are missing the default values to the arguments for IDWritePaintReader's MoveToFirstChild() and MoveToNextSibling(), so we make this explicit to work around the problem. Fixes: QTBUG-133336 Change-Id: Ia9a01e371e7424508db0d5ad3c75037caaf16854 Reviewed-by: Thiago Macieira (cherry picked from commit cbce69ebd643bb4841de20f34c5b23bddbcde0c6) Reviewed-by: Qt Cherry-pick Bot --- src/gui/configure.cmake | 14 ++++++++++++++ .../text/windows/qwindowsfontenginedirectwrite.cpp | 13 +++++++------ 2 files changed, 21 insertions(+), 6 deletions(-) diff --git a/src/gui/configure.cmake b/src/gui/configure.cmake index a42f453e4a5..26434f82044 100644 --- a/src/gui/configure.cmake +++ b/src/gui/configure.cmake @@ -635,6 +635,20 @@ int main(int, char **) IUnknown *factory = nullptr; // Just check that the API is available for the build DWRITE_PAINT_ELEMENT paintElement; + + if (false) { + DWRITE_COLOR_F dwColor; + dwColor.r = 0; + dwColor.g = 0; + dwColor.b = 0; + dwColor.a = 0; + IDWritePaintReader *paintReader = nullptr; + // Some versions of MinGW has a dwrite_3.h header with buggy generated APIs. One of these + // is that the SetTextColor() function takes a pointer instead of a const-ref. We check + // for this to disable the COLRv1 feature for broken headers. + paintReader->SetTextColor(dwColor); + } + return 0; } ") diff --git a/src/gui/text/windows/qwindowsfontenginedirectwrite.cpp b/src/gui/text/windows/qwindowsfontenginedirectwrite.cpp index cf5f530f8ae..2cf6aa92dd9 100644 --- a/src/gui/text/windows/qwindowsfontenginedirectwrite.cpp +++ b/src/gui/text/windows/qwindowsfontenginedirectwrite.cpp @@ -1031,13 +1031,13 @@ bool QWindowsFontEngineDirectWrite::traverseColr1(IDWritePaintReader *paintReade auto traverseChildren = [&](quint32 childCount) { DWRITE_PAINT_ELEMENT childPaintElement; - if (FAILED(paintReader->MoveToFirstChild(&childPaintElement))) + if (FAILED(paintReader->MoveToFirstChild(&childPaintElement, sizeof(DWRITE_PAINT_ELEMENT)))) return false; while (childCount-- > 0) { traverseColr1(paintReader, face7, &childPaintElement, paintGraphRenderer); if (childCount > 0) { - if (FAILED(paintReader->MoveToNextSibling(&childPaintElement))) { + if (FAILED(paintReader->MoveToNextSibling(&childPaintElement, sizeof(DWRITE_PAINT_ELEMENT)))) { return false; } } @@ -1100,7 +1100,7 @@ bool QWindowsFontEngineDirectWrite::traverseColr1(IDWritePaintReader *paintReade } else { DWRITE_PAINT_ELEMENT childElement; - HRESULT hr = paintReader->MoveToFirstChild(&childElement); + HRESULT hr = paintReader->MoveToFirstChild(&childElement, sizeof(DWRITE_PAINT_ELEMENT)); if (FAILED(hr)) { qErrnoWarning(hr, "%s: Cannot move to first child of composite node", __FUNCTION__); @@ -1108,7 +1108,7 @@ bool QWindowsFontEngineDirectWrite::traverseColr1(IDWritePaintReader *paintReade } // First draw back drop which is the second child - hr = paintReader->MoveToNextSibling(&childElement); + hr = paintReader->MoveToNextSibling(&childElement, sizeof(DWRITE_PAINT_ELEMENT)); if (FAILED(hr)) { qErrnoWarning(hr, "%s: Cannot move to second child of composite node", __FUNCTION__); @@ -1132,7 +1132,7 @@ bool QWindowsFontEngineDirectWrite::traverseColr1(IDWritePaintReader *paintReade return false; } - hr = paintReader->MoveToFirstChild(&childElement); + hr = paintReader->MoveToFirstChild(&childElement, sizeof(DWRITE_PAINT_ELEMENT)); if (FAILED(hr)) { qErrnoWarning(hr, "%s: Cannot move to first child of composite node", __FUNCTION__); @@ -1239,7 +1239,7 @@ bool QWindowsFontEngineDirectWrite::traverseColr1(IDWritePaintReader *paintReade } DWRITE_PAINT_ELEMENT childElement; - if (FAILED(paintReader->MoveToFirstChild(&childElement))) + if (FAILED(paintReader->MoveToFirstChild(&childElement, sizeof(DWRITE_PAINT_ELEMENT)))) return false; if (!traverseColr1(paintReader, face7, &childElement, paintGraphRenderer)) @@ -1301,6 +1301,7 @@ bool QWindowsFontEngineDirectWrite::renderColr1GlyphRun(QImage *image, D2D_RECT_F clipBox; hr = paintReader->SetCurrentGlyph(glyphRun->glyphIndices[0], &paintElement, + sizeof(DWRITE_PAINT_ELEMENT), &clipBox, nullptr); if (FAILED(hr)) {