Skip to content

Commit f67e181

Browse files
committed
Mac and Windows are using different font unit on SWT, try to fix it by
adding a function of adjustOSFontSize method
1 parent ff3aa7c commit f67e181

File tree

2 files changed

+19
-1
lines changed
  • sources/net.sf.j2s.java.org.eclipse.swt/src/org/eclipse/swt

2 files changed

+19
-1
lines changed

sources/net.sf.j2s.java.org.eclipse.swt/src/org/eclipse/swt/internal/browser/OS.java

Lines changed: 7 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -72,6 +72,13 @@ private OS() {
7272

7373
/**
7474
* @j2sNative
75+
window["swt.adjustOSFontSize"] = function (size) {
76+
if (window["swt.designer.os"] == "osx") {
77+
return size + "px";
78+
} else {
79+
return size + "pt"; // windows
80+
}
81+
};
7582
var os = $wt.internal.browser.OS;
7683
var dua = navigator.userAgent;
7784
os.isOpera = dua.indexOf ("Opera") >= 0;

sources/net.sf.j2s.java.org.eclipse.swt/src/org/eclipse/swt/widgets/Control.java

Lines changed: 12 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -2437,7 +2437,18 @@ public void setFont (Font font) {
24372437
if (font.data.name != null) {
24382438
handle.style.fontFamily = font.data.name;
24392439
}
2440-
handle.style.fontSize = font.data.height + "pt";
2440+
String fontSize = font.data.height + "pt";
2441+
/**
2442+
* @j2sNative
2443+
* if (window["swt.adjustOSFontSize"] != null) {
2444+
* c = window["swt.adjustOSFontSize"](a.data.height);
2445+
* }
2446+
* @j2sNativeSrc
2447+
* if (window["swt.adjustOSFontSize"] != null) {
2448+
* fontSize = window["swt.adjustOSFontSize"](font.data.height);
2449+
* }
2450+
*/ {}
2451+
handle.style.fontSize = fontSize;
24412452
if ((font.data.style & SWT.BOLD) != 0) {
24422453
handle.style.fontWeight = "bold";
24432454
} else {

0 commit comments

Comments
 (0)