Leaked source code of windows server 2003
You can not select more than 25 topics Topics must start with a letter or number, can include dashes ('-') and can be up to 35 characters long.

96 lines
3.2 KiB

  1. #include "stdafx.h"
  2. #include "Ctrl.h"
  3. #include "GdiHelp.h"
  4. /***************************************************************************\
  5. *
  6. * GdBuildFont (API)
  7. *
  8. * GdBuildFont() is a helper function that assists in making fonts easier to
  9. * create.
  10. *
  11. * This function is DESIGNED to work with Gadgets. When FS_COMPATIBLE is not
  12. * set, the font size will always be the same, regardless of when large-fonts
  13. * is enabled or not. When FS_COMPATIBLE is set, the font size will use the
  14. * MSDN documented mechanism to compute the font size, taking large-fonts
  15. * into account.
  16. *
  17. * The problem with FS_COMPATIBLE is that the font gets larger, but nothing
  18. * else does. DLU's try to fix this, but they have a lot of problems.
  19. * Gadgets solve this by using GDI's World Transforms and having complete
  20. * scaling of all drawing.
  21. *
  22. \***************************************************************************/
  23. HFONT
  24. GdBuildFont(
  25. IN LPCWSTR pszName, // Name of font
  26. IN int idxDeciSize, // Size in decipoints
  27. IN DWORD nFlags, // Font creation flags
  28. IN HDC hdcDevice) // Optional device (Display if NULL)
  29. {
  30. LOGFONTW lf;
  31. int nLogPixelsY;
  32. if (hdcDevice != NULL) {
  33. nLogPixelsY = GetDeviceCaps(hdcDevice, LOGPIXELSY);
  34. } else if (TestFlag(nFlags, FS_COMPATIBLE)) {
  35. HDC hdcDesktop = GetGdiCache()->GetTempDC();
  36. if (hdcDesktop == NULL) {
  37. return NULL;
  38. }
  39. nLogPixelsY = GetDeviceCaps(hdcDesktop, LOGPIXELSY);
  40. GetGdiCache()->ReleaseTempDC(hdcDesktop);
  41. } else {
  42. nLogPixelsY = 96; // Hard code for normal fonts
  43. }
  44. ZeroMemory(&lf, sizeof(LOGFONT));
  45. wcscpy(lf.lfFaceName, pszName);
  46. lf.lfHeight = -MulDiv(idxDeciSize, nLogPixelsY, 720);
  47. lf.lfWeight = nFlags & FS_BOLD ? FW_BOLD : FW_NORMAL;
  48. lf.lfItalic = (nFlags & FS_ITALIC) != 0;
  49. lf.lfUnderline = (nFlags & FS_UNDERLINE) != 0;
  50. lf.lfStrikeOut = (nFlags & FS_STRIKEOUT) != 0;
  51. lf.lfCharSet = DEFAULT_CHARSET;
  52. lf.lfOutPrecision = OUT_DEFAULT_PRECIS;
  53. lf.lfClipPrecision = CLIP_DEFAULT_PRECIS;
  54. lf.lfQuality = ANTIALIASED_QUALITY;
  55. lf.lfPitchAndFamily = DEFAULT_PITCH | FF_DONTCARE;
  56. return OS()->CreateFontIndirect(&lf);
  57. }
  58. /***************************************************************************\
  59. *
  60. * GdGetColor
  61. *
  62. * GdGetColor gets the color of a pixel at the specified point in the bitmap.
  63. * This utility function is designed to help when determining the transparent
  64. * color of a bitmap.
  65. *
  66. \***************************************************************************/
  67. COLORREF
  68. GdGetColor(HBITMAP hbmp, POINT * pptPxl)
  69. {
  70. POINT ptTest;
  71. if (pptPxl != NULL) {
  72. ptTest = *pptPxl;
  73. } else {
  74. ptTest.x = 0;
  75. ptTest.y = 0;
  76. }
  77. HDC hdcBitmap = GetGdiCache()->GetCompatibleDC();
  78. HBITMAP hbmpOld = (HBITMAP) SelectObject(hdcBitmap, hbmp);
  79. COLORREF crTr = GetPixel(hdcBitmap, ptTest.x, ptTest.y);
  80. SelectObject(hdcBitmap, hbmpOld);
  81. GetGdiCache()->ReleaseCompatibleDC(hdcBitmap);
  82. return crTr;
  83. }