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.

239 lines
7.0 KiB

  1. /******************************Module*Header*******************************\
  2. * Module Name: pathflat.hxx
  3. *
  4. * Path flattening defines.
  5. *
  6. * Created: 9-Oct-1991
  7. * Author: J. Andrew Goossen [andrewgo]
  8. *
  9. * Copyright (c) 1991-1999 Microsoft Corporation
  10. \**************************************************************************/
  11. // Flatten to an error of 2/3. During initial phase, use 18.14 format.
  12. #define TEST_MAGNITUDE_INITIAL (6 * 0x00002aa0L)
  13. // Error of 2/3. During normal phase, use 15.17 format.
  14. #define TEST_MAGNITUDE_NORMAL (TEST_MAGNITUDE_INITIAL << 3)
  15. /**********************************Class***********************************\
  16. * class HFDBASIS32
  17. *
  18. * Class for HFD vector objects.
  19. *
  20. * Public Interface:
  21. *
  22. * vInit(p1, p2, p3, p4) - Re-parameterizes the given control points
  23. * to our initial HFD error basis.
  24. * vLazyHalveStepSize(cShift) - Does a lazy shift. Caller has to remember
  25. * it changes 'cShift' by 2.
  26. * vSteadyState(cShift) - Re-parameterizes to our working normal
  27. * error basis.
  28. *
  29. * vTakeStep() - Forward steps to next sub-curve
  30. * vHalveStepSize() - Adjusts down (subdivides) the sub-curve
  31. * vDoubleStepSize() - Adjusts up the sub-curve
  32. * lError() - Returns error if current sub-curve were
  33. * to be approximated using a straight line
  34. * (value is actually multiplied by 6)
  35. * fxValue() - Returns rounded coordinate of first point in
  36. * current sub-curve. Must be in steady
  37. * state.
  38. *
  39. * History:
  40. * 10-Nov-1990 -by- J. Andrew Goossen [andrewgo]
  41. * Wrote it.
  42. \**************************************************************************/
  43. class HFDBASIS32
  44. {
  45. private:
  46. LONG e0;
  47. LONG e1;
  48. LONG e2;
  49. LONG e3;
  50. public:
  51. VOID vInit(FIX p1, FIX p2, FIX p3, FIX p4);
  52. VOID vLazyHalveStepSize(LONG cShift);
  53. VOID vSteadyState(LONG cShift);
  54. VOID vHalveStepSize();
  55. VOID vDoubleStepSize();
  56. VOID vTakeStep();
  57. LONG lParentErrorDividedBy4() { return(MAX(ABS(e3), ABS(e2 + e2 - e3))); }
  58. LONG lError() { return(MAX(ABS(e2), ABS(e3))); }
  59. FIX fxValue() { return((e0 + (1L << 12)) >> 13); }
  60. };
  61. /**********************************Class***********************************\
  62. * class BEZIER32
  63. *
  64. * Bezier cracker.
  65. *
  66. * A hybrid cubic Bezier curve flattener based on KirkO's error factor.
  67. * Generates line segments fast without using the stack. Used to flatten
  68. * a path.
  69. *
  70. * For an understanding of the methods used, see:
  71. *
  72. * Kirk Olynyk, "..."
  73. * Goossen and Olynyk, "System and Method of Hybrid Forward
  74. * Differencing to Render Bezier Splines"
  75. * Lien, Shantz and Vaughan Pratt, "Adaptive Forward Differencing for
  76. * Rendering Curves and Surfaces", Computer Graphics, July 1987
  77. * Chang and Shantz, "Rendering Trimmed NURBS with Adaptive Forward
  78. * Differencing", Computer Graphics, August 1988
  79. * Foley and Van Dam, "Fundamentals of Interactive Computer Graphics"
  80. *
  81. * Public Interface:
  82. *
  83. * vInit(pptfx) - pptfx points to 4 control points of
  84. * Bezier. Current point is set to the first
  85. * point after the start-point.
  86. * BEZIER32(pptfx) - Constructor with initialization.
  87. * vGetCurrent(pptfx) - Returns current polyline point.
  88. * bCurrentIsEndPoint() - TRUE if current point is end-point.
  89. * vNext() - Moves to next polyline point.
  90. *
  91. * History:
  92. * 1-Oct-1991 -by- J. Andrew Goossen [andrewgo]
  93. * Wrote it.
  94. \**************************************************************************/
  95. extern LONGLONG* gpeqErrorHigh;
  96. extern LONGLONG* gpeqErrorLow;
  97. class BEZIER32
  98. {
  99. //private:
  100. public:
  101. LONG cSteps;
  102. HFDBASIS32 x;
  103. HFDBASIS32 y;
  104. RECTFX rcfxBound;
  105. public:
  106. BOOL bInit(POINTFIX* aptfx, RECTFX*);
  107. BOOL bNext(POINTFIX* pptfx);
  108. };
  109. #define FRACTION64 28
  110. class HFDBASIS64
  111. {
  112. private:
  113. LONGLONG e0;
  114. LONGLONG e1;
  115. LONGLONG e2;
  116. LONGLONG e3;
  117. public:
  118. VOID vInit(FIX p1, FIX p2, FIX p3, FIX p4);
  119. VOID vHalveStepSize();
  120. VOID vDoubleStepSize();
  121. VOID vTakeStep();
  122. VOID vUntransform(FIX* afx);
  123. VOID vParentError(LONGLONG* peq);
  124. VOID vError(LONGLONG* peq);
  125. FIX fxValue();
  126. };
  127. class BEZIER64
  128. {
  129. //private:
  130. public:
  131. HFDBASIS64 xLow;
  132. HFDBASIS64 yLow;
  133. HFDBASIS64 xHigh;
  134. HFDBASIS64 yHigh;
  135. LONGLONG eqErrorLow;
  136. RECTFX* prcfxClip;
  137. RECTFX rcfxClip;
  138. LONG cStepsHigh;
  139. LONG cStepsLow;
  140. //public:
  141. BOOL bNext(POINTFIX* pptfx);
  142. VOID vInit(POINTFIX* aptfx, RECTFX* prcfx, LONGLONG* peq);
  143. };
  144. /**********************************Class***********************************\
  145. * class BEZIER
  146. *
  147. * Bezier cracker. Flattens any Bezier in our 28.4 device space down
  148. * to a smallest 'error' of 2^-7 = 0.0078. Will use fast 32 bit cracker
  149. * for small curves and slower 64 bit cracker for big curves.
  150. *
  151. * Public Interface:
  152. *
  153. * vInit(aptfx, prcfxClip, peqError)
  154. * - pptfx points to 4 control points of Bezier. The first point
  155. * retrieved by bNext() is the the first point in the approximation
  156. * after the start-point.
  157. *
  158. * - prcfxClip is an optional pointer to the bound box of the visible
  159. * region. This is used to optimize clipping of Bezier curves that
  160. * won't be seen. Note that this value should account for the pen's
  161. * width!
  162. *
  163. * - optional maximum error in 32.32 format, corresponding to Kirko's
  164. * error factor.
  165. *
  166. * bNext(pptfx)
  167. * - pptfx points to where next point in approximation will be
  168. * returned. Returns FALSE if the point is the end-point of the
  169. * curve.
  170. *
  171. * History:
  172. * 1-Oct-1991 -by- J. Andrew Goossen [andrewgo]
  173. * Wrote it.
  174. \**************************************************************************/
  175. class BEZIER
  176. {
  177. private:
  178. //
  179. // Can't do a straight union of BEZIER32 and BEZIER64 here because
  180. // C++ doesn't like the static constructors and destructors of the
  181. // EQUADs:
  182. //
  183. // Note:
  184. //
  185. union
  186. {
  187. BEZIER64 bez64;
  188. BEZIER32 bez32;
  189. } bez;
  190. BOOL bBez32;
  191. public:
  192. BEZIER() {}
  193. VOID vInit(POINTFIX* aptfx,
  194. RECTFX* prcfxClip = (RECTFX*) NULL,
  195. LONGLONG* peqError = gpeqErrorLow)
  196. {
  197. bBez32 = (peqError == gpeqErrorLow &&
  198. bez.bez32.bInit(aptfx, prcfxClip));
  199. if (!bBez32)
  200. bez.bez64.vInit(aptfx, prcfxClip, peqError);
  201. }
  202. BOOL bNext(POINTFIX* pptfx)
  203. {
  204. return(bBez32 ?
  205. bez.bez32.bNext(pptfx) :
  206. bez.bez64.bNext(pptfx));
  207. }
  208. };