How to detect if a font has certain properties eg. Bold, Underline

Is there a way to detect if a font is capable of doing various graphics properties?
I have found by experience that just setting
Underline = True
isn’t good enough.
I am also Not asking if there is the Bold version of the font installed, that is unless that is the best way.
I didn’t mean to be snarky about the Bold, but rather just saying I don’t know enough about this.

All that depends on the platform as well. It would have been nice to post that detail, or to use the appropriate platform channel.

Under Windows, you get all the fonts installed and their stylistic variations names.

On Mac you get only the font family name, and need declares or a plugin to get the stylistic variations available.

I’m pretty sure you can get the font weight / traits via the MBS plugins otherwise it will be declaring into the operating system.

I posted in the general because I was asking for general.
I knew I missed something. First off - Any platform including Linux.
I need to warn the user that the selected is not usable because it doesn’t have XXX attribute.
Both Mac and PC don’t show all of the information needed as in whether there are more members in the family (as in Bold).

Here are 2: TimesNewRoman and BatangChe.
On Mac, Times has everything and BatangChe has only the main font and no Bold or Italic.
On Pc It is the exact opposite.
They also only show the base name in the font count list.

I found this post Listing font families and associated styles
but no declares mentioned. and when I looked at the MBS page, I couldn’t figure out how to use it even though I was on the documentation page.
Edit: I did a seard on Dakin’s book “I_Wish_Declare_r29-Sep2017” for relevant declares and couldn’t find anything.

I found an article on XDev that explains for Mac how to do it.

/www.xdevmag.com/browse/14.2/14203/
Fun with fonts
Not sure how to do it on PC

On PC you don’t need anything to see the styles. The regular listing will show them.

For Mac, ask Christian. He has the plugin for that. I used it a while ago, but I forgot the exact name since.

I will trust you for the Pc. I am not near one.
Thank you for the word style. I could figure out what to call it and any search is therefore impossible

This will not help, but I discovered lately on macOS, the Font Book application displays these features.

I confirm what was said here earlier for WIndows, but in one case, I get Ital as the style name (for Italic). Also, Windows 10 uses a space as the style delimiter (the space is also used in the Family Name…).

This is symptomatic on how some things (half baked features) are implemented in Xojo and the kind of usual unsatisfactory answers:

a. Silence,
b. There is a Plug-in for that,
c. It is in the Book Xyz by John Newbie.

I may forgot one or many other strange answer(s).

After a long and boring search (a quest may I say ?), I found:

fullName in Apple’s developper web site. Is it possible for someone to translate that in Xojo ?

Another useful link is CGFont .

TIA.

[quote=392480:@Arthur Gabhart]I posted in the general because I was asking for general.
I knew I missed something. First off - Any platform including Linux.
I need to warn the user that the selected is not usable because it doesn’t have XXX attribute.
Both Mac and PC don’t show all of the information needed as in whether there are more members in the family (as in Bold).

Here are 2: TimesNewRoman and BatangChe.
On Mac, Times has everything and BatangChe has only the main font and no Bold or Italic.
On Pc It is the exact opposite.
They also only show the base name in the font count list.

I found this post Listing font families and associated styles
but no declares mentioned. and when I looked at the MBS page, I couldn’t figure out how to use it even though I was on the documentation page.
Edit: I did a seard on Dakin’s book “I_Wish_Declare_r29-Sep2017” for relevant declares and couldn’t find anything.[/quote]

http://www.monkeybreadsoftware.net/class-windowsfontfamilymbs.shtml
http://www.monkeybreadsoftware.net/class-nsfontmanagermbs.shtml

NOTE. Bold fonts mean that they have a weight of 700. This is a list of standard weights:
100: Thin, Hairline, Ultra-light, Extra-light
200: Light
300: Book
400: Regular, Normal, Plain, Roman, Standard
500: Medium
600: Semi-bold, Demi-bold
700: Bold
800: Heavy, Black, Extra-bold
900: Ultra-black, Extra-black, Ultra-bold, Heavy-black, Fat, Poster

Thank you. For ease of getting what I need, MBS apparently does it.

Thanks Kevin for getting me the MBS names

[quote=392498:@Emile Schwarz]a. Silence,
b. There is a Plug-in for that,
c. It is in the Book Xyz by John Newbie.[/quote]
This is not necessarily Xojo’s fault; on the Mac, Apple like to change things regularly, I swear sometimes just for shits and giggles. So much has changed in the macOS (almost every single API has been changed) in the last 4 years, it’s hard for Xojo (and other x-plat languages) to keep. I suspect that a large chunk of Xojo’s time is spent on simply keeping their Mac side up to date, as opposed to supporting the other platforms or implementing new features.

btw, you have to give Xojo credit for keeping up, especially when you compare their tools to others and realize that Xojo is still the most fleshed out x-plat tool on the market.

In some recent discussions with long time Mac developers (at least 2 decades), Apple’s rate of changing (I’d like to say improvement) is making it harder for even those that Xcode. I read an article recently about how people are already leaving Swift, it’s limitations and being in a constant state of flux appear to be among the top reasons, along with incompatibility with Android.

