@@ -226,70 +226,85 @@ public FontData open () {
226
226
227
227
display .externalEventLoop = true ;
228
228
display .sendPreExternalEventDispatchEvent ();
229
- /* Open the dialog */
230
- boolean success = OS .ChooseFont (lpcf );
231
- display .externalEventLoop = false ;
232
- display .sendPostExternalEventDispatchEvent ();
229
+ long currentDpiAwarenessContext = OS .GetThreadDpiAwarenessContext ();
230
+ boolean success = false ;
231
+ try {
232
+ /*
233
+ * Temporarily setting the thread dpi awareness to gdi scaling because window
234
+ * dialog has weird resize handling
235
+ */
236
+ if (display .isRescalingAtRuntime ()) {
237
+ currentDpiAwarenessContext = OS .SetThreadDpiAwarenessContext (OS .DPI_AWARENESS_CONTEXT_UNAWARE_GDISCALED );
238
+ }
233
239
234
- /* Clear the temporary dialog modal parent */
235
- if (( style & ( SWT . APPLICATION_MODAL | SWT . SYSTEM_MODAL )) != 0 ) {
236
- display .setModalDialog ( oldModal ) ;
237
- }
240
+ /* Open the dialog */
241
+ success = OS . ChooseFont ( lpcf );
242
+ display .externalEventLoop = false ;
243
+ display . sendPostExternalEventDispatchEvent ();
238
244
239
- /* Compute the result */
240
- if (success ) {
241
- LOGFONT logFont = new LOGFONT ();
242
- OS .MoveMemory (logFont , lpLogFont , LOGFONT .sizeof );
245
+ /* Clear the temporary dialog modal parent */
246
+ if ((style & (SWT .APPLICATION_MODAL | SWT .SYSTEM_MODAL )) != 0 ) {
247
+ display .setModalDialog (oldModal );
248
+ }
249
+
250
+ /* Compute the result */
251
+ if (success ) {
252
+ LOGFONT logFont = new LOGFONT ();
253
+ OS .MoveMemory (logFont , lpLogFont , LOGFONT .sizeof );
243
254
244
- /*
245
- * This will not work on multiple screens or
246
- * for printing. Should use DC for the proper device.
247
- */
248
- long hDC = OS .GetDC (0 );
249
- int logPixelsY = OS .GetDeviceCaps (hDC , OS .LOGPIXELSY );
250
- int pixels = 0 ;
251
- if (logFont .lfHeight > 0 ) {
252
255
/*
253
- * Feature in Windows. If the lfHeight of the LOGFONT structure
254
- * is positive, the lfHeight measures the height of the entire
255
- * cell, including internal leading, in logical units. Since the
256
- * height of a font in points does not include the internal leading,
257
- * we must subtract the internal leading, which requires a TEXTMETRIC,
258
- * which in turn requires font creation.
256
+ * This will not work on multiple screens or for printing. Should use DC for the
257
+ * proper device.
259
258
*/
260
- long hFont = OS .CreateFontIndirect (logFont );
261
- long oldFont = OS .SelectObject (hDC , hFont );
262
- TEXTMETRIC lptm = new TEXTMETRIC ();
263
- OS .GetTextMetrics (hDC , lptm );
264
- OS .SelectObject (hDC , oldFont );
265
- OS .DeleteObject (hFont );
266
- pixels = logFont .lfHeight - lptm .tmInternalLeading ;
267
- } else {
268
- pixels = -logFont .lfHeight ;
269
- }
270
- OS .ReleaseDC (0 , hDC );
259
+ long hDC = OS .GetDC (0 );
260
+ int logPixelsY = OS .GetDeviceCaps (hDC , OS .LOGPIXELSY );
261
+ int pixels = 0 ;
262
+ if (logFont .lfHeight > 0 ) {
263
+ /*
264
+ * Feature in Windows. If the lfHeight of the LOGFONT structure is positive, the
265
+ * lfHeight measures the height of the entire cell, including internal leading,
266
+ * in logical units. Since the height of a font in points does not include the
267
+ * internal leading, we must subtract the internal leading, which requires a
268
+ * TEXTMETRIC, which in turn requires font creation.
269
+ */
270
+ long hFont = OS .CreateFontIndirect (logFont );
271
+ long oldFont = OS .SelectObject (hDC , hFont );
272
+ TEXTMETRIC lptm = new TEXTMETRIC ();
273
+ OS .GetTextMetrics (hDC , lptm );
274
+ OS .SelectObject (hDC , oldFont );
275
+ OS .DeleteObject (hFont );
276
+ pixels = logFont .lfHeight - lptm .tmInternalLeading ;
277
+ } else {
278
+ pixels = -logFont .lfHeight ;
279
+ }
280
+ OS .ReleaseDC (0 , hDC );
271
281
272
- float points = pixels * 72f /logPixelsY ;
273
- fontData = FontData .win32_new (logFont , points );
274
- if (effectsVisible ) {
275
- int red = lpcf .rgbColors & 0xFF ;
276
- int green = (lpcf .rgbColors >> 8 ) & 0xFF ;
277
- int blue = (lpcf .rgbColors >> 16 ) & 0xFF ;
278
- rgb = new RGB (red , green , blue );
282
+ float points = pixels * 72f / logPixelsY ;
283
+ fontData = FontData .win32_new (logFont , points );
284
+ if (effectsVisible ) {
285
+ int red = lpcf .rgbColors & 0xFF ;
286
+ int green = (lpcf .rgbColors >> 8 ) & 0xFF ;
287
+ int blue = (lpcf .rgbColors >> 16 ) & 0xFF ;
288
+ rgb = new RGB (red , green , blue );
289
+ }
279
290
}
280
- }
281
-
282
- /* Free the OS memory */
283
- if (lpLogFont != 0 ) OS .HeapFree (hHeap , 0 , lpLogFont );
291
+ } finally {
292
+ /* Reset the dpi awareness context */
293
+ if (display .isRescalingAtRuntime ()) {
294
+ OS .SetThreadDpiAwarenessContext (currentDpiAwarenessContext );
295
+ }
296
+ /* Free the OS memory */
297
+ if (lpLogFont != 0 ) OS .HeapFree (hHeap , 0 , lpLogFont );
284
298
285
- /* Destroy the BIDI orientation window */
286
- if (hwndParent != hwndOwner ) {
287
- if (enabled ) OS .EnableWindow (hwndParent , true );
288
- OS .SetActiveWindow (hwndParent );
289
- OS .DestroyWindow (hwndOwner );
299
+ /* Destroy the BIDI orientation window */
300
+ if (hwndParent != hwndOwner ) {
301
+ if (enabled ) OS .EnableWindow (hwndParent , true );
302
+ OS .SetActiveWindow (hwndParent );
303
+ OS .DestroyWindow (hwndOwner );
304
+ }
305
+ if (!success ) return null ;
290
306
}
291
307
292
- if (!success ) return null ;
293
308
return fontData ;
294
309
}
295
310
0 commit comments