GdiPlusFontFamily.h
上传用户:jinlangri
上传日期:2022-07-17
资源大小:10774k
文件大小:6k
源码类别:

GDI/图象编程

开发平台:

Visual C++

  1. /**************************************************************************
  2. *
  3. * Copyright (c) 1998-2000, Microsoft Corp.  All Rights Reserved.
  4. *
  5. * Module Name:
  6. *
  7. *   GdiplusFontFamily.h
  8. *
  9. * Abstract:
  10. *
  11. *   Font family API related declarations
  12. *
  13. **************************************************************************/
  14. #ifndef _GDIPLUS_FONT_FAMILY_H
  15. #define _GDIPLUS_FONT_FAMILY_H
  16. inline 
  17. FontFamily::FontFamily() :
  18.     nativeFamily (NULL),
  19.     lastResult    (Ok)
  20. {
  21. }
  22. inline 
  23. FontFamily::FontFamily(
  24.     IN const WCHAR*          name,
  25.     IN const FontCollection* fontCollection
  26. )
  27. {
  28.     nativeFamily = NULL;
  29.     lastResult = DllExports::GdipCreateFontFamilyFromName(
  30.         name,
  31.         fontCollection ? fontCollection->nativeFontCollection : NULL,
  32.         &nativeFamily
  33.     );
  34.     
  35. #ifndef DCR_USE_NEW_135429
  36.     if ((INT) lastResult >= 10)
  37.         lastResult = NotFound;
  38. #endif
  39. }
  40. // private method
  41. inline
  42. FontFamily::FontFamily(
  43.     IN GpFontFamily *nativeOrig,
  44.     IN Status status
  45. )
  46. {
  47.     lastResult    = status;
  48.     nativeFamily = nativeOrig;
  49. }
  50. // Generic font family access
  51. inline const FontFamily *
  52. FontFamily::GenericSansSerif() 
  53. {
  54.     if (GenericSansSerifFontFamily != NULL)
  55.     {
  56.         return GenericSansSerifFontFamily;
  57.     }
  58.     GenericSansSerifFontFamily =
  59.         (FontFamily*) GenericSansSerifFontFamilyBuffer;
  60.     GenericSansSerifFontFamily->lastResult =
  61.         DllExports::GdipGetGenericFontFamilySansSerif(
  62.             &(GenericSansSerifFontFamily->nativeFamily)
  63.         );
  64. #ifndef DCR_USE_NEW_135429
  65.     if ((INT) GenericSansSerifFontFamily->lastResult >= 10)
  66.         GenericSansSerifFontFamily->lastResult = NotFound;
  67. #endif
  68.     return GenericSansSerifFontFamily;
  69. }
  70. inline const FontFamily *
  71. FontFamily::GenericSerif() 
  72. {
  73.     if (GenericSerifFontFamily != NULL)
  74.     {
  75.         return GenericSerifFontFamily;
  76.     }
  77.     GenericSerifFontFamily =
  78.         (FontFamily*) GenericSerifFontFamilyBuffer;
  79.     GenericSerifFontFamily->lastResult =
  80.         DllExports::GdipGetGenericFontFamilySerif(
  81.             &(GenericSerifFontFamily->nativeFamily)
  82.         );
  83. #ifndef DCR_USE_NEW_135429
  84.     if ((INT) GenericSerifFontFamily->lastResult >= 10)
  85.         GenericSerifFontFamily->lastResult = NotFound;
  86. #endif
  87.     return GenericSerifFontFamily;
  88. }
  89. inline const FontFamily *
  90. FontFamily::GenericMonospace()
  91. {
  92.     if (GenericMonospaceFontFamily != NULL)
  93.     {
  94.         return GenericMonospaceFontFamily;
  95.     }
  96.     GenericMonospaceFontFamily =
  97.         (FontFamily*) GenericMonospaceFontFamilyBuffer;
  98.     GenericMonospaceFontFamily->lastResult =
  99.         DllExports::GdipGetGenericFontFamilyMonospace(
  100.             &(GenericMonospaceFontFamily->nativeFamily)
  101.         );
  102. #ifndef DCR_USE_NEW_135429
  103.     if ((INT) GenericMonospaceFontFamily->lastResult >= 10)
  104.         GenericMonospaceFontFamily->lastResult = NotFound;
  105. #endif
  106.     return GenericMonospaceFontFamily;
  107. }
  108. inline FontFamily::~FontFamily()
  109. {
  110.     DllExports::GdipDeleteFontFamily (nativeFamily);
  111. }
  112. inline FontFamily *
  113. FontFamily::Clone() const
  114. {
  115.     GpFontFamily * clonedFamily = NULL;
  116.     SetStatus(DllExports::GdipCloneFontFamily (nativeFamily, &clonedFamily));
  117.     return new FontFamily(clonedFamily, lastResult);
  118. }
  119. inline Status 
  120. FontFamily::GetFamilyName(
  121.     IN WCHAR name[LF_FACESIZE],
  122.     IN LANGID language
  123. ) const
  124. {
  125.     return SetStatus(DllExports::GdipGetFamilyName(nativeFamily, 
  126.                                                    name, 
  127.                                                    language));
  128. }
  129. inline BOOL 
  130. FontFamily::IsStyleAvailable(IN INT style) const
  131. {
  132.     BOOL    StyleAvailable;
  133.     Status  status;
  134.     status = SetStatus(DllExports::GdipIsStyleAvailable(nativeFamily, style, &StyleAvailable));
  135.     if (status != Ok)
  136.         StyleAvailable = FALSE;
  137.     return StyleAvailable;
  138. }
  139. inline UINT16 
  140. FontFamily::GetEmHeight(IN INT style) const
  141. {
  142.     UINT16  EmHeight;
  143.     SetStatus(DllExports::GdipGetEmHeight(nativeFamily, style, &EmHeight));
  144.     return EmHeight;
  145. }
  146. inline UINT16 
  147. FontFamily::GetCellAscent(IN INT style) const
  148. {
  149.     UINT16  CellAscent;
  150.     SetStatus(DllExports::GdipGetCellAscent(nativeFamily, style, &CellAscent));
  151.     return CellAscent;
  152. }
  153. inline UINT16 
  154. FontFamily::GetCellDescent(IN INT style) const
  155. {
  156.     UINT16  CellDescent;
  157.     SetStatus(DllExports::GdipGetCellDescent(nativeFamily, style, &CellDescent));
  158.     return CellDescent;
  159. }
  160. inline UINT16 
  161. FontFamily::GetLineSpacing(IN INT style) const
  162. {
  163.     UINT16  LineSpacing;
  164.     SetStatus(DllExports::GdipGetLineSpacing(nativeFamily, style, &LineSpacing));
  165.     return LineSpacing;
  166. }
  167. #ifdef TEXTV2
  168. // The following APIs return data from the font OS/2 table
  169. inline INT16 
  170. FontFamily::GetTypographicAscent(IN INT style) const
  171. {
  172.     INT16  TypographicAscent;
  173.     SetStatus(DllExports::GdipGetTypographicAscent(nativeFamily, style, &TypographicAscent));
  174.     return TypographicAscent;
  175. }
  176. inline INT16 
  177. FontFamily::GetTypographicDescent(IN INT style) const
  178. {
  179.     INT16   TypographicDescent;
  180.     SetStatus(DllExports::GdipGetTypographicDescent(nativeFamily, style, &TypographicDescent));
  181.     return TypographicDescent;
  182. }
  183. inline INT16 
  184. FontFamily::GetTypographicLineGap(IN INT style) const
  185. {
  186.     INT16   TypographicLineGap;
  187.     SetStatus(DllExports::GdipGetTypographicLineGap(nativeFamily, style, &TypographicLineGap));
  188.     return TypographicLineGap;
  189. }
  190. #endif
  191. ///////////////////////////////////////////////////////////
  192. // GetLastStatus - return last error code and clear error code
  193. inline Status 
  194. FontFamily::GetLastStatus() const
  195. {
  196.     Status lastStatus = lastResult;
  197.     lastResult = Ok;
  198.     return lastStatus;
  199. }
  200. // protected method
  201. inline Status
  202. FontFamily::SetStatus(Status status) const 
  203. {
  204.     if (status != Ok)
  205.         return (lastResult = status);
  206.     else
  207.         return status;
  208. }
  209. #endif