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
00105
00106 #undef CDR_DOEXTRUDES
00107
00108 #include "camtypes.h"
00109 #include "cdrfiltr.h"
00110
00111
00112
00113 #include "progress.h"
00114 #include "cdrcol.h"
00115 #include "rifffile.h"
00116 #include "cdrform.h"
00117
00118 #include "nodepath.h"
00119
00120 #include "page.h"
00121
00122 #include "nodershp.h"
00123
00124
00125 #include "ndoptmz.h"
00126 #include "collist.h"
00127 #include "layer.h"
00128 #include "sglayer.h"
00129 #include "sprdmsg.h"
00130 #include "nodebmp.h"
00131 #include "nodetxts.h"
00132
00133 #include "zoomops.h"
00134
00135 #include "nodemold.h"
00136 #include "moldshap.h"
00137 #include "ndmldpth.h"
00138 #include "nodemldr.h"
00139
00140 #include "fontman.h"
00141
00142
00143 #include "cmxifltr.h"
00144
00145 DECLARE_SOURCE("$Revision: 1282 $");
00146
00147 CC_IMPLEMENT_DYNAMIC(CDRFilter, VectorFilter)
00148 CC_IMPLEMENT_MEMDUMP(CDRAttributeStore, List)
00149 CC_IMPLEMENT_MEMDUMP(CDRAttributeStoredItem, ListItem)
00150 CC_IMPLEMENT_MEMDUMP(CDRArrowheadStore, List)
00151 CC_IMPLEMENT_MEMDUMP(CDRArrowheadStoredItem, ListItem)
00152 CC_IMPLEMENT_MEMDUMP(CDRBitmapStore, List)
00153 CC_IMPLEMENT_MEMDUMP(CDRBitmapStoredItem, ListItem)
00154 CC_IMPLEMENT_MEMDUMP(CDRVectorStore, List)
00155 CC_IMPLEMENT_MEMDUMP(CDRVectorStoredItem, ListItem)
00156 CC_IMPLEMENT_MEMDUMP(CDRFontnameStore, List)
00157 CC_IMPLEMENT_MEMDUMP(CDRFontnameStoredItem, ListItem)
00158 CC_IMPLEMENT_MEMDUMP(CDRLayerList, List)
00159 CC_IMPLEMENT_MEMDUMP(CDRLayerListItem, ListItem)
00160 CC_IMPLEMENT_MEMDUMP(CDRPageList, List)
00161 CC_IMPLEMENT_MEMDUMP(CDRPageListItem, ListItem)
00162 CC_IMPLEMENT_MEMDUMP(CDRActionList, List)
00163 CC_IMPLEMENT_DYNAMIC(CDRActionListItem, ListItem)
00164 CC_IMPLEMENT_DYNAMIC(CDRActionTransform, CDRActionListItem)
00165 CC_IMPLEMENT_DYNAMIC(CDRActionGroupEnd, CDRActionListItem)
00166 CC_IMPLEMENT_MEMDUMP(CDRTransformConvertor, CC_CLASS_MEMDUMP)
00167 CC_IMPLEMENT_MEMDUMP(CDRTransformConvertor5, CDRTransformConvertor)
00168 CC_IMPLEMENT_MEMDUMP(CDRTransformConvertor4, CDRTransformConvertor)
00169 CC_IMPLEMENT_MEMDUMP(CDRTransformConvertor3, CDRTransformConvertor)
00170 CC_IMPLEMENT_MEMDUMP(CDRTextOnPathLink, ListItem)
00171
00172
00173 #define new CAM_DEBUG_NEW
00174
00175 #define PROGRESSUPDATE_MASK 0x7f
00176
00177 INT32 CDRFilter::BitmapNumber = 0;
00178 INT32 CDRFilter::PatternNumber = 0;
00179
00180
00181
00182
00183
00184
00185
00186
00187
00188
00189
00190
00191
00192
00193
00194 BOOL CDRFilter::UpdateProgress(BOOL Now)
00195 {
00196 BOOL Result = TRUE;
00197
00198 if(Now)
00199 {
00200 Result = ContinueSlowJob(RIFF->ProgressNow());
00201 ProgressCount = 0;
00202 }
00203 else
00204 {
00205 if((ProgressCount & PROGRESSUPDATE_MASK) == 0) {
00206 Result = ContinueSlowJob(RIFF->ProgressNow());
00207 }
00208
00209 ProgressCount++;
00210 }
00211
00212 if(!Result)
00213 {
00214 Error::ClearError();
00215 Error::SetError(_R(IDN_USER_CANCELLED));
00216 }
00217
00218 return Result;
00219 }
00220
00221
00222
00223
00224
00225
00226
00227
00228
00229
00230
00231
00232
00233
00234 CDRFilter::CDRFilter(void)
00235 {
00236
00237 FilterName.Load(_R(IDT_CDRFILTER_FILTERNAME));
00238 FilterInfo.Load(_R(IDT_CDRFILTER_FILTERINFO));
00239 FilterID = FILTERID_CDR;
00240
00241 Flags.CanImport = TRUE;
00242 Flags.CanExport = FALSE;
00243
00244 Version = CDRVERSION_NULL;
00245 }
00246
00247
00248
00249
00250
00251
00252
00253
00254
00255
00256
00257
00258
00259
00260
00261 BOOL CDRFilter::Init(void)
00262 {
00263
00264 pOILFilter = new CDROILFilter(this);
00265 if (pOILFilter == NULL)
00266 return FALSE;
00267
00268
00269 Version = CDRVERSION_NULL;
00270
00271
00272 return TRUE;
00273 }
00274
00275
00276
00277
00278
00279
00280
00281
00282
00283
00284
00285
00286
00287
00288
00289 INT32 CDRFilter::HowCompatible(PathName& Filename, ADDR HeaderStart,
00290 UINT32 HeaderSize, UINT32 FileSize)
00291 {
00292 PORTNOTE("byteorder", "TODO: Check byte ordering")
00293 BOOL ExtensionMatches = pOILFilter->DoesExtensionOfPathNameMatch(&Filename);
00294
00295
00296 if (ExtensionMatches)
00297 {
00298 if(camStrncmp((char *)HeaderStart, "WL", 2) == 0)
00299 return 10;
00300 }
00301
00302
00303 FOURCC FormType;
00304
00305 FormType = RIFFFile::CheckRIFFHeader(HeaderStart, FileSize);
00306
00307 Version = CDRVERSION_NULL;
00308
00309 switch (FormType)
00310 {
00311 case cdrT_CDR:
00312 Version = CDRVERSION_3;
00313 break;
00314
00315 case cdrT_CDR4:
00316 case cdrT_CDST:
00317 Version = CDRVERSION_4;
00318 break;
00319
00320 case cdrT_CDR5:
00321 case cdrT_CDT5:
00322 Version = CDRVERSION_5;
00323 break;
00324
00325 case cdrT_CDR6:
00326 case cdrT_CDT6:
00327 Version = CDRVERSION_6;
00328 break;
00329
00330 default:
00331 break;
00332 }
00333
00334 INT32 HowMuchWeLikedThisFile = 0;
00335
00336 if(Version != CDRVERSION_NULL)
00337 {
00338 HowMuchWeLikedThisFile = 10;
00339
00340
00341 if(HasCDRFileGotCMXFile(&Filename))
00342 {
00343 HowMuchWeLikedThisFile = 5;
00344 }
00345 }
00346
00347 return HowMuchWeLikedThisFile;
00348 }
00349
00350
00351
00352
00353
00354
00355
00356
00357
00358
00359
00360
00361
00362
00363
00364
00365 #define CDRFILTER_DI_RETURNERROR {Success = FALSE; return ClearUp();}
00366
00367 BOOL CDRFilter::DoImport(SelOperation *Op, CCLexFile *pDiskFile, Document *DestDoc,
00368 BOOL AutoChosen, ImportPosition *Pos,
00369 KernelBitmap** ppImportedBitmap, DocCoord* pPosTranslate, String_256* URL)
00370 {
00371
00372 if(!AutoChosen && HasCDRFileGotCMXFile(NULL, pDiskFile))
00373 {
00374 TRACEUSER( "Ben", _T(">>> loading CDR file with new CMXImportFilter\n"));
00375
00376
00377 CMXImportFilter *pFilter = new CMXImportFilter;
00378
00379 if(pFilter == NULL)
00380 return FALSE;
00381
00382 BOOL ok = pFilter->DoImport(Op, pDiskFile, DestDoc, AutoChosen, Pos);
00383
00384 delete pFilter;
00385 pFilter = NULL;
00386
00387 return ok;
00388 }
00389
00390
00391 BOOL ExtensionMatches = pOILFilter->DoesExtensionOfFileMatch(pDiskFile);
00392
00393 RIFFFile RIFFo;
00394
00395 TRACEUSER( "Ben", _T("In CDRFilter::DoImport\n"));
00396
00397
00398
00399 ERROR3IF(Fills.IsEmpty() == FALSE, "Fills store not empty");
00400 ERROR3IF(Outlines.IsEmpty() == FALSE, "Outlines store not empty");
00401 ERROR3IF(Styles.IsEmpty() == FALSE, "Styles store not empty");
00402 ERROR3IF(Fonts.IsEmpty() == FALSE, "Fonts store not empty");
00403 ERROR3IF(Arrowheads.IsEmpty() == FALSE, "Arrowheads store not empty");
00404 ERROR3IF(Patterns.IsEmpty() == FALSE, "Patterns store not empty");
00405 ERROR3IF(Bitmaps.IsEmpty() == FALSE, "Bitmap store not empty");
00406 ERROR3IF(Vectors.IsEmpty() == FALSE, "Vector store not empty");
00407 ERROR3IF(TextBBoxes.IsEmpty() == FALSE, "TextBBoxes list not empty");
00408 ERROR3IF(TextV4.IsEmpty() == FALSE, "TextV4 store not empty");
00409 ERROR3IF(TextOnPathLinks.IsEmpty() == FALSE, "TextOnPathLinks not empty");
00410
00411
00412 Fills.DeleteAll();
00413 Outlines.DeleteAll();
00414 Styles.DeleteAll();
00415 Fonts.DeleteAll();
00416 Arrowheads.DeleteAll();
00417 Patterns.DeleteAll();
00418 Bitmaps.DeleteAll();
00419 Vectors.DeleteAll();
00420 TextV4.DeleteAll();
00421 Pages.DeleteAll();
00422 Actions.DeleteAll();
00423 TextBBoxes.DeleteAll();
00424 TextOnPathLinks.DeleteAll();
00425
00426
00427 pDocument = DestDoc;
00428 Success = TRUE;
00429 SlowJobStarted = FALSE;
00430 TranslateByX = 0;
00431 TranslateByY = 0;
00432 PageX = 0;
00433 PageY = 0;
00434 pLevelNodeList = 0;
00435 DoneDoc = FALSE;
00436 DoneMasterPage = FALSE;
00437 InMasterPage = FALSE;
00438 ThisPage = 0;
00439 ThisLayer = 0;
00440 pMadeNode = 0;
00441 ObjectsConverted = 0;
00442 ObjectsFormatWrong = 0;
00443 ObjectsUnknown = 0;
00444 EnvelopesApproximated = 0;
00445 ObjDataBlock = 0;
00446 ObjDataBlockSize = 0;
00447 AttrsAlreadyApplied = FALSE;
00448 TransformChunk = 0;
00449 FontTableV3 = 0;
00450 FontStylesV3 = 0;
00451 LinkTable = 0;
00452 ThisOp = Op;
00453 LinkTransformsExist = FALSE;
00454 TheDocument = DestDoc;
00455
00456
00457 if(ExtensionMatches)
00458 {
00459
00460 TCHAR FirstBit[8];
00461
00462 if(pDiskFile->read((void *)FirstBit, sizeof(FirstBit)).bad())
00463 return FALSE;
00464
00465 ERROR1IF(camStrncmp((char *)FirstBit, "WL", 2) == 0, FALSE, _R(IDT_CDRFILTER_ISAV2FILE));
00466
00467
00468 if(pDiskFile->seek(0).bad())
00469 return FALSE;
00470 }
00471
00472
00473 RIFF = &RIFFo;
00474
00475 FOURCC FormType = RIFF->Init(pDiskFile);
00476
00477 if(FormType == 1)
00478 {
00479 CDRFILTER_DI_RETURNERROR;
00480 }
00481
00482
00483 switch(FormType)
00484 {
00485 case cdrT_CDR:
00486 Version = CDRVERSION_3;
00487 break;
00488
00489 case cdrT_CDR4:
00490 case cdrT_CDST:
00491 Version = CDRVERSION_4;
00492 break;
00493
00494 case cdrT_CDR5:
00495 case cdrT_CDT5:
00496 Version = CDRVERSION_5;
00497 break;
00498
00499 case cdrT_CDR6:
00500 case cdrT_CDT6:
00501
00502 ERROR1(FALSE, _R(IDE_CDRFILTER_CDR6));
00503 break;
00504
00505 default:
00506 TRACEUSER( "Ben", _T("Attempted to load something which wasn't a CDR file. I don't think so..."));
00507 ERROR1(FALSE, _R(IDE_CDRFILTER_NOTCDR));
00508 break;
00509 }
00510
00511
00512 ColList = DestDoc->GetIndexedColours();
00513
00514
00515 UseLayers = FALSE;
00516 #ifdef WEBSTER
00517
00518
00519 if (
00520 (!DestDoc->IsImporting() && Filter::OpenWithLayers) ||
00521 (DestDoc->IsImporting() && Filter::ImportWithLayers)
00522 )
00523 UseLayers = TRUE;
00524 #else
00525
00526
00527
00528 if (DestDoc->IsImporting())
00529 {
00530 Spread * pTheSpread = DestDoc->GetSelectedSpread();
00531 Layer * pFrame = NULL;
00532 if (pTheSpread != NULL)
00533 pFrame = pTheSpread->FindFirstFrameLayer();
00534 if (pFrame != NULL)
00535 UseLayers = FALSE;
00536 else
00537 UseLayers = Filter::ImportWithLayers;
00538 }
00539 else
00540 {
00541 UseLayers = Filter::OpenWithLayers;
00542 }
00543 #endif
00544
00545
00546 if(UseLayers == FALSE)
00547 {
00548 if (!MakeSureLayerExists(DestDoc))
00549 {
00550
00551 CDRFILTER_DI_RETURNERROR;
00552 }
00553 }
00554
00555
00556 pSpread = DestDoc->GetSelectedSpread();
00557 pPage = (Page *) pSpread->FindFirstPageInSpread();
00558
00559
00560 DocRect PageRect = pPage->GetPageRect();
00561 Origin = PageRect.lo;
00562
00563
00564
00565
00566 if (!SetUpCurrentAttrs())
00567 return FALSE;
00568
00569
00570 UINT32 id;
00571 switch(Version)
00572 {
00573 case CDRVERSION_4: id = _R(IDT_IMPORTMSG_CDR4); break;
00574 case CDRVERSION_5: id = _R(IDT_IMPORTMSG_CDR5); break;
00575 default: id = _R(IDT_IMPORTMSG_CDR3); break;
00576 }
00577 if(!DestDoc->IsImporting())
00578 id += _R(IDT_OPENMSG_CDR3) - _R(IDT_IMPORTMSG_CDR3);
00579
00580 String_64 ImportMessage = GetImportProgressString(pDiskFile, id);
00581
00582
00583
00584
00585 BeginSlowJob(RIFF->ProgressLimit(), FALSE, &ImportMessage);
00586 SlowJobStarted = TRUE;
00587
00588
00589 do
00590 {
00591
00592 if(!RIFF->NextObject())
00593 CDRFILTER_DI_RETURNERROR;
00594
00595 if(RIFF->GetObjType() == RIFFOBJECTTYPE_LISTSTART)
00596 {
00597 switch(RIFF->GetObjChunkType())
00598 {
00599 case cdrT_doc:
00600 if(!ProcessDoc())
00601 {
00602 TRACEUSER( "Ben", _T("ProcessDoc returned FALSE\n"));
00603 CDRFILTER_DI_RETURNERROR;
00604 }
00605 break;
00606
00607 case cdrT_page:
00608 if(!ProcessPage())
00609 {
00610 TRACEUSER( "Ben", _T("ProcessPage returned FALSE\n"));
00611 CDRFILTER_DI_RETURNERROR;
00612 }
00613 break;
00614
00615 default:
00616
00617 if(!RIFF->SkipToListEnd(RIFF->GetObjLevel()))
00618 CDRFILTER_DI_RETURNERROR;
00619 break;
00620 }
00621 }
00622
00623 if(!UpdateProgress())
00624 return FALSE;
00625 } while(RIFF->GetObjType() != RIFFOBJECTTYPE_FILEEND);
00626
00627
00628 ContinueSlowJob(RIFF->ProgressLimit());
00629
00630
00631 if(!AttachTextToPaths())
00632 return FALSE;
00633
00634
00635 if(ObjectsConverted > 0)
00636 {
00637
00638
00639 if(Pages.GetCount() < 1)
00640 {
00641 TRACEUSER( "Ben", _T("not enough pages in file\n"));
00642 CDRFILTER_DI_RETURNERROR;
00643 }
00644
00645
00646 CDRLayerList *MasterLayers;
00647 CDRPageListItem *En = (CDRPageListItem *)Pages.GetHead();
00648
00649 if(En == 0)
00650 CDRFILTER_DI_RETURNERROR;
00651
00652 MasterLayers = &En->Layers;
00653
00654
00655 CDRLayerList *PageLayers;
00656 En = (CDRPageListItem *)Pages.GetNext(En);
00657
00658 if(Version != CDRVERSION_3)
00659 {
00660 if(En == 0)
00661 CDRFILTER_DI_RETURNERROR;
00662
00663 PageLayers = &En->Layers;
00664
00665
00666 if(MasterLayers->GetCount() != PageLayers->GetCount())
00667 {
00668 TRACEUSER( "Ben", _T("not the same number of layers on master page and on page\n"));
00669 CDRFILTER_DI_RETURNERROR;
00670 }
00671 } else
00672 {
00673 PageLayers = 0;
00674 }
00675
00676 if(MasterLayers->GetCount() <= 0)
00677 CDRFILTER_DI_RETURNERROR;
00678
00679
00680 if(Version == CDRVERSION_3)
00681 {
00682
00683 if(!DestDoc->IsImporting() && PageX > 0 && PageY > 0)
00684 {
00685
00686
00687
00688 INT32 ms = (PageX > PageY)?PageX:PageY;
00689
00690
00691 if (pSpread)
00692 {
00693 BOOL ok = pSpread->SetPageSize(PageX, PageY, ms, 0, FALSE, TRUE);
00694
00695
00696
00697 DocRect PagesRect;
00698 NodeGrid* pGrid = pSpread->FindFirstDefaultGridInSpread();
00699 ok = ok && pSpread->GetPagesRect(&PagesRect);
00700 if (pGrid)
00701 pGrid->SetOrigin(PagesRect.lox, PagesRect.loy);
00702
00703 if (!ok)
00704 CDRFILTER_DI_RETURNERROR;
00705 }
00706 }
00707
00708 DocRect PageRect = pPage->GetPageRect();
00709 Origin = PageRect.lo;
00710
00711 TranslateByX = Origin.x + (PageX / 2);
00712 TranslateByY = Origin.y + (PageY / 2);
00713 }
00714
00715
00716 CDRLayerListItem *MasterEn = (CDRLayerListItem *)MasterLayers->GetTail();
00717 CDRLayerListItem *PageEn = 0;
00718 if(PageLayers != 0)
00719 PageEn = (CDRLayerListItem *)PageLayers->GetTail();
00720
00721 EndSlowJob();
00722 BeginSlowJob();
00723
00724
00725 if(UseLayers)
00726 {
00727
00728 while(MasterEn != 0)
00729 {
00730
00731 if(MasterEn->Objects != 0 || (PageEn != 0 && PageEn->Objects != 0))
00732 {
00733
00734 Layer *pLayer = new Layer();
00735
00736 if(pLayer == 0)
00737 CDRFILTER_DI_RETURNERROR;
00738
00739
00740 pLayer->SetLayerID(MasterEn->Name);
00741 pLayer->SetVisible(MasterEn->IsVisible);
00742 pLayer->SetLocked(MasterEn->IsLocked);
00743 pLayer->SetActive(FALSE);
00744 pLayer->SetPrintable(TRUE);
00745 pLayer->SetBackground(FALSE);
00746 pLayer->SetOutline(FALSE);
00747
00748
00749 Node *Objects = 0;
00750
00751 if(MasterEn->Objects != 0)
00752 {
00753 Objects = MasterEn->Objects;
00754 MasterEn->LayerInDocument = TRUE;
00755 }
00756 else
00757 {
00758 Objects = PageEn->Objects;
00759 PageEn->LayerInDocument = TRUE;
00760 }
00761
00762 ERROR3IF(Objects == 0, "Er, tried to make a layer for objects which didn't exist");
00763
00764
00765 Objects->InsertChainSimple(pLayer, FIRSTCHILD);
00766
00767
00768 if(Version == CDRVERSION_3)
00769 {
00770 Trans2DMatrix Trans(TranslateByX, TranslateByY);
00771 pLayer->Transform(Trans);
00772 }
00773
00774
00775 if (!Op->DoInsertNewNode(pLayer, (Node *)pSpread, LASTCHILD, TRUE))
00776 {
00777
00778 pLayer->CascadeDelete();
00779 delete pLayer;
00780 pLayer = NULL;
00781 CDRFILTER_DI_RETURNERROR;
00782 }
00783
00784
00785 pLayer->EnsureUniqueLayerID();
00786
00787
00788 if(!pLayer->OptimiseAttributes())
00789 CDRFILTER_DI_RETURNERROR;
00790 }
00791
00792
00793 MasterEn = (CDRLayerListItem *)MasterLayers->GetPrev(MasterEn);
00794 if(PageEn != 0)
00795 PageEn = (CDRLayerListItem *)PageLayers->GetPrev(PageEn);
00796 }
00797
00798
00799 DestDoc->ResetInsertionPosition();
00800 }
00801 else
00802 {
00803
00804 NodeGroup *pGroup = new NodeGroup;
00805 if(pGroup == 0)
00806 CDRFILTER_DI_RETURNERROR;
00807
00808
00809 while(MasterEn != 0)
00810 {
00811 TRACEUSER( "Ben", _T("Putting layer '%s' into document\n"), (TCHAR *)MasterEn->Name);
00812
00813
00814 if(MasterEn->Objects != 0)
00815 {
00816 MasterEn->Objects->InsertChainSimple(pGroup, LASTCHILD);
00817
00818 MasterEn->LayerInDocument = TRUE;
00819 }
00820
00821
00822 if(PageEn != 0 && PageEn->Objects != 0)
00823 {
00824 PageEn->Objects->InsertChainSimple(pGroup, LASTCHILD);
00825
00826 PageEn->LayerInDocument = TRUE;
00827 }
00828
00829
00830
00831 MasterEn = (CDRLayerListItem *)MasterLayers->GetPrev(MasterEn);
00832 if(PageEn != 0)
00833 PageEn = (CDRLayerListItem *)PageLayers->GetPrev(PageEn);
00834 }
00835
00836
00837 if(Version == CDRVERSION_3)
00838 {
00839 Trans2DMatrix Trans(TranslateByX, TranslateByY);
00840 pGroup->Transform(Trans);
00841 }
00842
00843
00844
00845
00846 NodeRenderableBounded *InsertNode = pGroup;
00847
00848 NodeRenderableBounded *FirstChild = (NodeRenderableBounded *)pGroup->FindFirstChild();
00849
00850 if(FirstChild != 0)
00851 {
00852
00853
00854 if(FirstChild->FindNext() == 0)
00855 InsertNode = FirstChild;
00856 }
00857
00858
00859 if (!Op->DoInsertNewNode(InsertNode, pSpread, TRUE))
00860 {
00861
00862 pGroup->CascadeDelete();
00863 delete pGroup;
00864 pGroup = NULL;
00865 CDRFILTER_DI_RETURNERROR;
00866 }
00867
00868 if(InsertNode != pGroup)
00869 delete pGroup;
00870
00871
00872 if(!InsertNode->OptimiseAttributes())
00873 CDRFILTER_DI_RETURNERROR;
00874 }
00875 }
00876 else
00877 {
00878
00879 if(!DestDoc->IsImporting())
00880 {
00881 if (!MakeSureLayerExists(DestDoc))
00882 CDRFILTER_DI_RETURNERROR;
00883
00884 DestDoc->ResetInsertionPosition();
00885 }
00886 }
00887
00888
00889 if(!AddStandardColourSet(pDocument))
00890 CDRFILTER_DI_RETURNERROR;
00891
00892
00893 DestDoc->PostImport();
00894
00895
00896 INT32 ObjNotConv = ObjectsFormatWrong + ObjectsUnknown;
00897
00898 if(ObjNotConv > 0)
00899 {
00900
00901 String_256 WarnMsg;
00902 WarnMsg.MakeMsg((ObjNotConv == 1)?_R(IDT_CDRFILTER_OBJWARNING1):_R(IDT_CDRFILTER_OBJWARNING), ObjNotConv);
00903 Error::SetError(0, WarnMsg, 0);
00904 InformWarning();
00905 Error::ClearError();
00906 }
00907
00908 if(EnvelopesApproximated > 0)
00909 {
00910
00911 String_256 WarnMsg;
00912 WarnMsg.MakeMsg((EnvelopesApproximated == 1)?_R(IDT_CDRFILTER_ENVAPPROXWARNING1):_R(IDT_CDRFILTER_ENVAPPROXWARNING), EnvelopesApproximated);
00913 Error::SetError(0, WarnMsg, 0);
00914 InformWarning();
00915 Error::ClearError();
00916 }
00917
00918 TRACEUSER( "Ben", _T("Do import finished\n"));
00919 return ClearUp();
00920 }
00921
00922
00923
00924
00925
00926
00927
00928
00929
00930
00931
00932
00933
00934
00935 BOOL CDRFilter::ProcessDoc(void)
00936 {
00937 BOOL InFillTable = FALSE;
00938 BOOL InOutlineTable = FALSE;
00939 BOOL InStyleTable = FALSE;
00940 BOOL InFontTable = FALSE;
00941 BOOL InArrowheadTable = FALSE;
00942 BOOL InPatternTable = FALSE;
00943 BOOL InBitmapTable = FALSE;
00944 BOOL GotPageInfo = FALSE;
00945
00946 ADDR VectorListContents = 0;
00947 INT32 VectorListContentsSize;
00948
00949 TRACEUSER( "Ben", _T("In ProcessDoc\n"));
00950
00951
00952 UINT32 StartLevel = RIFF->GetObjLevel();
00953
00954 do
00955 {
00956 switch(RIFF->GetObjType())
00957 {
00958 case RIFFOBJECTTYPE_LISTSTART:
00959
00960 switch(RIFF->GetObjChunkType())
00961 {
00962 case cdrT_filt: InFillTable = TRUE; break;
00963 case cdrT_otlt: InOutlineTable = TRUE; break;
00964 case cdrT_stlt: InStyleTable = TRUE; break;
00965 case cdrT_fntt: InFontTable = TRUE; break;
00966 case cdrT_arrt: InArrowheadTable = TRUE; break;
00967 case cdrT_bpft: InPatternTable = TRUE; break;
00968 case cdrT_bmpt: InBitmapTable = TRUE; break;
00969 default: break;
00970
00971 case cdrT_vect:
00972
00973 if(!RIFF->GetListContents(&VectorListContents, &VectorListContentsSize))
00974 return FALSE;
00975
00976
00977 if(!RIFF->SkipToListEnd(RIFF->GetObjLevel()))
00978 return FALSE;
00979 break;
00980
00981 case cdrT_btxt:
00982 if(Version == CDRVERSION_4)
00983 {
00984
00985 if(!ProcessTextList4())
00986 return FALSE;
00987 }
00988 break;
00989 }
00990 break;
00991
00992 case RIFFOBJECTTYPE_LISTEND:
00993 switch(RIFF->GetObjChunkType())
00994 {
00995 case cdrT_filt: InFillTable = FALSE; break;
00996 case cdrT_otlt: InOutlineTable = FALSE; break;
00997 case cdrT_stlt: InStyleTable = FALSE; break;
00998 case cdrT_fntt: InFontTable = FALSE; break;
00999 case cdrT_arrt: InArrowheadTable = FALSE; break;
01000 case cdrT_bpft: InPatternTable = FALSE; break;
01001 case cdrT_bmpt: InBitmapTable = FALSE; break;
01002 default: break;
01003 }
01004 break;
01005
01006 case RIFFOBJECTTYPE_CHUNK:
01007
01008 switch(RIFF->GetObjChunkType())
01009 {
01010 case cdrT_fill:
01011 if(InFillTable)
01012 Fills.AddChunkToStore(RIFF);
01013 break;
01014
01015 case cdrT_outl:
01016 if(InOutlineTable)
01017 Outlines.AddChunkToStore(RIFF);
01018 break;
01019
01020 case cdrT_styd:
01021 if(InStyleTable)
01022 Styles.AddChunkToStore(RIFF);
01023 break;
01024
01025 case cdrT_font:
01026 if(InFontTable)
01027 Fonts.AddChunkToStore(RIFF, Version);
01028 break;
01029
01030 case cdrT_arrw:
01031 if(InArrowheadTable)
01032 Arrowheads.AddChunkToStore(RIFF);
01033 break;
01034
01035 case cdrT_bmpf:
01036 if(InPatternTable)
01037 Patterns.AddChunkToStore(RIFF, TRUE, this);
01038
01039 UpdateProgress(TRUE);
01040 break;
01041
01042 case cdrT_bmp:
01043
01044
01045 UpdateProgress(TRUE);
01046
01047 if(InBitmapTable)
01048 Bitmaps.AddChunkToStore(RIFF, FALSE, this);
01049
01050 UpdateProgress(TRUE);
01051 break;
01052
01053 case cdrT_mcfg:
01054 {
01055 if(GotPageInfo)
01056 {
01057 TRACEUSER( "Ben", _T("mcfg chunk encountered twice in doc list\n"));
01058 ERROR1(FALSE, _R(IDE_CDRFILTER_FORMATERROR));
01059 }
01060
01061 if(!RIFF->AquireChunkData())
01062 return FALSE;
01063
01064 cdrfPageInfo *i = (cdrfPageInfo *)RIFF->GetAquiredData();
01065
01066 ERROR3IF(i == 0, "No aquired data returned from RIFF chunk");
01067
01068 PageX = CDRDATA_WORD(i->PageX) * CDRCOORDS_TO_MILLIPOINTS;
01069 PageY = CDRDATA_WORD(i->PageY) * CDRCOORDS_TO_MILLIPOINTS;
01070 Landscape = (CDRDATA_WORD(i->Orientation) == cdrf_ORIENTATION_LANDSCAPE)?TRUE:FALSE;
01071
01072 GotPageInfo = TRUE;
01073 }
01074 break;
01075
01076 case cdrT_tspc:
01077 if(Version == CDRVERSION_3)
01078 {
01079
01080 if((FontStylesV3 = (ADDR)CCMalloc(RIFF->GetObjSize())) == 0)
01081 return FALSE;
01082
01083 if(!RIFF->GetChunkData(FontStylesV3, RIFF->GetObjSize()))
01084 return FALSE;
01085 }
01086 break;
01087
01088 case cdrT_ftbl:
01089 if(Version == CDRVERSION_3)
01090 {
01091
01092 if((FontTableV3 = (ADDR)CCMalloc(RIFF->GetObjSize())) == 0)
01093 return FALSE;
01094
01095 if(!RIFF->GetChunkData(FontTableV3, RIFF->GetObjSize()))
01096 return FALSE;
01097
01098
01099 FontTableEntriesV3 = RIFF->GetObjSize() / sizeof(cdrfFontTableEntryV3);
01100
01101
01102 cdrfFontTableEntryV3 *FT = (cdrfFontTableEntryV3 *)FontTableV3;
01103 for(INT32 l = 0; l < FontTableEntriesV3; l++)
01104 {
01105 if(FT[l].Name[0] != '\0' && FT[l].Name[0] != ' ')
01106 {
01107
01108
01109 Fonts.AddFontToStore(FT[l].Reference, (TCHAR *)&FT[l].Name);
01110 }
01111 }
01112
01113 }
01114 break;
01115
01116 case cdrT_lnkt:
01117
01118 if((LinkTable = (ADDR)CCMalloc(RIFF->GetObjSize())) == 0)
01119 return FALSE;
01120
01121 if(!RIFF->GetChunkData(LinkTable, RIFF->GetObjSize()))
01122 return FALSE;
01123
01124
01125 if(!MakeTextOnPathLinkList())
01126 return FALSE;
01127 break;
01128
01129 default:
01130 break;
01131 }
01132 break;
01133
01134 default:
01135 break;
01136 }
01137 UpdateProgress();
01138
01139 if(!RIFF->NextObject())
01140 return FALSE;
01141
01142 ERROR3IF(RIFF->GetObjType() == RIFFOBJECTTYPE_FILEEND, "Unexpected end of RIFF file in ProcessDoc");
01143 } while(RIFF->GetObjType() != RIFFOBJECTTYPE_LISTEND || RIFF->GetObjLevel() > StartLevel);
01144
01145
01146 if(VectorListContents != 0)
01147 {
01148 if(!ProcessVectorList(VectorListContents, VectorListContentsSize))
01149 {
01150 CCFree(VectorListContents);
01151 return FALSE;
01152 }
01153
01154 CCFree(VectorListContents);
01155 }
01156
01157
01158 if(Version != CDRVERSION_3)
01159 {
01160 if(GotPageInfo == FALSE)
01161 {
01162 TRACEUSER( "Ben", _T("mcfg chunk not found in doc list\n"));
01163 ERROR1(FALSE, _R(IDE_CDRFILTER_FORMATERROR));
01164
01165 }
01166
01167
01168 if(!pDocument->IsImporting() && PageX > 0 && PageY > 0)
01169 {
01170
01171
01172
01173 INT32 ms = (PageX > PageY)?PageX:PageY;
01174
01175
01176 if (pSpread)
01177 {
01178 BOOL ok = pSpread->SetPageSize(PageX, PageY, ms, 0, FALSE, TRUE);
01179
01180
01181
01182
01183 DocRect PagesRect;
01184 NodeGrid* pGrid = pSpread->FindFirstDefaultGridInSpread();
01185 ok = ok && pSpread->GetPagesRect(&PagesRect);
01186 if (pGrid)
01187 pGrid->SetOrigin(PagesRect.lox, PagesRect.loy);
01188
01189 if (!ok)
01190 return FALSE;
01191 }
01192 }
01193
01194
01195 DocRect PageRect = pPage->GetPageRect();
01196 Origin = PageRect.lo;
01197
01198
01199
01200
01201 TranslateByX = Origin.x + (PageX / 2);
01202 TranslateByY = Origin.y + (PageY / 2);
01203 }
01204
01205 TRACEUSER( "Ben", _T("PageX = %d, PageY = %d\n"), PageX, PageY);
01206
01207 return TRUE;
01208 }
01209
01210
01211
01212
01213
01214
01215
01216
01217
01218
01219
01220
01221
01222
01223
01224 BOOL CDRFilter::ProcessPage(void)
01225 {
01226 TRACEUSER( "Ben", _T("In ProcessPage\n"));
01227
01228 ERROR3IF(ThisPage != 0, "ThisPage is not null - ProcessPage called in wrong context");
01229 ThisPage = new CDRPageListItem;
01230
01231 if(ThisPage == 0)
01232 return FALSE;
01233
01234
01235 Pages.AddTail(ThisPage);
01236
01237
01238 if(DoneMasterPage == FALSE)
01239 InMasterPage = TRUE;
01240
01241
01242
01243 UINT32 StartLevel = RIFF->GetObjLevel();
01244
01245 do
01246 {
01247 if(RIFF->GetObjType() == RIFFOBJECTTYPE_LISTSTART &&
01248 RIFF->GetObjChunkType() == cdrT_layr)
01249 {
01250
01251 if(!ProcessLayer())
01252 {
01253 TRACEUSER( "Ben", _T("ProcessLayer returned FALSE\n"));
01254 return FALSE;
01255 }
01256 }
01257
01258
01259
01260 if(Version == CDRVERSION_3 && RIFF->GetObjType() == RIFFOBJECTTYPE_CHUNK &&
01261 RIFF->GetObjChunkType() == cdrT_mcfg)
01262 {
01263 if(!RIFF->AquireChunkData())
01264 return FALSE;
01265
01266 cdrfPageInfoV3 *i = (cdrfPageInfoV3 *)RIFF->GetAquiredData();
01267
01268
01269 PageX = CDRDATA_WORD(i->PageX) * CDRCOORDS_TO_MILLIPOINTS * 2;
01270 PageY = CDRDATA_WORD(i->PageY) * CDRCOORDS_TO_MILLIPOINTS * 2;
01271 Landscape = FALSE;
01272 }
01273
01274 UpdateProgress();
01275
01276 if(!RIFF->NextObject())
01277 return FALSE;
01278
01279 ERROR3IF(RIFF->GetObjType() == RIFFOBJECTTYPE_FILEEND, "Unexpected end of RIFF file in ProcessDoc");
01280 } while(RIFF->GetObjType() != RIFFOBJECTTYPE_LISTEND || RIFF->GetObjLevel() > StartLevel);
01281
01282
01283
01284 ThisPage = 0;
01285
01286
01287 if(InMasterPage)
01288 {
01289 InMasterPage = FALSE;
01290 DoneMasterPage = TRUE;
01291 }
01292
01293 TRACEUSER( "Ben", _T("End ProcessPage\n"));
01294
01295 return TRUE;
01296 }
01297
01298
01299
01300
01301
01302
01303
01304
01305
01306
01307
01308
01309
01310
01311
01312
01313 BOOL CDRFilter::ProcessLayer(void)
01314 {
01315 TRACEUSER( "Ben", _T("In ProcessLayer\n"));
01316
01317 ERROR3IF(ThisLayer != 0, "ThisLayer is not null - ProcessLayer called in wrong context");
01318 ThisLayer = new CDRLayerListItem;
01319
01320 if(ThisLayer == 0)
01321 return FALSE;
01322
01323
01324 ThisPage->Layers.AddTail(ThisLayer);
01325
01326
01327 UINT32 StartLevel = RIFF->GetObjLevel();
01328
01329 ThisLayer->Objects = 0;
01330 ThisLayer->IsVisible = TRUE;
01331 ThisLayer->IsLocked = FALSE;
01332
01333
01334 ERROR3IF(pLevelNodeList != 0, "Level node list is not empty");
01335 pLevelNodeList = 0;
01336
01337
01338 if(InMasterPage)
01339 {
01340 BOOL Done = FALSE;
01341 FOURCC LookingFor = (Version == CDRVERSION_3)?cdrT_lobj:cdrT_loda;
01342
01343 do
01344 {
01345 if(RIFF->GetObjType() == RIFFOBJECTTYPE_CHUNK && RIFF->GetObjChunkType() == LookingFor)
01346 {
01347
01348 if(!RIFF->AquireChunkData())
01349 return FALSE;
01350
01351 cdrfMasterLayerInfo *i = (cdrfMasterLayerInfo *)RIFF->GetAquiredData();
01352
01353 if(i == 0)
01354 return FALSE;
01355
01356 if(i->Size != RIFF->GetObjSize()) {
01357 TRACEUSER( "Ben", _T("level data in master page has wrong size\n"));
01358 ERROR1(FALSE, _R(IDE_CDRFILTER_FORMATERROR));
01359 }
01360
01361
01362 if(Version == CDRVERSION_3)
01363 {
01364 cdrfMasterLayerInfoV3 *ii = (cdrfMasterLayerInfoV3 *)RIFF->GetAquiredData();
01365 TRACEUSER( "Ben", _T("name of layer = %s\n"), ii->Name);
01366 ThisLayer->Name = (char *)ii->Name;
01367 } else
01368 {
01369 TRACEUSER( "Ben", _T("name of layer = %s\n"), i->Name);
01370 ThisLayer->Name = (char *)i->Name;
01371 }
01372
01373 Done = TRUE;
01374 }
01375 else if(RIFF->GetObjType() == RIFFOBJECTTYPE_CHUNK && RIFF->GetObjChunkType() == cdrT_flgs)
01376 {
01377
01378 if(!RIFF->AquireChunkData())
01379 return FALSE;
01380
01381 WORD *pFlags = (WORD *)RIFF->GetAquiredData();
01382
01383 ERROR3IF(pFlags == 0, "RIFF class shouldn't have done that");
01384
01385 INT32 Flags = CDRDATA_WORD(*pFlags);
01386
01387 if((Flags & cdrfLAYERFLAGS_INVISIBLE) != 0)
01388 ThisLayer->IsVisible = FALSE;
01389
01390 if((Flags & cdrfLAYERFLAGS_LOCKED) != 0)
01391 ThisLayer->IsLocked = TRUE;
01392 }
01393
01394 if(!RIFF->NextObject())
01395 return FALSE;
01396
01397 } while(Done == FALSE && (RIFF->GetObjType() != RIFFOBJECTTYPE_LISTEND || RIFF->GetObjLevel() > StartLevel));
01398
01399 if(Done == FALSE)
01400 {
01401 TRACEUSER( "Ben", _T("Reached level end in master page layer without finding layer attributes\n"));
01402 ERROR1(FALSE, _R(IDE_CDRFILTER_FORMATERROR));
01403 }
01404 } else {
01405 ThisLayer->Name = "";
01406 }
01407
01408
01409 if(!ProcessObjectTree(StartLevel))
01410 return FALSE;
01411
01412
01413 ThisLayer->Objects = pLevelNodeList;
01414 pLevelNodeList = 0;
01415
01416
01417 ThisLayer = 0;
01418
01419 TRACEUSER( "Ben", _T("End ProcessLayer\n"));
01420 return TRUE;
01421 }
01422
01423
01424
01425
01426
01427
01428
01429
01430
01431
01432
01433
01434
01435
01436
01437 BOOL CDRFilter::ProcessObjectTree(UINT32 Level)
01438 {
01439 do
01440 {
01441 switch(RIFF->GetObjType())
01442 {
01443 case RIFFOBJECTTYPE_LISTSTART:
01444
01445 switch(RIFF->GetObjChunkType())
01446 {
01447 case cdrT_obj:
01448 if(!ProcessObject())
01449 return FALSE;
01450 break;
01451
01452
01453 case cdrT_grp:
01454
01455 if(!ProcessGroup(RIFF->GetObjLevel()))
01456 return FALSE;
01457 break;
01458
01459 case cdrT_lnkg:
01460
01461
01462 if(!ProcessLink())
01463 return FALSE;
01464 break;
01465
01466 default:
01467 break;
01468 }
01469 break;
01470
01471 case RIFFOBJECTTYPE_LISTEND:
01472
01473 if(!Actions.IsEmpty())
01474 {
01475 CDRActionListItem *Act, *Previous;
01476
01477 Act = (CDRActionListItem *)Actions.GetTail();
01478
01479
01480 while(Act != 0)
01481 {
01482 if(Act->GetLevel() >= RIFF->GetObjLevel())
01483 {
01484
01485 if(!Act->DoAction(this))
01486 return FALSE;
01487
01488
01489 Previous = (CDRActionListItem *)Actions.GetPrev(Act);
01490
01491
01492 delete Actions.RemoveTail();
01493
01494
01495 Act = Previous;
01496 } else {
01497
01498 break;
01499 }
01500 }
01501 }
01502 break;
01503
01504 default:
01505 break;
01506 }
01507
01508 if(!UpdateProgress())
01509 return FALSE;
01510
01511 if(!RIFF->NextObject())
01512 return FALSE;
01513
01514 ERROR3IF(RIFF->GetObjType() == RIFFOBJECTTYPE_FILEEND, "Unexpected end of RIFF file in ProcessLayer");
01515
01516 } while(RIFF->GetObjType() != RIFFOBJECTTYPE_LISTEND || RIFF->GetObjLevel() > Level);
01517
01518 return TRUE;
01519 }
01520
01521
01522
01523
01524
01525
01526
01527
01528
01529
01530
01531
01532
01533
01534
01535 BOOL CDRFilter::ProcessGroup(UINT32 Level, BOOL FromLink)
01536 {
01537
01538 if(Version == CDRVERSION_3)
01539 {
01540
01541 BOOL Found = FALSE;
01542 do {
01543 if(!RIFF->NextObject())
01544 return FALSE;
01545
01546 FOURCC id = RIFF->GetObjChunkType();
01547
01548
01549 if(id == cdrT_grp || id == cdrT_lnkg || id == cdrT_obj)
01550 {
01551
01552 RIFF->RepeatCurrent();
01553
01554 break;
01555 }
01556
01557 if(id == cdrT_lobj && RIFF->GetObjType() == RIFFOBJECTTYPE_CHUNK)
01558 {
01559
01560 Found = TRUE;
01561 }
01562 } while(Found == FALSE);
01563
01564
01565 if(Found)
01566 {
01567 TRACEUSER( "Ben", _T("Setting transform for CDR3 group at level %d\n"), Level);
01568 CDRActionTransform *TAct = new CDRActionTransform;
01569
01570 if(TAct == 0)
01571 return FALSE;
01572
01573
01574
01575 if(!TAct->Init(RIFF, Version))
01576 return FALSE;
01577
01578
01579 TAct->SetLevel(Level);
01580
01581
01582 Actions.AddTail(TAct);
01583 }
01584 }
01585 else if(!FromLink)
01586 {
01587
01588 BOOL Found = FALSE;
01589 do {
01590 if(!RIFF->NextObject())
01591 return FALSE;
01592
01593 FOURCC id = RIFF->GetObjChunkType();
01594
01595
01596 if(id == cdrT_grp || id == cdrT_lnkg || id == cdrT_obj)
01597 {
01598
01599 RIFF->RepeatCurrent();
01600
01601 break;
01602 }
01603
01604 if(id == cdrT_trfl && RIFF->GetObjType() == RIFFOBJECTTYPE_LISTSTART)
01605 {
01606
01607 Found = TRUE;
01608 }
01609 } while(Found == FALSE);
01610
01611
01612 if(Found)
01613 {
01614 CDRActionTransform *Act = new CDRActionTransform;
01615
01616 if(Act == 0)
01617 return FALSE;
01618
01619
01620
01621 if(!Act->Init(RIFF, Version))
01622 return FALSE;
01623
01624
01625 if(IsTransformJustMatrices(Act->Chunk, Act->ChunkSize))
01626 {
01627
01628 delete Act;
01629 }
01630 else
01631 {
01632
01633 Act->SetLevel(Level);
01634
01635
01636 Act->SetIsAGroupTransform(TRUE);
01637
01638
01639 Actions.AddTail(Act);
01640 }
01641 }
01642 }
01643
01644 CDRActionGroupEnd *Act = new CDRActionGroupEnd;
01645
01646 if(Act == 0)
01647 return FALSE;
01648
01649
01650 Act->pOldLevelNodeList = pLevelNodeList;
01651
01652
01653 Act->SetLevel(Level);
01654
01655
01656 pLevelNodeList = 0;
01657
01658 Actions.AddTail(Act);
01659
01660 return TRUE;
01661 }
01662
01663
01664
01665
01666
01667
01668
01669
01670
01671
01672
01673
01674
01675
01676
01677 BOOL CDRActionGroupEnd::DoAction(CDRFilter *C)
01678 {
01679
01680 if(C->pLevelNodeList == 0)
01681 {
01682
01683 C->pLevelNodeList = pOldLevelNodeList;
01684
01685 return TRUE;
01686 }
01687
01688
01689 NodeGroup *pGroup = new NodeGroup;
01690
01691 if(pGroup == 0)
01692 return FALSE;
01693
01694
01695 C->pLevelNodeList->InsertChainSimple(pGroup, LASTCHILD);
01696
01697
01698 C->pLevelNodeList = pOldLevelNodeList;
01699
01700
01701 if(C->pLevelNodeList == 0)
01702 {
01703 C->pLevelNodeList = pGroup;
01704 } else {
01705 pGroup->AttachNode(C->pLevelNodeList, PREV);
01706 C->pLevelNodeList = pGroup;
01707 }
01708
01709
01710 return TRUE;
01711 }
01712
01713
01714
01715
01716
01717
01718
01719
01720
01721
01722
01723
01724
01725
01726
01727 void CDRActionGroupEnd::ImportFailure(CDRFilter *C)
01728 {
01729 if(pOldLevelNodeList != 0)
01730 {
01731
01732 C->DeleteNodeList(pOldLevelNodeList);
01733 }
01734 }
01735
01736
01737
01738
01739
01740
01741
01742
01743
01744
01745
01746
01747
01748
01749
01750 BOOL CDRFilter::ProcessLink(void)
01751 {
01752
01753 UINT32 GroupLevel = RIFF->GetObjLevel();
01754
01755
01756
01757 if(Version != CDRVERSION_3)
01758 {
01759
01760
01761
01762
01763 BOOL Found = FALSE;
01764 do {
01765 if(!RIFF->NextObject())
01766 return FALSE;
01767
01768 FOURCC id = RIFF->GetObjChunkType();
01769
01770
01771 if(id == cdrT_grp || id == cdrT_lnkg || id == cdrT_obj)
01772 {
01773
01774 RIFF->RepeatCurrent();
01775
01776 break;
01777 }
01778
01779 if(id == cdrT_trfl && RIFF->GetObjType() == RIFFOBJECTTYPE_LISTSTART)
01780 {
01781
01782 Found = TRUE;
01783 }
01784 } while(Found == FALSE);
01785
01786
01787 if(Found)
01788 {
01789 CDRActionTransform *Act = new CDRActionTransform;
01790
01791 if(Act == 0)
01792 return FALSE;
01793
01794
01795
01796 if(!Act->Init(RIFF, Version))
01797 return FALSE;
01798
01799
01800 Act->SetLevel(GroupLevel);
01801
01802
01803 Act->LinkTrans = TRUE;
01804 LinkTransformsExist = TRUE;
01805
01806
01807 Actions.AddTail(Act);
01808 }
01809 }
01810
01811
01812 if(!ProcessGroup(GroupLevel, TRUE))
01813 return FALSE;
01814
01815 return TRUE;
01816 }
01817
01818
01819
01820
01821
01822
01823
01824
01825
01826
01827
01828
01829
01830
01831
01832 BOOL CDRActionTransform::Init(RIFFFile *RIFF, CDRVersion Version)
01833 {
01834 if(Version == CDRVERSION_3)
01835 {
01836
01837 ERROR3IF(RIFF->GetObjType() != RIFFOBJECTTYPE_CHUNK, "CDRActionTransform::Init called with RIFFFile in wrong state");
01838
01839 ERROR3IF(Chunk != 0, "CDRActionTransform::Init called more than once");
01840
01841
01842 if((Chunk = (ADDR)CCMalloc(RIFF->GetObjSize())) == 0)
01843 return FALSE;
01844
01845
01846 if(!RIFF->GetChunkData(Chunk, RIFF->GetObjSize()))
01847 return FALSE;
01848 }
01849 else
01850 {
01851
01852 ERROR3IF(RIFF->GetObjType() != RIFFOBJECTTYPE_LISTSTART, "CDRActionTransform::Init called with RIFFFile in wrong state");
01853
01854 ERROR3IF(Chunk != 0, "CDRActionTransform::Init called more than once");
01855
01856
01857 if(!RIFF->GetListContents(&Chunk, &ChunkSize))
01858 return FALSE;
01859 }
01860
01861
01862 return TRUE;
01863 }
01864
01865
01866
01867
01868
01869
01870
01871
01872
01873
01874
01875
01876
01877
01878
01879 BOOL CDRActionTransform::DoAction(CDRFilter *C)
01880 {
01881 ERROR3IF(Chunk == 0, "CDRActionTransform not initialised");
01882
01883 if(LinkTrans)
01884 {
01885 return TRUE;
01886 }
01887
01888 ADDR Transform = Chunk;
01889
01890
01891
01892 if(C->Version == CDRVERSION_3)
01893 {
01894 cdrfOffsetHeader *Header = (cdrfOffsetHeader *)Chunk;
01895
01896
01897 if((Transform = C->FindDataInObject(Header, cdrfOBJOFFSETTYPE_TRANSFORM_V3)) == 0)
01898 return TRUE;
01899 }
01900
01901
01902
01903
01904 Node *pNext = C->pLevelNodeList->FindNext();
01905 C->pLevelNodeList->UnlinkNodeFromTree();
01906
01907
01908 if(!LinkTrans && C->pLevelNodeList != 0)
01909 C->TransformConvertedObject(&C->pLevelNodeList, Transform, ChunkSize, FALSE, IsAGroupTransform, TRUE);
01910
01911
01912 if(pNext != 0)
01913 C->pLevelNodeList->AttachNode(pNext, PREV);
01914
01915 return TRUE;
01916 }
01917
01918
01919
01920
01921
01922
01923
01924
01925
01926
01927
01928
01929
01930
01931
01932
01933 void CDRActionTransform::ImportFailure(CDRFilter *C)
01934 {
01935 }
01936
01937
01938
01939
01940
01941
01942
01943
01944
01945
01946
01947
01948
01949
01950
01951 CDRActionTransform::~CDRActionTransform()
01952 {
01953 CCFree(Chunk);
01954 }
01955
01956
01957
01958
01959
01960
01961
01962
01963
01964
01965
01966
01967
01968
01969
01970 BOOL CDRFilter::ConvertColour(cdrfColour *Col, DocColour *Out)
01971 {
01972 ERROR3IF(Col == 0 || Out == 0, "Null pointers passed to ConvertColour");
01973
01974 ImportedNewColour ICol;
01975
01976 switch(Version)
01977 {
01978 case CDRVERSION_5: CDRColour::Convert5(Col, &ICol); break;
01979 case CDRVERSION_4: CDRColour::Convert4(Col, &ICol); break;
01980 default: CDRColour::Convert3(Col, &ICol); break;
01981 }
01982
01983 IndexedColour *NewCol = new IndexedColour(ICol.Model, &ICol.Colour);
01984
01985 if(NewCol == 0)
01986 return FALSE;
01987
01988 ColList->GetUnnamedColours()->AddTail(NewCol);
01989
01990 Out->MakeRefToIndexedColour(NewCol);
01991
01992 return TRUE;
01993 }
01994
01995
01996
01997
01998
01999
02000
02001
02002
02003
02004
02005
02006
02007
02008
02009
02010 BOOL CDRFilter::ProcessObject(void)
02011 {
02012 UINT32 StartLevel = RIFF->GetObjLevel();
02013
02014
02015 pMadeNode = 0;
02016
02017
02018 AttrsAlreadyApplied = FALSE;
02019
02020
02021 IsText = FALSE;
02022 IsTextStory = FALSE;
02023
02024
02025 BOOL Found = FALSE;
02026 FOURCC LookingFor = (Version == CDRVERSION_3)?cdrT_lobj:cdrT_loda;
02027 do
02028 {
02029
02030 if(RIFF->GetObjType() == RIFFOBJECTTYPE_CHUNK && RIFF->GetObjChunkType() == cdrT_spnd) {
02031
02032 if(!RIFF->AquireChunkData())
02033 return FALSE;
02034
02035 WORD *Data = (WORD *)RIFF->GetAquiredData();
02036
02037 if(Data == 0)
02038 return FALSE;
02039
02040
02041 SerialNumber = CDRDATA_WORD(*Data);
02042 }
02043
02044 if(RIFF->GetObjType() == RIFFOBJECTTYPE_CHUNK && RIFF->GetObjChunkType() == LookingFor) {
02045 Found = TRUE;
02046 break;
02047 }
02048
02049 if(!UpdateProgress())
02050 return FALSE;
02051
02052 if(!RIFF->NextObject())
02053 return FALSE;
02054
02055 } while(RIFF->GetObjType() != RIFFOBJECTTYPE_LISTEND || RIFF->GetObjLevel() > StartLevel);
02056
02057
02058 if(Found == FALSE)
02059 {
02060 TRACEUSER( "Ben", _T("Could not find loda (or lobj) chunk in object\n"));
02061 ObjectsFormatWrong++;
02062 return TRUE;
02063 }
02064
02065
02066
02067 cdrfOffsetHeader *Header;
02068
02069
02070 if(ObjDataBlock == 0 || ObjDataBlockSize < RIFF->GetObjSize())
02071 {
02072
02073 CCFree(ObjDataBlock);
02074
02075
02076 INT32 Size = RIFF->GetObjSize();
02077
02078 if((ObjDataBlock = (ADDR)CCMalloc(Size)) == 0)
02079 return FALSE;
02080
02081 ObjDataBlockSize = Size;
02082 }
02083
02084 if(!RIFF->GetChunkData(ObjDataBlock, ObjDataBlockSize))
02085 return FALSE;
02086
02087 Header = (cdrfOffsetHeader *)ObjDataBlock;
02088
02089
02090 FormatError = FALSE;
02091
02092 INT32 ObjectType = CDRDATA_WORD(Header->ObjectType);
02093
02094
02095 if(Version == CDRVERSION_3)
02096 ObjectType += cdrfOBJTYPE_V3ADD;
02097
02098 switch(ObjectType) {
02099 case cdrfOBJTYPE_RECTANGLE:
02100 if(!ConvertRectangle(Header))
02101 return FALSE;
02102 break;
02103
02104 case cdrfOBJTYPE_ELLIPSE:
02105 if(!ConvertEllipse(Header))
02106 return FALSE;
02107 break;
02108
02109 case cdrfOBJTYPE_PATH:
02110 if(!ConvertPath(Header))
02111 return FALSE;
02112 break;
02113
02114 case cdrfOBJTYPE_TEXT:
02115 case cdrfOBJTYPE_TEXTSTORY:
02116 if(!ConvertText(Header))
02117 return FALSE;
02118 break;
02119
02120 case cdrfOBJTYPE_BITMAP:
02121 if(!ConvertBitmap(Header))
02122 return FALSE;
02123 break;
02124
02125 default:
02126
02127 ObjectsUnknown++;
02128 RIFF->SkipToListEnd(StartLevel);
02129 return TRUE;
02130 break;
02131 }
02132
02133
02134 if(FormatError)
02135 {
02136 TRACEUSER( "Ben", _T("A convert object function returned a format error\n"));
02137 ObjectsFormatWrong++;
02138
02139 if(TransformChunk != 0)
02140 {
02141 CCFree(TransformChunk);
02142 TransformChunk = 0;
02143 }
02144
02145 return TRUE;
02146 }
02147
02148 ERROR3IF(pMadeNode == 0, "No node made, but still nothing errored\n");
02149
02150
02151 BOOL UnsetTransparency = FALSE;
02152 if(Version == CDRVERSION_5)
02153 {
02154 cdrfLensDefn *Lens = (cdrfLensDefn *)FindDataInObject(Header, cdrfOBJOFFSETTYPE_LENS);
02155
02156 if(Lens != 0)
02157 {
02158
02159 if(Lens->Type == cdrfLENSTYPE_TRANSPARENT)
02160 {
02161
02162 UINT32 Percent = CDRDATA_WORD(Lens->Percent) / 10;
02163 if(Percent <= 100)
02164 {
02165
02166 Percent = 256 - ((Percent * 256) / 100);
02167
02168
02169 switch(Lens->SubType)
02170 {
02171 case cdrfTRANSPARENTTYPE_MIX:
02172 SetFlatTranspFill(T_REFLECTIVE, Percent);
02173 UnsetTransparency = TRUE;
02174 break;
02175
02176 case cdrfTRANSPARENTTYPE_STAINED:
02177 SetFlatTranspFill(T_SUBTRACTIVE, Percent);
02178 UnsetTransparency = TRUE;
02179 break;
02180
02181 case cdrfTRANSPARENTTYPE_BLEACH:
02182 SetFlatTranspFill(T_ADDITIVE, Percent);
02183 UnsetTransparency = TRUE;
02184 break;
02185
02186 default:
02187 break;
02188 }
02189 }
02190 }
02191 }
02192 }
02193
02194
02195
02196 ADDR TransformData = 0;
02197 INT32 TransformDataSize = 0;
02198 if(TransformChunk != 0)
02199 {
02200
02201
02202 TransformData = TransformChunk;
02203 TransformDataSize = TransformChunkSize;
02204 }
02205 else if(Version == CDRVERSION_3)
02206 {
02207 TransformData = FindDataInObject(Header, cdrfOBJOFFSETTYPE_TRANSFORM_V3);
02208 }
02209 else
02210 {
02211 Found = FALSE;
02212 do
02213 {
02214 if(RIFF->GetObjType() == RIFFOBJECTTYPE_LISTSTART && RIFF->GetObjChunkType() == cdrT_trfl) {
02215 Found = TRUE;
02216 break;
02217 }
02218
02219 UpdateProgress();
02220
02221 if(!RIFF->NextObject())
02222 return FALSE;
02223
02224 } while(RIFF->GetObjType() != RIFFOBJECTTYPE_LISTEND || RIFF->GetObjLevel() > StartLevel);
02225
02226
02227 if(Found == FALSE)
02228 {
02229 TRACEUSER( "Ben", _T("Could not find trfd chunk in object\n"));
02230 ObjectsFormatWrong++;
02231
02232 delete pMadeNode;
02233 return TRUE;
02234 }
02235
02236
02237 if(!RIFF->AquireListContents(&TransformDataSize))
02238 {
02239 delete pMadeNode;
02240 return FALSE;
02241 }
02242 TransformData = RIFF->GetAquiredData();
02243 }
02244
02245 if(TransformData == 0)
02246 {
02247 ObjectsFormatWrong++;
02248
02249 delete pMadeNode;
02250 return TRUE;
02251 }
02252
02253
02254 if(Version != CDRVERSION_3)
02255 {
02256 if(LinkTransformsExist)
02257 {
02258 BOOL FoundSome = FALSE;
02259
02260 CDRActionListItem *Act = (CDRActionListItem *)Actions.GetTail();
02261
02262 while(Act != 0)
02263 {
02264 if(IS_A(Act, CDRActionTransform))
02265 {
02266 CDRActionTransform *Tran = (CDRActionTransform *)Act;
02267
02268 if(Tran->LinkTrans)
02269 {
02270
02271 FoundSome = TRUE;
02272
02273
02274 if(!TransformConvertedObject(&pMadeNode, Tran->Chunk, Tran->ChunkSize, FALSE))
02275 {
02276 delete pMadeNode;
02277 return FALSE;
02278 }
02279 }
02280 }
02281
02282 Act = (CDRActionListItem *)Actions.GetPrev(Act);
02283 }
02284
02285 LinkTransformsExist = FoundSome;
02286 }
02287 }
02288
02289
02290 if(!TransformConvertedObject(&pMadeNode, TransformData, TransformDataSize))
02291 {
02292 delete pMadeNode;
02293 return FALSE;
02294 }
02295
02296
02297 if(AttrsAlreadyApplied == FALSE)
02298 {
02299
02300 if(!SetFillAttr(Header))
02301 return FALSE;
02302
02303
02304 if(!SetLineAttr(Header))
02305 return FALSE;
02306 }
02307
02308 BOOL Result;
02309 if(AttrsAlreadyApplied == FALSE)
02310 {
02311
02312
02313 if (ObjFilled == FALSE)
02314 CurrentAttrs[ATTR_FILLGEOMETRY].Ignore = TRUE;
02315
02316
02317 Result = AttributeManager::ApplyBasedOnDefaults(pMadeNode, CurrentAttrs);
02318
02319
02320 CurrentAttrs[ATTR_FILLGEOMETRY].Ignore = FALSE;
02321 } else {
02322 Result = TRUE;
02323 }
02324
02325 if(!Result)
02326 return FALSE;
02327
02328 if(UnsetTransparency)
02329 {
02330 SetNoTranspFill();
02331 }
02332
02333
02334 if(pLevelNodeList != 0)
02335 pMadeNode->AttachNode(pLevelNodeList, PREV);
02336
02337 pLevelNodeList = pMadeNode;
02338
02339
02340 pMadeNode = 0;
02341
02342
02343 ObjectsConverted++;
02344
02345
02346 if(TransformChunk != 0)
02347 {
02348 CCFree(TransformChunk);
02349 TransformChunk = 0;
02350 }
02351
02352 return TRUE;
02353 }
02354
02355
02356
02357
02358
02359
02360
02361
02362
02363
02364
02365
02366
02367
02368
02369
02370
02371 BOOL CDRFilter::ConvertPath(cdrfOffsetHeader *Header)
02372 {
02373
02374 cdrfPathCoordHeader *CHdr = (cdrfPathCoordHeader *)FindDataInObject(Header, cdrfOBJOFFSETTYPE_COORDS);
02375
02376
02377 if(CHdr == 0)
02378 {
02379 FormatError = TRUE;
02380 return TRUE;
02381 }
02382
02383
02384 cdrfCoord *Coords = (cdrfCoord *)(CHdr + 1);
02385
02386
02387 UINT32 NCoords = CDRDATA_WORD(CHdr->NCoords);
02388 BYTE *Types = (BYTE *)(Coords + NCoords);
02389
02390
02391 if((NCoords * (sizeof(cdrfCoord) + sizeof(BYTE))) > CDRDATA_WORD(Header->Size) || NCoords < 2)
02392 {
02393 FormatError = TRUE;
02394 return TRUE;
02395 }
02396
02397
02398 NodePath *pPath = new NodePath;
02399 if(pPath == 0 || (!pPath->SetUpPath()))
02400 {
02401 delete pPath;
02402 return FALSE;
02403 }
02404
02405
02406 pPath->InkPath.FindStartOfPath();
02407
02408
02409 ObjFilled = FALSE;
02410 ObjStroked = TRUE;
02411
02412 if(!AddElementsToPath(&pPath->InkPath, NCoords, Coords, Types, &ObjFilled))
02413 goto NoMemory;
02414
02415
02416 if(!pPath->InkPath.EnsureValid())
02417 {
02418
02419 delete pPath;
02420 FormatError = TRUE;
02421 return TRUE;
02422 }
02423
02424
02425 pPath->InvalidateBoundingRect();
02426 pPath->InkPath.IsFilled = ObjFilled;
02427
02428
02429 pMadeNode = pPath;
02430
02431
02432 {
02433 CDRTextOnPathLink *Item = (CDRTextOnPathLink *)TextOnPathLinks.GetHead();
02434
02435 while(Item != 0)
02436 {
02437
02438 if(SerialNumber == Item->PathSerialNumber)
02439 {
02440
02441 Item->pPath = pPath;
02442 }
02443
02444
02445 Item = (CDRTextOnPathLink *)TextOnPathLinks.GetNext(Item);
02446 }
02447 }
02448
02449
02450 return TRUE;
02451
02452 NoMemory:
02453
02454 if(pPath != 0)
02455 pPath->CascadeDelete();
02456
02457 delete pPath;
02458
02459 return FALSE;
02460 }
02461
02462
02463
02464
02465
02466
02467
02468
02469
02470
02471
02472
02473
02474
02475
02476 BOOL CDRFilter::AddElementsToPath(Path *pPath, INT32 NCoords, cdrfCoord *Coords, BYTE *Types, BOOL *IsClosed)
02477 {
02478
02479 INT32 c;
02480 UINT32 CoordType;
02481 UINT32 Control1 = 0;
02482 UINT32 Control2 = 0;
02483 DocCoord co, cn1, cn2;
02484 PathFlags Flags;
02485 BOOL NeedMoveTo = TRUE;
02486
02487 if(IsClosed != 0)
02488 (*IsClosed) = FALSE;
02489
02490
02491 for(c = 0; c < NCoords; c++)
02492 {
02493 CoordType = Types[c] & cdrfPATHCOORDTYPE_MASK;
02494
02495 co.x = CDRDATA_SWORD(Coords[c].X) * CDRCOORDS_TO_MILLIPOINTS;
02496 co.y = CDRDATA_SWORD(Coords[c].Y) * CDRCOORDS_TO_MILLIPOINTS;
02497
02498
02499 if(NeedMoveTo && CoordType != cdrfPATHCOORDTYPE_MOVE)
02500 {
02501 if(!pPath->InsertMoveTo(co))
02502 return FALSE;
02503 }
02504
02505 NeedMoveTo = FALSE;
02506
02507
02508 switch(CoordType)
02509 {
02510 case cdrfPATHCOORDTYPE_MOVE:
02511
02512 if(!pPath->InsertMoveTo(co))
02513 return FALSE;
02514 break;
02515
02516 case cdrfPATHCOORDTYPE_LINETO:
02517
02518 if(!pPath->InsertLineTo(co))
02519 return FALSE;
02520 break;
02521
02522 case cdrfPATHCOORDTYPE_CURVE:
02523
02524
02525 if(Control1 == 0 || Control2 == 0)
02526 {
02527 TRACEUSER( "Ben", _T("No control points for curve element\n"));
02528 break;
02529 }
02530
02531
02532 cn1.x = CDRDATA_SWORD(Coords[Control1].X) * CDRCOORDS_TO_MILLIPOINTS;
02533 cn1.y = CDRDATA_SWORD(Coords[Control1].Y) * CDRCOORDS_TO_MILLIPOINTS;
02534 cn2.x = CDRDATA_SWORD(Coords[Control2].X) * CDRCOORDS_TO_MILLIPOINTS;
02535 cn2.y = CDRDATA_SWORD(Coords[Control2].Y) * CDRCOORDS_TO_MILLIPOINTS;
02536
02537
02538 Flags.IsSelected = FALSE;
02539 Flags.IsSmooth = Flags.IsRotate = ((Types[c] & cdrfPATHCOORDATTR_SMOOTH) != 0)?TRUE:FALSE;
02540 Flags.IsEndPoint;
02541
02542
02543 if(!pPath->InsertCurveTo(cn1, cn2, co, &Flags))
02544 return FALSE;
02545 break;
02546
02547 case cdrfPATHCOORDTYPE_CONTROL:
02548
02549 Control1 = Control2;
02550 Control2 = c;
02551 break;
02552
02553 default:
02554
02555 break;
02556 }
02557
02558
02559 if((Types[c] & cdrfPATHCOORDATTR_CLOSE) != 0)
02560 {
02561 if(IsClosed != 0)
02562 (*IsClosed) = TRUE;
02563
02564
02565 if(CoordType != cdrfPATHCOORDTYPE_MOVE)
02566 {
02567 if(!pPath->CloseSubPath())
02568 return FALSE;
02569
02570
02571 NeedMoveTo = TRUE;
02572 }
02573 }
02574 }
02575
02576 return TRUE;
02577 }
02578
02579
02580
02581
02582
02583
02584
02585
02586
02587
02588
02589
02590
02591
02592
02593 #define RECTANGLE_CORNER_MAGIC (1.0 - 0.552)
02594
02595 #define RECT_MOVE(px, py) {co.x = (px); co.y = (py); if(!pPath->InkPath.InsertMoveTo(co)) goto NoMemory;}
02596 #define RECT_LINE(px, py) {co.x = (px); co.y = (py); if(!pPath->InkPath.InsertLineTo(co)) goto NoMemory;}
02597 #define RECT_CURVE(cx1, cy1, cx2, cy2, px, py) {cn1.x = (cx1); cn1.y = (cy1); cn2.x = (cx2); cn2.y = (cy2); \
02598 co.x = (px); co.y = (py); if(!pPath->InkPath.InsertCurveTo(cn1, cn2, co)) goto NoMemory;}
02599 #define RECT_CLOSE {if(!pPath->InkPath.CloseSubPath()) goto NoMemory;}
02600
02601
02602 BOOL CDRFilter::ConvertRectangle(cdrfOffsetHeader *Header)
02603 {
02604
02605 cdrfRectangleData *Size = (cdrfRectangleData *)FindDataInObject(Header, cdrfOBJOFFSETTYPE_COORDS);
02606
02607
02608 if(Size == 0)
02609 {
02610 FormatError = TRUE;
02611 return TRUE;
02612 }
02613
02614
02615 INT32 Width = CDRDATA_SWORD(Size->Width) * CDRCOORDS_TO_MILLIPOINTS;
02616 INT32 Height = CDRDATA_SWORD(Size->Height) * CDRCOORDS_TO_MILLIPOINTS;
02617 INT32 CornerRadius = CDRDATA_SWORD(Size->CornerRadius) * CDRCOORDS_TO_MILLIPOINTS;
02618
02619 if(CornerRadius < 0)
02620 CornerRadius = 0 - CornerRadius;
02621
02622
02623 NodeRegularShape *NewShape = new (NodeRegularShape);
02624
02625 if ((NewShape == NULL) || !NewShape->SetUpShape() )
02626 {
02627 ERROR1(FALSE, _R(IDS_OUT_OF_MEMORY));
02628 }
02629
02630 INT32 AWidth = Width;
02631 INT32 AHeight = Height;
02632 if(AWidth < 0) AWidth = 0 - AWidth;
02633 if(AHeight < 0) AHeight = 0 - AHeight;
02634
02635 if(!NewShape->MakeRectangle(AWidth, AHeight, CornerRadius))
02636 return FALSE;
02637
02638
02639 Trans2DMatrix Trans(Width / 2, Height / 2);
02640
02641 NewShape->Transform(Trans);
02642
02643
02644 NewShape->InvalidateBoundingRect();
02645
02646
02647 ObjFilled = TRUE;
02648 ObjStroked = TRUE;
02649
02650
02651 pMadeNode = NewShape;
02652
02653 return TRUE;
02654
02655 }
02656
02657
02658
02659
02660
02661
02662
02663
02664
02665
02666
02667
02668
02669
02670
02671 BOOL CDRFilter::ConvertEllipse(cdrfOffsetHeader *Header)
02672 {
02673
02674 cdrfEllipseData *Size = (cdrfEllipseData *)FindDataInObject(Header, cdrfOBJOFFSETTYPE_COORDS);
02675
02676
02677 if(Size == 0)
02678 {
02679 FormatError = TRUE;
02680 return TRUE;
02681 }
02682
02683
02684 NodeRegularShape *NewShape = new (NodeRegularShape);
02685
02686 if ((NewShape == NULL) || !NewShape->SetUpShape() )
02687 {
02688 ERROR1(FALSE, _R(IDS_OUT_OF_MEMORY));
02689 }
02690
02691
02692 NewShape->SetNumSides(4);
02693
02694 INT32 Width = CDRDATA_SWORD(Size->Width) * CDRCOORDS_TO_MILLIPOINTS;
02695 INT32 Height = CDRDATA_SWORD(Size->Height) * CDRCOORDS_TO_MILLIPOINTS;
02696
02697 DocCoord co;
02698 co.x = Width / 2;
02699 co.y = Height / 2;
02700 NewShape->SetCentrePoint(co);
02701 co.x = Width;
02702 NewShape->SetMajorAxes(co);
02703 co.x /= 2;
02704 co.y = Height;
02705 NewShape->SetMinorAxes(co);
02706
02707 NewShape->SetCircular(TRUE);
02708 NewShape->SetStellated(FALSE);
02709 NewShape->SetPrimaryCurvature(TRUE);
02710 NewShape->SetStellationCurvature(FALSE);
02711
02712
02713 NewShape->InvalidateBoundingRect();
02714
02715
02716 ObjFilled = TRUE;
02717 ObjStroked = TRUE;
02718
02719
02720 pMadeNode = NewShape;
02721
02722 return TRUE;
02723 }
02724
02725
02726
02727
02728
02729
02730
02731
02732
02733
02734
02735
02736
02737
02738
02739 #define BITM_MOVE(px, py) {co.x = (px); co.y = (py); if(!pPath->InkPath.InsertMoveTo(co)) return FALSE;}
02740 #define BITM_LINE(px, py) {co.x = (px); co.y = (py); if(!pPath->InkPath.InsertLineTo(co)) return FALSE;}
02741 #define BITM_CLOSE {if(!pPath->InkPath.CloseSubPath()) return FALSE;}
02742
02743 BOOL CDRFilter::ConvertBitmap(cdrfOffsetHeader *Header)
02744 {
02745
02746 cdrfBitmapData *BInfo = (cdrfBitmapData *)FindDataInObject(Header, cdrfOBJOFFSETTYPE_COORDS);
02747
02748
02749 if(BInfo == 0)
02750 {
02751 FormatError = TRUE;
02752 return TRUE;
02753 }
02754
02755
02756 struct {
02757 DWORD Reference;
02758 INT32 SizeX;
02759 INT32 SizeY;
02760 INT32 Left;
02761 INT32 Right;
02762 INT32 Bottom;
02763 INT32 Top;
02764 } Info;
02765
02766
02767 if(Version != CDRVERSION_3)
02768 {
02769 Info.Reference = CDRDATA_WORD(BInfo->BitmapReference);
02770 Info.SizeX = CDRDATA_SWORD(BInfo->SizeX) * CDRCOORDS_TO_MILLIPOINTS;
02771 Info.SizeY = CDRDATA_SWORD(BInfo->SizeY) * CDRCOORDS_TO_MILLIPOINTS;
02772 Info.Left = CDRDATA_SWORD(BInfo->Left) * CDRCOORDS_TO_MILLIPOINTS;
02773 Info.Right = CDRDATA_SWORD(BInfo->Right) * CDRCOORDS_TO_MILLIPOINTS;
02774 Info.Bottom = CDRDATA_SWORD(BInfo->Bottom) * CDRCOORDS_TO_MILLIPOINTS;
02775 Info.Top = CDRDATA_SWORD(BInfo->Top) * CDRCOORDS_TO_MILLIPOINTS;
02776 }
02777 else
02778 {
02779 cdrfBitmapData3 *B3Info = (cdrfBitmapData3 *)BInfo;
02780
02781 Info.Reference = CDRDATA_WORD(B3Info->BitmapReference);
02782 Info.SizeX = CDRDATA_SWORD(B3Info->SizeX) * CDRCOORDS_TO_MILLIPOINTS;
02783 Info.SizeY = CDRDATA_SWORD(B3Info->SizeY) * CDRCOORDS_TO_MILLIPOINTS;
02784 Info.Left = CDRDATA_SWORD(B3Info->Left) * CDRCOORDS_TO_MILLIPOINTS;
02785 Info.Right = CDRDATA_SWORD(B3Info->Right) * CDRCOORDS_TO_MILLIPOINTS;
02786 Info.Bottom = CDRDATA_SWORD(B3Info->Bottom) * CDRCOORDS_TO_MILLIPOINTS;
02787 Info.Top = CDRDATA_SWORD(B3Info->Top) * CDRCOORDS_TO_MILLIPOINTS;
02788 }
02789
02790
02791 KernelBitmap *pBitmap = Bitmaps.FindBitmap(Info.Reference);
02792
02793 if(pBitmap == 0)
02794 {
02795 FormatError = TRUE;
02796 return TRUE;
02797 }
02798
02799
02800 DocRect BoundsRect;
02801
02802 if(Info.SizeX > 0)
02803 {
02804 BoundsRect.lo.x = 0;
02805 BoundsRect.hi.x = Info.SizeX;
02806 } else {
02807 BoundsRect.lo.x = Info.SizeX;
02808 BoundsRect.hi.x = 0;
02809 }
02810
02811 if(Info.SizeY > 0)
02812 {
02813 BoundsRect.lo.y = 0;
02814 BoundsRect.hi.y = Info.SizeY;
02815 } else {
02816 BoundsRect.lo.y = Info.SizeY;
02817 BoundsRect.hi.y = 0;
02818 }
02819
02820
02821
02822
02823 if(Info.Left == 0 && Info.Right == Info.SizeX && Info.Top == 0 && Info.Bottom == Info.SizeY)
02824 {
02825
02826 NodeBitmap *NewBitmap = new NodeBitmap;
02827
02828 if((NewBitmap == NULL) || !NewBitmap->SetUpPath())
02829 return FALSE;
02830
02831 NewBitmap->CreateShape(BoundsRect);
02832
02833
02834 NewBitmap->GetBitmapRef()->Attach(pBitmap, GetDocument());
02835 if (NewBitmap->GetBitmap() != pBitmap)
02836 {
02837
02838 delete pBitmap;
02839 }
02840
02841
02842 NewBitmap->ApplyDefaultBitmapAttrs(0);
02843
02844
02845 NewBitmap->InvalidateBoundingRect();
02846
02847
02848 ObjFilled = FALSE;
02849 ObjStroked = FALSE;
02850
02851
02852 AttrsAlreadyApplied = TRUE;
02853
02854
02855 pMadeNode = NewBitmap;
02856 }
02857 else
02858 {
02859
02860
02861 NodePath *pPath = new NodePath;
02862 if(pPath == 0 || (!pPath->SetUpPath()))
02863 {
02864 delete pPath;
02865 return FALSE;
02866 }
02867
02868
02869 pPath->InkPath.FindStartOfPath();
02870
02871 DocCoord co, cn1, cn2;
02872
02873
02874 BITM_MOVE(Info.Left, Info.Bottom)
02875 BITM_LINE(Info.Right, Info.Bottom)
02876 BITM_LINE(Info.Right, Info.Top)
02877 BITM_LINE(Info.Left, Info.Top)
02878 BITM_LINE(Info.Left, Info.Bottom)
02879 BITM_CLOSE
02880
02881
02882 pPath->InvalidateBoundingRect();
02883 pPath->InkPath.IsFilled = TRUE;
02884
02885
02886 ObjFilled = TRUE;
02887 ObjStroked = FALSE;
02888
02889
02890 if(!SetLineColour(DocColour(COLOUR_TRANS)))
02891 return FALSE;
02892
02893
02894 DocCoord Start = DocCoord(BoundsRect.lo.x, BoundsRect.lo.y);
02895 DocCoord End1 = DocCoord(BoundsRect.hi.x, BoundsRect.lo.y);
02896 DocCoord End2 = DocCoord(BoundsRect.lo.x, BoundsRect.hi.y);
02897 if(!SetBitmapFill(pBitmap, Start, End1, End2))
02898 return FALSE;
02899
02900
02901 SetPathFilled(TRUE);
02902 CurrentAttrs[ATTR_FILLGEOMETRY].Ignore = FALSE;
02903 if(!AttributeManager::ApplyBasedOnDefaults(pPath, CurrentAttrs))
02904 return FALSE;
02905
02906
02907 AttrsAlreadyApplied = TRUE;
02908
02909
02910 pMadeNode = pPath;
02911 }
02912
02913 return TRUE;
02914 }
02915
02916
02917
02918
02919
02920
02921
02922
02923
02924
02925
02926
02927
02928
02929
02930
02931 ADDR CDRFilter::FindDataInObject(cdrfOffsetHeader *Header, WORD Type)
02932 {
02933 WORD *Types;
02934 WORD *Offsets;
02935
02936 Types = (WORD *)(((BYTE *)Header) + CDRDATA_WORD(Header->TypesOffset));
02937 Offsets = (WORD *)(((BYTE *)Header) + CDRDATA_WORD(Header->OffsetsOffset));
02938
02939 UINT32 l;
02940
02941 for(l = 0; l < CDRDATA_WORD(Header->NOffsets); l++)
02942 {
02943 if(CDRDATA_WORD(Types[l]) == Type)
02944 {
02945 UINT32 Off = CDRDATA_WORD(Offsets[Header->NOffsets - l - 1]);
02946 if(Off > CDRDATA_WORD(Header->Size))
02947 return 0;
02948
02949 return (ADDR)(((BYTE *)Header) + Off);
02950 }
02951 }
02952
02953 return 0;
02954 }
02955
02956
02957
02958
02959
02960
02961
02962
02963
02964
02965
02966
02967
02968
02969
02970
02971 BOOL CDRFilter::GetMatrixFromTransform(Matrix *M, ADDR Trans, INT32 Size, BOOL TranslateForPage)
02972 {
02973
02974 CDRTransformConvertor *Conv;
02975
02976
02977
02978 CDRTransformConvertor5 Conv5;
02979 CDRTransformConvertor4 Conv4;
02980 CDRTransformConvertor3 Conv3;
02981
02982 switch(Version)
02983 {
02984 case CDRVERSION_5: Conv = &Conv5; break;
02985 case CDRVERSION_4: Conv = &Conv4; break;
02986 case CDRVERSION_3: Conv = &Conv3; break;
02987 default: return FALSE; break;
02988 }
02989
02990
02991 Conv->Init(Trans, Size);
02992
02993
02994
02995 cdrMatrix Ma, Mb, Mt;
02996 BOOL DoneFirst = FALSE;
02997
02998
02999 INT32 t;
03000 for(t = Conv->GetNTransforms() - 1; t >= 0; t--)
03001 {
03002
03003 if(Conv->GetTransformType(t) != CDRTRANSFORMTYPE_MATRIX)
03004 continue;
03005
03006 if(DoneFirst)
03007 {
03008
03009
03010
03011 if(!Conv->GetMatrix(&Mb, t))
03012 return FALSE;
03013
03014
03015 Mt.a = (Mb.a * Ma.a) + (Mb.d * Ma.b);
03016 Mt.b = (Mb.b * Ma.a) + (Mb.e * Ma.b);
03017 Mt.c = (Mb.c * Ma.a) + (Mb.f * Ma.b) + Ma.c;
03018 Mt.d = (Mb.a * Ma.d) + (Mb.d * Ma.e);
03019 Mt.e = (Mb.b * Ma.d) + (Mb.e * Ma.e);
03020 Mt.f = (Mb.c * Ma.d) + (Mb.f * Ma.e) + Ma.f;
03021
03022 Ma = Mt;
03023 } else {
03024
03025 if(!Conv->GetMatrix(&Ma, t))
03026 return FALSE;
03027
03028 DoneFirst = TRUE;
03029 }
03030 }
03031
03032
03033 if(!DoneFirst)
03034 {
03035 cdrMatrix Mx = {1, 0, 0, 0, 1, 0};
03036
03037 Ma = Mx;
03038 }
03039
03040
03041 if(TranslateForPage)
03042 {
03043 Ma.c += TranslateByX;
03044 Ma.f += TranslateByY;
03045 }
03046
03047
03048 *M = Matrix(Ma.a, Ma.d, Ma.b, Ma.e, (INT32)Ma.c, (INT32)Ma.f);
03049
03050 return TRUE;
03051 }
03052
03053
03054
03055
03056
03057
03058
03059
03060
03061
03062
03063
03064
03065
03066
03067
03068 BOOL CDRFilter::IsTransformJustMatrices(ADDR Trans, INT32 Size)
03069 {
03070
03071 CDRTransformConvertor *Conv;
03072
03073
03074
03075 CDRTransformConvertor5 Conv5;
03076 CDRTransformConvertor4 Conv4;
03077 CDRTransformConvertor3 Conv3;
03078
03079 switch(Version)
03080 {
03081 case CDRVERSION_5: Conv = &Conv5; break;
03082 case CDRVERSION_4: Conv = &Conv4; break;
03083 case CDRVERSION_3: Conv = &Conv3; break;
03084 default: return FALSE; break;
03085 }
03086
03087
03088 Conv->Init(Trans, Size);
03089
03090
03091 for(INT32 t = Conv->GetNTransforms() - 1; t >= 0; t--)
03092 {
03093 switch(Conv->GetTransformType(t))
03094 {
03095 case CDRTRANSFORMTYPE_MATRIX:
03096 case CDRTRANSFORMTYPE_UNKNOWN:
03097 break;
03098
03099 default:
03100 return FALSE;
03101 break;
03102 }
03103
03104 }
03105
03106 return TRUE;
03107 }
03108
03109
03110
03111
03112
03113
03114
03115
03116
03117
03118
03119
03120
03121
03122
03123
03124
03125
03126
03127
03128
03129
03130 BOOL CDRFilter::TransformConvertedObject(NodeRenderable **N, ADDR Trans, INT32 Size, BOOL TranslateForPage,
03131 BOOL IsAGroupTransform, BOOL WorkAtOrigin)
03132 {
03133 if(IsText)
03134 {
03135 (*N)->OptimiseAttributes();
03136 }
03137
03138
03139 if(Version == CDRVERSION_3) WorkAtOrigin = FALSE;
03140
03141
03142 if(WorkAtOrigin)
03143 {
03144 Trans2DMatrix Trans(-TranslateByX, -TranslateByY);
03145 (*N)->Transform(Trans);
03146 }
03147
03148
03149 CDRTransformConvertor *Conv;
03150
03151
03152
03153 CDRTransformConvertor5 Conv5;
03154 CDRTransformConvertor4 Conv4;
03155 CDRTransformConvertor3 Conv3;
03156
03157 switch(Version)
03158 {
03159 case CDRVERSION_5: Conv = &Conv5; break;
03160 case CDRVERSION_4: Conv = &Conv4; break;
03161 case CDRVERSION_3: Conv = &Conv3; break;
03162 default: return FALSE; break;
03163 }
03164
03165
03166 Conv->Init(Trans, Size);
03167
03168
03169 cdrMatrix Ma, Mb, Mt;
03170 BOOL HaveMatrix = FALSE;
03171
03172 BOOL ApplyMatrices = IsAGroupTransform?FALSE:TRUE;
03173
03174 #ifdef CDR_DOEXTRUDE
03175 for(UINT32 g = 0; g < Conv->GetNTransforms(); g++)
03176 {
03177 CDRTransformType Type = Conv->GetTransformType(t);
03178
03179 if(Type == CDRTRANSFORMTYPE_EXTRUDE)
03180 ApplyMatrices = FALSE;
03181 }
03182 #endif
03183
03184
03185
03186 for(UINT32 t = 0; t < Conv->GetNTransforms(); t++)
03187 {
03188 CDRTransformType Type = Conv->GetTransformType(t);
03189
03190
03191 if(Type == CDRTRANSFORMTYPE_UNKNOWN)
03192 continue;
03193
03194
03195 if(Type == CDRTRANSFORMTYPE_MATRIX)
03196 {
03197 if(ApplyMatrices)
03198 {
03199 if(HaveMatrix)
03200 {
03201
03202
03203
03204 if(!Conv->GetMatrix(&Mb, t))
03205 return FALSE;
03206
03207
03208 Mt.a = (Ma.a * Mb.a) + (Ma.d * Mb.b);
03209 Mt.b = (Ma.b * Mb.a) + (Ma.e * Mb.b);
03210 Mt.c = (Ma.c * Mb.a) + (Ma.f * Mb.b) + Mb.c;
03211 Mt.d = (Ma.a * Mb.d) + (Ma.d * Mb.e);
03212 Mt.e = (Ma.b * Mb.d) + (Ma.e * Mb.e);
03213 Mt.f = (Ma.c * Mb.d) + (Ma.f * Mb.e) + Mb.f;
03214
03215 Ma = Mt;
03216 } else {
03217
03218 if(!Conv->GetMatrix(&Ma, t))
03219 return FALSE;
03220
03221 HaveMatrix = TRUE;
03222 }
03223 }
03224 }
03225 else
03226 {
03227
03228 if(HaveMatrix)
03229 {
03230
03231 if(!ApplyMatrices)
03232 {
03233 if(!TransformConvertedObjectDoMatrix(N, &Ma, FALSE))
03234 return FALSE;
03235 }
03236
03237 }
03238
03239
03240 HaveMatrix = FALSE;
03241
03242
03243 ERROR3IF(Type == CDRTRANSFORMTYPE_MATRIX, "Matrix got through in TransformConvertedObject")
03244
03245 switch(Type)
03246 {
03247 case CDRTRANSFORMTYPE_PERSPECTIVE:
03248 {
03249
03250 cdrPerspective P;
03251
03252 if(!Conv->GetPerspective(&P, t))
03253 return FALSE;
03254
03255
03256 if(!TransformConvertedObjectDoPerspective(N, &P, IsAGroupTransform))
03257 return FALSE;
03258 }
03259 break;
03260
03261 case CDRTRANSFORMTYPE_ENVELOPE:
03262 if(!(Version != CDRVERSION_3 && IsTextStory))
03263 {
03264
03265 DocRect OBBox;
03266 Path *Shape = 0;
03267 INT32 Corners[4];
03268
03269 if(Conv->GetEnvelope(&Shape, &OBBox, (INT32 *)&Corners, t))
03270 {
03271
03272 if(!TransformConvertedObjectDoEnvelope(N, Shape, &OBBox, (INT32 *)&Corners, IsAGroupTransform))
03273 return FALSE;
03274
03275
03276 delete Shape;
03277 }
03278 }
03279 break;
03280
03281 case CDRTRANSFORMTYPE_EXTRUDE:
03282 {
03283 cdrExtrudeInfo Info;
03284
03285 if(Conv->GetExtrude(&Info, t))
03286 {
03287
03288 if(!TransformConvertedObjectDoExtrude(N, &Info, IsAGroupTransform))
03289 return FALSE;
03290 }
03291 ApplyMatrices = TRUE;
03292 }
03293 break;
03294
03295 default:
03296 break;
03297 }
03298
03299 if(Version == CDRVERSION_5)
03300 {
03301
03302 ApplyMatrices = TRUE;
03303 }
03304 }
03305 }
03306
03307
03308 if(HaveMatrix)
03309 {
03310
03311 if(ApplyMatrices)
03312 {
03313 if(!TransformConvertedObjectDoMatrix(N, &Ma, TranslateForPage))
03314 return FALSE;
03315 }
03316 }
03317 else if(!HaveMatrix && TranslateForPage)
03318 {
03319
03320 cdrMatrix Mi = {1, 0, 0, 0, 1, 0};
03321
03322
03323 if(!TransformConvertedObjectDoMatrix(N, &Mi, TranslateForPage))
03324 return FALSE;
03325 }
03326
03327
03328 if(WorkAtOrigin)
03329 {
03330 Trans2DMatrix Trans(TranslateByX, TranslateByY);
03331 (*N)->Transform(Trans);
03332 }
03333
03334 return TRUE;
03335 }
03336
03337
03338
03339
03340
03341
03342
03343
03344
03345
03346
03347
03348
03349
03350 BOOL CDRFilter::TransformConvertedObjectDoMatrix(NodeRenderable **N, cdrMatrix *Ma, BOOL TranslateForPage)
03351 {
03352
03353 Matrix M(Ma->a, Ma->d, Ma->b, Ma->e, (INT32)Ma->c + (TranslateForPage?TranslateByX:0),
03354 (INT32)Ma->f + (TranslateForPage?TranslateByY:0));
03355
03356
03357
03358 if(IS_A(*N, TextStory))
03359 {
03360
03361 DocRect *BBox = TextBBoxes.Find(*N);
03362
03363
03364 Trans2DMatrix TTransform(M);
03365 if(BBox != 0)
03366 TTransform.GetMatrix().TransformBounds(BBox);
03367
03368
03369 if(IsTextStory)
03370 {
03371
03372 double ScaleX = sqrt((Ma->a * Ma->a) + (Ma->b * Ma->b));
03373 double ScaleY = sqrt((Ma->d * Ma->d) + (Ma->e * Ma->e));
03374
03375
03376 M = Matrix(Ma->a / ScaleX, Ma->d / ScaleY, Ma->b / ScaleX, Ma->e / ScaleY,
03377 (INT32)Ma->c + (TranslateForPage?TranslateByX:0),
03378 (INT32)Ma->f + (TranslateForPage?TranslateByY:0));
03379
03380
03381 TextStory *TSNode = (TextStory *)(*N);
03382 double Width = ((double)TSNode->GetImportFormatWidth()) * ScaleX;
03383 TSNode->SetImportFormatWidth((INT32)Width);
03384 }
03385 }
03386
03387
03388 Trans2DMatrix Transform(M);
03389 (*N)->Transform(Transform);
03390
03391 return TRUE;
03392 }
03393
03394
03395
03396
03397
03398
03399
03400
03401
03402
03403
03404
03405
03406
03407
03408 #define PERS_MOVE(co) {if(!pShape->InkPath.InsertMoveTo(co)) return FALSE;}
03409 #define PERS_LINE(co) {if(!pShape->InkPath.InsertLineTo(co)) return FALSE;}
03410 #define PERS_CLOSE {if(!pShape->InkPath.CloseSubPath()) return FALSE;}
03411
03412 BOOL CDRFilter::TransformConvertedObjectDoPerspective(NodeRenderable **N, cdrPerspective *P, BOOL TranslateShapeForPage)
03413 {
03414 TRACEUSER( "Ben", _T("applying perspective\n"));
03415
03416
03417 NodeMould* pMouldParent = new NodeMould;
03418 if (pMouldParent == 0)
03419 return FALSE;
03420
03421
03422
03423 if(!pMouldParent->CreateGeometry(MOULDSPACE_PERSPECTIVE))
03424 {
03425 delete pMouldParent;
03426 return FALSE;
03427 }
03428
03429
03430 NodePath *pShape = new NodePath;
03431 if(pShape == 0 || (!pShape->SetUpPath()))
03432 {
03433 delete pMouldParent;
03434 return FALSE;
03435 }
03436
03437
03438 pShape->InkPath.FindStartOfPath();
03439
03440
03441 DocCoord co;
03442 PERS_MOVE(P->NewCorners[0])
03443 PERS_LINE(P->NewCorners[1])
03444 PERS_LINE(P->NewCorners[2])
03445 PERS_LINE(P->NewCorners[3])
03446 PERS_LINE(P->NewCorners[0])
03447 PERS_CLOSE
03448
03449
03450 DocRect OriginalBBox = P->OriginalBBox;
03451 if(TranslateShapeForPage)
03452 {
03453 Trans2DMatrix Transform(Matrix(TranslateByX, TranslateByY));
03454 pShape->Transform(Transform);
03455
03456 OriginalBBox.Translate(TranslateByX, TranslateByY);
03457 }
03458
03459
03460 NodeMouldPath* pNodeMPath = pMouldParent->AddNewMouldShape(&pShape->InkPath, 0, NULL);
03461 if (!pNodeMPath)
03462 return FALSE;
03463
03464
03465 if(!pMouldParent->GetGeometry()->Define(&(pNodeMPath->InkPath), &OriginalBBox))
03466 return FALSE;
03467
03468
03469 NodeMouldGroup* pMouldGroup = pMouldParent->AddNewMouldGroup(NULL);
03470 if (!pMouldGroup)
03471 return FALSE;
03472
03473
03474 (*N)->AttachNode((Node *) pMouldGroup, FIRSTCHILD, FALSE);
03475
03476
03477 *N = pMouldParent;
03478
03479
03480 delete pShape;
03481
03482 return TRUE;
03483 }
03484
03485
03486
03487
03488
03489
03490
03491
03492
03493
03494
03495
03496
03497
03498
03499 BOOL CDRFilter::TransformConvertedObjectDoEnvelope(NodeRenderable **N, Path *P, DocRect *pOriginalBBox, INT32 *Corners, BOOL TranslateShapeForPage)
03500 {
03501 TRACEUSER( "Ben", _T("applying envelope\n"));
03502
03503
03504 NodeMould* pMouldParent = new NodeMould;
03505 if (pMouldParent == 0)
03506 return FALSE;
03507
03508
03509
03510 if(!pMouldParent->CreateGeometry(MOULDSPACE_ENVELOPE))
03511 {
03512 delete pMouldParent;
03513 return FALSE;
03514 }
03515
03516
03517 Path *Shape = P;
03518 UINT32 errID;
03519 if(pMouldParent->GetGeometry()->Validate(Shape,errID) == FALSE)
03520 {
03521
03522 Path *NewShape;
03523 if(!pMouldParent->GetGeometry()->MakeValidFrom(&NewShape, Shape, Corners))
03524 {
03525
03526 return TRUE;
03527 }
03528
03529 Shape = NewShape;
03530
03531
03532 EnvelopesApproximated++;
03533 }
03534
03535
03536 DocRect OriginalBBox = *pOriginalBBox;
03537 if(TranslateShapeForPage)
03538 {
03539 Shape->Translate(TranslateByX, TranslateByY);
03540
03541 OriginalBBox.Translate(TranslateByX, TranslateByY);
03542 }
03543
03544
03545 NodeMouldPath* pNodeMPath = pMouldParent->AddNewMouldShape(Shape, 0, NULL);
03546 if (!pNodeMPath)
03547 return FALSE;
03548
03549
03550 if(!pMouldParent->GetGeometry()->Define(&(pNodeMPath->InkPath), &OriginalBBox))
03551 return FALSE;
03552
03553
03554 NodeMouldGroup* pMouldGroup = pMouldParent->AddNewMouldGroup(NULL);
03555 if (!pMouldGroup)
03556 return FALSE;
03557
03558
03559 (*N)->AttachNode((Node *) pMouldGroup, FIRSTCHILD, FALSE);
03560
03561
03562 *N = pMouldParent;
03563
03564
03565 if(Shape != P)
03566 delete Shape;
03567
03568 return TRUE;
03569 }
03570
03571
03572
03573
03574
03575
03576
03577
03578
03579
03580
03581
03582
03583
03584
03585
03586 BOOL CDRFilter::TransformConvertedObjectDoExtrude(NodeRenderable **N, cdrExtrudeInfo *Info, BOOL TranslateShapeForPage)
03587 {
03588
03589
03590
03591
03592
03593
03594 NodeGroup *pTempGroup = new NodeGroup;
03595 if(pTempGroup == 0)
03596 return FALSE;
03597
03598
03599 (*N)->AttachNode(pTempGroup, FIRSTCHILD);
03600
03601
03602 BecomeA ParamBecomeA(BECOMEA_REPLACE,
03603 CC_RUNTIME_CLASS(NodePath),
03604 NULL);
03605
03606
03607 Node* Current = (*N);
03608 while (Current->FindFirstChild() != NULL && !(Current->FindFirstChild())->IsKindOf(CC_RUNTIME_CLASS(TextStory)))
03609 {
03610 Current = Current->FindFirstChild();
03611 }
03612
03613
03614 while(Current != 0)
03615 {
03616 if(Current->IsKindOf(CC_RUNTIME_CLASS(NodeRenderableInk)) && !Current->IsKindOf(CC_RUNTIME_CLASS(NodePath)))
03617 {
03618 if (Current->CanBecomeA(&ParamBecomeA))
03619 {
03620
03621 if (Current->IsKindOf(CC_RUNTIME_CLASS(TextStory)))
03622 {
03623
03624 ((TextStory *)Current)->FormatAndChildren();
03625 }
03626
03627 if (!(Current)->DoBecomeA(&ParamBecomeA))
03628 {
03629 return FALSE;
03630 }
03631 }
03632 }
03633
03634
03635 Current = Current->FindNextDepthFirst(*N);
03636 }
03637
03638
03639 Current = pTempGroup;
03640 while (Current->FindFirstChild() != NULL)
03641 {
03642 Current = Current->FindFirstChild();
03643 }
03644
03645
03646 while(Current != 0)
03647 {
03648 if(IS_A(Current, NodePath))
03649 {
03650 if(!TransformConvertedObjectDoExtrudeTransPath((NodePath *)Current, Info))
03651 return FALSE;
03652 }
03653
03654
03655 Current = Current->FindNextDepthFirst(pTempGroup);
03656 }
03657
03658
03659 (*N) = (NodeRenderable *)pTempGroup->FindFirstChild();
03660 ERROR2IF((*N) == 0, FALSE, "Oi! there that node just vanished");
03661 ERROR2IF(!(*N)->IsKindOf(CC_RUNTIME_CLASS(NodeRenderable)), FALSE, "Oh! Mr. Node changing into something non-renderable");
03662
03663
03664 (*N)->UnlinkNodeFromTree();
03665
03666
03667 delete pTempGroup;
03668
03669 return TRUE;
03670 }
03671
03672
03673
03674
03675
03676
03677
03678
03679
03680
03681
03682
03683
03684
03685 BOOL CDRFilter::TransformConvertedObjectDoExtrudeTransPath(NodePath *pPath, cdrExtrudeInfo *Info)
03686 {
03687
03688 ERROR2IF(pPath == 0 || Info == 0, FALSE, "Null something supplied where a raspberry is required");
03689 ERROR2IF(!IS_A(pPath, NodePath), FALSE, "Oi! I asked for a NodePath you silly person");
03690
03691
03692 DocCoord *Coords = pPath->InkPath.GetCoordArray();
03693 ERROR2IF(Coords == 0, FALSE, "Hmmm. I think that path is a bit of a dodgy one really");
03694 INT32 NCoords = pPath->InkPath.GetNumCoords();
03695
03696
03697 if(Info->Camera.z == 0)
03698 return TRUE;
03699
03700
03701 FLOAT8 projA = - Info->Camera.x / Info->Camera.z;
03702 FLOAT8 projB = - Info->Camera.y / Info->Camera.z;
03703 FLOAT8 projC = - 1 / Info->Camera.z;
03704
03705
03706 for(INT32 c = 0; c < NCoords; c++)
03707 {
03708 FLOAT8 x = (FLOAT8)Coords[c].x, y = (FLOAT8)Coords[c].y;
03709
03710 FLOAT8 alpha = x * Info->Trans.cf11 + y * Info->Trans.cf21 + Info->Trans.cf41;
03711 FLOAT8 beta = x * Info->Trans.cf12 + y * Info->Trans.cf22 + Info->Trans.cf42;
03712 FLOAT8 gamma = x * Info->Trans.cf13 + y * Info->Trans.cf23 + Info->Trans.cf43;
03713
03714 FLOAT8 norm = gamma * projC + 1;
03715
03716 Coords[c].x = (INT32)((alpha + gamma * projA) / norm);
03717 Coords[c].y = (INT32)((beta + gamma * projB) / norm);
03718 }
03719
03720
03721 return TRUE;
03722 }
03723
03724
03725
03726
03727
03728
03729
03730
03731
03732
03733
03734
03735
03736
03737 BOOL CDRTransformConvertor5::Init(ADDR Data, INT32 Size)
03738 {
03739 List = Data;
03740 ListSize = Size;
03741
03742 ADDR TransformData;
03743
03744 if(!RIFFFile::FindChunkWithinListContents(List, ListSize, cdrT_trfd, 0, &TransformData, 0))
03745 return 0;
03746
03747 Trans = (cdrfTransform *)TransformData;
03748
03749 return TRUE;
03750 }
03751
03752
03753
03754
03755
03756
03757
03758
03759
03760
03761
03762
03763
03764
03765
03766 BOOL CDRTransformConvertor4::Init(ADDR Data, INT32 Size)
03767 {
03768 List = Data;
03769 ListSize = Size;
03770
03771 ADDR TransformData;
03772
03773 if(!RIFFFile::FindChunkWithinListContents(List, ListSize, cdrT_trfd, 0, &TransformData, 0))
03774 return 0;
03775
03776 Trans = (cdrfTransformV4 *)TransformData;
03777
03778 return TRUE;
03779 }
03780
03781
03782
03783
03784
03785
03786
03787
03788
03789
03790
03791
03792
03793
03794
03795 CDRTransformType CDRTransformConvertor5::GetTransformType(UINT32 n)
03796 {
03797 if(n >= CDRDATA_WORD(Trans->NTransforms))
03798 return CDRTRANSFORMTYPE_UNKNOWN;
03799
03800 cdrfTransformHeader *Hdr = (cdrfTransformHeader *)(((ADDR)Trans) + CDRDATA_WORD(Trans->TransformOffsets[n]));
03801
03802 switch(CDRDATA_WORD(Hdr->Type))
03803 {
03804 case cdrfTRANSFORMTYPE_MATRIX:
03805 return CDRTRANSFORMTYPE_MATRIX;
03806 break;
03807
03808 case cdrfTRANSFORMTYPE_PERSPECTIVE:
03809 return CDRTRANSFORMTYPE_PERSPECTIVE;
03810 break;
03811
03812 #ifdef CDR_DOEXTRUDE
03813 case cdrfTRANSFORMTYPE_EXTRUDE:
03814 return CDRTRANSFORMTYPE_EXTRUDE;
03815 break;
03816 #endif
03817
03818 case cdrfTRANSFORMTYPE_ENVELOPE:
03819 return CDRTRANSFORMTYPE_ENVELOPE;
03820 break;
03821
03822 default:
03823 TRACEUSER( "Ben", _T("[] Unknown v5 transform type\n"));
03824 break;
03825 }
03826
03827 return CDRTRANSFORMTYPE_UNKNOWN;
03828 }
03829
03830
03831
03832
03833
03834
03835
03836
03837
03838
03839
03840
03841
03842
03843
03844 CDRTransformType CDRTransformConvertor4::GetTransformType(UINT32 n)
03845 {
03846 if(n >= CDRDATA_WORD(Trans->NTransforms))
03847 return CDRTRANSFORMTYPE_UNKNOWN;
03848
03849 WORD *Offsets = (WORD *)(((ADDR)Trans) + CDRDATA_WORD(Trans->OffsetsStart));
03850 cdrfTransformHeader *Hdr = (cdrfTransformHeader *)(((ADDR)Trans) + CDRDATA_WORD(Offsets[n]));
03851
03852 switch(CDRDATA_WORD(Hdr->Type))
03853 {
03854 case cdrfTRANSFORMTYPE_MATRIX:
03855 return CDRTRANSFORMTYPE_MATRIX;
03856 break;
03857
03858 case cdrfTRANSFORMTYPE_PERSPECTIVE:
03859 return CDRTRANSFORMTYPE_PERSPECTIVE;
03860 break;
03861
03862 #ifdef CDR_DOEXTRUDE
03863 case cdrfTRANSFORMTYPE_EXTRUDE:
03864 return CDRTRANSFORMTYPE_EXTRUDE;
03865 break;
03866 #endif
03867
03868 case cdrfTRANSFORMTYPE_ENVELOPE:
03869 return CDRTRANSFORMTYPE_ENVELOPE;
03870 break;
03871
03872 default:
03873 TRACEUSER( "Ben", _T("[] Unknown v4 transform type\n"));
03874 break;
03875 }
03876
03877 return CDRTRANSFORMTYPE_UNKNOWN;
03878 }
03879
03880
03881
03882
03883
03884
03885
03886
03887
03888
03889
03890
03891
03892
03893
03894 BOOL CDRTransformConvertor5::GetMatrix(cdrMatrix *M, UINT32 n)
03895 {
03896 if(n >= CDRDATA_WORD(Trans->NTransforms))
03897 return FALSE;
03898
03899 cdrfTransformHeader *Hdr = (cdrfTransformHeader *)(((ADDR)Trans) + CDRDATA_WORD(Trans->TransformOffsets[n]));
03900
03901 ERROR3IF(CDRDATA_WORD(Hdr->Type) != cdrfTRANSFORMTYPE_MATRIX, "GetMatrix called for a non matrix trfd entry");
03902 ERROR3IF((sizeof(FLOAT8) / 2) != sizeof(DWORD) || sizeof(DWORD) != 4, "Non valid sizeof assumptions");
03903
03904
03905 FLOAT8 *TData = (FLOAT8 *)(Hdr + 1);
03906 FLOAT8 *Out = (FLOAT8 *)M;
03907
03908 INT32 l;
03909 for(l = 0; l < 6; l++)
03910 {
03911 Out[l] = CDRDATA_FLOAT8(TData[l]);
03912 }
03913
03914
03915 M->c *= CDRCOORDS_TO_MILLIPOINTS;
03916 M->f *= CDRCOORDS_TO_MILLIPOINTS;
03917
03918 return TRUE;
03919 }
03920
03921
03922
03923
03924
03925
03926
03927
03928
03929
03930
03931
03932
03933
03934
03935 BOOL CDRTransformConvertor::ConvertPerspective(cdrPerspective *P, cdrfPerspectiveTransform *Tran)
03936 {
03937
03938 INT32 x0, y0, y1, x1;
03939 x0 = CDRDATA_SWORD(Tran->Ox0) * CDRCOORDS_TO_MILLIPOINTS;
03940 y0 = CDRDATA_SWORD(Tran->Oy0) * CDRCOORDS_TO_MILLIPOINTS;
03941 x1 = CDRDATA_SWORD(Tran->Ox1) * CDRCOORDS_TO_MILLIPOINTS;
03942 y1 = CDRDATA_SWORD(Tran->Oy1) * CDRCOORDS_TO_MILLIPOINTS;
03943
03944 if(x0 > x1)
03945 {
03946 INT32 t = x1;
03947 x1 = x0;
03948 x0 = t;
03949 }
03950
03951 if(y0 > y1)
03952 {
03953 INT32 t = y1;
03954 y1 = y0;
03955 y0 = t;
03956 }
03957
03958 P->OriginalBBox.lo.x = x0;
03959 P->OriginalBBox.lo.y = y0;
03960 P->OriginalBBox.hi.x = x1;
03961 P->OriginalBBox.hi.y = y1;
03962
03963
03964 for(INT32 l = 0; l < 4; l++)
03965 {
03966 P->NewCorners[l].x = CDRDATA_SWORD(Tran->NewCorners[l].X) * CDRCOORDS_TO_MILLIPOINTS;
03967 P->NewCorners[l].y = CDRDATA_SWORD(Tran->NewCorners[l].Y) * CDRCOORDS_TO_MILLIPOINTS;
03968 }
03969
03970 return TRUE;
03971 }
03972
03973
03974
03975
03976
03977
03978
03979
03980
03981
03982
03983
03984
03985
03986
03987 BOOL CDRTransformConvertor5::GetPerspective(cdrPerspective *P, UINT32 n)
03988 {
03989 if(n >= CDRDATA_WORD(Trans->NTransforms))
03990 return FALSE;
03991
03992 cdrfTransformHeader *Hdr = (cdrfTransformHeader *)(((ADDR)Trans) + CDRDATA_WORD(Trans->TransformOffsets[n]));
03993
03994 ERROR3IF(CDRDATA_WORD(Hdr->Type) != cdrfTRANSFORMTYPE_PERSPECTIVE, "GetPerspective called for a non matrix trfd entry");
03995
03996 cdrfPerspectiveEntry *Per = (cdrfPerspectiveEntry *)Hdr;
03997
03998 return ConvertPerspective(P, &Per->Trans);
03999 }
04000
04001
04002
04003
04004
04005
04006
04007
04008
04009
04010
04011
04012
04013
04014
04015 BOOL CDRTransformConvertor4::GetPerspective(cdrPerspective *P, UINT32 n)
04016 {
04017 if(n >= Trans->NTransforms)
04018 return FALSE;
04019
04020 WORD *Offsets = (WORD *)(((ADDR)Trans) + Trans->OffsetsStart);
04021 cdrfTransformHeader *Hdr = (cdrfTransformHeader *)(((ADDR)Trans) + Offsets[n]);
04022
04023 ERROR3IF(Hdr->Type != cdrfTRANSFORMTYPE_PERSPECTIVE, "GetPerspective called for a non matrix trfd entry");
04024
04025 cdrfPerspectiveEntry *Per = (cdrfPerspectiveEntry *)Hdr;
04026
04027 return ConvertPerspective(P, & Per->Trans);
04028 }
04029
04030
04031
04032
04033
04034
04035
04036
04037
04038
04039
04040
04041
04042
04043
04044 BOOL CDRTransformConvertor4::GetMatrix(cdrMatrix *M, UINT32 n)
04045 {
04046 if(n >= Trans->NTransforms)
04047 return FALSE;
04048
04049 WORD *Offsets = (WORD *)(((ADDR)Trans) + Trans->OffsetsStart);
04050 cdrfTransformHeader *Hdr = (cdrfTransformHeader *)(((ADDR)Trans) + Offsets[n]);
04051
04052 ERROR3IF(Hdr->Type != cdrfTRANSFORMTYPE_MATRIX, "GetMatrix called for a non matrix trfd entry");
04053
04054
04055 WORD *TDataUS = (WORD *)(Hdr + 1);
04056
04057 SWORD *TDataS = (SWORD *)(Hdr + 1);
04058
04059 SDWORD *TDDataS = (SDWORD *)(Hdr + 1);
04060
04061
04062
04063 M->a = (FLOAT8)CDRDATA_SWORD(TDataS[1]) + ((FLOAT8)CDRDATA_WORD(TDataUS[0]) / 0xffff);
04064 M->b = (FLOAT8)CDRDATA_SWORD(TDataS[3]) + ((FLOAT8)CDRDATA_WORD(TDataUS[2]) / 0xffff);
04065 M->c = (FLOAT8)(CDRDATA_DSWORD(TDDataS[2]) * CDRCOORDS_TO_MILLIPOINTS);
04066 M->d = (FLOAT8)CDRDATA_SWORD(TDataS[7]) + ((FLOAT8)CDRDATA_WORD(TDataUS[6]) / 0xffff);
04067 M->e = (FLOAT8)CDRDATA_SWORD(TDataS[9]) + ((FLOAT8)CDRDATA_WORD(TDataUS[8]) / 0xffff);
04068 M->f = (FLOAT8)(CDRDATA_DSWORD(TDDataS[5]) * CDRCOORDS_TO_MILLIPOINTS);
04069
04070 return TRUE;
04071 }
04072
04073
04074
04075
04076
04077
04078
04079
04080
04081
04082
04083
04084
04085
04086
04087 CDRTransformType CDRTransformConvertor3::GetTransformType(UINT32 n)
04088 {
04089 if(n >= CDRDATA_WORD(Trans->NTransforms))
04090 return CDRTRANSFORMTYPE_UNKNOWN;
04091
04092 cdrfTransformEntryV3 *En = (cdrfTransformEntryV3 *)(Trans + 1);
04093
04094 switch(CDRDATA_WORD(En[n].Type))
04095 {
04096 case cdrfTRANSFORMTYPE_MATRIX_V3:
04097 return CDRTRANSFORMTYPE_MATRIX;
04098 break;
04099
04100 case cdrfTRANSFORMTYPE_PERSPECTIVE_V3:
04101 return CDRTRANSFORMTYPE_PERSPECTIVE;
04102 break;
04103
04104 case cdrfTRANSFORMTYPE_ENVELOPE_V3:
04105 return CDRTRANSFORMTYPE_ENVELOPE;
04106 break;
04107
04108 #ifdef CDR_DOEXTRUDE
04109 case cdrfTRANSFORMTYPE_EXTRUDE_V3:
04110 return CDRTRANSFORMTYPE_EXTRUDE;
04111 break;
04112 #endif
04113
04114 default:
04115 TRACEUSER( "Ben", _T("[] Unknown v3 transform type %x\n"), En[n].Type);
04116 break;
04117 }
04118
04119 return CDRTRANSFORMTYPE_UNKNOWN;
04120 }
04121
04122
04123
04124
04125
04126
04127
04128
04129
04130
04131
04132
04133
04134
04135
04136 BOOL CDRTransformConvertor3::GetExtrude(cdrExtrudeInfo *Info, UINT32 n)
04137 {
04138 if(n >= CDRDATA_WORD(Trans->NTransforms))
04139 return FALSE;
04140
04141 cdrfTransformEntryV3 *En = (cdrfTransformEntryV3 *)(Trans + 1);
04142 cdrfTransformExtrudeV3 *Data = (cdrfTransformExtrudeV3 *)(((BYTE *)Trans) + En[n].Offset);
04143
04144 Info->Trans.cf11 = (FLOAT8)CDRDATA_SWORD(Data->cf11b) + ((FLOAT8)CDRDATA_WORD(Data->cf11a) / 0xffff);
04145 Info->Trans.cf12 = (FLOAT8)CDRDATA_SWORD(Data->cf12b) + ((FLOAT8)CDRDATA_WORD(Data->cf12a) / 0xffff);
04146 Info->Trans.cf13 = (FLOAT8)CDRDATA_SWORD(Data->cf13b) + ((FLOAT8)CDRDATA_WORD(Data->cf13a) / 0xffff);
04147 Info->Trans.cf21 = (FLOAT8)CDRDATA_SWORD(Data->cf21b) + ((FLOAT8)CDRDATA_WORD(Data->cf21a) / 0xffff);
04148 Info->Trans.cf22 = (FLOAT8)CDRDATA_SWORD(Data->cf22b) + ((FLOAT8)CDRDATA_WORD(Data->cf22a) / 0xffff);
04149 Info->Trans.cf23 = (FLOAT8)CDRDATA_SWORD(Data->cf23b) + ((FLOAT8)CDRDATA_WORD(Data->cf23a) / 0xffff);
04150 Info->Trans.cf31 = (FLOAT8)CDRDATA_SWORD(Data->cf31b) + ((FLOAT8)CDRDATA_WORD(Data->cf31a) / 0xffff);
04151 Info->Trans.cf32 = (FLOAT8)CDRDATA_SWORD(Data->cf32b) + ((FLOAT8)CDRDATA_WORD(Data->cf32a) / 0xffff);
04152 Info->Trans.cf33 = (FLOAT8)CDRDATA_SWORD(Data->cf33b) + ((FLOAT8)CDRDATA_WORD(Data->cf33a) / 0xffff);
04153 Info->Trans.cf41 = (FLOAT8)CDRDATA_FLOAT4(Data->f41);
04154 Info->Trans.cf42 = (FLOAT8)CDRDATA_FLOAT4(Data->f42);
04155 Info->Trans.cf43 = (FLOAT8)CDRDATA_FLOAT4(Data->f43);
04156
04157 Info->Camera.x = CDRDATA_SWORD(Data->Cx) * CDRCOORDS_TO_MILLIPOINTS;
04158 Info->Camera.y = CDRDATA_SWORD(Data->Cy) * CDRCOORDS_TO_MILLIPOINTS;
04159 Info->Camera.z = CDRDATA_DWORD(Data->Cz) * CDRCOORDS_TO_MILLIPOINTS;
04160
04161 return TRUE;
04162 }
04163
04164
04165
04166
04167
04168
04169
04170
04171
04172
04173
04174
04175
04176
04177
04178 BOOL CDRTransformConvertor::ConvertExtrudeInfo(cdrfTransformExtrude *pTransform, cdrExtrudeInfo *Info)
04179 {
04180 Info->Trans.cf11 = (FLOAT8)CDRDATA_SWORD(pTransform->cf11b) + ((FLOAT8)CDRDATA_WORD(pTransform->cf11a) / 0xffff);
04181 Info->Trans.cf12 = (FLOAT8)CDRDATA_SWORD(pTransform->cf12b) + ((FLOAT8)CDRDATA_WORD(pTransform->cf12a) / 0xffff);
04182 Info->Trans.cf13 = (FLOAT8)CDRDATA_SWORD(pTransform->cf13b) + ((FLOAT8)CDRDATA_WORD(pTransform->cf13a) / 0xffff);
04183 Info->Trans.cf21 = (FLOAT8)CDRDATA_SWORD(pTransform->cf21b) + ((FLOAT8)CDRDATA_WORD(pTransform->cf21a) / 0xffff);
04184 Info->Trans.cf22 = (FLOAT8)CDRDATA_SWORD(pTransform->cf22b) + ((FLOAT8)CDRDATA_WORD(pTransform->cf22a) / 0xffff);
04185 Info->Trans.cf23 = (FLOAT8)CDRDATA_SWORD(pTransform->cf23b) + ((FLOAT8)CDRDATA_WORD(pTransform->cf23a) / 0xffff);
04186 Info->Trans.cf31 = (FLOAT8)CDRDATA_SWORD(pTransform->cf31b) + ((FLOAT8)CDRDATA_WORD(pTransform->cf31a) / 0xffff);
04187 Info->Trans.cf32 = (FLOAT8)CDRDATA_SWORD(pTransform->cf32b) + ((FLOAT8)CDRDATA_WORD(pTransform->cf32a) / 0xffff);
04188 Info->Trans.cf33 = (FLOAT8)CDRDATA_SWORD(pTransform->cf33b) + ((FLOAT8)CDRDATA_WORD(pTransform->cf33a) / 0xffff);
04189 Info->Trans.cf41 = (FLOAT8)CDRDATA_DWORD(pTransform->f41);
04190 Info->Trans.cf42 = (FLOAT8)CDRDATA_DWORD(pTransform->f42);
04191 Info->Trans.cf43 = (FLOAT8)CDRDATA_DWORD(pTransform->f43);
04192
04193 Info->Camera.x = CDRDATA_SWORD(pTransform->Cx) * CDRCOORDS_TO_MILLIPOINTS;
04194 Info->Camera.y = CDRDATA_SWORD(pTransform->Cy) * CDRCOORDS_TO_MILLIPOINTS;
04195 Info->Camera.z = CDRDATA_DWORD(pTransform->Cz) * CDRCOORDS_TO_MILLIPOINTS;
04196
04197 return TRUE;
04198 }
04199
04200
04201
04202
04203
04204
04205
04206
04207
04208
04209
04210
04211
04212
04213
04214 BOOL CDRTransformConvertor4::GetExtrude(cdrExtrudeInfo *Info, UINT32 n)
04215 {
04216 if(n >= Trans->NTransforms)
04217 return FALSE;
04218
04219 WORD *Offsets = (WORD *)(((ADDR)Trans) + Trans->OffsetsStart);
04220 cdrfTransformHeader *Hdr = (cdrfTransformHeader *)(((ADDR)Trans) + Offsets[n]);
04221
04222 return ConvertExtrudeInfo((cdrfTransformExtrude *)Hdr, Info);
04223 }
04224
04225
04226
04227
04228
04229
04230
04231
04232
04233
04234
04235
04236
04237
04238
04239 BOOL CDRTransformConvertor5::GetExtrude(cdrExtrudeInfo *Info, UINT32 n)
04240 {
04241 if(n >= CDRDATA_WORD(Trans->NTransforms))
04242 return FALSE;
04243
04244 cdrfTransformHeader *Hdr = (cdrfTransformHeader *)(((ADDR)Trans) + CDRDATA_WORD(Trans->TransformOffsets[n]));
04245
04246 return ConvertExtrudeInfo((cdrfTransformExtrude *)Hdr, Info);
04247 }
04248
04249
04250
04251
04252
04253
04254
04255
04256
04257
04258
04259
04260
04261
04262
04263 BOOL CDRTransformConvertor3::GetMatrix(cdrMatrix *M, UINT32 n)
04264 {
04265 if(n >= CDRDATA_WORD(Trans->NTransforms))
04266 return FALSE;
04267
04268 cdrfTransformEntryV3 *En = (cdrfTransformEntryV3 *)(Trans + 1);
04269 BYTE *Data = ((BYTE *)Trans) + En[n].Offset;
04270
04271
04272 WORD *TDataUS = (WORD *)Data;
04273
04274 SWORD *TDataS = (SWORD *)Data;
04275
04276 SDWORD *TDDataS = (SDWORD *)Data;
04277
04278
04279
04280 M->a = (FLOAT8)CDRDATA_SWORD(TDataS[1]) + ((FLOAT8)CDRDATA_WORD(TDataUS[0]) / 0xffff);
04281 M->b = (FLOAT8)CDRDATA_SWORD(TDataS[3]) + ((FLOAT8)CDRDATA_WORD(TDataUS[2]) / 0xffff);
04282 M->c = (FLOAT8)(CDRDATA_DSWORD(TDDataS[2]) * CDRCOORDS_TO_MILLIPOINTS);
04283 M->d = (FLOAT8)CDRDATA_SWORD(TDataS[7]) + ((FLOAT8)CDRDATA_WORD(TDataUS[6]) / 0xffff);
04284 M->e = (FLOAT8)CDRDATA_SWORD(TDataS[9]) + ((FLOAT8)CDRDATA_WORD(TDataUS[8]) / 0xffff);
04285 M->f = (FLOAT8)(CDRDATA_DSWORD(TDDataS[5]) * CDRCOORDS_TO_MILLIPOINTS);
04286
04287 return TRUE;
04288 }
04289
04290
04291
04292
04293
04294
04295
04296
04297
04298
04299
04300
04301
04302
04303
04304 BOOL CDRTransformConvertor3::GetPerspective(cdrPerspective *P, UINT32 n)
04305 {
04306 if(n >= CDRDATA_WORD(Trans->NTransforms))
04307 return FALSE;
04308
04309 cdrfTransformEntryV3 *En = (cdrfTransformEntryV3 *)(Trans + 1);
04310 BYTE *Data = ((BYTE *)Trans) + En[n].Offset;
04311
04312 return ConvertPerspective(P, (cdrfPerspectiveTransform *)Data);
04313 }
04314
04315
04316
04317
04318
04319
04320
04321
04322
04323
04324
04325
04326
04327
04328
04329
04330 BOOL CDRTransformConvertor::ConvertEnvelopeBBox(ADDR Entry, DocRect *BBox, INT32 *Corners)
04331 {
04332
04333 cdrfTransformEnvelope *En = (cdrfTransformEnvelope *)Entry;
04334
04335 INT32 x0, y0, y1, x1;
04336 x0 = CDRDATA_SWORD(En->Ox0) * CDRCOORDS_TO_MILLIPOINTS;
04337 y0 = CDRDATA_SWORD(En->Oy0) * CDRCOORDS_TO_MILLIPOINTS;
04338 x1 = CDRDATA_SWORD(En->Ox1) * CDRCOORDS_TO_MILLIPOINTS;
04339 y1 = CDRDATA_SWORD(En->Oy1) * CDRCOORDS_TO_MILLIPOINTS;
04340
04341 if(x0 > x1)
04342 {
04343 INT32 t = x1;
04344 x1 = x0;
04345 x0 = t;
04346 }
04347
04348 if(y0 > y1)
04349 {
04350 INT32 t = y1;
04351 y1 = y0;
04352 y0 = t;
04353 }
04354
04355 BBox->lo.x = x0;
04356 BBox->lo.y = y0;
04357 BBox->hi.x = x1;
04358 BBox->hi.y = y1;
04359
04360
04361 for(INT32 l = 0; l < 4; l++)
04362 {
04363 Corners[l] = CDRDATA_WORD(En->Corners[l]);
04364 }
04365
04366 return TRUE;
04367 }
04368
04369
04370
04371
04372
04373
04374
04375
04376
04377
04378
04379
04380
04381
04382
04383 BOOL CDRTransformConvertor::ConvertEnvelopePath(ADDR List, INT32 ListSize, INT32 Entry, Path **ppPath)
04384 {
04385
04386 ADDR Chunk;
04387 INT32 ChunkSize;
04388 if(!RIFFFile::FindChunkWithinListContents(List, ListSize, cdrT_envd, Entry, &Chunk, &ChunkSize))
04389 return FALSE;
04390
04391
04392 cdrfOffsetHeader *Hdr = (cdrfOffsetHeader *)Chunk;
04393 INT32 NCoords = CDRDATA_WORD(Hdr->ObjectType);
04394
04395
04396 ADDR Coords = CDRFilter::FindDataInObject(Hdr, cdrfENVELOPEOFFSETTYPE_COORDS);
04397 ADDR Types = CDRFilter::FindDataInObject(Hdr, cdrfENVELOPEOFFSETTYPE_TYPES);
04398
04399 if(Coords == 0 || Types == 0)
04400 return FALSE;
04401
04402
04403
04404 Path *pPath = new Path;
04405 if(pPath == 0 || (!pPath->Initialise()))
04406 {
04407 delete pPath;
04408 return FALSE;
04409 }
04410
04411
04412 pPath->FindStartOfPath();
04413
04414 if(!CDRFilter::AddElementsToPath(pPath, NCoords, (cdrfCoord *)Coords, Types, 0))
04415 return FALSE;
04416
04417
04418 if(!pPath->EnsureValid())
04419 {
04420
04421 delete pPath;
04422 return FALSE;
04423 }
04424
04425
04426 (*ppPath) = pPath;
04427
04428 return TRUE;
04429 }
04430
04431
04432
04433
04434
04435
04436
04437
04438
04439
04440
04441
04442
04443
04444
04445
04446 BOOL CDRTransformConvertor5::GetEnvelope(Path **P, DocRect *OriginalBBox, INT32 *Corners, UINT32 n)
04447 {
04448 if(n >= CDRDATA_WORD(Trans->NTransforms))
04449 return FALSE;
04450
04451 cdrfTransformHeader *Hdr;
04452
04453
04454 INT32 EnvelopesSoFar = 0;
04455 for(UINT32 l = 0; l <= n; l++)
04456 {
04457 Hdr = (cdrfTransformHeader *)(((ADDR)Trans) + CDRDATA_WORD(Trans->TransformOffsets[l]));
04458
04459
04460 if(CDRDATA_WORD(Hdr->Type) == cdrfTRANSFORMTYPE_ENVELOPE)
04461 EnvelopesSoFar++;
04462 }
04463
04464 ERROR2IF(EnvelopesSoFar <= 0, FALSE, "No envelopes found!");
04465
04466
04467 if(!ConvertEnvelopeBBox((ADDR)Hdr, OriginalBBox, Corners))
04468 return FALSE;
04469
04470 if(!ConvertEnvelopePath(List, ListSize, EnvelopesSoFar - 1, P))
04471 return FALSE;
04472
04473 return TRUE;
04474 }
04475
04476
04477
04478
04479
04480
04481
04482
04483
04484
04485
04486
04487
04488
04489
04490
04491 BOOL CDRTransformConvertor4::GetEnvelope(Path **P, DocRect *OriginalBBox, INT32 *Corners, UINT32 n)
04492 {
04493 if(n >= CDRDATA_WORD(Trans->NTransforms))
04494 return FALSE;
04495
04496 cdrfTransformHeader *Hdr;
04497 WORD *Offsets = (WORD *)(((ADDR)Trans) + Trans->OffsetsStart);
04498
04499
04500 INT32 EnvelopesSoFar = 0;
04501 for(UINT32 l = 0; l <= n; l++)
04502 {
04503 Hdr = (cdrfTransformHeader *)(cdrfTransformHeader *)(((ADDR)Trans) + Offsets[l]);
04504
04505
04506 if(CDRDATA_WORD(Hdr->Type) == cdrfTRANSFORMTYPE_ENVELOPE)
04507 EnvelopesSoFar++;
04508 }
04509
04510 ERROR2IF(EnvelopesSoFar <= 0, FALSE, "No envelopes found!");
04511
04512
04513 if(!ConvertEnvelopeBBox((ADDR)Hdr, OriginalBBox, Corners))
04514 return FALSE;
04515
04516 if(!ConvertEnvelopePath(List, ListSize, EnvelopesSoFar - 1, P))
04517 return FALSE;
04518
04519 return TRUE;
04520 }
04521
04522
04523
04524
04525
04526
04527
04528
04529
04530
04531
04532
04533
04534
04535
04536
04537 #define ENVV3_NCOORDS 25
04538
04539 BOOL CDRTransformConvertor3::GetEnvelope(Path **P, DocRect *OriginalBBox, INT32 *Corners, UINT32 n)
04540 {
04541 if(n >= CDRDATA_WORD(Trans->NTransforms))
04542 return FALSE;
04543
04544 cdrfTransformEntryV3 *En = (cdrfTransformEntryV3 *)(Trans + 1);
04545 BYTE *Data = ((BYTE *)Trans) + En[n].Offset;
04546
04547
04548 cdrfTransformEnvelopeV3 *Env = (cdrfTransformEnvelopeV3 *)Data;
04549
04550
04551 INT32 x0, y0, y1, x1;
04552 x0 = CDRDATA_SWORD(Env->Ox0) * CDRCOORDS_TO_MILLIPOINTS;
04553 y0 = CDRDATA_SWORD(Env->Oy0) * CDRCOORDS_TO_MILLIPOINTS;
04554 x1 = CDRDATA_SWORD(Env->Ox1) * CDRCOORDS_TO_MILLIPOINTS;
04555 y1 = CDRDATA_SWORD(Env->Oy1) * CDRCOORDS_TO_MILLIPOINTS;
04556
04557 if(x0 > x1)
04558 {
04559 INT32 t = x1;
04560 x1 = x0;
04561 x0 = t;
04562 }
04563
04564 if(y0 > y1)
04565 {
04566 INT32 t = y1;
04567 y1 = y0;
04568 y0 = t;
04569 }
04570
04571 OriginalBBox->lo.x = x0;
04572 OriginalBBox->lo.y = y0;
04573 OriginalBBox->hi.x = x1;
04574 OriginalBBox->hi.y = y1;
04575
04576
04577 DocCoord Co[ENVV3_NCOORDS];
04578 INT32 l;
04579 for(l = 0; l < ENVV3_NCOORDS; l++)
04580 {
04581 Co[l].x = CDRDATA_SWORD(Env->Coords[l].X) * CDRCOORDS_TO_MILLIPOINTS;
04582 Co[l].y = CDRDATA_SWORD(Env->Coords[l].Y) * CDRCOORDS_TO_MILLIPOINTS;
04583 }
04584
04585
04586 Path *pShape = new Path;
04587 if(pShape == 0 || (!pShape->Initialise()))
04588 {
04589 delete pShape;
04590 return FALSE;
04591 }
04592
04593
04594 pShape->FindStartOfPath();
04595
04596
04597 if(!pShape->InsertMoveTo(Co[0]))
04598 return FALSE;
04599 for(INT32 c = 1; c < ENVV3_NCOORDS; c += 3)
04600 {
04601 if(!pShape->InsertCurveTo(Co[c], Co[c + 1], Co[c + 2]))
04602 return FALSE;
04603 }
04604 if(!pShape->CloseSubPath())
04605 return FALSE;
04606
04607 *P = pShape;
04608
04609
04610 Corners[0] = 0;
04611 Corners[1] = 6;
04612 Corners[2] = 12;
04613 Corners[3] = 18;
04614
04615 return TRUE;
04616 }
04617
04618
04619
04620
04621
04622
04623
04624
04625
04626
04627
04628
04629
04630
04631
04632 BOOL CDRFilter::ClearUp(void)
04633 {
04634 Version = CDRVERSION_NULL;
04635
04636 if(SlowJobStarted == TRUE)
04637 EndSlowJob();
04638
04639 if(Success == FALSE)
04640 {
04641
04642 while(!Actions.IsEmpty())
04643 {
04644 CDRActionListItem *Act = (CDRActionListItem *)Actions.GetTail();
04645
04646 ERROR3IF(Act == 0, "Returned tail in a non-empty Action list is 0");
04647
04648 Act->ImportFailure(this);
04649
04650 delete Actions.RemoveItem(Act);
04651 }
04652
04653
04654 DeleteNodeList(pLevelNodeList);
04655
04656
04657 if(UseLayers)
04658 {
04659 LayerSGallery::MakeTopLayerActive(pSpread);
04660 BROADCAST_TO_ALL(SpreadMsg(pSpread, SpreadMsg::LAYERCHANGES));
04661 }
04662 }
04663
04664 TRACEUSER( "Ben", _T("At CDRFilter::ClearUp(), Fills has %d entries\n"), Fills.GetCount());
04665 TRACEUSER( "Ben", _T("At CDRFilter::ClearUp(), Outlines has %d entries\n"), Outlines.GetCount());
04666 TRACEUSER( "Ben", _T("At CDRFilter::ClearUp(), Styles has %d entries\n"), Styles.GetCount());
04667 TRACEUSER( "Ben", _T("At CDRFilter::ClearUp(), Fonts has %d entries\n"), Fonts.GetCount());
04668 TRACEUSER( "Ben", _T("At CDRFilter::ClearUp(), Arrowheads has %d entries\n"), Arrowheads.GetCount());
04669 TRACEUSER( "Ben", _T("At CDRFilter::ClearUp(), Patterns has %d entries\n"), Patterns.GetCount());
04670 TRACEUSER( "Ben", _T("At CDRFilter::ClearUp(), Bitmaps has %d entries\n"), Bitmaps.GetCount());
04671 TRACEUSER( "Ben", _T("At CDRFilter::ClearUp(), Vectors has %d entries\n"), Vectors.GetCount());
04672 TRACEUSER( "Ben", _T("At CDRFilter::ClearUp(), TextV4 has %d entries\n"), TextV4.GetCount());
04673 TRACEUSER( "Ben", _T("At CDRFilter::ClearUp(), Pages has %d entries\n"), Pages.GetCount());
04674 TRACEUSER( "Ben", _T("At CDRFilter::ClearUp(), Actions has %d entries\n"), Actions.GetCount());
04675 TRACEUSER( "Ben", _T("At CDRFilter::ClearUp(), TextBBoxes has %d entries\n"), TextBBoxes.GetCount());
04676 TRACEUSER( "Ben", _T("At CDRFilter::ClearUp(), TextOnPathLinks has %d entries\n"), TextOnPathLinks.GetCount());
04677 TRACEUSER( "Ben", _T("ObjectsConverted = %d\nObjectsFormatWrong = %d\nObjectsUnknown = %d\nEnvelopesApproximated = %d\n"), ObjectsConverted, ObjectsFormatWrong, ObjectsUnknown, EnvelopesApproximated);
04678
04679 ERROR3IF(Success == TRUE && Actions.GetCount() != 0, "Not all actions used at the end of a successful CDR convert!");
04680
04681 Fills.DeleteAll();
04682 Outlines.DeleteAll();
04683 Styles.DeleteAll();
04684 Fonts.DeleteAll();
04685 Arrowheads.DeleteAll();
04686 Patterns.DeleteAll();
04687 Bitmaps.DeleteAll();
04688 Vectors.DeleteAll();
04689 TextV4.DeleteAll();
04690 Pages.DeleteAll();
04691 Actions.DeleteAll();
04692 TextBBoxes.DeleteAll();
04693 TextOnPathLinks.DeleteAll();
04694
04695
04696 ColourCMYK CNullCol;
04697 CNullCol.Cyan = 1;
04698 CNullCol.Magenta = 1;
04699 CNullCol.Yellow = 1;
04700 CNullCol.Key = 1;
04701 DocColour NullCol = DocColour(COLOURMODEL_CMYK, (ColourGeneric *)&CNullCol);
04702 SetLineColour(NullCol);
04703 SetFillColour(NullCol);
04704
04705
04706 DeleteCurrentAttrs();
04707
04708
04709 CCFree(ObjDataBlock);
04710 CCFree(FontTableV3);
04711 CCFree(FontStylesV3);
04712 CCFree(LinkTable);
04713
04714 TRACEUSER( "Ben", _T("ClearUp finished - import of CDR over\n"));
04715 return Success;
04716 }
04717
04718
04719
04720
04721
04722
04723
04724
04725
04726
04727
04728
04729
04730
04731
04732 void CDRFilter::DeleteNodeList(Node *Start)
04733 {
04734 Node *This, *Next;
04735
04736 This = Start;
04737
04738 while(This != 0)
04739 {
04740 Next = This->FindNext();
04741
04742 This->CascadeDelete();
04743
04744 delete This;
04745
04746 This = Next;
04747 }
04748 }
04749
04750
04751
04752
04753
04754
04755
04756
04757
04758
04759
04760
04761
04762
04763
04764 BOOL CDRFilter::DoExport(Operation*, CCLexFile*, PathName*, Document*, BOOL)
04765 {
04766
04767 return FALSE;
04768 }
04769
04770
04771
04772
04773
04774
04775
04776
04777
04778
04779
04780
04781
04782
04783
04784 BOOL CDRAttributeStore::AddChunkToStore(RIFFFile *RIFF)
04785 {
04786 if(RIFF->GetObjType() != RIFFOBJECTTYPE_CHUNK)
04787 {
04788 ERROR2(FALSE, "CDRAttributeStore::AddChunkToStore called without a chunk in the RIFFFile");
04789 }
04790
04791
04792 CDRAttributeStoredItem *Item = new CDRAttributeStoredItem;
04793
04794 if(Item == 0)
04795 return FALSE;
04796
04797
04798 if(!Item->Aquire(RIFF))
04799 {
04800 delete Item;
04801 return FALSE;
04802 }
04803
04804 Item->Size = RIFF->GetObjSize();
04805
04806
04807 AddTail(Item);
04808
04809 return TRUE;
04810 }
04811
04812
04813
04814
04815
04816
04817
04818
04819
04820
04821
04822
04823
04824
04825
04826 ADDR CDRAttributeStore::Find(DWORD Reference, INT32 *Size)
04827 {
04828 CDRAttributeStoredItem *Item;
04829
04830 if(IsEmpty())
04831 return 0;
04832
04833 Item = (CDRAttributeStoredItem *)GetHead();
04834
04835
04836 while(Item != 0)
04837 {
04838 if(CDRDATA_DWORD(*((DWORD *)(Item->Block))) == Reference)
04839 {
04840 *Size = Item->Size;
04841 return Item->Block;
04842 }
04843
04844 Item = (CDRAttributeStoredItem *)GetNext(Item);
04845 }
04846
04847 return 0;
04848 }
04849
04850
04851
04852
04853
04854
04855
04856
04857
04858
04859
04860
04861
04862
04863
04864 ADDR CDRAttributeStore::Find(WORD Reference, INT32 *Size)
04865 {
04866 CDRAttributeStoredItem *Item;
04867
04868 if(IsEmpty())
04869 return 0;
04870
04871 Item = (CDRAttributeStoredItem *)GetHead();
04872
04873
04874 while(Item != 0)
04875 {
04876 if(CDRDATA_WORD(*((WORD *)(Item->Block))) == Reference)
04877 {
04878 *Size = Item->Size;
04879 return Item->Block;
04880 }
04881
04882 Item = (CDRAttributeStoredItem *)GetNext(Item);
04883 }
04884
04885 return 0;
04886 }
04887
04888
04889
04890
04891
04892
04893
04894
04895
04896
04897
04898
04899
04900
04901
04902 CDRAttributeStoredItem::CDRAttributeStoredItem(void)
04903 {
04904 Block = 0;
04905 }
04906
04907
04908
04909
04910
04911
04912
04913
04914
04915
04916
04917
04918
04919
04920
04921 CDRAttributeStoredItem::~CDRAttributeStoredItem(void)
04922 {
04923 CCFree(Block);
04924 }
04925
04926
04927
04928
04929
04930
04931
04932
04933
04934
04935
04936
04937
04938
04939
04940 BOOL CDRAttributeStoredItem::Aquire(RIFFFile *RIFF)
04941 {
04942 ERROR3IF(Block != 0, "CDRAttributeStoredItem already has data");
04943
04944 Size = RIFF->GetObjSize();
04945
04946
04947 if((Block = (ADDR)CCMalloc(Size)) == 0)
04948 return FALSE;
04949
04950
04951 if(!RIFF->GetChunkData(Block, Size))
04952 return FALSE;
04953
04954
04955 return TRUE;
04956 }
04957
04958
04959
04960
04961
04962
04963
04964
04965
04966
04967
04968
04969
04970
04971
04972 CDRLayerListItem::CDRLayerListItem()
04973 {
04974 Objects = 0;
04975 LayerInDocument = FALSE;
04976 IsVisible = TRUE;
04977 IsLocked = FALSE;
04978 }
04979
04980
04981
04982
04983
04984
04985
04986
04987
04988
04989
04990
04991
04992
04993
04994 CDRLayerListItem::~CDRLayerListItem()
04995 {
04996 Node *Previous;
04997 Node *This;
04998
04999 This = Objects;
05000
05001 if(LayerInDocument == FALSE)
05002 {
05003
05004 while(This != 0)
05005 {
05006
05007
05008 ERROR3IF(This->FindNext() != 0, "Node in layer has next pointer during deletion");
05009
05010
05011 Previous = This->FindPrevious();
05012
05013
05014 This->CascadeDelete();
05015
05016
05017 delete This;
05018
05019
05020 This = Previous;
05021 }
05022 Objects = 0;
05023 }
05024 }
05025
05026
05027
05028
05029
05030
05031
05032
05033
05034
05035
05036
05037
05038
05039
05040 CDRLayerList::CDRLayerList()
05041 {
05042 }
05043
05044
05045
05046
05047
05048
05049
05050
05051
05052
05053
05054
05055
05056
05057
05058 CDRLayerList::~CDRLayerList()
05059 {
05060 DeleteAll();
05061 }
05062
05063
05064
05065
05066
05067
05068
05069
05070
05071
05072
05073
05074
05075
05076
05077 CDRPageList::CDRPageList()
05078 {
05079 }
05080
05081
05082
05083
05084
05085
05086
05087
05088
05089
05090
05091
05092
05093
05094
05095 CDRPageList::~CDRPageList()
05096 {
05097 }
05098
05099
05100
05101
05102
05103
05104
05105
05106
05107
05108
05109
05110
05111
05112
05113 CDRPageListItem::CDRPageListItem()
05114 {
05115 }
05116
05117
05118
05119
05120
05121
05122
05123
05124
05125
05126
05127
05128
05129
05130
05131 CDRPageListItem::~CDRPageListItem()
05132 {
05133 }
05134
05135
05136
05137
05138
05139
05140
05141
05142
05143
05144
05145
05146
05147
05148
05149
05150
05151
05152 BOOL CDRFilter::HasCDRFileGotCMXFile(PathName *FileName, CCLexFile *pFile)
05153 {
05154 CCDiskFile oTheFile;
05155 CCLexFile *pTheFile;
05156 INT32 pos;
05157
05158 if(pFile == NULL)
05159 {
05160 if (!(oTheFile.open(*FileName, ios::in | ios::binary)))
05161 {
05162 TRACEUSER( "Ben", _T("couldn't open file to check it for CMX\n"));
05163 return FALSE;
05164 }
05165 pTheFile = &oTheFile;
05166 }
05167 else
05168 {
05169 pTheFile = pFile;
05170 pos = pFile->tellIn();
05171 }
05172
05173
05174 RIFFFile_Header Hdr;
05175 pTheFile->read(&Hdr, sizeof(Hdr));
05176
05177 if(Hdr.CK.ckID != RIFFTYPE_RIFF)
05178 return FALSE;
05179
05180 UINT32 loc = sizeof(Hdr);
05181
05182
05183 BOOL Found = FALSE;
05184 while(loc < Hdr.CK.ckSize)
05185 {
05186 RIFFck ck;
05187 pTheFile->read(&ck, sizeof(ck));
05188 loc += sizeof(ck);
05189 if(ck.ckID == cdrT_cmx1)
05190 {
05191
05192 Found = TRUE;
05193 break;
05194 }
05195
05196
05197 loc += ck.ckSize;
05198 pTheFile->seekIn(loc);
05199 }
05200
05201
05202 if(pFile == NULL)
05203 {
05204 oTheFile.close();
05205 }
05206 else
05207 {
05208 pFile->seekIn(pos);
05209 }
05210
05211 return Found;
05212 }
05213
05214