Avoid overflows when calculating metafile coordinates in wxMSW.
Use MulDiv() instead of naive multiplication followed by division as this could overflow, and did when large paper sizes were used in print preview. Closes #16138. git-svn-id: https://svn.wxwidgets.org/svn/wx/wxWidgets/trunk@76219 c3d73ce0-8a6f-49c7-b76d-6d57e0e08775
This commit is contained in:
@@ -257,10 +257,9 @@ void PixelToHIMETRIC(LONG *x, LONG *y, HDC hdcRef)
|
||||
iWidthPels = GetDeviceCaps(hdcRef, HORZRES),
|
||||
iHeightPels = GetDeviceCaps(hdcRef, VERTRES);
|
||||
|
||||
*x *= (iWidthMM * 100);
|
||||
*x /= iWidthPels;
|
||||
*y *= (iHeightMM * 100);
|
||||
*y /= iHeightPels;
|
||||
// Take care to use MulDiv() here to avoid overflow.
|
||||
*x = ::MulDiv(*x, iWidthMM * 100, iWidthPels);
|
||||
*y = ::MulDiv(*y, iHeightMM * 100, iHeightPels);
|
||||
}
|
||||
|
||||
void HIMETRICToPixel(LONG *x, LONG *y, HDC hdcRef)
|
||||
@@ -270,10 +269,8 @@ void HIMETRICToPixel(LONG *x, LONG *y, HDC hdcRef)
|
||||
iWidthPels = GetDeviceCaps(hdcRef, HORZRES),
|
||||
iHeightPels = GetDeviceCaps(hdcRef, VERTRES);
|
||||
|
||||
*x *= iWidthPels;
|
||||
*x /= (iWidthMM * 100);
|
||||
*y *= iHeightPels;
|
||||
*y /= (iHeightMM * 100);
|
||||
*x = ::MulDiv(*x, iWidthPels, iWidthMM * 100);
|
||||
*y = ::MulDiv(*y, iHeightPels, iHeightMM * 100);
|
||||
}
|
||||
|
||||
void HIMETRICToPixel(LONG *x, LONG *y)
|
||||
|
Reference in New Issue
Block a user