#include <blndhelp.h>
Inheritance diagram for BlendHelpers:
Public Member Functions | |
BlendHelpers () | |
~BlendHelpers () | |
BOOL | BlendAttributes (BlendNodeParam *pParam, CCAttrMap *pAttrMap) |
Blends the attributes of the two BlendPath objects by the amount specified in BlendRatio. | |
BOOL | BlendPaths (BlendNodeParam *pParam, Path *pPath) |
Blends two BlendPath objects by the amount specified in BlendRatio. | |
Private Member Functions | |
CC_DECLARE_DYNAMIC (BlendHelpers) | |
Trans2DMatrix * | GetRotateMatrix (NodeRenderableBounded *pNode, double Angle) |
Function that returns a matrix that will rotate around the centre of the bounds of the given node. | |
DocCoord * | GetCoordArray (UINT32 MinSize) |
Used to get an array you can write to. | |
PathVerb * | GetVerbArray (UINT32 MinSize) |
Used to get an array you can write to. | |
PathFlags * | GetFlagArray (UINT32 MinSize) |
Used to get an array you can write to. | |
UINT32 * | GetGBlendBuff (UINT32 MinSize) |
Used to get a buffer you can write to. | |
BOOL | ReallocTempBuffers (UINT32 Size) |
Allocates memory for the temp path arrays, and sets the size var to 0 You can use calls to GetCoordArray(), GetVerbArray() and GetFlagArray() to get the alloced arrays. | |
void | DeallocTempBuffers () |
Releases memory allocated for the temp path arrays, and sets the size var to 0. | |
Private Attributes | |
UINT32 | m_TempArraySize |
DocCoord * | m_pTempCoords |
PathVerb * | m_pTempVerbs |
PathFlags * | m_pTempFlags |
UINT32 | m_GBlendBuffSize |
UINT32 * | m_pGBlendBuff |
UINT32 | m_ArrayLength |
Definition at line 122 of file blndhelp.h.
|
Definition at line 120 of file blndhelp.cpp. 00121 { 00122 m_TempArraySize = 0; 00123 m_pTempCoords = NULL; 00124 m_pTempVerbs = NULL; 00125 m_pTempFlags = NULL; 00126 m_GBlendBuffSize = 0; 00127 m_pGBlendBuff = NULL; 00128 m_ArrayLength = 0; 00129 }
|
|
Definition at line 131 of file blndhelp.cpp. 00132 { 00133 DeallocTempBuffers(); 00134 }
|
|
Blends the attributes of the two BlendPath objects by the amount specified in BlendRatio.
Definition at line 149 of file blndhelp.cpp. 00150 { 00151 // Check entry params 00152 double BlendRatio = pParam->GetAttrBlendRatio(); 00153 00154 BOOL ok = (pParam != NULL && pBlendedAttrMap != NULL); 00155 ERROR3IF(!ok,"One or more NULL entry params"); 00156 if (!ok) return FALSE; 00157 00158 // Find the attributes that are applied to the blend paths 00159 00160 BlendPath * pBlendPathStart = pParam->GetStartBlendPath(); 00161 BlendPath * pBlendPathEnd = pParam->GetEndBlendPath(); 00162 ok = (pBlendPathStart != NULL && pBlendPathEnd != NULL); 00163 ERROR3IF(!ok, "Blend paths are NULL"); 00164 if (!ok) return FALSE; 00165 00166 ok = (pBlendPathStart->GetCreatedByNode() != NULL && 00167 pBlendPathEnd->GetCreatedByNode() != NULL); 00168 ERROR3IF(!ok, "Blend path created by nodes are NULL"); 00169 if (!ok) return FALSE; 00170 00171 BOOL startExludeGLAs = TRUE, endExcludeGLAs = TRUE; 00172 00173 NodeAttribute * pAttr = NULL; 00174 if(pBlendPathStart->GetCreatedByNode()->FindAppliedAttribute(CC_RUNTIME_CLASS(AttrFeather),&pAttr)) 00175 { 00176 startExludeGLAs = FALSE; 00177 } 00178 if(pBlendPathEnd->GetCreatedByNode()->FindAppliedAttribute(CC_RUNTIME_CLASS(AttrFeather),&pAttr)) 00179 { 00180 endExcludeGLAs = FALSE; 00181 } 00182 00183 CCAttrMap* pAttrMapStart = CCAttrMap::MakeAppliedAttrMap(pBlendPathStart->GetCreatedByNode(), startExludeGLAs); 00184 CCAttrMap* pAttrMapEnd = CCAttrMap::MakeAppliedAttrMap(pBlendPathEnd->GetCreatedByNode(), endExcludeGLAs); 00185 00186 if (!pAttrMapStart || !pAttrMapEnd) 00187 return FALSE; 00188 00189 // find the attributes on the nodes 00190 00191 if (pParam->GetNodeBlendPath() != NULL) 00192 { 00193 Trans2DMatrix* pRotateStart = GetRotateMatrix(pParam->GetNodeStart(), 00194 360.0 - pParam->GetAngleStart()); 00195 Trans2DMatrix* pRotateEnd = GetRotateMatrix(pParam->GetNodeEnd(), 00196 360.0 - pParam->GetAngleEnd()); 00197 if (pRotateStart) pAttrMapStart->Transform(*pRotateStart); 00198 if (pRotateEnd) pAttrMapEnd ->Transform(*pRotateEnd); 00199 00200 if (pRotateStart) 00201 delete pRotateStart; 00202 00203 if (pRotateEnd) 00204 delete pRotateEnd; 00205 } 00206 00207 // These vars are used as params to the CCAttrMap funcs 00208 CCRuntimeClass *pTypeStart; 00209 void *pValStart; 00210 void *pValEnd; 00211 double OldBlendRatio = pParam->GetBlendRatio(); 00212 // Process each attribute in turn 00213 CCAttrMap::iterator PosStart = pAttrMapStart->GetStartPosition(); 00214 CCAttrMap::iterator EndStart = pAttrMapStart->GetEndPosition(); 00215 for (;PosStart != EndStart;) 00216 { 00217 // Get a ptr to the attr at position PosStart in the start node's attr map 00218 pAttrMapStart->GetNextAssoc(PosStart,pTypeStart,pValStart); 00219 NodeAttribute* pNodeAttrStart = (NodeAttribute *)pValStart; 00220 00221 BlendRatio = OldBlendRatio; 00222 // Diccon 10/99 When using non-linear profiles for the objects those attributes 00223 // that make use of control points were not being profiled, making the objects look strange. 00224 // to avoid this those attributes now share the same profiles as the objects. 00225 if (pNodeAttrStart->IsAGradFill()) 00226 { 00227 00228 if (!((AttrFillGeometry*)pNodeAttrStart)->IsAColourFill()) 00229 { 00230 00231 BlendRatio = pParam->GetObjectRatio(); 00232 00233 } 00234 else 00235 { 00236 BlendRatio = pParam->GetInvertedAttributeRatio(); 00237 00238 } 00239 00240 } 00241 if (pNodeAttrStart->IsAFlatFill() || (pNodeAttrStart->GetRuntimeClass() == CC_RUNTIME_CLASS(AttrLineWidth))) 00242 { 00243 BlendRatio = pParam->GetInvertedAttributeRatio(); 00244 } 00245 00246 // Get a blended attribute 00247 NodeAttribute* pBlendedNodeAttr = NULL; 00248 00249 // Find an attr of the same type in the end object's attr list, 00250 // and blend the two attrs together 00251 pValEnd = NULL; 00252 00253 if (pAttrMapEnd->Lookup(pTypeStart,pValEnd)) 00254 { 00255 // We've found a matching end attr, so try to blend it with the start attr 00256 00257 // Set up the param object to pass to the start attr's blend method 00258 BlendAttrParam BlendParam; 00259 00260 NodeAttribute * pEndAttr = (NodeAttribute *)pValEnd; 00261 00262 // Initialise the BlendParam with the end attr and blend ratio 00263 if (BlendParam.Init(pParam->GetRenderRegion(), 00264 pEndAttr,BlendRatio, 00265 pParam->GetColourBlendType(), 00266 pAttrMapStart, pAttrMapEnd)) 00267 { 00268 // Successfully initialised, so now try blending the attributes 00269 if (pNodeAttrStart->Blend(&BlendParam)) 00270 { 00271 // Attrs successfully blended, now get a ptr to the new attr. 00272 // Once we get the blended attr ptr, it belongs to us, so we have 00273 // to delete it when it is not needed 00274 pBlendedNodeAttr = BlendParam.GetBlendedAttr(); 00275 } 00276 } 00277 } 00278 00279 // If we have a blended attr, pBlendedNodeAttr != NULL 00280 if (pBlendedNodeAttr != NULL) 00281 { 00282 // Get the type of the blended attr 00283 CCRuntimeClass *pTypeBlend = pBlendedNodeAttr->GetAttributeType(); 00284 void* pValBlend; 00285 00286 // If we already have an attr in the blended attr map of the same type, 00287 // remove it and delete it, before inserting a new attr of this type 00288 if (pBlendedAttrMap->Lookup(pTypeBlend,pValBlend)) 00289 { 00290 if (pValBlend != NULL) 00291 { 00292 pBlendedAttrMap->RemoveKey(pTypeBlend); 00293 delete (NodeAttribute*)pValBlend; 00294 } 00295 } 00296 // add it to the blend map 00297 pBlendedAttrMap->SetAt(pTypeBlend,pBlendedNodeAttr); 00298 } 00299 } 00300 00301 if (pParam->GetNodeBlendPath() != NULL) 00302 { 00303 Trans2DMatrix* pRotateStart = GetRotateMatrix(pParam->GetNodeStart(), 00304 pParam->GetAngleStart()); 00305 Trans2DMatrix* pRotateEnd = GetRotateMatrix(pParam->GetNodeEnd(), 00306 pParam->GetAngleEnd() ); 00307 if (pRotateStart) pAttrMapStart->Transform(*pRotateStart); 00308 if (pRotateEnd) pAttrMapEnd ->Transform(*pRotateEnd); 00309 00310 if (pRotateStart) 00311 delete pRotateStart; 00312 00313 if (pRotateEnd) 00314 delete pRotateEnd; 00315 } 00316 00317 delete pAttrMapStart; 00318 delete pAttrMapEnd; 00319 00320 return TRUE; 00321 }
|
|
Blends two BlendPath objects by the amount specified in BlendRatio.
ArrayLength = the length of all three arrays This allows the caller to decide what to do with the blended path in a very flexible way.
Definition at line 545 of file blndhelp.cpp. 00546 { 00547 // Check entry params 00548 BlendPath * pBlendPathStart = pParam->GetStartBlendPath(); 00549 BlendPath * pBlendPathEnd = pParam->GetEndBlendPath(); 00550 00551 ERROR2IF(!pBlendPathStart->GetBlendNode()->IsNodePath(), FALSE, 00552 "Start blend path's node isn't a node path"); 00553 00554 ERROR2IF(!pBlendPathEnd->GetBlendNode()->IsNodePath(), FALSE, 00555 "End blend path's node isn't a node path"); 00556 00557 BOOL ok = (pBlendPathStart != NULL && pBlendPathEnd != NULL); 00558 if (ok) ok = (pBlendPathStart->GetBlendNode() != NULL && pBlendPathEnd->GetBlendNode() != NULL); 00559 ERROR3IF(!ok,"One or more NULL entry params"); 00560 if (!ok) return FALSE; 00561 00562 // Get the types of the two paths 00563 PathTypeEnum PathTypeStart = pBlendPathStart->GetPathType(); 00564 PathTypeEnum PathTypeEnd = pBlendPathEnd ->GetPathType(); 00565 00566 // The blended path will be closed if either of the paths is a shape 00567 BOOL Closed = (PathTypeStart == PATHTYPE_SHAPE) || (PathTypeEnd == PATHTYPE_SHAPE); 00568 00569 Path * pPathStart = NULL; 00570 00571 // Find the paths associated with the start and end blend paths 00572 if (pBlendPathStart->GetBlendNode()->IsNodePath()) 00573 { 00574 pPathStart = &(((NodePath *)pBlendPathStart->GetBlendNode())->InkPath); 00575 } 00576 00577 Path * pPathEnd = NULL; 00578 00579 if (pBlendPathEnd->GetBlendNode()->IsNodePath()) 00580 { 00581 pPathEnd = &(((NodePath *)pBlendPathEnd->GetBlendNode())->InkPath); 00582 } 00583 00584 // Calculate how large the arrays have to be to store the blended path definition 00585 INT32 DestPathSize = ((pPathStart->GetNumCoords()+pPathEnd->GetNumCoords())*3)+500; 00586 00587 // Get some arrays used to hold the blended path data, and error if any are NULL 00588 DocCoord* pDestCoords = GetCoordArray(DestPathSize); 00589 PathVerb* pDestVerbs = GetVerbArray(DestPathSize); 00590 PathFlags* pDestFlags = GetFlagArray(DestPathSize); 00591 UINT32* pBuff = GetGBlendBuff(DestPathSize); 00592 if (pDestCoords == NULL || pDestVerbs == NULL || pDestFlags == NULL || pBuff == NULL) 00593 return FALSE; 00594 00595 // This section copes with the case when blending a line with a shape. 00596 // In this case we need to get a temp path the is actually a shape version of the line. 00597 // The line is simply reversed back onto itself to form a shape that would look identical to the 00598 // line if rendered. This allows the line to appear to open up to the shape when blended. 00599 Path Shape; 00600 if (PathTypeStart != PathTypeEnd) 00601 { 00602 BOOL ok = FALSE; 00603 if (!Shape.Initialise()) return FALSE; 00604 00605 // if going from a line to a shape, convert the start path to a shape 00606 if (PathTypeStart == PATHTYPE_LINE && PathTypeEnd == PATHTYPE_SHAPE) 00607 { 00608 ok = NodeBlender::ConvertLineToShape(pPathStart,&Shape); 00609 pPathStart = &Shape; 00610 } 00611 00612 // if going from a shape to a line, convert the end path to a shape 00613 if (PathTypeStart == PATHTYPE_SHAPE && PathTypeEnd == PATHTYPE_LINE) 00614 { 00615 ok = NodeBlender::ConvertLineToShape(pPathEnd,&Shape); 00616 pPathEnd = &Shape; 00617 } 00618 00619 if (!ok) return FALSE; 00620 } 00621 00622 // The blend should do a one-to-one mapping when the OneToOne flag is set AND both paths 00623 // have the same number of elements 00624 BOOL OneToOne = FALSE; 00625 if (pParam->GetOneToOne()) 00626 OneToOne = (pBlendPathStart->GetNumElements() == pBlendPathEnd->GetNumElements()); 00627 00628 // Now actually blend the two paths 00629 00630 GBlend GBlendObj; 00631 00632 // Define the blend 00633 GBlendObj.Define( (PPOINT)pPathStart->GetCoordArray(), // Specify the start path 00634 pPathStart->GetVerbArray(), 00635 pPathStart->GetNumCoords(), 00636 00637 (PPOINT)pPathEnd ->GetCoordArray(), // Specify the end path 00638 pPathEnd ->GetVerbArray(), 00639 pPathEnd ->GetNumCoords(), 00640 00641 OneToOne, // The one-to-one flag 00642 1024, // Flatness 00643 00644 pBuff, // Buffer for GBlend to use 00645 DestPathSize*sizeof(UINT32)); // The buffer size 00646 00647 // Blend the paths 00648 m_ArrayLength = GBlendObj.Blend(pParam->GetBlendRatio(), // The blend ratio, 0.0 < BlendRatio < 1.0 00649 (PPOINT)pDestCoords, // Array to store blended coords 00650 pDestVerbs, // Array to store blended verbs 00651 DestPathSize); // The num elements in the two arrays 00652 00653 00654 // If we're blending a line to another line, we need to make sure that the blended line 00655 // is going in a direction that corresponds to the source lines. This ensures attributes 00656 // that depend on this direction (e.g. start and end arrows) look correct. 00657 // 00658 // When creating blend paths of lines, we can detect if the blend path has been reversed, 00659 // in relation to the original path, by the original mapping value. 00660 // If it's 0 it has NOT been reversed, otherwise it's been reversed. 00661 // 00662 // If the blend ratio is <=0.5, the blended path is closest to the start blend path, 00663 // so we look at the start blend path's original mapping. 00664 // 00665 // If blend ration > 0.5, look at the end blend path's original mapping. 00666 // 00667 // The (BlendRation <= 0.5) cut-off point is the same as the cut-off point used in the blending 00668 // of attributes. 00669 if (pBlendPathStart->IsLine() && pBlendPathEnd->IsLine()) 00670 { 00671 BlendPath* pBlendPath; 00672 if (pParam->GetBlendRatio() <= 0.5) 00673 pBlendPath = pBlendPathStart; 00674 else 00675 pBlendPath = pBlendPathEnd; 00676 00677 if (pBlendPath->GetOrigMapping() != 0) 00678 NodeBlender::ReversePath(pDestCoords,pDestVerbs,m_ArrayLength); 00679 } 00680 00681 // We need to do some work on the blended path 00682 if (!NodeBlender::ProcessBlendedPath(pDestCoords,pDestVerbs,pDestFlags,m_ArrayLength,Closed)) 00683 return FALSE; 00684 00685 Path RetnPath; 00686 RetnPath.Initialise(m_ArrayLength); 00687 00688 BOOL Filled = pPathStart->IsFilled || pPathEnd->IsFilled; 00689 BOOL Stroked = pPathStart->IsStroked || pPathEnd->IsStroked; 00690 00691 RetnPath.MergeTwoPaths(pDestCoords,pDestVerbs,pDestFlags,m_ArrayLength,Filled); 00692 00693 pPath->ClearPath(); 00694 pPath->CloneFrom(RetnPath); 00695 pPath->IsFilled = Filled; 00696 pPath->IsStroked = Stroked; 00697 00698 return TRUE; 00699 }
|
|
|
|
Releases memory allocated for the temp path arrays, and sets the size var to 0.
Definition at line 373 of file blndhelp.cpp. 00374 { 00375 if (m_pTempCoords != NULL) { CCFree(m_pTempCoords); m_pTempCoords = NULL; } 00376 if (m_pTempVerbs != NULL) { CCFree(m_pTempVerbs); m_pTempVerbs = NULL; } 00377 if (m_pTempFlags != NULL) { CCFree(m_pTempFlags); m_pTempFlags = NULL; } 00378 m_TempArraySize = 0; 00379 00380 if (m_pGBlendBuff != NULL) { CCFree(m_pGBlendBuff); m_pGBlendBuff = NULL; } 00381 m_GBlendBuffSize = 0; 00382 }
|
|
Used to get an array you can write to.
Definition at line 398 of file blndhelp.cpp. 00399 { 00400 MinSize++; 00401 if (m_TempArraySize >= MinSize) return m_pTempCoords; 00402 00403 if (ReallocTempBuffers(MinSize)) 00404 return m_pTempCoords; 00405 else 00406 return NULL; 00407 }
|
|
Used to get an array you can write to.
Definition at line 448 of file blndhelp.cpp. 00449 { 00450 MinSize++; 00451 if (m_TempArraySize >= MinSize) return m_pTempFlags; 00452 00453 if (ReallocTempBuffers(MinSize)) 00454 return m_pTempFlags; 00455 else 00456 return NULL; 00457 }
|
|
Used to get a buffer you can write to.
Definition at line 473 of file blndhelp.cpp. 00474 { 00475 MinSize++; 00476 if (m_GBlendBuffSize >= MinSize) return m_pGBlendBuff; 00477 00478 if (m_pGBlendBuff != NULL) CCFree(m_pGBlendBuff); 00479 00480 m_pGBlendBuff = (UINT32*) CCMalloc(MinSize*sizeof(UINT32)); 00481 00482 if (m_pGBlendBuff != NULL) 00483 m_GBlendBuffSize = MinSize; 00484 else 00485 m_GBlendBuffSize = 0; 00486 00487 return m_pGBlendBuff; 00488 }
|
|
Function that returns a matrix that will rotate around the centre of the bounds of the given node.
Definition at line 508 of file blndhelp.cpp. 00509 { 00510 Trans2DMatrix* pMatrix = NULL; 00511 00512 if (pNode != NULL && fmod(Angle,360.0) != 0.0) 00513 { 00514 DocRect BoundsStart = pNode->GetBoundingRect(); 00515 DocCoord Centre = BoundsStart.Centre(); 00516 pMatrix = new Trans2DMatrix(Centre,Angle); 00517 } 00518 00519 return pMatrix; 00520 }
|
|
Used to get an array you can write to.
Definition at line 423 of file blndhelp.cpp. 00424 { 00425 MinSize++; 00426 if (m_TempArraySize >= MinSize) return m_pTempVerbs; 00427 00428 if (ReallocTempBuffers(MinSize)) 00429 return m_pTempVerbs; 00430 else 00431 return NULL; 00432 }
|
|
Allocates memory for the temp path arrays, and sets the size var to 0 You can use calls to GetCoordArray(), GetVerbArray() and GetFlagArray() to get the alloced arrays.
Definition at line 338 of file blndhelp.cpp. 00339 { 00340 DeallocTempBuffers(); 00341 00342 // Allocate the arrays 00343 m_TempArraySize = Size; 00344 m_pTempCoords = (DocCoord*) CCMalloc(Size*sizeof(DocCoord)); 00345 m_pTempVerbs = (PathVerb*) CCMalloc(Size*sizeof(PathVerb)); 00346 m_pTempFlags = (PathFlags*) CCMalloc(Size*sizeof(PathFlags)); 00347 00348 // If any of the arrays are not allocated, dealloc the alloced ones, and return FALSE 00349 if (m_pTempCoords == NULL || m_pTempVerbs == NULL || m_pTempFlags == NULL) 00350 { 00351 DeallocTempBuffers(); 00352 return FALSE; 00353 } 00354 00355 // It's all OK, so return TRUE 00356 return TRUE; 00357 }
|
|
Definition at line 159 of file blndhelp.h. |
|
Definition at line 157 of file blndhelp.h. |
|
Definition at line 158 of file blndhelp.h. |
|
Definition at line 154 of file blndhelp.h. |
|
Definition at line 156 of file blndhelp.h. |
|
Definition at line 155 of file blndhelp.h. |
|
Definition at line 153 of file blndhelp.h. |