// XFontSize.cpp Version 1.0 // // Author: Hans Dietrich // hdietrich@gmail.com // // License: // This software is released into the public domain. You are free to use // it in any way you like, except that you may not sell this source code. // // This software is provided "as is" with no expressed or implied warranty. // I accept no liability for any damage or loss of business that this // software may cause. // /////////////////////////////////////////////////////////////////////////////// #include "stdafx.h" //#include "windows.h" #define XFONTSIZE_CPP #include "XFontSize.h" #include "tchar.h" int CXFontSize::m_cyPixelsPerInch = 0; //============================================================================= CXFontSize::CXFontSize() //============================================================================= { Init(); } //============================================================================= void CXFontSize::Init() //============================================================================= { if (m_cyPixelsPerInch == 0) { HDC hdc = ::CreateDC(_T("DISPLAY"), NULL, NULL, NULL); if (hdc) { m_cyPixelsPerInch = ::GetDeviceCaps(hdc, LOGPIXELSY); ::DeleteDC(hdc); } } } //============================================================================= CXFontSize::~CXFontSize() //============================================================================= { } //============================================================================= int CXFontSize::GetFontPointSize(int nHeight) //============================================================================= { Init(); int nPointSize = 0; if (m_cyPixelsPerInch) { nPointSize = MulDiv(nHeight, 72, m_cyPixelsPerInch); if (nPointSize < 0) nPointSize = -nPointSize; } return nPointSize; } //============================================================================= int CXFontSize::GetFontHeight(int nPointSize) //============================================================================= { Init(); int nHeight = 0; if (m_cyPixelsPerInch) { nHeight = -MulDiv(nPointSize, m_cyPixelsPerInch, 72); } return nHeight; }