Skip to main content


Eclipse Community Forums
Forum Search:

Search      Help    Register    Login    Home
Home » Eclipse Projects » NatTable » Gap between grid lines and cells in HDPI environments with CSS & swt.autoScale(There might be a gap rendered between grid lines in HDPI environments with CSS & vmarg -Dswt.autoScale=quarter)
Gap between grid lines and cells in HDPI environments with CSS & swt.autoScale [message #1769284] Fri, 28 July 2017 15:03 Go to next message
Lothar L. is currently offline Lothar L.Friend
Messages: 27
Registered: July 2016
Junior Member
When running in a HDPI environment (3840*2160, Windows 10 scaling factor 200%) and using the swt.autoScale switch [1] in our application the grid lines in our nattable don't fill out the whole gap between cells anymore. As can be seen in the attached examples the background shines through. Apparently the gap gets scaled while the lines remain at 1px height.

We would expect the grid lines to increase in height accordingly or the gap between cells not to scale.


We can reproduce the effect with the e4 CSS based nattable examples.

Add a background-color to the basic definition such as:
.basic {
	cell-background-color: white;
	text-align: left;
	table-border-color: auto;
	fill-handle-color: blue;
	fill-handle-border: 1px black solid;
	fill-region-border: 2px blue solid;
	/* column-width: percentage; */
	grid-line-color: black;
	grid-line-width: 1px;
	
	background-color:  cyan;
}


Add the switch
-Dswt.autoScale=quarter
to the vmargs in your run configuration.

Please note: Removing grid-line-width: 1px; has no effect on the issue for us.

Attached you find screenshot of the [CSSExample] with the switch set to false and set to quarter, i.e. scaling enabled. With scaling disabled the height of elements in the column [Food] is to low.

index.php/fa/30173/0/
Sample with -Dswt.autoScale=quarter and background visible between cells

index.php/fa/30175/0/
Sample with -Dswt.autoScale=false. Height of elements of column [Food] to low.

[1]: https://www.eclipse.org/eclipse/news/4.6/platform.php#swt-autoscale-tweaks

[Updated on: Fri, 28 July 2017 15:37]

Report message to a moderator

Re: Gap between grid lines and cells in HDPI environments with CSS & swt.autoScale [message #1769296 is a reply to message #1769284] Fri, 28 July 2017 17:33 Go to previous messageGo to next message
Dirk Fauth is currently offline Dirk FauthFriend
Messages: 2902
Registered: July 2012
Senior Member
Open a ticket. And optimally provide a patch.

Not sure what else you want to hear as there is no question in your post.
Re: Gap between grid lines and cells in HDPI environments with CSS & swt.autoScale [message #1769393 is a reply to message #1769296] Mon, 31 July 2017 10:02 Go to previous messageGo to next message
Lothar L. is currently offline Lothar L.Friend
Messages: 27
Registered: July 2016
Junior Member
Hi Dirk,

thank you very much for your reply.


Well, we are hoping for comments on the situation. Specific questions:

  • Should gap and line thickness be scaled or what would be the expected behavior?
  • Is NatTable doing something special here?
  • And if so, why would NatTable have to do something special should this not be handled by SWT?
  • If the issues only emerges with the SWT switch in play is it then really relevant or more to the point how relevant do you deem the issue?
  • For example should the SWT switch be used when scaling is done via Windows anyways?
  • Maybe we are not using the switch correctly?
  • Has somebody else had the problem and maybe even found a workaround.


I can open a bug as you suggested.

Would you be able to provide some pointers (class name) as to where to look in the source code or maybe how you would analyze the issue?
My starting point would be the GridLineCellLayerPainter in NatTable. For SWT I have no idea.
Re: Gap between grid lines and cells in HDPI environments with CSS & swt.autoScale [message #1769435 is a reply to message #1769393] Mon, 31 July 2017 14:23 Go to previous messageGo to next message
Dirk Fauth is currently offline Dirk FauthFriend
Messages: 2902
Registered: July 2012
Senior Member
Quote:
Should gap and line thickness be scaled or what would be the expected behavior?

NatTable has not implemented anything to scale line thickness. You can see this also for line border decorators. That would be something we need to add. But there should be no gap. Might be some rounding issue because the rendering of the background is done taking the grid lines into account. And IIRC the issue is that they move a little bit more than they should. At least it was similar on printing.
Quote:
Is NatTable doing something special here?

NatTable is a custom painted control based on Canvas, so scaling is implemented internally. Some places seem to be missing like for example the grid lines.
Quote:
And if so, why would NatTable have to do something special should this not be handled by SWT?

NatTable Core is still based on Eclipse Helios IIRC. The flags you refer to were added in Neon (and I wasn't really aware of them). Because of that dependency and the fact that NatTable is a custom painted control we did the upscaling some years ago ourselves.
Quote:
If the issues only emerges with the SWT switch in play is it then really relevant or more to the point how relevant do you deem the issue?

In the end I would ask the SWT team where the issue would come from. It seems not all painting operations take the switch into account. Why do some paint operations scale automatically (e.g. the internal blue border) and others not like the grid lines?
Quote:
For example should the SWT switch be used when scaling is done via Windows anyways?

As said before, NatTable does the upscaling internally by inspecting the DPI from the display. So from a NatTable point of view, that flag is not needed as it is not inspected.
Quote:
Maybe we are not using the switch correctly?

That is something I really can't tell as I learned about that flag from your post.

You can open a ticket that not all paint operations scale correctly. E.g. the TableCellPainter does not upscale the internal cells. That needs to be added. Also some of the line painter probably.

The GridLineCellLayerPainter would be one thing. Sure can the line width be manually increased to see if that fixes the issue. Not sure if that is enough as the cell dimensions have a fixed 1 pixel modification for the grid lines. That makes it more complicated overall.
Re: Gap between grid lines and cells in HDPI environments with CSS & swt.autoScale [message #1769670 is a reply to message #1769435] Wed, 02 August 2017 14:09 Go to previous messageGo to next message
Lothar L. is currently offline Lothar L.Friend
Messages: 27
Registered: July 2016
Junior Member
Thank you very much for your reply.

As said before, NatTable does the upscaling internally by inspecting the DPI from the display. So from a NatTable point of view, that flag is not needed as it is not inspected.

We tested this again.

We update the used Windows 10 installation with latest patches to Version 1703 (Build 15063.483) because MS had done some work in regards to UI scaling.
For the new testing we used the _000_Default_NatTable class only changing the #createExample method to:
    @Override
    public Control createExampleControl(Composite parent) {
        NatTable natTable = new NatTable(parent);
        natTable.setBackground(natTable.getShell().getDisplay().getSystemColor(SWT.COLOR_CYAN));
        return natTable;
    }

We did not(!) use the SWT switch and consequently the CSS engine was not used either.
Edit: This is wrong. The default value for the switch is "integer". In order to test without the switch one must set the value of the switch to "false". Which we apparently didn't do.

The result is that the gap is visible with OS scaling enabled - as you can see in the attached screen shots. In consequence the title of the issue indeed is wrong and the issues appears be affected by the OS scaling (which is enabled by default) only. Edit: This is wrong. The title is correct in regards the the switch swt.autoScale leading to a gap between cells. Rather the switch has only a negative effect if the OS does apply scaling as well.
index.php/fa/30231/0/
OS scaling disabled.
index.php/fa/30232/0/
OS scaling set to 200% (OS default value)

Quote:

NatTable has not implemented anything to scale line thickness. You can see this also for line border decorators. That would be something we need to add. But there should be no gap. Might be some rounding issue because the rendering of the background is done taking the grid lines into account. And IIRC the issue is that they move a little bit more than they should. At least it was similar on printing.
...
NatTable is a custom painted control based on Canvas, so scaling is implemented internally. Some places seem to be missing like for example the grid lines.

Thank you very much for the explanation. That is very helpful.
May we ask why the internal scaling was/is needed in the first place? Was this indeed added for HIDPI environments? Would it be feasible to disable the internal scaling maybe for some use cases at least for Windows 10 onwards (not sure about Windows 8)?

As said before, NatTable does the upscaling internally by inspecting the DPI from the display. So from a NatTable point of view, that flag is not needed as it is not inspected.

In regards to the scaling looking at the image defaultNatTableWithoutOSScaling.png should the table then not be bigger, should there not be scaling be visible in the image first image (no OS scaling)?
Would you be able to point us to were the scaling is done?

[Updated on: Mon, 07 August 2017 17:20]

Report message to a moderator

Re: Gap between grid lines and cells in HDPI environments with CSS & swt.autoScale [message #1769676 is a reply to message #1769670] Wed, 02 August 2017 14:56 Go to previous messageGo to next message
Dirk Fauth is currently offline Dirk FauthFriend
Messages: 2902
Registered: July 2012
Senior Member
Why should the first image without OS scaling be bigger? That doesn't make sense. Maybe my explanation was not good enough.

Please have a look at the NatTable implementation. On initialization a ConfigureScalingCommand is triggered to inform SizeConfig and some ILayer that scaling needs to be done according to the current OS scaling.

It was introduced with NatTable 1.2, so several years ago. https://eclipse.org/nattable/nandn/nandn_120.php

You can try to fire another command that has a fixed scaling of 1.0. That should disable the internal scaling hopefully.

I noticed in the past that I need to logoff and login again after I changed the OS scaling. When I don't re-login there are strange effects with SWT.
Re: Gap between grid lines and cells in HDPI environments with CSS & swt.autoScale [message #1770043 is a reply to message #1769676] Mon, 07 August 2017 17:33 Go to previous messageGo to next message
Lothar L. is currently offline Lothar L.Friend
Messages: 27
Registered: July 2016
Junior Member
We made a mistake. Whilst testing we assumed the default for the switch would be "false" but indeed it is "integer". Thus the switch has always been enabled whilst we have been testing. This also noted in the news description [1]. We tried to update the second post accordingly. The issues seems to arise out of the combination of OS scaling and SWT scaling.

We haven't found the place were extra pixels are added that cause the gap but we are still looking into this and hopefully find something.


[1]: https://www.eclipse.org/eclipse/news/4.6/platform.php#swt-autoscale-tweaks
Re: Gap between grid lines and cells in HDPI environments with CSS & swt.autoScale [message #1772241 is a reply to message #1770043] Thu, 07 September 2017 05:04 Go to previous messageGo to next message
PC PC is currently offline PC PCFriend
Messages: 2
Registered: September 2017
Junior Member
Am facing issue with Cell Borders, There is gap between the borders. am useing CustomLineBorderDecorator.java to piant Cell Borders.
I tried with tweaking as false on VM argument level, but for me its not working..
tried with:
1. Spacing as 0 (Zero)
2. Padding

but not success so far.

Suggest if anything else i can apply.
Re: Gap between grid lines and cells in HDPI environments with CSS & swt.autoScale [message #1772960 is a reply to message #1772241] Tue, 19 September 2017 14:06 Go to previous messageGo to next message
Lothar L. is currently offline Lothar L.Friend
Messages: 27
Registered: July 2016
Junior Member
Our findings after investigating this issue further:


  • The NatTable scaling is never active because org.eclipse.nebula.widgets.nattable.util.GUIHelper.getDpiFactor(int) always returns 1 (even in a 4k environment with OS scaling disabled). This based on Display.getDefault().getDPI().x which returns 96. This makes sense becuase SWT uses org.eclipse.swt.internal.DPIUtil.deviceZoom for scaling.

  • The acutal line width used for painting is set in
    org.eclipse.nebula.widgets.nattable.painter.layer.GridLineCellLayerPainter.paintLayer(ILayer, GC, int, int, Rectangle, IConfigRegistry)
    {
    ...
            // Draw GridLines
            if (this.renderGridLines) {
                // check if there is a configuration for the grid line width
                Integer width = configRegistry.getConfigAttribute(
                        CellConfigAttributes.GRID_LINE_WIDTH,
                        DisplayMode.NORMAL,
                        labels);
                this.gridLineWidth = (width != null) ? width : 1;
    
                int oldLineWidth = gc.getLineWidth();
                gc.setLineWidth(this.gridLineWidth);
    ...
    }
    

  • For some reason in the context of NatTable a line width of exactly 1 is not scaled when painting. From what I can tell this should not be the case and is the reason for the issue. Please also see [1]. Any line width > 0 should be scaled with the swt.autoScale switch. Using a line width > 1 such as 2 works as expected, i.e. the line is scaled.

  • As a workaround we set the scaled line width manually before calling #paintLayer : gc.setLineWidth(DPIUtil.autoScaleUp(this.gridLineWidth));
  • NOTE gc.getGCData().lineWidth works as well in this case and returns 2.0f and might indicate that the scaling is partly applied but not working.

  • This workaround works only for cells. If you point us to where the headers/borders are painted we could check this as well.


We tested this with org.eclipse.swt.win32.win32.x86_64_3.106.0.v20170608-0516.jar


Because a line width of 1 is not scaled we are wondering if NatTable is doing anything special with the GC?

Should we go ahead open a bug and try contribute our findings as code?


[1] https://www.eclipse.org/forums/index.php/t/1088692/
Re: Gap between grid lines and cells in HDPI environments with CSS & swt.autoScale [message #1772994 is a reply to message #1772960] Tue, 19 September 2017 20:37 Go to previous messageGo to next message
Dirk Fauth is currently offline Dirk FauthFriend
Messages: 2902
Registered: July 2012
Senior Member
NatTable is based on Eclipse Helios with regards to the SWT API in use. Making use of a current API would possibly break existing projects that are not able to use the latest SWT API. So you need to be careful with a contribution.

I also think setting GC#setLineWidth() before paintLayer() is not correct. Other painters might change that on the way. So you would need to adjust that in every painter. So to answer your question, you need to check every ILayerPainter and ICellPainter and check for occurences where a line width is not set correcly according to the scaling. And you also need to ensure that the cell bounds are set correctly in adjustCellBounds. And the CompositeLayer needs to be adjusted to calculate not with a 1 pixel fixed border.

Maybe it is easier and the cell bounds don't need to be adjusted, but for correctness I think that needs to be done.
Re: Gap between grid lines and cells in HDPI environments with CSS & swt.autoScale [message #1773115 is a reply to message #1772994] Thu, 21 September 2017 19:09 Go to previous messageGo to next message
Lothar L. is currently offline Lothar L.Friend
Messages: 27
Registered: July 2016
Junior Member
Mh..contributing in this case would probably not mean that the code will be pulled into the project. But we could provide you with a (small) workaround. The issue is quite severe - for us. Maybe this will help to analyze the problem.

My knowledge with SWT and NatTable is fairly limited. Best would be if an SWT expert would check on what is going there.

Quote:

NatTable is based on Eclipse Helios with regards to the SWT API in use. Making use of a current API would possibly break existing projects that are not able to use the latest SWT API. So you need to be careful with a contribution.

I checked today with the SWT-Bundle packaged with Helios SR2 and think that the change we would provide is part of the SWT-Helios API.

Quote:

I also think setting GC#setLineWidth() before paintLayer() is not correct. Other painters might change that on the way. So you would need to adjust that in every painter.
So to answer your question, you need to check every ILayerPainter and ICellPainter and check for occurences where a line width is not set correcly according to the scaling.
And you also need to ensure that the cell bounds are set correctly in adjustCellBounds. And the CompositeLayer needs to be adjusted to calculate not with a 1 pixel fixed border.


This is all correct of course. We don't think this would be a permanent (or the correct) solution to the problem.


Thank you for your information. We have a look at the other places you pointed out and try to find the reason for the problem.
Re: Gap between grid lines and cells in HDPI environments with CSS & swt.autoScale [message #1775191 is a reply to message #1773115] Thu, 26 October 2017 05:51 Go to previous message
Dirk Fauth is currently offline Dirk FauthFriend
Messages: 2902
Registered: July 2012
Senior Member
Hi Lothar,

thanks for contacting me at EclipseCon Europe directly again on this topic. I had an idea that could be checked. Add the following code to the NatTable class (or a local subclass of course):

    @Override
    public boolean isAutoScalable() {
        return false;
    }


This should disable the SWT autoscaling and use the NatTable scaling internally.

To be honest, I am not sure if this works or produces any other side effects, but it may be worth a try.
If that would work out, we could then think about how to integrate it into NatTable. Not sure when this method was added to SWT and to which SWT version we would then be dependent.
Previous Topic:GroupByDataLayer and TreeData
Next Topic:Text wrapping in row header region and cells in edit mode
Goto Forum:
  


Current Time: Fri Apr 19 07:11:22 GMT 2024

Powered by FUDForum. Page generated in 0.02088 seconds
.:: Contact :: Home ::.

Powered by: FUDforum 3.0.2.
Copyright ©2001-2010 FUDforum Bulletin Board Software

Back to the top