I use macosLib’s functions. For instance, I use the snippet below to know if a given font has fixedPitch:

dim ns as new Cocoa.NSFontManager dim s() as String = ns.AvailableFontFamilies dim nsF as Cocoa.NSFont for i as Integer = 0 to UBound(s) nsF = ns.SharedManager.GetFont(s(i)) if nsf.IsFixedPitch then //etc.

Another function useful to me is to get a list of fonts supporting Indian (or Semitic etc.) glyphs.

Here is macOS code to get a list of Font families.

[code]Public Function fontFamilies() as string()
#if TargetMacOS then
declare function NSClassFromString lib “Cocoa” ( className as CFStringRef ) as integer
declare function sharedFontManager lib “Cocoa” selector “sharedFontManager” ( classRef as integer ) as integer
declare function availableFonts lib “Cocoa” selector “availableFontFamilies” ( NSFontManager as integer ) as integer
declare function count lib “Cocoa” selector “count” ( NSArray as integer ) as integer
declare function objectAtIndex lib “Cocoa” selector “objectAtIndex:” ( NSArray as integer, index as integer ) as CFStringRef

Dim fontArray as integer = availableFonts( sharedFontManager( NSClassFromString( "NSFontManager" ) ) )
Dim fCount as integer = count( fontArray )-1
Dim rvalue( -1 ) as string

for fPos as integer = 0 to fCount
  rvalue.append objectAtIndex( fontArray, fPos )
next

return rvalue

#endif
End Function
[/code]

Below is macOS code to get the variants from a font family, it returns a pair for each variant. The left side is the PostScript name (used for setting the font) and the right is the “Display Only” name of the variation.

[code]Public Function fontVariations(inFontName as string) as pair()
#if TargetCocoa then
declare function NSClassFromString lib “Cocoa” ( className as CFStringRef ) as integer
declare function sharedFontManager lib “Cocoa” selector “sharedFontManager” ( classRef as integer ) as integer
declare function availableFonts lib “Cocoa” selector “availableMembersOfFontFamily:” ( NSFontManager as integer, fontFamily as CFStringRef ) as integer
declare function count lib “Cocoa” selector “count” ( NSArray as integer ) as integer
declare function objectAtIndex lib “Cocoa” selector “objectAtIndex:” ( NSArray as integer, index as integer ) as integer
declare function stringAtIndex lib “Cocoa” selector “objectAtIndex:” ( NSArray as integer, index as integer ) as CFStringRef

Dim fontArray as integer = availableFonts( sharedFontManager( NSClassFromString( "NSFontManager" ) ), inFontName )
Dim fCount as integer = count( fontArray )-1
Dim rvalue() as pair
Dim cFont as integer

for fPos as integer = 0 to fCount
  cFont = objectAtIndex( fontArray, fPos )
  rvalue.Append stringAtIndex( cFont, 0 ) : stringAtIndex( cFont, 1 )
next

return rvalue

#endif
End Function
[/code]

And to get the family name from a postscript font name…

[code]Public Function fontFamilyName(inFontName as string) as string
#if TargetMacOS then
declare function NSClassFromString lib “Cocoa” ( className as CFStringRef ) as integer
declare Function NSFontWithName lib “Cocoa” selector “fontWithName:size:” (NSFontClass as integer, name as CFStringRef, size as CGFloat) as integer
declare Function NSFontFamilyName lib “Cocoa” selector “familyName” (NSFontInstance as integer) as CFStringRef

return NSFontFamilyName( NSFontWithName( NSClassFromString( "NSFont" ), inFontName, 13 ) )

#endif
End Function
[/code]

So when you’re building a font selector on the macOS, you need two controls, one for choosing the family and one for choosing the variation. You use the postscript name from the variation in your code for drawing and printing, but you need the regular name for display, this function will help you find the family name, to which you can use to then set your font family selector correctly.

“Gill Sans SemiBold Italic”, postscript name is “GillSans-SemiBoldItalic”.

There is yet another difference between Mac and Windows.

On Mac with Cocoa, Bold, Italic and BoldItalic must have the proper font, or the style is simply not available. It was not always the case. Carbon used to synthesize these styles by playing on weight and slant.

Windows still synthesizes Bold, Italic and BoldItalic when the specific stylistic variation font is not present. So in practice, these attributes are always available to the user.

A synthetic bold is relatively easy to obtain by playing on the font weight. However, synthetic italics are not typographically correct. They should be called oblique, since true italic have a different form for letters such as a, f for instance, which in italic do a, f.

I get an eye on the old Inside Macintosh I to VI…, so, things have really changed.

In these times, Fonts are called by ID (excepted in PostScript, and some years later, in TrueType Fonts).

Thank you for the shared code.

Sam:

Thanks for sharing the code (far complex than what I expected)…

After removing a stupid error (of mine), it works fine !

Sad to disagree Michel. I’ve had the opposite experience especially on Windows. It might be the font I’m choosing but no it doesn’t always present Bold.

There is always an exception to the rule. I tried to help, and you have several options available above. That should be enough to get you going.

Might not want to argue with Michel about fonts… since he is probably the most knowledgable about all aspects of that subject