If this is your first visit, be sure to
check out the
FAQ
by clicking the
link above. You may have to
register
or
Login
before you can post: click the register link above to proceed. To start viewing messages,
select the forum that you want to visit from the selection below.
I'm currently using CreateFont() to create fonts for my application. In the front-end, my application works with Twips which at SOME point needs to be converted to work with CreateFont(). The first parameter of CreateFont() is the height of the font in "logical units" which I have no idea about. Does this mean pixels? What algorithm or function can I use to convert twips to the units required by CreateFont()? Thanks.
Currently I'm using:
MulDiv( twips, GetDeviceCaps( m_mdc, LOGPIXELSY ), 1440 );
Which doesn't seem to work. The font is smaller than the size I expect.
Code:
//===================================================================================================
s32 FontData::TwipsToPixels( s32 twips )
return MulDiv( twips, GetDeviceCaps( m_mdc, LOGPIXELSY ), 1440 );
//===================================================================================================
void FontData::ChangeSingleFont( HFONT& font, s32 size_in_twips, const std::wstring& typefaceName )
font = CreateFontW(
TwipsToPixels( size_in_twips ), // Font Height
0, // Font Width (0 = auto)
0, // Escapement
0, // Orientation
FW_BOLD, // Weight
FALSE, // Italic
FALSE, // Underline
FALSE, // Strike-Out
ANSI_CHARSET, // Character Set
OUT_DEFAULT_PRECIS, // Output Precision
CLIP_DEFAULT_PRECIS, // Clip Precision
DEFAULT_QUALITY, // Quality
DEFAULT_PITCH | FF_DONTCARE, // Pitch & Family
typefaceName.c_str() // Face (font type)
meassert( font );
On second thought, it's not working like I expected. Perhaps I'm doing something else wrong?
I pass in 100 as the first parameter to CreateFontW() after setting to MM_TWIPS, however the text is EXTREMELY huge! It shouldn't be that big. Any idea what's going on? here's my code:
Code:
int previousMapMode = SetMapMode( m_mdc, MM_TWIPS );
font = CreateFontW(
size_in_twips, // Font Height
0, // Font Width (0 = auto)
0, // Escapement
0, // Orientation
FW_NORMAL, // Weight
FALSE, // Italic
FALSE, // Underline
FALSE, // Strike-Out
DEFAULT_CHARSET, // Character Set
OUT_DEFAULT_PRECIS, // Output Precision
CLIP_DEFAULT_PRECIS, // Clip Precision
DEFAULT_QUALITY, // Quality
DEFAULT_PITCH | FF_DONTCARE, // Pitch & Family
typefaceName.c_str() // Face (font type)
meassert( font );
SetMapMode( m_mdc, previousMapMode );
If there's anything else you need to see, just let me know. Thanks.
HFONT HFont, previousHFont;
int previousMapMode = SetMapMode(hdc, MM_TWIPS);
SelectObject(hdc, GetStockObject(BLACK_PEN));
HFont = CreateFont(
300, // Font Height
0, // Font Width (0 = auto)
0, // Escapement
0, // Orientation
FW_NORMAL, // Weight
FALSE, // Italic
FALSE, // Underline
FALSE, // Strike-Out
DEFAULT_CHARSET, // Character Set
OUT_DEFAULT_PRECIS, // Output Precision
CLIP_DEFAULT_PRECIS, // Clip Precision
DEFAULT_QUALITY, // Quality
DEFAULT_PITCH | FF_DONTCARE, // Pitch & Family
"Verdana" // Face (font type)
previousHFont = (HFONT) SelectObject(hdc, HFont);
TextOut(hdc, 400, 10, "Test", 4);
SelectObject(hdc, previousHFont);
DeleteObject(HFont);
SetMapMode(hdc, previousMapMode);
The size of the characters with a MM_TWIPS and a height of 300 is about the same as the size I get with MM_TEXT and a height of 15.
* The Best Reasons to Target Windows 8
Learn some of the best reasons why you should seriously consider bringing your Android mobile development expertise to bear on the Windows 8 platform.
* Porting from Android to Windows 8: The Real Story
Do you have an Android application? How hard would it really be to port to Windows 8?
* Guide to Porting Android Applications to Windows 8
If you've already built for Android, learn what do you really need to know to port your application to Windows Phone 8.
* HTML5 Development Center
Our portal for articles, videos, and news on HTML5, CSS3, and JavaScript
* Windows App Gallery
See the Windows 8.x apps we've spotlighted or submit your own app to the gallery!
Advertiser Disclosure:
Some of the products that appear on this site are from companies from which TechnologyAdvice receives compensation. This compensation may impact how and where products appear on this site including, for example, the order in which they appear. TechnologyAdvice does not include all companies or all types of products available in the marketplace.