Skip to content

Commit be58f57

Browse files
authored
Merge pull request #53 from pmd/issue-10
Resolve text rendering issues across different platforms
2 parents a4b96b9 + e82bff2 commit be58f57

File tree

1 file changed

+51
-1
lines changed

1 file changed

+51
-1
lines changed

src/main/java/net/sourceforge/pmd/util/fxdesigner/DesignerStarter.java

Lines changed: 51 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -4,8 +4,13 @@
44

55
package net.sourceforge.pmd.util.fxdesigner;
66

7+
import java.io.IOException;
8+
import java.io.InputStream;
9+
import java.util.Properties;
710
import javax.swing.JOptionPane;
811

12+
import org.apache.commons.lang3.SystemUtils;
13+
914
import com.beust.jcommander.JCommander;
1015
import com.beust.jcommander.ParameterException;
1116
import javafx.application.Application;
@@ -20,6 +25,13 @@ public final class DesignerStarter {
2025
+ " Please install JavaFX on your system and try again." + System.lineSeparator()
2126
+ " See https://gluonhq.com/products/javafx/";
2227

28+
private static final String INCOMPATIBLE_JAVAFX =
29+
"You seem to be running an older version of JavaFX runtime." + System.lineSeparator()
30+
+ " Please install the latest JavaFX on your system and try again." + System.lineSeparator()
31+
+ " See https://gluonhq.com/products/javafx/";
32+
33+
private static final int MIN_JAVAFX_VERSION_ON_MAC_OSX = 14;
34+
2335
private static final int ERROR_EXIT = 1;
2436
private static final int OK = 0;
2537

@@ -71,6 +83,41 @@ public static void main(String[] args) {
7183
launchGui(args);
7284
}
7385

86+
private static void setSystemProperties() {
87+
if (SystemUtils.IS_OS_LINUX) {
88+
// On Linux, JavaFX renders text poorly by default. These settings help to alleviate the problems.
89+
System.setProperty("prism.text", "t2k");
90+
System.setProperty("prism.lcdtext", "true");
91+
}
92+
}
93+
94+
private static boolean isCompatibleJavaFxVersion() {
95+
if (SystemUtils.IS_OS_MAC_OSX) {
96+
final String javaFxVersion = getJavaFxVersion();
97+
if (javaFxVersion != null) {
98+
final int major = Integer.parseInt(javaFxVersion.split("\\.")[0]);
99+
if (major < MIN_JAVAFX_VERSION_ON_MAC_OSX) {
100+
// Prior to JavaFx 14, text on Mac OSX was garbled and unreadable
101+
return false;
102+
}
103+
}
104+
}
105+
106+
return true;
107+
}
108+
109+
private static String getJavaFxVersion() {
110+
try (InputStream is = DesignerStarter.class.getClassLoader().getResourceAsStream("javafx.properties")) {
111+
final Properties javaFxProperties = new Properties();
112+
javaFxProperties.load(is);
113+
return (String) javaFxProperties.get("javafx.version");
114+
} catch (IOException ignored) {
115+
// Can't determine the version
116+
}
117+
118+
return null;
119+
}
120+
74121
private static String getHelpText(JCommander jCommander) {
75122

76123
StringBuilder sb = new StringBuilder();
@@ -93,9 +140,13 @@ private static String getHelpText(JCommander jCommander) {
93140

94141
@SuppressWarnings("PMD.AvoidCatchingThrowable")
95142
private static void launchGui(String[] args) {
143+
setSystemProperties();
144+
96145
String message = null;
97146
if (!isJavaFxAvailable()) {
98147
message = MISSING_JAVAFX;
148+
} else if (!isCompatibleJavaFxVersion()) {
149+
message = INCOMPATIBLE_JAVAFX;
99150
}
100151

101152
if (message != null) {
@@ -104,7 +155,6 @@ private static void launchGui(String[] args) {
104155
System.exit(ERROR_EXIT);
105156
}
106157

107-
108158
try {
109159
Application.launch(Designer.class, args);
110160
} catch (Throwable unrecoverable) {

0 commit comments

Comments
 (0)