Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Blurry Fonts on Mac #342

Open
david-San opened this issue Mar 14, 2022 · 17 comments
Open

Blurry Fonts on Mac #342

david-San opened this issue Mar 14, 2022 · 17 comments

Comments

@david-San
Copy link

Hi! I just installed ptII and the fonts look very blurry on macOS. I have tried different JVM from 8 to 17 and fonts look blurry.
Is there something I need to configure?

@edwardalee
Copy link
Contributor

Which installation mechanism did you use? Which MacOS? I will try to replicate.

@david-San
Copy link
Author

david-San commented Mar 14, 2022

I downloaded https://ptolemy.berkeley.edu/ptolemyII/ptII11.0/ptII11.0.1.setup.mac.app.tar.gz

I followed the instructions on this page: https://ptolemy.berkeley.edu/ptolemyII/ptII11.0/mac.htm
Executing the installer by hand.
cd ~/Downloads/ptII11.0.1.setup.mac.app/Contents/Resources/Java
java -jar ptII11.0.1.setup.mac.jar

I used Java 8(OpenJDK 1.8.0_251 Oracle) and later again with Java 17 (OpenJDK Runtime Environment Temurin-17.0.2+8).
I am using a MacBook with Retina display with Big Sur 11.6.4. Radeon Pro 560X

Fonts look like out of focus (They are not crisp). It is possible to work with it, but it gets uncomfortable after a while. (Other Java Swing apps like Netbeans look fine on my system). It gets more evident with Plot windows

Screenshot 2022-03-14

@cxbrooks
Copy link
Member

cxbrooks commented Mar 14, 2022 via email

@david-San
Copy link
Author

david-San commented Mar 15, 2022

https://wiki.archlinux.org/title/Java_Runtime_Environment_fonts

I tried but I id not have any success. Do you know where I could add options to the JVM? Is there a config file or something similar?

In this link says that macOS does not offer font configuration files:

https://docs.oracle.com/en/java/javase/11/intl/font-configuration-files.html#GUID-48F5ADDD-FB48-461D-8F26-9805DFB783CD

@cxbrooks
Copy link
Member

cxbrooks commented Mar 15, 2022 via email

@cxbrooks
Copy link
Member

Summary: The installer includes JDK 1.8, which seems to be blurry under recent versions of macOS such as macOS 11.6.3 (Big Sur). Ptolemy II 11.0.1 will work with JDK up to JDK 10, but Ptolemy II 11.0.1 fails to start with JDK 11.0 or later because the JDK changed in a non-backward compatible way.

The workaround is to compile Ptolemy II from sources, see https://www.icyphy.org/ptII/

I'll continue to look in to the blurry font problem.

Also, there are a bunch of bad links on https://github.com/icyphy/ptII, it looks like the README.md has links to cdn.jsdelivr.net that no longer render the page, for example: https://cdn.jsdelivr.net/gh/icyphy/ptII@master/doc/install_index.htm

Details:

I have a macBook Pro late 2013 running macOS 11.6.3 (Big Sur). When I run Ptolemy II from within the installer, the fonts are definitely blurry. The are also blurry when I run

open $PTII/bin/Vergil.app

where $PTII is set to the directory where Ptolemy II was installed

bash-3.2$ echo $PTII
/Applications/ptII11.0.1-15Mar2022
bash-3.2$ ls $PTII
CONTRIBUTING.md
Install_V11.0.1_20220315202059_10205814287260929653.log
README.md
Uninstaller
ant
bin
build.default.xml
build.xml.in
cluster.xml
com
...

If I recall correctly, the installer runs $PTII/bin/Vergil.app which uses the JDK 1.8.0_101-b13 that we ship in $PTII/jdk.

Once Ptolemy II starts up, to check which JVM you are running, do File -> New -> Graph Editor then do View -> JVM PropertiesI was incorrect, there is a file that sets the command line arguments when $PTII/bin/Vergil.app is run. That file is $PTII/bin/Vergil.app/Contents/Info.plist. When open $PTII/bin/Vergil.app is run, then
$PTII/bin/Vergil.app/Contents/MacOS/universalJavaApplicationStub is run. However, the version that is shipped with Ptolemy II 11.0.1 does not seem to parse more recent version numbers. Substituting in a more recent version from https://raw.githubusercontent.com/tofi86/universalJavaApplicationStub/master/src/universalJavaApplicationStub works with JDK 11, but fails to start, the stack trace is:

