如何防止96 dpi下自动缩放
在 NatTable 版本 2 中,创建表时添加了自动缩放功能,默认 DPI 转换器支持:DefaultHorizontalDpiConverter、DefaultVerticalDpiConverter
。在版本 1 中,96 DPI 以下的所有内容都没有缩小,但是,现在在版本 2 中,对于较低 DPI,NatTables 被缩小,因此图像看起来很难看,字体还可以:
72dpi - 不可以:
96dpi - 好的:
防止 96 DPI 下默认缩放的最简单方法是什么?
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:
96dpi - ok:
What would be the simplest way to prevent default scaling under 96 DPI?
如果你对这篇内容有疑问,欢迎到本站社区发帖提问 参与讨论,获取更多帮助,或者扫码二维码加入 Web 技术交流群。
绑定邮箱获取回复消息
由于您还没有绑定你的真实邮箱,如果其他用户或者作者回复了您的评论,将不能在第一时间通知您!
发布评论
评论(1)
NatTable 2.0添加的功能是完整的动态缩放和对所有DPI的完全支持。以下博客文章应该提供更多详细信息 NatTable – 动态缩放 事实上,
我想知道较低的 DPI 有何“丑陋”之处。至少在现代显示器上这不应该是一个问题。我唯一能想到的就是图像。但通常缩小尺寸不会使图像变得难看。因此,了解问题所在真的很有趣。
您有两种选择来处理这个问题:
由于您可以在运行时动态缩放 NatTable,因此您只需执行
ConfigureScalingCommand
即可强制进行所需的缩放。请注意,这需要在NatTable#configure()
之后完成。如果您甚至想在动态缩放中阻止较低的缩放,您可以实现一个自定义的
ConfigureScalingCommandHandler
来检查IDpiConverter
中的 dpiFactor 以及是否低于1 在SizeConfigs
上注册一个FixedScalingDpiConverter
。然后需要在DataLayer
上注册该自定义ConfigureScalingCommandHandler
以替换默认值。第二种方法可能有点复杂,需要更好地了解 NatTable 内部结构。它阻止动态缩放功能来真正缩小巨大的桌子。因此,这取决于您的用例使用哪种方法。通常第一个选项应该足够了。
顺便说一句,如果图像是问题所在,则在运行时更改缩放而不重新注册图像也可能会导致渲染问题。原因是图像存储在 ImageRegistry 中,并且需要在缩放发生变化时进行更新。对于方法 1,这意味着在
ConfigureScalingCommand
之后再次将所有图像注册到ConfigRegistry
中。至少如果您不使用主题或 CSS 样式。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:
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 AFTERNatTable#configure()
.If you even want to block lower scalings on the dynamic scaling, you can implement a custom
ConfigureScalingCommandHandler
that checks for the dpiFactor in theIDpiConverter
and if that is lower than 1 register aFixedScalingDpiConverter
on theSizeConfigs
. That customConfigureScalingCommandHandler
then needs to be registered on theDataLayer
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 theConfigRegistry
again after theConfigureScalingCommand
. At least if you are not using themes or CSS styling.