00001
00002
00003
00004
00005
00006
00007
00008
00009
00010
00011
00012
00013
00014
00015
00016
00017
00018
00019
00020
00021
00022
00023
00024
00025
00026
00027
00028
00029
00030
00031
00032
00033
00034
00035
00036
00037
00038
00039
00040
00041
00042
00043
00044
00045
00046
00047
00048
00049
00050
00051
00052
00053
00054
00055
00056
00057
00058
00059
00060
00061
00062
00063
00064
00065
00066
00067
00068
00069
00070
00071
00072
00073
00074
00075
00076
00077
00078
00079
00080
00081
00082
00083
00084
00085
00086
00087
00088
00089
00090
00091
00092
00093
00094
00095
00096
00097
00098
00099
00100
00101 #ifndef INC_PATHS
00102 #define INC_PATHS
00103
00104 #include "doccoord.h"
00105 #include "docrect.h"
00106 #include "handles.h"
00107 #include "pathtype.h"
00108 #include "attr.h"
00109 #include "gconsts.h"
00110
00111 class RenderRegion;
00112 class NodePath;
00113 class Operation;
00114 class ProcessFlags;
00115 class CCAttrMap;
00116
00117
00118
00119 const INT32 NUMEXTRACHANNELS = 1;
00120
00121
00122 const UINT32 MAXPATHDIFFRATE = 64;
00123
00124
00125 typedef enum
00126 {
00127 CI_PRESSURE
00128 } ChannelIndex;
00129
00130 typedef UINT32 PathExtraElement;
00131 typedef UINT32 PathWidth;
00132
00133 const PathExtraElement EXTRAVALUEMAX = 65535;
00134
00135
00136
00137
00138
00139
00140
00141
00142
00143
00144
00145
00146
00147
00148
00149
00150 class PathExtraInfo
00151 {
00152 friend class Path;
00153 public:
00154
00155 PathExtraInfo();
00156 ~PathExtraInfo();
00157
00158
00159 BOOL Init(ChannelIndex, INT32);
00160 BOOL Add(ChannelIndex, INT32);
00161 void Sync(INT32);
00162 void Next() { CurrentExtraPos++; }
00163
00164
00165 BOOL HasWidthInfo();
00166
00167
00168 void MapWidthInfo(ChannelIndex);
00169
00170
00171 PathWidth GetWidthInfo();
00172 PathWidth* GetWidthArray();
00173
00174 private:
00175
00176 BOOL IncreaseExtraBlocks(INT32);
00177 BOOL DecreaseExtraBlocks(INT32);
00178 void ShiftUpExtraInfo(INT32, INT32, INT32);
00179 void ShiftDownExtraInfo(INT32, INT32, INT32);
00180 void CopyExtraInfo(PathExtraInfo*);
00181
00182 private:
00183
00184
00185 MHANDLE ExtraInfoHandles[NUMEXTRACHANNELS];
00186
00187 FIXED16 Scaling[NUMEXTRACHANNELS];
00188
00189 INT32 CurrentExtraPos;
00190
00191
00192 ChannelIndex WidthChannel;
00193 };
00194
00195 typedef enum
00196 {
00197 JOIN_START,
00198 JOIN_END,
00199 JOIN_MIDDLE,
00200 JOIN_NONE
00201 } JoinType;
00202
00203
00204 struct JoinInfo
00205 {
00206 JoinType JoinedAt;
00207 INT32 JoinPos;
00208
00209 };
00210
00211
00212
00213 enum PathTypeEnum {PATHTYPE_NONE, PATHTYPE_SHAPE, PATHTYPE_LINE };
00214
00215
00216
00217
00218
00219
00220
00221
00222
00223
00224
00225
00226
00227
00228
00229
00230
00231
00232
00233
00234
00235 #define POINTFLAG_ENDPOINTS 0x0001 // return endpoints
00236 #define POINTFLAG_CONTROLPOINTS 0x0002 // return control points
00237 #define POINTFLAG_ENDSFIRST 0x0004 // look at endpoints first
00238
00239
00240
00241
00242
00243
00244
00245
00246
00247
00248
00249
00250
00251
00252
00253 class Path
00254 {
00255 public:
00256
00257 Path();
00258 ~Path();
00259
00260
00261 BOOL CopyPathDataFrom( Path* SrcPath );
00262 BOOL CopyPathDataFrom( DocCoord* Coords, PathVerb* Verbs, INT32 NumCoords,
00263 BOOL Filled = FALSE, BOOL Stroked = TRUE);
00264
00265
00266 BOOL CreatePathFromDocRect(DocRect* pRect);
00267
00268
00269 BOOL Initialise(INT32 InitialSize=24, INT32 BlockSize=12);
00270
00271
00272 BOOL FindStartOfPath();
00273 void FindStartOfSubPath();
00274 void FindStartOfSubPath(INT32* Index) const;
00275 void FindEndOfSubPath();
00276 void FindEndOfSubPath(INT32* Index) const;
00277 void FindEndElOfSubPath(INT32* Index) const;
00278 void ExpandRange(INT32* start, INT32* end, INT32 num);
00279
00280 BOOL FindNext();
00281 BOOL FindNext(INT32* Index) const;
00282 BOOL FindPrev();
00283 BOOL FindPrev(INT32* Index) const;
00284 BOOL FindPrevEndPoint(INT32* index) const;
00285 BOOL FindNextEndPoint(INT32* index) const;
00286 BOOL GetSubPathEnds(DocCoord* start, DocCoord* end);
00287 BOOL FindNearestPoint(DocCoord pos, UINT32 flags, INT32* position);
00288 BOOL PointCloseToLine(DocCoord pos, INT32* position);
00289 BOOL ClosestSelectedEndpoint(DocCoord pos, INT32* position, double* distance);
00290 BOOL FindNextSelected(INT32* Index);
00291 BOOL FindSelectionLimits(INT32 index, INT32* p, INT32* q);
00292 INT32 FindOppositeControlPoint(INT32 ThisIndex);
00293 INT32 FindPrevControlPoint(INT32 position);
00294 INT32 FindNextControlPoint(INT32 position);
00295
00296 double SqrDistanceToPoint(const DocCoord pt, INT32* NearEl, double* mu);
00297 DocCoord ClosestPointTo(const double t, const INT32 index);
00298 BOOL IsPointCloseTo(const DocCoord ICoord, INT32 range, INT32* NearElement, double* mu );
00299 double SqrLength();
00300 double GetPathLength(double dFlatness = 64.0);
00301 double DistReparameterise(const double sqrdist, INT32* Element);
00302 DocCoord ConvSqrDistToCoord(const double sqrdist);
00303 INT32 BreakInTwo(Path* pChildPath);
00304 INT32 NumSplinters();
00305
00306 BOOL DistanceTo(INT32 index, double t, double* distance, double dFlatness=64.0);
00307 BOOL DistanceTo(DocCoord Coord, double* dist, double dFlatness=64.0);
00308 BOOL SplitAtPoint(const DocCoord& SplitPoint, INT32* SplitAt, INT32* NewElements);
00309 BOOL GetPointAtDistance(MILLIPOINT Distance, DocCoord* pPoint,double* pTangent=NULL, UINT32* pPressure = NULL);
00310 BOOL GetDistanceToPoint(DocCoord Point, MILLIPOINT* Distance);
00311
00312 void Scale(const DocCoord dcOrigin, const double dDPI=96.0);
00313
00314
00315 INT32 GetPathPosition();
00316 void SetPathPosition( INT32);
00317
00318
00319 BOOL IsInPath();
00320
00321
00322 PathVerb GetVerb() const;
00323 DocCoord GetCoord() const;
00324 PathFlags GetFlags() const;
00325 PathWidth GetWidth() const;
00326 PathTypeEnum GetPathType() const;
00327
00328 INT32 GetPathByteLength() const;
00329 INT32 GetNumElements() const;
00330 INT32 GetNumCoords() const;
00331 INT32 GetNumEndPoints() const;
00332 INT32 GetAllOpenEnds(INT32 MaxElements, DocCoord* EndCoords) const;
00333 INT32 GetNumSelEndPoints() const;
00334 INT32 GetNumSubpaths() const;
00335
00336
00337 DocRect GetBoundingRect() const;
00338 #if !defined(EXCLUDE_FROM_XARLIB)
00339 DocRect GetBlobRect() const;
00340 BOOL GetTrueBoundingRect( DocRect* pRect, MILLIPOINT LineWidth = 0,
00341 CCAttrMap* pAttrMap = NULL );
00342 #endif
00343
00344 DocCoord GetEndPoint();
00345 DocCoord GetControl1();
00346 DocCoord GetControl2();
00347
00348 DocCoord* GetCoordArray() const;
00349 PathVerb* GetVerbArray() const;
00350 PathFlags* GetFlagArray() const;
00351 PathWidth* GetWidthArray();
00352 void GetPathArrays(PathVerb** pV, DocCoord** pC = NULL, PathFlags** pF = NULL);
00353
00354 void GetFlags( PathFlags* NewFlags);
00355 void SetFlags( const PathFlags& NewFlags);
00356 void InitialiseFlags();
00357 void InitialiseFlags( const INT32 Startindex, const INT32 Len);
00358 void InitialiseFlags( PathVerb* pVerbs, PathFlags* pFlags, const INT32 Len);
00359
00360
00361 BOOL InsertMoveTo(DocCoord p1, PathFlags* NewFlags = NULL);
00362 BOOL InsertLineTo(DocCoord p1, PathFlags* NewFlags = NULL);
00363 BOOL InsertCurveTo(DocCoord p1, DocCoord p2, DocCoord p3, PathFlags* NewFlags = NULL);
00364 BOOL CloseSubPath();
00365 BOOL InsertSection(INT32 StartSlot, INT32 NumSlots);
00366 BOOL AddMoveTo(DocCoord p1, PathFlags* NewFlags = NULL);
00367 BOOL AddLineTo(DocCoord p1, PathFlags* NewFlags = NULL);
00368 BOOL AddCurveTo(DocCoord p1, DocCoord p2, DocCoord p3, PathFlags* NewFlags = NULL);
00369 BOOL AddCurveTo(DocCoord p1, PathFlags* NewFlags = NULL);
00370
00371
00372 BOOL DeleteSection(INT32 StartSlot, INT32 NumSlots);
00373 BOOL DeleteElement();
00374 BOOL DeleteFromElement(INT32 ElementNum);
00375 BOOL ClearPath();
00376 BOOL ClearPath(BOOL compress);
00377 BOOL Compact();
00378
00379
00380 BOOL IsSelected();
00381 BOOL IsSmooth();
00382 BOOL IsRotate();
00383 BOOL IsEndPoint();
00384 BOOL IsSubSelection();
00385
00386
00387 BOOL IsNearOpenEnd(const DocRect& BlobRect, INT32* SlotNum);
00388 BOOL IsOpenEnd(const INT32 index);
00389 BOOL IsComplexPath();
00390 BOOL IsIsometric(const Path& OtherPath, Matrix* pTransform, const double& Tolerance = 1.0) const;
00391 INT32 CalcCRC();
00392 INT32 CalcRegionCRC(const INT32 StartIndex, const INT32 EndIndex);
00393 INT32 CalcSelectedCRC();
00394 INT32 CalcSelPointsCRC(const INT32 StartIndex, const INT32 EndIndex);
00395 XLONG CalcArea();
00396
00397
00398 INT32 ComparePathToPath(Path* pComparePath, BOOL QuickCheck = TRUE);
00399
00400
00401 void DumpPath();
00402 void GetDebugDetails(StringBase* Str);
00403
00404 #if !defined(EXCLUDE_FROM_XARLIB)
00405
00406 void RenderPathBlobs(Spread* pSpread);
00407 void RenderPathBlobs(RenderRegion* pRender);
00408 void RenderPathControlBlobs(Spread* Spread, INT32 EndPtIndex);
00409 void RenderPathControlBlobs(RenderRegion* pRender,INT32 EndPtIndex);
00410 void RenderPathSelectedControlBlobs(Spread* pSpread, BOOL Removing = TRUE);
00411 void RenderPathSelectedControlBlobs(Spread* pSpread, RenderRegion* pRender);
00412 void RenderSelectedControlBlobsToPendingRegions(Spread* pSpread);
00413 void RenderPathPenBlobs(Spread* pSpread);
00414 void RenderPathPenBlobs(RenderRegion* pRegion);
00415
00416
00417 void DrawBlob(RenderRegion*, const DocCoord&, BOOL);
00418 void DrawControlBlob(RenderRegion*, const DocCoord&);
00419 void DrawControlLine(RenderRegion*, const DocCoord&, const DocCoord&);
00420 #endif
00421
00422
00423 void ClearSubSelection();
00424 void SetAllSubSelection();
00425 void EnsureSelection(BOOL UseStarts);
00426
00427
00428 void SmoothCurve(BOOL SetRenderFlags = FALSE, BOOL SnapEnds = FALSE, INT32 SnapIndex = 0);
00429 void CalcDoubleCurve( DocCoord&, DocCoord&, DocCoord&, DocCoord*, DocCoord*);
00430 void CalcPointCurve( DocCoord&, DocCoord&, DocCoord&, DocCoord*);
00431 void CalcPointLine( DocCoord&, DocCoord&, DocCoord&, DocCoord*);
00432 void CalcPointEnd( DocCoord&, DocCoord&, DocCoord*);
00433 void CalcRotate( DocCoord&, DocCoord*, DocCoord*, DocCoord&);
00434
00435
00436 void Reverse();
00437 void ReverseSection(INT32 StartSlot, INT32 SubPathLen);
00438 void TryToClose();
00439 void RotateElementsLeft(const INT32 Start, const INT32 End, INT32 Rotate);
00440 BOOL MergeTwoPaths(const Path& Other);
00441 BOOL MergeTwoPaths(DocCoord* OtherCoords,PathVerb* OtherVerbs,PathFlags* OtherFlags,INT32 Length,BOOL Filled);
00442 BOOL SplitAtPoint(const DocCoord SplitPt, INT32* SplitElement, UINT32* NumElements, PathVerb* Verbs, DocCoord* Coords);
00443 BOOL ChangeStartElement(INT32 StartIndex);
00444 void Translate(const INT32 x, const INT32 y);
00445 void Translate(const DocCoord& coord);
00446
00447 #if !defined(EXCLUDE_FROM_XARLIB)
00448 INT32 ClipPathToPath(const Path& Src,Path* const pDest,UINT32 Flags,
00449 UINT32 Tolerance = 100,double SrcFlatness = 750.0,double ClipFlatness = 750.0);
00450
00451 BOOL StrokePathToPath( MILLIPOINT LineWidth = 250,
00452 LineCapType LineCap = LineCapButt,
00453 JointType JoinStyle = MitreJoin,
00454 DashType* pDash = NULL,
00455 Path* pDest = NULL,
00456 double Flatness = 200.0,
00457 BOOL Close = FALSE);
00458
00459
00460
00461 double CalculateFlatnessValueFromPath(double DividerValue = 375.0, double LowerLimit = 1.0, double UpperLimit = 375.0);
00462
00463
00464
00465 INT32 InitializeContourValues(UINT32 Width, JoinStyles JoinS = JOIN_ROUND, BOOL IsAnOuterContour = TRUE,
00466 double Flatness = 200.0, BOOL ClosePath = TRUE, BOOL UseContourMode = TRUE,
00467 CapStyles CapS = CAPS_ROUND, UINT32 MitreLimit = 751941);
00468
00469 INT32 GetContourForStep(Path* pDest, double StepValue = 1.0);
00470
00471 #endif
00472
00473
00474 void ClearNeedToRender();
00475
00476
00477 BOOL CopySectionFrom(const Path& Other, INT32 StartIndex, INT32 NumToCopy);
00478 BOOL CopySectionTo(Path* Dest, INT32 StartIndex, INT32 NumToCopy);
00479 BOOL MergeSectionFrom(INT32 DestinPos, const Path& Source, INT32 SourcePos, INT32 Length);
00480 BOOL MergeSectionTo(INT32 SourcePos, INT32 Length, Path* Destin, INT32 DestinPos);
00481 BOOL MakePathFromSection(const INT32 Start, const INT32 Length, Path* pDestin);
00482 BOOL MakePathFromSubPath(const INT32 lSubpathIndex, Path* pDestin);
00483 BOOL CloneFrom(const Path& Other);
00484
00485
00486 BOOL SimpleJoin(Path* Other, INT32*, BOOL*, BOOL *Reversed = NULL);
00487 BOOL ComplexJoin(Path* Other, INT32*, BOOL*);
00488 BOOL ComplexToSameComplexJoin(Path* Other, INT32*, BOOL*);
00489 BOOL FindJoinedSubPathInfo(const DocCoord& JoinCoord, INT32* Start, INT32* Length, BOOL* JoinAtStart);
00490 BOOL JoinToAnother(Path* OtherPath, INT32 MainIndex, INT32 OtherIndex);
00491
00492
00493 BOOL RetroReplaceSection(INT32 StartSlot, INT32 NumSlots, Path* NewPath, BOOL KeepStart);
00494
00495
00496 BOOL SmoothRegions(const double error, BOOL smoothall, BOOL reselect);
00497 BOOL SmoothSection(INT32 index1, INT32* index2, const double error, INT32 selection);
00498 BOOL Smooth(const double error);
00499 BOOL Quantise(const double threshold, Path* pOutput);
00500 BOOL Flatten(const double flatness, Path* pOutput);
00501 BOOL CreateFlatPath(const ProcessFlags& PFlags, const double flatness, Path* pOutput);
00502
00503
00504 BOOL MakeSpaceInPath(INT32 NumSlots);
00505 BOOL MakeSpaceInPath(INT32 NumSlots, INT32 Position);
00506 BOOL MakeSpaceAtEnd(INT32 NumSlots);
00507 BOOL OpenGap(INT32 NumSlots);
00508 BOOL OpenGap(INT32 NumSlots, INT32 Position);
00509 BOOL EnsureVolume(INT32 NumSlots);
00510
00511
00512 BOOL ExternalArraysAdded(const INT32 Added);
00513 BOOL ExternalArraysReplaced(const INT32 Size);
00514
00515
00516 BOOL HasWidth();
00517
00518
00519 void MapWidth(ChannelIndex);
00520
00521
00522 BOOL InitExtraInfo(ChannelIndex);
00523 BOOL AddExtraInfo(ChannelIndex, INT32);
00524 void SyncExtraInfo();
00525 void NextExtraInfo() { ExtraInfo->Next(); }
00526
00527 DocCoord SmoothControlPoint(INT32 Index,
00528 BOOL StartAndEndSnapped = FALSE,
00529 BOOL JoinedToAnother = FALSE,
00530 BOOL OtherIsCurve = TRUE,
00531 const DocCoord& OtherCoord = DocCoord(0,0) );
00532
00533
00534
00535
00536
00537
00538
00539
00540
00541
00542 BOOL IsSubPathClosed(INT32 Index);
00543 BOOL IsClosed();
00544
00545 #ifdef _DEBUG
00546
00547 BOOL CheckPathValid();
00548 #endif
00549 BOOL EnsureValid(BOOL* ChangesMade = NULL);
00550
00551 private:
00552
00553 BOOL InsertSectionAtEnd(const Path* Other, INT32 StartPos, INT32 NumSlots);
00554
00555 #if !defined(EXCLUDE_FROM_XARLIB)
00556
00557 INT32 m_ContourWidth;
00558 JoinStyles m_ContourJoinS;
00559 CapStyles m_ContourCapS;
00560 double m_ContourFlatness;
00561 UINT32 m_ContourMitreLimit;
00562 UINT32 m_ContourLength;
00563 BOOL m_IsAnOuterContour;
00564 BOOL m_DoClosePath;
00565 BOOL m_UseContourMode;
00566 #endif
00567
00568 public:
00569
00570 BOOL IsFilled;
00571 BOOL IsStroked;
00572
00573 INT32 GetUsedSlots () { return (UsedSlots); }
00574
00575 private:
00576
00577 MHANDLE VerbHandle;
00578 MHANDLE CoordHandle;
00579 MHANDLE FlagsHandle;
00580
00581
00582 PathExtraInfo* ExtraInfo;
00583
00584
00585 INT32 UnUsedSlots;
00586 INT32 UsedSlots;
00587 INT32 SlotAllocSize;
00588 INT32 SlotInitSize;
00589
00590
00591 INT32 CurrentPos;
00592 };
00593
00594
00595 #endif // INC_PATH
00596