Skip to content
Merged
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
Original file line number Diff line number Diff line change
Expand Up @@ -3898,14 +3898,14 @@ void init(Drawable drawable, GCData data, long hDC) {
data.background = OS.GetBkColor(hDC);
}
data.state &= ~(NULL_BRUSH | NULL_PEN);
if (data.nativeZoom == 0) {
data.nativeZoom = extractZoom(hDC);
}
Font font = data.font;
if (font != null) {
data.state &= ~FONT;
} else {
data.font = Font.win32_new(device, OS.GetCurrentObject(hDC, OS.OBJ_FONT));
}
if (data.nativeZoom == 0) {
data.nativeZoom = extractZoom(hDC);
data.font = SWTFontProvider.getFont(device, OS.GetCurrentObject(hDC, OS.OBJ_FONT), data.nativeZoom);
}
Image image = data.image;
if (image != null) {
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -71,6 +71,11 @@ public Font getFont(FontData fontData, int zoom) {
return font;
}

@Override
public Font getFont(long fontHandle, int zoom) {
return Font.win32_new(device, fontHandle, zoom);
}

private Font registerFont(FontData fontData, Font font) {
FontData clonedFontData = new FontData(fontData.toString());
fontsMap.put(clonedFontData, font);
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -61,6 +61,21 @@ public static Font getFont(Device device, FontData fontData, int zoom) {
return getFontRegistry(device).getFont(fontData, zoom);
}

/**
* Returns the font with the given fontHandle for the given device at the
* specified zoom.
*
* <b>Note:</b> This operation is not thread-safe. It must thus always be called
* from the same thread for the same device, such as the display's UI thread.
*
* @param device the device to retrieve the font for, must not be {@code null}
* @param fontHandle the handle to an existing font
* @param zoom the zoom for which the font shall be scaled
*/
public static Font getFont(Device device, long fontHandle, int zoom) {
return getFontRegistry(device).getFont(fontHandle, zoom);
}

/**
* Disposes the font registry for the given device, if one exists.
*
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -46,6 +46,18 @@ public interface SWTFontRegistry {
*/
Font getFont(FontData fontData, int zoom);


/**
* Provides a font optimally suited for the specified zoom. If the handle is yet unknown to
* the registry, the font will not be managed by the font registry. Only Fonts created in the
* font registry are managed by it and should not be disposed of externally.
*
* @param fontHandle the handle to an existing font
* @param zoom zoom in % of the standard resolution to determine the appropriate font
* @return the font best suited for the specified zoom
*/
Font getFont(long fontHandle, int zoom);

/**
* Disposes all fonts managed by the font registry.
*/
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -44,6 +44,7 @@ private Font getScaledFont(int zoom) {

private Font createAndCacheFont(int zoom) {
Font newFont = createFont(zoom);
customFontHandlesKeyMap.put(newFont.handle, this);
scaledFonts.put(zoom, newFont);
return newFont;
}
Expand Down Expand Up @@ -112,6 +113,7 @@ protected void dispose() {

private ScaledFontContainer systemFontContainer;
private Map<FontData, ScaledFontContainer> customFontsKeyMap = new HashMap<>();
private Map<Long, ScaledFontContainer> customFontHandlesKeyMap = new HashMap<>();
private Device device;

ScalingSWTFontRegistry(Device device) {
Expand All @@ -137,6 +139,14 @@ public Font getFont(FontData fontData, int zoom) {
return container.getScaledFont(zoom);
}

@Override
public Font getFont(long fontHandle, int zoom) {
if (customFontHandlesKeyMap.containsKey(fontHandle)) {
return customFontHandlesKeyMap.get(fontHandle).getScaledFont(zoom);
}
return Font.win32_new(device, fontHandle, zoom);
}

@Override
public void dispose() {
customFontsKeyMap.values().forEach(ScaledFontContainer::dispose);
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -1525,7 +1525,6 @@ LRESULT WM_PAINT (long wParam, long lParam) {
Control control = findBackgroundControl ();
if (control == null) control = this;
data.background = control.getBackgroundPixel ();
data.font = Font.win32_new(display, OS.SendMessage (handle, OS.WM_GETFONT, 0, 0), getNativeZoom());
data.uiState = (int)OS.SendMessage (handle, OS.WM_QUERYUISTATE, 0, 0);
if ((style & SWT.NO_BACKGROUND) != 0) {
/* This code is intentionally commented because it may be slow to copy bits from the screen */
Expand All @@ -1536,6 +1535,8 @@ LRESULT WM_PAINT (long wParam, long lParam) {
drawBackground (phdc [0], rect);
}
GC gc = createNewGC(phdc [0], data);
data.font = SWTFontProvider.getFont(display, OS.SendMessage (handle, OS.WM_GETFONT, 0, 0), data.nativeZoom);

Event event = new Event ();
event.gc = gc;
event.setBounds(DPIUtil.scaleDown(new Rectangle(ps.left, ps.top, width, height), getZoom()));
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -1315,7 +1315,7 @@ public Font getFont () {
if (font != null) return font;
long hFont = OS.SendMessage (handle, OS.WM_GETFONT, 0, 0);
if (hFont == 0) hFont = defaultFont ();
return Font.win32_new (display, hFont, getNativeZoom());
return SWTFontProvider.getFont(display, hFont, getNativeZoom());
}

/**
Expand Down Expand Up @@ -1753,14 +1753,18 @@ public long internal_new_GC (GCData data) {
}
}
data.device = display;
data.nativeZoom = nativeZoom;
data.nativeZoom = getNativeZoom();
int foreground = getForegroundPixel ();
if (foreground != OS.GetTextColor (hDC)) data.foreground = foreground;
Control control = findBackgroundControl ();
if (control == null) control = this;
int background = control.getBackgroundPixel ();
if (background != OS.GetBkColor (hDC)) data.background = background;
data.font = font != null ? font : Font.win32_new (display, OS.SendMessage (hwnd, OS.WM_GETFONT, 0, 0));
if (font != null) {
data.font = font;
} else {
data.font = SWTFontProvider.getFont(display, OS.SendMessage (hwnd, OS.WM_GETFONT, 0, 0), data.nativeZoom);
}
data.uiState = (int)OS.SendMessage (hwnd, OS.WM_QUERYUISTATE, 0, 0);
}
return hDC;
Expand Down
Loading