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 #include "camtypes.h"
00102 #include "metafilt.h"
00103
00104
00105
00106
00107
00108 #include "gdimagic.h"
00109
00110 #include "camelot.h"
00111 #include "nodepath.h"
00112
00113 #include "oilfiles.h"
00114 #include "csrstack.h"
00115 #include "progress.h"
00116 #include "page.h"
00117
00118
00119
00120
00121
00122
00123
00124
00125
00126 #include "layer.h"
00127 #include "osrndrgn.h"
00128 #include "camvw.h"
00129 #include "wbitmap.h"
00130
00131 #include "nodebmp.h"
00132 #include "nodetxts.h"
00133 #include "nodeelip.h"
00134
00135 #include "clipext.h"
00136
00137 #include "metaview.h"
00138
00139
00140 CC_IMPLEMENT_DYNCREATE(MetaFileClipMap, ClipboardMapping)
00141
00142
00143
00144
00145
00146
00147
00148 typedef short INT16;
00149 typedef WORD UINT16;
00150
00151 #ifdef _MSC_VER
00152
00153
00154 #pragma pack(push, 1)
00155
00156 typedef struct
00157 {
00158 INT16 lbStyle;
00159 COLORREF lbColor;
00160 INT16 lbHatch;
00161 } LOGBRUSH_16;
00162
00163 typedef struct
00164 {
00165 INT16 x;
00166 INT16 y;
00167 } POINT_16;
00168
00169 typedef struct
00170 {
00171 INT16 lopnStyle;
00172 POINT_16 lopnWidth;
00173 COLORREF lopnColor;
00174 } LOGPEN_16;
00175
00176 typedef struct
00177 {
00178 BYTE peRed;
00179 BYTE peGreen;
00180 BYTE peBlue;
00181 BYTE peFlags;
00182 } PALETTEENTRY_16;
00183
00184 typedef struct
00185 {
00186 WORD palVersion;
00187 WORD palNumEntries;
00188 PALETTEENTRY_16 palPalEntry[1];
00189 } LOGPALETTE_16;
00190
00191 #pragma pack(pop)
00192 #else
00193 #error Dont know how to pack structures with this compiler!
00194 #endif // _MSC_VER
00195
00196
00197
00198
00199
00200
00201
00202
00203
00204
00205
00206 typedef enum
00207 {
00208 HANDLE_NONE,
00209 HANDLE_PEN,
00210 HANDLE_BRUSH,
00211 HANDLE_PALETTE,
00212 HANDLE_PATTERNBRUSH,
00213 HANDLE_FONTINDIRECT,
00214 HANDLE_REGION
00215 } HandleType;
00216
00217
00218
00219
00220
00221
00222
00223
00224
00225
00226
00227
00228
00229
00230
00231 class HandleRecord
00232 {
00233 public:
00234 HandleType Type;
00235 DocColour Colour;
00236 MILLIPOINT PenWidth;
00237 LOGFONT_16* pFont;
00238 };
00239
00240
00241
00242
00243
00244
00245
00246
00247
00248
00249
00250
00251
00252
00253
00254
00255
00256
00257
00258
00259
00260 class HandleTable
00261 {
00262 public:
00263 HandleTable(MetaFileFilter *);
00264 ~HandleTable();
00265
00266
00267 BOOL CreatePen(LOGPEN_16 *);
00268 BOOL CreateBrush(LOGBRUSH_16 *);
00269 BOOL CreatePalette(LOGPALETTE_16 *);
00270 BOOL CreatePatternBrush(WORD*);
00271 BOOL CreateFontIndirect(LOGFONT_16*);
00272 BOOL CreateRegion(WORD*);
00273
00274
00275 BOOL SelectObject(INT32 Index);
00276 BOOL DeleteObject(INT32 Index);
00277
00278 private:
00279 INT32 FindFreeSlot();
00280
00281
00282 MetaFileFilter *Context;
00283
00284
00285 HandleRecord *Handles;
00286
00287
00288 INT32 TableSize;
00289 };
00290
00291
00292
00293
00294
00295
00296
00297
00298
00299
00300
00301
00302 HandleTable::HandleTable(MetaFileFilter *pFilter)
00303 {
00304 Handles = NULL;
00305 TableSize = 0;
00306 Context = pFilter;
00307 }
00308
00309
00310
00311
00312
00313
00314
00315
00316
00317
00318
00319
00320 HandleTable::~HandleTable()
00321 {
00322 CCFree(Handles);
00323 Handles = NULL;
00324 TableSize = 0;
00325 }
00326
00327
00328
00329
00330
00331 static const INT32 TableGranularity = 10;
00332
00333
00334 static const INT32 BAD_SLOT = -1;
00335
00336
00337
00338
00339
00340
00341
00342
00343
00344
00345
00346
00347
00348
00349
00350
00351
00352
00353
00354 INT32 HandleTable::FindFreeSlot()
00355 {
00356 INT32 Slot;
00357
00358
00359 for (Slot = 0; Slot < TableSize; Slot++)
00360 {
00361 if (Handles[Slot].Type == HANDLE_NONE)
00362 return Slot;
00363 }
00364
00365
00366
00367 INT32 NewTableSize = TableSize + TableGranularity;
00368
00369
00370 HandleRecord *NewHandles;
00371 if (Handles == NULL)
00372 NewHandles = (HandleRecord *) CCMalloc(NewTableSize * sizeof(HandleRecord));
00373 else
00374 NewHandles = (HandleRecord *) CCRealloc(Handles, NewTableSize * sizeof(HandleRecord));
00375
00376
00377 if (NewHandles == NULL)
00378 {
00379
00380 return BAD_SLOT;
00381 }
00382
00383
00384 for (Slot = TableSize; Slot < NewTableSize; Slot++)
00385 {
00386 NewHandles[Slot].Type = HANDLE_NONE;
00387
00388
00389
00390
00391
00392
00393 new(&NewHandles[Slot].Colour) DocColour;
00394 }
00395
00396
00397 Slot = TableSize;
00398
00399
00400 Handles = NewHandles;
00401 TableSize = NewTableSize;
00402
00403
00404 return Slot;
00405 }
00406
00407
00408
00409
00410
00411
00412
00413
00414
00415
00416
00417
00418
00419
00420
00421
00422 BOOL HandleTable::CreatePen(LOGPEN_16 *pPen)
00423 {
00424 INT32 Style = pPen->lopnStyle;
00425 COLORREF Col = (COLORREF) pPen->lopnColor;
00426
00427
00428 INT32 Slot = FindFreeSlot();
00429
00430 if (Slot == BAD_SLOT)
00431
00432 return FALSE;
00433
00434 Handles[Slot].Type = HANDLE_PEN;
00435
00436 switch (Style)
00437 {
00438 case PS_SOLID:
00439 case PS_INSIDEFRAME:
00440 Handles[Slot].Colour = DocColour(GetRValue(Col), GetGValue(Col), GetBValue(Col));
00441 break;
00442
00443 case PS_NULL:
00444 Handles[Slot].Colour = DocColour(COLOUR_TRANS);
00445 break;
00446
00447 default:
00448 ENSURE(FALSE, "Unknown pen style in metafile!");
00449 ERROR(_R(IDT_BAD_METAFILE), FALSE);
00450 }
00451
00452
00453 DocCoord PenSize(pPen->lopnWidth.x, 0);
00454 Context->ScaleCoord(&PenSize);
00455 Handles[Slot].PenWidth = PenSize.x;
00456
00457
00458 return TRUE;
00459 }
00460
00461
00462
00463
00464
00465
00466
00467
00468
00469
00470
00471
00472
00473
00474
00475
00476
00477 BOOL HandleTable::CreateBrush(LOGBRUSH_16 *pBrush)
00478 {
00479 INT32 Style = pBrush->lbStyle;
00480 COLORREF Col = (COLORREF) pBrush->lbColor;
00481
00482
00483 INT32 Slot = FindFreeSlot();
00484
00485 if (Slot == BAD_SLOT)
00486
00487 return FALSE;
00488
00489 Handles[Slot].Type = HANDLE_BRUSH;
00490
00491 switch (Style)
00492 {
00493 case BS_SOLID:
00494 Handles[Slot].Colour = DocColour(GetRValue(Col), GetGValue(Col), GetBValue(Col));
00495 break;
00496
00497 case BS_NULL:
00498 Handles[Slot].Colour = DocColour(COLOUR_TRANS);
00499 break;
00500
00501 default:
00502 ENSURE(FALSE, "Unknown brush style in metafile!");
00503 ERROR(_R(IDT_BAD_METAFILE), FALSE);
00504 }
00505
00506
00507 return TRUE;
00508 }
00509
00510
00511
00512
00513
00514
00515
00516
00517
00518
00519
00520
00521 BOOL HandleTable::CreatePalette(LOGPALETTE_16 *)
00522 {
00523
00524 INT32 Slot = FindFreeSlot();
00525
00526
00527 if (Slot == BAD_SLOT)
00528 return FALSE;
00529
00530
00531 Handles[Slot].Type = HANDLE_PALETTE;
00532
00533
00534 return TRUE;
00535 }
00536
00537
00538
00539
00540
00541
00542
00543
00544
00545
00546
00547
00548 BOOL HandleTable::CreatePatternBrush(WORD*)
00549 {
00550
00551 INT32 Slot = FindFreeSlot();
00552
00553
00554 if (Slot == BAD_SLOT)
00555 return FALSE;
00556
00557
00558 Handles[Slot].Type = HANDLE_PATTERNBRUSH;
00559
00560
00561 return TRUE;
00562 }
00563
00564
00565
00566
00567
00568
00569
00570
00571
00572
00573
00574
00575
00576 BOOL HandleTable::CreateFontIndirect(LOGFONT_16* pNewFont)
00577 {
00578
00579 INT32 Slot = FindFreeSlot();
00580
00581
00582 if (Slot == BAD_SLOT)
00583 return FALSE;
00584
00585
00586 Handles[Slot].Type = HANDLE_FONTINDIRECT;
00587 Handles[Slot].pFont = pNewFont;
00588
00589
00590 return TRUE;
00591 }
00592
00593
00594
00595
00596
00597
00598
00599
00600
00601
00602
00603
00604 BOOL HandleTable::CreateRegion(WORD*)
00605 {
00606
00607 INT32 Slot = FindFreeSlot();
00608
00609
00610 if (Slot == BAD_SLOT)
00611 return FALSE;
00612
00613
00614 Handles[Slot].Type = HANDLE_REGION;
00615
00616
00617 return TRUE;
00618 }
00619
00620
00621
00622
00623
00624
00625
00626
00627
00628
00629
00630
00631
00632
00633
00634
00635 BOOL HandleTable::SelectObject(INT32 Index)
00636 {
00637
00638 if ((Index < 0) || (Index >= TableSize))
00639 {
00640
00641 if (IsUserName("Rik"))
00642 TRACE( _T("Tried to select out of range object\n"));
00643 ERROR(_R(IDT_BAD_METAFILE), FALSE);
00644 }
00645
00646
00647 switch (Handles[Index].Type)
00648 {
00649 case HANDLE_NONE:
00650
00651 if (IsUserName("Rik"))
00652 TRACE( _T("Tried to select non-existent object\n"));
00653 return FALSE;
00654
00655 case HANDLE_PEN:
00656 Context->SetLineColour(Handles[Index].Colour);
00657 Context->SetLineWidth(Handles[Index].PenWidth);
00658 break;
00659
00660 case HANDLE_BRUSH:
00661 Context->SetFillColour(Handles[Index].Colour);
00662 break;
00663
00664 case HANDLE_PALETTE:
00665 break;
00666
00667 case HANDLE_PATTERNBRUSH:
00668 break;
00669
00670 case HANDLE_FONTINDIRECT:
00671 Context->SetLogicalFont(Handles[Index].pFont);
00672 break;
00673
00674 case HANDLE_REGION:
00675 break;
00676
00677 default:
00678 ENSURE(FALSE, "Bad metafile handle type!");
00679 ERROR(_R(IDT_BAD_METAFILE), FALSE);
00680 }
00681
00682
00683 return TRUE;
00684 }
00685
00686
00687
00688
00689
00690
00691
00692
00693
00694
00695
00696
00697
00698
00699
00700
00701 BOOL HandleTable::DeleteObject(INT32 Index)
00702 {
00703
00704 if ((Index < 0) || (Index >= TableSize))
00705 {
00706
00707 if (IsUserName("Rik"))
00708 TRACE( _T("Tried to delete out of range object\n"));
00709 return FALSE;
00710 }
00711
00712
00713 switch (Handles[Index].Type)
00714 {
00715 case HANDLE_NONE:
00716
00717 if (IsUserName("Rik"))
00718 TRACE( _T("Tried to delete non-existent object\n"));
00719 return FALSE;
00720
00721 case HANDLE_PEN:
00722 case HANDLE_BRUSH:
00723 case HANDLE_PALETTE:
00724 case HANDLE_PATTERNBRUSH:
00725 case HANDLE_FONTINDIRECT:
00726 case HANDLE_REGION:
00727 Handles[Index].Type = HANDLE_NONE;
00728 break;
00729
00730 default:
00731 ENSURE(FALSE, "Bad metafile handle type!");
00732 ERROR(_R(IDT_BAD_METAFILE), FALSE);
00733 }
00734
00735
00736 return TRUE;
00737 }
00738
00739
00740
00741
00742
00743
00744
00745
00746
00747
00748
00749
00750
00751
00752
00753
00754
00755
00756
00757
00758
00759
00760
00761
00762
00763
00764
00765
00766
00767
00768
00769
00770
00771
00772
00773 MetaFileClipMap::MetaFileClipMap(ClipboardMappingType TheType, Filter *TheFilter,
00774 InternalClipboardFormat &TheInternalDataType,
00775 UINT32 TheExternalDataType,
00776 UINT32 ThePriority)
00777 : ClipboardMapping(TheType, TheFilter, TheInternalDataType,
00778 TheExternalDataType, ThePriority)
00779 {
00780 }
00781
00782
00783
00784
00785
00786
00787
00788
00789
00790
00791
00792
00793
00794
00795
00796
00797
00798
00799
00800
00801
00802
00803
00804
00805
00806
00807
00808
00809
00810
00811
00812
00813 void MetaFileClipMap::CreateAndRegister(ClipboardMappingType TheType, Filter *TheFilter,
00814 InternalClipboardFormat &TheInternalDataType,
00815 UINT32 TheExternalDataType,
00816 UINT32 ThePriority)
00817 {
00818 MetaFileClipMap *Mapping = new MetaFileClipMap(TheType, TheFilter,
00819 TheInternalDataType,
00820 TheExternalDataType,
00821 ThePriority);
00822 if (Mapping == NULL)
00823 InformError();
00824 else
00825 ExternalClipboard::RegisterDataType(Mapping);
00826 }
00827
00828
00829
00830
00831
00832
00833
00834
00835
00836
00837
00838
00839
00840
00841
00842
00843
00844
00845
00846
00847
00848 BOOL MetaFileClipMap::HandleImport(SelOperation *Caller,
00849 HANDLE ClipboardData, InternalClipboard *Dest)
00850 {
00851 BOOL ok = FALSE;
00852
00853
00854
00855 char *tempname = GetTempFileName();
00856 if (tempname == NULL)
00857 {
00858 ERROR3("Couldn't get a temp filename");
00859 return(FALSE);
00860 }
00861
00862
00863
00864 METAFILEPICT *Info = (METAFILEPICT *) GlobalLock(ClipboardData);
00865
00866 if (Info == NULL)
00867 {
00868 RemoveTempFile();
00869 return(FALSE);
00870 }
00871
00872 HMETAFILE hCopy = CopyMetaFile(Info->hMF, tempname);
00873
00874 GlobalUnlock(ClipboardData);
00875
00876 if (hCopy != NULL)
00877 {
00878 ok = ImportFromTempFile(tempname, Caller, Dest);
00879 DeleteMetaFile(hCopy);
00880 }
00881
00882 RemoveTempFile();
00883
00884 return(ok);
00885 }
00886
00887
00888
00889
00890
00891
00892
00893
00894
00895
00896
00897
00898
00899
00900
00901
00902
00903
00904
00905
00906
00907
00908
00909
00910
00911
00912
00913
00914 HANDLE MetaFileClipMap::HandleExport(Operation *Caller, InternalClipboard *Source)
00915 {
00916 #if (_OLE_VER >= 0x200)
00917
00918
00919 HANDLE hGlobalMem;
00920 if ((hGlobalMem = m_hMem) != 0)
00921 {
00922
00923 if (m_cbMemSize < sizeof(METAFILEPICT)) return 0;
00924 }
00925 else
00926 {
00927
00928 hGlobalMem = m_hMem = GlobalAlloc(GHND, sizeof(METAFILEPICT));
00929 if (!hGlobalMem) return 0;
00930 }
00931
00932 #else
00933
00934 HANDLE hGlobalMem = GlobalAlloc(GHND, sizeof(METAFILEPICT));
00935 if (!hGlobalMem) return 0;
00936
00937 #endif
00938
00939 METAFILEPICT* Info = (METAFILEPICT*) GlobalLock(hGlobalMem);
00940
00941
00942 Info->mm = MM_ANISOTROPIC;
00943 Info->xExt = 0;
00944 Info->yExt = 0;
00945 Info->hMF = NULL;
00946
00947
00948
00949 char *temp[1024];
00950 CCMemFile DummyFile(temp, 1000);
00951
00952 ((MetaFileFilter *)pFilter)->DoExport(Caller, &DummyFile, (Document *)Source, Info);
00953
00954 if (DummyFile.isOpen()) DummyFile.close();
00955
00956
00957
00958
00959 GlobalUnlock(hGlobalMem);
00960 return(hGlobalMem);
00961 }
00962
00963
00964
00965
00966
00967
00968
00969
00970
00971
00972
00973
00974 MetaFileFilter::MetaFileFilter()
00975 {
00976
00977 FilterName.Load(_R(IDT_METAFILE_FILTERNAME));
00978 FilterInfo.Load(_R(IDT_METAFILE_FILTERINFO));
00979 FilterID = FILTERID_METAFILE;
00980
00981
00982 Flags.CanImport = TRUE ;
00983 Flags.CanExport = TRUE;
00984
00985 OutputFile = NULL;
00986 ExportRegion = NULL;
00987 ExportMsgID = _R(IDT_EXPORTMSG_METAFILE1);
00988
00989
00990 FlipYCoords = FALSE;
00991 YShift = 0;
00992 IsYExtentNegative = FALSE;
00993 Dpi = 96;
00994
00995
00996 TextColour = DocColour(0,0,0);
00997
00998
00999 SelectedFont.lfHeight = -96;
01000 SelectedFont.lfWidth = 0;
01001 SelectedFont.lfEscapement = 0;
01002 SelectedFont.lfOrientation = 0;
01003 SelectedFont.lfWeight = 0;
01004 SelectedFont.lfItalic = FALSE;
01005 SelectedFont.lfUnderline = FALSE;
01006 SelectedFont.lfStrikeOut = FALSE;
01007 SelectedFont.lfCharSet = 0;
01008 SelectedFont.lfOutPrecision = 3;
01009 SelectedFont.lfClipPrecision = 2;
01010 SelectedFont.lfQuality = 1;
01011 SelectedFont.lfPitchAndFamily = 18;
01012
01013 camStrcpy(SelectedFont.lfFaceName, (TCHAR *)String_64(_R(IDS_METAFILT_FONT)));
01014
01015
01016 pMetaView = NULL;
01017 };
01018
01019
01020
01021
01022
01023
01024
01025
01026
01027
01028
01029
01030 void MetaFileFilter::AddNodeToMetaFileGroup(NodeRenderableBounded *pNewNode)
01031 {
01032 if (pLastInsertedNode)
01033
01034
01035 pNewNode->AttachNode(pLastInsertedNode, NEXT);
01036 else
01037
01038
01039 pNewNode->AttachNode(pNode, LASTCHILD);
01040
01041 pNewNode->GetBoundingRect();
01042
01043
01044 pLastInsertedNode = pNewNode;
01045 }
01046
01047
01048
01049
01050
01051
01052
01053
01054
01055
01056
01057 MetaFileFilter::~MetaFileFilter()
01058 {
01059 }
01060
01061
01062
01063
01064
01065
01066
01067
01068
01069
01070
01071 BOOL MetaFileFilter::Init()
01072 {
01073
01074
01075 pOILFilter = new MetaFileOILFilter(this);
01076 if (pOILFilter==NULL)
01077
01078 return FALSE;
01079
01080 MetaFile = NULL;
01081 MetaFileDC = NULL;
01082 Handles = NULL;
01083
01084
01085
01086
01087 InternalClipboardFormat Format(CLIPTYPE_VECTOR);
01088 MetaFileClipMap::CreateAndRegister(CLIPMAP_IMPORTONLY, this, Format, CF_METAFILEPICT, 100);
01089
01090
01091 return TRUE;
01092 }
01093
01094
01095
01096
01097
01098
01099
01100
01101
01102
01103
01104
01105
01106
01107
01108
01109
01110
01111
01112
01113
01114
01115 BOOL MetaFileFilter::IsDefaultDocRequired(const TCHAR* pcszPathName)
01116 {
01117
01118
01119 return TRUE;
01120 }
01121
01122
01123
01124
01125
01126
01127
01128
01129
01130
01131
01132
01133 BOOL MetaFileFilter::PrepareToImport()
01134 {
01135
01136 ENSURE(MetaFile == NULL, "PrepareToImport: still attached to a metafile!");
01137 MetaFile = NULL;
01138 ENSURE(MetaFileDC == NULL, "PrepareToImport: still attached to a metafile DC!");
01139 MetaFileDC = NULL;
01140
01141
01142 if (!SetUpCurrentAttrs())
01143 return FALSE;
01144
01145
01146 ENSURE(Handles == NULL, "PrepareToImport: still got a handle table!");
01147 Handles = new HandleTable(this);
01148 if (Handles==NULL)
01149
01150 return FALSE;
01151
01152
01153 FileSize = 0;
01154 BytesRead = 0;
01155
01156
01157 CurrentMappingMode = MM_TEXT;
01158 MetaFileOrigin.x = 0;
01159 MetaFileOrigin.y = 0;
01160
01161
01162 TextColour = DocColour(0,0,0);
01163
01164 return TRUE;
01165 }
01166
01167
01168
01169
01170
01171
01172
01173
01174
01175
01176
01177 void MetaFileFilter::CleanUpAfterImport()
01178 {
01179 DeleteCurrentAttrs();
01180
01181
01182 if (MetaFile != NULL)
01183 {
01184 if (!::DeleteMetaFile(MetaFile))
01185 ENSURE(FALSE, "Error occured while closing metafile");
01186 MetaFile = NULL;
01187 }
01188
01189
01190 if (MetaFileDC != NULL)
01191 {
01192 if (!::CloseMetaFile(MetaFileDC))
01193 {
01194 ENSURE(FALSE, "Error occured while closing metafile");
01195 }
01196 MetaFileDC = NULL;
01197 }
01198
01199
01200 delete Handles;
01201 Handles = NULL;
01202 }
01203
01204
01205
01206
01207
01208
01209
01210
01211
01212
01213
01214
01215
01216
01217
01218
01219
01220
01221
01222
01223
01224
01225
01226
01227
01228
01229 INT32 CALLBACK MetaFileFilter::DecodeMetaFile(HDC hdc, HANDLETABLE FAR* pHandleTable,
01230 METARECORD FAR* pMetaRec, INT32 cObj, LPARAM lParam)
01231 {
01232 MetaFileFilter *Filter = (MetaFileFilter*)lParam;
01233 INT32 Result = Filter->DecodeMetafileRecord(pMetaRec);
01234
01235
01236 if (Result!=1)
01237 ERROR1(FALSE, _R(IDE_BADMETAFILE));
01238
01239
01240 return 1;
01241 }
01242
01243
01244
01245
01246
01247
01248
01249
01250
01251
01252
01253
01254
01255 BOOL MetaFileFilter::OpenAndIterateMetafile(CCLexFile *pDiskFile)
01256 {
01257
01258 if (!pDiskFile->IS_KIND_OF(CCDiskFile))
01259 {
01260 TRACEUSER( "JustinF", _T("Non-CCDiskFile in MetaFileFilter::OpenAndIterateMetafile\n"));
01261 return FALSE;
01262 }
01263
01264 METADATA MetaData;
01265 PathName Path = ((CCDiskFile*) pDiskFile)->GetPathName();
01266 String_256 PathString = Path.GetPath();
01267 MetaFile = GetMetaFileHandle((TCHAR*) PathString, &MetaData);
01268
01269 if (MetaFile == NULL)
01270 {
01271
01272 TRACEUSER( "Jonathan", _T("Could not open metafile\n"));
01273 ERROR(_R(IDT_IMPORT_NOTFOUND), FALSE);
01274 }
01275
01276
01277 Placeable = MetaData.Placeable;
01278
01279
01280 if (Placeable)
01281 {
01282
01283 MetaFileOrigin.x = MetaData.Header.bbox.left;
01284 MetaFileOrigin.y = MetaData.Header.bbox.bottom;
01285
01286
01287 FlipYCoords = FALSE;
01288 IsYExtentNegative = FALSE;
01289
01290
01291 INT32 YExtent = MetaData.Header.bbox.top-MetaFileOrigin.y;
01292 if (YExtent < 0)
01293 IsYExtentNegative = TRUE;
01294
01295
01296 if (MetaFileOrigin.y > MetaData.Header.bbox.top)
01297 YShift = -YExtent;
01298
01299
01300
01301 Dpi = MetaData.Header.inch;
01302 ScaleFactor = (72000 / MetaData.Header.inch);
01303
01304 TRACEUSER( "Jonathan", _T("Placable metafile -\n (%ld, %ld) %ld\n"), MetaFileOrigin.x, MetaFileOrigin.y, ScaleFactor);
01305 TRACEUSER( "Jonathan", _T("Bbox (%ld, %ld)\n (%ld, %ld)\n"), MetaData.Header.bbox.left, MetaData.Header.bbox.bottom, MetaData.Header.bbox.right, MetaData.Header.bbox.top);
01306 TRACEUSER( "Jonathan", _T("Is Negative %d\n"), IsYExtentNegative);
01307 }
01308 else
01309 {
01310
01311 MetaFileOrigin.x = 0;
01312 MetaFileOrigin.y = 0;
01313 ScaleFactor = 72000 / 96;
01314 FlipYCoords = FALSE;
01315 YShift = 0;
01316
01317
01318 IsYExtentNegative = TRUE;
01319 Dpi = 96;
01320 TRACEUSER( "Jonathan", _T("Non-Placable metafile -\n Origin (%ld, %ld) ScaleFactor %ld\n"), MetaFileOrigin.x, MetaFileOrigin.y, ScaleFactor);
01321 TRACEUSER( "Jonathan", _T("Is Negative %d\n"), IsYExtentNegative);
01322 }
01323
01324
01325 FileSize = GetMetaFileBitsEx(MetaFile, 0, NULL);
01326 if (FileSize == 0)
01327 {
01328 if (IsUserName("Rik"))
01329 TRACE( _T("Couldn't take size of the MetaFile\n"));
01330 ERROR(_R(IDT_IMPORT_NOTFOUND), FALSE);
01331 }
01332
01333
01334 MetaFileDC = CreateMetaFile(NULL);
01335 if (MetaFileDC == NULL)
01336 {
01337 return FALSE;
01338 }
01339
01340
01341 String_64 ImportMessage(_R(IDT_IMPORTMSG_METAFILE));
01342 ImportMessage = GetImportProgressString(pDiskFile, _R(IDT_IMPORTMSG_METAFILE));
01343 BeginSlowJob(FileSize, TRUE, &ImportMessage);
01344
01345
01346 BOOL Worked = ::EnumMetaFile(MetaFileDC, MetaFile, DecodeMetaFile, (LPARAM) this);
01347
01348 EndSlowJob();
01349
01350 return Worked;
01351 }
01352
01353
01354
01355
01356
01357
01358
01359
01360
01361
01362
01363
01364
01365
01366
01367
01368
01369
01370
01371
01372
01373
01374
01375
01376 BOOL MetaFileFilter::DoImport(SelOperation *Op, CCLexFile* pDiskFile,
01377 Document *DestDoc, BOOL AutoChosen, ImportPosition *pPos,
01378 KernelBitmap** ppImportedBitmap,DocCoord* pPosTranslate, String_256* URL)
01379 {
01380
01381 InFile = 0;
01382
01383
01384 TheDocument = DestDoc;
01385
01386
01387 if (!PrepareToImport())
01388 return FALSE;
01389
01390
01391 if (!MakeSureLayerExists(DestDoc))
01392
01393 return FALSE;
01394
01395
01396 pLayer = GetActiveLayer(DestDoc);
01397 ENSURE(pLayer != NULL, "Spread has no active layer");
01398
01399 NodeGroup* pGroup = new NodeGroup;
01400 if (!pGroup)
01401 return FALSE;
01402 pNode = pGroup;
01403
01404
01405 AttachNodeDirection dir;
01406
01407 Node *pInsertPoint = pLayer->FindLastChild();
01408 if (pInsertPoint)
01409 {
01410 if (pInsertPoint->IsAnInsertionNode())
01411 dir = PREV;
01412 else
01413 dir = NEXT;
01414 }
01415 else
01416 {
01417 pInsertPoint = pLayer;
01418 dir = LASTCHILD;
01419 }
01420
01421 Op->DoInsertNewNode(pGroup,
01422 pInsertPoint,
01423 dir,
01424 TRUE,
01425 TRUE,
01426 TRUE,
01427 FALSE);
01428
01429
01430
01431 pLastInsertedNode = 0;
01432
01433 ImportInfo.pOp = Op;
01434
01435 if (pPos == NULL)
01436 {
01437 ImportInfo.Pos.pSpread = GetFirstSpread(DestDoc);
01438 DocCoord centre = ImportInfo.Pos.pSpread->FindFirstPageInSpread()->GetPageRect().Centre();
01439 ImportInfo.Pos.Position.x = centre.x;
01440 ImportInfo.Pos.Position.y = centre.y;
01441 }
01442 else
01443 ImportInfo.Pos = *pPos;
01444
01445
01446
01447 AllUnderstood = TRUE;
01448 BOOL Worked = OpenAndIterateMetafile( pDiskFile );
01449
01450 CleanUpAfterImport();
01451
01452 if (InFile)
01453 {
01454 _lclose(InFile);
01455 InFile = 0;
01456 }
01457
01458 if (!Worked)
01459 {
01460
01461
01462 return FALSE;
01463 }
01464
01465
01466
01467 pGroup->InvalidateBoundingRect();
01468
01469 DocCoord GroupCentre = pGroup->GetBoundingRect().Centre();
01470 DocCoord GroupTrans;
01471
01472 GroupTrans.x = ImportInfo.Pos.Position.x - GroupCentre.x;
01473 GroupTrans.y = ImportInfo.Pos.Position.y - GroupCentre.y;
01474
01475 Trans2DMatrix trans(GroupTrans.x, GroupTrans.y);
01476 pGroup->Transform(trans);
01477
01478 pGroup->InvalidateBoundingRect();
01479 Op->DoInvalidateNodeRegion(pGroup, FALSE, FALSE, FALSE);
01480
01481
01482 if ((TheDocument!=NULL) && (pNode!=NULL))
01483 TheDocument->PostImport();
01484
01485
01486 if ((Worked) && (!AllUnderstood))
01487 {
01488 Error::SetError(_R(IDS_MEATFILE_WARN), 0);
01489 InformWarning();
01490 Error::ClearError();
01491 }
01492
01493 return Worked;
01494 }
01495
01496
01497
01498
01499
01500
01501
01502
01503
01504
01505
01506
01507
01508
01509
01510
01511 BOOL MetaFileFilter::MetaFileHeaderIsOk(METAHEADER *pHeader)
01512 {
01513 return( (pHeader->mtType == 1) &&
01514
01515 (pHeader->mtHeaderSize >= 9) &&
01516 (pHeader->mtHeaderSize < 100) &&
01517
01518 (pHeader->mtSize >= 9) &&
01519 (pHeader->mtSize < 0xFF000000L) &&
01520
01521 (pHeader->mtVersion >= 0x200));
01522
01523 }
01524
01525
01526
01527
01528
01529
01530
01531
01532
01533
01534
01535
01536
01537
01538
01539
01540
01541
01542
01543
01544 INT32 MetaFileFilter::HowCompatible(PathName& Filename, ADDR HeaderStart, UINT32 HeaderSize,
01545 UINT32 FileSize)
01546 {
01547
01548 METAFILEHEADER *pMetaFileHeader = (METAFILEHEADER *) HeaderStart;
01549
01550 if (pMetaFileHeader->key == METAFILEHEADERKEY)
01551
01552 return 10;
01553
01554
01555 METAHEADER *pMetaHeader = (METAHEADER *) HeaderStart;
01556
01557 if (MetaFileHeaderIsOk(pMetaHeader))
01558 {
01559
01560 String Extension = Filename.GetType();
01561 if (_tcsicmp((TCHAR *) Extension, "wmf") == 0)
01562
01563 return 9;
01564 else
01565
01566 return 5;
01567 }
01568 else
01569
01570 return 0;
01571 }
01572
01573
01574
01575
01576
01577
01578
01579
01580
01581
01582
01583
01584
01585
01586
01587
01588
01589
01590 HMETAFILE MetaFileFilter::GetMetaFileHandle(LPSTR Filename, METADATA *pMetaData)
01591 {
01592 OFSTRUCT OpenBuf;
01593
01594
01595 OpenBuf.cBytes = sizeof(OpenBuf);
01596 InFile = OpenFile(Filename, &OpenBuf, OF_READ);
01597
01598
01599 if (InFile == HFILE_ERROR)
01600 return NULL;
01601
01602
01603 INT32 BytesRead = _lread(InFile, &pMetaData->Header, sizeof(DWORD));
01604
01605 if (BytesRead != sizeof(DWORD))
01606 {
01607
01608 _lclose(InFile);
01609 InFile = 0;
01610 return NULL;
01611 }
01612
01613 METAHEADER MetaHeader;
01614
01615
01616 if (pMetaData->Header.key != METAFILEHEADERKEY)
01617 {
01618
01619
01620
01621 _llseek(InFile, 0L, 0);
01622 _lread(InFile, &MetaHeader, sizeof(MetaHeader));
01623 _lclose(InFile);
01624 InFile = 0;
01625
01626 if (!MetaFileHeaderIsOk(&MetaHeader))
01627
01628 return NULL;
01629
01630
01631 pMetaData->Placeable = FALSE;
01632 return ::GetMetaFile(Filename);
01633 }
01634
01635
01636 BytesRead = _lread(InFile, (LPVOID) &(pMetaData->Header.hmf), sizeof(METAFILEHEADER)-sizeof(DWORD));
01637
01638
01639 if (BytesRead!=(sizeof(METAFILEHEADER)-sizeof(DWORD)))
01640 {
01641
01642 _lclose(InFile);
01643 InFile = 0;
01644 return NULL;
01645 }
01646
01647
01648 BytesRead = _lread(InFile, (LPSTR) &MetaHeader, sizeof(METAHEADER));
01649
01650
01651 if (BytesRead != sizeof(METAHEADER))
01652 {
01653
01654 _lclose(InFile);
01655 InFile = 0;
01656 return NULL;
01657 }
01658
01659
01660 GLOBALHANDLE MemHandle = GlobalAlloc(GHND, (MetaHeader.mtSize * 2L));
01661
01662 if (MemHandle == NULL)
01663 {
01664
01665 _lclose(InFile);
01666 InFile = 0;
01667 return NULL;
01668 }
01669
01670
01671 LPSTR MemPtr = (LPSTR) GlobalLock(MemHandle);
01672
01673 if (MemPtr == NULL)
01674 {
01675
01676 GlobalFree(MemHandle);
01677 _lclose(InFile);
01678 InFile = 0;
01679 return NULL;
01680 }
01681
01682
01683 _llseek(InFile, sizeof(METAFILEHEADER), 0);
01684
01685
01686 BytesRead = _lread(InFile, MemPtr, (UINT32)(MetaHeader.mtSize * 2));
01687
01688
01689
01690 if ((UINT32) BytesRead == (MetaHeader.mtSize * 2))
01691 {
01692
01693 HMETAFILE MetaFileHandle;
01694 MetaFileHandle = SetMetaFileBitsEx(BytesRead, (LPBYTE) MemPtr);
01695
01696 if (MetaFileHandle != NULL)
01697 {
01698
01699 pMetaData->Placeable = TRUE;
01700 return MetaFileHandle;
01701 }
01702 }
01703
01704
01705 GlobalUnlock(MemHandle);
01706 GlobalFree(MemHandle);
01707 _lclose(InFile);
01708 InFile = 0;
01709
01710 return NULL;
01711 }
01712
01713
01714
01715
01716
01717
01718
01719
01720
01721 typedef struct
01722 {
01723 INT16 PolyCount;
01724 INT16 VertCounts[1];
01725 } POLYPOLYGON_INFO16;
01726
01727
01728
01729
01730
01731
01732
01733
01734
01735
01736
01737
01738
01739
01740 BOOL MetaFileFilter::DecodeBitBlt(METARECORD* pMetaRec)
01741 {
01742 TRACEUSER( "Jonathan", _T("Decoding Bit Blt\n"));
01743 AllUnderstood = FALSE;
01744 return TRUE;
01745 }
01746
01747
01748
01749
01750
01751
01752
01753
01754
01755
01756
01757
01758
01759
01760
01761 BOOL MetaFileFilter::DecodeStretchBlt(METARECORD* pMetaRec)
01762 {
01763 TRACEUSER( "Jonathan", _T("Decoding Stretch Blt\n"));
01764 AllUnderstood = FALSE;
01765 return TRUE;
01766 }
01767
01768
01769
01770
01771
01772
01773
01774
01775
01776
01777
01778
01779
01780
01781 BOOL MetaFileFilter::DecodeDIBToDevice(METARECORD* pMetaRec)
01782 {
01783 TRACEUSER( "Jonathan", _T("Decoding Set DIB To Device\n"));
01784 AllUnderstood = FALSE;
01785 return TRUE;
01786 }
01787
01788
01789
01790
01791
01792
01793
01794
01795
01796
01797
01798
01799
01800
01801 BOOL MetaFileFilter::DecodeDIBBitBlt(METARECORD* pMetaRec)
01802 {
01803 TRACEUSER( "Jonathan", _T("Decoding DIB Bit Blt\n"));
01804 AllUnderstood = FALSE;
01805 return TRUE;
01806 }
01807
01808
01809
01810
01811
01812
01813
01814
01815
01816
01817
01818
01819
01820
01821 BOOL MetaFileFilter::DecodeDIBStretchBlt(METARECORD* pRec)
01822 {
01823 TRACEUSER( "Jonathan", _T("Decoding DIBSTRETCHBLT\n"));
01824 AllUnderstood = FALSE;
01825
01826
01827
01828
01829
01830
01831
01832
01833
01834
01835
01836
01837
01838
01839
01840
01841
01842
01843
01844
01845
01846
01847
01848
01849
01850
01851
01852
01853
01854
01855
01856
01857
01858
01859
01860
01861
01862
01863
01864
01865
01866 return TRUE;
01867 }
01868
01869
01870
01871
01872
01873
01874
01875
01876
01877
01878
01879
01880
01881
01882 BOOL MetaFileFilter::DecodeStretchDIB(METARECORD* pRec)
01883 {
01884 TRACEUSER( "Jonathan", _T("Decoding Stretch DIB\n"));
01885
01886
01887 LPWORD pWords = (LPWORD) pRec->rdParm;
01888
01889
01890
01891 pWords+=7;
01892
01893
01894 INT16 DestYExt = (UINT16) *pWords++;
01895 INT16 DestXExt = (UINT16) *pWords++;
01896 INT16 DestY = (UINT16) *pWords++;
01897 INT16 DestX = (UINT16) *pWords++;
01898
01899
01900 BITMAPINFO* pBmpInfo = (BITMAPINFO*) pWords;
01901 KernelBitmap* pBitmap = CreateBitmap(pBmpInfo);
01902
01903
01904 if (pBitmap==NULL)
01905 return FALSE;
01906
01907
01908 DocCoord Position((INT32)DestX, (INT32)DestY);
01909 DocCoord Size(Position.x + (INT32)DestXExt, Position.y + (INT32)DestYExt);
01910
01911
01912 TransformCoord(&Position);
01913 TransformCoord(&Size);
01914
01915
01916 DocRect BoundsRect;
01917 BoundsRect.lo.x = min(Position.x, Size.x);
01918 BoundsRect.lo.y = min(Position.y, Size.y);
01919 BoundsRect.hi.x = max(Position.x, Size.x);
01920 BoundsRect.hi.y = max(Position.y, Size.y);
01921
01922
01923 NodeBitmap* pNodeBitmap = BuildNodeBitmap(pBitmap, BoundsRect);
01924
01925
01926 return TRUE;
01927 }
01928
01929
01930
01931
01932
01933
01934
01935
01936
01937
01938
01939
01940
01941
01942
01943
01944
01945
01946
01947
01948
01949 KernelBitmap* MetaFileFilter::CreateBitmap(BITMAPINFO* pBitmapStart)
01950 {
01951
01952 BITMAPINFOHEADER Header = pBitmapStart->bmiHeader;
01953 LPBYTE pData = NULL;
01954
01955
01956 LPBITMAPINFO pInfo = AllocDIB(Header.biWidth, Header.biHeight, Header.biBitCount, &pData);
01957
01958
01959 if ((pInfo==NULL) || (pData==NULL))
01960 return NULL;
01961
01962
01963 INT32 OldPalSize = Header.biClrUsed * sizeof(RGBQUAD);
01964 INT32 NewPalSize = pInfo->bmiHeader.biClrUsed * sizeof(RGBQUAD);
01965 ERROR3IF(OldPalSize!=NewPalSize, "Palettes are of a different size");
01966
01967
01968 LPBYTE pBitsStart = (LPBYTE) pBitmapStart;
01969 pBitsStart += sizeof(BITMAPINFOHEADER) + OldPalSize;
01970
01971
01972 memcpy(pData, pBitsStart, Header.biSizeImage);
01973
01974
01975 memcpy(pInfo->bmiColors, pBitmapStart->bmiColors, NewPalSize);
01976
01977
01978 WinBitmap* pWinBitmap = new WinBitmap(pInfo, pData);
01979
01980
01981 if (pWinBitmap==NULL)
01982 return NULL;
01983
01984
01985 KernelBitmap* pKernelBmp = new KernelBitmap(pWinBitmap, FALSE);
01986 if (pKernelBmp==NULL)
01987 {
01988 delete pWinBitmap;
01989 return NULL;
01990 }
01991
01992
01993 return pKernelBmp;
01994 }
01995
01996
01997
01998
01999
02000
02001
02002
02003
02004
02005
02006
02007
02008
02009
02010
02011 NodeBitmap* MetaFileFilter::BuildNodeBitmap(KernelBitmap* pBitmap, const DocRect& Position)
02012 {
02013
02014 NodeBitmap *pNodeBitmap = new NodeBitmap;
02015
02016 if (pNodeBitmap==NULL)
02017 return NULL;
02018
02019
02020 if (!pNodeBitmap->SetUpPath(12,12))
02021 {
02022
02023 pNodeBitmap->CascadeDelete();
02024 delete pNodeBitmap;
02025 return NULL;
02026 }
02027
02028
02029 pNodeBitmap->GetBitmapRef()->Attach(pBitmap, GetDocument());
02030 if (pNodeBitmap->GetBitmap() != pBitmap)
02031 {
02032
02033 delete pBitmap;
02034 }
02035
02036
02037 pNodeBitmap->CreateShape(Position);
02038
02039
02040 pNodeBitmap->ApplyDefaultBitmapAttrs(NULL);
02041
02042
02043 AddNodeToMetaFileGroup(pNodeBitmap);
02044
02045 return pNodeBitmap;
02046 }
02047
02048
02049
02050
02051
02052
02053
02054
02055
02056
02057
02058
02059
02060
02061
02062
02063
02064 BOOL MetaFileFilter::DecodePolyPolygon(METARECORD *pRec)
02065 {
02066 BOOL retvalue;
02067
02068
02069 POLYPOLYGON_INFO16 *pPolyInfo = (POLYPOLYGON_INFO16 *) pRec->rdParm;
02070
02071
02072 DocCoord Coord;
02073
02074
02075 DocRect BoundingRect;
02076
02077
02078 UINT32 NumPolys = (UINT32) pPolyInfo->PolyCount;
02079
02080
02081
02082
02083
02084 INT16 *pVertCount = pPolyInfo->VertCounts;
02085
02086 UINT32 NumSlots = 0;
02087
02088
02089 while (NumPolys > 0)
02090 {
02091
02092 NumSlots += (UINT32) *pVertCount;
02093
02094
02095 pVertCount++;
02096 NumPolys--;
02097 }
02098
02099
02100 NodePath *pPath = new NodePath;
02101 if (pPath==NULL)
02102 return FALSE;
02103
02104
02105 if (!pPath->SetUpPath(NumSlots))
02106 {
02107
02108
02109 if (pPath != NULL)
02110 pPath->CascadeDelete();
02111
02112
02113 delete pPath;
02114
02115
02116 return FALSE;
02117 }
02118
02119
02120 pPath->InkPath.FindStartOfPath();
02121
02122
02123 pVertCount = pPolyInfo->VertCounts;
02124 NumPolys = (UINT32) pPolyInfo->PolyCount;
02125
02126
02127 POINT_16 *pCoord = (POINT_16 *) (pPolyInfo->VertCounts + NumPolys);
02128
02129
02130 while (NumPolys > 0)
02131 {
02132
02133 UINT32 NumPoints = (UINT32) *pVertCount;
02134
02135
02136 Coord.x = pCoord->x;
02137 Coord.y = pCoord->y;
02138 TransformCoord(&Coord);
02139 if (!pPath->InkPath.InsertMoveTo(Coord))
02140
02141 goto NoMemory;
02142
02143
02144 pCoord++;
02145 NumPoints--;
02146
02147 while (NumPoints > 0)
02148 {
02149 Coord.x = pCoord->x;
02150 Coord.y = pCoord->y;
02151 TransformCoord(&Coord);
02152 if (!pPath->InkPath.InsertLineTo(Coord))
02153
02154 goto NoMemory;
02155
02156
02157 pCoord++;
02158 NumPoints--;
02159 }
02160
02161
02162 pVertCount++;
02163 NumPolys--;
02164 }
02165
02166
02167 pCoord--;
02168 CurrentPoint.x = pCoord->x;
02169 CurrentPoint.y = pCoord->y;
02170
02171
02172 if (!pPath->InkPath.CloseSubPath())
02173
02174 goto NoMemory;
02175
02176
02177 BOOL ChangesMade;
02178 if (!pPath->InkPath.EnsureValid(&ChangesMade))
02179 {
02180
02181 TRACE( _T("dpp Found a path that was so badly damaged we had to throw it away\n"));
02182 Error::ClearError();
02183
02184
02185 if (pPath != NULL)
02186 pPath->CascadeDelete();
02187
02188
02189 delete pPath;
02190
02191
02192 return TRUE;
02193 }
02194
02195 #ifdef _DEBUG
02196
02197 if (ChangesMade)
02198 {
02199
02200 TRACE( _T("We had to change this path as it was corrupt\n"));
02201 }
02202 #endif
02203
02204
02205
02206 FlatFillAttribute *pAttr;
02207 pAttr = (FlatFillAttribute *) CurrentAttrs[ATTR_FILLGEOMETRY].pAttr;
02208 ENSURE(pAttr->IsKindOf(CC_RUNTIME_CLASS(FlatFillAttribute)),
02209 "Bad fill type in metafile filter");
02210
02211 pPath->InkPath.IsFilled = !(pAttr->Colour.IsTransparent());
02212
02213
02214 retvalue = AddAttributes(pPath);
02215
02216 AddNodeToMetaFileGroup(pPath);
02217
02218 return retvalue;
02219
02220 NoMemory:
02221
02222
02223
02224 if (pPath != NULL)
02225 pPath->CascadeDelete();
02226
02227
02228 delete pPath;
02229
02230
02231 return FALSE;
02232 }
02233
02234
02235
02236
02237
02238
02239
02240
02241
02242
02243
02244
02245
02246
02247
02248
02249
02250
02251
02252
02253
02254
02255 BOOL MetaFileFilter::DecodePolygon(METARECORD *pRec, BOOL FillPolygon)
02256 {
02257 DocRect BoundingRect;
02258 BOOL retvalue;
02259
02260
02261 INT16 *pNumPoints;
02262 pNumPoints = (INT16 *) (pRec->rdParm);
02263
02264
02265 UINT32 NumPoints;
02266 NumPoints = (UINT32) *pNumPoints;
02267
02268
02269 if (NumPoints < 2)
02270 return TRUE;
02271
02272
02273 NodePath *pPath = new NodePath;
02274 if (pPath==NULL)
02275 return FALSE;
02276
02277
02278 if (!pPath->SetUpPath(NumPoints))
02279 {
02280
02281
02282 if (pPath != NULL)
02283 pPath->CascadeDelete();
02284
02285
02286 delete pPath;
02287
02288
02289 return FALSE;
02290 }
02291
02292
02293 pPath->InkPath.FindStartOfPath();
02294
02295
02296 POINT_16 *pCoord = (POINT_16 *) (pNumPoints + 1);
02297
02298
02299 DocCoord Coord;
02300 Coord.x = pCoord->x;
02301 Coord.y = pCoord->y;
02302 TransformCoord(&Coord);
02303 if (!pPath->InkPath.InsertMoveTo(Coord))
02304
02305 goto NoMemory;
02306
02307
02308 pCoord++;
02309 NumPoints--;
02310
02311 while (NumPoints > 0)
02312 {
02313 Coord.x = pCoord->x;
02314 Coord.y = pCoord->y;
02315 TransformCoord(&Coord);
02316 if (!pPath->InkPath.InsertLineTo(Coord))
02317
02318 goto NoMemory;
02319
02320
02321 pCoord++;
02322 NumPoints--;
02323 }
02324
02325
02326 pCoord--;
02327 CurrentPoint.x = pCoord->x;
02328 CurrentPoint.y = pCoord->y;
02329
02330
02331 if ((FillPolygon) && (!pPath->InkPath.CloseSubPath()))
02332
02333 goto NoMemory;
02334
02335
02336 BOOL ChangesMade;
02337 if (!pPath->InkPath.EnsureValid(&ChangesMade))
02338 {
02339
02340 TRACE( _T("dp Found a path that was so badly damaged we had to throw it away\n"));
02341 Error::ClearError();
02342
02343
02344 if (pPath != NULL)
02345 pPath->CascadeDelete();
02346
02347
02348 delete pPath;
02349
02350
02351 return TRUE;
02352 }
02353
02354 #ifdef _DEBUG
02355
02356 if (ChangesMade)
02357 {
02358
02359 TRACE( _T("We had to change this path as it was corrupt\n"));
02360 }
02361 #endif
02362
02363 if (FillPolygon)
02364 {
02365
02366
02367 FlatFillAttribute *pAttr;
02368 pAttr = (FlatFillAttribute *) CurrentAttrs[ATTR_FILLGEOMETRY].pAttr;
02369 ENSURE(pAttr->IsKindOf(CC_RUNTIME_CLASS(FlatFillAttribute)),
02370 "Bad fill type in metafile filter");
02371
02372 pPath->InkPath.IsFilled = !(pAttr->Colour.IsTransparent());
02373 }
02374 else
02375 {
02376
02377 pPath->InkPath.IsFilled = FALSE;
02378 }
02379
02380
02381 retvalue = AddAttributes(pPath);
02382
02383 AddNodeToMetaFileGroup(pPath);
02384
02385 return retvalue;
02386
02387 NoMemory:
02388
02389
02390
02391 if (pPath != NULL)
02392 pPath->CascadeDelete();
02393
02394
02395 delete pPath;
02396
02397
02398 return FALSE;
02399 }
02400
02401
02402
02403
02404
02405
02406
02407
02408
02409
02410
02411
02412
02413
02414
02415 BOOL MetaFileFilter::DecodeLineTo(METARECORD* pMetaRec)
02416 {
02417
02418
02419
02420
02421 NodePath *pPath = new NodePath;
02422 if (pPath==NULL)
02423 return FALSE;
02424
02425
02426 if (!pPath->SetUpPath(2))
02427 {
02428
02429 pPath->CascadeDelete();
02430 delete pPath;
02431 return FALSE;
02432 }
02433
02434
02435 pPath->InkPath.FindStartOfPath();
02436 pPath->InkPath.IsFilled = FALSE;
02437
02438
02439 if (!pPath->InkPath.InsertMoveTo(CurrentPoint))
02440 {
02441
02442 pPath->CascadeDelete();
02443 delete pPath;
02444 return FALSE;
02445 }
02446
02447
02448 CurrentPoint.y = (INT16) pMetaRec->rdParm[0];
02449 CurrentPoint.x = (INT16) pMetaRec->rdParm[1];
02450 TransformCoord(&CurrentPoint);
02451
02452
02453 if (!pPath->InkPath.InsertLineTo(CurrentPoint))
02454 {
02455
02456 pPath->CascadeDelete();
02457 delete pPath;
02458 return FALSE;
02459 }
02460
02461
02462 BOOL ChangesMade;
02463 if (!pPath->InkPath.EnsureValid(&ChangesMade))
02464 {
02465
02466 TRACE( _T("dl Found a path that was so badly damaged we had to throw it away\n"));
02467 Error::ClearError();
02468 pPath->CascadeDelete();
02469 delete pPath;
02470
02471
02472 return TRUE;
02473 }
02474
02475 #ifdef _DEBUG
02476
02477 if (ChangesMade)
02478 {
02479
02480 TRACE( _T("We had to change this path as it was corrupt\n"));
02481 }
02482 #endif
02483
02484
02485 BOOL retvalue = AddAttributes(pPath);
02486
02487 AddNodeToMetaFileGroup(pPath);
02488
02489 return retvalue;
02490 }
02491
02492
02493
02494
02495
02496
02497
02498
02499
02500
02501
02502
02503
02504
02505 BOOL MetaFileFilter::DecodeEllipse(METARECORD* pMetaRec)
02506 {
02507 TRACEUSER( "Jonathan", _T("Decoding Ellipse\n"));
02508
02509
02510 NodeEllipse *pElip = new NodeEllipse;
02511 if (pElip==NULL)
02512 return FALSE;
02513
02514
02515 if (!pElip->SetUpPath(12,12))
02516 {
02517
02518 pElip->CascadeDelete();
02519 delete pElip;
02520 return FALSE;
02521 }
02522
02523
02524 INT16 *pCoord = (INT16 *) (pMetaRec->rdParm);
02525
02526
02527 DocCoord TopRight((INT32) pCoord[1], (INT32) pCoord[2]);
02528 DocCoord BotLeft((INT32) pCoord[3], (INT32) pCoord[0]);
02529 TransformCoord(&TopRight);
02530 TransformCoord(&BotLeft);
02531
02532 DocRect Rect(min(TopRight.x, BotLeft.x),
02533 min(TopRight.y, BotLeft.y),
02534 max(TopRight.x, BotLeft.x),
02535 max(TopRight.y, BotLeft.y));
02536
02537
02538 pElip->CreateShape(Rect);
02539 pElip->InkPath.IsFilled = TRUE;
02540
02541
02542 BOOL retvalue = AddAttributes(pElip);
02543
02544 AddNodeToMetaFileGroup(pElip);
02545
02546 return retvalue;
02547 }
02548
02549
02550
02551
02552
02553
02554
02555
02556
02557
02558
02559
02560
02561
02562
02563 BOOL MetaFileFilter::DecodeRectangle(METARECORD* pMetaRec)
02564 {
02565 BOOL retvalue;
02566 TRACEUSER( "Jonathan", _T("Decoding Rectangle\n"));
02567
02568
02569 NodePath *pPath = new NodePath;
02570 if (pPath==NULL)
02571 return FALSE;
02572
02573
02574 if (!pPath->SetUpPath(12,12))
02575 {
02576
02577 if (pPath != NULL)
02578 pPath->CascadeDelete();
02579
02580
02581 delete pPath;
02582
02583
02584 return FALSE;
02585 }
02586
02587
02588 pPath->InkPath.FindStartOfPath();
02589
02590
02591 INT16 *pCoord = (INT16 *) (pMetaRec->rdParm);
02592
02593
02594 DocCoord TopRight((INT32) pCoord[1], (INT32) pCoord[2]);
02595 DocCoord BotLeft((INT32) pCoord[3], (INT32) pCoord[0]);
02596 TransformCoord(&TopRight);
02597 TransformCoord(&BotLeft);
02598
02599 DocRect Rect(min(TopRight.x, BotLeft.x),
02600 min(TopRight.y, BotLeft.y),
02601 max(TopRight.x, BotLeft.x),
02602 max(TopRight.y, BotLeft.y));
02603
02604
02605 DocCoord Coord;
02606 Coord.x = Rect.lo.x;
02607 Coord.y = Rect.lo.y;
02608 if (!pPath->InkPath.InsertMoveTo(Coord))
02609
02610 goto NoMemory;
02611
02612
02613 Coord.y = Rect.hi.y;
02614 if (!pPath->InkPath.InsertLineTo(Coord))
02615
02616 goto NoMemory;
02617
02618 Coord.x = Rect.hi.x;
02619 if (!pPath->InkPath.InsertLineTo(Coord))
02620
02621 goto NoMemory;
02622
02623 Coord.y = Rect.lo.y;
02624 if (!pPath->InkPath.InsertLineTo(Coord))
02625
02626 goto NoMemory;
02627
02628 Coord.x = Rect.lo.x;
02629 if (!pPath->InkPath.InsertLineTo(Coord))
02630
02631 goto NoMemory;
02632
02633
02634 if (!pPath->InkPath.CloseSubPath())
02635
02636 goto NoMemory;
02637
02638
02639 BOOL ChangesMade;
02640 if (!pPath->InkPath.EnsureValid(&ChangesMade))
02641 {
02642
02643 TRACE( _T("Found a path that was so badly damaged we had to throw it away\n"));
02644 Error::ClearError();
02645
02646
02647 if (pPath != NULL)
02648 pPath->CascadeDelete();
02649
02650
02651 delete pPath;
02652
02653
02654 return TRUE;
02655 }
02656
02657 #ifdef _DEBUG
02658
02659 if (ChangesMade)
02660 {
02661
02662 TRACE( _T("We had to change this path as it was corrupt\n"));
02663 }
02664 #endif
02665
02666
02667 pPath->InkPath.IsFilled = TRUE;
02668
02669
02670 retvalue = AddAttributes(pPath);
02671
02672 AddNodeToMetaFileGroup(pPath);
02673
02674 return retvalue;
02675
02676 NoMemory:
02677
02678
02679 if (pPath != NULL)
02680 pPath->CascadeDelete();
02681
02682
02683 delete pPath;
02684
02685
02686 return FALSE;
02687 }
02688
02689
02690
02691
02692
02693
02694
02695
02696
02697
02698
02699
02700
02701 BOOL MetaFileFilter::DecodeTextStory(METARECORD* pMetaRec)
02702 {
02703
02704 LPWORD pWords = (LPWORD) pMetaRec->rdParm;
02705
02706
02707 INT16 Count = (UINT16) *pWords++;
02708
02709
02710 char* pString = new char[Count+1];
02711 if (pString==NULL)
02712 return FALSE;
02713
02714
02715 camStrncpy(pString, (char*)pWords, Count);
02716 pString[Count] = 0;
02717 TRACE( _T("- %s\n"), pString);
02718
02719
02720 while (Count>0)
02721 {
02722 pWords++;
02723 Count-=2;
02724 }
02725
02726
02727 DocCoord Position(0,0);
02728
02729
02730 Position.y = (INT16) *pWords++;
02731 Position.x = (INT16) *pWords++;
02732
02733
02734 TransformCoord(&Position);
02735
02736
02737 TRACEUSER( "Jonathan", _T("Text Story : %s\n"), pString);
02738 TextStory* pNewStory = TextStory::CreateFromChars(Position, pString, NULL, GetDocument(),
02739 &SelectedFont, FALSE, &TextColour);
02740
02741 delete pString;
02742
02743
02744 if (pNewStory==NULL)
02745 return FALSE;
02746
02747
02748 AddNodeToMetaFileGroup(pNewStory);
02749
02750
02751 return TRUE;
02752 }
02753
02754
02755
02756
02757
02758
02759
02760
02761
02762
02763
02764
02765
02766
02767
02768 BOOL MetaFileFilter::DecodeExtTextStory(METARECORD* pMetaRec)
02769 {
02770
02771 LPWORD pWords = (LPWORD) pMetaRec->rdParm;
02772
02773
02774 DocCoord Position(0,0);
02775
02776
02777 Position.y = (INT16) *pWords++;
02778 Position.y -= SelectedFont.lfHeight;
02779 Position.x = (INT16) *pWords++;
02780
02781
02782 TransformCoord(&Position);
02783
02784
02785 INT16 Count = (UINT16) *pWords++;
02786
02787
02788 INT16 Option = (UINT16) *pWords++;
02789 if (Option!=0)
02790 {
02791
02792 pWords++;
02793 pWords++;
02794 pWords++;
02795 pWords++;
02796 }
02797
02798
02799 char* pString = new char[Count+1];
02800 if (pString==NULL)
02801 return FALSE;
02802
02803
02804 camStrncpy(pString, (char*)pWords, Count);
02805 pString[Count] = 0;
02806 TRACE( _T("%s\n"), pString);
02807
02808
02809 while (Count>0)
02810 {
02811 pWords++;
02812 Count-=2;
02813 }
02814
02815
02816 TextStory* pNewStory = TextStory::CreateFromChars(Position, pString, NULL, GetDocument(),
02817 &SelectedFont, FALSE, &TextColour);
02818
02819 delete pString;
02820
02821
02822 if (pNewStory==NULL)
02823 return FALSE;
02824
02825
02826 AddNodeToMetaFileGroup(pNewStory);
02827
02828
02829 return TRUE;
02830 }
02831
02832
02833
02834
02835
02836
02837
02838
02839
02840
02841
02842
02843
02844
02845
02846 void MetaFileFilter::SetLogicalFont(LOGFONT_16* pNewFont)
02847 {
02848
02849
02850 SelectedFont.lfHeight = pNewFont->lfHeight;
02851 SelectedFont.lfWidth = pNewFont->lfWidth;
02852 SelectedFont.lfEscapement = pNewFont->lfEscapement;
02853 SelectedFont.lfOrientation = pNewFont->lfOrientation;
02854 SelectedFont.lfWeight = pNewFont->lfWeight;
02855 SelectedFont.lfItalic = pNewFont->lfItalic;
02856 SelectedFont.lfUnderline = pNewFont->lfUnderline;
02857 SelectedFont.lfStrikeOut = pNewFont->lfStrikeOut;
02858 SelectedFont.lfCharSet = pNewFont->lfCharSet;
02859 SelectedFont.lfOutPrecision = pNewFont->lfOutPrecision;
02860 SelectedFont.lfClipPrecision = pNewFont->lfClipPrecision;
02861 SelectedFont.lfQuality = pNewFont->lfQuality;
02862 SelectedFont.lfPitchAndFamily = pNewFont->lfPitchAndFamily;
02863 camStrcpy(SelectedFont.lfFaceName, pNewFont->lfFaceName);
02864
02865
02866 switch (CurrentMappingMode)
02867 {
02868 case MM_TEXT:
02869
02870 SelectedFont.lfHeight = (SelectedFont.lfHeight * 96) / Dpi;
02871 SelectedFont.lfWidth = (SelectedFont.lfWidth * 96) / Dpi;
02872 break;
02873
02874 case MM_LOMETRIC:
02875
02876
02877 SelectedFont.lfHeight = (SelectedFont.lfHeight * 96) / 254;
02878 SelectedFont.lfWidth = (SelectedFont.lfWidth * 96) / 254;
02879 break;
02880
02881 case MM_HIMETRIC:
02882
02883
02884 SelectedFont.lfHeight = (SelectedFont.lfHeight * 96) / 2540;
02885 SelectedFont.lfWidth = (SelectedFont.lfWidth * 96) / 2540;
02886 break;
02887
02888 case MM_LOENGLISH:
02889
02890
02891 SelectedFont.lfHeight = (SelectedFont.lfHeight * 96) / 100;
02892 SelectedFont.lfWidth = (SelectedFont.lfWidth * 96) / 100;
02893 break;
02894
02895 case MM_HIENGLISH:
02896
02897
02898 SelectedFont.lfHeight = (SelectedFont.lfHeight * 96) / 1000;
02899 SelectedFont.lfWidth = (SelectedFont.lfWidth * 96) / 1000;
02900 break;
02901
02902 case MM_TWIPS:
02903
02904
02905 SelectedFont.lfHeight = (SelectedFont.lfHeight * 96) / 1440;
02906 SelectedFont.lfWidth = (SelectedFont.lfWidth * 96) / 1440;
02907 break;
02908
02909 default:
02910 SelectedFont.lfHeight = (SelectedFont.lfHeight * 96) / Dpi;
02911 SelectedFont.lfWidth = (SelectedFont.lfWidth * 96) / Dpi;
02912 break;
02913 }
02914 }
02915
02916
02917
02918
02919
02920
02921
02922
02923
02924
02925
02926
02927
02928
02929
02930
02931
02932
02933
02934
02935
02936 INT32 MetaFileFilter::DecodeMetafileRecord( METARECORD FAR* pMetaRec )
02937 {
02938 NodePath *pPath = NULL;
02939 DocCoord Coord;
02940 LOGPEN_16 *pPen;
02941 LOGBRUSH_16 *pBrush;
02942 DocRect BoundingRect;
02943 LOGFONT_16* pFont;
02944 LOGPALETTE_16* pPalette;
02945
02946
02947 BytesRead += pMetaRec->rdSize * 2;
02948
02949
02950 if (BytesRead>FileSize)
02951 BytesRead = FileSize;
02952
02953
02954 #if WIN32
02955 if (BytesRead > (LastProgressUpdate + 2048))
02956 {
02957 if (!ContinueSlowJob(BytesRead))
02958 {
02959
02960 ERROR(_R(IDT_IMPORT_USERABORT), FALSE);
02961 }
02962 else
02963 {
02964 LastProgressUpdate = BytesRead;
02965 }
02966 }
02967 #endif
02968
02969
02970 switch (pMetaRec->rdFunction)
02971 {
02972 case META_SETTEXTCHAREXTRA:
02973 AllUnderstood = FALSE;
02974 TRACEUSER( "Jonathan", _T("SETTEXTCHAREXTRA\n"));
02975 break;
02976
02977 case META_SETTEXTCOLOR:
02978 {
02979
02980 COLORREF* pColour = (COLORREF*) pMetaRec->rdParm;
02981 DocColour NewColour(INT32(GetRValue(*pColour)), INT32(GetGValue(*pColour)),
02982 INT32(GetBValue(*pColour)));
02983
02984
02985 TextColour = NewColour;
02986 break;
02987 }
02988
02989 case META_SETTEXTJUSTIFICATION:
02990 AllUnderstood = FALSE;
02991 TRACEUSER( "Jonathan", _T("SETTEXTJUSTIFICATION\n"));
02992 break;
02993
02994 case META_SETTEXTALIGN:
02995
02996 break;
02997
02998 case META_EXTTEXTOUT:
02999 if (!DecodeExtTextStory(pMetaRec))
03000 return FALSE;
03001 break;
03002
03003 case META_TEXTOUT:
03004 if (!DecodeTextStory(pMetaRec))
03005 return FALSE;
03006 break;
03007
03008
03009
03010 case META_SETSTRETCHBLTMODE:
03011
03012 break;
03013
03014 case META_DIBBITBLT:
03015 if (!DecodeDIBBitBlt(pMetaRec))
03016 return FALSE;
03017 break;
03018
03019 case META_DIBSTRETCHBLT:
03020 if (!DecodeDIBStretchBlt(pMetaRec))
03021 return FALSE;
03022 break;
03023
03024 case META_STRETCHDIB:
03025 if (!DecodeStretchDIB(pMetaRec))
03026 return FALSE;
03027 break;
03028
03029 case META_SETDIBTODEV:
03030 if (!DecodeDIBToDevice(pMetaRec))
03031 return FALSE;
03032 break;
03033
03034 case META_BITBLT:
03035 if (!DecodeBitBlt(pMetaRec))
03036 return FALSE;
03037 break;
03038
03039 case META_STRETCHBLT:
03040 if (!DecodeStretchBlt(pMetaRec))
03041 return FALSE;
03042 break;
03043
03044 case META_PATBLT:
03045 AllUnderstood = FALSE;
03046 TRACEUSER( "Jonathan", _T("PATBLT\n"));
03047 break;
03048
03049 case META_DIBCREATEPATTERNBRUSH:
03050 AllUnderstood = FALSE;
03051 TRACEUSER( "Jonathan", _T("DIBCREATEPATTERNBRUSH\n"));
03052 break;
03053
03054
03055
03056 case META_SETWINDOWORG:
03057 {
03058
03059 if (!Placeable)
03060 {
03061
03062 MetaFileOrigin.y = (INT16) pMetaRec->rdParm[0];
03063 MetaFileOrigin.x = (INT16) pMetaRec->rdParm[1];
03064 YShift = 0;
03065 }
03066 break;
03067 }
03068
03069 case META_SETWINDOWEXT:
03070 {
03071
03072
03073 {
03074 INT16 YExtent = (INT16) pMetaRec->rdParm[0];
03075 TRACEUSER( "Jonathan", _T("Extent - x=%d, y=%d\n"), pMetaRec->rdParm[1], pMetaRec->rdParm[0]);
03076 if (YExtent<0 && !IsYExtentNegative)
03077 FlipYCoords = TRUE;
03078
03079 if (YExtent>=0 && IsYExtentNegative)
03080 FlipYCoords = TRUE;
03081
03082 if (FlipYCoords)
03083 YShift = 0;
03084 }
03085 break;
03086 }
03087
03088 case META_OFFSETWINDOWORG:
03089 AllUnderstood = FALSE;
03090 TRACEUSER( "Jonathan", _T("OFFSETWINDOWORG\n"));
03091 break;
03092
03093 case META_SCALEWINDOWEXT:
03094 AllUnderstood = FALSE;
03095 TRACEUSER( "Jonathan", _T("SCALEWINDOWEXT\n"));
03096 break;
03097
03098 case META_OFFSETVIEWPORTORG:
03099 AllUnderstood = FALSE;
03100 TRACEUSER( "Jonathan", _T("OFFSETVIEWPORTORG\n"));
03101 break;
03102
03103 case META_SCALEVIEWPORTEXT:
03104 AllUnderstood = FALSE;
03105 TRACEUSER( "Jonathan", _T("SCALEVIEWPORTEXT\n"));
03106 break;
03107
03108 case META_SETVIEWPORTORG:
03109 AllUnderstood = FALSE;
03110 TRACEUSER( "Jonathan", _T("SetViewportOrg\n"));
03111 break;
03112
03113 case META_SETVIEWPORTEXT:
03114 AllUnderstood = FALSE;
03115 TRACEUSER( "Jonathan", _T("SetViewportExt\n"));
03116 break;
03117
03118
03119
03120 case META_SETPOLYFILLMODE:
03121 if (((INT32) pMetaRec->rdParm[0]) == WINDING)
03122 {
03123
03124 SetWindingRule(NonZeroWinding);
03125 }
03126 else
03127 {
03128
03129 SetWindingRule(EvenOddWinding);
03130 }
03131 break;
03132
03133 case META_POLYGON:
03134 if (!DecodePolygon(pMetaRec, TRUE))
03135
03136 return FALSE;
03137 break;
03138
03139 case META_POLYPOLYGON:
03140 if (!DecodePolyPolygon(pMetaRec))
03141
03142 return FALSE;
03143 break;
03144
03145 case META_POLYLINE:
03146
03147 if (!DecodePolygon(pMetaRec, FALSE))
03148 return FALSE;
03149 break;
03150
03151
03152
03153 case META_ESCAPE:
03154
03155 break;
03156
03157
03158
03159 case META_SELECTOBJECT:
03160 if (!Handles->SelectObject(pMetaRec->rdParm[0]))
03161 return FALSE;
03162 break;
03163
03164 case META_DELETEOBJECT:
03165 if (!Handles->DeleteObject(pMetaRec->rdParm[0]))
03166 return FALSE;
03167 break;
03168
03169 case META_CREATEPALETTE:
03170 pPalette = (LOGPALETTE_16 *) pMetaRec->rdParm;
03171 if (!Handles->CreatePalette(pPalette))
03172
03173 return FALSE;
03174 break;
03175
03176 case META_CREATEPATTERNBRUSH:
03177 if (!Handles->CreatePatternBrush(pMetaRec->rdParm))
03178
03179 return FALSE;
03180 break;
03181
03182 case META_CREATEFONTINDIRECT:
03183 pFont = (LOGFONT_16 *) pMetaRec->rdParm;
03184 if (!Handles->CreateFontIndirect(pFont))
03185
03186 return FALSE;
03187 break;
03188
03189 case META_CREATEREGION:
03190 if (!Handles->CreateRegion(pMetaRec->rdParm))
03191
03192 return FALSE;
03193 break;
03194
03195 case META_CREATEPENINDIRECT:
03196 pPen = (LOGPEN_16 *) pMetaRec->rdParm;
03197 if (!Handles->CreatePen(pPen))
03198
03199 return FALSE;
03200 break;
03201
03202 case META_CREATEBRUSHINDIRECT:
03203 pBrush = (LOGBRUSH_16 *) pMetaRec->rdParm;
03204 if (!Handles->CreateBrush(pBrush))
03205
03206 return FALSE;
03207 break;
03208
03209
03210
03211 case META_LINETO:
03212
03213 if (!DecodeLineTo(pMetaRec))
03214 return FALSE;
03215 break;
03216
03217 case META_MOVETO:
03218
03219 CurrentPoint.y = (INT16) pMetaRec->rdParm[0];
03220 CurrentPoint.x = (INT16) pMetaRec->rdParm[1];
03221 TransformCoord(&CurrentPoint);
03222 break;
03223
03224 case META_FLOODFILL:
03225
03226 break;
03227
03228 case META_EXTFLOODFILL:
03229
03230 break;
03231
03232 case META_ARC:
03233 AllUnderstood = FALSE;
03234 TRACEUSER( "Jonathan", _T("Arc\n"));
03235 break;
03236
03237 case META_ELLIPSE:
03238 if (!DecodeEllipse(pMetaRec))
03239 return FALSE;
03240 break;
03241
03242 case META_PIE:
03243 AllUnderstood = FALSE;
03244 TRACEUSER( "Jonathan", _T("Pie\n"));
03245 break;
03246
03247 case META_RECTANGLE:
03248 if (!DecodeRectangle(pMetaRec))
03249 return FALSE;
03250 break;
03251
03252 case META_ROUNDRECT:
03253 if (!DecodeRectangle(pMetaRec))
03254 return FALSE;
03255 break;
03256
03257 case META_CHORD:
03258 AllUnderstood = FALSE;
03259 TRACEUSER( "Jonathan", _T("Chord\n"));
03260 break;
03261
03262 case META_SETPIXEL:
03263
03264 break;
03265
03266
03267
03268 case META_SELECTPALETTE:
03269
03270 break;
03271
03272 case META_REALIZEPALETTE:
03273
03274 break;
03275
03276 case META_ANIMATEPALETTE:
03277
03278 break;
03279
03280 case META_SETPALENTRIES:
03281
03282 break;
03283
03284 case META_RESIZEPALETTE:
03285
03286 break;
03287
03288
03289
03290 case META_FILLREGION:
03291 AllUnderstood = FALSE;
03292 TRACEUSER( "Jonathan", _T("FILLREGION\n"));
03293 break;
03294
03295 case META_FRAMEREGION:
03296 AllUnderstood = FALSE;
03297 TRACEUSER( "Jonathan", _T("FRAMEREGION\n"));
03298 break;
03299
03300 case META_INVERTREGION:
03301 AllUnderstood = FALSE;
03302 TRACEUSER( "Jonathan", _T("INVERTREGION\n"));
03303 break;
03304
03305 case META_PAINTREGION:
03306 AllUnderstood = FALSE;
03307 TRACEUSER( "Jonathan", _T("PAINTREGION\n"));
03308 break;
03309
03310 case META_SELECTCLIPREGION:
03311 AllUnderstood = FALSE;
03312 TRACEUSER( "Jonathan", _T("SELECTCLIPREGION\n"));
03313 break;
03314
03315
03316
03317 case META_SAVEDC:
03318
03319 break;
03320
03321 case META_RESTOREDC:
03322
03323 break;
03324
03325 case META_SETROP2:
03326
03327 if ( ((INT32)pMetaRec->rdParm[0]) != R2_COPYPEN)
03328 TRACEUSER( "Jonathan", _T("SetROP2 - Not Copy Pen!\n"));
03329 break;
03330
03331
03332
03333 case META_EXCLUDECLIPRECT:
03334
03335 break;
03336
03337 case META_INTERSECTCLIPRECT:
03338
03339 break;
03340
03341 case META_OFFSETCLIPRGN:
03342
03343 break;
03344
03345
03346
03347 case META_SETMAPPERFLAGS:
03348 AllUnderstood = FALSE;
03349 TRACEUSER( "Jonathan", _T("SETMAPPERFLAGS\n"));
03350 break;
03351
03352
03353
03354 case META_SETBKCOLOR:
03355
03356 break;
03357
03358 case META_SETBKMODE:
03359
03360 break;
03361
03362 case META_SETMAPMODE:
03363 CurrentMappingMode = (INT32) ((INT16) pMetaRec->rdParm[0]);
03364 TRACEUSER( "Jonathan", _T("SetMapMode: %d\n"), CurrentMappingMode);
03365 break;
03366
03367 case META_SETRELABS:
03368
03369
03370
03371
03372 TRACEUSER( "Jonathan", _T("SETRELABS\n"));
03373 break;
03374
03375 default:
03376 TRACEUSER( "Jonathan", _T("Unknown Function %x\n"), pMetaRec->rdFunction);
03377 return FALSE;
03378 break;
03379 }
03380
03381
03382 return 1;
03383 }
03384
03385
03386
03387
03388
03389
03390
03391
03392
03393
03394
03395
03396
03397
03398 void MetaFileFilter::TransformCoord(DocCoord *C)
03399 {
03400
03401 C->x -= MetaFileOrigin.x;
03402 C->y -= MetaFileOrigin.y;
03403
03404
03405 C->y += YShift;
03406
03407
03408 ScaleCoord(C);
03409 }
03410
03411
03412
03413
03414
03415
03416
03417
03418
03419
03420
03421
03422
03423 void MetaFileFilter::ScaleCoord(DocCoord *C)
03424 {
03425
03426 if (Placeable)
03427 {
03428
03429 C->x *= ScaleFactor;
03430 C->y *= ScaleFactor;
03431 }
03432 else
03433 {
03434 switch (CurrentMappingMode)
03435 {
03436 case MM_TEXT:
03437
03438
03439 C->x *= ScaleFactor;
03440 C->y *= ScaleFactor;
03441 break;
03442
03443 case MM_LOMETRIC:
03444
03445
03446 C->x *= (72000 / 254);
03447 C->y *= (72000 / 254);
03448 break;
03449
03450 case MM_HIMETRIC:
03451
03452
03453 C->x *= (72000 / 2540);
03454 C->y *= (72000 / 2540);
03455 break;
03456
03457 case MM_LOENGLISH:
03458
03459
03460 C->x *= (72000 / 100);
03461 C->y *= (72000 / 100);
03462 break;
03463
03464 case MM_HIENGLISH:
03465
03466
03467 C->x *= (72000 / 1000);
03468 C->y *= (72000 / 1000);
03469 break;
03470
03471 case MM_TWIPS:
03472
03473
03474 C->x *= (72000 / 1440);
03475 C->y *= (72000 / 1440);
03476 break;
03477
03478
03479
03480
03481
03482
03483
03484
03485
03486 default:
03487 C->x *= ScaleFactor;
03488 C->y *= ScaleFactor;
03489 break;
03490 }
03491 }
03492
03493
03494 if (FlipYCoords)
03495 C->y = -C->y;
03496 }
03497
03498
03499
03500
03501
03502
03503
03504
03505
03506
03507
03508
03509
03510
03511
03512
03513
03514
03515 BOOL MetaFileFilter::AddAttributes(Node* pNewNode)
03516 {
03517
03518 if (pNewNode->IS_KIND_OF(NodePath))
03519 {
03520 NodePath* pPath = (NodePath*) pNewNode;
03521 if (!pPath->InkPath.IsFilled)
03522 CurrentAttrs[ATTR_FILLGEOMETRY].Ignore = TRUE;
03523 }
03524
03525
03526 BOOL Result = AttributeManager::ApplyBasedOnDefaults(pNewNode, CurrentAttrs);
03527
03528
03529 CurrentAttrs[ATTR_FILLGEOMETRY].Ignore = FALSE;
03530
03531
03532 return Result;
03533 }
03534
03535
03536
03537
03538
03539
03540
03541
03542
03543
03544
03545
03546
03547
03548
03549
03550 BOOL MetaFileFilter::DoExport(Operation*, CCLexFile* pFile, PathName* pPath, Document* pDoc,
03551 BOOL ShowOptions)
03552 {
03553
03554
03555
03556 if (!pFile->isOpen())
03557 {
03558 if (pFile->IsKindOf(CC_RUNTIME_CLASS(CCDiskFile)))
03559 {
03560 BOOL ok = OpenExportFile((CCDiskFile*) pFile, pPath);
03561 if (!ok) return FALSE;
03562 }
03563 else
03564 {
03565 TRACEUSER( "JustinF", _T("Tried to open non-CCDiskFile in MetaFileFilter::DoExport\n"));
03566 return FALSE;
03567 }
03568 }
03569
03570
03571 Spread* pSpread = GetFirstSpread(pDoc);
03572 ExportClipRect.MakeEmpty();
03573
03574
03575
03576 if (!PrepareToExport(pFile, pSpread))
03577 {
03578 CleanUpAfterExport();
03579 return FALSE;
03580 }
03581
03582
03583 MetafileDC.SetMapMode(pMetaView->GetMetafileMapMode());
03584
03585
03586 BOOL ok = ExportRender(ExportRegion);
03587 HMETAFILE hMetafile = NULL;
03588
03589
03590 if (ok)
03591 {
03592
03593 hMetafile = MetafileDC.Close();
03594 if (hMetafile == NULL)
03595 {
03596 ERROR1RAW( _R(IDE_MF_NOCLOSE) );
03597 ok = FALSE;
03598 }
03599 }
03600
03601
03602 if (!ok)
03603 {
03604 if (hMetafile) DeleteMetaFile(hMetafile);
03605 CleanUpAfterExport();
03606 return FALSE;
03607 }
03608
03609
03610
03611 String_64 ProgressString(_R(IDT_EXPORTMSG_METAFILE2));
03612 ProgressString = GetExportProgressString(pFile, _R(IDT_EXPORTMSG_METAFILE2));
03613 BeginSlowJob(100, FALSE, &ProgressString);
03614
03615
03616 METAFILEHEADER Header;
03617 Header.key = METAFILEHEADERKEY;
03618 Header.hmf = 0;
03619 Header.inch = pMetaView->GetMetafileDPI();
03620 Header.reserved = 0L;
03621 Header.checksum = 0;
03622
03623
03624 FIXED16 PixelSize;
03625 pMetaView->GetPixelSize(&PixelSize, &PixelSize);
03626 INT32 Size = PixelSize.MakeLong();
03627 Header.bbox.left = (short) (ExportClipRect.lo.x / Size);
03628 Header.bbox.top = (short) (ExportClipRect.lo.y / Size);
03629 Header.bbox.right = (short) (ExportClipRect.hi.x / Size);
03630 Header.bbox.bottom = (short) (ExportClipRect.hi.y / Size);
03631
03632
03633 LPWORD p = (LPWORD) &Header;
03634 INT32 i = 10;
03635 while (i--)
03636 {
03637
03638 Header.checksum ^= *p++;
03639 }
03640
03641
03642 ok = WriteToFile( hMetafile, &Header );
03643 DeleteMetaFile( hMetafile );
03644
03645
03646
03647 CleanUpAfterExport();
03648 EndSlowJob();
03649
03650
03651 return ok;
03652 }
03653
03654
03655
03656
03657
03658
03659
03660
03661
03662
03663
03664
03665
03666
03667
03668 BOOL MetaFileFilter::DoExport(Operation*, CCLexFile* pFile, Document* pDoc, METAFILEPICT* pMetaInfo)
03669 {
03670
03671 Spread *pSpread = GetFirstSpread(pDoc);
03672 ExportClipRect.MakeEmpty();
03673
03674
03675
03676 if (!PrepareToExport(NULL, pSpread))
03677 {
03678 CleanUpAfterExport();
03679 return FALSE;
03680 }
03681
03682
03683 MetafileDC.SetMapMode(pMetaView->GetMetafileMapMode());
03684 pMetaInfo->mm = pMetaView->GetMetafileMapMode();
03685
03686
03687 BOOL ok = ExportRender(ExportRegion);
03688 HMETAFILE hMetafile = NULL;
03689
03690 if (ok)
03691 {
03692
03693 hMetafile = MetafileDC.Close();
03694 if (hMetafile==NULL)
03695 {
03696 ERROR1RAW(_R(IDE_MF_NOCLOSE));
03697 ok = FALSE;
03698 }
03699 }
03700
03701
03702 if (!ok)
03703 {
03704
03705 if (hMetafile)
03706 DeleteMetaFile(hMetafile);
03707
03708
03709 CleanUpAfterExport();
03710 return FALSE;
03711 }
03712
03713
03714 String_64 ProgressString(_R(IDT_EXPORTMSG_METAFILE2));
03715 ProgressString = GetExportProgressString(pFile, _R(IDT_EXPORTMSG_METAFILE2));
03716 BeginSlowJob(100, FALSE, &ProgressString);
03717
03718
03719
03720 FIXED16 PixelSize;
03721 pMetaView->GetPixelSize(&PixelSize, &PixelSize);
03722 INT32 Size = PixelSize.MakeLong();
03723 pMetaInfo->xExt = ExportClipRect.Width() / Size;
03724 pMetaInfo->yExt = ExportClipRect.Height() / Size;
03725 pMetaInfo->hMF = hMetafile;
03726
03727
03728
03729 CleanUpAfterExport();
03730 EndSlowJob();
03731
03732 return ok;
03733 }
03734
03735
03736
03737
03738
03739
03740
03741
03742
03743
03744
03745
03746 BOOL MetaFileFilter::PrepareToExport(CCLexFile* pFile, Spread* pSpread)
03747 {
03748
03749
03750 OutputFile = pFile;
03751
03752
03753
03754 DocRect SpreadRect;
03755 SpreadRect.MakeEmpty();
03756
03757
03758 Node* pNode = pSpread->FindFirstChild();
03759 while (pNode!=NULL)
03760 {
03761
03762 if (IS_A(pNode, Layer))
03763 {
03764
03765 Layer* pLayer = (Layer*) pNode;
03766 if (pLayer->IsVisible())
03767 {
03768
03769 DocRect LayerRect = pLayer->GetBoundingRect();
03770 SpreadRect = SpreadRect.Union(LayerRect);
03771 }
03772 }
03773
03774
03775 pNode = pNode->FindNext();
03776 }
03777
03778
03779 DocRect ClipRect = SpreadRect;
03780 ExportClipRect = SpreadRect;
03781
03782
03783
03784
03785
03786 pMetaView = new MetafileView();
03787 if (pMetaView==NULL)
03788 return FALSE;
03789
03790
03791 if (!pMetaView->Init())
03792 {
03793 delete pMetaView;
03794 pMetaView = NULL;
03795 return FALSE;
03796 }
03797
03798
03799 FIXED16 XScale, YScale;
03800 pMetaView->GetScaleFactor(&XScale, &YScale);
03801 Matrix Identity(XScale, YScale);
03802
03803
03804 FIXED16 Scale(1);
03805
03806
03807 ExportRegion = OSRenderRegion::Create(ClipRect, Identity, Scale, RENDERTYPE_METAFILE16, pMetaView, TRUE );
03808 if (ExportRegion == NULL)
03809
03810 return FALSE;
03811
03812
03813 if (!MetafileDC.Create( NULL ))
03814 ERROR1( FALSE, _R(IDE_MF_NOCREATE) );
03815
03816
03817
03818 if (!ReferenceDC.CreateIC( "DISPLAY", NULL, NULL, NULL ))
03819 ERROR1( FALSE, _R(IDE_MF_NOCREATE) );
03820
03821
03822 MetafileDC.SetAttribDC( ReferenceDC.m_hDC );
03823
03824
03825 MetafileDC.m_bPrinting = TRUE;
03826
03827
03828 return ExportRegion->AttachDevice(pMetaView, &MetafileDC, pSpread);
03829 }
03830
03831
03832
03833
03834
03835
03836
03837
03838
03839 void MetaFileFilter::CleanUpAfterExport()
03840 {
03841
03842 if (pMetaView!=NULL)
03843 {
03844 delete pMetaView;
03845 pMetaView = NULL;
03846 }
03847
03848
03849 if (MetafileDC.m_hDC)
03850 {
03851 MetafileDC.DeleteDC();
03852 }
03853
03854
03855 if (ReferenceDC.m_hDC)
03856 {
03857 ReferenceDC.DeleteDC();
03858 }
03859
03860
03861 if (OutputFile)
03862 {
03863 OutputFile->close();
03864
03865 OutputFile = NULL;
03866 }
03867 }
03868
03869
03870
03871
03872
03873
03874
03875
03876
03877
03878
03879 BOOL MetaFileFilter::WriteToFile( HMETAFILE hMetafile, METAFILEHEADER *PlaceableHeader )
03880 {
03881
03882 OutputFile->write( PlaceableHeader, sizeof(METAFILEHEADER) );
03883
03884
03885 UINT32 size = GetMetaFileBitsEx( hMetafile, 0, NULL );
03886 ERROR1IF( size==0, FALSE, _R(IDE_MF_NOMEMLOCK) );
03887
03888 LPVOID block = CCMalloc( size );
03889 ERROR1IF( block==NULL, FALSE, _R(IDS_OUT_OF_MEMORY) );
03890
03891 size = GetMetaFileBitsEx( hMetafile, size, block );
03892 if (size)
03893 {
03894 OutputFile->write( block, size );
03895 CCFree( block );
03896 return TRUE;
03897 }
03898 else
03899 {
03900 CCFree( block );
03901 ERROR1( FALSE, _R(IDE_MF_NOMEMLOCK) );
03902 }
03903 }
03904
03906
03907
03908
03909
03910
03911
03912
03913