ava.io.IOException: Failed to get field handle to set library path
	at ptolemy.util.StringUtilities.addDirectoryToJavaLibraryPath(StringUtilities.java:144)
	at ptolemy.util.StringUtilities.addPtolemyLibraryDirectoryToJavaLibraryPath(StringUtilities.java:166)
	at ptolemy.actor.gui.ConfigurationApplication.<init>(ConfigurationApplication.java:235)
	at ptolemy.actor.gui.MoMLApplication.<init>(MoMLApplication.java:100)
	at ptolemy.vergil.VergilApplication.<init>(VergilApplication.java:128)
	at ptolemy.vergil.VergilApplication.<init>(VergilApplication.java:112)
	at ptolemy.vergil.VergilApplication$1.run(VergilApplication.java:273)
	at java.desktop/java.awt.event.InvocationEvent.dispatch(InvocationEvent.java:316)
	at java.desktop/java.awt.EventQueue.dispatchEventImpl(EventQueue.java:770)
	at java.desktop/java.awt.EventQueue$4.run(EventQueue.java:721)
	at java.desktop/java.awt.EventQueue$4.run(EventQueue.java:715)
	at java.base/java.security.AccessController.doPrivileged(AccessController.java:391)
	at java.base/java.security.ProtectionDomain$JavaSecurityAccessImpl.doIntersectionPrivilege(ProtectionDomain.java:85)
	at java.desktop/java.awt.EventQueue.dispatchEvent(EventQueue.java:740)
	at java.desktop/java.awt.EventDispatchThread.pumpOneEventForFilters(EventDispatchThread.java:203)
	at java.desktop/java.awt.EventDispatchThread.pumpEventsForFilter(EventDispatchThread.java:124)
	at java.desktop/java.awt.EventDispatchThread.pumpEventsForHierarchy(EventDispatchThread.java:113)
	at java.desktop/java.awt.EventDispatchThread.pumpEvents(EventDispatchThread.java:109)
	at java.desktop/java.awt.EventDispatchThread.pumpEvents(EventDispatchThread.java:101)
	at java.desktop/java.awt.EventDispatchThread.run(EventDispatchThread.java:90)
Caused by: java.lang.NoSuchFieldException: usr_paths
	at java.base/java.lang.Class.getDeclaredField(Class.java:2549)
	at ptolemy.util.StringUtilities.addDirectoryToJavaLibraryPath(StringUtilities.java:123)
	... 19 more

usr_paths is no longer supported, the ptII development tree has fixes for this, see https://github.com/icyphy/ptII/search?q=usr_paths

@cxbrooks
Copy link
Member

Bingo! https://superuser.com/questions/988379/how-do-i-run-java-apps-upscaled-on-a-high-dpi-display says:

f you stumbled across this question but are actually looking for a solution that works on Linux, this is for you.

If you can add parameters to the java binary which launches the application, you can use the option -D to pass a value for the sun.java2d.uiScale proprty to specify a scaling factor for Java2D. This will scale your application. The scaling factor value is a double. Make sure that you pass this option to the java binary itself, not the launched Java application.

Example: Launch NearInfinity.jar with a UI scaling factor of 2.5

java -Dsun.java2d.uiScale=2.5 -jar ~/jars/NearInfinity.jar

Alternatively, you can set the GDK_SCALE environment variable. Example:

GDK_SCALE=2 java -jar ~/jars/NearInfinity.jar

I found this ArchLinux Wiki article quite useful in general for running Linux on HiDPI systems, and some of the things might work on Windows as well.

What worked for me was to edit bin/Vergil.app/Contents/Info.plist and change

      <key>VMOptions</key>
       <string>-Xmx4096m</string>

to

      <key>VMOptions</key>
      <array>
        <string>-Xmx4096m</string>
        <string>-Dsun.java2d.uiScale=2.5</string>
      </array>

and then run open $PTII/bin/Vergil.app

Note that the title bar is still blurry, but the contents of the window is more crisp:
Screen Shot 2022-03-15 at 10 22 59 PM

I'll think about creating a new installer that has this change, but it could be tricky or impossible to do.

I'll add something to https://ptolemy.berkeley.edu/ptolemyII/ptII11.0/mac.htm

@david-San
Copy link
Author

david-San commented Mar 16, 2022

Thank you cxbrooks. I am trying the workarounds you suggested but I do not get any difference in Big Sur.

  • I decided to try an old Mavericks (OS X 10.9) with Oracle Java 1.8 and all default settings and still the text looks blurry. Definitely the issue is with the HiDPI. Workarounds do not work here either.

  • I tried the Windows installer on a Windows 11 Parallels Virtual Machine. The installer says that it provides a whole environment with JRE and everything, but the installer needs Java 1.6 already installed on the machine (!?). The error message looks blurry as well (even worse than on Mac), so I did not bothered to continue.

  • I will try again in a Linux machine.

Screenshot 2022-03-16

@cxbrooks
Copy link
Member

Check to make sure that sun.java2d.uiScale is set to 2.5 in the running Java Vergil process.

The way to do this is to start Vergil, either by running open $PTII/bin/Vergil.app in the Terminal or clicking on the Vergil icon in $PTII/bin.

Then do File -> New -> Graph Editor and then in the Graph Editor Window, do View -> JVM Properties. Look for sun.java2d.uiScale See my example above. If it is not set, the reply with the portion of bin/Vergil.app/Contents/Info.plist where you set sun.java2d.uiScale. It should look like:

      <key>VMOptions</key>
      <array>
        <string>-Xmx4096m</string>
        <string>-Dsun.java2d.uiScale=2.5</string>
      </array>

