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
00102
00103
00104 typedef bool GBOOL ;
00105 typedef __int64 DLONG ;
00106 typedef __uint64 UDLONG ;
00107 typedef double DOUBLE ;
00108
00109 struct FPOINT ;
00110 struct GPOINT ;
00111
00112 #define TypeDef(name) \
00113 typedef const name c##name ; \
00114 typedef name* p##name ; \
00115 typedef const name* pc##name ; \
00116 typedef name* const cp##name ; \
00117 typedef const name* const cpc##name ; \
00118 typedef name** pp##name ; \
00119 typedef const name** ppc##name ;
00120
00121 TypeDef( GBOOL )
00122 TypeDef( INT32 )
00123 TypeDef( UINT32 )
00124 TypeDef( DLONG )
00125 TypeDef( UDLONG )
00126
00127 TypeDef( BYTE )
00128 TypeDef( WORD )
00129 TypeDef( DWORD )
00130
00131 TypeDef( FLOAT )
00132 TypeDef( DOUBLE )
00133
00134 TypeDef( POINT )
00135 TypeDef( FPOINT )
00136 TypeDef( GPOINT )
00137
00138 struct FPOINT {
00139 double X ;
00140 double Y ;
00141 FPOINT() {} ;
00142 FPOINT( cDOUBLE X,cDOUBLE Y ) : X(X),Y(Y) {} ;
00143 FPOINT( cGPOINT P ) ;
00144 bool operator==(cFPOINT& P) const { return X==P.X && Y==P.Y ; }
00145 bool operator!=(cFPOINT& P) const { return X!=P.X || Y!=P.Y ; }
00146 FPOINT operator+ (cFPOINT& P) const { return FPOINT(X+P.X,Y+P.Y) ; }
00147 FPOINT operator- (cFPOINT& P) const { return FPOINT(X-P.X,Y-P.Y) ; }
00148 FPOINT operator* (cFPOINT& P) const { return FPOINT(X*P.X,Y*P.Y) ; }
00149 FPOINT operator* (cDOUBLE& F) const { return FPOINT(X*F ,Y*F ) ; }
00150
00151
00152 FPOINT operator* (cINT32& I) const { return FPOINT(X*I ,Y*I ) ; }
00153 FPOINT operator/ (cDOUBLE& F) const { cDOUBLE R=1/F ;
00154 return FPOINT(X*R ,Y*R ) ; }
00155 FPOINT operator+ () const { return *this ; }
00156 FPOINT operator- () const { return FPOINT(-X,-Y) ; }
00157 DOUBLE Length () const { return sqrt(X*X+Y*Y) ; }
00158 FPOINT Normalise () const { cDOUBLE L=Length() ;
00159 return L>0 ? *this/L : FPOINT(0,0) ; }
00160 } ;
00161 inline FPOINT operator*(cDOUBLE& F,cFPOINT& P) { return P*F ; }
00162
00163
00164 inline FPOINT operator*(cINT32& I,cFPOINT& P) { return P*I ; }
00165
00166 struct GPOINT {
00167 INT32 X ;
00168 INT32 Y ;
00169 GPOINT() {} ;
00170 GPOINT( cINT32 X,cINT32 Y ) : X(X),Y(Y) {} ;
00171 GPOINT( cFPOINT P ) : X((INT32)P.X),Y((INT32)P.Y) {} ;
00172 bool operator==(cGPOINT& P) const { return X==P.X && Y==P.Y ; }
00173 bool operator!=(cGPOINT& P) const { return X!=P.X || Y!=P.Y ; }
00174 GPOINT operator+ (cGPOINT& P) const { return GPOINT(X+P.X,Y+P.Y) ; }
00175 GPOINT operator- (cGPOINT& P) const { return GPOINT(X-P.X,Y-P.Y) ; }
00176 GPOINT operator* ( cINT32& I) const { return GPOINT(X*I ,Y*I ) ; }
00177 GPOINT operator<<( cINT32& I) const { return GPOINT(X<<I ,Y<<I ) ; }
00178 GPOINT operator>>( cINT32& I) const { return GPOINT(X>>I ,Y>>I ) ; }
00179 GPOINT operator+ () const { return *this ; }
00180 GPOINT operator- () const { return GPOINT(-X,-Y) ; }
00181 } ;
00182 inline GPOINT operator*(cINT32& I,cGPOINT& P) { return P*I ; }
00183 inline FPOINT::FPOINT( cGPOINT P ) : X(P.X),Y(P.Y) {}
00184
00185
00186
00187 class CBezier
00188 {
00189 public :
00190 CBezier( cpcFPOINT C ) ;
00191 double Length( cDOUBLE T ) ;
00192 private :
00193 double BLength( cDOUBLE T ) ;
00194 double P0,P1,P2,P3,P4 ;
00195 } ;
00196
00197
00198
00199 struct BEVEL_FACE {
00200 GPOINT aFace[4] ;
00201 GBOOL bTriangle ;
00202 FPOINT Normal ;
00203 } ;
00204
00205 struct DASH {
00206 DWORD Length ;
00207 DWORD Offset ;
00208 DWORD Array[8] ;
00209 } ;
00210
00211 TypeDef( BEVEL_FACE )
00212 TypeDef( DASH )
00213
00214
00215
00216 class GenStroke
00217 {
00218
00219 public :
00220 virtual ~GenStroke() { }
00221
00222 enum {
00223 MAX_DASH_LENGTH = 8
00224 } ;
00225
00226
00227
00228
00229
00230
00231
00232
00233
00234
00235 INT32 StrokePathToPath(
00236 cpcPOINT pIPoints,
00237 cpcBYTE pITypes,
00238 UINT32 nILength,
00239 ppPOINT ppOPoints,
00240 ppBYTE ppOTypes,
00241 BOOL bClose,
00242 UINT32 nLineWidth,
00243 UINT32 nMitreLimit,
00244
00245 DOUBLE nFlatness,
00246 const CapStyles LineCaps,
00247 const JoinStyles LineJoin,
00248 cpcDASH pDash
00249 ) ;
00250
00251 protected :
00252
00253 enum eEndStyle {
00254 END_UNDEFINED,
00255 END_JOIN,
00256 END_SMOOTH,
00257 END_START_CAP,
00258 END_END_CAP
00259 } ;
00260
00261 CapStyles CapStyle ;
00262 JoinStyles JoinStyle ;
00263 DOUBLE FFlatness ;
00264 DOUBLE FFlatness8 ;
00265 DOUBLE FLineWidth ;
00266 DOUBLE FSqrLineWidth ;
00267 DOUBLE FDivLineWidth ;
00268 DOUBLE FDivSqrLineWidth ;
00269 DOUBLE FMitreLimit ;
00270 DOUBLE FSmoothLimit ;
00271 DOUBLE FStrokeLimit ;
00272
00273 pGPOINT pOutputPoints ;
00274 pBYTE pOutputTypes ;
00275 UINT32 nOutputLength ;
00276 UINT32 nMaxOutputLength ;
00277
00278 FPOINT FirstPoint1 ;
00279 FPOINT FirstPoint2 ;
00280 FPOINT FirstPoint ;
00281 FPOINT SecondPoint1 ;
00282 FPOINT SecondPoint2 ;
00283 FPOINT SecondPoint ;
00284 FPOINT ThisPoint1 ;
00285 FPOINT ThisPoint2 ;
00286 FPOINT ThisPoint ;
00287 FPOINT PrevPoint1 ;
00288 FPOINT PrevPoint2 ;
00289 FPOINT PrevPoint ;
00290 FPOINT LastPoint1 ;
00291 FPOINT LastPoint2 ;
00292 FPOINT LastPoint ;
00293 FPOINT FirstOffsetS ;
00294 FPOINT FirstOffsetE ;
00295 FPOINT SecondOffsetS ;
00296 FPOINT SecondOffsetE ;
00297 FPOINT ThisOffsetS ;
00298 FPOINT ThisOffsetE ;
00299 FPOINT PrevOffsetS ;
00300 FPOINT PrevOffsetE ;
00301 FPOINT ThisMitre ;
00302 FPOINT PrevMitre ;
00303 DOUBLE ThisSin ;
00304 DOUBLE PrevSin ;
00305 DOUBLE ThisCos ;
00306 DOUBLE FirstLengthS ;
00307 DOUBLE FirstLengthE ;
00308 DOUBLE SecondLengthS ;
00309 DOUBLE SecondLengthE ;
00310 DOUBLE ThisLengthS ;
00311 DOUBLE ThisLengthE ;
00312 DOUBLE PrevLengthE ;
00313 GBOOL ThisMitreFlag ;
00314 GBOOL PrevMitreFlag ;
00315 GBOOL ThisLengthFlag ;
00316 GBOOL PrevLengthFlag ;
00317 eEndStyle FirstLineEnd ;
00318 eEndStyle ThisLineEnd ;
00319 eEndStyle PrevLineEnd ;
00320 eEndStyle LastLineEnd ;
00321 GBOOL FirstIsCurve ;
00322 GBOOL SecondIsCurve ;
00323 GBOOL ThisIsCurve ;
00324 GBOOL PrevIsCurve ;
00325 GBOOL LastIsCurve ;
00326 GBOOL FirstOSign ;
00327 GBOOL FirstISign ;
00328 GBOOL SecondOSign ;
00329 GBOOL SecondISign ;
00330 GBOOL ThisOSign ;
00331 GBOOL ThisISign ;
00332 GBOOL PrevOSign ;
00333 GBOOL PrevISign ;
00334 GBOOL LastOSign ;
00335 GBOOL LastISign ;
00336
00337 size_t DashArrayLength ;
00338 INT32 DashStartRemain ;
00339 DOUBLE DashRemain ;
00340 UINT32 DashStartCount ;
00341 UINT32 DashCount ;
00342 GBOOL DashStartState ;
00343 GBOOL DashState ;
00344 GBOOL DashFlag ;
00345 UINT32 DashTotalLength ;
00346 UINT32 aDashArray[MAX_DASH_LENGTH] ;
00347
00348 GBOOL bInner ;
00349 GBOOL bOuter ;
00350
00351 FPOINT PrevCOffset ;
00352 FPOINT ThisCOffset ;
00353
00354 static cFLOAT aArcTable[0x201] ;
00355 static cpcFLOAT pArcTable ;
00356
00357 void StrokePath(
00358 cpcGPOINT pInputPoints,
00359 cpcBYTE pInputTypes,
00360 cUINT32 InputLength,
00361 cGBOOL bClose,
00362 cUINT32 LineWidth,
00363 cUINT32 MitreLimit,
00364
00365 cDOUBLE nFlatness,
00366 const CapStyles LineCaps,
00367 const JoinStyles LineJoin,
00368 cpcDASH pDash
00369 ) ;
00370
00371 void StrokeLine ( cFPOINT EndPoint, const eEndStyle End = END_JOIN ) ;
00372 void StrokeCurve( FPOINT C[4] ) ;
00373 void StrokeCurve( cpcFPOINT FPoint, cGBOOL bOSign,cGBOOL bISign ) ;
00374 void StrokeCurve( cpcFPOINT FPoint, const eEndStyle End, cGBOOL bOSign,cGBOOL bISign ) ;
00375 void GenSection(
00376 cFPOINT Point1,cFPOINT Point2,cFPOINT Point,
00377 cFPOINT OffsetS,cDOUBLE LengthS,
00378 cFPOINT OffsetE,cDOUBLE LengthE,
00379 const eEndStyle LineEnd,
00380 cGBOOL IsCurve,
00381 cGBOOL bOSign,cGBOOL bISign
00382 ) ;
00383 virtual void GenLineEdge() ;
00384
00385 void GenStrokeCurves(
00386 cFPOINT P0,cFPOINT P1,cFPOINT P2,cFPOINT P3,
00387 cFPOINT N00,cFPOINT N33
00388 ) ;
00389 void GenStrokeInnerCurves(
00390 cFPOINT P0,cFPOINT P1,cFPOINT P2,cFPOINT P3,
00391 cFPOINT N00,cFPOINT N33
00392 ) ;
00393 void DoStrokeCurves(
00394 cINT32 Depth,
00395 cFPOINT P06,cFPOINT P26,cFPOINT P46,cFPOINT P66, cFPOINT PC1,cFPOINT PC2,
00396 cFPOINT T06,cFPOINT T26,cFPOINT T46,cFPOINT T66,
00397 cFPOINT N06,cFPOINT N26,cFPOINT N46,cFPOINT N66
00398 ) ;
00399
00400 void SplitCurve( cpFPOINT C0, cpFPOINT C1, cDOUBLE T ) ;
00401
00402 void GenRoundCap( cFPOINT C,cFPOINT O ) ;
00403 void CalcCurveOffset() ;
00404 void AddPoint( UINT32 n ) ;
00405 virtual void MoveTo_Start( cDOUBLE X,cDOUBLE Y ) ;
00406 virtual void LineTo_Start( cDOUBLE X,cDOUBLE Y ) ;
00407 virtual void LineTo_End ( cDOUBLE X,cDOUBLE Y ) ;
00408 virtual void Close() ;
00409 virtual void LineTo(
00410 cFPOINT C0,cFPOINT C1,
00411 cFPOINT P0,cFPOINT P1
00412 ) ;
00413 virtual void CurveTo(
00414 cFPOINT C0,cFPOINT C1,cFPOINT C2,cFPOINT C3,
00415 cFPOINT P0,cFPOINT P1,cFPOINT P2,cFPOINT P3
00416 ) ;
00417 void Set_Prev( cFPOINT P ) ;
00418 virtual void PathOpen () {} ;
00419 virtual void PathClose() {} ;
00420
00421 enum {
00422 PT_PATHELEMENT = 6
00423 } ;
00424
00425 inline GBOOL IsClosed ( cBYTE Type ) { return (Type & PT_CLOSEFIGURE) ; }
00426 inline GBOOL IsntClosed ( cBYTE Type ) { return !(Type & PT_CLOSEFIGURE) ; }
00427 inline GBOOL IsMoveTo ( cBYTE Type ) { return (Type & PT_PATHELEMENT)==PT_MOVETO ; } ;
00428 inline GBOOL IsntMoveTo ( cBYTE Type ) { return (Type & PT_PATHELEMENT)!=PT_MOVETO ; } ;
00429 inline GBOOL IsLineTo ( cBYTE Type ) { return (Type & PT_PATHELEMENT)==PT_LINETO ; } ;
00430 inline GBOOL IsntLineTo ( cBYTE Type ) { return (Type & PT_PATHELEMENT)!=PT_LINETO ; } ;
00431 inline GBOOL IsBezierTo( cBYTE Type ) { return (Type & PT_PATHELEMENT)==PT_BEZIERTO ; } ;
00432 inline GBOOL IsntBezierTo( cBYTE Type ) { return (Type & PT_PATHELEMENT)!=PT_BEZIERTO ; } ;
00433 } ;
00434
00435
00436
00437 class GenPathContour : public GenStroke
00438 {
00439 public :
00440
00441
00442
00443
00444
00445
00446
00447
00448
00449
00450
00451 INT32 ContourPath(
00452 cpcPOINT pIPoints,
00453 cpcBYTE pITypes,
00454 UINT32 nILength,
00455 ppPOINT ppOPoints,
00456 ppBYTE ppOTypes,
00457 UINT32 LineWidth,
00458 UINT32 MitreLimit,
00459
00460 DOUBLE nFlatness,
00461 const JoinStyles LineJoin,
00462 bool bOuter
00463 ) ;
00464
00465 protected :
00466 bool bStart ;
00467
00468 void GenLineEdge() ;
00469 void GenOuterEdge() ;
00470 void GenInnerEdge() ;
00471
00472 void LineTo_Start( cDOUBLE X,cDOUBLE Y ) ;
00473 void PathOpen () { bStart = true ; }
00474 void PathClose() { if (!bStart) Close() ; }
00475 } ;
00476
00477
00478
00479 class GenBevelFaces : public GenStroke
00480 {
00481 public :
00482
00483
00484
00485
00486
00487
00488
00489
00490
00491
00492
00493 INT32 BevelPath(
00494 cpcPOINT pIPoints,
00495 cpcBYTE pITypes,
00496 UINT32 ILength,
00497 ppBEVEL_FACE ppOutputFaces,
00498 UINT32 LineWidth,
00499 UINT32 MitreLimit,
00500
00501 DOUBLE nFlatness,
00502 const JoinStyles LineJoin,
00503 bool bOuter
00504 ) ;
00505
00506 protected :
00507 pBEVEL_FACE pBFaces ;
00508 UINT32 nMaxBFaces ;
00509 UINT32 nBFaces ;
00510
00511 pBEVEL_FACE NewBFace() ;
00512
00513 void GenLineEdge() ;
00514 void GenOuterEdge() ;
00515 void GenInnerEdge() ;
00516
00517 void LineTo(
00518 cFPOINT C0,cFPOINT C1,
00519 cFPOINT P0,cFPOINT P1
00520 ) ;
00521 void CurveTo(
00522 cFPOINT C0,cFPOINT C1,cFPOINT C2,cFPOINT C3,
00523 cFPOINT P0,cFPOINT P1,cFPOINT P2,cFPOINT P3
00524 ) ;
00525 void CurveTo( cFPOINT C, cFPOINT P0,cFPOINT P1,cFPOINT P2,cFPOINT P3 ) ;
00526 } ;
00527
00528