FontSize.cpp 1.2 KB

12345678910111213141516171819202122232425262728293031323334353637383940414243444546
  1. // FontSize.cpp Version 1.0
  2. //
  3. // Author: Hans Dietrich
  4. // hdietrich2@hotmail.com
  5. //
  6. // This software is released into the public domain.
  7. // You are free to use it in any way you like.
  8. //
  9. // This software is provided "as is" with no expressed
  10. // or implied warranty. I accept no liability for any
  11. // damage or loss of business that this software may cause.
  12. //
  13. ///////////////////////////////////////////////////////////////////////////////
  14. #include "stdafx.h"
  15. #include "FontSize.h"
  16. ///////////////////////////////////////////////////////////////////////////////
  17. // GetFontPointSize()
  18. int GetFontPointSize(int nHeight)
  19. {
  20. HDC hdc = ::CreateDC(_T("DISPLAY"), NULL, NULL, NULL);
  21. ASSERT(hdc);
  22. int cyPixelsPerInch = ::GetDeviceCaps(hdc, LOGPIXELSY);
  23. ::DeleteDC(hdc);
  24. int nPointSize = MulDiv(nHeight, 72, cyPixelsPerInch);
  25. if (nPointSize < 0)
  26. nPointSize = -nPointSize;
  27. return nPointSize;
  28. }
  29. ///////////////////////////////////////////////////////////////////////////////
  30. // GetFontHeight()
  31. int GetFontHeight(int nPointSize)
  32. {
  33. HDC hdc = ::CreateDC(_T("DISPLAY"), NULL, NULL, NULL);
  34. ASSERT(hdc);
  35. int cyPixelsPerInch = ::GetDeviceCaps(hdc, LOGPIXELSY);
  36. ::DeleteDC(hdc);
  37. int nHeight = -MulDiv(nPointSize, cyPixelsPerInch, 72);
  38. return nHeight;
  39. }