I am developing this application and in order to ensure content is adjusted to page size, a the application uses the current font size and the value that GetTextExtentPoint32 returned to adjust the page size by feeding the out come into a while loop. I was rather schocked to discover that GetExtentPoint32 keep returning the same value inspite of decrrase of font-size. Why is that so, how can I solve this challenge.
The relevant codes are shown below:
GetTextExtentPoint32(hdc, wstSchoolName11.c_str(), lstrlen(wstSchoolName11.c_str()), &size);
if ((iTextLeft + size.cx) > (iPaperWidth - iPictureWidth - iOffsetX))
{
iFontSize--;
hNewFont = CreateAppFont(iFontSize, FW_BOLD);
hOldFont = (HFONT)SelectObject(hdc, hNewFont);
GetTextMetrics(hdc, &tm);
wstring wstSchoolName11 = utf8_decode(stSchoolName);
CharUpper(&wstSchoolName11[0]);
GetTextExtentPoint32(hdc, wstSchoolName11.c_str(), lstrlen(wstSchoolName11.c_str()), &size);
}
else
{
bMaximumWith = true;
}
int iWindowExtX = 1000 * GetDeviceCaps(hDC,HORZSIZE);
int iWindowExtY = 1000 * GetDeviceCaps(hDC, VERTSIZE);
int iViewPortX = GetDeviceCaps(hDC, HORZRES);
int iViewPortY = GetDeviceCaps(hDC, VERTRES);
SetMapMode(hDC, MM_ISOTROPIC);
SetWindowExtEx(hDC, iWindowExtX, iWindowExtY, nullptr);
SetViewportExtEx(hDC, iViewPortX, iViewPortY, nullptr);
The definition of CreateFont app is as shown below. Is there anything wrong with it?
HFONT CreateAppFont(int cHeight, int cWeight, DWORD bItalic = 0, int cEscapement = 0, DWORD bUnderline = 0, LPCWSTR pszFaceName = L"Times New Roman");
HFONT CreateAppFont(int cHeight, int cWeight, DWORD bItalic, int cEscapement, DWORD bUnderline, LPCWSTR pszFaceName)
{
return CreateFont(cHeight, 0, cEscapement, cEscapement, cWeight, bItalic, bUnderline, FALSE, DEFAULT_CHARSET, OUT_OUTLINE_PRECIS,
CLIP_DEFAULT_PRECIS, CLEARTYPE_QUALITY, VARIABLE_PITCH, pszFaceName);
}
What I have tried:
I have done have spent reasonable time debugging. The outcome neccitated this post.