How to get CTFontCreateWithQuickdrawInstance to work (macOS)?

Hello,


We have a macOS app (mostly C++, built in Xcode 10) which lets users select fonts and store references to them, by name, in their documents. We currently use Core Text functions to iterate and locate fonts, which mostly works fine. However, some older documents, from older versions of our app, have QuickDraw font names stored in them. I'm trying to convert these QuickDraw names to "real" font names; or more specifically, to idenfity an installed CTFontRef font from a QuickDraw name.


I see the function CTFontCreateWithQuickdrawInstance, which seems to be exactly what I need, but I can't seem to get it to return anything but NULL/nil, at least not on Mojave. I've done a lot of searching, but have not been able to find any usage examples.


So my question is: Assuming I'm starting out with a std::string in Mac Roman encoding, which contains a valid Quick Draw font name, and that I have installed on my system the same font from which the QuickDraw name was retrieved, in an older version of our app (probably via an ancient call like FMGetFontFamilyName), how can I call CTFontCreateWithQuickdrawInstance to get that font (i.e. to return something other than NULL)?


Here's what I have so far:


std::string QuickDrawName = "Charcoal"; // actually gotten from a CFStringRef in kCFStringEncodingMacRoman

unsigned char pascalName[256] = "";

*pascalName = (unsigned char)QuickDrawName.length();

strcpy((char*)pascalName + 1, QuickDrawName.c_str());

CTFontRef foundFontRef = CTFontCreateWithQuickdrawInstance(pascalName, 0, 0, 0); // always returns NULL


What am I doing wrong?


Thanks,

Dan

Replies

>...at least not on Mojave.


I don't think you can get there from here...I'd speculate it's working as expected.


From the linked docs:


"This function is provided for compatibility support between Core Text and clients needing to support QuickDraw-style font references. QuickDraw is a deprecated technology in macOS 10.4 and later."


I'd suggest testing on macOS <10.4 to see if it's ok there, and also file a bug and see what comes back.