CFontDialog
-
Hi All, I have created an application in which i can change the font attributes of a text. I am using CFontDialog to select font size, font family etc Before calling CFontDialog (while debugging) m_TextFont.m_cf.iPointSize is 140. (Font Size is 14). But when Font dialog is popped it is showing Font Size as 17. What may be the problem?
-
Hi All, I have created an application in which i can change the font attributes of a text. I am using CFontDialog to select font size, font family etc Before calling CFontDialog (while debugging) m_TextFont.m_cf.iPointSize is 140. (Font Size is 14). But when Font dialog is popped it is showing Font Size as 17. What may be the problem?
Care to share a code snippet with us?
"A good athlete is the result of a good and worthy opponent." - David Crow
"To have a respect for ourselves guides our morals; to have deference for others governs our manners." - Laurence Sterne
-
Hi All, I have created an application in which i can change the font attributes of a text. I am using CFontDialog to select font size, font family etc Before calling CFontDialog (while debugging) m_TextFont.m_cf.iPointSize is 140. (Font Size is 14). But when Font dialog is popped it is showing Font Size as 17. What may be the problem?
I would hazard a guess to say that it is to do with how Windows maps fonts. In the LOGFONT structure, for example, it needs a *negative* value to get the full character height - a positive value gives a slightly different size as it doesn't check against the full character cell height. Now, this doesn't necessarily mean it's true in your case. I think we are going to need to see some sample code and / or an explanation of what you do as a user with the font dialogue in between examining those values - for example, do you simply cancel it, or do you choose something?
-
I would hazard a guess to say that it is to do with how Windows maps fonts. In the LOGFONT structure, for example, it needs a *negative* value to get the full character height - a positive value gives a slightly different size as it doesn't check against the full character cell height. Now, this doesn't necessarily mean it's true in your case. I think we are going to need to see some sample code and / or an explanation of what you do as a user with the font dialogue in between examining those values - for example, do you simply cancel it, or do you choose something?
CFontDialog* m_TextFont = new CFontDialog(&lfFontAttr, CF_BOTH | CF_TTONLY | CF_INITTOLOGFONTSTRUCT);
lfFontAttr is LOGFONT structure.
m_TextFont->GetCurrentFont(&lfFontAttr);
Here m_TextFont->m_cf.iPointSize is 140 (i got the value while debugging)
if (m_TextFont->DoModal() == IDOK)
{
m_TextFont->GetCurrentFont(&lfFontAttr);
-------
}Font size 17 is shown in dialog.
-
CFontDialog* m_TextFont = new CFontDialog(&lfFontAttr, CF_BOTH | CF_TTONLY | CF_INITTOLOGFONTSTRUCT);
lfFontAttr is LOGFONT structure.
m_TextFont->GetCurrentFont(&lfFontAttr);
Here m_TextFont->m_cf.iPointSize is 140 (i got the value while debugging)
if (m_TextFont->DoModal() == IDOK)
{
m_TextFont->GetCurrentFont(&lfFontAttr);
-------
}Font size 17 is shown in dialog.
My hunch was strangely accurate. If you look at the constructor for CFontDialog in MSDN, it has a sample (reproduced below) that sets a negative value (the pixel height) into lfHeight, not 1/10ths of a point as you have: // Show the font dialog with 12 point "Times New Roman" as the // selected font. LOGFONT lf; memset(&lf, 0, sizeof(LOGFONT)); CClientDC dc(this); lf.lfHeight = -MulDiv(12, dc.GetDeviceCaps(LOGPIXELSY), 72); strcpy(lf.lfFaceName, "Times New Roman"); CFontDialog dlg(&lf); dlg.DoModal(); I believe this to be the source of the problem.