hundsmiachn
Programmer
Hi
I am using VS 2012 and making a app which displays several texts via GDI+ DrawText. When using ARIAL font, text looks okay, no problems.
But I wanted to use my own ttf fonts for the texts. So I added the ttf files to the resources and made an BINARY Object out of this ttf files.
When I use one font only all text are displayed ok. But when I use different fonts in the same WM_PAINT loop, the text looks completely garbage, strange letters are displayed.
Here is my code for displaying the text, it is called in my own method (DrawText) and is called for every text element, so local variables are destroyed.
Does the LoadResource/LockResource need a unlock or something???? I think it allocates some wrong memory when loading a second font..??
Here are 3 examples images:
The first uses only one font resource (IDR_FNT_ROBOTO_COND_BOLD):
The second uses a second font resource, but only that one (IDR_FNT_BEBASNEUE_REG):
And here the third example, where I use both fonts:
As you can see, every font alone works fine, but when I use more than one, the output text is garbage.
thanks for any help.
regards
Erich
I am using VS 2012 and making a app which displays several texts via GDI+ DrawText. When using ARIAL font, text looks okay, no problems.
But I wanted to use my own ttf fonts for the texts. So I added the ttf files to the resources and made an BINARY Object out of this ttf files.
When I use one font only all text are displayed ok. But when I use different fonts in the same WM_PAINT loop, the text looks completely garbage, strange letters are displayed.
Here is my code for displaying the text, it is called in my own method (DrawText) and is called for every text element, so local variables are destroyed.
Does the LoadResource/LockResource need a unlock or something???? I think it allocates some wrong memory when loading a second font..??
Code:
Gdiplus::PrivateFontCollection fntcol;
HINSTANCE hResInstance = (HINSTANCE)GetModuleHandle(NULL);
HRSRC res = ::FindResource(hResInstance, MAKEINTRESOURCE(font.id), L"BINARY");
if (res) {
HGLOBAL mem = ::LoadResource(hResInstance, res);
void *data = ::LockResource(mem);
size_t len = ::SizeofResource(hResInstance, res);
Gdiplus::Status nResults = fntcol.AddMemoryFont(data,len);
}
FontFamily fontFamily;
int nNumFound=0;
Gdiplus::Status nResults = fntcol.GetFamilies(1,&fontFamily, &nNumFound);
Gdiplus::Font fnt(&fontFamily,(float)font.size,FontStyleRegular,UnitPixel);
LinearGradientBrush brush(Rect(x,y, 1000, (int)fnt.GetHeight(&rgraphics)), col1, col2, LinearGradientModeVertical);
rgraphics.DrawString(text, -1, &fnt, origin, &fmt, &brush);
Here are 3 examples images:
The first uses only one font resource (IDR_FNT_ROBOTO_COND_BOLD):
The second uses a second font resource, but only that one (IDR_FNT_BEBASNEUE_REG):
And here the third example, where I use both fonts:
As you can see, every font alone works fine, but when I use more than one, the output text is garbage.
thanks for any help.
regards
Erich