|
Font size to pixels |
Billybob
Member #3,136
January 2003
|
This one should be easy, but of course it isn't
|
ReyBrujo
Moderator
January 2001
|
Quote: There are 72 points in an inch. The problem is here I think. Are you sure about this? -- |
DmAndrew12
Member #1,950
February 2002
|
If I recall, font size measures the height of the font, not the maximum width of a character in the font. I don't think there really is a way to get pixel size from the font size, as TrueType fonts are comprised of vectors. |
Gideon Weems
Member #3,925
October 2003
|
72 pixels/inch is a common resolution for bitmaps, is it not? I think your info equates "point" with "pixel," and assuming that 72 pixels equal an inch is obviously not wise. So, why not... // pixel_height_of_font / pixels_per_inch int nHeight = text_height(font) / GetDeviceCaps(dc, LOGPIXELSY);
|
Billybob
Member #3,136
January 2003
|
Quote: If I recall, font size measures the height of the font, not the maximum width of a character in the font. I need height, not width. Gideon: MFC. And on another note, does anyone know how to set the color of a dialog in MFC?
|
X-G
Member #856
December 2000
|
Quote: The font size on my app is 18, that should be 1/4 of an inch. It's more like half an inch or more. Are you measuring this on a monitor? If so, don't even expect it to be appropriate. You can't just say that "1 unit = 72 pixels" when monitors are concerned; resolution and monitor size completely destroy that. As for LOGPIXELSY... I'm not sure. There might be more shenanigans involved if you want to do that conversion, and I'm not even sure you CAN get it accurate. Monitors just weren't designed to work that way. As for printing, it should be accurate if your printer is printing at 72 dpi (that is, draw the font 72 points high and they should come out one inch high). -- |
Oscar Giner
Member #2,207
April 2002
|
Quote: And on another note, does anyone know how to set the color of a dialog in MFC? It's certainly [edit]not[/edit] a very easy thing, but here is it. Using the class wizard add a handler to the message WM_CTLCOLOR for your dialog. The definition of the handler will be HBRUSH CYouDialog::OnCtlColor(CDC* pDC, CWnd* pWnd, UINT nCtlColor). This function is not only called for the dialog, but for all objects it contains, so if you want to only set the color of the dialog, you have to check the nCtlColor parameter (it's value is CTLCOLOR_DLG when it's a dialog box), or just pWnd that contains the window class. Now, to the code: HBRUSH CYourDlg::OnCtlColor(CDC* pDC, CWnd* pWnd, UINT nCtlColor) { HBRUSH hbr = CDialog::OnCtlColor(pDC, pWnd, nCtlColor); if (nCtlColor == CTLCOLOR_DLG) // or if (pWnd->GetDlgCtrlID() == IDD_DIALOG_ID) // (IDD_DIALOG_ID is the id of your dialog) { return (HBRUSH)m_pen_dlg.GetSafeHandle(); } return hbr; } m_pen_dlg is a member variable with type CBrush. You initialize it in the OnInitDialog, for example: COLORREF color; color = RGB(190, 210, 210); m_pen_dlg.CreateSolidBrush(color);
[edit] Suggestion: buy a book about MFC. It's not the type of library you can learn by yourself It has lots of little things you'll never know about / take you too much time to get to work [edit] -- |
Matt Smith
Member #783
November 2000
|
The point sizes in fonts are in 1/72". This is an old printer's term from the letterpress days. The actual height of a capital letter is often much smaller than the pt size would suggest, so you can't predict exactly, unless you specify the font and make adjustments. |
|