eclipse-platform / eclipse.platform.swt

Eclipse SWT
https://www.eclipse.org/swt/
Eclipse Public License 2.0
114 stars 131 forks source link

Non-integer-scaling: The Autoscale feature delivers strange results. #60

Open MarcelBoerner opened 2 years ago

MarcelBoerner commented 2 years ago

On a pure SWT application we used the SWTs gc with drawText, draw Rectangle and draw String method. When using scalings with different values you see that the text and the drawing of the rectangle are not scaled the same way. So the text is sometimes to small or cuts the rectangle. So SWT is not usable for custom drawings (like drawing a table) since the customers do get texts which are cut off or cells wich have much lost space which is not used. image In the above picture you can see how icons lose information when they are scaled down, which also happens to images (1). The title areas are adapted to their height at each scaling but the width is only extended when you go above or blow the 175% (2). The height and the width of the shell on which is drawen is also only adapted on 175% scaling changes (3). But the biggest problem is that drawing with drawText or drawString and using the draw Rectangle method, leads to text which does not fit into the drawen rectangles at different zooms (4) The following snippet delivers the results seen on the picture when starting it with different scalings. ` public static void main(String[] args) { Display display = new Display(); Shell shell = new Shell(display); try { shell.addPaintListener(new PaintListener() {

    @Override
    public void paintControl(PaintEvent e) {
      e.gc.drawText("Long Test Text", 20, 40);
      e.gc.drawRectangle(20, 40, 95, 30);
      e.gc.drawString("Long Test Text", 20, 75);
      e.gc.drawRectangle(20, 75, 95, 30);
    }
  });
  shell.setMinimumSize(400, 450);
  shell.pack();
  shell.open();
  while (!shell.isDisposed()) {
    if (!display.readAndDispatch()) {
      display.sleep();
    }
  }
} finally {
  display.dispose();
}

} `

niraj-modi commented 2 years ago

200% zoom missing from this comparison ?

niraj-modi commented 2 years ago

SWT works best with integer scaling factor, same was documented: https://www.eclipse.org/eclipse/news/4.6/platform.php#swt-autoscale-tweaks

niraj-modi commented 2 years ago

We appreciate ideas and fix-proposal to improve the support here.

amarkevich commented 1 year ago

image

For zoom values of 100, 125 & 150 rectangle is the same but text rendered using selected scale. As possible solution which also applied for higher zoom factor:

          Point textSize = e.gc.textExtent("Long Test Text");
          e.gc.drawString("Long Test Text", 20, 150);
          e.gc.drawRectangle(20, 150, textSize.x, textSize.y);