Skip to content

Commit 1226486

Browse files
akoch-yattaal-noori
authored andcommitted
[win32] Fix Control#print when GC zoom != control zoom
This commit adapts Control#print to apply a scale factor if the zoom of the GC is different to the zoom of the control. Co-authored-by: al-noori <lowejatan.noori@yatta.de>
1 parent 87f04f3 commit 1226486

1 file changed

Lines changed: 8 additions & 2 deletions

File tree

  • bundles/org.eclipse.swt/Eclipse SWT/win32/org/eclipse/swt/widgets

bundles/org.eclipse.swt/Eclipse SWT/win32/org/eclipse/swt/widgets/Control.java

Lines changed: 8 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -2260,6 +2260,7 @@ public boolean print (GC gc) {
22602260
long hdc = gc.handle;
22612261
int state = 0;
22622262
long gdipGraphics = gc.getGCData().gdipGraphics;
2263+
float scaleFactor = 1f * gc.getGCData().nativeZoom/nativeZoom;
22632264
if (gdipGraphics != 0) {
22642265
long clipRgn = 0;
22652266
Gdip.Graphics_SetPixelOffsetMode(gdipGraphics, Gdip.PixelOffsetModeNone);
@@ -2275,6 +2276,7 @@ public boolean print (GC gc) {
22752276
long matrix = Gdip.Matrix_new(1, 0, 0, 1, 0, 0);
22762277
if (matrix == 0) error(SWT.ERROR_NO_HANDLES);
22772278
Gdip.Graphics_GetTransform(gdipGraphics, matrix);
2279+
Gdip.Matrix_Scale(matrix, scaleFactor, scaleFactor, Gdip.MatrixOrderPrepend);
22782280
if (!Gdip.Matrix_IsIdentity(matrix)) {
22792281
lpXform = new float[6];
22802282
Gdip.Matrix_GetElements(matrix, lpXform);
@@ -2284,12 +2286,16 @@ public boolean print (GC gc) {
22842286
state = OS.SaveDC(hdc);
22852287
if (lpXform != null) {
22862288
OS.SetGraphicsMode(hdc, OS.GM_ADVANCED);
2287-
OS.SetWorldTransform(hdc, lpXform);
2289+
OS.ModifyWorldTransform(hdc, lpXform, OS.MWT_LEFTMULTIPLY);
22882290
}
22892291
if (clipRgn != 0) {
22902292
OS.SelectClipRgn(hdc, clipRgn);
22912293
OS.DeleteObject(clipRgn);
22922294
}
2295+
} else {
2296+
state = OS.SaveDC(hdc);
2297+
float[] translateMatrix = new float[] {scaleFactor, 0, 0, scaleFactor, 0, 0};
2298+
OS.ModifyWorldTransform(hdc, translateMatrix, OS.MWT_LEFTMULTIPLY);
22932299
}
22942300
int flags = OS.RDW_UPDATENOW | OS.RDW_ALLCHILDREN;
22952301
OS.RedrawWindow (topHandle, null, 0, flags);
@@ -2300,8 +2306,8 @@ public boolean print (GC gc) {
23002306
*/
23012307
printWindowFlags |= OS.PW_RENDERFULLCONTENT;
23022308
printWidget (topHandle, hdc, gc, printWindowFlags);
2309+
OS.RestoreDC(hdc, state);
23032310
if (gdipGraphics != 0) {
2304-
OS.RestoreDC(hdc, state);
23052311
Gdip.Graphics_ReleaseHDC(gdipGraphics, hdc);
23062312
}
23072313
return true;

0 commit comments

Comments
 (0)