Logo Questions Linux Laravel Mysql Ubuntu Git Menu
 

gdi+ PrivateFontCollection AddFontFile always returns status with "InvalidParameter"

every one, I'm using GDI+ to rendering text with my own typeface, but I always get a error status InvalidParameter when using member function AddFontFile(WCHAR*) of PrivateFontCollection to load my font file, here is my code:

PrivateFontCollection m_font_collection;
... // initialize window
GdiplusStartup(&gdi_token, &gdi_startup_input, NULL);
// here the result always is 2 (that specified as "InvalidParameter")
Status result = m_font_collection.AddFontFile(L"myfont.ttf");

I can't find any explanation why this error occur, does anyone knows how to fix that problem? Thanks! ps: forgive my poor English... :)


I've solved this problem, this is a stupid question, so, forgive me... please check my answer below
My answer
like image 364
Artiano Avatar asked Sep 15 '25 06:09

Artiano


1 Answers

OK, I've solved this problem... how stupid I am... the question is quite stupid, I defined the m_font_collection too early! It should be defined after the function GdiplusStartup has been called, only after the GDI+ has been initialized the PrivateFontCollection can load your own font files... Hope can help somebody

like image 134
Artiano Avatar answered Sep 17 '25 19:09

Artiano