How do you deal with Font Families?

To make the things clear, here’s an example for the American Typewriter Font family:

American Typewriter
American Typewriter Light
American Typewriter Semibold
American Typewriter Bold
American Typewriter Condensed
American Typewriter Condensed Light
American Typewriter Condensed Bold

Here start the troubles with Xojo / macOS.

There is no more (since years) Styles (Bold, Italic, etc.) in macOS.
You directly use the Family Member you want (American Typewriter Bold for example).

Also, try with XPress to apply the Bold Style to a Text when the set Font is (for example) American Typewriter Bold. At print time (or pdf generation time), you will get a warning and the application stop until you understand and correct your error.

I read the documlentation (Styled Text) and it says too use the styles (.SelectedBold for example).

This needs some work because of all I wrote above and…:

When you install a Font Menu, you will get all Family Member as individual entries (real the names of the individual entries of the American Typewriter Font far above.

Apple’s TextEdit application shows:
image

And that is clear: Family Name (Famille) on the left and Family Members (Police de caractères [!]) on the right.
From my French macOS (Big Sur).

Excepted if I overlook something, Xojo does not know - yet - the Family Name / Family Members concept.

What I actually do is to display a window with ONE ListBox and:


Sub Open() Handles Open
  Dim i As Integer
  Dim Font_Count As Integer = FontCount - 1
  
  For i = 0 To Font_Count
    LB_Fonts.AddRow(Font(i))
  Next
End Sub

and I get the list of all Family Members in the ListBox and that gave me 573 entries (default entries; remove 1 because I added 1 Font to my System, minutes ago).
That is… who (a) can deal with so many Font entries ?

(a) what user can deal…

Fortunately, I do not added a Font Menu !

The solution Apple used for TextEdit is displayed above: a list of the Family Names and a second list of the Family Members. How can we do that in pure (no plug-in) Xojo ?

More information available TrueType-Reference-Manual (Chapter 6: Name).

Hi @Emile_Schwarz

I think you can find some hints about “how-to” do it in the macOSSystemFonts Example Project included in the Example Projects > Platform-Specific-macOS.

Thank you Javier.

I was in a hurry to go back home and so I forgot to check. But I recall the idea comes to mind - but go away faster and so I do.

Your screen shot is for a “word processor”, not for a simple font chooser for ListBox Font setter :grinning:

I will explorate the example if I can get time today.

In the mean time, I was thiunking at a simple PopupMenu with some predefined entries (like less than 20 Fonts, including some Google Fonts).

Hi Émile,

In order to properly use the current fonts, you’d need to use the NSFont class. It should be available in the open-source macoslib project (which requires no plugin), but I guess that is not what you want and you want to deal with the Carbon version of font-handling (don’t we all?).

I am not sure that “There is no more Styles in macOS” is true. I suspect (but it needs to be checked) that the Carbon font manager and/or CoreText can handle font families, though differently.

I have written the declares to get all Font Families, or Font Families that are appropriate for the user based on locale. There’s also the declares needed to display the Font Families in a WYSIWYG popup menu.

Screen Shot 2021-12-22 at 10.44.15 AM

It’s part of the Ohanaware App Kit App Kit 2021 - Building Better Mac Applications You can download the demo application from the page and click on the “Text Areas” item in the sidebar.

In some old macOS, the Style is applied to the standard font.

Actually (and since some times), you have to have the Standard font (Times) and members of the family (say TimesBold, TimesItalic, etc. files). Then the OS allow you to choose the Font you need: TimesBold.

No more check box to set Bold, Iatlic, Underline, Shadow (when available).

I was awaiting a Class Name for Font Family and FontMember to look for Members of the family in API2.

This will come in API3, next year.

Nice example. But it does not fit in:

Easy to Start, Fast to Develop

My article in xDev 14.2 shows you exactly how to do this for MacOS (Article 14203: : Fun with Fonts).

This is a screenshot of the included demo:

I’m using dual listboxes for the demo, but you could easily change those to a menu and submenu.

The article itself is behind a paywall, but if you just want to explore the code to do it, you can download the demo code for the article at the above URL for free. It is a few years old, but still works fine on latest Xojo and M1 Mac running Monterey.

1 Like

Everybody tries to leave ancient things behind and move ahead, yet sometime innovations may lack something ancient procedures allowed us to do.
I’m referring to the ability of CoreText (MacOSLib) to let me know the languages supported by each font, something not possible nowadays (Apple Docs don’t mention it anymore, or at least I could not find it)…
And since AppStore does not complain about CoreText, I’m still using it.

IIRC, at least for TrueType And TrueType Collection fonts, If you have access to the actual font files, it is not that difficult to pull that info (as well as family and face) out of the font file itself with Xojo code.

The file formats are published so, it’s just a matter of parsing the files as the files are text.

-karen

As I mentioned above there is code in the Ohanaware App Kit that filters font’s via language.

What I wanted to say is that you can select the best font with the NSFont object as you can select a font family and its properties (italic, boldness…)