Fixes #686 - [RichText] Add support for monitor specific scaling#687
Fixes #686 - [RichText] Add support for monitor specific scaling#687
Conversation
Signed-off-by: Dirk Fauth <dirk.fauth@googlemail.com>
| @@ -4,7 +4,7 @@ Bundle-Name: Nebula Rich Text Editor Examples | |||
| Bundle-SymbolicName: org.eclipse.nebula.widgets.richtext.example | |||
| Bundle-Version: 1.0.0.qualifier | |||
There was a problem hiding this comment.
You should have at least some some minimal version change here.
There was a problem hiding this comment.
I suppose you mean the version of the richtext bundle, not the examples. Did that.
There was a problem hiding this comment.
Nobody cares about the examples. They are not published and only used for development testing AFAIK. That is why nobody ever mentioned them in 11 years.
But ... you are completely right, and just because nobody cared so far doesn't mean it is correct. ;)
I updated the version. :)
There was a problem hiding this comment.
I didn't actually look at the context around this. 😁
merks
left a comment
There was a problem hiding this comment.
I think this:
nebula/.github/workflows/maven.yaml
Line 12 in 328cd09
and this
Line 14 in 328cd09
need attention with your Java 21 upgrade.
Last time I looked into that topic was: Don't do it... actually at Linux I can configure a custom scaling factor for fonts making anything that tries to "adjust" fonts simply fail. Next SWT/OS lies at you (well ... it do best effort)... so you get a logical DPI not the real hardware DPI... and so on. So the best one can do is having adapt to system font sizes and maybe add a preference for the user to define an own scaling factor. If you need Fonts matching an exact bounds, the best is to compute it dynamically using the Font Metrics and then possibly adjust it incrementally. |
Thanks for the hint. As the upcoming Eclipse release requires Java 21, this needs to be adapted here also. @laeubi With CKEditor you can edit and format text in HTML. For the text formatting, the corresponding style elements are added to the tags. And I need to convert these style informations to SWT. The font height is set in px, but Fonts in SWT need to be created with point values. So there is no existing font that would match here at that time from which I could retrieve FontMetrics. At least I would not be aware of something like that. If you have an idea how to solve this in a better way, please let me know. |
Then maybe you can give an example of where exactly this conversion is needed.
So far so good :-)
Where? Html supports a wide range of font size definitions including px, pt, em, ...
If you can create Fonts you have a Display and you can create a GC and get FontMetrics from that.... |
| Rectangle embeddedShellBounds = embeddedShell.getBounds(); | ||
|
|
||
| String updateOnRuntime = System.getProperty("swt.autoScale.updateOnRuntime", "false"); //$NON-NLS-1$ //$NON-NLS-2$ | ||
| if (!Boolean.parseBoolean(updateOnRuntime)) { |
There was a problem hiding this comment.
I have to admit that I do not understand why the distinction between monitor-specific scaling disabled/enabled has to be made here. I would expect that if you need to do something special for non-100% in monitor-specific scaling, you will probably need to do the same with monitor-specific scaling disabled at zooms of 175% and higher (but that's just a guess because I do not know why these different calculations are necessary here).
Anyway, in case the distinction is necessary, I propose to use getDisplay.isRescalingAtRuntime() instead of evaluating the system property. It should give you an even "more correct" value (as you can change the system property after the display with its shells has been created).
|
The HTML is generated by CKEditor, and I don't have much influence on how it is generated. For example if a text is selected to have a size of 20, the generated HTML looks like this In the I use instructions to process the tags accordingly, and the font style is applied via You can use the RichTextViewerExample to see it in action. With the current implementation, the selected font size in the browser reflects correctly in the viewer. At least it does on Windows with different scalings (or at least it did). @HeikoKlare Thanks for the hint about @merks |
I a quite sure this is not caused by updateOnRuntime but by the SWT autoscale mode that is (implicitly) changed when enabling updateOnRuntime. Precisely, without updateOnRuntime the autoscale mode Related to this, the size of the shell does not look as intended to me when having updateOnRuntime set to false. So the shell seems to be autoscaled to 100%/200%. |



This PR adds support for monitor specific scaling in the richtext widget.
It uses the new
Shell#getZoom()API from the upcoming 2026-03 release, so it should not be merged until the release is done.There is also one open topic related to conversion from a pixel value to point for the font creation.