@@ -132,7 +132,9 @@ Rectangle getBoundsInPixels () {
132132 if (width == 0 ) {
133133 int [] buffer = new int [1 ];
134134 if (OS .SystemParametersInfo (OS .SPI_GETCARETWIDTH , 0 , buffer , 0 )) {
135- return new Rectangle (getXInPixels (), getYInPixels (), buffer [0 ], getHeightInPixels ());
135+ int width = DPIUtil .pixelToPoint (buffer [0 ], getPrimaryMonitorZoomAtStartup ());
136+ int widthInPixels = Win32DPIUtils .pointToPixel (width , getNativeZoom ());
137+ return new Rectangle (getXInPixels (), getYInPixels (), widthInPixels , getHeightInPixels ());
136138 }
137139 }
138140 return new Rectangle (getXInPixels (), getYInPixels (), getWidthInPixels (), getHeightInPixels ());
@@ -226,7 +228,9 @@ Point getSizeInPixels () {
226228 if (width == 0 ) {
227229 int [] buffer = new int [1 ];
228230 if (OS .SystemParametersInfo (OS .SPI_GETCARETWIDTH , 0 , buffer , 0 )) {
229- return new Point (buffer [0 ], getHeightInPixels ());
231+ int width = DPIUtil .pixelToPoint (buffer [0 ], getPrimaryMonitorZoomAtStartup ());
232+ int widthInPixels = Win32DPIUtils .pointToPixel (width , getNativeZoom ());
233+ return new Point (widthInPixels , getHeightInPixels ());
230234 }
231235 }
232236 return new Point (getWidthInPixels (), getHeightInPixels ());
@@ -370,7 +374,8 @@ void resize () {
370374 if (image == null && widthInPixels == 0 ) {
371375 int [] buffer = new int [1 ];
372376 if (OS .SystemParametersInfo (OS .SPI_GETCARETWIDTH , 0 , buffer , 0 )) {
373- widthInPixels = buffer [0 ];
377+ int width = DPIUtil .pixelToPoint (buffer [0 ], getPrimaryMonitorZoomAtStartup ());
378+ widthInPixels = Win32DPIUtils .pointToPixel (width , getNativeZoom ());
374379 }
375380 }
376381 OS .CreateCaret (hwnd , hBitmap , widthInPixels , getHeightInPixels ());
@@ -449,7 +454,8 @@ void setFocus () {
449454 if (image == null && widthInPixels == 0 ) {
450455 int [] buffer = new int [1 ];
451456 if (OS .SystemParametersInfo (OS .SPI_GETCARETWIDTH , 0 , buffer , 0 )) {
452- widthInPixels = buffer [0 ];
457+ int width = DPIUtil .pixelToPoint (buffer [0 ], getPrimaryMonitorZoomAtStartup ());
458+ widthInPixels = Win32DPIUtils .pointToPixel (width , getNativeZoom ());
453459 }
454460 }
455461 OS .CreateCaret (hwnd , hBitmap , widthInPixels , getHeightInPixels ());
@@ -646,6 +652,13 @@ public void setVisible (boolean visible) {
646652 }
647653}
648654
655+ private int getPrimaryMonitorZoomAtStartup () {
656+ long hDC = OS .GetDC (0 );
657+ int dpi = OS .GetDeviceCaps (hDC , OS .LOGPIXELSX );
658+ OS .ReleaseDC (0 , hDC );
659+ return DPIUtil .mapDPIToZoom (dpi );
660+ }
661+
649662/**
650663 * <b>IMPORTANT:</b> This method is not part of the public
651664 * API for Image. It is marked public only so that it
0 commit comments