Logo Questions Linux Laravel Mysql Ubuntu Git Menu
 

Java SWT Browser. Different output on screens with Ultra HD (4K) or higher resolutions

We use SWT browser in our java app to render HTML content. The problems arise when the environment has a very high resolution (4K). When the content has a such html:

<html> <head> <style> .test { font-size: 35px;font-family: Arial;} </style> </head><body><div class='test'>TEST</div></body></html>

And the used java source is:

import org.eclipse.swt.SWT;
import org.eclipse.swt.browser.*;
import org.eclipse.swt.layout.*;
import org.eclipse.swt.widgets.*;

public class SWTTest {

  public void run() {
    Display display = new Display();
    Shell shell = new Shell(display);
    shell.setText("SWT test");
    createContents(shell);
    shell.open();
    while (!shell.isDisposed()) {
      if (!display.readAndDispatch()) {
        display.sleep();
      }
    }
    display.dispose();
  }

  private void createContents(Shell shell) {
    shell.setLayout(new FillLayout());

   Browser browser = new Browser(shell, SWT.NONE);

   browser.setText("<html> \r\n" + 
            "<head> <style> .test { font-size: 85px;font-family: Arial;} </style> </head>\r\n" + 
            "<body>\r\n" + 
            "<div class=\"test\">TEST</div>\r\n" + 
            "</body>\r\n" + 
            "</html>");
  }

 public static void main(String[] args) {
    new SWTTest().run();
  }
}

On regular environments with 1920x1080 and resolution is 96, the rendered content and the viewed content in the Internet Explorer are same (We save the example text html as a file and open with IE)

On some laptops where we have a resolution more than 128 and 4K dimensions, the rendered content has the elements (TEST div) with 35px font size very small compared to IE.

As we know SWT uses the underlying IE, but I think IE makes some post process operations to fine tune the content and fixes the element sizes depending on the screen properties (resolution etc), which is not done when called from SWT.

Any solution without modifying the html content?

System properties: OS: Windows 10 (updated) IE: 11 Java 1.8.161 (32bits) SWT: 4.3

like image 918
benchpresser Avatar asked May 16 '18 07:05

benchpresser


2 Answers

There seem to be some important fixes to high-DPI display in Java 9 (see also here). If your user community can move forward, that might be the easiest fix.

like image 127
Bob Jacobsen Avatar answered Sep 20 '22 11:09

Bob Jacobsen


This probably requires a newer version of SWT, I suggest you pick the latest release. Note, that Photon Eclipse 4.8 is about to be released, so current RC builds should be quite good as well. Regarding HDPI w/ Eclipse on Windows, there's also a related forum thread here.

like image 42
Jörg Avatar answered Sep 23 '22 11:09

Jörg