Skip to content

Commit b6b36e0

Browse files
Introducing new method to get handle
also encapsulating handle field to private. It cant be accessed from outside of this class
1 parent ee0fdb8 commit b6b36e0

File tree

1 file changed

+34
-5
lines changed
  • bundles/org.eclipse.swt/Eclipse SWT/win32/org/eclipse/swt/graphics

1 file changed

+34
-5
lines changed

bundles/org.eclipse.swt/Eclipse SWT/win32/org/eclipse/swt/graphics/Font.java

Lines changed: 34 additions & 5 deletions
Original file line numberDiff line numberDiff line change
@@ -50,6 +50,11 @@ public final class Font extends Resource {
5050
*/
5151
public long handle;
5252

53+
/**
54+
* this field is used to store fontData provided during initialization
55+
*/
56+
private final FontData fontData;
57+
5358
/**
5459
* The zoom in % of the standard resolution used for conversion of point height to pixel height
5560
* (Warning: This field is platform dependent)
@@ -67,12 +72,14 @@ public final class Font extends Resource {
6772
*/
6873
Font(Device device) {
6974
super(device);
75+
this.fontData = null;
7076
this.zoom = DPIUtil.getNativeDeviceZoom();
7177
this.fontHeight = 0;
7278
}
7379

7480
private Font(Device device, long handle, int zoom) {
7581
super(device);
82+
this.fontData = null;
7683
this.handle = handle;
7784
this.zoom = zoom;
7885
this.fontHeight = device.computePoints(fetchLogFontData(), handle, zoom);
@@ -101,15 +108,15 @@ private Font(Device device, long handle, int zoom) {
101108
public Font(Device device, FontData fd) {
102109
super(device);
103110
this.zoom = DPIUtil.getNativeDeviceZoom();
104-
init(fd);
111+
this.fontData = fd;
105112
this.fontHeight = fd.height;
106113
init();
107114
}
108115

109116
private Font(Device device, FontData fd, int zoom) {
110117
super(device);
111118
this.zoom = zoom;
112-
init(fd);
119+
this.fontData = fd;
113120
this.fontHeight = fd.height;
114121
init();
115122
}
@@ -148,7 +155,7 @@ public Font(Device device, FontData[] fds) {
148155
}
149156
this.zoom = DPIUtil.getNativeDeviceZoom();
150157
FontData fd = fds[0];
151-
init(fds[0]);
158+
this.fontData = fd;
152159
this.fontHeight = fd.height;
153160
init();
154161
}
@@ -181,7 +188,7 @@ public Font(Device device, String name, int height, int style) {
181188
super(device);
182189
if (name == null) SWT.error(SWT.ERROR_NULL_ARGUMENT);
183190
this.zoom = DPIUtil.getNativeDeviceZoom();
184-
init(new FontData (name, height, style));
191+
this.fontData = new FontData (name, height, style);
185192
this.fontHeight = height;
186193
init();
187194
}
@@ -190,7 +197,7 @@ public Font(Device device, String name, int height, int style) {
190197
super(device);
191198
if (name == null) SWT.error(SWT.ERROR_NULL_ARGUMENT);
192199
this.zoom = DPIUtil.getNativeDeviceZoom();
193-
init(new FontData (name, height, style));
200+
this.fontData = new FontData (name, height, style);
194201
this.fontHeight = height;
195202
init();
196203
}
@@ -294,6 +301,28 @@ public String toString () {
294301
return "Font {" + handle + "}";
295302
}
296303

304+
/**
305+
* <b>IMPORTANT:</b> This method is not part of the public
306+
* API for Font. It is marked public only so that it
307+
* can be shared within the packages provided by SWT. It is not
308+
* available on all platforms, and should never be called from
309+
* application code.
310+
*
311+
* Creates a new handle for the requested font or returns the existing one
312+
*
313+
* @param font the font to get the handle of
314+
*
315+
* @return handle of the font
316+
*
317+
* @noreference This method is not intended to be referenced by clients.
318+
*/
319+
public static long win32_getHandle (Font font) {
320+
if(font.handle == 0 && font.fontData != null) {
321+
font.init(font.fontData);
322+
}
323+
return font.handle;
324+
}
325+
297326
/**
298327
* Invokes platform specific functionality to allocate a new font.
299328
* <p>

0 commit comments

Comments
 (0)