GdiPlusFont.h 5.4 KB

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