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 @@ -333,10 +333,10 @@ void checkGC(int mask) {
}
}
if ((state & FONT) != 0) {
Font font = data.font;
OS.SelectObject(handle, font.handle);
long fontHandle = SWTFontProvider.getFontHandle(data.font, data.nativeZoom);
OS.SelectObject(handle, fontHandle);
long[] hFont = new long[1];
long gdipFont = createGdipFont(handle, font.handle, gdipGraphics, device.fontCollection, null, hFont);
long gdipFont = createGdipFont(handle, fontHandle, gdipGraphics, device.fontCollection, null, hFont);
if (hFont[0] != 0) OS.SelectObject(handle, hFont[0]);
if (data.hGDIFont != 0) OS.DeleteObject(data.hGDIFont);
data.hGDIFont = hFont[0];
Expand Down Expand Up @@ -454,8 +454,8 @@ void checkGC(int mask) {
OS.SetTextColor(handle, data.foreground);
}
if ((state & FONT) != 0) {
Font font = data.font;
OS.SelectObject(handle, font.handle);
long fontHandle = SWTFontProvider.getFontHandle(data.font, data.nativeZoom);
OS.SelectObject(handle, fontHandle);
}
}

Expand Down Expand Up @@ -2388,7 +2388,7 @@ void drawText(long gdipGraphics, String string, int x, int y, int flags, Point s
char[] chars = string.toCharArray();
long hdc = Gdip.Graphics_GetHDC(gdipGraphics);
long hFont = data.hGDIFont;
if (hFont == 0 && data.font != null) hFont = data.font.handle;
if (hFont == 0 && data.font != null) hFont = SWTFontProvider.getFontHandle(data.font, data.nativeZoom);
long oldFont = 0;
if (hFont != 0) oldFont = OS.SelectObject(hdc, hFont);
TEXTMETRIC lptm = new TEXTMETRIC();
Expand Down Expand Up @@ -2478,7 +2478,7 @@ RectF drawText(long gdipGraphics, char[] buffer, int start, int length, int x, i
}
long hdc = Gdip.Graphics_GetHDC(gdipGraphics);
long hFont = data.hGDIFont;
if (hFont == 0 && data.font != null) hFont = data.font.handle;
if (hFont == 0 && data.font != null) hFont = SWTFontProvider.getFontHandle(data.font, data.nativeZoom);
long oldFont = 0;
if (hFont != 0) oldFont = OS.SelectObject(hdc, hFont);
if (start != 0) {
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -763,7 +763,7 @@ private void addStringInPixels(PathHandle pathHandle, float x, float y) {
char[] buffer = string.toCharArray();
long hDC = device.internal_new_GC(null);
long [] family = new long [1];
long gdipFont = GC.createGdipFont(hDC, SWTFontProvider.getFont(device, this.fontData, zoom).handle, 0, device.fontCollection, family, null);
long gdipFont = GC.createGdipFont(hDC, SWTFontProvider.getFontHandle(device, this.fontData, zoom), 0, device.fontCollection, family, null);
PointF point = new PointF();
point.X = x - (Gdip.Font_GetSize(gdipFont) / 6);
point.Y = y;
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -1969,12 +1969,12 @@ long getItemFont (StyleItem item, GC gc) {
if (item.fallbackFont != 0) return item.fallbackFont;
final int zoom = getNativeZoom(gc);
if (item.style != null && item.style.font != null) {
return Font.win32_new(item.style.font, zoom).handle;
return SWTFontProvider.getFontHandle(item.style.font, zoom);
}
if (this.font != null) {
return Font.win32_new(this.font, zoom).handle;
return SWTFontProvider.getFontHandle(this.font, zoom);
}
return SWTFontProvider.getSystemFont(device, zoom).handle;
return SWTFontProvider.getSystemFontHandle(device, zoom);
}

/**
Expand Down Expand Up @@ -2131,15 +2131,15 @@ public FontMetrics getLineMetrics (int lineIndex) {
long hDC = device.internal_new_GC(null);
long srcHdc = OS.CreateCompatibleDC(hDC);
TEXTMETRIC lptm = new TEXTMETRIC();
Font availableFont = font != null ? font : device.systemFont;
OS.SelectObject(srcHdc, availableFont.handle);
final int zoom = getZoom();
long availableFont = font != null ? SWTFontProvider.getFontHandle(font, zoom) : SWTFontProvider.getSystemFontHandle(device, zoom);
OS.SelectObject(srcHdc, availableFont);
metricsAdapter.GetTextMetrics(srcHdc, lptm);
OS.DeleteDC(srcHdc);
device.internal_dispose_GC(hDC, null);
final int zoom = getZoom();
int ascentInPoints = Math.max(DPIUtil.scaleDown(this.device, lptm.tmAscent, zoom), this.ascent);
int descentInPoints = Math.max(DPIUtil.scaleDown(this.device, lptm.tmDescent, zoom), this.descent);
int leadingInPoints = DPIUtil.scaleDown(this.device, lptm.tmInternalLeading, availableFont.zoom);
int leadingInPoints = DPIUtil.scaleDown(this.device, lptm.tmInternalLeading, zoom);
if (text.length() != 0) {
for (StyleItem run : runs[lineIndex]) {
if (run.ascentInPoints > ascentInPoints) {
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -16,6 +16,7 @@
import java.util.*;
import java.util.concurrent.*;

import org.eclipse.swt.*;
import org.eclipse.swt.graphics.*;
import org.eclipse.swt.widgets.*;

Expand Down Expand Up @@ -46,6 +47,10 @@ public static Font getSystemFont(Device device, int zoom) {
return getFontRegistry(device).getSystemFont(zoom);
}

public static long getSystemFontHandle(Device device, int zoom) {
return getSystemFont(device, zoom).handle;
}

/**
* Returns the font with the given font data for the given device at the
* specified zoom.
Expand All @@ -61,6 +66,17 @@ public static Font getFont(Device device, FontData fontData, int zoom) {
return getFontRegistry(device).getFont(fontData, zoom);
}

public static long getFontHandle(Device device, FontData fontData, int zoom) {
return getFont(device, fontData, zoom).handle;
}

public static long getFontHandle(Font font, int zoom) {
if (font == null) {
SWT.error(SWT.ERROR_NULL_ARGUMENT);
}
return getFont(font.getDevice(), font.getFontData()[0], zoom).handle;
}

/**
* Returns the font with the given fontHandle for the given device at the
* specified zoom.
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -509,7 +509,7 @@ public void setImage (Image image) {
void setIMEFont () {
if (!OS.IsDBLocale) return;
long hFont = 0;
if (font != null) hFont = font.handle;
if (font != null) hFont = SWTFontProvider.getFontHandle(font, getNativeZoom());
if (hFont == 0) hFont = defaultFont ();
long hwnd = parent.handle;
long hIMC = OS.ImmGetContext (hwnd);
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -1419,7 +1419,7 @@ LRESULT WM_GETFONT (long wParam, long lParam) {
if (result != null) return result;
long code = callWindowProc (handle, OS.WM_GETFONT, wParam, lParam);
if (code != 0) return new LRESULT (code);
return new LRESULT (font != null ? font.handle : defaultFont ());
return new LRESULT (font != null ? SWTFontProvider.getFontHandle(font, getNativeZoom()) : defaultFont ());
}

@Override
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -721,7 +721,7 @@ int defaultBackground () {
}

long defaultFont() {
return display.getSystemFont(getNativeZoom()).handle;
return SWTFontProvider.getSystemFontHandle(display, getNativeZoom());
}

int defaultForeground () {
Expand Down Expand Up @@ -3334,7 +3334,7 @@ public void setCursor (Cursor cursor) {
}

void setDefaultFont () {
long hFont = display.getSystemFont (getNativeZoom()).handle;
long hFont = SWTFontProvider.getSystemFontHandle(display, getNativeZoom());
OS.SendMessage (handle, OS.WM_SETFONT, hFont, 0);
}

Expand Down Expand Up @@ -5894,8 +5894,7 @@ private static void resizeFont(Control control, int newZoom) {
if (font == null) {
long currentFontHandle = OS.SendMessage (control.handle, OS.WM_GETFONT, 0, 0);
if (currentFontHandle != 0) {
Font newFont = display.getSystemFont(newZoom);
long newFontHandle = newFont.handle;
long newFontHandle = SWTFontProvider.getSystemFontHandle(display, newZoom);
OS.SendMessage(control.handle, OS.WM_SETFONT, newFontHandle, 1);
}
} else {
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -509,7 +509,7 @@ void setBackgroundPixel (int pixel) {
@Override
public void setFont (Font font) {
super.setFont (font);
hFont = font != null ? font.handle : 0;
hFont = font != null ? SWTFontProvider.getFontHandle(font, getNativeZoom()) : 0;
layoutItems (0, true);
}

Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -157,8 +157,8 @@ void destroyWidget () {
}

long fontHandle (int index) {
if (cellFont != null && cellFont [index] != null) return cellFont [index].handle;
if (font != null) return font.handle;
if (cellFont != null && cellFont [index] != null) return SWTFontProvider.getFontHandle(cellFont[index], getNativeZoom());
if (font != null) return SWTFontProvider.getFontHandle(font, getNativeZoom());
return -1;
}

Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -316,8 +316,8 @@ void destroyWidget () {
}

long fontHandle (int index) {
if (cellFont != null && cellFont [index] != null) return cellFont [index].handle;
if (font != null) return font.handle;
if (cellFont != null && cellFont [index] != null) return SWTFontProvider.getFontHandle(cellFont[index], getNativeZoom());
if (font != null) return SWTFontProvider.getFontHandle(font, getNativeZoom());
return -1;
}

Expand Down
Loading