Other things to try:

  1. Make sure that Vergil is not running when you restart Vergil so that the new settings in Info.plist are used. I suggest running pkill java to make sure that there are no Java processes running before restarting Vergil.
  2. Try running touch $PTII/bin/Vergil.app to prompt the Finder to see the new settings.
  3. Reboot?

About Windows, I can eventually take a look, but it is a low priority for me.

I can take a look tonight (Pacific time).

@cxbrooks
Copy link
Member

Under Windows, I was able to install Ptolemy II 11.0.1 using the Windows installer at https://ptolemy.berkeley.edu/ptolemyII/ptII11.0/index.htm and it was not blurry. I installed it on a fairly old Intel NUC running Windows 10 with 1920x1080 resolution.

The machine did have Java installed before I ran the installer. I'll update the top of https://ptolemy.berkeley.edu/ptolemyII/ptII11.0/windows.htm to be more clear. In theory, the installer could include a version of the JVM for use during installation, the tricky part would be to have the JVM used by the installer and the JVM that is installed be one and the same.

@cxbrooks
Copy link
Member

I updated https://ptolemy.berkeley.edu/ptolemyII/ptII11.0/windows.htm to be more clear that Java is needed to run the installer.

Let me know if sun.java2d.uiScale appears in Vergil's JVM Properties window.

I suggest trying the build from the command line, see https://www.icyphy.org/ptII/

@david-San
Copy link
Author

david-San commented Mar 18, 2022

I updated https://ptolemy.berkeley.edu/ptolemyII/ptII11.0/windows.htm to be more clear that Java is needed to run the installer.

Not any flavour of Java. (I am using Windows 11 on HiDPI monitor).

  • I installed Java 17 x64 (Adoption LTS) and it does not run. The installer complains that it needs Java 1.6. (Screenshot 1)
    Java 1.6 is not available in OpenJDK flavours. So, I had to registered at Oracle and download it from there:
    https://www.oracle.com/java/technologies/javase-java-archive-javase6-downloads.html

  • Run again the installer. It complains that has to be Java 1.8. (Screenshot 2). So I download Temurin JRE 8 LTE.

  • Run again the installer. It complains that it needs Java 1.6. (Screenshot 1)

  • So, I went and download JRE 8u321 from Oracle Java. The link that the installer pointed. Finally it worked on that version. Blurry fonts, though (Screenshot 3).

  • Finally Ptolemy runs. Not blurry anymore, it's true. But so tiny! (Screenshot 3. HiDPI seems not used).

Screenshot 2022-03-18 at 11 23 29

Screenshot 2022-03-18 at 11 33 53

Screenshot 2022-03-18 at 11 49 59

@david-San
Copy link
Author

david-San commented Mar 18, 2022

Bingo! https://superuser.com/questions/988379/how-do-i-run-java-apps-upscaled-on-a-high-dpi-display says:

I tried on my PTII installation that runs the internal 1.8 despite I have on my Mac JDK 17, and it is not being loaded. I am using the default installation since I cannot clone the git repository, so I cannot compile a new version:

git clone --depth=50 --branch=master --single-branch https://github.com/icyphy/ptII
Cloning into 'ptII'...
remote: Enumerating objects: 20981, done.
remote: Counting objects: 100% (20981/20981), done.
remote: Compressing objects: 100% (15188/15188), done.
fatal: The remote end hung up unexpectedly4 MiB | 3.21 MiB/s   
fatal: early EOF
fatal: index-pack failed

Screenshot 2022-03-18 at 15 15 48

@cxbrooks
Copy link
Member

cxbrooks commented Mar 18, 2022 via email

@david-San
Copy link
Author

david-San commented Mar 18, 2022

I think you misread my post. I do not think this workaround did anything. It has always been like this. It looks completely out of focus. Click on the image and look how my normal page is at full resolution.

In fact, I added the commands but the JVM is not using them. You can see it on the screenshot. As I said before, it is not unusable, just uncomfortable and after a few minutes I even get dizzy.

Honestly, I think it looks better on Windows. It is small, but it does not cause dizziness.

@cxbrooks
Copy link
Member

cxbrooks commented Mar 18, 2022 via email

@cxbrooks
Copy link
Member

The summary is that the JVM that is in the macOS Ptolemy 11.0.1 installer seems to ignore sun.java2d.uiScale. I also tried JDK 1.8.0_211. Using a different JVM, such as 10.0.2 seems to not have the blurry fonts.

Probably the best thing to do is to try building from sources, so maybe try cloning the repo again.B

BTW - When I look at your screen shot of the Ptolemy II Vergil JDK Properties window, I don't see the sun.java2d.uiScale property being set to 2.5. Compare and contrast this to my screenshot of that window where the properties are:
sun.java.launcher
sun.java2d.uiScale
sun.jnu.encoding
Your screenshot has
sun.java.launcher
sun.jnu.encoding
and
sun.java2d.uiScale
is missing from your screenshot. This means that for some reason, the property is not being set in the JVM. I had to do touch bin/Vergil.app to get the macOS Finder to notice a change to the file.

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
None yet
Projects
None yet
Development

No branches or pull requests

3 participants