> I am creating CGFonts using CGFontCreateWithPlatformFont for all
> our text drawing.
> Initially, I recreate the CGFont each time to draw a piece of text.
> This turned out to be bad at least for the PDF conversion done by
> Quartz (as accessible via the print dialog): the resulting PDFs
> contain a separate embedded font subset for each time
> CGFontCreateWithPlatformFont is called. This can result in
> ridiculously large and slow PDFs.
> Now I am caching the CGFonts as I create them, using a mapping
> against ATSFontRefs. Works beautifully, but do I need to be
> concerned about resource use? Like restricting the number of fonts
> in the cache to some upper number? Or is it best (certainly it is
> easiest) just to keep any CGFont around once it is created until
> the program exists?
> Note: I have a notification for font list changes installed with
> ATSFontNotificationSubscribe and handle this correctly, dropping
> fonts from the cache which are no longer available.
I think your approach is exactly the right thing to do. You don't
really need to worry about resource use — CGFonts are themselves
lightweight, and we manage the resources they use internally to keep
them low without sacrificing performance. I'd create a CGFont once
and hang on to it until the program exits.