您最多选择25个主题 主题必须以字母或数字开头,可以包含连字符 (-),并且长度不得超过35个字符
 
 
 
 
 
 

300 行
5.8 KiB

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