1 Reply
      Latest reply on Jan 24, 2020 4:45 PM by Renaun
      PanyZ Level 1 Level 1 (0 points)

        My Function:

            We have a Wordart Template, when app launched, we will download the template and draw the wordart with the Default Font File in the template resouce. But the Default Font File just contain the Default Word. When user input some word, we will request the service to get a new font ttf file, which Just contain the words that   the user input (For Less Network Traffic And Quick Rsponse).Then i will draw the wordart with the new font and the new words that the user just input.  The same template will have the same font, so the new ttf file we got, will have the same PostScriptName.

        My Question:

            When the app launched, i regitster the Default Font File with the API CTFontManagerRegisterFontsForURL and draw the default words.It work perfectly. After the user input the other words, i request for a new font file that just contain the words that user just input. This two font file have the same font and the same post script name but contain different words (just several useful words). I noticed that the Apple Document said " Any attempt to register a font that is either already registered or contains the same Postscript of an already registered font will fail ". So, firstly, i call the API CTFontManagerUnregisterFontsForURL to unregister the old font that i have registed (i have record the old font file url). After that, i call the API  CTFontManagerRegisterFontsForURL to regist the new font file i just download. Then i attempt to draw some words with the font, but the font not work.

             I have try CTFontManagerRegisterGraphicsFont and main thread too, but also not work. So, what should i do to make it work?

        • Re: CTFontManagerRegisterFontsForURL Not Work
          Renaun Level 1 Level 1 (10 points)

          I found that if you ever use UIFont(name:) with the font that you loaded dynamically. that the CTFontManagerUnregisterFontsForURL doesn't work as stated above.

           

          So the workaround is to use

          let desc = UIFontDescriptor(name: <name>, size: <size>)

          let font = UIFont(descriptor: desc, size: <size>)

           

          If at any time you use UIFont(name: <name>) the unregister doesn't really unregister it.

           

          Not I found this to be the case with CTFontManager Register/Unregstier FontsForURL api and GraphicsFont apis.