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
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.
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.
If you love us? You can donate to us via Paypal or buy me a coffee so we can maintain and grow! Thank you!
Donate Us With