How to prevent automatic scaling under 96 dpi

97 Views Asked by At

In NatTable version 2 an autoscale was added while the tables are being created, supported by default DPI converters: DefaultHorizontalDpiConverter, DefaultVerticalDpiConverter. In version 1 everything under 96 DPI was not scaled down, however, now in version 2 for lower DPIs NatTables are scaled down hence images look ugly, fonts are ok:

72dpi - not ok:

enter image description here enter image description here enter image description here

96dpi - ok:

enter image description here enter image description here enter image description here

What would be the simplest way to prevent default scaling under 96 DPI?

1

There are 1 best solutions below

4
Dirk Fauth On

The feature that was added with NatTable 2.0 is a complete dynamic scaling and the full support for all DPI. The following blog post should give some more details NatTable – dynamic scaling enhancements

Actually I wonder what is "ugly" with lower DPIs. At least on modern displays it should not be an issue. The only thing I could think of are the images. But typically downscaling doesn't make images ugly. So it would be really interesting to know what the issue is.

You have two options to handle that:

  1. As you can scale NatTable dynamically at runtime, you can simply execute the ConfigureScalingCommand to force the scaling you want. Note that this needs to be done AFTER NatTable#configure().

    if (Display.getDefault().getDPI().x < 96) {
        natTable.doCommand(
            new ConfigureScalingCommand(new FixedScalingDpiConverter(96)));
    }
    
  2. If you even want to block lower scalings on the dynamic scaling, you can implement a custom ConfigureScalingCommandHandler that checks for the dpiFactor in the IDpiConverter and if that is lower than 1 register a FixedScalingDpiConverter on the SizeConfigs. That custom ConfigureScalingCommandHandlerthen needs to be registered on the DataLayer to replace the default.

The second approach is probably a bit more complicated and needs a better understanding of NatTable internals. And it blocks the dynamic scaling feature to really zoom out on huge tables. So it depends on your use cases which approach to use. Typically the first option should be sufficient.

BTW, if the images are the issue, changing the scaling at runtime without re-registering the images could also cause a rendering issue. The reason for this is that images are stored in the ImageRegistry and they need to be updated there in case of scaling changes. For approach 1. that means to register all images in the ConfigRegistry again after the ConfigureScalingCommand. At least if you are not using themes or CSS styling.