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.

181 lines
5.0 KiB

  1. /*
  2. * _MEASURE.H
  3. *
  4. * Purpose:
  5. * CMeasurer class
  6. *
  7. * Authors:
  8. * Original RichEdit code: David R. Fulmer
  9. * Christian Fortini
  10. * Murray Sargent
  11. */
  12. #ifndef _MEASURE_H
  13. #define _MEASURE_H
  14. #include "_rtext.h"
  15. #include "_line.h"
  16. #include "_disp.h"
  17. #ifdef LINESERVICES
  18. #include "_ols.h"
  19. #endif
  20. class CCcs;
  21. class CDevDesc;
  22. class CPartialUpdate;
  23. class CUniscribe;
  24. const short BITMAP_WIDTH_SUBTEXT = 4;
  25. const short BITMAP_HEIGHT_SUBTEXT = 4;
  26. const short BITMAP_WIDTH_HEADING = 10;
  27. const short BITMAP_HEIGHT_HEADING = 10;
  28. #define TA_STARTOFLINE 32768
  29. #define TA_ENDOFLINE 16384
  30. #define TA_LOGICAL 8192
  31. // =========================== CMeasurer ===============================
  32. // CMeasurer - specialized rich text pointer used to compute text metrics.
  33. // All metrics are computed and stored in device units for the device
  34. // indicated by _pdd.
  35. class CMeasurer : public CRchTxtPtr
  36. {
  37. friend class CDisplay;
  38. friend class CDisplayML;
  39. friend class CDisplayPrinter;
  40. friend class CDisplaySL;
  41. friend class CLine;
  42. friend struct COls;
  43. friend class CUniscribe;
  44. public:
  45. CMeasurer (const CDisplay* const pdp);
  46. CMeasurer (const CDisplay* const pdp, const CRchTxtPtr &rtp);
  47. virtual ~CMeasurer();
  48. const CDisplay* GetPdp() const {return _pdp;}
  49. void AdjustLineHeight();
  50. LONG GetDyrInch() {return _dyrInch;}
  51. LONG GetDxrInch() {return _dxrInch;}
  52. LONG GetDypInch() {return _dypInch;}
  53. LONG GetDxpInch() {return _dxpInch;}
  54. #ifdef LINESERVICES
  55. COls * GetPols(CMeasurer **ppme);
  56. CUniscribe* Getusp() const { return GetPed()->Getusp(); }
  57. #endif
  58. CCcs* GetCcs(const CCharFormat *pCF);
  59. CCcs* GetCcsFontFallback(const CCharFormat *pCF);
  60. CCcs* ApplyFontCache(BOOL fFallback);
  61. void CheckLineHeight();
  62. CCcs * Check_pccs(BOOL fBullet = FALSE);
  63. LONG GetNumber() const {return _wNumber;}
  64. WCHAR GetPasswordChar() const {return _chPassword;}
  65. const CParaFormat *Get_pPF() {return _pPF;}
  66. LONG GetCch() const {return _li._cch;}
  67. void SetCch(LONG cch) {_li._cch = cch;}
  68. CLine & GetLine(void) {return _li;}
  69. HITTEST HitTest(LONG x);
  70. BOOL fFirstInPara() const {return _li._bFlags & fliFirstInPara;}
  71. BOOL fUseLineServices() const {return GetPed()->fUseLineServices();}
  72. BOOL IsRenderer() const {return _fRenderer;}
  73. LONG LXtoDX(LONG x);
  74. LONG LYtoDY(LONG y);
  75. void NewLine(BOOL fFirstInPara);
  76. void NewLine(const CLine &li);
  77. LONG MeasureLeftIndent();
  78. LONG MeasureRightIndent();
  79. LONG MeasureLineShift();
  80. LONG MeasureText(LONG cch);
  81. BOOL MeasureLine(
  82. LONG cchMax,
  83. LONG xWidthMax,
  84. UINT uiFlags,
  85. CLine* pliTarget = NULL);
  86. LONG MeasureTab(unsigned ch);
  87. void SetNumber(WORD wNumber);
  88. void UpdatePF() {_pPF = GetPF();}
  89. LONG XFromU(LONG u);
  90. LONG UFromX(LONG x);
  91. CCcs* GetCcsBullet(CCharFormat *pcfRet);
  92. void SetUseTargetDevice(BOOL fUseTargetDevice);
  93. BOOL FUseTargetDevice(void) {return _fTarget || _dypInch == _dyrInch;}
  94. BOOL fAdjustFELineHt() {return _fAdjustFELineHt;}
  95. void SetGlyphing(BOOL fGlyphing);
  96. protected:
  97. void Init(const CDisplay *pdp);
  98. LONG Measure(LONG xWidthMax, LONG cchMax, UINT uiFlags);
  99. LONG MeasureBullet();
  100. LONG GetBullet(WCHAR *pch, CCcs *pccs, LONG *pxWidth);
  101. BOOL FormatIsChanged();
  102. void ResetCachediFormat();
  103. LONG DXtoLX(LONG x);
  104. private:
  105. void RecalcLineHeight(CCcs *,
  106. const CCharFormat * const pCF); // Helper to recalc max line height
  107. LONG MaxWidth(); // Helper for calc max width
  108. protected:
  109. CLine _li; // Line we are measuring
  110. const CDevDesc* _pddReference; // Reference device
  111. LONG _dyrInch; // Resolution of reference device
  112. LONG _dxrInch;
  113. const CDisplay* _pdp; // Display we are operating in
  114. LONG _dypInch; // Resolution of presentation device
  115. LONG _dxpInch;
  116. CCcs* _pccs; // Current font cache
  117. const CParaFormat *_pPF; // Current CParaFormat
  118. SHORT _xAddLast; // Last char considered but unused for line
  119. WCHAR _chPassword; // Password character if any
  120. WORD _wNumber; // Number offset
  121. SHORT _iFormat; // Current format
  122. BYTE _dtRef; // Device Caps technology for reference device
  123. BYTE _dtPres; // Device Caps technology for presentation device
  124. BYTE _fRenderer:1; // 0/1 for CMeasurer/CRenderer, resp.
  125. BYTE _fTarget:1; // TRUE if we are supposed to be using
  126. // reference metrics for laying out text
  127. BYTE _fAdjustFELineHt:1; // TRUE if we need to adjust line height
  128. // for FE run
  129. BYTE _fFallback:1; // Current font cache is fallback font
  130. BYTE _fGlyphing:1; // In the process of creating glyphs
  131. };
  132. // Values for uiFlags in MeasureLine()
  133. #define MEASURE_FIRSTINPARA 0x0001
  134. #define MEASURE_BREAKATWORD 0x0002
  135. #define MEASURE_BREAKBEFOREWIDTH 0x0004 // Breaks at character before target width
  136. #define MEASURE_IGNOREOFFSET 0x0008
  137. #define MEASURE_DONTINIT 0x0020
  138. // Returned error codes for Measure(), MeasureText(), MeasureLine()
  139. #define MRET_FAILED -1
  140. #define MRET_NOWIDTH -2
  141. inline BOOL CMeasurer::FormatIsChanged()
  142. {
  143. return !_pccs || _iFormat != _rpCF.GetFormat() || _fFallback;
  144. }
  145. inline void CMeasurer::ResetCachediFormat()
  146. {
  147. _iFormat = _rpCF.GetFormat();
  148. }
  149. #endif