Bug 568520 - Provide access to more system fonts for SWT
Summary: Provide access to more system fonts for SWT
Status: REOPENED
Alias: None
Product: Platform
Classification: Eclipse Project
Component: SWT (show other bugs)
Version: 4.14   Edit
Hardware: All All
: P3 enhancement (vote)
Target Milestone: ---   Edit
Assignee: Platform-SWT-Inbox CLA
QA Contact:
URL:
Whiteboard:
Keywords:
Depends on:
Blocks:
 
Reported: 2020-11-04 05:14 EST by Christoph Laeubrich CLA
Modified: 2020-11-14 03:55 EST (History)
7 users (show)

See Also:


Attachments

Note You need to log in before you can comment on or make changes to this bug.
Description Christoph Laeubrich CLA 2020-11-04 05:14:46 EST
Currently its a bit hard to provide nice looking UI (components) across platforms when it comes to choosing a good font.

As there is no concept of system-fonts (or at least non I'm aware of) like in AWT it is even not possible to choose for at least a fallback in case the best looking font is not available and every hard coded name is inherit platform dependent (look at [1] for an example).

The proposal is that SWT at least includes a handful of free fonts (e.g. Apache License or SIL Open Font License) that could be reliable used across platforms.

These fonts should be accessible via Display.getSystemFont(int) as it is today the case for Display.getSystemColor/getSystemCursor/getSystemImage


[1] https://git.eclipse.org/r/c/platform/eclipse.platform.swt/+/163593/22
Comment 1 Lars Vogel CLA 2020-11-05 04:19:51 EST
Alexander, WDYT?
Comment 2 Lakshmi P Shanmugam CLA 2020-11-05 05:17:55 EST
(In reply to Christoph Laeubrich from comment #0)
> These fonts should be accessible via Display.getSystemFont(int) as it is
> today the case for Display.getSystemColor/getSystemCursor/getSystemImage
> 
Have you tried Device.getSystemFont()?
From the javadoc: "Returns a reasonable font for applications to use. On some platforms, this will match the "default font" or "system font" if such can be found."
Comment 3 Christoph Laeubrich CLA 2020-11-05 05:27:47 EST
(In reply to Lakshmi P Shanmugam from comment #2)
> Have you tried Device.getSystemFont()?
> From the javadoc: "Returns a reasonable font for applications to use. On
> some platforms, this will match the "default font" or "system font" if such
> can be found."

The problem is: What is "reasonable" clearly depends on the context! For example I wan't an equally spaced "console" font, or I like some font with or without serifs. Or in the referenced example one that support a given set of (unicode) symbols. See [1] how AWT uses the concept of "physical" versus "logical" fonts.


[1] https://docs.oracle.com/javase/tutorial/2d/text/fonts.html
Comment 4 Mickael Istria CLA 2020-11-13 07:38:57 EST
The motto of SWT is to stick to the OS default as much as possible. I don't think SWT should come out of the box with some extra fonts.
However, SWT must (and already does) offer ways for adopters to ship their SWT-based software with whichever font they like and to use it at runtime.

Necessary fonts should be included downstream, eg if one font is useful in Eclipse Platform to replace some icons, we can include it in Platform and use it there. SWT is not the right layer where to put such new fonts.
Comment 5 Christoph Laeubrich CLA 2020-11-13 07:50:04 EST
Please see the discussion at https://git.eclipse.org/r/c/platform/eclipse.platform.swt/+/163593/22 where it has shown that SWT can need fonts with given properties too.

Weather or not these are provided by a font-file or by some "system specific default fonts" don't matter much as long as there are some guaranteed properties (serif vs sans-serif, equal spaced vs dynamic space, unicode symbols supported...) one can rely on.
Comment 6 Mickael Istria CLA 2020-11-13 08:07:52 EST
(In reply to Christoph Laeubrich from comment #5)
> Please see the discussion at
> https://git.eclipse.org/r/c/platform/eclipse.platform.swt/+/163593/22 where
> it has shown that SWT can need fonts with given properties too.

The C* widgets are the anomaly in SWT, as they're drawn manually instead of relying on native. They're not IMO worth influencing design discussions too much.
Does win32 API come with fonts, does GTK come with fonts? I may be wrong, but I think they don't, for the reason that they expect them to be provided by the OS, or by the application. This is the right pattern for widget libraries regarding fonts and SWT should stick to it.
Comment 7 Christoph Laeubrich CLA 2020-11-13 09:11:48 EST
There is already Display.getSystemFont() that return a "system dependent font" so I don't see how this introduces a complete *NEW* aspect but enhancing an existing concept.

Beside this it's just exceedingly complex to put the burden to the usercode to decide what are the most likely default fonts for a given task, while I would expsect this to be done in the abstraction between os and user-level (swt) like it is done for cursors already, and I think fonts are a similar demand, it would allow to have similar appearance even for custom drawn components!
Comment 8 Mickael Istria CLA 2020-11-13 09:28:57 EST
(In reply to Christoph Laeubrich from comment #7)
> There is already Display.getSystemFont() that return a "system dependent
> font" so I don't see how this introduces a complete *NEW* aspect but
> enhancing an existing concept.

So you're suggesting to add some new Display.get*Font() ?
Have you seen JFaceResources class which does actually host reference to various system fonts for several use-cases. Providing a reference to a new font for XXX seems to be a better fit here than in SWT.

However, we're digressing, my concern is not about adding references to some system fonts in SWT, it's more about adding in SWT some non-system fonts. This is not really how SWT is supposed to work since its principal rule is to stick as close as possible/delegate as much as possible to the OS by default (and allow some customization). SWT is not application-level nor user-level, it's the widget toolkit standard framework, a bit like HTML language; it's not supposed to be a gallery of custom fonts/images/whatever; dealing with custom graphical resources is consumers' duty.
Comment 9 Christoph Laeubrich CLA 2020-11-13 10:54:27 EST
(In reply to Mickael Istria from comment #8)
> So you're suggesting to add some new Display.get*Font() ?

I would rather suggest the same pattern like with Display.getSystemCursors(int) /getSystemImage(int) / getSystemColor(int) that uses a SWT constant

> Have you seen JFaceResources various system fonts for several use-cases. 

Yes of course its always possible to add other libraries but it often makes sense to add those thing in the base.

> my concern is not about adding references to some
> system fonts in SWT, it's more about adding in SWT some non-system fonts.

A list of known default fonts for would perfectly solve this.

> This is not really how SWT is supposed to work

But how are fonts different from colors, cursors or even images where SWT provide different(logical)  choices across platforms.

> a bit like HTML

HTML (well at least CSS) defines (beside colors and cursors) also defines a set of 'safe' names: serif/sans-serif/monospace/cursive/fantasy not more or less I would suggest here.
Comment 10 Mickael Istria CLA 2020-11-13 11:01:12 EST
(In reply to Christoph Laeubrich from comment #9)
> (In reply to Mickael Istria from comment #8)
> > So you're suggesting to add some new Display.get*Font() ?
> 
> I would rather suggest the same pattern like with
> Display.getSystemCursors(int) /getSystemImage(int) / getSystemColor(int)
> that uses a SWT constant
> A list of known default fonts for would perfectly solve this.

Cool.

> > This is not really how SWT is supposed to work
> 
> But how are fonts different from colors, cursors or even images where SWT
> provide different(logical)  choices across platforms.

I agree, as long as the proposal is not to add extra fonts inside SWt.
 
> HTML (well at least CSS) defines (beside colors and cursors) also defines a
> set of 'safe' names: serif/sans-serif/monospace/cursive/fantasy not more or
> less I would suggest here.

Ok, good then.
I think this approach is valid. I retitled the issue accordingly.

I'm glad we managed to get rid of
> The proposal is that SWT at least includes a handful of free fonts (e.g. Apache License or SIL Open Font License) that could be reliable used across platforms.
which was my main point of disagreement.

Please keep in mind that -as usual with Platform- we'd ideally need a consumer in Platform (for example can be JFaceResources font definition) to consume those new API elements in order to accept them safely in SWT.
Also, we'll need this to be implemented for all 3 platforms in SWT before we add APIs. That's usually both a technical and organizational challenge!
Comment 11 Christoph Laeubrich CLA 2020-11-13 11:07:24 EST
(In reply to Mickael Istria from comment #10)
> I agree, as long as the proposal is not to add extra fonts inside SWt.
[...]
> I'm glad we managed to get rid of

Sorry for confusion, I just wanted to express that if a system does not provide a suitable font it could be "emulated" with a free-font as it is done for example with the DateWidget in GTK where no suitable system widget exits.
Comment 12 Paul Pazderski CLA 2020-11-13 11:13:08 EST
I had a similar problem when I made my SnippetExplorer in pure SWT and had the problem to get a platform independent monospace font.
I remember to google around and found others had similar problems before (most solutions used JFace) and searching again brought me to bug 48055. Have not read all of it but it might overlap with this bug.
Comment 13 Christoph Laeubrich CLA 2020-11-14 02:53:40 EST
(In reply to Paul Pazderski from comment #12)
> I had a similar problem when I made my SnippetExplorer in pure SWT and had
> the problem to get a platform independent monospace font.

Is SnippetExplorer part of SWT and could be used as a consumer as requested my Mickael?
Comment 14 Sravan Kumar Lakkimsetti CLA 2020-11-14 03:19:00 EST
(In reply to Christoph Laeubrich from comment #13)
> (In reply to Paul Pazderski from comment #12)
> > I had a similar problem when I made my SnippetExplorer in pure SWT and had
> > the problem to get a platform independent monospace font.
> 
> Is SnippetExplorer part of SWT and could be used as a consumer as requested
> my Mickael?

SnippetExplorer is part of SWT snippets. you can access it here. Its a pure SWT application.
Comment 15 Mickael Istria CLA 2020-11-14 03:55:56 EST
(In reply to Christoph Laeubrich from comment #13)
> Is SnippetExplorer part of SWT and could be used as a consumer as requested
> my Mickael?

It's borderline. For this change, I think the natural consumer would be JFaceResources, that would then reuse SWT system fonts to intialize eg the default dialog font and the text font.