Skip to main content
Inspiring
June 26, 2012
Question

Loading font into memory.

  • June 26, 2012
  • 1 reply
  • 1685 views

Hi all,

I have a scenario where i have to load the font(ttf files) into the memory  and apply it to all the selected textframe in the active document. So for loading the font i am using 'AddFontResourceEx()' api.

The problem is this, when i used this api it will not load the font at the same time, it will take some time to load the font. But the plugin will try to apply that font to the text frame. Sometimes font will apply somtimes not.

I am unable to understand its behaviour. Can someone tell me why its happening? Also is there any api through which we can refresh font list?

Thanks in advance....

This topic has been closed for replies.

1 reply

A. Patterson
Inspiring
June 26, 2012

Interesting. I have a similar problem I solved using AddFontResourceEx(), but it was sort of the reverse. I have a library using FreeType that wouldn't 'see' fonts Adobe was loading (because they were coming from their own folders and not the Windows Font folder).

You have the reverse problem, sort of. You also need to load additional fonts from (presumably) odd locations, but you want Illustrator to see the result. I'm not sure what to do for your case, though perhaps its a matter of timing? Are you seeing this "sometimes it works, sometimes it doesn't" on the same machine, or different ones? If the latter, it could just be the plugin load order. If it's the same machine, that's more troubling.

Either way, your best bet is to find as early a place as possible to do the font loading. Where are you doing it now?

Inspiring
June 27, 2012

Hi Patterson,

Thanks for the reply. Let me explain more on my problem.

I have a flex panel which populate the list of fonts. When I clicked on any font from the list, plugin loads that font into memory (this font will appear in the font list of illustrator).

I am using AddFontResourceEx() and SendNotifyMessage() functions.

After this, I dispatch a csxs event to the flex panel on the basis of error code of mentioned functions.

Flex listen the event and apply that font to the selected textframe in the document.

But the problem is, even getting the expected return values from above function, font is not being enumerated instantly in Illustrator font list.

It took time about 7-8 seconds or even more to being enumerated.

Could you please tell how I can overcome from this problem?

All my need is that enumerating font asap.

Here is the code snipped..

////Start


     long count = 0;

     sAIFont->CountFonts(&count);           //Here value of count is 187

     int err = 0;

     err = AddFontResourceEx( fontPath, // font file name

                                             FR_PRIVATE, // font characteristics

                                             NULL

                                                                                                                                     );

       //value of err is 1 as I am loading one font..

    

     if(err==0)

     {

                         return false;

     }

 

     // send font change notification

     bool isNotified = SendNotifyMessage(HWND_BROADCAST, WM_FONTCHANGE, 0, 0);

     //value returned by SendNotifyMessage is true.

    

     sAIFont->CountFonts(&count);           //Still the value of count is 187 .

////End

Thanks,


A. Patterson
Inspiring
June 27, 2012

Is there any reason you can't pre-load the fonts before they're clicked on in the panel? Or is that the point of the plugin, to load additional fonts?

I don't know what causes the delay, or if there's a way to 'kick' it to make it update faster. The best bet is to have done it long before its needed so they're already there, but if that's the point of the panel, I guess we'll need to see if we can find something else.