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 #include "camtypes.h"
00101
00102
00103 #include "lineattr.h"
00104 #include "blendatt.h"
00105 #include "blndhelp.h"
00106 #include "attrmap.h"
00107 #include "nodebldr.h"
00108
00109
00110 #include "ndbldpth.h"
00111
00112 #include "gblend.h"
00113
00114 #include "fthrattr.h"
00115
00116 CC_IMPLEMENT_DYNAMIC(BlendHelpers, CCObject);
00117 CC_IMPLEMENT_DYNAMIC(SumAllPathsPathProcessor, PathProcessor);
00118 CC_IMPLEMENT_DYNCREATE(SumAllPathsElem, ListItem);
00119
00120 BlendHelpers::BlendHelpers()
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 }
00130
00131 BlendHelpers::~BlendHelpers()
00132 {
00133 DeallocTempBuffers();
00134 }
00135
00136
00137
00138
00139
00140
00141
00142
00143
00144
00145
00146
00147
00148
00149 BOOL BlendHelpers::BlendAttributes(BlendNodeParam * pParam, CCAttrMap* pBlendedAttrMap)
00150 {
00151
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
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
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
00208 CCRuntimeClass *pTypeStart;
00209 void *pValStart;
00210 void *pValEnd;
00211 double OldBlendRatio = pParam->GetBlendRatio();
00212
00213 CCAttrMap::iterator PosStart = pAttrMapStart->GetStartPosition();
00214 CCAttrMap::iterator EndStart = pAttrMapStart->GetEndPosition();
00215 for (;PosStart != EndStart;)
00216 {
00217
00218 pAttrMapStart->GetNextAssoc(PosStart,pTypeStart,pValStart);
00219 NodeAttribute* pNodeAttrStart = (NodeAttribute *)pValStart;
00220
00221 BlendRatio = OldBlendRatio;
00222
00223
00224
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
00247 NodeAttribute* pBlendedNodeAttr = NULL;
00248
00249
00250
00251 pValEnd = NULL;
00252
00253 if (pAttrMapEnd->Lookup(pTypeStart,pValEnd))
00254 {
00255
00256
00257
00258 BlendAttrParam BlendParam;
00259
00260 NodeAttribute * pEndAttr = (NodeAttribute *)pValEnd;
00261
00262
00263 if (BlendParam.Init(pParam->GetRenderRegion(),
00264 pEndAttr,BlendRatio,
00265 pParam->GetColourBlendType(),
00266 pAttrMapStart, pAttrMapEnd))
00267 {
00268
00269 if (pNodeAttrStart->Blend(&BlendParam))
00270 {
00271
00272
00273
00274 pBlendedNodeAttr = BlendParam.GetBlendedAttr();
00275 }
00276 }
00277 }
00278
00279
00280 if (pBlendedNodeAttr != NULL)
00281 {
00282
00283 CCRuntimeClass *pTypeBlend = pBlendedNodeAttr->GetAttributeType();
00284 void* pValBlend;
00285
00286
00287
00288 if (pBlendedAttrMap->Lookup(pTypeBlend,pValBlend))
00289 {
00290 if (pValBlend != NULL)
00291 {
00292 pBlendedAttrMap->RemoveKey(pTypeBlend);
00293 delete (NodeAttribute*)pValBlend;
00294 }
00295 }
00296
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 }
00322
00323
00324
00325
00326
00327
00328
00329
00330
00331
00332
00333
00334
00335
00336
00337
00338 BOOL BlendHelpers::ReallocTempBuffers(UINT32 Size)
00339 {
00340 DeallocTempBuffers();
00341
00342
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
00349 if (m_pTempCoords == NULL || m_pTempVerbs == NULL || m_pTempFlags == NULL)
00350 {
00351 DeallocTempBuffers();
00352 return FALSE;
00353 }
00354
00355
00356 return TRUE;
00357 }
00358
00359
00360
00361
00362
00363
00364
00365
00366
00367
00368
00369
00370
00371
00372
00373 void BlendHelpers::DeallocTempBuffers()
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 }
00383
00384
00385
00386
00387
00388
00389
00390
00391
00392
00393
00394
00395
00396
00397
00398 DocCoord* BlendHelpers::GetCoordArray(UINT32 MinSize)
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 }
00408
00409
00410
00411
00412
00413
00414
00415
00416
00417
00418
00419
00420
00421
00422
00423 PathVerb* BlendHelpers::GetVerbArray(UINT32 MinSize)
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 }
00433
00434
00435
00436
00437
00438
00439
00440
00441
00442
00443
00444
00445
00446
00447
00448 PathFlags* BlendHelpers::GetFlagArray(UINT32 MinSize)
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 }
00458
00459
00460
00461
00462
00463
00464
00465
00466
00467
00468
00469
00470
00471
00472
00473 UINT32* BlendHelpers::GetGBlendBuff(UINT32 MinSize)
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 }
00489
00490
00491
00492
00493
00494
00495
00496
00497
00498
00499
00500
00501
00502
00503
00504
00505
00506
00507
00508 Trans2DMatrix* BlendHelpers::GetRotateMatrix(NodeRenderableBounded* pNode,double Angle)
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 }
00521
00522
00523
00524
00525
00526
00527
00528
00529
00530
00531
00532
00533
00534
00535
00536
00537
00538
00539
00540
00541
00542
00543
00544
00545 BOOL BlendHelpers::BlendPaths(BlendNodeParam * pParam, Path * pPath)
00546 {
00547
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
00563 PathTypeEnum PathTypeStart = pBlendPathStart->GetPathType();
00564 PathTypeEnum PathTypeEnd = pBlendPathEnd ->GetPathType();
00565
00566
00567 BOOL Closed = (PathTypeStart == PATHTYPE_SHAPE) || (PathTypeEnd == PATHTYPE_SHAPE);
00568
00569 Path * pPathStart = NULL;
00570
00571
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
00585 INT32 DestPathSize = ((pPathStart->GetNumCoords()+pPathEnd->GetNumCoords())*3)+500;
00586
00587
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
00596
00597
00598
00599 Path Shape;
00600 if (PathTypeStart != PathTypeEnd)
00601 {
00602 BOOL ok = FALSE;
00603 if (!Shape.Initialise()) return FALSE;
00604
00605
00606 if (PathTypeStart == PATHTYPE_LINE && PathTypeEnd == PATHTYPE_SHAPE)
00607 {
00608 ok = NodeBlender::ConvertLineToShape(pPathStart,&Shape);
00609 pPathStart = &Shape;
00610 }
00611
00612
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
00623
00624 BOOL OneToOne = FALSE;
00625 if (pParam->GetOneToOne())
00626 OneToOne = (pBlendPathStart->GetNumElements() == pBlendPathEnd->GetNumElements());
00627
00628
00629
00630 GBlend GBlendObj;
00631
00632
00633 GBlendObj.Define( (PPOINT)pPathStart->GetCoordArray(),
00634 pPathStart->GetVerbArray(),
00635 pPathStart->GetNumCoords(),
00636
00637 (PPOINT)pPathEnd ->GetCoordArray(),
00638 pPathEnd ->GetVerbArray(),
00639 pPathEnd ->GetNumCoords(),
00640
00641 OneToOne,
00642 1024,
00643
00644 pBuff,
00645 DestPathSize*sizeof(UINT32));
00646
00647
00648 m_ArrayLength = GBlendObj.Blend(pParam->GetBlendRatio(),
00649 (PPOINT)pDestCoords,
00650 pDestVerbs,
00651 DestPathSize);
00652
00653
00654
00655
00656
00657
00658
00659
00660
00661
00662
00663
00664
00665
00666
00667
00668
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
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 }
00700
00702
00703
00704
00705
00706
00707
00708
00709
00710
00711
00712
00713
00714
00715
00716
00717
00718
00719
00720
00721 BOOL CompoundNodeBlendBecomeA::PassBack(NodeRenderableInk* pNewNode,
00722 NodeRenderableInk* pCreatedByNode,
00723 CCAttrMap* pAttrMap)
00724
00725 {
00726 ERROR2IF(pCreatedByNode == NULL, FALSE, "CompoundNodeBlendBecomeA - no created by node");
00727
00728 NodeRenderableInk * pNewCompound = NULL;
00729
00730 if (pAttrMap == NULL)
00731 {
00732 CCAttrMap * pAppliedAttrMap = CCAttrMap::MakeAppliedAttrMap(pCreatedByNode);
00733
00734 pAttrMap = pAppliedAttrMap->Copy();
00735 delete pAppliedAttrMap;
00736 }
00737
00738 pNewCompound = m_pCompound->CreateTreeFromNodeToBlend(pNewNode, pAttrMap);
00739
00740 if (pNewCompound && pNewCompound->IsCompound())
00741 {
00742 ((NodeCompound *)pNewCompound)->SetBlendCreatedByNode(m_pCompound);
00743
00744 TRACEUSER( "DavidM", _T("Count %d Num path nodes %d\n"),
00745 m_Count, m_NumPathNodes);
00746
00747 if (m_Count == 0)
00748 {
00749 ((NodeCompound*)pNewCompound)->SetStartBlendGroupNode();
00750 }
00751
00752 if (m_Count == m_NumPathNodes-1)
00753 {
00754 ((NodeCompound*)pNewCompound)->SetEndBlendGroupNode();
00755 }
00756 }
00757
00758 m_Count++;
00759
00760 return m_pBecomeA->PassBack(pNewCompound, pCreatedByNode, pAttrMap);
00761 }
00762
00764
00765
00766
00767
00768
00769
00770
00771
00772
00773
00774
00775
00776
00777
00778 SumAllPathsPathProcessor::SumAllPathsPathProcessor(BOOL bDrawOriginalPaths)
00779 {
00780 m_bDrawPaths = bDrawOriginalPaths;
00781 m_bEnabled = TRUE;
00782 }
00783
00784
00785
00786
00787
00788
00789
00790
00791
00792
00793
00794
00795
00796 SumAllPathsPathProcessor::~SumAllPathsPathProcessor()
00797 {
00798 PathList.DeleteAll();
00799 }
00800
00801
00802
00803
00804
00805
00806
00807
00808
00809
00810
00811
00812
00813
00814
00815 void SumAllPathsPathProcessor::ProcessPath(Path *pPath,
00816 RenderRegion *pRender,
00817 PathShape ShapePath)
00818 {
00819 if (!m_bEnabled)
00820 {
00821 pRender->DrawPath(pPath, this);
00822 return;
00823 }
00824
00825 if (m_bDrawPaths)
00826 {
00827 pRender->DrawPath(pPath, this);
00828 }
00829
00830
00831 CCAttrMap *pAttrMap = CCAttrMap::MakeAttrMapFromRenderRegion(pRender);
00832
00833 SumAllPathsElem * pElem = new SumAllPathsElem(pPath, pAttrMap);
00834
00835 PathList.AddTail(pElem);
00836 }
00837
00838
00839
00840
00841
00842
00843
00844
00845
00846
00847
00848
00849
00850
00851
00852
00853
00854 void SumAllPathsPathProcessor::InsertSumAllPathsElem (SumAllPathsElem* newElem)
00855 {
00856 PathList.AddTail(newElem);
00857 }
00858
00860
00861
00862 SumAllPathsElem::SumAllPathsElem(Path * pPath, CCAttrMap * pAttrMap)
00863 {
00864 m_Path.Initialise(pPath->GetNumCoords());
00865 m_Path.CopyPathDataFrom(pPath);
00866
00867 m_pAttrMap = pAttrMap;
00868 }
00869
00870 SumAllPathsElem::~SumAllPathsElem()
00871 {
00872
00873 m_pAttrMap->DeleteAttributes();
00874 delete m_pAttrMap;
00875 }
00876
00877
00878
00879
00880
00881
00882
00883