00001
00002
00003
00004
00005
00006
00007
00008
00009
00010
00011
00012
00013
00014
00015
00016
00017
00018
00019
00020
00021
00022
00023
00024
00025
00026
00027
00028
00029
00030
00031
00032
00033
00034
00035
00036
00037
00038
00039
00040
00041
00042
00043
00044
00045
00046
00047
00048
00049
00050
00051
00052
00053
00054
00055
00056
00057
00058
00059
00060
00061
00062
00063
00064
00065
00066
00067
00068
00069
00070
00071
00072
00073
00074
00075
00076
00077
00078
00079
00080
00081
00082
00083
00084
00085
00086
00087
00088
00089
00090
00091
00092
00093
00094
00095
00096
00097
00098
00099
00100
00101
00102
00103 #include "camtypes.h"
00104 #include "freeeps.h"
00105
00106
00107
00108
00109 #include "colcomp.h"
00110 #include "colourix.h"
00111 #include "collist.h"
00112
00113 #include "nodepath.h"
00114
00115 DECLARE_SOURCE("$Revision: 1314 $");
00116
00117 CC_IMPLEMENT_DYNAMIC(FreeHandEPSFilter, EPSFilter)
00118
00119 #define new CAM_DEBUG_NEW
00120
00121
00122 enum
00123 {
00124
00125 EPSC_Xa = EPSC_EOF + 1,
00126 EPSC_xa,
00127 EPSC_Ka,
00128 EPSC_ka,
00129
00130
00131 EPSC_radfill,
00132 EPSC_recfill,
00133 EPSC_load,
00134
00135
00136 EPSC_BeginSetup,
00137 EPSC_def,
00138 EPSC_newcmykcustomcolor,
00139
00140
00141 EPSC_makesetfont,
00142 EPSC_ts,
00143 EPSC_sts,
00144
00145
00146 EPSC_eomode,
00147 EPSC_true,
00148 EPSC_false,
00149
00150
00151 EPSC_concat,
00152 EPSC_vms,
00153 EPSC_vmr,
00154 EPSC_vmrs,
00155 EPSC_stob,
00156 EPSC_fhsetspreadallow,
00157 EPSC_FREEHAND_IGNOREDTOKEN
00158 };
00159
00160
00161 CommandMap FreeHandEPSFilter::FHCommands[] =
00162 {
00163
00164 { EPSC_Xa, _T("Xa") },
00165 { EPSC_xa, _T("xa") },
00166 { EPSC_Ka, _T("Ka") },
00167 { EPSC_ka, _T("ka") },
00168
00169
00170 { EPSC_radfill, _T("radfill") },
00171 { EPSC_recfill, _T("recfill") },
00172 { EPSC_load, _T("load") },
00173
00174
00175 { EPSC_BeginSetup, _T("%%BeginSetup")},
00176 { EPSC_def, _T("def") },
00177 { EPSC_newcmykcustomcolor, _T("newcmykcustomcolor") },
00178
00179
00180 { EPSC_makesetfont, _T("makesetfont") },
00181 { EPSC_ts, _T("ts") },
00182 { EPSC_sts, _T("sts") },
00183
00184
00185 { EPSC_eomode, _T("eomode") },
00186 { EPSC_true, _T("true") },
00187 { EPSC_false, _T("false") },
00188
00189
00190 { EPSC_concat, _T("concat") },
00191 { EPSC_vms, _T("vms") },
00192 { EPSC_vmr, _T("vmr") },
00193 { EPSC_vmrs, _T("vmrs") },
00194 { EPSC_stob, _T("stob") },
00195 { EPSC_fhsetspreadallow, _T("fhsetspreadallow") },
00196
00197
00198 { EPSC_Invalid, _T("Invalid") }
00199 };
00200
00201
00202
00203
00204
00205
00206
00207
00208
00209
00210
00211
00212
00213 FreeHandEPSFilter::FreeHandEPSFilter()
00214 {
00215
00216 FilterNameID = _R(IDT_FREEHANDEPS_FILTERNAME);
00217 FilterInfoID = _R(IDT_FREEHANDEPS_FILTERINFO);
00218 ImportMsgID = _R(IDT_IMPORTMSG_FREEHANDEPS);
00219
00220 FilterID = FILTERID_FREEHAND_EPS;
00221
00222 Flags.CanImport = TRUE;
00223 Flags.CanExport = FALSE;
00224
00225 AdjustOrigin = FALSE;
00226 }
00227
00228
00229
00230
00231
00232
00233
00234
00235
00236
00237
00238
00239
00240
00241 BOOL FreeHandEPSFilter::Init()
00242 {
00243
00244 pOILFilter = new FreeHandEPSOILFilter(this);
00245 if (pOILFilter == NULL)
00246 return FALSE;
00247
00248
00249 FilterName.Load(FilterNameID);
00250 FilterInfo.Load(FilterInfoID);
00251
00252
00253 return TRUE;
00254 }
00255
00256
00257
00258
00259
00260
00261
00262
00263
00264
00265
00266
00267
00268 BOOL FreeHandEPSFilter::PrepareToImport()
00269 {
00270 if(!EPSFilter::PrepareToImport())
00271 return FALSE;
00272
00273
00274 HadhToken = FALSE;
00275 DoingGradFill = FALSE;
00276 OldFill = 0;
00277 InColours = FALSE;
00278 InText = FALSE;
00279 ComplexPathMode = FALSE;
00280 pLastPathSeen = 0;
00281
00282
00283 ClipRegion.SetClippingFlags(2);
00284
00285
00286 pNewColours = new ImportedColours(pColours, FALSE);
00287 if(pNewColours == 0 || !pNewColours->Init())
00288 return FALSE;
00289
00290
00291 ColourArray = (IndexedColour **)CCMalloc(FHEF_COLOURARRAY_INITIALSIZE * sizeof(IndexedColour *));
00292 if(ColourArray == 0)
00293 {
00294 delete pNewColours;
00295 pNewColours = 0;
00296 return FALSE;
00297 }
00298 ColourArrayEntries = 0;
00299 ColourArraySize = FHEF_COLOURARRAY_INITIALSIZE;
00300
00301 return TRUE;
00302 }
00303
00304
00305
00306
00307
00308
00309
00310
00311
00312
00313
00314
00315
00316 void FreeHandEPSFilter::CleanUpAfterImport(BOOL Successful)
00317 {
00318
00319 if(OldFill != 0)
00320 delete OldFill;
00321
00322 OldFill = 0;
00323
00324
00325 if(Successful)
00326 {
00327 pNewColours->AddColoursToDocument();
00328 }
00329 else
00330 {
00331 pNewColours->DestroyColours();
00332 }
00333
00334
00335 if(ColourArray != 0)
00336 {
00337 CCFree(ColourArray);
00338 ColourArray = 0;
00339 }
00340
00341
00342 Stack.DeleteAll ();
00343
00344 EPSFilter::CleanUpAfterImport(Successful);
00345 }
00346
00347
00348
00349
00350
00351
00352
00353
00354
00355
00356
00357
00358
00359
00360 INT32 FreeHandEPSFilter::EPSHeaderIsOk(ADDR pFileHeader, UINT32 HeaderSize)
00361 {
00362
00363 if (strncmp((char *) pFileHeader, "%!PS-Adobe", 10) != 0)
00364 {
00365
00366 return 0;
00367 }
00368
00369
00370 TCHAR *Buffer;
00371 CCMemTextFile HeaderFile((char *)pFileHeader, HeaderSize);
00372 if(HeaderFile.IsMemFileInited() == FALSE || HeaderFile.InitLexer() == FALSE)
00373 {
00374 HeaderFile.close();
00375 return 0;
00376 }
00377
00378
00379 BOOL HaveCreatorString = FALSE;
00380
00381 UINT32 Lines = 0;
00382 while ((Lines < 20) && !HeaderFile.eof())
00383 {
00384 HeaderFile.GetLineToken();
00385 Buffer = (TCHAR *)HeaderFile.GetTokenBuf();
00386 ERROR2IF(Buffer == 0, 0, "Returned buffer from lex file == 0");
00387 Lines++;
00388
00389
00390
00391 if (camStrncmp( (const TCHAR *)Buffer, _T("%%Creator: "), 11) == 0 &&
00392 camStrstr( (const TCHAR*)Buffer, _T("FreeHand")) != 0)
00393 {
00394
00395
00396 HaveCreatorString = TRUE;
00397 }
00398
00399 if (camStrncmp(Buffer, _T("%%DocumentProcSets: FreeHand_header 3 "), 38) == 0 && HaveCreatorString)
00400 {
00401
00402 HeaderFile.close();
00403 return 10;
00404 }
00405
00406
00407
00408 if (camStrncmp(Buffer, _T("%%Compression:"), 14)==0)
00409 break;
00410 }
00411
00412 HeaderFile.close();
00413
00414 return 0;
00415 }
00416
00417
00418
00419
00420
00421
00422
00423
00424
00425
00426
00427
00428
00429
00430
00431 void FreeHandEPSFilter::LookUpToken()
00432 {
00433
00434
00435 INT32 i = 0;
00436 while (FHCommands[i].Cmd != EPSC_Invalid)
00437 {
00438 if (camStrcmp(TokenBuf, FHCommands[i].CmdStr) == 0)
00439 {
00440
00441 Token = FHCommands[i].Cmd;
00442 return;
00443 }
00444
00445 i++;
00446 }
00447
00448
00449 EPSFilter::LookUpToken();
00450 }
00451
00452
00453
00454
00455
00456
00457
00458
00459
00460
00461
00462
00463
00464
00465
00466
00467
00468 #define FHEF_SENDh { if(pPath != 0) { \
00469 EPSCommand ThisToken = Token; \
00470 Token = ComplexPathMode?EPSC_s:EPSC_h; \
00471 if(!EPSFilter::ProcessToken()) \
00472 return FALSE; \
00473 Token = ThisToken; \
00474 HadhToken = FALSE; } }
00475
00476
00477 BOOL FreeHandEPSFilter::ProcessToken()
00478 {
00479
00480 switch (Token)
00481 {
00482
00483 case EPSC_vms:
00484 if(!Import_gsave())
00485 return FALSE;
00486 break;
00487
00488 case EPSC_vmr:
00489 if(!Import_grestore())
00490 return FALSE;
00491 break;
00492
00493 case EPSC_vmrs:
00494 if(!Import_grestore())
00495 return FALSE;
00496 if(!Import_gsave())
00497 return FALSE;
00498 break;
00499
00500
00501 case EPSC_FREEHAND_IGNOREDTOKEN:
00502 break;
00503
00504
00505 case EPSC_load:
00506 case EPSC_fhsetspreadallow:
00507 if(!Stack.Discard(1))
00508 goto EPSError;
00509 break;
00510
00511 case EPSC_concat:
00512 if(!Stack.DiscardArray())
00513 goto EPSError;
00514 break;
00515
00516
00517 case EPSC_eomode:
00518 {
00519 INT32 ComplexStart;
00520
00521 if(!Stack.Pop(&ComplexStart))
00522 goto EPSError;
00523
00524
00525 if(ComplexStart != TRUE)
00526 {
00527 ComplexPathMode = FALSE;
00528 }
00529 else
00530 {
00531 HadFirstOfComplexPath = FALSE;
00532 ComplexPathMode = TRUE;
00533 }
00534 }
00535 break;
00536
00537 case EPSC_true:
00538 Stack.Push((INT32)TRUE);
00539 break;
00540
00541 case EPSC_false:
00542 Stack.Push((INT32)FALSE);
00543 break;
00544
00545 case EPSC_u:
00546 HadFirstOfComplexPath = FALSE;
00547 return EPSFilter::ProcessToken();
00548 break;
00549
00550
00551 case EPSC_Ka:
00552 case EPSC_ka:
00553 {
00554 DocColour Colour;
00555
00556 if(PopColour(&Colour))
00557 {
00558
00559 if (Token == EPSC_ka)
00560 {
00561 if (!SetFillColour(Colour))
00562 goto NoMemory;
00563 }
00564 else
00565 {
00566 if (!SetLineColour(Colour))
00567 goto NoMemory;
00568 }
00569 }
00570 else
00571
00572 goto EPSError;
00573 }
00574 break;
00575
00576 case EPSC_Xa:
00577 case EPSC_xa:
00578 {
00579 DocColour Colour;
00580
00581 if(PopNamedColour(&Colour))
00582 {
00583
00584 if (Token == EPSC_xa)
00585 {
00586 if (!SetFillColour(Colour))
00587 goto NoMemory;
00588 }
00589 else
00590 {
00591 if (!SetLineColour(Colour))
00592 goto NoMemory;
00593 }
00594 }
00595 else
00596
00597 goto EPSError;
00598 }
00599 break;
00600
00601 case EPSC_H:
00602 if(ComplexPathMode)
00603 {
00604
00605 Token = EPSC_S;
00606 }
00607 return EPSFilter::ProcessToken();
00608 break;
00609
00610 case EPSC_h:
00611 if(ComplexPathMode)
00612 {
00613
00614 Token = EPSC_s;
00615 return EPSFilter::ProcessToken();
00616 break;
00617 }
00618
00619
00620 HadhToken = TRUE;
00621 break;
00622
00623
00624 case EPSC_q:
00625
00626 if(DoingGradFill)
00627 {
00628 if(pPath != 0)
00629 {
00630
00631 NodePath *pPathClone;
00632
00633 if(!pPath->NodeCopy((Node **)&pPathClone))
00634 {
00635 goto NoMemory;
00636 }
00637
00638
00639 EPSFlagsDefn EPSFlagsClone = EPSFlags;
00640
00641
00642 Token = (pInkPath->IsFilled)?EPSC_f:EPSC_s;
00643 if(!EPSFilter::ProcessToken())
00644 return FALSE;
00645
00646
00647 if(!RestoreCurrentFill())
00648 goto NoMemory;
00649
00650
00651 pPath = pPathClone;
00652 pInkPath = &pPath->InkPath;
00653
00654
00655 EPSFlags = EPSFlagsClone;
00656
00657
00658 HadhToken = TRUE;
00659 }
00660
00661
00662 DoingGradFill = FALSE;
00663
00664
00665 Token = EPSC_q;
00666 }
00667
00668
00669 if(HadhToken)
00670 FHEF_SENDh
00671
00672
00673 return EPSFilter::ProcessToken();
00674 break;
00675
00676
00677 case EPSC_W:
00678 if(pPath == 0)
00679 {
00680
00681 if(pLastPathSeen == 0)
00682 goto EPSError;
00683
00684
00685 NodePath *pClone;
00686
00687 if(!pLastPathSeen->NodeCopy((Node **)&pClone))
00688 goto NoMemory;
00689
00690
00691 pClone->DeleteChildren(pClone->FindFirstChild());
00692
00693
00694 pPath = pClone;
00695 pInkPath = &pPath->InkPath;
00696 ThePathType = PATH_NORMAL;
00697 EPSFlags.NoAttributes = TRUE;
00698 }
00699 if(pPath != 0)
00700 return EPSFilter::ProcessToken();
00701 break;
00702
00703
00704 case EPSC_s:
00705 case EPSC_S:
00706 if(Token == EPSC_S)
00707 {
00708
00709 if(HadhToken)
00710 FHEF_SENDh
00711
00712
00713 if(DoingGradFill)
00714 Token = EPSC_b;
00715 }
00716
00717
00718 HadhToken = FALSE;
00719 return EPSFilter::ProcessToken();
00720 break;
00721
00722
00723 case EPSC_n:
00724 if(DoingGradFill)
00725 {
00726 Token = EPSC_f;
00727 HadhToken = FALSE;
00728 return EPSFilter::ProcessToken();
00729 break;
00730 }
00731 HadhToken = FALSE;
00732
00733 if(pPath != 0)
00734 return EPSFilter::ProcessToken();
00735 break;
00736
00737
00738 case EPSC_N:
00739 case EPSC_F:
00740 case EPSC_f:
00741 case EPSC_B:
00742 case EPSC_b:
00743 HadhToken = FALSE;
00744 return EPSFilter::ProcessToken();
00745 break;
00746
00747
00748 case EPSC_m:
00749 if(InText)
00750 {
00751
00752 if(!Stack.Discard(2))
00753 goto EPSError;
00754
00755 break;
00756 }
00757 case EPSC_l:
00758 case EPSC_L:
00759 case EPSC_c:
00760 case EPSC_C:
00761 case EPSC_v:
00762 case EPSC_V:
00763 case EPSC_y:
00764 case EPSC_Y:
00765
00766 if(HadhToken)
00767 FHEF_SENDh
00768
00769
00770 if(DoingGradFill)
00771 {
00772
00773 DoingGradFill = FALSE;
00774
00775
00776 RestoreCurrentFill();
00777 }
00778 return EPSFilter::ProcessToken();
00779 break;
00780
00781
00782 case EPSC_recfill:
00783 {
00784
00785 DocColour StartColour, EndColour;
00786
00787 if(!PopColour(&EndColour) ||
00788 !PopColour(&StartColour))
00789 goto EPSError;
00790
00791
00792 if(!DiscardFillSubType())
00793 goto EPSError;
00794
00795
00796 DocCoord Centre;
00797 double Angle;
00798 DocRect BBox;
00799 if(!Stack.PopCoordPair(&BBox.hi) ||
00800 !Stack.PopCoordPair(&BBox.lo) ||
00801 !Stack.Pop(&Angle) ||
00802 !Stack.PopCoordPair(&Centre))
00803 goto EPSError;
00804
00805
00806 Angle += 225;
00807 Angle = (Angle * (2 * PI)) / 360;
00808
00809
00810 if(pPath != 0)
00811 {
00812 BBox = pPath->GetBoundingRect();
00813 Centre.x = BBox.lo.x + (BBox.Width() / 2);
00814 Centre.y = BBox.lo.y + (BBox.Height() / 2);
00815 }
00816
00817
00818 BBox.Translate(0 - Centre.x, 0 - Centre.y);
00819 DocCoord StartPoint, EndPoint;
00820
00821 StartPoint.x = Centre.x + (INT32)(((double)BBox.lo.x * cos(Angle)) - ((double)BBox.lo.y * sin(Angle)));
00822 StartPoint.y = Centre.y + (INT32)(((double)BBox.lo.x * sin(Angle)) + ((double)BBox.lo.y * cos(Angle)));
00823 EndPoint.x = Centre.x + (INT32)(((double)BBox.hi.x * cos(Angle)) - ((double)BBox.hi.y * sin(Angle)));
00824 EndPoint.y = Centre.y + (INT32)(((double)BBox.hi.x * sin(Angle)) + ((double)BBox.hi.y * cos(Angle)));
00825
00826
00827 SaveCurrentFill();
00828
00829
00830 if(!SetLinearFill(StartColour, EndColour, StartPoint, EndPoint))
00831 goto NoMemory;
00832
00833
00834 DoingGradFill = TRUE;
00835 HadhToken = FALSE;
00836 }
00837 break;
00838
00839 case EPSC_radfill:
00840 {
00841
00842 DocColour StartColour, EndColour;
00843
00844 if(!PopColour(&StartColour) ||
00845 !PopColour(&EndColour))
00846 goto EPSError;
00847
00848
00849 DocCoord Centre;
00850 INT32 Radius;
00851 if(!Stack.PopCoord(&Radius) ||
00852 !Stack.PopCoordPair(&Centre))
00853 goto EPSError;
00854
00855
00856 SaveCurrentFill();
00857
00858
00859 DocCoord EndPoint(Centre.x + Radius, Centre.y);
00860 if(!SetRadialFill(StartColour, EndColour, Centre, EndPoint))
00861 goto NoMemory;
00862
00863
00864 DoingGradFill = TRUE;
00865 HadhToken = FALSE;
00866 }
00867 break;
00868
00869 case EPSC_BeginSetup:
00870
00871 {
00872 BOOL Found = FALSE;
00873
00874 while(Found == FALSE)
00875 {
00876 if(!EPSFile->GetToken())
00877 return FALSE;
00878
00879 if(EPSFile->GetTokenType() == TOKEN_NORMAL)
00880 {
00881 if(camStrcmp(TokenBuf, _T("spots")) == 0)
00882 {
00883
00884 if(!EPSFile->GetToken())
00885 return FALSE;
00886
00887 if(TokenBuf[0] == '[')
00888 {
00889 TRACEUSER( "Ben", _T("Found spots\n"));
00890 Found = TRUE;
00891 }
00892 }
00893 }
00894
00895 if(camStrncmp(TokenBuf, _T("%%EndSetup"), 10) == 0)
00896 {
00897 TRACEUSER( "Ben", _T("Met end of setup without finding spots\n"));
00898 break;
00899 }
00900
00901 if(EPSFile->eof())
00902 goto EPSError;
00903 }
00904
00905 if(Found == TRUE)
00906 {
00907 InColours = TRUE;
00908 }
00909 }
00910 break;
00911
00912 case EPSC_def:
00913 if(InColours)
00914 {
00915
00916 TRACEUSER( "Ben", _T("Finished spot colours\n"));
00917
00918 BOOL Found = FALSE;
00919
00920 while(Found == FALSE)
00921 {
00922 if(!EPSFile->GetToken())
00923 return FALSE;
00924
00925 if(EPSFile->GetTokenType() == TOKEN_COMMENT)
00926 {
00927 if(camStrncmp(TokenBuf, _T("%%EndSetup"), 10) == 0)
00928 {
00929 TRACEUSER( "Ben", _T("Found end of setup\n"));
00930 Found = TRUE;
00931 }
00932 }
00933
00934 if(EPSFile->eof())
00935 goto EPSError;
00936 }
00937
00938
00939 EPSCommand Ignored;
00940 Stack.PopCmd(&Ignored);
00941
00942
00943 Stack.DeleteAll ();
00944 InColours = FALSE;
00945 }
00946 else
00947 {
00948
00949 Stack.DeleteAll ();
00950 }
00951 break;
00952
00953 case EPSC_newcmykcustomcolor:
00954
00955 {
00956
00957 if(!Stack.Discard())
00958 goto EPSError;
00959
00960
00961 String_64 ColourName;
00962 if(!Stack.Pop(&ColourName))
00963 goto EPSError;
00964
00965
00966 double C, M, Y, K;
00967 if(!Stack.Pop(&K) ||
00968 !Stack.Pop(&Y) ||
00969 !Stack.Pop(&M) ||
00970 !Stack.Pop(&C))
00971 goto EPSError;
00972
00973
00974 ColourCMYK Colour;
00975 Colour.Cyan = C;
00976 Colour.Magenta = M;
00977 Colour.Yellow = Y;
00978 Colour.Key = K;
00979
00980
00981 if(!pNewColours->AddColour(&ColourName, &Colour))
00982 goto NoMemory;
00983
00984
00985
00986 IndexedColour *TheNewColour = pNewColours->GetColour(ColourName);
00987
00988 if(TheNewColour == 0)
00989 goto NoMemory;
00990
00991
00992
00993 if((ColourArrayEntries + 1) >= ColourArraySize)
00994 {
00995 TRACEUSER( "Ben", _T("Extening colour array\n"));
00996 IndexedColour **NewPtr = (IndexedColour **)CCRealloc(ColourArray, (ColourArraySize + FHEF_COLOURARRAY_CHUNK) * sizeof(IndexedColour *));
00997
00998 if(NewPtr == 0)
00999 goto NoMemory;
01000
01001 ColourArray = NewPtr;
01002 ColourArraySize += FHEF_COLOURARRAY_CHUNK;
01003 }
01004
01005
01006 ColourArray[ColourArrayEntries] = TheNewColour;
01007 ColourArrayEntries++;
01008 }
01009 break;
01010
01011
01012 case EPSC_makesetfont:
01013 if(!Stack.DiscardArray())
01014 goto EPSError;
01015 if(!Stack.Discard(1))
01016 goto EPSError;
01017 InText = TRUE;
01018 break;
01019
01020 case EPSC_ts:
01021 if(!Stack.Discard(6))
01022 goto EPSError;
01023 break;
01024
01025 case EPSC_stob:
01026 case EPSC_sts:
01027 Stack.DeleteAll ();
01028 InText = FALSE;
01029 break;
01030
01031 default:
01032
01033 return EPSFilter::ProcessToken();
01034 }
01035
01036
01037
01038 return TRUE;
01039
01040
01041
01042 EPSError:
01043 HandleEPSError();
01044 return FALSE;
01045
01046 NoMemory:
01047 HandleNoMemory();
01048 return FALSE;
01049 }
01050
01051
01052
01053
01054
01055
01056
01057
01058
01059
01060
01061
01062
01063 BOOL FreeHandEPSFilter::DiscardFillSubType()
01064 {
01065 BOOL Done = FALSE;
01066 EPSType Type;
01067 while(Done == FALSE)
01068 {
01069 Type = Stack.GetType();
01070 if(Type == EPSTYPE_NONE)
01071 {
01072
01073 return FALSE;;
01074 }
01075 else if(Type == EPSTYPE_STRING)
01076 {
01077
01078 String_64 Str;
01079 if(!Stack.Pop(&Str))
01080 return FALSE;
01081 if(camStrcmp(Str, _T("{")) == 0)
01082 Done = TRUE;
01083 }
01084 else
01085 {
01086
01087 if(!Stack.Discard())
01088 return FALSE;
01089 }
01090 }
01091
01092 return TRUE;
01093 }
01094
01095
01096
01097
01098
01099
01100
01101
01102
01103
01104
01105
01106
01107
01108
01109 BOOL FreeHandEPSFilter::PopColour(DocColour *Col)
01110 {
01111
01112
01113
01114 EPSCommand Cmd;
01115 if(!Stack.PopCmd(&Cmd))
01116 return FALSE;
01117 if(Cmd != EPSC_ArrayEnd)
01118 return FALSE;
01119
01120
01121 double C, M, Y, K;
01122 if(!Stack.Pop(&K) ||
01123 !Stack.Pop(&Y) ||
01124 !Stack.Pop(&M) ||
01125 !Stack.Pop(&C))
01126 return FALSE;
01127
01128
01129 if(!Stack.PopCmd(&Cmd))
01130 return FALSE;
01131 if(Cmd != EPSC_ArrayStart)
01132 return FALSE;
01133
01134
01135 ColourCMYK Colour;
01136
01137 Colour.Cyan = C;
01138 Colour.Magenta = M;
01139 Colour.Yellow = Y;
01140 Colour.Key = K;
01141
01142 IndexedColour *NewCol = new IndexedColour(COLOURMODEL_CMYK, (ColourGeneric *)&Colour);
01143
01144 if(NewCol == 0)
01145 return FALSE;
01146
01147 pColours->GetColourList()->GetUnnamedColours()->AddTail(NewCol);
01148
01149 Col->MakeRefToIndexedColour(NewCol);
01150
01151 return TRUE;
01152 }
01153
01154
01155
01156
01157
01158
01159
01160
01161
01162
01163
01164
01165
01166
01167
01168 BOOL FreeHandEPSFilter::PopNamedColour(DocColour *Col)
01169 {
01170
01171
01172
01173
01174
01175
01176 EPSCommand Cmd;
01177 if(!Stack.PopCmd(&Cmd))
01178 return FALSE;
01179 if(Cmd != EPSC_ArrayEnd)
01180 return FALSE;
01181
01182
01183 double Random;
01184 INT32 Index;
01185 if(!Stack.Pop(&Index) ||
01186 !Stack.Pop(&Random))
01187 return FALSE;
01188
01189
01190 if(!Stack.PopCmd(&Cmd))
01191 return FALSE;
01192 if(Cmd != EPSC_ArrayStart)
01193 return FALSE;
01194
01195
01196 if(Index < 0 || Index >= ColourArrayEntries)
01197 return FALSE;
01198
01199
01200 Col->MakeRefToIndexedColour(ColourArray[Index]);
01201
01202 return TRUE;
01203 }
01204
01205
01206
01207
01208
01209
01210
01211
01212
01213
01214
01215
01216
01217
01218 BOOL FreeHandEPSFilter::SaveCurrentFill()
01219 {
01220
01221 if(OldFill != 0)
01222 delete OldFill;
01223
01224
01225 CCRuntimeClass* ObjectType = CurrentAttrs[ATTR_FILLGEOMETRY].pAttr->GetRuntimeClass();
01226 AttributeValue* AttrClone = (AttributeValue*)ObjectType->CreateObject();
01227
01228 if(AttrClone == 0)
01229 return FALSE;
01230
01231 AttrClone->SimpleCopy(CurrentAttrs[ATTR_FILLGEOMETRY].pAttr);
01232
01233
01234 OldFill = AttrClone;
01235
01236 return TRUE;
01237 }
01238
01239
01240
01241
01242
01243
01244
01245
01246
01247
01248
01249
01250
01251
01252 BOOL FreeHandEPSFilter::RestoreCurrentFill()
01253 {
01254 if(OldFill == 0)
01255 return TRUE;
01256
01257
01258 if(CurrentAttrs[ATTR_FILLGEOMETRY].pAttr != 0)
01259 delete CurrentAttrs[ATTR_FILLGEOMETRY].pAttr;
01260
01261
01262 CurrentAttrs[ATTR_FILLGEOMETRY].pAttr = OldFill;
01263
01264
01265 OldFill = 0;
01266
01267 return TRUE;
01268 }
01269
01270
01271
01272
01273
01274
01275
01276
01277
01278
01279
01280
01281
01282 BOOL FreeHandEPSFilter::ValidateGroup(Node *pGroup)
01283 {
01284 ERROR2IF(pGroup == 0, FALSE, "Group passed to validateGroup is null");
01285
01286 Node *pFirstChild = pGroup->FindFirstChild();
01287
01288 ERROR2IF(pFirstChild == 0, FALSE, "Group without children passed to ValidateGroup - should have been deleted by EndGroup");
01289
01290 if(pFirstChild->FindNext() == 0)
01291 {
01292
01293
01294
01295 if(pFirstNodeInRange == pGroup)
01296 pFirstNodeInRange = pFirstChild;
01297
01298
01299 if (!ImportInfo.pOp->DoMoveNode(pFirstChild, pNode, LASTCHILD))
01300 return FALSE;
01301
01302
01303 if (!ImportInfo.pOp->DoHideNode(pGroup, TRUE))
01304 return FALSE;
01305
01306 }
01307
01308 return TRUE;
01309 }
01310
01311
01312
01313
01314
01315
01316
01317
01318
01319
01320
01321
01322 BOOL FreeHandEPSFilter::MaskedGroupEnding()
01323 {
01324
01325 if(ThePathType == PATH_DISCARD || ThePathType == PATH_DISCARD_STICKY)
01326 {
01327 ThePathType = PATH_NORMAL;
01328 }
01329
01330 return TRUE;
01331 }
01332
01333
01334
01335
01336
01337
01338
01339
01340
01341
01342
01343
01344
01345
01346 BOOL FreeHandEPSFilter::RemoveLastSubPathIfNotUnique(Path *pIPath)
01347 {
01348
01349 INT32 NCoords = pIPath->GetNumCoords();
01350 DocCoord *Coords = pIPath->GetCoordArray();
01351 PathVerb *Verbs = pIPath->GetVerbArray();
01352
01353
01354 INT32 LastMoveTo = -1;
01355 INT32 c;
01356
01357 for(c = 0; c < NCoords; c++)
01358 {
01359 if((Verbs[c] & ~PT_CLOSEFIGURE) == PT_MOVETO)
01360 {
01361 LastMoveTo = c;
01362 }
01363 }
01364
01365
01366 if(LastMoveTo == -1 || LastMoveTo == 0)
01367 return TRUE;
01368
01369
01370 for(c = 0; c < LastMoveTo; c++)
01371 {
01372 if((Verbs[c] & ~PT_CLOSEFIGURE) == PT_MOVETO)
01373 {
01374
01375 INT32 n = 0;
01376
01377 while(((Verbs[c+n] & ~PT_CLOSEFIGURE) == (Verbs[LastMoveTo+n] & ~PT_CLOSEFIGURE)) && (Coords[c+n] == Coords[LastMoveTo+n]))
01378 {
01379
01380
01381 if((LastMoveTo+n+1) == NCoords)
01382 {
01383
01384 return pIPath->DeleteFromElement(LastMoveTo);
01385 }
01386
01387 n++;
01388 }
01389 }
01390 }
01391
01392 return TRUE;
01393 }
01394
01395
01396
01397
01398
01399
01400
01401
01402
01403
01404
01405
01406
01407
01408
01409 BOOL FreeHandEPSFilter::AddNewNode(Node *pNewNode)
01410 {
01411 if(IS_A(pNewNode, NodePath))
01412 pLastPathSeen = (NodePath *)pNewNode;
01413
01414
01415 if((ComplexPathMode == FALSE) || (pNewNode == 0) || (pNode == 0) || (!IS_A(pNewNode, NodePath)))
01416 return EPSFilter::AddNewNode(pNewNode);
01417
01418
01419 if(HadFirstOfComplexPath == FALSE)
01420 {
01421 HadFirstOfComplexPath = TRUE;
01422 return EPSFilter::AddNewNode(pNewNode);
01423 }
01424
01425
01426 Node *pLastChild = pNode->FindLastChild();
01427 if(pLastChild == 0 || !IS_A(pLastChild, NodePath))
01428 return EPSFilter::AddNewNode(pNewNode);
01429
01430
01431 Path *pTarget = &((NodePath *)pLastChild)->InkPath;
01432 Path *pAddition = &((NodePath *)pNewNode)->InkPath;
01433
01434
01435 BOOL TargetFilled = pTarget->IsFilled;
01436 BOOL TargetStroked = pTarget->IsStroked;
01437 if(pAddition->IsFilled) TargetFilled = TRUE;
01438 if(pAddition->IsStroked) TargetStroked = TRUE;
01439
01440
01441 if(!pTarget->MergeTwoPaths(*pAddition))
01442 return FALSE;
01443
01444
01445 if(!RemoveLastSubPathIfNotUnique(pTarget))
01446 return FALSE;
01447
01448
01449 pTarget->IsFilled = TargetFilled;
01450 pTarget->IsStroked = TargetStroked;
01451
01452
01453 pLastChild->DeleteChildren(pLastChild->FindFirstChild());
01454
01455
01456 SetPathFilled(TargetFilled);
01457 if(!AddAttributes((NodePath *)pLastChild, TargetStroked, TargetFilled))
01458 return FALSE;
01459
01460
01461
01462
01463 pNewNode->CascadeDelete();
01464 delete pNewNode;
01465
01466
01467 pLastPathSeen = (NodePath *)pLastChild;
01468
01469
01470 return TRUE;
01471 }
01472
01473
01474
01475