Source code of Windows XP (NT5)
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.

261 lines
4.9 KiB

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