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.

280 lines
5.7 KiB

  1. /**************************************************************************\
  2. *
  3. * Copyright (c) 1998-2001, Microsoft Corp. All Rights Reserved.
  4. *
  5. * Module Name:
  6. *
  7. * GdiplusFont.h
  8. *
  9. * Abstract:
  10. *
  11. * GDI+ Font class
  12. *
  13. \**************************************************************************/
  14. #ifndef _GDIPLUSFONT_H
  15. #define _GDIPLUSFONT_H
  16. inline
  17. Font::Font(IN HDC hdc)
  18. {
  19. GpFont *font = NULL;
  20. lastResult = DllExports::GdipCreateFontFromDC(hdc, &font);
  21. SetNativeFont(font);
  22. }
  23. inline
  24. Font::Font(IN HDC hdc,
  25. IN const HFONT hfont)
  26. {
  27. GpFont *font = NULL;
  28. if (hfont)
  29. {
  30. LOGFONTA lf;
  31. if(GetObjectA(hfont, sizeof(LOGFONTA), &lf))
  32. lastResult = DllExports::GdipCreateFontFromLogfontA(hdc, &lf, &font);
  33. else
  34. lastResult = DllExports::GdipCreateFontFromDC(hdc, &font);
  35. }
  36. else
  37. {
  38. lastResult = DllExports::GdipCreateFontFromDC(hdc, &font);
  39. }
  40. SetNativeFont(font);
  41. }
  42. inline
  43. Font::Font(IN HDC hdc,
  44. IN const LOGFONTW* logfont)
  45. {
  46. GpFont *font = NULL;
  47. if (logfont)
  48. {
  49. lastResult = DllExports::GdipCreateFontFromLogfontW(hdc, logfont, &font);
  50. }
  51. else
  52. {
  53. lastResult = DllExports::GdipCreateFontFromDC(hdc, &font);
  54. }
  55. SetNativeFont(font);
  56. }
  57. inline
  58. Font::Font(IN HDC hdc,
  59. IN const LOGFONTA* logfont)
  60. {
  61. GpFont *font = NULL;
  62. if (logfont)
  63. {
  64. lastResult = DllExports::GdipCreateFontFromLogfontA(hdc, logfont, &font);
  65. }
  66. else
  67. {
  68. lastResult = DllExports::GdipCreateFontFromDC(hdc, &font);
  69. }
  70. SetNativeFont(font);
  71. }
  72. inline
  73. Font::Font(
  74. IN const FontFamily * family,
  75. IN REAL emSize,
  76. IN INT style,
  77. IN Unit unit
  78. )
  79. {
  80. GpFont *font = NULL;
  81. lastResult = DllExports::GdipCreateFont(family ? family->nativeFamily : NULL,
  82. emSize,
  83. style,
  84. unit,
  85. &font);
  86. SetNativeFont(font);
  87. }
  88. inline
  89. Font::Font(
  90. IN const WCHAR * familyName,
  91. IN REAL emSize,
  92. IN INT style,
  93. IN Unit unit,
  94. IN const FontCollection * fontCollection
  95. )
  96. {
  97. nativeFont = NULL;
  98. FontFamily family(familyName, fontCollection);
  99. GpFontFamily *nativeFamily = family.nativeFamily;
  100. lastResult = family.GetLastStatus();
  101. if (lastResult != Ok)
  102. {
  103. nativeFamily = FontFamily::GenericSansSerif()->nativeFamily;
  104. lastResult = FontFamily::GenericSansSerif()->lastResult;
  105. if (lastResult != Ok)
  106. return;
  107. }
  108. lastResult = DllExports::GdipCreateFont(nativeFamily,
  109. emSize,
  110. style,
  111. unit,
  112. &nativeFont);
  113. if (lastResult != Ok)
  114. {
  115. nativeFamily = FontFamily::GenericSansSerif()->nativeFamily;
  116. lastResult = FontFamily::GenericSansSerif()->lastResult;
  117. if (lastResult != Ok)
  118. return;
  119. lastResult = DllExports::GdipCreateFont(
  120. nativeFamily,
  121. emSize,
  122. style,
  123. unit,
  124. &nativeFont);
  125. }
  126. }
  127. inline Status
  128. Font::GetLogFontA(IN const Graphics *g,
  129. OUT LOGFONTA *logfontA) const
  130. {
  131. return SetStatus(DllExports::GdipGetLogFontA(nativeFont, g ? g->nativeGraphics : NULL, logfontA));
  132. }
  133. inline Status
  134. Font::GetLogFontW(IN const Graphics *g,
  135. OUT LOGFONTW *logfontW) const
  136. {
  137. return SetStatus(DllExports::GdipGetLogFontW(nativeFont, g ? g->nativeGraphics : NULL, logfontW));
  138. }
  139. inline Font*
  140. Font::Clone() const
  141. {
  142. GpFont *cloneFont = NULL;
  143. SetStatus(DllExports::GdipCloneFont(nativeFont, &cloneFont));
  144. return new Font(cloneFont, lastResult);
  145. }
  146. inline
  147. Font::~Font()
  148. {
  149. DllExports::GdipDeleteFont(nativeFont);
  150. }
  151. // Operations
  152. inline BOOL
  153. Font::IsAvailable() const
  154. {
  155. return (nativeFont ? TRUE : FALSE);
  156. }
  157. inline Status
  158. Font::GetFamily(OUT FontFamily *family) const
  159. {
  160. if (family == NULL)
  161. {
  162. return SetStatus(InvalidParameter);
  163. }
  164. Status status = DllExports::GdipGetFamily(nativeFont, &(family->nativeFamily));
  165. family->SetStatus(status);
  166. return SetStatus(status);
  167. }
  168. inline INT
  169. Font::GetStyle() const
  170. {
  171. INT style;
  172. SetStatus(DllExports::GdipGetFontStyle(nativeFont, &style));
  173. return style;
  174. }
  175. inline REAL
  176. Font::GetSize() const
  177. {
  178. REAL size;
  179. SetStatus(DllExports::GdipGetFontSize(nativeFont, &size));
  180. return size;
  181. }
  182. inline Unit
  183. Font::GetUnit() const
  184. {
  185. Unit unit;
  186. SetStatus(DllExports::GdipGetFontUnit(nativeFont, &unit));
  187. return unit;
  188. }
  189. inline REAL
  190. Font::GetHeight(IN const Graphics *graphics) const
  191. {
  192. REAL height;
  193. SetStatus(DllExports::GdipGetFontHeight(
  194. nativeFont,
  195. graphics ? graphics->nativeGraphics : NULL,
  196. &height
  197. ));
  198. return height;
  199. }
  200. inline REAL
  201. Font::GetHeight(IN REAL dpi) const
  202. {
  203. REAL height;
  204. SetStatus(DllExports::GdipGetFontHeightGivenDPI(nativeFont, dpi, &height));
  205. return height;
  206. }
  207. inline
  208. Font::Font(IN GpFont* font,
  209. IN Status status)
  210. {
  211. lastResult = status;
  212. SetNativeFont(font);
  213. }
  214. inline VOID
  215. Font::SetNativeFont(GpFont *Font)
  216. {
  217. nativeFont = Font;
  218. }
  219. inline Status
  220. Font::GetLastStatus(void) const
  221. {
  222. return lastResult;
  223. }
  224. inline Status
  225. Font::SetStatus(IN Status status) const
  226. {
  227. if (status != Ok)
  228. return (lastResult = status);
  229. else
  230. return status;
  231. }
  232. #endif