GetTextMetrics
-
I'm experiencing an odd behaviour with GetTextMetrics() (used sooo many times). I've created two fonts with CreateFont. Select the first font in the device context (PDFWriter printer device context) and do a TextOut(). To increase the y, I call GetTextMetrics() to read the tmHeight and tmExternalLeading values but the program hangs on GetTextMetrics(). If TextOut is not called, GetTextMetrics works. I'm using VC++ 6.0.
-
I'm experiencing an odd behaviour with GetTextMetrics() (used sooo many times). I've created two fonts with CreateFont. Select the first font in the device context (PDFWriter printer device context) and do a TextOut(). To increase the y, I call GetTextMetrics() to read the tmHeight and tmExternalLeading values but the program hangs on GetTextMetrics(). If TextOut is not called, GetTextMetrics works. I'm using VC++ 6.0.
Nyarlatotep wrote:
've created two fonts with CreateFont. Select the first font in the device context (PDFWriter printer device context) and do a TextOut(). To increase the y, I call GetTextMetrics() to read the tmHeight and tmExternalLeading values but the program hangs on GetTextMetrics(). If TextOut is not called, GetTextMetrics works.
You may need to select the font again so that the device context gets new tmHeight and tmExternalLeading values that you updated.:~ Knock out 't' from can't, You can if you think you can :cool:
-
Nyarlatotep wrote:
've created two fonts with CreateFont. Select the first font in the device context (PDFWriter printer device context) and do a TextOut(). To increase the y, I call GetTextMetrics() to read the tmHeight and tmExternalLeading values but the program hangs on GetTextMetrics(). If TextOut is not called, GetTextMetrics works.
You may need to select the font again so that the device context gets new tmHeight and tmExternalLeading values that you updated.:~ Knock out 't' from can't, You can if you think you can :cool:
uhm. the code is like this ... SelectObject(hfont1); GetTextMetrics(hdc,tm1); // it works TextOut(hdc, ....); y += tm1.tmHeight + tm1.tmExternalLeading; SelectObject(hfont2); GetTextMetrics(hdc,tm2); // it hangs the program if TextOut() is not called, the second GetTextMetrics() does not hang. The only solution i've found is to retrieve all the text metrics before doing any TextOut() SelectObject(hfont1); GetTextMetrics(hdc,tm1); SelectObject(hfont2); GetTextMetrics(hdc,tm2); SelectObject(hfont1); TextOut(hdc, ....); y += tm1.tmHeight + tm1.tmExternalLeading; ... ... -- modified at 5:44 Tuesday 13th June, 2006
-
uhm. the code is like this ... SelectObject(hfont1); GetTextMetrics(hdc,tm1); // it works TextOut(hdc, ....); y += tm1.tmHeight + tm1.tmExternalLeading; SelectObject(hfont2); GetTextMetrics(hdc,tm2); // it hangs the program if TextOut() is not called, the second GetTextMetrics() does not hang. The only solution i've found is to retrieve all the text metrics before doing any TextOut() SelectObject(hfont1); GetTextMetrics(hdc,tm1); SelectObject(hfont2); GetTextMetrics(hdc,tm2); SelectObject(hfont1); TextOut(hdc, ....); y += tm1.tmHeight + tm1.tmExternalLeading; ... ... -- modified at 5:44 Tuesday 13th June, 2006
Nyarlatotep wrote:
SelectObject(hfont1); GetTextMetrics(hdc,tm1); SelectObject(hfont2); GetTextMetrics(hdc,tm2);
I have tested that when you create the font and retrive the external leading it returns '0' mostly. why you don't try using the tmHeight parameter of the CreateFont when tmExternalLeading is 0 without making call for GetTextMetrics repeatlly. Knock out 't' from can't, You can if you think you can :cool:
-
uhm. the code is like this ... SelectObject(hfont1); GetTextMetrics(hdc,tm1); // it works TextOut(hdc, ....); y += tm1.tmHeight + tm1.tmExternalLeading; SelectObject(hfont2); GetTextMetrics(hdc,tm2); // it hangs the program if TextOut() is not called, the second GetTextMetrics() does not hang. The only solution i've found is to retrieve all the text metrics before doing any TextOut() SelectObject(hfont1); GetTextMetrics(hdc,tm1); SelectObject(hfont2); GetTextMetrics(hdc,tm2); SelectObject(hfont1); TextOut(hdc, ....); y += tm1.tmHeight + tm1.tmExternalLeading; ... ... -- modified at 5:44 Tuesday 13th June, 2006
please try the following code: ---------------------------------------
hOldFont = SelectObject(hfont1); GetTextMetrics(hdc,tm1); TextOut(hdc, ....); y += tm1.tmHeight + tm1.tmExternalLeading; // Do not forget to clean up. SelectObject(hdc, hOldFont); DeleteObject(hfont1); hOldFont = SelectObject(hfont2); GetTextMetrics(hdc,tm2);
--------------------------------------- -
Nyarlatotep wrote:
SelectObject(hfont1); GetTextMetrics(hdc,tm1); SelectObject(hfont2); GetTextMetrics(hdc,tm2);
I have tested that when you create the font and retrive the external leading it returns '0' mostly. why you don't try using the tmHeight parameter of the CreateFont when tmExternalLeading is 0 without making call for GetTextMetrics repeatlly. Knock out 't' from can't, You can if you think you can :cool:
I could. But GetTextMetrics() is called only at the beginning of the code and not every time TextOut is called. The question is why GetTextMetrics hangs. Never happened before !!! :)
-
please try the following code: ---------------------------------------
hOldFont = SelectObject(hfont1); GetTextMetrics(hdc,tm1); TextOut(hdc, ....); y += tm1.tmHeight + tm1.tmExternalLeading; // Do not forget to clean up. SelectObject(hdc, hOldFont); DeleteObject(hfont1); hOldFont = SelectObject(hfont2); GetTextMetrics(hdc,tm2);
---------------------------------------Selecting the old font and destroyng hfont1 works. :) But in this way i've to re-create hfont1 each time (i use it in many places along with hfont2).
-
I could. But GetTextMetrics() is called only at the beginning of the code and not every time TextOut is called. The question is why GetTextMetrics hangs. Never happened before !!! :)
Nyarlatotep wrote:
The question is why GetTextMetrics hangs. Never happened before !!!
This may due to following. -You have taken the device context of the printer where lots of jobs may pending -When you get the device context of printer and textout the text the device context is in use while jobs may pending or your process is not scheduled. -and you are trying to get/set the information of the device context which may denied as exclusive access to device context:~ Hope you got the issue. Knock out 't' from can't, You can if you think you can :cool: