Detecting the actual system font on OSX

[quote=212703:@Norman Palardy]Not using system means on 10.7 10.8 and 10.9 you look one way, 10.10 another, and in 10.11 another
If they change the system font every release you’d only ever look right on one
Thats the whole point of “System”[/quote]

What do you mean, Norman ? If you use a custom font setting, your font will always look the same.

Sure
It just wont look like what the HIG says it should in terms of fonts

[quote=212761:@Norman Palardy]Sure
It just wont look like what the HIG says it should in terms of fonts[/quote]

Indeed.

Mind you, using “System” did cause trouble on Japanese systems a few years back, and that’s why I had to find work-arounds for that, as some of my Japanese customers kept asking me. I’ll have to see if that’s gotten resolved by now.

Also, using System had its problems with 10.10 until recently as well, IIRC.

But if all is will now in Xojo, then Eli’s way makes most sense and I’ll see if that’ll actually work perfectly now on all OS X versions and locales. It certainly wasn’t always so.

[quote=212764:@Thomas Tempelmann]Mind you, using “System” did cause trouble on Japanese systems a few years back, and that’s why I had to find work-arounds for that, as some of my Japanese customers kept asking me. I’ll have to see if that’s gotten resolved by now.

Also, using System had its problems with 10.10 until recently as well, IIRC.

But if all is will now in Xojo, then Eli’s way makes most sense and I’ll see if that’ll actually work perfectly now on all OS X versions and locales. It certainly wasn’t always so.[/quote]

The solution seems obvious : apply the workaround only in system versions where necessary. There are always edge cases. Japanese does seem like one. It probably requires larger font size as well, given the complexity of Kanji script.

Michel, what shall I take from your answer? You’re basically telling me: Do what’s necessary.

I started this thread because I’ve been having troubles with RS’ and Xojo’s font particularities for years. I’ve been constantly trying to find work-around for issues that were clearly not obvious. If I could just use Cocoa’s NSFont APIs, it would have been all a non-issue. But I can’t, and so I kept running into trouble and ask for help here. Telling me that I need to find my own work-arounds and implement them on my own is not what I need to hear from others - I can as much figure out myself, and have so far, thank you very much :wink:

You mean this report <https://xojo.com/issue/11322> which was for Carbon only ?
It may very well still apply for Carbon apps but we don’t ship a Carbon framework in current versions.
For older systems you might use the older Font Manager routines directly since you know they’re running on systems with Carbon API’s
Basically what Xojo presents is the Font Family name - not the specific variations (Ie/ Lucida Grande Bold Italic)
Carbon definitely made that more invisible that Cocoa does and would synthesize variations on the fly if the font did not have them
Unfortunately Cocoa doesn’t

What do you mean by that? Per HIG I’d have to use [NSFont systemFontOfSize:] and similar functions. But I can’t because those fonts cannot be use with Xojo’s font system. Or do you mean the Xojo HIG?

Ah, thanks for looking that up. That solves that issue, at least. Having dealt with Font issues repeatedly over the years I’ve lost track of what got fixed and what not. Even this bug report was never fixed, so I never checked it off on my end.

I’m not entirely sure what you mean by “cannot be used with Xojo’s font system”. The Xojo “System” font just ends up resolving to a call to that same NSFont method…

System 0 is that size - really
Thats the point of that font & size

Is that exact? I think that when I looked up some font or family names from NSFont lately, I got names that I could not directly match up to Xojo’s Font names. May be I just looked at the wrong values.

Ah, but that’s an implementation detail that you’ve not so far revealed. I had asked about these relationships earlier in this thread and got no responses.

But yes, it makes sense that the “System” font in Xojo Controls translates to [NSFont systemFontOfSize:Control.FontSize].

But my question here was the other way around: I asked how I can list all fonts for the user to choose from and then tell which of these fonts represents the System font. This used to work somewhat but doesn’t work in 10.11 any more (actually, even TextEdit doesn’t list “San Francicso” nor does it list “system”, so one cannot even seem to write a rich text using the system font in 10.11 any more, it seems).

So now I have to give up showing the actual font name and add a pseudo “System” font name to the Fonts list, just like Eli suggested. That works, but wasn’t obvious, because all of the old Font examples never did that, either. It takes a while to realize that something that used to work not doesn’t any more, and neither Norman nor Joe seemed to be aware of this change. In fact, I’d argue that the Font list should include “System” at least on 10.11 and later now, so that it doesn’t miss the system font, because I’m sure I am not the only one who expects that the Font() array contains all available fonts, including the one used by the system.

