#include <pathproc.h>
Inheritance diagram for ProcessPath:
Public Member Functions | |
ProcessPath (const double flat) | |
~ProcessPath () | |
ProcessPath class destructor. | |
BOOL | Init (Path *pSource) |
BOOL | Process (const ProcessFlags &PFlags) |
Processes a path. It will scan through the elements of a path, passing points to a NewPoint virtual function. It will also flatten curves if found and pass the generated points on as well. | |
virtual void | OpenElement (PathVerb Verb, INT32 index) |
Does nothing. | |
virtual BOOL | NewPoint (PathVerb Verb, DocCoord *pCoord)=0 |
virtual BOOL | CloseElement (BOOL ok, PathVerb Verb, INT32 index) |
Does nothing. | |
virtual void | CloseFigure (void) |
Derived-class interface. Called after closing a LINETO or BEZIERTO element which constitutes the end of this figure (subpath) (as indicated by this element having the PT_CLOSEFIGURE flag set). | |
Protected Member Functions | |
BOOL | FlattenCurve (INT32 Px0, INT32 Py0, INT32 Px1, INT32 Py1, INT32 Px2, INT32 Py2, INT32 Px3, INT32 Py3, BOOL QuantiseAll=FALSE) |
Generates a set of points on the bezier curve specified. The points start at (Px0,Py0) and traverse the curve to (Px3,Py3). If the points are joined with straight lines, the lines (given a good flatness value) should approximate the curve accurately enough to appear continuous. Obviously this is soley dependent on the flat value passed to the function. A value around 64 is a good approximator. | |
BOOL | FlattenSplit (INT32 Px0, INT32 Py0, INT32 Px1, INT32 Py1, INT32 Px2, INT32 Py2, INT32 Px3, INT32 Py3, BOOL QuantiseAll=FALSE) |
Recursive partner to FlattenCurve. NOT to be called by anything other than FlattenCurve. | |
virtual BOOL | InsertQuantisedLineTo (DocCoord *pEnd, DocCoord *pStart) |
inserts a quantised lineto | |
Protected Attributes | |
Path * | ProcSource |
INT32 * | ProcCache |
INT32 | ProcNumCached |
BOOL | ProcFirstPoint |
double | ProcFlatness |
DocCoord | ProcPreviousEl |
Private Member Functions | |
CC_DECLARE_DYNAMIC (ProcessPath) |
Definition at line 141 of file pathproc.h.
|
Definition at line 159 of file pathproc.cpp. 00160 { 00161 ProcSource = NULL; 00162 ProcCache = NULL; 00163 ProcNumCached = 0; 00164 ProcFirstPoint = TRUE; 00165 ProcFlatness = flat; 00166 }
|
|
ProcessPath class destructor.
Definition at line 183 of file pathproc.cpp.
|
|
|
|
Does nothing. BOOL ProcessDistance::CloseElement(BOOL done, PathVerb Verb, INT32 index)
Reimplemented in ProcessLength, ProcessDistance, and ProcessPathToTrapezoids. Definition at line 532 of file pathproc.cpp. 00533 { 00534 // Base class null function 00535 return FALSE; 00536 }
|
|
Derived-class interface. Called after closing a LINETO or BEZIERTO element which constitutes the end of this figure (subpath) (as indicated by this element having the PT_CLOSEFIGURE flag set).
The base class does nothing
Reimplemented in ProcessPathToTrapezoids. Definition at line 559 of file pathproc.cpp.
|
|
Generates a set of points on the bezier curve specified. The points start at (Px0,Py0) and traverse the curve to (Px3,Py3). If the points are joined with straight lines, the lines (given a good flatness value) should approximate the curve accurately enough to appear continuous. Obviously this is soley dependent on the flat value passed to the function. A value around 64 is a good approximator.
Definition at line 356 of file pathproc.cpp. 00360 { 00361 INT32 diff; 00362 00363 INT32 dx0 = (Px1*3 - Px0*2 - Px3); 00364 if (dx0 < 0) dx0 = -dx0; 00365 //dx0 = dx0 < 0 ? -dx0 : dx0; 00366 00367 INT32 dy0 = (Py1*3 - Py0*2 - Py3); 00368 if (dy0 < 0) dy0 = -dy0; 00369 //dy0 = dy0 < 0 ? -dy0 : dy0; 00370 00371 // Get the line's distance from the curve 00372 if (dx0 >= dy0) 00373 diff = 3*dx0 + dy0; 00374 else 00375 diff = dx0 + 3*dy0; 00376 00377 // Is the straight line close enough to the curve ? 00378 if (diff > ProcFlatness) 00379 { 00380 // Not close enough so split it into two and recurse for each half 00381 BOOL ok = FlattenSplit(Px0,Py0, Px1,Py1, Px2,Py2, Px3,Py3, QuantiseAll); 00382 return ok; 00383 } 00384 00385 INT32 dx1 = (Px2*3 - Px0 - Px3*2); 00386 if (dx1 < 0) dx1 = -dx1; 00387 //dx1 = dx1 < 0 ? -dx1 : dx1; 00388 00389 INT32 dy1 = (Py2*3 - Py0 - Py3*2); 00390 if (dy1 < 0) dy1 = -dy1; 00391 //1 = dy1 < 0 ? -dy1 : dy1; 00392 00393 // Get the line's distance from the curve 00394 if (dx1 >= dy1) 00395 diff = 3*dx1 + dy1; 00396 else 00397 diff = dx1 + 3*dy1; 00398 00399 // Is the straight line close enough to the curve ? 00400 if (diff > ProcFlatness) 00401 { 00402 // Not close enough so split it into two and recurse for each half 00403 BOOL ok = FlattenSplit(Px0,Py0, Px1,Py1, Px2,Py2, Px3,Py3, QuantiseAll); 00404 return ok; 00405 } 00406 00407 DocCoord npoint; 00408 npoint.x = Px3; 00409 npoint.y = Py3; 00410 00411 // Line is now close enough so call the virtual function 00412 if (!QuantiseAll) 00413 return NewPoint(PT_LINETO, &npoint); 00414 else 00415 { 00416 DocCoord spoint; 00417 spoint.x = Px0; 00418 spoint.y = Py0; 00419 return InsertQuantisedLineTo(&npoint,&spoint); 00420 } 00421 }
|
|
Recursive partner to FlattenCurve. NOT to be called by anything other than FlattenCurve.
Definition at line 434 of file pathproc.cpp. 00438 { 00439 00440 // Calculate the first half of the curve 00441 INT32 lx0 = Px0; 00442 INT32 ly0 = Py0; 00443 INT32 lx1 = (Px0 + Px1)/2; 00444 INT32 ly1 = (Py0 + Py1)/2; 00445 INT32 lx2 = (Px0 + 2*Px1 + Px2)/4; 00446 INT32 ly2 = (Py0 + 2*Py1 + Py2)/4; 00447 INT32 lx3 = (Px0 + 3*Px1 + 3*Px2 + Px3)/8; 00448 INT32 ly3 = (Py0 + 3*Py1 + 3*Py2 + Py3)/8; 00449 00450 // Calculate the second half of the curve 00451 INT32 rx0 = lx3; 00452 INT32 ry0 = ly3; 00453 INT32 rx1 = (Px1 + 2*Px2 + Px3)/4; 00454 INT32 ry1 = (Py1 + 2*Py2 + Py3)/4; 00455 INT32 rx2 = (Px2 + Px3)/2; 00456 INT32 ry2 = (Py2 + Py3)/2; 00457 INT32 rx3 = Px3; 00458 INT32 ry3 = Py3; 00459 00460 // Recurse for both halfs of the curve 00461 BOOL ok = FlattenCurve(lx0,ly0, lx1,ly1, lx2,ly2, lx3,ly3, QuantiseAll); 00462 if (ok) ok = FlattenCurve(rx0,ry0, rx1,ry1, rx2,ry2, rx3,ry3, QuantiseAll); 00463 00464 return ok; 00465 }
|
|
Definition at line 201 of file pathproc.cpp. 00202 { 00203 // Allocate a cache for ourselves 00204 // ProcCache = (INT32*) CCMalloc(PROC_CACHE_SIZE*sizeof(INT32)); 00205 // if (ProcCache == NULL) 00206 // return FALSE; 00207 00208 ProcSource = pSource; 00209 return TRUE; 00210 }
|
|
inserts a quantised lineto
Definition at line 475 of file pathproc.cpp. 00476 { 00477 INT32 dx = pEnd->x - pStart->x; 00478 INT32 dy = pEnd->y - pStart->y; 00479 INT32 pdx = (dx<0)?(-dx):dx; 00480 INT32 pdy = (dy<0)?(-dy):dy; 00481 INT32 maxdist = (pdx<pdy)?pdy:pdx; 00482 INT32 points = (INT32)((((double)maxdist/ProcFlatness)) + 0.5); 00483 if (points<=1) return NewPoint(PT_LINETO, pEnd); 00484 if (points>10) points=10; 00485 DocCoord intermediate; 00486 INT32 n; 00487 for (n=1; n<=points; n++) 00488 { 00489 double d=((double)n/(double)points); 00490 intermediate.x=pStart->x + (INT32)(0.5+d*(double)dx); 00491 intermediate.y=pStart->y + (INT32)(0.5+d*(double)dy); 00492 if (!NewPoint(PT_LINETO, &intermediate)) return FALSE; 00493 } 00494 return TRUE; 00495 }
|
|
Implemented in ProcessFlatten, ProcessLength, ProcessDistance, ProcessPathDistance, and ProcessPathToTrapezoids. |
|
Does nothing. void ProcessPath::OpenElement(PathVerb Verb, INT32 index)
Reimplemented in ProcessLength, and ProcessDistance. Definition at line 509 of file pathproc.cpp.
|
|
Processes a path. It will scan through the elements of a path, passing points to a NewPoint virtual function. It will also flatten curves if found and pass the generated points on as well.
Definition at line 238 of file pathproc.cpp. 00239 { 00240 00241 // The idea here is that we create a quantised path. This means we 00242 // scan through the path descretizing curves and lines dependent 00243 // on the flatness value given. 00244 00245 DocCoord* ICoords = ProcSource->GetCoordArray(); 00246 PathVerb* IVerbs = ProcSource->GetVerbArray(); 00247 00248 INT32 numinsource = ProcSource->GetNumCoords(); 00249 00250 INT32 i=0; 00251 BOOL ok = TRUE; 00252 00253 // scan through the input verbs 00254 while ((i<numinsource) && (ok)) 00255 { 00256 switch (IVerbs[i] & ~PT_CLOSEFIGURE) 00257 { 00258 case PT_MOVETO: 00259 OpenElement(PT_MOVETO, i); 00260 ok = NewPoint(PT_MOVETO, &ICoords[i]); 00261 if (CloseElement(ok, PT_MOVETO, i)) 00262 i=(numinsource-1); 00263 break; 00264 00265 case PT_LINETO: 00266 { 00267 BOOL IsCloseFigure = ((IVerbs[i] & PT_CLOSEFIGURE) != 0); // Remember if this is the closing element 00268 00269 OpenElement(PT_LINETO, i); 00270 if (!PFlags.QuantiseAll) 00271 { 00272 if (!PFlags.QuantiseLines) 00273 ok = NewPoint(PT_LINETO, &ICoords[i]); 00274 else 00275 { 00276 DocCoord End = ICoords[i]; 00277 for (double mu = 0.2; (mu<1.2) && ok; mu+=0.2 ) 00278 { 00279 DocCoord dest; 00280 dest.x = (INT32)((1-mu)*ProcPreviousEl.x + mu*End.x); 00281 dest.y = (INT32)((1-mu)*ProcPreviousEl.y + mu*End.y); 00282 ok = NewPoint(PT_LINETO, &dest); 00283 } 00284 } 00285 } 00286 else 00287 { 00288 ok = InsertQuantisedLineTo(&ICoords[i], &ProcPreviousEl); 00289 } 00290 if (CloseElement(ok, PT_LINETO, i)) 00291 i=(numinsource-1); 00292 else if (IsCloseFigure) // If continuing, and this is the end of a closed figure 00293 CloseFigure(); // then close it off 00294 } 00295 break; 00296 00297 case PT_BEZIERTO: 00298 { 00299 BOOL IsCloseFigure = ((IVerbs[i+2] & PT_CLOSEFIGURE) != 0); // Remember if this is the closing element 00300 00301 OpenElement(PT_BEZIERTO, i); 00302 if (!PFlags.FlattenCurves) 00303 ok = NewPoint(PT_BEZIERTO, &ICoords[i]); 00304 else 00305 { 00306 ok = FlattenCurve(ProcPreviousEl.x, ProcPreviousEl.y, 00307 ICoords[i].x, ICoords[i].y, 00308 ICoords[i+1].x, ICoords[i+1].y, 00309 ICoords[i+2].x, ICoords[i+2].y, (PFlags.QuantiseAll) ); 00310 } 00311 if (CloseElement(ok, PT_BEZIERTO, i)) 00312 i=(numinsource-1); 00313 else 00314 { 00315 if (IsCloseFigure) // If continuing, and this is the end of a closed figure 00316 CloseFigure(); // then close it off 00317 00318 i+=2; 00319 } 00320 } 00321 break; 00322 00323 default: ERROR3("ProcessPath::Process() - unknown path verb!"); 00324 00325 } 00326 ICoords = ProcSource->GetCoordArray(); 00327 IVerbs = ProcSource->GetVerbArray(); 00328 i++; 00329 ProcFirstPoint = FALSE; 00330 ProcPreviousEl = ICoords[i-1]; 00331 } 00332 return ok; 00333 }
|
|
Definition at line 166 of file pathproc.h. |
|
Definition at line 168 of file pathproc.h. |
|
Definition at line 169 of file pathproc.h. |
|
Definition at line 167 of file pathproc.h. |
|
Definition at line 171 of file pathproc.h. |
|
Definition at line 165 of file pathproc.h. |