How to use italic LucidaGrande font for a Cocoa App - cocoa

Recently I'm working on Carbon to Cocoa transition for my App.
The font my App used is "LucidaGrande", I got it from this method:
myUIFont = [NSFont systemFontOfSize: [NSFont systemFontSize]];
Sometimes my app want to show italic style font in its UI, so I call this:
myUIFont = [[NSFontManager sharedFontManager] convertFont:myUIFont toHaveTrait:NSItalicFontMask];
But this conversion failed. I found that it's because that there is no italic style for "LucidaGrande" font. I can verify this by calling:
NSArray* availableNames = [[NSFontManager sharedFontManager] availableFontNamesWithTraits:NSItalicFontMask];
There's no "LucidaGrande" in availableNames. It is very curious because I can use italic "LucidaGrande" font in my Carbon App. Is there any solution to get a italic "LucidaGrande" font for Cocoa App? Or how can I get a similar italic one?
Thanks very much!

There is no italic version of Lucida Grande per se. Carbon text APIs fake it by slanting the regular version. Lucida Sans and Lucida Sans Unicode (regular) are identical in their Latin subsets, and have italic versions, but do not ship with the OS.

Related

GDI+ font fallback not working for emojis

In our app we draw text using GDI+ (Graphics::DrawString()). We're using a clone of a StringFormat::GenericTypographic() string format with StringFormatFlagsMeasureTrailingSpaces as the only additional flag. StringFormatFlagsNoFontFallback is definitely not set in the format.
This all works great, except for emojis when the selected font doesn't include the emoji glyph. My expectation is that GDI+ will fall back on a font that does have this glyph (e.g. Segoe UI Emoji), however this doesn't seem to be working. If we manually switch to Segoe UI Emoji then all the emojis render correctly.
This is on Windows 10.

Fixed spacing numbers in AppKit

I have an app with a timer. This timer is centered in the view. When macOS's default font was Helvetica Neue, this worked fine. It seems that the font's numbers are spaced evenly, so when the timer is running, everything stays in place.
Now with San Francisco as the default font, this is broken. Ever number seems to have a different width, causing the timer to flux in size continuously while running. Hard coding the font to Helvetica Neue fixes the issue, but I'd like to use the font that's default to the OS.
Is there some kind of hint I can set with NSTextField that would render the default system font with fixed width numbers like before? I seem to remember this being available, but I cannot find it. I don't want to use a fixed-width font, as it breaks the aesthetic. It seems like the stop watch app on iOS is doing this somehow.
Use this class method of NSFont
Swift
class func monospacedDigitSystemFont(ofSize fontSize: CGFloat, weight: CGFloat) -> NSFont
Objective-C
+ (NSFont *)monospacedDigitSystemFontOfSize:(CGFloat)fontSize weight:(CGFloat)weight;
Available macOS 10.11+

Inserting regular space between characters in Cocoa text drawing

Which is the font style used in NSFont to create alignment/space between characters?
I tried doing with this code, but not able to align the characters.
NSFont *font=[NSFont fontWithName:#"TimesNewRomanPSMT" size:15.0 ];
[textview setFont: font];
Please specify the font style name which suits the above mentioned problem.
What about trying fontspace and pick the font you want.
And if you are looking to adjust the space between characters in a UILabel you can use:
#property(nonatomic) BOOL adjustsLetterSpacingToFitWidth;
Edit: Above code for ios.

Qt font families and styles on Mac OS X

I have a GUI application based on Qt (PyQt) running on Mac OS X (and other platforms). It allows the user to select fonts and has check boxes for bold and italic options.
On updating to the new Cocoa-based Qt, a user found the QFontComboBox no longer displays the different font styles (e.g. condensed, oblique, bold...) and just displays the font family name. Under Carbon it showed both. The user also cannot enter the name with the style in the combo box. Furthermore, I cannot construct the same font passing the name into the QFont constructor.
QFont doesn't seem to know anything about these missing styles. Confusingly it has another different notion of style. It looks like QFontDatabase has the information about the style variants. It can also construct fonts based on a family, style and point size.
So, are the following changes the correct approach?
Rather than have bold and italic buttons, have a combobox filled with the styles from QFontDatabase for the font selected in the QFontComboBox.
Store the style in saved documents (as text), rather than bold or italic.
So
Can I rely on the style being the same on systems with different languages? Can I include it in saved documents?
Is a style "Bold Italic" as robust a way of making a QFont with the desired properties, than setting the bold and italic properties of that QFont?
If I want to retain bold and italic checkboxes, how can I convert these attributes into the correct style? Can I just guess "Bold", "Italic" or "Bold Italic"?

How do I create an NSFont that is both Bold and Italic?

This is a beginner's question about font handling in Cocoa. I have a font family, e.g. Verdana, that has the following typefaces: Regular, Bold, Italic, and Bold Italic. I know those typefaces exist since they are available in the Fonts panel.
This works:
NSFont *regular = [NSFont fontWithName:#"Verdana" size:75];
NSFont *bold = [NSFont fontWithName:#"Verdana-Bold" size:75];
NSFont *italic = [NSFont fontWithName:#"Verdana-Italic" size:75];
This does not work:
NSFont *boldItalic = [NSFont fontWithName:#"Verdana-Bold Italic" size:75];
What is the simplest way to get the Bold Italic version of a given font family?
This works:
NSFontManager *fontManager = [NSFontManager sharedFontManager];
NSFont *boldItalic = [fontManager fontWithFamily:#"Verdana"
traits:NSBoldFontMask|NSItalicFontMask
weight:0
size:75];
See NSFontManager and -convertFont:toHaveTrait:
For more detailed information, I would suggest reading the Font Handling Guide and specifically the section titled Converting Fonts Manually.
Note, that the font you are using needs to have some version of it with the traits you are asking for, otherwise, you will get back a font, but without the requested trait.
If, eventually, you are seeking to add an italic trait to a font that doesn't have one, check out:
How do I get Lucida Grande italic into my application?
Verdana-BoldItalic.
(The actual name of the bold-italic variant of the font depends on the family, and some font doesn't have bold-italic, Use a NSFontDescriptor with -fontDescriptorWithSymbolicTraits: to get the exact bold italic font.)

Resources