3 Replies
      Latest reply on May 3, 2019 10:37 AM by KMT
      Dan.Korn Level 1 Level 1 (0 points)

        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

        • Re: How to get CTFontCreateWithQuickdrawInstance to work (macOS)?
          KMT Level 9 Level 9 (14,635 points)

               >...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.

            • Re: How to get CTFontCreateWithQuickdrawInstance to work (macOS)?
              Dan.Korn Level 1 Level 1 (0 points)

              Thanks for the reply.

               

              I understand that QuickDraw itself is deprecated.  Though it does still work in a 32-bit app on Mojave, even though it's completely impossible to use those old APIs in a 64-bit app built in Xcode 10.

              But as far as I can tell, there's nothing to indicate that the CTFontCreateWithQuickdrawInstance function is deprecated.  If it were, it would be annotated with __OSX_AVAILABLE_BUT_DEPRECATED, but it's not, and I get no warning when targeting 10.14.  So I think your speculation that it shouldn't work is unwarranted.

              Furthermore, to me, the link you quote reinforces my contention that this function should work as I expect.  I'm not trying to use QuickDraw, I'm trying to resolve an old QuickDraw-style font reference, and compatibility support between Core Text and that old name is exactly what I need.

               

              I don't have a system earlier than 10.9 to test with.  Older versions of our software ran on those older versions of OS X, and even back to the OS 9 / Classic days, but the whole point here is that I need a way to resolve the old font name retrieved with the older APIs to a font I can use with new APIs.

               

              My question still stands.

               

              Thanks,

              Dan