@@ -121,7 +121,8 @@ public Font getBoldFont() {
121121 }
122122
123123 FontData [] boldData = getModifiedFontData (SWT .BOLD );
124- boldFont = new Font (Display .getCurrent (), boldData );
124+ Display display = getDisplayAndHookForDisposal ();
125+ boldFont = new Font (display , boldData );
125126 return boldFont ;
126127 }
127128
@@ -157,7 +158,8 @@ public Font getItalicFont() {
157158 }
158159
159160 FontData [] italicData = getModifiedFontData (SWT .ITALIC );
160- italicFont = new Font (Display .getCurrent (), italicData );
161+ Display display = getDisplayAndHookForDisposal ();
162+ italicFont = new Font (display , italicData );
161163 return italicFont ;
162164 }
163165
@@ -489,13 +491,10 @@ else if (fonts.length == 0) {
489491 * @return FontRecord for the new Font or <code>null</code>.
490492 */
491493 private FontRecord createFont (String symbolicName , FontData [] fonts ) {
492- Display display = Display . getCurrent ();
494+ Display display = getDisplayAndHookForDisposal ();
493495 if (display == null ) {
494496 return null ;
495497 }
496- if (cleanOnDisplayDisposal && !displayDisposeHooked .contains (display )) {
497- hookDisplayDispose (display );
498- }
499498
500499 FontData [] validData = filterData (fonts , display );
501500 if (validData .length == 0 ) {
@@ -509,6 +508,17 @@ private FontRecord createFont(String symbolicName, FontData[] fonts) {
509508 return new FontRecord (newFont , validData );
510509 }
511510
511+ private Display getDisplayAndHookForDisposal () {
512+ Display display = Display .getCurrent ();
513+ if (display == null ) {
514+ return null ;
515+ }
516+ if (cleanOnDisplayDisposal && !displayDisposeHooked .contains (display )) {
517+ hookDisplayDispose (display );
518+ }
519+ return display ;
520+ }
521+
512522 /**
513523 * Calculates the default font and returns the result.
514524 * This method creates a font that must be disposed.
0 commit comments