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 <thiago.macieira@intel.com>
(cherry picked from commit cbce69ebd643bb4841de20f34c5b23bddbcde0c6)
Reviewed-by: Qt Cherry-pick Bot <cherrypick_bot@qt-project.org>
This commit is contained in:
Eskil Abrahamsen Blomfeldt 2025-01-30 11:13:55 +01:00 committed by Qt Cherry-pick Bot
parent 9ffc3b0705
commit b6557e4be8
2 changed files with 21 additions and 6 deletions

View File

@ -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;
}
")

View File

@ -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)) {