00001
00002
00003
00004
00005
00006
00007
00008
00009
00010
00011
00012
00013
00014
00015
00016
00017
00018
00019
00020
00021
00022
00023
00024
00025
00026
00027
00028
00029
00030
00031
00032
00033
00034
00035
00036
00037
00038
00039
00040
00041
00042
00043
00044
00045
00046
00047
00048
00049
00050
00051
00052
00053
00054
00055
00056
00057
00058
00059
00060
00061
00062
00063
00064
00065
00066
00067
00068
00069
00070
00071
00072
00073
00074
00075
00076
00077
00078
00079
00080
00081
00082
00083
00084
00085
00086
00087
00088
00089
00090
00091
00092
00093
00094
00095
00096
00097
00098
00099
00100 #include "camtypes.h"
00101
00102 #include "riffform.h"
00103 #include "progress.h"
00104 #include "nodepath.h"
00105 #include "nodebmp.h"
00106 #include "nodershp.h"
00107
00108 #include "cmxifltr.h"
00109 #include "cmxistut.h"
00110 #include "cmxidata.h"
00111 #include "cmxibits.h"
00112 #include "cmxibitm.h"
00113
00114 #include "riffform.h"
00115 #include "progress.h"
00116 #include "nodepath.h"
00117
00118
00119 #include "nodetxts.h"
00120 #include "unicdman.h"
00121 #include "nodetxtl.h"
00122
00123
00124
00125
00126
00127
00128
00129
00130
00131
00132
00133
00134
00135
00136 BOOL CMXImportFilter::Stage4_ConvertPage(void)
00137 {
00138 TRACEUSER( "Ben", _T("Stage4_ConvertPage\n"));
00139
00140
00141
00142
00143
00144
00145
00146
00147 if(Data->MasterIndexEntries[cmxMASTERIN_PAGE] == 0)
00148 CMXFORMATERROR(FALSE)
00149
00150 TRACEUSER( "Ben", _T("index page at %d?\n"), Data->MasterIndexEntries[cmxMASTERIN_PAGE]);
00151 Seek(Data->MasterIndexEntries[cmxMASTERIN_PAGE]);
00152 RIFFck chdr;
00153 pFile->read(&chdr, sizeof(chdr));
00154 if(chdr.ckID != cmxRIFFCI_PageIndex)
00155 CMXFORMATERROR(FALSE)
00156
00157
00158 CI_READDATA(SimpleIndexHeader, ih)
00159 if(ih.RecordCount < 1)
00160 CMXFORMATERROR(FALSE)
00161
00162
00163 CI_READDATA(PageIndexEntry, ie)
00164 TRACEUSER( "Ben", _T("Page is at %d\n"), ie.PageOffset);
00165
00166
00167 Seek(ie.PageOffset);
00168 pFile->read(&chdr, sizeof(chdr));
00169 if(chdr.ckID != cmxRIFFCI_Page)
00170 CMXFORMATERROR(FALSE)
00171
00172
00173 INT32 PageEndFileLoc = Tell() + chdr.ckSize;
00174 Data->InPage = TRUE;
00175
00176
00177 INT32 wobble = 0;
00178
00179
00180 TRACEUSER( "Ben", _T("processing commands:\n"));
00181 while(Data->InPage == TRUE)
00182 {
00183
00184 if(!ProcessCommand(&wobble))
00185 return FALSE;
00186
00187
00188 if(Tell() >= PageEndFileLoc)
00189 Data->InPage = FALSE;
00190
00191
00192 if(Data->CommandsInPage != -1)
00193 {
00194 wobble++;
00195 if(!Data->pProgress->Update(wobble))
00196 {
00197 TRACEUSER( "claude", _T("User Escaped!\n"));
00198 Error::SetError(_R(IDN_CMXCANCELIMPORT));
00199
00200
00201 TRACEUSER( "claude", _T("after InformError()\n"));
00202 return FALSE;
00203 }
00204 }
00205 }
00206 TRACEUSER( "Ben", _T("finished processing commands\n"));
00207 TRACEUSER( "claude", _T("finished processing commands\n"));
00208
00209 return TRUE;
00210 }
00211
00212
00213
00214
00215
00216
00217
00218
00219
00220
00221
00222
00223
00224
00225 #define PC_DISPATCH(instr) case cmxINSTR_##instr: \
00226 TRACEUSER( "Ben", _T(" * " #instr "\n")); \
00227 TRACEUSER( "Claude", _T(" * " #instr "\n")); \
00228 if(!Process_##instr()) return FALSE; break;
00229 #define NEEDLAYER {if(Data->pCurrentLayer == NULL) {TRACEUSER( "Ben", _T("no layer\n")); \
00230 CMXFORMATERROR(FALSE)}}
00231
00232 BOOL CMXImportFilter::ProcessCommand(INT32 *ProgressThingy)
00233 {
00234
00235 INT32 CommandEndFilePos = Tell();
00236
00237
00238 CI_READDATA(CommandHeader, ch)
00239
00240
00241 if(ch.Code < 0 && !Is32Bit)
00242 ch.Code = 0 - ch.Code;
00243
00244 CommandEndFilePos += ch.Size;
00245
00246
00247 switch(ch.Code)
00248 {
00249 PC_DISPATCH(BeginPage)
00250 PC_DISPATCH(EndPage)
00251 PC_DISPATCH(BeginLayer)
00252 PC_DISPATCH(EndLayer)
00253 PC_DISPATCH(BeginGroup)
00254 PC_DISPATCH(EndGroup)
00255 PC_DISPATCH(EndSection)
00256 PC_DISPATCH(PolyCurve)
00257 PC_DISPATCH(Rectangle)
00258 PC_DISPATCH(AddGlobalTransform)
00259 PC_DISPATCH(SetGlobalTransform)
00260 PC_DISPATCH(RestoreLastGlobalTransform)
00261 PC_DISPATCH(DrawImage)
00262 PC_DISPATCH(AddClippingRegion)
00263 PC_DISPATCH(RemoveLastClippingRegion)
00264 PC_DISPATCH(ClearClipping)
00265 PC_DISPATCH(BeginTextStream)
00266 PC_DISPATCH(TextFrame)
00267 PC_DISPATCH(Characters)
00268 PC_DISPATCH(CharInfo)
00269 PC_DISPATCH(BeginParagraph)
00270 PC_DISPATCH(EndParagraph)
00271 PC_DISPATCH(EndTextStream)
00272
00273
00274 case cmxINSTR_JumpAbsolute:
00275 {
00276 CI_READDATA(JumpAbsolute, ja)
00277 TRACEUSER( "Ben", _T(" * JumpAbsolute to %d\n"), ja.Offset);
00278 TRACEUSER( "Claude", _T(" * JumpAbsolute to %d\n"), ja.Offset);
00279
00280
00281
00282 CommandEndFilePos = ja.Offset;
00283
00284 if(ProgressThingy != NULL)
00285 (*ProgressThingy)--;
00286 }
00287 break;
00288
00289 default:
00290
00291 TRACEUSER( "Ben", _T(" * <<unknown command>>\n"));
00292 TRACEUSER( "Claude", _T(" * <<unknown command>>\n"));
00293 TRACEUSER( "Graeme", _T(" * <<unknown command>>\n"));
00294 break;
00295 }
00296
00297
00298 if(Tell() != CommandEndFilePos)
00299 Seek(CommandEndFilePos);
00300
00301 return TRUE;
00302 }
00303
00304
00305
00306
00307
00308
00309
00310
00311
00312
00313
00314
00315
00316 BOOL CMXImportFilter::Process_EndPage(void)
00317 {
00318
00319
00320 Data->InPage = FALSE;
00321
00322 return TRUE;
00323 }
00324
00325
00326
00327
00328
00329
00330
00331
00332
00333
00334
00335
00336
00337
00338 BOOL CMXImportFilter::Process_BeginPage(void)
00339 {
00340
00341 CI_READDATA(BeginPage, bp)
00342
00343
00344 Data->CommandsInPage = bp.InstructionCount;
00345 if(Data->pProgress != NULL)
00346 {
00347 delete Data->pProgress;
00348 Data->pProgress = NULL;
00349 }
00350 Data->pProgress = new Progress(_R(IDT_CMX_IMPORTMSG), Data->CommandsInPage, FALSE);
00351 if(Data->pProgress == NULL)
00352 return FALSE;
00353
00354 return TRUE;
00355 }
00356
00357
00358
00359
00360
00361
00362
00363
00364
00365
00366
00367
00368
00369
00370 BOOL CMXImportFilter::Process_EndLayer(void)
00371 {
00372 if(Data->pCurrentLayer == NULL)
00373 CMXFORMATERROR(FALSE)
00374
00375
00376 Data->pCurrentLayer = NULL;
00377
00378 return TRUE;
00379 }
00380
00381
00382
00383
00384
00385
00386
00387
00388
00389
00390
00391
00392
00393
00394 BOOL CMXImportFilter::Process_BeginLayer(void)
00395 {
00396 if(Data->pCurrentLayer != NULL)
00397 CMXFORMATERROR(FALSE)
00398
00399
00400 CI_READDATA(BeginLayer, bl)
00401 TRACEUSER( "Ben", _T(" layer name = %s\n"), (TCHAR *)(*bl.pLayerName));
00402
00403
00404 Data->pCurrentLayer = new CMXImportLayer;
00405 if(Data->pCurrentLayer == NULL)
00406 return FALSE;
00407
00408
00409 Data->Layers.AddTail(Data->pCurrentLayer);
00410
00411
00412 Data->pCurrentLayer->SetName(bl.pLayerName);
00413
00414
00415 delete bl.pLayerName;
00416
00417 return TRUE;
00418 }
00419
00420
00421
00422
00423
00424
00425
00426
00427
00428
00429
00430
00431
00432
00433 BOOL CMXImportFilter::Process_BeginGroup(void)
00434 {
00435 NEEDLAYER
00436
00437 if(!Data->pCurrentLayer->StartGroup())
00438 return FALSE;
00439
00440 return TRUE;
00441 }
00442
00443
00444
00445
00446
00447
00448
00449
00450
00451
00452
00453
00454
00455
00456 BOOL CMXImportFilter::Process_EndGroup(void)
00457 {
00458 NEEDLAYER
00459
00460 if(!Data->pCurrentLayer->EndGroup())
00461 return FALSE;
00462
00463 return TRUE;
00464 }
00465
00466
00467
00468
00469
00470
00471
00472
00473
00474
00475
00476
00477
00478
00479 BOOL CMXImportFilter::Process_PolyCurve(void)
00480 {
00481 NEEDLAYER
00482
00483
00484 CI_READDATA(PolyCurve, pc)
00485
00486
00487
00488
00489 if((pc.RenderAttributes.Mask & cmxRENDATTRMASK_CONTAIN) != 0)
00490 {
00491 if(!Process_PolyCurveContainer(pc))
00492 return FALSE;
00493 }
00494
00495
00496 NodePath *pPNode = new NodePath;
00497 if(pPNode == NULL || !pPNode->SetUpPath(pc.PointList->GetNumCoords() + 4))
00498 return FALSE;
00499
00500 if(!pPNode->InkPath.CloneFrom(*pc.PointList))
00501 return FALSE;
00502
00503 pPNode->InkPath.IsFilled = pc.PointList->IsFilled;
00504 pPNode->InkPath.IsStroked = pc.PointList->IsStroked;
00505
00506 if(!pPNode->InkPath.EnsureValid())
00507 return FALSE;
00508
00509 Node *pNode = pPNode;
00510
00511
00512 if(!TransformNode(pNode)
00513 || !SetAttributesForNode(pNode, &pc.RenderAttributes)
00514 || !ClipNode(&pNode)
00515 || !ApplyAttributesToNode(pNode))
00516 return FALSE;
00517
00518
00519 Data->pCurrentLayer->AddNode(pNode);
00520
00521
00522 delete pc.PointList;
00523
00524 return TRUE;
00525 }
00526
00527
00528
00529
00530
00531
00532
00533
00534
00535
00536
00537
00538
00539 BOOL CMXImportFilter::Process_PolyCurveContainer(cmxiPolyCurve &pc)
00540 {
00541
00542
00543
00544
00545 if(pc.RenderAttributes.ContainerSpec.ContainerReference <= 0
00546 || pc.RenderAttributes.ContainerSpec.ContainerReference > Data->NumProcedures)
00547 CMXFORMATERROR(FALSE)
00548
00549
00550 INT32 Position = Data->Procedures[pc.RenderAttributes.ContainerSpec.ContainerReference-1].Position;
00551 if(Position <= 0)
00552 CMXFORMATERROR(FALSE)
00553
00554
00555 INT32 StartFilePos = Tell();
00556
00557
00558 Seek(Position);
00559
00560
00561 RIFFck hdr;
00562 pFile->read(&hdr, sizeof(hdr));
00563
00564
00565 BOOL EndProcLoc = Tell() + hdr.ckSize;
00566
00567
00568 Path *pClipPath = new Path;
00569 if(pClipPath == NULL || !pClipPath->Initialise())
00570 return FALSE;
00571 pClipPath->CloneFrom(*pc.PointList);
00572 CMXImportClipper *pClipper = new CMXImportClipper(pClipPath, TRUE);
00573 if(pClipper == NULL)
00574 return FALSE;
00575 Data->ClipperStack.Push(pClipper);
00576
00577
00578 TRACEUSER( "Ben", _T("processing commands in container procedure:\n"));
00579 BOOL InProc = TRUE;
00580 Data->EndSectionFound = FALSE;
00581 while(InProc == TRUE)
00582 {
00583
00584 if(!ProcessCommand())
00585 return FALSE;
00586
00587 if(Data->EndSectionFound == TRUE)
00588 InProc = FALSE;
00589
00590
00591 if(Tell() >= EndProcLoc)
00592 InProc = FALSE;
00593 }
00594 TRACEUSER( "Ben", _T("finished processing commands in procedure\n"));
00595
00596
00597 Seek(StartFilePos);
00598
00599
00600 delete Data->ClipperStack.Pop();
00601
00602 return TRUE;
00603 }
00604
00605
00606
00607
00608
00609
00610
00611
00612
00613
00614
00615
00616
00617 BOOL CMXImportFilter::Process_Rectangle ( void )
00618 {
00619 NodeRegularShape *pRectangle = NULL;
00620 Matrix RectMatrix;
00621 DocCoord MajorAxis ( 0, 0 );
00622 DocCoord MinorAxis ( 0, 0 );
00623 double RootTwo = sqrt ( 2 );
00624 FIXED16 RotateCos;
00625 FIXED16 RotateSin;
00626
00627
00628 NEEDLAYER
00629
00630
00631 CI_READDATA ( Rectangle, Rect )
00632
00633
00634 if ( ( pRectangle = new NodeRegularShape () ) == NULL )
00635 return FALSE;
00636
00637
00638
00639
00640 MajorAxis.y = ( INT32 ) ( ( double ) ( Rect.Height / 2 ) * RootTwo );
00641 MinorAxis.x = ( INT32 ) ( ( double ) ( Rect.Width / 2 ) * RootTwo );
00642
00643
00644 RotateSin = sin ( Rect.Rotation );
00645 RotateCos = cos ( Rect.Rotation );
00646
00647
00648 RectMatrix.Compose ( RotateCos, RotateCos, -RotateSin, RotateSin, Rect.Centre );
00649
00650 pRectangle->SetUpShape ();
00651 pRectangle->SetNumSides ( 4 );
00652 pRectangle->SetTransformMatrix ( &RectMatrix );
00653 pRectangle->SetCentrePoint ( DocCoord (0, 0) );
00654 pRectangle->SetMajorAxes ( MajorAxis );
00655 pRectangle->SetMinorAxes ( MinorAxis );
00656
00657
00658 if ( !TransformNode ( pRectangle ) ||
00659 !SetAttributesForNode ( pRectangle, &Rect.RenderAttributes ) ||
00660 !ClipNode ( ( Node ** ) &pRectangle ) ||
00661 !ApplyAttributesToNode ( pRectangle ) )
00662 {
00663
00664 return FALSE;
00665 }
00666
00667
00668 Data->pCurrentLayer->AddNode( pRectangle );
00669
00670 return TRUE;
00671 }
00672
00673
00674
00675
00676
00677
00678
00679
00680
00681
00682
00683
00684
00685 BOOL CMXImportFilter::Process_AddGlobalTransform(void)
00686 {
00687
00688 CI_READDATA(AddGlobalTransform, gt)
00689
00690
00691 CMXImportTransform *pNewTrans = new CMXImportTransform(>.TransformMatrix, TRUE);
00692 if(pNewTrans == NULL)
00693 return FALSE;
00694
00695
00696 Data->TransformStack.Push(pNewTrans);
00697
00698 return TRUE;
00699 }
00700
00701
00702
00703
00704
00705
00706
00707
00708
00709
00710
00711
00712
00713
00714 BOOL CMXImportFilter::Process_SetGlobalTransform(void)
00715 {
00716
00717 CI_READDATA(SetGlobalTransform, gt)
00718
00719
00720 CMXImportTransform *pNewTrans = new CMXImportTransform(>.TransformMatrix, FALSE);
00721 if(pNewTrans == NULL)
00722 return FALSE;
00723
00724
00725 Data->TransformStack.Push(pNewTrans);
00726
00727 return TRUE;
00728 }
00729
00730
00731
00732
00733
00734
00735
00736
00737
00738
00739
00740
00741
00742
00743 BOOL CMXImportFilter::Process_RestoreLastGlobalTransform(void)
00744 {
00745
00746
00747 delete Data->TransformStack.Pop();
00748
00749 return TRUE;
00750 }
00751
00752
00753
00754
00755
00756
00757
00758
00759
00760
00761
00762
00763
00764
00765 BOOL CMXImportFilter::Process_DrawImage(void)
00766 {
00767 NEEDLAYER
00768
00769
00770 CI_READDATA(DrawImage, db)
00771
00772
00773 if(db.ImageType != cmxDRAWIMAGE_IMAGETYPE_COLOUR)
00774 return TRUE;
00775
00776
00777
00778 if(db.ImageExtent != db.CroppingRectangle)
00779 return Process_DrawImage_Cropped(db);
00780
00781
00782 INT32 Ref = db.ImageFileReference1 - 1;
00783 if(!Data->RImages[Ref].IsRImage())
00784 return TRUE;
00785 KernelBitmap *pBitmap = Data->RImages[Ref].GetBitmap(this);
00786 if(pBitmap == 0)
00787 return FALSE;
00788
00789
00790 NodeBitmap *NewBitmap = new NodeBitmap;
00791
00792 if((NewBitmap == NULL) || !NewBitmap->SetUpPath())
00793 return FALSE;
00794
00795 NewBitmap->CreateShape(db.ImageExtent);
00796
00797
00798 Trans2DMatrix Transform(db.Transformation);
00799 NewBitmap->Transform(Transform);
00800
00801
00802 NewBitmap->GetBitmapRef()->Attach(pBitmap, GetDocument());
00803 if (NewBitmap->GetBitmap() != pBitmap)
00804 {
00805
00806 delete pBitmap;
00807 }
00808
00809
00810 NewBitmap->ApplyDefaultBitmapAttrs(0);
00811
00812
00813 NewBitmap->InvalidateBoundingRect();
00814
00815
00816 Node *pNode = NewBitmap;
00817 if(!TransformNode(pNode)
00818 || !ClipNode(&pNode))
00819 return FALSE;
00820
00821
00822 Data->pCurrentLayer->AddNode(pNode);
00823
00824 return TRUE;
00825 }
00826
00827
00828
00829
00830
00831
00832
00833
00834
00835
00836
00837
00838
00839
00840 #define BITM_MOVE(px, py) {co.x = (px); co.y = (py); if(!pPath->InkPath.InsertMoveTo(co)) return FALSE;}
00841 #define BITM_LINE(px, py) {co.x = (px); co.y = (py); if(!pPath->InkPath.InsertLineTo(co)) return FALSE;}
00842 #define BITM_CLOSE {if(!pPath->InkPath.CloseSubPath()) return FALSE;}
00843
00844 BOOL CMXImportFilter::Process_DrawImage_Cropped(cmxiDrawImage &db)
00845 {
00846
00847 INT32 Ref = db.ImageFileReference1 - 1;
00848 if(!Data->RImages[Ref].IsRImage())
00849 return TRUE;
00850 KernelBitmap *pBitmap = Data->RImages[Ref].GetBitmap(this);
00851 if(pBitmap == 0)
00852 return FALSE;
00853
00854
00855
00856 NodePath *pPath = new NodePath;
00857 if(pPath == 0 || (!pPath->SetUpPath()))
00858 {
00859 delete pPath;
00860 return FALSE;
00861 }
00862
00863
00864 pPath->InkPath.FindStartOfPath();
00865
00866 DocCoord co, cn1, cn2;
00867
00868
00869 BITM_MOVE(db.CroppingRectangle.lo.x, db.CroppingRectangle.lo.y)
00870 BITM_LINE(db.CroppingRectangle.hi.x, db.CroppingRectangle.lo.y)
00871 BITM_LINE(db.CroppingRectangle.hi.x, db.CroppingRectangle.hi.y)
00872 BITM_LINE(db.CroppingRectangle.lo.x, db.CroppingRectangle.hi.y)
00873 BITM_LINE(db.CroppingRectangle.lo.x, db.CroppingRectangle.lo.y)
00874 BITM_CLOSE
00875
00876
00877 pPath->InvalidateBoundingRect();
00878 pPath->InkPath.IsFilled = TRUE;
00879
00880
00881 Data->ObjFilled = TRUE;
00882
00883
00884 if(!SetLineColour(DocColour(COLOUR_TRANS)))
00885 return FALSE;
00886
00887
00888 DocCoord Start = DocCoord(db.ImageExtent.lo.x, db.ImageExtent.lo.y);
00889 DocCoord End1 = DocCoord(db.ImageExtent.hi.x, db.ImageExtent.lo.y);
00890 DocCoord End2 = DocCoord(db.ImageExtent.lo.x, db.ImageExtent.hi.y);
00891 if(!SetBitmapFill(pBitmap, Start, End1, End2))
00892 return FALSE;
00893
00894
00895 SetPathFilled(TRUE);
00896 CurrentAttrs[ATTR_FILLGEOMETRY].Ignore = FALSE;
00897 if(!AttributeManager::ApplyBasedOnDefaults(pPath, CurrentAttrs))
00898 return FALSE;
00899
00900
00901 Trans2DMatrix Transform(db.Transformation);
00902 pPath->Transform(Transform);
00903
00904
00905 Node *pNode = pPath;
00906 if(!TransformNode(pNode)
00907 || !ClipNode(&pNode))
00908 return FALSE;
00909
00910
00911 Data->pCurrentLayer->AddNode(pNode);
00912
00913 return TRUE;
00914 }
00915
00916
00917
00918
00919
00920
00921
00922
00923
00924
00925
00926
00927
00928
00929 BOOL CMXImportFilter::Process_AddClippingRegion(void)
00930 {
00931 CI_READDATA(AddClippingRegion, cr)
00932
00933
00934 switch(cr.RegionType)
00935 {
00936 case cmxADDCLIPREGION_TYPE_NONE:
00937 return TRUE;
00938 break;
00939
00940 case cmxADDCLIPREGION_TYPE_POLYGON:
00941 break;
00942
00943 default:
00944 TRACEUSER( "Neville", _T("---- thingy. type of clipping region not supported\n"));
00945
00946
00947
00948 return TRUE;
00949 break;
00950 }
00951
00952
00953 BOOL Intersect = TRUE;
00954 if(cr.ClipMode == cmxADDCLIPREGIOM_MODE_COPY)
00955 Intersect = FALSE;
00956
00957
00958 CMXImportClipper *pClipper = new CMXImportClipper(cr.Spec.pPolygon, Intersect);
00959 if(pClipper == NULL)
00960 return FALSE;
00961
00962
00963 if(!Data->ClipperStack.Push(pClipper))
00964 return FALSE;
00965
00966 return TRUE;
00967 }
00968
00969
00970
00971
00972
00973
00974
00975
00976
00977
00978
00979
00980
00981
00982 BOOL CMXImportFilter::Process_RemoveLastClippingRegion(void)
00983 {
00984
00985 if(Data->ClipperStack.GetCount() > 0)
00986 delete Data->ClipperStack.Pop();
00987
00988 return TRUE;
00989 }
00990
00991
00992
00993
00994
00995
00996
00997
00998
00999
01000
01001
01002
01003
01004 BOOL CMXImportFilter::Process_ClearClipping(void)
01005 {
01006
01007 while(Data->ClipperStack.GetCount() != 0)
01008 {
01009 delete Data->ClipperStack.Pop();
01010 }
01011
01012 return TRUE;
01013 }
01014
01015
01016
01017
01018
01019
01020
01021
01022
01023
01024
01025
01026
01027 BOOL CMXImportFilter::Process_EndSection(void)
01028 {
01029 Data->EndSectionFound = TRUE;
01030
01031 return TRUE;
01032 }
01033
01034
01035
01036
01037
01038
01039
01040
01041
01042
01043
01044
01045
01046
01047
01048
01049
01050
01051
01052
01053
01054
01055
01056
01057
01058
01059
01060
01061
01062
01063
01064
01065 BOOL CMXImportFilter::Process_BeginTextStream(void)
01066 {
01067 CI_READDATA(BeginTextStream, text)
01068 TRACEUSER( "Claude", _T("BeginTextStream"));
01069
01070
01071 DocCoord Pos = text.BBox.hi;
01072
01073
01074 Data->pTextStory = TextStory::CreateTextObject(Pos);
01075
01076
01077 return TRUE;
01078 }
01079
01080
01081
01082
01083
01084
01085
01086
01087
01088
01089
01090
01091
01092
01093 BOOL CMXImportFilter::Process_TextFrame(void)
01094 {
01095 TRACEUSER( "Claude", _T("TextFrame"));
01096
01097 CI_READDATA(TextFrame, textf)
01098
01099
01100
01101 Data->TextFrameRead = TRUE;
01102
01103 INT32 TextWidth = 70000;
01104
01105 for(INT32 i = 0 ; i < textf.columns.count ; i++)
01106 {
01107 TextWidth += textf.columns.columns[i];
01108 TextWidth += textf.columns.gutters[i];
01109 }
01110
01111
01112
01113 Data->pTextStory->SetImportFormatWidth((INT32)(TextWidth * Data->BaseScaleFactor));
01114
01115
01116 Data->pTextStory->SetStoryMatrix(textf.Mat);
01117
01118
01119
01120 delete textf.columns.columns;
01121 delete textf.columns.gutters;
01122
01123 return TRUE;
01124 }
01125
01126
01127
01128
01129
01130
01131
01132
01133
01134
01135
01136
01137
01138
01139 BOOL CMXImportFilter::Process_Characters(void)
01140 {
01141
01142 CI_READDATA(Characters, fabbyChars)
01143
01144
01145 Data->pTextLine = Data->pTextStory->FindLastLine();
01146 SetNonTextAttributeIgnore();
01147 if (!AttributeManager::ApplyBasedOnDefaults(Data->pTextLine, CurrentAttrs))
01148 {
01149 delete Data->pTextLine;
01150 Data->pTextLine = NULL;
01151 }
01152 SetNonTextAttributeNotIgnore();
01153
01154 for(INT32 i = 0 ; i < fabbyChars.ch.count ; i++)
01155 {
01156
01157 BOOL Ignore = FALSE;
01158 TRACEUSER( "Claude", _T("Character %d is %c\n"), i, fabbyChars.ch.characters[i]);
01159
01160 if(fabbyChars.ch.characters[i] < 32)
01161 {
01162 if(fabbyChars.ch.characters[i] == 13)
01163 {
01164
01165
01166 Data->pTextLine = TextLine::CreateEmptyTextLine(Data->pTextStory, LASTCHILD);
01167 SetNonTextAttributeIgnore();
01168 if (!AttributeManager::ApplyBasedOnDefaults(Data->pTextLine, CurrentAttrs))
01169 {
01170 delete Data->pTextLine;
01171 Data->pTextLine = NULL;
01172 }
01173 SetNonTextAttributeNotIgnore();
01174 Ignore = TRUE;
01175 }
01176 else
01177 if(fabbyChars.ch.characters[i] == 9)
01178 fabbyChars.ch.characters[i] = 32;
01179 else
01180
01181 Ignore = TRUE;
01182 }
01183
01184 if(!Ignore)
01185 {
01186
01187 VisibleTextNode* pLastNode = Data->pTextLine->FindLastVTN();
01188 ERROR2IF(pLastNode == NULL, NULL, "Empty Story");
01189
01190 VisibleTextNode* pNew = new TextChar(pLastNode, PREV, fabbyChars.ch.characters[i]);
01191 if (pNew != NULL)
01192 {
01193
01194
01195
01196
01197 INT32 UMASK = 0;
01198
01199 if(!CorelDraw7)
01200 {
01201 if(Data->NumCharInfo != 0)
01202 UMASK = Data->CharInfos[fabbyChars.ch.indices[i]].UsageMask;
01203 }
01204 else
01205 {
01206 if(fabbyChars.ch.indices[i] != cmxMaxValueWORD)
01207 UMASK = Data->CharInfos[fabbyChars.ch.indices[i]].UsageMask;
01208 }
01209
01210 if(((UMASK & cmxUSAGEMASK_UseTypeNum) != 0) ||
01211 ((UMASK & cmxUSAGEMASK_UseTypeStyle) != 0))
01212
01213 {
01214 INT32 fontRef = Data->CharInfos[fabbyChars.ch.indices[i]].FontRef-1;
01215 String_64 name((TCHAR*)*Data->Fonts[fontRef].mFont);
01216
01217 SetTextTypeFace(&name);
01218
01219 SetTextItalic(Data->Fonts[fontRef].mIsItalic);
01220 SetTextBold(Data->Fonts[fontRef].mIsBold);
01221 }
01222
01223 if((UMASK & cmxUSAGEMASK_UseTypeSize) != 0)
01224
01225 SetTextSize(Data->CharInfos[fabbyChars.ch.indices[i]].TypeSize);
01226
01227 if(((UMASK & cmxUSAGEMASK_UseCharFill) != 0) ||
01228 ((UMASK & cmxUSAGEMASK_UseCharOutline) != 0))
01229
01230 SetAttributesForNode(pNew, &Data->CharInfos[fabbyChars.ch.indices[i]].RenderAttributes, FALSE);
01231 else
01232
01233 SetAttributesForNode(pNew, &Data->textRenderAttributes, FALSE);
01234
01235
01236
01237 if (!AttributeManager::ApplyBasedOnDefaults(pNew, CurrentAttrs))
01238 {
01239 delete pNew;
01240 pNew = NULL;
01241 }
01242
01243
01244
01245 String_64 name((TCHAR*)*Data->Fonts[Data->currentRef].mFont);
01246
01247 SetTextTypeFace(&name);
01248
01249 SetTextItalic(Data->Fonts[Data->currentRef].mIsItalic);
01250 SetTextBold(Data->Fonts[Data->currentRef].mIsBold);
01251 SetTextSize(Data->currentSize);
01252
01253 }
01254
01255 }
01256 }
01257
01258
01259
01260 delete fabbyChars.ch.characters;
01261 delete fabbyChars.ch.indices;
01262
01263 return TRUE;
01264 }
01265
01266
01267
01268
01269
01270
01271
01272
01273
01274
01275
01276
01277
01278 BOOL CMXImportFilter::Process_CharInfo(void)
01279 {
01280 CI_READDATA(CharInfo, ci)
01281
01282
01283 Data->NumCharInfo++;
01284 Data->CharInfos[Data->NumCharInfo-1].UsageMask = ci.UsageMask;
01285 Data->CharInfos[Data->NumCharInfo-1].FontRef = ci.FontRef;
01286 Data->CharInfos[Data->NumCharInfo-1].TypeSize = ci.TypeSize;
01287 Data->CharInfos[Data->NumCharInfo-1].CharAngle = ci.CharAngle;
01288 Data->CharInfos[Data->NumCharInfo-1].RenderAttributes = ci.RenderAttributes;
01289 Data->CharInfos[Data->NumCharInfo-1].HShift = ci.HShift;
01290 Data->CharInfos[Data->NumCharInfo-1].VShift = ci.VShift;
01291
01292 return TRUE;
01293 }
01294
01295
01296
01297
01298
01299
01300
01301
01302
01303
01304
01305
01306
01307
01308
01309
01310 BOOL CMXImportFilter::Process_BeginParagraph(void)
01311 {
01312 SetTextAttributeNotIgnore();
01313
01314 CI_READDATA(BeginParagraph, Paragraph)
01315
01316
01317 Data->currentRef = Paragraph.FontRef-1;
01318
01319 Data->currentSize = Paragraph.FontSize;
01320
01321
01322 String_64 name((TCHAR*)*Data->Fonts[Paragraph.FontRef-1].mFont);
01323 SetTextTypeFace(&name);
01324
01325
01326 SetTextItalic(Data->Fonts[Paragraph.FontRef-1].mIsItalic);
01327 SetTextBold(Data->Fonts[Paragraph.FontRef-1].mIsBold);
01328 SetTextSize(Paragraph.FontSize);
01329
01330 switch(Paragraph.Justification)
01331 {
01332
01333 case cmxNoAlignment:
01334
01335 Data->textJustification = JLEFT;
01336 break;
01337 case cmxLeftJustification:
01338 Data->textJustification = JLEFT;
01339 break;
01340 case cmxCenterJustification:
01341 Data->textJustification = JCENTRE;
01342 break;
01343 case cmxRightJustification:
01344 Data->textJustification = JRIGHT;
01345 break;
01346 case cmxFullJustification:
01347 Data->textJustification = JFULL;
01348 break;
01349 case cmxForceJustification:
01350 Data->textJustification = JFULL;
01351 break;
01352 default:
01353 break;
01354 }
01355
01356 SetTextJustification(Data->textJustification);
01357
01358
01359
01360
01361 Data->pTextStory->SetLeftIndent((INT32)(Paragraph.LeftMargin * Data->BaseScaleFactor));
01362 Data->pTextStory->SetRightIndent((INT32)(Paragraph.RightMargin * Data->BaseScaleFactor));
01363
01364
01365
01366 Data->textRenderAttributes = Paragraph.RenderAttributes;
01367
01368 return TRUE;
01369 }
01370
01371
01372
01373
01374
01375
01376
01377
01378
01379
01380
01381
01382
01383
01384 BOOL CMXImportFilter::Process_EndParagraph(void)
01385 {
01386
01387 SetTextAttributeIgnore();
01388
01389 return TRUE;
01390 }
01391
01392
01393
01394
01395
01396
01397
01398
01399
01400
01401
01402
01403
01404
01405 BOOL CMXImportFilter::Process_EndTextStream(void)
01406 {
01407
01408 Data->TextFrameRead = FALSE;
01409
01410 Node *pNode = Data->pTextStory;
01411
01412 if( !TransformNode(pNode) ||
01413 !ClipNode(&pNode))
01414
01415 return FALSE;
01416
01417
01418 Data->pCurrentLayer->AddNode(pNode);
01419
01420 return TRUE;
01421 }