I am drawing some text with Gdi+ and I’m trying to make sure the Font I create actually exists. I noticed that it was working no matter what font I specified. I have the following code:
Font font(TEXT("SomeGibberishFOEIHSFUE"), 12, 0, UnitPoint);
if (!font.IsAvailable())
exit(0);
// draw text
I have no font installed on my system called SomeGibberishFOEIHSFUE, but IsAvailable returns TRUE and the program runs and draws the text with a font that looks like Arial instead of exiting. Why is this?
If I am using IsAvailable wrong, what function should I use to tell whether the creation of a Font succeeded or not? I have also tried GetLastStatus which returns Ok.
That’s the Windows font mapper at work, it will always find a substitute font if it cannot supply the requested one. Falling back to the default GUI font if necessary. You could use the FontFamily class instead. The .NET version of it (looks like you’re using it) will throw an ArgumentException when you use its constructor and pass a non-existing font. The native GDI+ version of it has an IsAvailable() method. Yes, kinda screwy behavior but that’s not unusual in GDI+.