You misunderstood my point. I am not telling you “just deal with it”. I am trying to suggest a roadmap. I remember other threads where you wanted to know which font was used by system, but did not realize that was the issue.

If the system font does not display correctly under some versions of the system, the obvious route is to find for each version of the system an equivalent font that works for your app. Obviously, the “Official” Helvetica Neue does not support Japanese, according to Font Book. Chances are the hidden one does not either. Neither Helvetica nor Lucida Grande or Arial do support Japanese.

But right next there is Higanino Kaku Gothic Pro which seems like a possible sans serif alternative that does support Japanese.

I would start by making sure the font I pick is able to display the characters needed, then I simply would use that one whenever I know the system font cannot. It should even be possible to detect Japanese whenever the Text property becomes UTF-16.

Michel, maybe I expressed the Japanese font issue not well, but as Norman already pointed out, it was a Carbon-related issue that’s not occuring in Cocoa builds any more, supposedly. Also, it was not about ME picking a font for Japanese, but it was that the System font that RS used was not displaying right, with Roman letters. So, whatever you assumed, you were totally off-track :slight_smile:

Gets the font name by index from
[[NSFontManager sharedFontManager] availableFontFamilies];
so … its as “exact” as I can tell

Didn’t read the original post back in April
Can’t read everything

But now that I did - since you commented on that - there’s no need to translate - the names we have are the names NSFont gives us (see above)

[quote=212778:@Thomas Tempelmann]
But yes, it makes sense that the “System” font in Xojo Controls translates to [NSFont systemFontOfSize:Control.FontSize].

But my question here was the other way around: I asked how I can list all fonts for the user to choose from and then tell which of these fonts represents the System font. This used to work somewhat but doesn’t work in 10.11 any more (actually, even TextEdit doesn’t list “San Francicso” nor does it list “system”, so one cannot even seem to write a rich text using the system font in 10.11 any more, it seems).

So now I have to give up showing the actual font name and add a pseudo “System” font name to the Fonts list, just like Eli suggested. That works, but wasn’t obvious, because all of the old Font examples never did that, either. It takes a while to realize that something that used to work not doesn’t any more, and neither Norman nor Joe seemed to be aware of this change. In fact, I’d argue that the Font list should include “System” at least on 10.11 and later now, so that it doesn’t miss the system font, because I’m sure I am not the only one who expects that the Font() array contains all available fonts, including the one used by the system.[/quote]

Previously how would the user of your software know which one was “The system font” ?
The name “System” has always been a special name so adding it to the list of available fonts and having a user select that special name would always have returned “the system font” regardless of what it was
Thats about all we do for the font selector in the IDE - start with “System” and “SmallSystem” then add the rest of the list
So no I didn’t notice because - well … we already make it easy for you to select one of those two in the IDE without caring what the specific name really is

You are right. Difficult to guess what you have really been after for 6 months… Plenty of people have tried to assist, obviously in vain… I am just one of them, and will now stop participating in the charade. Sorry.

Good luck. Have fun with your font issues :wink:

I’m also wanting to resolve what the “System” font is and get its actual name. Beyond the “you have to add the “system” entry” answer, it clearly should be doable to get the system’s font name.

Adding a “System” entry in a Fonts menu isn’t always ideal anyway. By making a basic text editor, for instance, there’s a default font applied to a TextArea control (“System”, if you don’t change it). Now, an average user isn’t going to know what the “System” font is; it’s an OS concept.

Any way to map the system font to its real value so that the corresponding menu item in a fonts menu can be checked?

Chances are it would be possible to get the actual font name through a declare.
It seems to be here

var font: NSFont? The font of all the receiver’s text.

https://developer.apple.com/documentation/appkit/nstext

But that is far from being as easy as Xojo. If you are willing to learn, though, declares are a great way to get under the hood and do things impossible otherwise.

But unless you have an absolute necessity to know the exact font name, and somehow reinvent the wheel, stick to “System” as a way to conform to Apple’s guidelines. Each maxOS version has it’s own set of fonts, in particular for menus.

You don’t have to present the user with “System”, nor do you have to set the default font to “System”. You can set the default font to anything you want, really.