icyphy / ptII

Ptolemy II is an open-source software framework supporting experimentation with actor-oriented design.
https://ptolemy.eecs.berkeley.edu/ptolemyII
Other
99 stars 43 forks source link

Blurry Fonts on Mac #342

Open david-San opened 2 years ago

david-San commented 2 years ago

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 commented 2 years ago

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

david-San commented 2 years ago

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 commented 2 years ago

The font problem rings a bell, but a quick search did not find anything.  I can look further tonight (Pacific time).

It might be possible to set some command line arguments, see

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

More later ...

_Christopher

On 3/14/22 10:54 AM, david-San wrote:

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.

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 https://user-images.githubusercontent.com/677981/158232013-eb2e9fa9-25be-456f-9355-2a2e089046f2.png

— Reply to this email directly, view it on GitHub https://github.com/icyphy/ptII/issues/342#issuecomment-1067119080, or unsubscribe https://github.com/notifications/unsubscribe-auth/AAGSOJYIJT2XMTNQKLWP5WDU754OFANCNFSM5QVMCLZQ. Triage notifications on the go with GitHub Mobile for iOS https://apps.apple.com/app/apple-store/id1477376905?ct=notification-email&mt=8&pt=524675 or Android https://play.google.com/store/apps/details?id=com.github.android&referrer=utm_campaign%3Dnotification-email%26utm_medium%3Demail%26utm_source%3Dgithub.

You are receiving this because you are subscribed to this thread.Message ID: @.***>

david-San commented 2 years ago

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 commented 2 years ago

I got caught up with other tasks last night.

There is no Ptolemy II-specific configuration file to set command line parameters.  When building from source, $PTII/bin/ptinvoke.in is read in and $PTII/bin/ptinvoke is created.  $PTII/bin/vergil is a symbolic link to ptinvoke.

If I recall, you are running Java from the command line, so that is where you would add Java command-line arguments.

I'm sorry for the delay, I should be able to take a look tonight.

_Christopher

On 3/15/22 9:22 AM, david-San wrote:

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?

— Reply to this email directly, view it on GitHub https://github.com/icyphy/ptII/issues/342#issuecomment-1068185676, or unsubscribe https://github.com/notifications/unsubscribe-auth/AAGSOJ63GEOXVZWNDNTUVVTVAC2KRANCNFSM5QVMCLZQ. Triage notifications on the go with GitHub Mobile for iOS https://apps.apple.com/app/apple-store/id1477376905?ct=notification-email&mt=8&pt=524675 or Android https://play.google.com/store/apps/details?id=com.github.android&referrer=utm_campaign%3Dnotification-email%26utm_medium%3Demail%26utm_source%3Dgithub.

You are receiving this because you commented.Message ID: @.***>

cxbrooks commented 2 years ago

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 commented 2 years ago

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 commented 2 years ago

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

cxbrooks commented 2 years ago

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 commented 2 years ago

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 commented 2 years ago

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 commented 2 years ago

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).

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 commented 2 years ago

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 commented 2 years ago

Great! Thanks for trying again.

I might be slightly confused, but it seems that the screen is less blurry for you, right?

You were able to add sun.java2d.uiScale=2.5 to the VM command line args which solved the problem.  I'll keep this issue open until I rebuild the macOS installer with that setting built in. It could be awhile, I have other tasks.  However, this issue will help anyone else who has the problem.

I'm not sure why my screen capture is a bit blurry.

About the Windows installer, I'll update the web page to suggest JDK 1.8.  Thanks for trying various options.  My install on a Windows machine did use JDK 1.8.  It is too bad that the Java maintainers completely broke backward compatibility.

About git failing, that message is a new one to me.  If you are interested in installing Ptolemy II from sources, you could see if doing "cd ptII; git pull" works.  Otherwise, remove the ptII directory possibly created by git and try again.  If the error persists, see

https://errorseverywhere.com/solve-git-fatal-the-remote-end-hung-up-unexpectedly-error/

On 3/18/22 8:28 AM, david-San wrote:

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 |

I have to say that my screen looks less blurry than yours.

Screenshot 2022-03-18 at 15 15 48 https://user-images.githubusercontent.com/677981/159032154-ee852dc5-6b05-4925-a9c8-b3e824149a0c.png

— Reply to this email directly, view it on GitHub https://github.com/icyphy/ptII/issues/342#issuecomment-1072520546, or unsubscribe https://github.com/notifications/unsubscribe-auth/AAGSOJ4OTSDMP3DTSVWEW6DVASOIHANCNFSM5QVMCLZQ. Triage notifications on the go with GitHub Mobile for iOS https://apps.apple.com/app/apple-store/id1477376905?ct=notification-email&mt=8&pt=524675 or Android https://play.google.com/store/apps/details?id=com.github.android&referrer=utm_campaign%3Dnotification-email%26utm_medium%3Demail%26utm_source%3Dgithub.

You are receiving this because you commented.Message ID: @.***>

david-San commented 2 years ago

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 commented 2 years ago

Right, I thought I was misreading your post.  I'm away from my computer for a few days, I'll take a look on Monday or Sunday.

On 3/18/22 9:48 AM, david-San wrote:

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. Look how my normal page looks.

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.

— Reply to this email directly, view it on GitHub https://github.com/icyphy/ptII/issues/342#issuecomment-1072595843, or unsubscribe https://github.com/notifications/unsubscribe-auth/AAGSOJZN5IANSD2VBZV3WC3VASXWRANCNFSM5QVMCLZQ. Triage notifications on the go with GitHub Mobile for iOS https://apps.apple.com/app/apple-store/id1477376905?ct=notification-email&mt=8&pt=524675 or Android https://play.google.com/store/apps/details?id=com.github.android&referrer=utm_campaign%3Dnotification-email%26utm_medium%3Demail%26utm_source%3Dgithub.

You are receiving this because you commented.Message ID: @.***>

cxbrooks commented 2 years ago

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.