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.

347 lines
9.4 KiB

  1. /**************************************************************************\
  2. *
  3. * Copyright (c) 1999 Microsoft Corporation
  4. *
  5. * Abstract:
  6. *
  7. * Font family
  8. *
  9. * Revision History:
  10. *
  11. * 27/06/1999 cameronb
  12. * Created it.
  13. *
  14. \**************************************************************************/
  15. #ifndef _GDIPLUSFONTFAMILY_H
  16. #define _GDIPLUSFONTFAMILY_H
  17. #define NumFontFaces 4
  18. #define PFF_ENUMERABLE 0x1
  19. #include "fontable.hpp"
  20. class GpFontFace;
  21. class FontFamily;
  22. class GpFamilyFallback;
  23. const UINT FamilyNameMax = 32;
  24. typedef struct _FAMILYCACHEENTRY
  25. {
  26. UINT cjThis;
  27. // Cache the data from here
  28. INT iFont;
  29. // Cache engine supprt
  30. UINT cFilePathName[NumFontFaces];
  31. WCHAR Name[FamilyNameMax]; // Captialized Family name
  32. WCHAR NormalName[FamilyNameMax]; // Family name
  33. // Alias name
  34. WCHAR FamilyAliasName[FamilyNameMax]; // Captialized FamilyAliasName
  35. WCHAR NormalFamilyAliasName[FamilyNameMax]; // FamilyAliasName
  36. BOOL bAlias;
  37. // Lang ID for Family name and FamilyAliasName
  38. LANGID LangID;
  39. LANGID AliasLnagID;
  40. ULARGE_INTEGER LastWriteTime[NumFontFaces];
  41. // We need to get a charset to let font select into DC
  42. BYTE lfCharset;
  43. } FAMILYCACHEENTRY;
  44. struct FallbackFactory
  45. {
  46. GpStatus Create(const GpFontFamily *family);
  47. void Destroy();
  48. GpFamilyFallback *familyfallback;
  49. };
  50. /*********************************Class************************************\
  51. * class GpFontFamily
  52. *
  53. * Font family consisiting of pointers to the following font styles:
  54. * (1) regular
  55. * (2) italic
  56. * (3) bold
  57. * (4) bold italic
  58. *
  59. * History:
  60. *
  61. * 27/06/1999 cameronb created it
  62. *
  63. \**************************************************************************/
  64. class GpFontFamily
  65. {
  66. private:
  67. // We now use an ObjectTag to determine if the object is valid
  68. // instead of using a BOOL. This is much more robust and helps
  69. // with debugging. It also enables us to version our objects
  70. // more easily with a version number in the ObjectTag.
  71. ObjectTag Tag; // Keep this as the 1st value in the object!
  72. protected:
  73. VOID SetValid(BOOL valid)
  74. {
  75. Tag = valid ? ObjectTagFontFamily : ObjectTagInvalid;
  76. }
  77. // This method is here so that we have a virtual function table so
  78. // that we can add virtual methods in V2 without shifting the position
  79. // of the Tag value within the data structure.
  80. virtual VOID DontCallThis()
  81. {
  82. DontCallThis();
  83. }
  84. public:
  85. GpFontFamily(const WCHAR *name, GpFontFile * fontfile, INT iFont, FAMILYCACHEENTRY * pCacheEntry, GpFontCollection *fontCollection = NULL);
  86. GpFontFamily(FAMILYCACHEENTRY * pCacheEntry);
  87. ~GpFontFamily();
  88. // If the famly came from a different version of GDI+, its tag
  89. // will not match, and it won't be considered valid.
  90. BOOL IsValid() const
  91. {
  92. #ifdef _X86_
  93. // We have to guarantee that the Tag field doesn't move for
  94. // versioning to work between releases of GDI+.
  95. ASSERT(offsetof(GpFontFamily, Tag) == 4);
  96. #endif
  97. ASSERT((Tag == ObjectTagFontFamily) || (Tag == ObjectTagInvalid));
  98. #if DBG
  99. if (Tag == ObjectTagInvalid)
  100. {
  101. WARNING1("Invalid Font Family");
  102. }
  103. #endif
  104. return (Tag == ObjectTagFontFamily);
  105. }
  106. // Name has been captialized
  107. const WCHAR *GetCaptializedName() {return cacheEntry->Name;}
  108. // The original name is not capitalized
  109. GpStatus GetFamilyName(WCHAR name[LF_FACESIZE], LANGID language = MAKELANGID(LANG_NEUTRAL, SUBLANG_NEUTRAL)) const;
  110. void SetFaceAndFile(INT style, GpFontFace *face, GpFontFile * fontfile);
  111. GpFontFace *GetFace(INT style) const;
  112. GpFontFace *GetFaceAbsolute(INT style) const;
  113. BOOL GpFontFamily::IsFileLoaded(BOOL loadFontFile = TRUE) const;
  114. GpFontFile * GetFontFile(UINT i) { return FontFile[i]; }
  115. GpFontCollection *GetFontCollection ()
  116. {
  117. return associatedFontCollection;
  118. }
  119. BOOL FaceExist(INT style) const
  120. {
  121. // Return face for the given style - either the direct face
  122. // or one which can support this style through simulation.
  123. if (Face[style&3])
  124. {
  125. // Distinct font exists
  126. return TRUE;
  127. }
  128. else
  129. {
  130. return FALSE;
  131. }
  132. }
  133. GpFamilyFallback *GetFamilyFallback() const
  134. {
  135. if (!FamilyFallbackInitialized)
  136. {
  137. if (fallback.Create(this) != Ok)
  138. return NULL;
  139. FamilyFallbackInitialized = TRUE;
  140. }
  141. return fallback.familyfallback;
  142. }
  143. BOOL IsPrivate() const;
  144. INT AvailableFaces(void) const;
  145. BOOL SupportsLanguage (INT style, LANGID lang) const;
  146. BOOL SupportsCharacters(INT style, WCHAR* str, INT len) const;
  147. BOOL IsStyleAvailable (INT style) const {return GetFace(style) != NULL;}
  148. UINT16 GetDesignEmHeight (INT style) const;
  149. UINT16 GetDesignCellAscent (INT style) const;
  150. UINT16 GetDesignCellDescent (INT style) const;
  151. UINT16 GetDesignLineSpacing (INT style) const;
  152. UINT16 GetDesignUnderscoreSize (INT style) const;
  153. INT16 GetDesignUnderscorePosition (INT style) const;
  154. UINT16 GetDesignStrikeoutSize (INT style) const;
  155. INT16 GetDesignStrikeoutPosition (INT style) const;
  156. GpStatus GetFontData(FontStyle style, UINT32 tag, INT* tableSize, BYTE** pjTable);
  157. void ReleaseFontData(FontStyle style);
  158. BOOL Deletable(); /* the font family can be removed from the font family list */
  159. BOOL IncFontFamilyRef(void); /* return false if all the faces are removed */
  160. void DecFontFamilyRef(void);
  161. // API support for Family Alias name
  162. BOOL IsAliasName() const
  163. {
  164. return cacheEntry->bAlias;
  165. }
  166. WCHAR * GetAliasName()
  167. {
  168. return cacheEntry->bAlias ? cacheEntry->FamilyAliasName : NULL;
  169. }
  170. FAMILYCACHEENTRY * GetCacheEntry()
  171. {
  172. return cacheEntry;
  173. }
  174. VOID ReleaseCacheEntry()
  175. {
  176. ASSERT(cacheEntry);
  177. if (!bLoadFromCache && cacheEntry)
  178. {
  179. GpFree(cacheEntry);
  180. cacheEntry = NULL;
  181. }
  182. }
  183. static GpStatus CreateFontFamilyFromName
  184. (const WCHAR *name,
  185. GpFontCollection *fontCollection,
  186. GpFontFamily **fontFamily);
  187. static GpStatus GetGenericFontFamilySansSerif
  188. (GpFontFamily **nativeFamily);
  189. static GpStatus GetGenericFontFamilySerif
  190. (GpFontFamily **nativeFamily);
  191. static GpStatus GetGenericFontFamilyMonospace
  192. (GpFontFamily **nativeFamily);
  193. // private member function
  194. private:
  195. BOOL AreAllFacesRemoved();
  196. BOOL WriteToCache();
  197. BOOL ReadFromCache();
  198. // private data
  199. private:
  200. FAMILYCACHEENTRY * cacheEntry;
  201. // Indicate
  202. mutable BOOL bFontFileLoaded;
  203. // Ref count for FontFamily objects that point to this GpFontFamily
  204. INT cFontFamilyRef;
  205. // GpFontFace
  206. mutable GpFontFace *Face[NumFontFaces]; // Pointers to instance of each face
  207. // GpFontFile
  208. mutable GpFontFile *FontFile[NumFontFaces]; // Pointer to font file
  209. mutable FallbackFactory fallback;
  210. mutable BOOL FamilyFallbackInitialized;
  211. BOOL bLoadFromCache;
  212. GpFontCollection * associatedFontCollection; // if NULL, then GpInstalledFontCollection
  213. };
  214. /*********************************Class************************************\
  215. * class GpFontFamilyList
  216. *
  217. * Handles the enumerated list of font families
  218. *
  219. * History:
  220. *
  221. * 27/06/1999 cameronb created it
  222. *
  223. \**************************************************************************/
  224. class GpFontFamilyList
  225. {
  226. public:
  227. // Internal structure for list handling
  228. struct FamilyNode
  229. {
  230. GpFontFamily *Item;
  231. FamilyNode *Prev;
  232. FamilyNode *Next;
  233. FamilyNode(GpFontFamily *family=NULL)
  234. {
  235. Item = family;
  236. Prev = NULL;
  237. Next = NULL;
  238. }
  239. };
  240. public:
  241. GpFontFamilyList();
  242. ~GpFontFamilyList();
  243. private:
  244. void DeleteList(void);
  245. public:
  246. INT Enumerable(GpGraphics* graphics = 0) const;
  247. Status Enumerate(INT numSought, GpFontFamily * gpfamilies[], INT& numFound,
  248. GpGraphics * graphics = 0) const;
  249. GpFontFamily* GetFamily(const WCHAR *familyName) const;
  250. GpFontFamily* GetAnyFamily() const;
  251. BOOL AddFont(GpFontFile* fontFile, GpFontCollection *fontCollection);
  252. BOOL RemoveFontFamily(GpFontFamily* fontFamily);
  253. VOID UpdateFamilyListToCache(BOOL bLoadFromRegistry, HKEY hkey, ULONG registrySize, ULONG numExpected);
  254. BOOL BuildFamilyListFromCache(BOOL bLoadFromRegistry);
  255. private:
  256. BOOL InsertOrdered(GpFontFamily * family, FontStyle style, GpFontFile * fontfile,
  257. GpFontFace * face, BOOL bSetFace);
  258. // Data members
  259. private:
  260. FamilyNode* Head; // The enumerated list
  261. BYTE * FamilyCacheEntry;
  262. };
  263. #endif