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.

552 lines
16 KiB

  1. #ifndef _FACEREALIZATION_
  2. #define _FACEREALIZATION_
  3. #define GLYPHDATABLOCKCOUNT 16
  4. #define MAXRECENTLYUSEDCOUNT 32
  5. #define EMPTY_GLYPH_FFFF 0xFFFF // Display nothing, neither ink nor width.
  6. // Typedefs for cached funtion pointers in GpFaceRealization.
  7. class GpFaceRealization;
  8. /* used in aatext.cxx and facerealization.cpp : */
  9. #define CJ_CTGD(cx,cy) (ALIGN4(offsetof(GLYPHBITS,aj)) + ALIGN4((cx) * (cy)))
  10. #define ALIGN4(X) (((X) + 3) & ~3)
  11. #define ALIGN(object, p) p = (p + ((UINT)sizeof(object) - 1)) & ~((UINT)sizeof(object) - 1);
  12. inline BOOL IsGridFittedTextRealizationMethod(TextRenderingHint method)
  13. {
  14. switch (method)
  15. {
  16. case TextRenderingHintSingleBitPerPixelGridFit:
  17. case TextRenderingHintAntiAliasGridFit:
  18. case TextRenderingHintClearTypeGridFit:
  19. return TRUE;
  20. default:
  21. return FALSE;
  22. }
  23. }
  24. ///// GpGlyphMetrics
  25. //
  26. // Metrics for text handling and glyph placement.
  27. // There are separate records for horizontal and vertical baselines.
  28. struct GpGlyphMetrics {
  29. // Metrics along baseline in 28.4
  30. INT AdvanceWidth;
  31. INT LeadingSidebearing;
  32. INT TrailingSidebearing;
  33. PointF Origin; // Float
  34. };
  35. struct GpGlyphAABits
  36. {
  37. GpGlyphAABits * Next;
  38. ULONG X, Y;
  39. BYTE Bits[1]; // variable size
  40. };
  41. struct GpGlyphData {
  42. GpGlyphMetrics GlyphMetrics[2]; // one for horizontal metrics and one for vertical metrics
  43. union {
  44. GLYPHBITS *GlyphBits; // Same as GDI structure at this moment
  45. GpGlyphPath *GlyphPath;
  46. GpGlyphAABits *GlyphAABits; // null terminated singly-linked list
  47. };
  48. };
  49. struct GlyphDataBlock
  50. {
  51. GlyphDataBlock *NextGlyphDataBlock;
  52. GpGlyphData GlyphDataArray[GLYPHDATABLOCKCOUNT];
  53. };
  54. // blocks of memory used to store glyphbits
  55. struct GlyphBitsBlock
  56. {
  57. GlyphBitsBlock *NextGlyphBitsBlock; // next block in the list
  58. UINT SizeGlyphBitsBlock; // Bytes allocated
  59. BYTE Bits[1]; // bits
  60. };
  61. //// CacheFaceRealization - cache entries referenced by FaceRealization
  62. //
  63. //
  64. class EXTFONTOBJ
  65. {
  66. public:
  67. FONTOBJ fobj; // pass to DDI, we need to have it to back compatible with GDI
  68. };
  69. enum GpGlyphDataCacheType
  70. {
  71. CacheBits,
  72. CachePath,
  73. CacheAABits
  74. };
  75. class CacheFaceRealization : public EXTFONTOBJ
  76. {
  77. public:
  78. // New type information
  79. BOOL NoCache; // Cache type -
  80. GpGlyphDataCacheType CacheType; // bits, path or AA bits
  81. BOOL ForcedPath; // was this CacheFaceRealization forced to use path because of huge font size
  82. // claudebe, try to get rid of both, redundant with fontObj flags : should correspond to what is actually realized
  83. TextRenderingHint realizationMethod;
  84. ULONG QueryFontDataMode;
  85. // Physical font information (font source).
  86. const GpFontFace *Face; // pointer to physical font entry
  87. // Font transform information.
  88. // DDI callback transform object. A reference to this EXFORMOBJ is passed
  89. // to the driver so that it can callback XFORMOBJ_ services for the notional
  90. // to device transform for this font.
  91. GpMatrix mxForDDI; // xoForDDI's matrix
  92. // cached here upon font realization for fast access
  93. ULONG MaxGlyphByteCount; // (MaxGlyphPixelWidth + 7)/8 * MaxGlyphPixelHeight, or at least it should be for 1 bpp
  94. FD_DEVICEMETRICS DeviceMetrics; // Hinted metric indformation
  95. // Root of per glyph metrics and images
  96. GpGlyphData **GlyphDataArray; // array of pointers to GpGlyphData's
  97. // CacheFaceRealization linked list for a particular face
  98. CacheFaceRealization *NextCacheFaceRealization;
  99. CacheFaceRealization *PreviousCacheFaceRealization;
  100. // CacheFaceRealization last recently used linked list
  101. CacheFaceRealization *NextRecentCacheFaceRealization;
  102. CacheFaceRealization *PreviousRecentCacheFaceRealization;
  103. // Font cache information.
  104. GlyphDataBlock *FirstGlyphDataBlock; // First block in chain - used for destruction
  105. GlyphBitsBlock *FirstGlyphBitsBlock;
  106. // Info for GlyphDataBlock being constructed
  107. GlyphDataBlock *GlyphDataBlockUnderConstruction;
  108. UINT NextFreeGlyphDataIndex; // (All other blocks are already full)
  109. // Info for GlyphBitBlock under construction
  110. GlyphBitsBlock *GlyphBitsBlockUnderConstruction;
  111. UINT SizeGlyphBitsBlockUnderConstruction; // Bytes allocated
  112. UINT UsedBytesGlyphBitsBlockUnderConstruction; // Bytes used
  113. // Lookaside cache - holds bits or path and metrics for a single glyph, used whern
  114. // data too big for cache block.
  115. GpGlyphData *LookasideGlyphData; // Same as GDI structure at this moment
  116. SIZE_T LookasideByteCount; // size of current lookaside buffer
  117. // claudebe : still need to be updated to use the global cache size limit :
  118. UINT cBlocksMax; // max # of blocks allowed
  119. UINT cBlocks; // # of blocks allocated so far
  120. };
  121. //// FaceRealization
  122. //
  123. // Represents a font at a given size (?on a given device?)
  124. class GpFaceRealization
  125. {
  126. private:
  127. mutable CacheFaceRealization *prface;
  128. GpStatus Status;
  129. INT Style;
  130. BOOL LimitSubpixel;
  131. public:
  132. // Constructors -- Lock the CacheFaceRealization.
  133. GpFaceRealization()
  134. : prface (NULL),
  135. Status (InvalidParameter)
  136. {}
  137. GpFaceRealization(
  138. const GpFontFace *pface,
  139. INT style,
  140. const GpMatrix *matrix,
  141. const SizeF dpi,
  142. TextRenderingHint renderMethod,
  143. BOOL bPath,
  144. BOOL bCompatibleWidth, /* we want ClearType compatible width when we come from DrawDriverString */
  145. BOOL bSideways /* for far east vertical writing, run of glyph layed out sideways,
  146. used to do the italic simulation in the right direction */
  147. );
  148. // Destructor -- Unlocks the CacheFaceRealization
  149. ~GpFaceRealization();
  150. // To clone another GpFaceRealiztion from Bits to Path
  151. void CloneFaceRealization(
  152. const GpFaceRealization * pfaceRealizaton,
  153. BOOL bPath
  154. );
  155. // GetStatus - Called following instantiation to check that construction worked.
  156. GpStatus GetStatus() const {return Status;}
  157. INT GetStyle() const
  158. {
  159. #if DBG
  160. INT style = 0;
  161. if ( prface->Face->pifi->fsSelection & FM_SEL_BOLD
  162. || prface->fobj.flFontType & FO_SIM_BOLD)
  163. {
  164. style |= FontStyleBold;
  165. }
  166. if ( prface->Face->pifi->fsSelection & FM_SEL_ITALIC
  167. || prface->fobj.flFontType & FO_SIM_ITALIC_SIDEWAYS
  168. || prface->fobj.flFontType & FO_SIM_ITALIC)
  169. {
  170. style |= FontStyleItalic;
  171. }
  172. ASSERT(style == (Style & (FontStyleBold | FontStyleItalic)));
  173. #endif
  174. return Style;
  175. }
  176. BOOL bInit(
  177. const GpFontFace *pface,
  178. INT style,
  179. const GpMatrix *matrix,
  180. SizeF dpi,
  181. TextRenderingHint textMode,
  182. BOOL bPath,
  183. BOOL bCompatibleWidth, /* we want ClearType compatible width when we come from DrawDriverString */
  184. BOOL bSideways /* for far east vertical writing, run of glyph layed out sideways,
  185. used to do the italic simulation in the right direction */
  186. );
  187. // bDelete -- Removes an CacheFaceRealization
  188. BOOL DeleteRealizedFace();
  189. // Reuse an CacheFaceRealization
  190. BOOL ReuseRealizedFace();
  191. // bInitCache -- Initialize the cache
  192. BOOL bInitCache() const;
  193. BOOL AllocateCache() const;
  194. // vDeleteCache -- Delete the CACHE from existence.
  195. VOID vDeleteCache() const;
  196. BOOL noCache() const {return prface->NoCache ;}
  197. // FindRealizedFace -- check to see whether there is existing realization
  198. // on the CacheFaceRealization list in the GpFontFile.
  199. BOOL FindRealizedFace(
  200. FD_XFORM *fdx,
  201. const GpFontFace *fontFace,
  202. BOOL needPaths,
  203. FLONG fl
  204. ) const;
  205. // RealizeFont -- Initializer; for IFI, calls driver to realize
  206. // font represented by PFE.
  207. BOOL Realize(
  208. SizeF dpi,
  209. const GpFontFace *pfe,
  210. INT style, // style - which may require simulation
  211. PFD_XFORM pfdx, // font xform (Notional to Device)
  212. FLONG fl, // these two really modify the xform
  213. BOOL bNeedPaths
  214. );
  215. // Valid -- Returns TRUE if object was successfully locked
  216. BOOL IsValid ()
  217. {
  218. return(prface != 0);
  219. }
  220. ULONG QueryFontDataMode() const
  221. {
  222. return prface->QueryFontDataMode;
  223. }
  224. BOOL bGetDEVICEMETRICS();
  225. // return the font face for this RFace
  226. const GpFontFace * GetFontFace() const {return(prface->Face);}
  227. // Is it in private font file table or not
  228. BOOL IsPrivate() const {return prface->Face->IsPrivate();}
  229. // pfdx -- Return pointer to the notional to device font transform.
  230. FD_XFORM *pfdx() const {return (&prface->fobj.fdx);}
  231. // pfo -- Return pointer to the font object
  232. FONTOBJ *pfo() const {return(&prface->fobj);}
  233. // kill driver realization of the font, i.e. "FONT CONTEXT" in the old lingo.
  234. // Method calling DrvDestroyFont before CacheFaceRealization is killed itself.
  235. VOID vDestroyRealizedFace();
  236. // vGetCache -- Claims the cache semaphore
  237. VOID vGetCache ()
  238. {
  239. // EnterCriticalSection(&prface->FaceRealizationCritSection);
  240. }
  241. // vReleaseCache -- Releases the cache semaphore
  242. VOID vReleaseCache ()
  243. {
  244. if ( prface->LookasideGlyphData != NULL )
  245. {
  246. GpFree((PVOID) prface->LookasideGlyphData);
  247. prface->LookasideByteCount = 0;
  248. prface->LookasideGlyphData = NULL;
  249. }
  250. // LeaveCriticalSection(&prface->FaceRealizationCritSection);
  251. }
  252. ULONG GetGlyphsSupported() const
  253. {
  254. if (prface && prface->Face)
  255. {
  256. return (prface->Face->NumGlyphs);
  257. }
  258. return 0;
  259. }
  260. GpStatus GetGlyphStringDeviceAdvanceVector(
  261. const UINT16 *glyphs,
  262. INT glyphCount,
  263. BOOL vertical,
  264. REAL *deviceAdvances
  265. ) const;
  266. GpStatus GetGlyphStringDeviceAdvanceVector(
  267. const UINT16 *glyphs,
  268. INT glyphCount,
  269. BOOL vertical,
  270. INT *deviceAdvances // Returned in 28.4
  271. ) const;
  272. GpStatus GetGlyphStringIdealAdvanceVector(
  273. const UINT16 *glyphs,
  274. INT glyphCount,
  275. REAL deviceToIdeal,
  276. BOOL vertical,
  277. INT *idealAdvances
  278. ) const;
  279. GpStatus GetGlyphStringSidebearings(
  280. const UINT16 *glyphs,
  281. INT glyphCount,
  282. BOOL vertical,
  283. BOOL reverse, // For example right-to-left
  284. INT *leadingSidebearing, // 28.4
  285. INT *trailingSidebearing // 28.4
  286. ) const;
  287. GpStatus GetGlyphStringVerticalOriginOffsets(
  288. IN const UINT16 *glyphs,
  289. IN INT glyphCount,
  290. OUT PointF *offsets
  291. ) const;
  292. // GetGlyphPath
  293. GpStatus
  294. GetGlyphPath(
  295. const UINT16 glyphIndice,
  296. GpGlyphPath **pGlyphPath,
  297. PointF *sidewaysOffset
  298. ) const;
  299. // GetGlyphPos
  300. INT GetGlyphPos(
  301. const INT cGlyphs, // How many glyphs Client want to request
  302. const UINT16 *glyphIndex, // An array of glyph index
  303. GpGlyphPos *pgpos, // An array of GLYPHPOS
  304. const PointF *glyphOrigin, // X,Y positions for sub-pixel calculation
  305. INT *cParsed, // How many glyphs we parsed
  306. BOOL sideways // e.g. FE characters in vertical text
  307. ) const;
  308. // Realization mode
  309. inline TextRenderingHint RealizationMethod() const {return(prface->realizationMethod);}
  310. // IisPathFont -- Is this a path font?
  311. inline BOOL IsPathFont() const {return(prface->CacheType == CachePath);}
  312. VOID FlushCache() const;
  313. // Construction hack used by GpFaceRealizationTMP during CacheFaceRealization cleanup
  314. void Setprface(CacheFaceRealization *rface) {prface = rface;}
  315. CacheFaceRealization *Getprface() const {return prface;}
  316. INT GetXMin() const {return prface->DeviceMetrics.xMin;};
  317. INT GetXMax() const {return prface->DeviceMetrics.xMax;};
  318. INT GetYMin() const {return prface->DeviceMetrics.yMin;};
  319. INT GetYMax() const {return prface->DeviceMetrics.yMax;};
  320. BOOL IsHorizontalTransform() const {return prface->DeviceMetrics.HorizontalTransform;};
  321. BOOL IsVerticalTransform() const {return prface->DeviceMetrics.VerticalTransform;};
  322. BOOL IsFixedPitch() const {return (prface->Face->pifi->flInfo & FM_INFO_OPTICALLY_FIXED_PITCH);};
  323. BOOL GetLimitSubpixel() { return LimitSubpixel; }
  324. void SetLimitSubpixel(BOOL limitSubpixel) { LimitSubpixel = limitSubpixel; }
  325. private:
  326. GpStatus CheckGlyphStringMetricsCached(const UINT16 *glyphs, INT glyphCount) const;
  327. // vInsert -- Insert this CacheFaceRealization onto the head of an CacheFaceRealization doubly linked list.
  328. VOID vInsert (CacheFaceRealization **pprfaceHead);
  329. // vRemove -- Remove this CacheFaceRealization from an CacheFaceRealization doubly linked list.
  330. VOID vRemove (CacheFaceRealization **pprfaceHead);
  331. // Access to cached glyph data
  332. GpGlyphData *GetGlyphDataCached(UINT16 glyphIndex, BOOL allowFlush) const;
  333. GpGlyphData *GetGlyphDataLookaside(UINT16 glyphIndex) const;
  334. BOOL CheckMetricsCache() const;
  335. VOID *pgbCheckGlyphCache(SIZE_T cjNeeded) const;
  336. VOID ConvertGLYPHDATAToGpGlyphMetrics(
  337. IN INT glyphIndex,
  338. IN GLYPHDATA *pgd,
  339. OUT GpGlyphData *pgpgd
  340. ) const;
  341. GpStatus IsMetricsCached(UINT16 glyph, ULONG * pcjNeeded) const;
  342. BOOL InsertGlyphBits(UINT16 glyph, ULONG cjNeeded, BOOL bFlushOk) const;
  343. BOOL InsertGlyphPath(UINT16 glyph, BOOL allowFlush) const;
  344. // bMatchFDXForm -- Is pfdx identical to current font xform?
  345. inline BOOL MatchFDXForm(FD_XFORM *pfdx) const
  346. {
  347. return(!memcmp((PBYTE)pfdx, (PBYTE)&prface->fobj.fdx, sizeof(FD_XFORM)));
  348. }
  349. // Calculating sub-pixel position
  350. BOOL GetAAGlyphDataCached(
  351. UINT16 glyphIndex,
  352. GpGlyphPos * pgpos,
  353. BOOL allowFlush,
  354. INT x,
  355. INT y,
  356. BOOL sideways // e.g. FE characters in vertical text
  357. ) const;
  358. };
  359. class GpFaceRealizationTMP : public GpFaceRealization
  360. {
  361. public:
  362. GpFaceRealizationTMP(CacheFaceRealization *_prface) {Setprface(_prface);}
  363. ~GpFaceRealizationTMP() {Setprface(NULL);}
  364. };
  365. class GpCacheFaceRealizationList
  366. {
  367. public:
  368. GpCacheFaceRealizationList() { head = NULL; count = 0; }
  369. ~GpCacheFaceRealizationList();
  370. void AddMostRecent(CacheFaceRealization *prface);
  371. void RemoveFace(CacheFaceRealization *prface);
  372. CacheFaceRealization *ReuseLeastRecent (void);
  373. INT GetCount() {return count; }
  374. private:
  375. CacheFaceRealization *head;
  376. INT count;
  377. };
  378. #endif // __FACEREALIZATION__