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.

218 lines
7.1 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. * Copyright (c) 1995-2000 Microsoft Corporation. All rights reserved.
  13. */
  14. #ifndef _MEASURE_H
  15. #define _MEASURE_H
  16. #include "_rtext.h"
  17. #include "_line.h"
  18. #include "_disp.h"
  19. #ifndef NOLINESERVICES
  20. #include "_ols.h"
  21. #endif
  22. class CCcs;
  23. class CDevDesc;
  24. class CPartialUpdate;
  25. class CUniscribe;
  26. class COleObject;
  27. const short BITMAP_WIDTH_SUBTEXT = 4;
  28. const short BITMAP_HEIGHT_SUBTEXT = 4;
  29. const short BITMAP_WIDTH_HEADING = 10;
  30. const short BITMAP_HEIGHT_HEADING = 10;
  31. #define TA_STARTOFLINE 32768
  32. #define TA_ENDOFLINE 16384
  33. #define TA_LOGICAL 8192
  34. #define TA_CELLTOP 4096
  35. // =========================== CMeasurer ===============================
  36. // CMeasurer - specialized rich text pointer used to compute text metrics.
  37. // All metrics are computed and stored in device units for the device
  38. // indicated by _pdd.
  39. class CMeasurer : public CRchTxtPtr
  40. {
  41. friend class CLayout;
  42. friend class CDisplay;
  43. friend class CDisplayML;
  44. friend class CDisplayPrinter;
  45. friend class CDisplaySL;
  46. friend class CLine;
  47. friend struct COls;
  48. friend class CUniscribe;
  49. #ifndef NOLINESERVICES
  50. friend LSERR WINAPI OlsOleFmt(PLNOBJ plnobj, PCFMTIN pcfmtin, FMTRES *pfmres);
  51. friend LSERR WINAPI OlsGetRunTextMetrics(POLS pols, PLSRUN plsrun,
  52. enum lsdevice deviceID, LSTFLOW kTFlow, PLSTXM plsTxMet);
  53. friend LSERR WINAPI OlsFetchPap(POLS pols, LSCP cpLs, PLSPAP plspap);
  54. friend LSERR WINAPI OlsGetRunCharKerning(POLS, PLSRUN, LSDEVICE, LPCWSTR, DWORD, LSTFLOW, int*);
  55. friend LSERR WINAPI OlsFetchTabs(POLS, LSCP, PLSTABS, BOOL*,long *, WCHAR*);
  56. #endif
  57. public:
  58. CMeasurer (const CDisplay* const pdp);
  59. CMeasurer (const CDisplay* const pdp, const CRchTxtPtr &rtp);
  60. virtual ~CMeasurer();
  61. const CDisplay* GetPdp() const {return _pdp;}
  62. void AdjustLineHeight();
  63. COleObject *GetObjectFromCp(LONG cp) const
  64. {return GetPed()->GetObjectMgr()->GetObjectFromCp(cp);}
  65. #ifndef NOLINESERVICES
  66. COls * GetPols();
  67. CUniscribe* Getusp() const { return GetPed()->Getusp(); }
  68. #endif
  69. CCcs* GetCcs(const CCharFormat *pCF);
  70. CCcs* GetCcsFontFallback(const CCharFormat *pCF, WORD wScript);
  71. CCcs* ApplyFontCache(BOOL fFallback, WORD wScript);
  72. void CheckLineHeight();
  73. CCcs * Check_pccs(BOOL fBullet = FALSE);
  74. LONG GetNumber() const {return _wNumber;}
  75. WCHAR GetPasswordChar() const {return _chPassword;}
  76. const CParaFormat *Get_pPF() {return _pPF;}
  77. LONG GetCch() const {return _li._cch;}
  78. void SetCch(LONG cch) {_li._cch = cch;}
  79. CLine & GetLine(void) {return _li;}
  80. LONG GetRightIndent() {return _upRight;}
  81. HITTEST HitTest(LONG x);
  82. BOOL fFirstInPara() const {return _li._fFirstInPara;}
  83. BOOL fUseLineServices() const {return GetPed()->fUseLineServices();}
  84. BOOL IsRenderer() const {return _fRenderer;}
  85. BOOL IsMeasure() const {return _fMeasure;}
  86. LONG LUtoDU(LONG u) { return MulDiv(u, _fTarget ? _durInch : _dupInch, LX_PER_INCH);}
  87. LONG LVtoDV(LONG v) { return MulDiv(v, _fTarget ? _dvrInch : _dvpInch, LX_PER_INCH);}
  88. const CLayout *GetLayout() {return _plo;}
  89. void SetLayout(const CLayout *plo) {_plo = plo;}
  90. LONG GetDulLayout() {return _dulLayout;}
  91. LONG GetCchLine() const {return _cchLine;}
  92. LONG GetPBorderWidth(LONG dxlLine);
  93. void SetDulLayout(LONG dul) {_dulLayout = dul;}
  94. void SetIhyphPrev(LONG ihyphPrev) {_ihyphPrev = ihyphPrev;}
  95. LONG GetIhyphPrev(void) {return _ihyphPrev;}
  96. TFLOW GetTflow() const {return _pdp->GetTflow();}
  97. void NewLine(BOOL fFirstInPara);
  98. void NewLine(const CLine &li);
  99. LONG MeasureLeftIndent();
  100. LONG MeasureRightIndent();
  101. LONG MeasureLineShift();
  102. LONG MeasureText(LONG cch);
  103. BOOL MeasureLine(UINT uiFlags, CLine* pliTarget = NULL);
  104. LONG MeasureTab(unsigned ch);
  105. void SetNumber(WORD wNumber);
  106. void UpdatePF() {_pPF = GetPF();}
  107. LONG XFromU(LONG u);
  108. LONG UFromX(LONG x);
  109. CCcs* GetCcsBullet(CCharFormat *pcfRet);
  110. void SetUseTargetDevice(BOOL fUseTargetDevice);
  111. BOOL FUseTargetDevice(void) {return _fTarget || _dvpInch == _dvrInch;}
  112. BOOL FAdjustFELineHt() {return !(GetPed()->Get10Mode()) && !fUseUIFont() && _pdp->IsMultiLine();}
  113. void SetGlyphing(BOOL fGlyphing);
  114. protected:
  115. void Init(const CDisplay *pdp);
  116. LONG Measure(LONG dulMax, LONG cchMax, UINT uiFlags);
  117. LONG MeasureBullet();
  118. LONG GetBullet(WCHAR *pch, CCcs *pccs, LONG *pdup);
  119. void UpdateWrapState(USHORT &dvpLine, USHORT &dvpDescent);
  120. void UpdateWrapState(USHORT &dvpLine, USHORT &dvpDescent, BOOL fLeft);
  121. BOOL FormatIsChanged();
  122. void ResetCachediFormat();
  123. LONG DUtoLU(LONG u) {return MulDiv(u, LX_PER_INCH, _fTarget ? _durInch : _dupInch);}
  124. LONG FindCpDraw(LONG cpStart, int cobjectPrev, BOOL fLeft);
  125. private:
  126. void RecalcLineHeight(CCcs *,
  127. const CCharFormat * const pCF); // Helper to recalc max line height
  128. COleObject* FindFirstWrapObj(BOOL fLeft);
  129. void RemoveFirstWrap(BOOL fLeft);
  130. int CountQueueEntries(BOOL fLeft);
  131. void AddObjectToQueue(COleObject *pobjAdd);
  132. protected:
  133. CLine _li; // Line we are measuring
  134. const CDisplay* _pdp; // Display we are operating in
  135. const CDevDesc* _pddReference; // Reference device
  136. CArray<COleObject*> _rgpobjWrap;// A queue of objects to wrapped around
  137. LONG _dvpWrapLeftRemaining; //For objects being wrapped around,
  138. LONG _dvpWrapRightRemaining; //how much of the height is remaining
  139. LONG _dvrInch; // Resolution of reference device
  140. LONG _durInch;
  141. LONG _dvpInch; // Resolution of presentation device
  142. LONG _dupInch;
  143. LONG _dulLayout; // Width of layout we are measuring in
  144. LONG _cchLine; // If !_fMeasure, tells us number of chars on line
  145. CCcs* _pccs; // Current font cache
  146. const CParaFormat *_pPF; // Current CParaFormat
  147. const CLayout *_plo; // Current layout we are measuring in (0 if SL)
  148. LONG _dxBorderWidths;// Cell border widths
  149. SHORT _dupAddLast; // Last char considered but unused for line
  150. WCHAR _chPassword; // Password character if any
  151. WORD _wNumber; // Number offset
  152. SHORT _iFormat; // Current format
  153. SHORT _upRight; // Line right indent
  154. BYTE _ihyphPrev; // Hyphenation information for previous line
  155. // Used for support of khyphChangeAfter
  156. BYTE _fRenderer:1; // 0/1 for CMeasurer/CRenderer, resp.
  157. BYTE _fTarget:1; // TRUE if we are supposed to be using
  158. // reference metrics for laying out text
  159. BYTE _fFallback:1; // Current font cache is fallback font
  160. BYTE _fGlyphing:1; // In the process of creating glyphs
  161. BYTE _fMeasure:1; // TRUE if we are measuring. Else, we are
  162. // rendering or we are hit-testing which means we need
  163. // to justify the text and that data cached at measure time is valid.
  164. };
  165. // Values for uiFlags in MeasureLine()
  166. #define MEASURE_FIRSTINPARA 0x0001
  167. #define MEASURE_BREAKATWORD 0x0002
  168. #define MEASURE_BREAKBEFOREWIDTH 0x0004 // Breaks at character before target width
  169. #define MEASURE_IGNOREOFFSET 0x0008
  170. // Returned error codes for Measure(), MeasureText(), MeasureLine()
  171. #define MRET_FAILED -1
  172. #define MRET_NOWIDTH -2
  173. inline BOOL CMeasurer::FormatIsChanged()
  174. {
  175. return !_pccs || _iFormat != _rpCF.GetFormat() || _fFallback;
  176. }
  177. inline void CMeasurer::ResetCachediFormat()
  178. {
  179. _iFormat = _rpCF.GetFormat();
  180. }
  181. const int duMax = tomForward;
  182. #endif