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.

453 lines
11 KiB

  1. /**************************************************************************\
  2. *
  3. * Copyright (c) 1999 Microsoft Corporation
  4. *
  5. * Module Name:
  6. *
  7. * PathWidener.hpp
  8. *
  9. * Abstract:
  10. *
  11. * Class used for Path widening
  12. *
  13. * Revision History:
  14. *
  15. * 11/24/99 ikkof
  16. * Created it.
  17. *
  18. \**************************************************************************/
  19. #ifndef _PATHWIDENER_HPP
  20. #define _PATHWIDENER_HPP
  21. enum GpLineCapMode
  22. {
  23. LineCapDefaultMode = 0,
  24. LineCapDashMode = 1
  25. };
  26. class GpPathWidener
  27. {
  28. private:
  29. // We now use an ObjectTag to determine if the object is valid
  30. // instead of using a BOOL. This is much more robust and helps
  31. // with debugging. It also enables us to version our objects
  32. // more easily with a version number in the ObjectTag.
  33. ObjectTag Tag; // Keep this as the 1st value in the object!
  34. protected:
  35. VOID SetValid(BOOL valid)
  36. {
  37. Tag = valid ? ObjectTagPathWidener : ObjectTagInvalid;
  38. }
  39. public:
  40. GpPathWidener(
  41. const GpPointF* points,
  42. const BYTE* types,
  43. INT count,
  44. const DpPen* pen,
  45. const GpMatrix* matrix,
  46. REAL dpiX,
  47. REAL dpiY,
  48. BOOL isAntiAliased,
  49. BOOL isInsetPen = FALSE
  50. )
  51. {
  52. Initialize(
  53. points,
  54. types,
  55. count,
  56. pen,
  57. matrix,
  58. dpiX,
  59. dpiY,
  60. isAntiAliased,
  61. isInsetPen
  62. );
  63. }
  64. GpPathWidener(
  65. GpPath *path,
  66. const DpPen* pen,
  67. const GpMatrix* matrix,
  68. REAL dpiX,
  69. REAL dpiY,
  70. BOOL isAntiAliased,
  71. BOOL isInsetPen = FALSE
  72. )
  73. {
  74. const GpPointF* points = path->GetPathPoints();
  75. const BYTE* types = path->GetPathTypes();
  76. INT count = path->GetPointCount();
  77. Initialize(
  78. points,
  79. types,
  80. count,
  81. pen,
  82. matrix,
  83. dpiX,
  84. dpiY,
  85. isAntiAliased,
  86. isInsetPen
  87. );
  88. }
  89. GpPathWidener(
  90. const GpPointF* points,
  91. const BYTE* types,
  92. INT count,
  93. const DpPen* pen,
  94. const GpMatrix* matrix,
  95. REAL dpiX,
  96. REAL dpiY,
  97. BOOL isAntiAliased,
  98. BYTE* centerTypesBuffer,
  99. GpPointF* centerPointsBuffer,
  100. GpPointF* gradientsBuffer,
  101. GpPointF* normalsBuffer,
  102. BYTE* leftTypesBuffer,
  103. GpPointF* leftPointsBuffer,
  104. BYTE* rightTypesBuffer,
  105. GpPointF* rightPointsBuffer,
  106. INT bufferCount,
  107. BOOL isInsetPen = FALSE
  108. ) : CenterTypes(centerTypesBuffer, bufferCount),
  109. CenterPoints(centerPointsBuffer, bufferCount),
  110. Gradients(gradientsBuffer, bufferCount),
  111. Normals(normalsBuffer, bufferCount),
  112. LeftTypes(leftTypesBuffer, bufferCount),
  113. LeftPoints(leftPointsBuffer, bufferCount),
  114. RightTypes(rightTypesBuffer, bufferCount),
  115. RightPoints(rightPointsBuffer, bufferCount)
  116. {
  117. Initialize(points, types, count, pen, matrix, dpiX, dpiY,
  118. isAntiAliased, isInsetPen);
  119. }
  120. ~GpPathWidener()
  121. {
  122. SetValid(FALSE); // so we don't use a deleted object
  123. }
  124. GpStatus Widen(
  125. DynPointFArray* widenedPoints,
  126. DynByteArray* widenedTypes
  127. );
  128. GpStatus Widen(GpPath **path);
  129. BOOL IsValid() const
  130. {
  131. ASSERT((Tag == ObjectTagPathWidener) || (Tag == ObjectTagInvalid));
  132. #if DBG
  133. if (Tag == ObjectTagInvalid)
  134. {
  135. WARNING1("Invalid PathWidener");
  136. }
  137. #endif
  138. return (Tag == ObjectTagPathWidener);
  139. }
  140. REAL GetPenDelta();
  141. protected:
  142. VOID Initialize(
  143. const GpPointF* points,
  144. const BYTE* types,
  145. INT count,
  146. const DpPen* pen,
  147. const GpMatrix* matrix,
  148. REAL dpiX,
  149. REAL dpiY,
  150. BOOL isAntiAliased,
  151. BOOL isInsetPen = FALSE
  152. );
  153. GpStatus WidenSubpath(
  154. DynPointFArray* widenedPoints,
  155. DynByteArray* widenedTypes,
  156. REAL leftWidth,
  157. REAL rightWidth,
  158. INT startIndex,
  159. INT endIndex,
  160. BOOL isClosed,
  161. GpLineCap startCap,
  162. GpLineCap endCap,
  163. BOOL useBevelJoinInside
  164. );
  165. GpStatus CalculateGradients(
  166. INT startIndex,
  167. INT endIndex
  168. );
  169. GpStatus CalculateNormals(
  170. REAL leftWidth,
  171. REAL rightWidth
  172. );
  173. GpStatus SetPolygonJoin(
  174. REAL leftWidth,
  175. REAL rightWidth,
  176. BOOL isAntialiased
  177. );
  178. GpStatus SetStartCapInset(
  179. REAL inset
  180. )
  181. {
  182. Inset1 = inset;
  183. return Ok;
  184. }
  185. GpStatus SetEndCapInset(
  186. REAL inset
  187. )
  188. {
  189. Inset2 = inset;
  190. return Ok;
  191. }
  192. VOID WidenFirstPoint(
  193. REAL leftWidth,
  194. REAL rightWidth,
  195. GpLineJoin lineJoin,
  196. REAL miterLimit2,
  197. GpPointF* leftPoints,
  198. BYTE* leftTypes,
  199. INT* addedLeftCount,
  200. GpPointF* rightPoints,
  201. BYTE* rightTypes,
  202. INT* addedRightCount,
  203. GpPointF* leftEndPt,
  204. GpPointF* rightEndPt,
  205. const GpPointF* grad,
  206. const GpPointF* norm,
  207. const GpPointF* dataPoints,
  208. INT dataCount,
  209. GpPointF* lastPt,
  210. const REAL* firstInsets,
  211. INT flag
  212. );
  213. GpStatus
  214. WidenEachPathType(
  215. BYTE pathType,
  216. REAL leftWidth,
  217. REAL rightWidth,
  218. GpLineJoin lineJoin,
  219. REAL miterLimit2,
  220. GpPointF* leftPoints,
  221. BYTE* leftTypes,
  222. INT* addedLeftCount,
  223. GpPointF* rightPoints,
  224. BYTE* rightTypes,
  225. INT* addedRightCount,
  226. const GpPointF* grad,
  227. const GpPointF* norm,
  228. const GpPointF* dataPoints,
  229. INT dataCount,
  230. GpPointF* lastPt,
  231. const REAL* lastInsets,
  232. INT flag
  233. );
  234. GpStatus
  235. WidenLinePoints(
  236. REAL leftWidth,
  237. REAL rightWidth,
  238. GpLineJoin lineJoin,
  239. REAL miterLimit2,
  240. GpPointF* leftPoints,
  241. BYTE* leftTypes,
  242. INT* addedLeftCount,
  243. GpPointF* rightPoints,
  244. BYTE* rightTypes,
  245. INT* addedRightCount,
  246. const GpPointF* grad,
  247. const GpPointF* norm,
  248. const GpPointF* dataPoints,
  249. INT dataCount,
  250. GpPointF* lastPt,
  251. const REAL* lastInsets,
  252. INT flag
  253. );
  254. GpStatus
  255. WidenBezierPoints(
  256. REAL leftWidth,
  257. REAL rightWidth,
  258. GpLineJoin lineJoin,
  259. REAL miterLimit2,
  260. GpPointF* leftPoints,
  261. BYTE* leftTypes,
  262. INT* addedLeftCount,
  263. GpPointF* rightPoints,
  264. BYTE* rightTypes,
  265. INT* addedRightCount,
  266. const GpPointF* grad,
  267. const GpPointF* norm,
  268. const GpPointF* dataPoints,
  269. INT dataCount,
  270. GpPointF* lastPt,
  271. const REAL* lastInsets,
  272. INT flag
  273. );
  274. GpStatus SetCaps(
  275. GpLineCap startCap,
  276. GpLineCap endCap,
  277. const GpPointF& startPoint,
  278. const GpPointF& startGrad,
  279. const GpPointF& startNorm,
  280. const GpPointF& endPoint,
  281. const GpPointF& endGrad,
  282. const GpPointF& endNorm,
  283. REAL leftWidth,
  284. REAL rightWidth,
  285. const GpPointF *points,
  286. INT pointCount
  287. );
  288. GpStatus SetCustomFillCaps(
  289. GpCustomLineCap* customStartCap,
  290. GpCustomLineCap* customEndCap,
  291. const GpPointF& startPoint,
  292. const GpPointF& endPoint,
  293. REAL leftWidth,
  294. REAL rightWidth,
  295. const GpPointF *centerPoints,
  296. const BYTE *centerTypes,
  297. INT centerPointCount,
  298. DynPointFArray *startCapPoints,
  299. DynPointFArray *endCapPoints,
  300. DynByteArray *startCapTypes,
  301. DynByteArray *endCapTypes
  302. );
  303. GpStatus SetCustomStrokeCaps(
  304. GpCustomLineCap* customStartCap,
  305. GpCustomLineCap* customEndCap,
  306. const GpPointF& startPoint,
  307. const GpPointF& endPoint,
  308. REAL leftWidth,
  309. REAL rightWidth,
  310. const GpPointF *centerPoints,
  311. const BYTE *centerTypes,
  312. INT centerPointCount,
  313. DynPointFArray *startCapPoints,
  314. DynPointFArray *endCapPoints,
  315. DynByteArray *startCapTypes,
  316. DynByteArray *endCapTypes
  317. );
  318. GpStatus SetRoundCap(
  319. const GpPointF& point,
  320. const GpPointF& grad,
  321. BOOL isStartCap,
  322. REAL leftWidth,
  323. REAL rightWidth
  324. );
  325. GpStatus SetDoubleRoundCap(
  326. const GpPointF& point,
  327. const GpPointF& grad,
  328. BOOL isStartCap,
  329. REAL leftWidth,
  330. REAL rightWidth
  331. );
  332. GpStatus SetTriangleCap(
  333. const GpPointF& point,
  334. const GpPointF& grad,
  335. BOOL isStartCap,
  336. REAL leftWidth,
  337. REAL rightWidth,
  338. const GpPointF *points,
  339. INT pointCount
  340. );
  341. GpStatus CombineSubpathOutlines(
  342. DynPointFArray* widenedPoints,
  343. DynByteArray* widenedTypes,
  344. BOOL isClosed,
  345. BOOL closeStartCap = FALSE,
  346. BOOL closeEndCap = FALSE
  347. );
  348. GpStatus CombineClosedCaps(
  349. DynPointFArray* widenedPoints,
  350. DynByteArray* widenedTypes,
  351. DynPointFArray *daStartCapPoints,
  352. DynPointFArray *daEndCapPoints,
  353. DynByteArray *daStartCapTypes,
  354. DynByteArray *daEndCapTypes
  355. );
  356. GpStatus AddCompoundCaps(
  357. DynPointFArray* widenedPoints,
  358. DynByteArray* widenedTypes,
  359. REAL leftWidth,
  360. REAL rightWidth,
  361. INT startIndex,
  362. INT endIndex,
  363. GpLineCap startCap,
  364. GpLineCap endCap
  365. );
  366. REAL GetSubpathPenMiterDelta(BOOL isClosed);
  367. protected:
  368. DpPathIterator Iterator;
  369. DynByteArray CenterTypes;
  370. DynPointFArray CenterPoints;
  371. DynPointFArray Gradients;
  372. DynPointFArray Normals;
  373. DynByteArray LeftTypes;
  374. DynPointFArray LeftPoints;
  375. DynByteArray RightTypes;
  376. DynPointFArray RightPoints;
  377. BOOL InsetPenMode; // are we doing inset pen using a center pen.
  378. const DpPen* Pen;
  379. GpMatrix XForm;
  380. GpMatrix InvXForm;
  381. REAL UnitScale; // Scale factor for Page to Device units
  382. REAL StrokeWidth;
  383. REAL OriginalStrokeWidth; // StrokeWidth is clamped to a minimum value
  384. // but OriginalStrokeWidth is actual transformed
  385. // pen width.
  386. REAL MinimumWidth;
  387. REAL MaximumWidth;
  388. BOOL IsAntiAliased;
  389. BOOL NeedsToTransform;
  390. BOOL NeedsToAdjustNormals;
  391. REAL DpiX;
  392. REAL DpiY;
  393. DynPointFArray JoinPolygonPoints;
  394. DynRealArray JoinPolygonAngles;
  395. // CapTypes1 and CapPoints1 are used for the start cap and left join.
  396. DynByteArray CapTypes1;
  397. DynPointFArray CapPoints1;
  398. REAL Inset1; // Inset value for the starting position.
  399. // CapTypes2 and CapPoints2 are used for the end cap and right join.
  400. DynByteArray CapTypes2;
  401. DynPointFArray CapPoints2;
  402. REAL Inset2; // Inset value for the ending position.
  403. };
  404. #endif