00001
00002
00003
00004
00005
00006
00007
00008
00009
00010
00011
00012
00013
00014
00015
00016
00017
00018
00019
00020
00021
00022
00023
00024
00025
00026
00027
00028
00029
00030
00031
00032
00033
00034
00035
00036
00037
00038
00039
00040
00041
00042
00043
00044
00045
00046
00047
00048
00049
00050
00051
00052
00053
00054
00055
00056
00057
00058
00059
00060
00061
00062
00063
00064
00065
00066
00067
00068
00069
00070
00071
00072
00073
00074
00075
00076
00077
00078
00079
00080
00081
00082
00083
00084
00085
00086
00087
00088
00089
00090
00091
00092
00093
00094
00095
00096
00097
00098
00099
00100
00101
00102
00103
00104 #include "camtypes.h"
00105
00106 #include "coreleps.h"
00107
00108 #include <sstream>
00109
00110 #include "nodepath.h"
00111
00112
00113
00114
00115
00116
00117
00118 DECLARE_SOURCE("$Revision: 1312 $");
00119
00120 #define new CAM_DEBUG_NEW
00121
00122 CC_IMPLEMENT_DYNAMIC(CorelEPSFilter, EPSFilter)
00123 CC_IMPLEMENT_DYNAMIC(Corel3EPSFilter, CorelEPSFilter)
00124 CC_IMPLEMENT_DYNAMIC(Corel4EPSFilter, CorelEPSFilter)
00125
00126
00127
00128 enum
00129 {
00130 EPSC_cd_0sv = EPSC_EOF + 1,
00131 EPSC_cd_0sm,
00132 EPSC_cd_0rs,
00133 EPSC_cd_0rax,
00134 EPSC_cd_0B,
00135 EPSC_cd_0E,
00136 EPSC_cd_0G,
00137 EPSC_cd_0g,
00138 EPSC_cd_0j,
00139 EPSC_cd_0J,
00140 EPSC_cd_0w,
00141 EPSC_cd_0c,
00142 EPSC_cd_0t,
00143 EPSC_cd_0tm,
00144 EPSC_cd_a,
00145 EPSC_cd_r,
00146 EPSC_cd_x,
00147 EPSC_cd_X,
00148 EPSC_cd_e,
00149 EPSC_cd_z,
00150 EPSC_cd_Z,
00151 EPSC_cd_T,
00152 EPSC_cd_m,
00153 EPSC_matrix,
00154 EPSC_currentmatrix,
00155 EPSC_def,
00156 EPSC_begin,
00157 EPSC_cd_Sentinel
00158 };
00159
00160
00161 CommandMap CorelEPSFilter::CorelCommands[] =
00162 {
00163 EPSC_cd_0sv, "@sv",
00164 EPSC_cd_0sm, "@sm",
00165 EPSC_cd_0rs, "@rs",
00166 EPSC_cd_0rax, "@rax",
00167 EPSC_cd_0B, "@B",
00168 EPSC_cd_0E, "@E",
00169 EPSC_cd_0G, "@G",
00170 EPSC_cd_0g, "@g",
00171 EPSC_cd_0j, "@j",
00172 EPSC_cd_0J, "@J",
00173 EPSC_cd_0w, "@w",
00174 EPSC_cd_0c, "@c",
00175 EPSC_cd_0t, "@t",
00176 EPSC_cd_0tm, "@tm",
00177 EPSC_cd_a, "a",
00178 EPSC_cd_r, "r",
00179 EPSC_cd_x, "x",
00180 EPSC_cd_X, "X",
00181 EPSC_cd_e, "e",
00182 EPSC_cd_z, "z",
00183 EPSC_cd_Z, "Z",
00184 EPSC_cd_T, "T",
00185 EPSC_cd_m, "m",
00186
00187 EPSC_matrix, "matrix",
00188 EPSC_currentmatrix, "currentmatrix",
00189 EPSC_def, "def",
00190 EPSC_begin, "begin",
00191
00192
00193 EPSC_Invalid, "Invalid"
00194 };
00195
00196
00197
00198
00199
00200
00201
00202
00203
00204
00205
00206
00207
00208 CorelEPSFilter::CorelEPSFilter()
00209 {
00210
00211 FilterID = FILTERID_NONE;
00212
00213 #ifndef STANDALONE
00214 Flags.CanImport = TRUE;
00215 Flags.CanExport = FALSE;
00216 #else
00217 Flags.CanImport = FALSE;
00218 Flags.CanExport = FALSE;
00219 #endif
00220
00221
00222 SupportsLayers = FALSE;
00223 }
00224
00225
00226
00227
00228
00229
00230
00231
00232
00233
00234
00235
00236
00237
00238 BOOL CorelEPSFilter::Init()
00239 {
00240
00241 return TRUE;
00242 }
00243
00244
00245
00246
00247
00248
00249
00250
00251
00252
00253
00254
00255
00256 void CorelEPSFilter::LookUpToken()
00257 {
00258
00259 if (Token == EPSC_Comment)
00260 return;
00261
00262
00263
00264 INT32 i = 0;
00265 while (CorelCommands[i].Cmd != EPSC_Invalid)
00266 {
00267 if (camStrcmp(TokenBuf, CorelCommands[i].CmdStr) == 0)
00268 {
00269
00270 Token = CorelCommands[i].Cmd;
00271 return;
00272 }
00273
00274 i++;
00275 }
00276
00277
00278 EPSFilter::LookUpToken();
00279 }
00280
00281
00282
00283
00284
00285
00286
00287
00288
00289
00290
00291
00292
00293
00294
00295 BOOL CorelEPSFilter::ProcessToken()
00296 {
00297
00298 DocCoord Coords[3];
00299 INT32 Long;
00300 FIXEDPOINT FixedPoint;
00301 PColourCMYK Col;
00302 DocColour DocCol;
00303 String_64 ColName;
00304 FIXEDPOINT TintVal;
00305
00306
00307 switch (Token)
00308 {
00309 case EPSC_S:
00310 case EPSC_b:
00311 case EPSC_B:
00312 case EPSC_f:
00313 case EPSC_F:
00314 case EPSC_s:
00315 if (ThePathType == PATH_DISCARD)
00316 {
00317
00318 ThePathType = PATH_NORMAL;
00319 break;
00320 }
00321
00322 if (ThePathType == PATH_DISCARD_STICKY)
00323
00324 break;
00325
00326 ENSURE((ThePathType == PATH_NORMAL) ||
00327 (ThePathType == PATH_RECT) ||
00328 (ThePathType == PATH_ELLIPSE), "No path in stroke!");
00329
00330
00331
00332 if (pPath == NULL)
00333 break;
00334
00335
00336
00337 if ((Token == EPSC_s) || (Token == EPSC_b) || (Token == EPSC_f))
00338 {
00339 if (!pPath->InkPath.CloseSubPath())
00340
00341 goto NoMemory;
00342 }
00343
00344
00345
00346
00347 if ((Token == EPSC_b) ||
00348 (Token == EPSC_B) ||
00349 (Token == EPSC_F) ||
00350 (Token == EPSC_f))
00351 {
00352 pPath->InkPath.IsFilled = TRUE;
00353 SetPathFilled(TRUE);
00354 }
00355 else
00356 {
00357 pPath->InkPath.IsFilled = FALSE;
00358 SetPathFilled(FALSE);
00359 }
00360
00361 if (!EPSFlags.ComplexPath)
00362 {
00363
00364 pPath->InvalidateBoundingRect();
00365
00366
00367 if (EPSFlags.NoAttributes)
00368 {
00369 if (!AddAttributes(pPath, (Token != EPSC_f) && (Token != EPSC_F), pPath->InkPath.IsFilled))
00370 goto NoMemory;
00371 EPSFlags.NoAttributes = FALSE;
00372 }
00373
00374
00375 if (!AddNewNode(pPath))
00376 goto NoMemory;
00377
00378
00379
00380 pPath = NULL;
00381 pInkPath = NULL;
00382 }
00383 else
00384 EPSFlags.StrokeComplexPath = (Token != EPSC_f) && (Token != EPSC_F);
00385
00386
00387 ThePathType = PATH_NORMAL;
00388 break;
00389
00390 case EPSC_cd_0sv:
00391 case EPSC_cd_0sm:
00392 case EPSC_cd_0rs:
00393 case EPSC_cd_0rax:
00394
00395 break;
00396
00397 case EPSC_cd_0E:
00398
00399 if (!Stack.Discard(4))
00400 goto EPSError;
00401 break;
00402
00403 case EPSC_cd_0B:
00404 case EPSC_cd_a:
00405 case EPSC_cd_r:
00406
00407
00408
00409 break;
00410
00411 case EPSC_cd_0G:
00412 case EPSC_cd_0g:
00413
00414 if (!Stack.Pop(&Long))
00415 goto EPSError;
00416 if (Long == 1)
00417 {
00418
00419 if (!Stack.Discard(3))
00420 goto EPSError;
00421 }
00422 break;
00423
00424 case EPSC_cd_0J:
00425 case EPSC_cd_0j:
00426
00427 break;
00428
00429 case EPSC_cd_0w:
00430
00431
00432 if (!Stack.Discard(2))
00433 goto EPSError;
00434
00435 if (Stack.Pop(&FixedPoint))
00436 {
00437
00438
00439 if (!SetLineWidth((MILLIPOINT) (FixedPoint * EPSScaleFactor) / FixedPointScale))
00440 goto NoMemory;
00441
00442
00443 if (Stack.Pop(&Long))
00444 {
00445 if (Long == 1)
00446 {
00447 if (!Stack.DiscardArray())
00448 goto EPSError;
00449 }
00450 }
00451 else
00452 goto EPSError;
00453 }
00454 else
00455 goto EPSError;
00456 break;
00457
00458 case EPSC_cd_0c:
00459
00460 if (pPath == NULL)
00461
00462 goto EPSError;
00463
00464 if (!pPath->InkPath.CloseSubPath())
00465
00466 goto NoMemory;
00467 break;
00468
00469 case EPSC_cd_0t:
00470
00471 if (!Stack.Discard(3))
00472 goto EPSError;
00473 break;
00474
00475 case EPSC_cd_0tm:
00476 {
00477
00478
00479 EPSCommand Cmd;
00480 Stack.PopCmd(&Cmd);
00481 if (Cmd != EPSC_ArrayEnd)
00482 {
00483 if (IsUserName("Tim"))
00484 TRACE( _T("@tm: Expected ArrayEnd, found '%s'\n"), GetEPSCommand(Cmd));
00485 goto EPSError;
00486 }
00487
00488
00489 double M[6];
00490 INT32 i = 5;
00491 for (i = 5; i >= 0; i--)
00492 {
00493 if (!Stack.Pop(&M[i]))
00494 goto EPSError;
00495 }
00496
00497 Stack.PopCmd(&Cmd);
00498 if (Cmd != EPSC_ArrayStart)
00499 {
00500 if (IsUserName("Tim"))
00501 TRACE( _T("@tm: Expected ArrayStart, found '%s'\n"), GetEPSCommand(Cmd));
00502 goto EPSError;
00503 }
00504
00505
00506 FIXED16 F16[4];
00507 for (i = 0; i < 4; i++)
00508 {
00509 F16[i] = FIXED16(M[i]);
00510 }
00511
00512
00513 INT32 L1 = (INT32) (M[4] * 1000.0);
00514 INT32 L2 = (INT32) (M[5] * 1000.0);
00515
00516
00517
00518 Matrix TextMatrix(F16[0], F16[1], F16[2], F16[3], L1, L2);
00519 Stack.SetXformMatrix(TextMatrix);
00520
00521 break;
00522 }
00523
00524 case EPSC_cd_x:
00525
00526 GradFill = FALSE;
00527 if (Stack.PopColour(&Col, TINT_COREL, &TintVal, &ColName))
00528 {
00529 GetEPSColour(&DocCol, &Col, TINT_COREL, TintVal, &ColName);
00530
00531
00532 if (!SetFillColour(DocCol))
00533 goto NoMemory;
00534 }
00535 else
00536
00537 goto EPSError;
00538 break;
00539
00540 case EPSC_cd_X:
00541
00542 if (Stack.PopColour(&Col, TINT_COREL, &TintVal, &ColName))
00543 {
00544 GetEPSColour(&DocCol, &Col, TINT_COREL, TintVal, &ColName);
00545
00546
00547 if (!SetLineColour(DocCol))
00548 goto NoMemory;
00549 }
00550 else
00551
00552 goto EPSError;
00553 break;
00554
00555 case EPSC_cd_e:
00556
00557 break;
00558
00559 case EPSC_cd_z:
00560
00561 if (!Stack.Discard(2))
00562 goto EPSError;
00563 break;
00564
00565 case EPSC_cd_Z:
00566
00567 if (!Stack.Discard(3) || !Stack.DiscardArray())
00568 goto EPSError;
00569 break;
00570
00571 case EPSC_cd_T:
00572
00573 Stack.SetNoXformMatrix();
00574 break;
00575
00576
00577 case EPSC_cd_m:
00578
00579 if (Stack.PopCoordPair(&Coords[0]))
00580 {
00581 if (pPath == NULL)
00582 {
00583 ERROR3IF(pInkPath != NULL,"Already got a path");
00584 if (pInkPath != NULL)
00585 goto EPSError;
00586
00587
00588 pPath = new NodePath;
00589
00590
00591 EPSFlags.NoAttributes = TRUE;
00592
00593 if ((pPath == NULL) || (!pPath->SetUpPath()))
00594
00595 goto NoMemory;
00596
00597
00598 pPath->InkPath.FindStartOfPath();
00599
00600 pInkPath = &pPath->InkPath;
00601 }
00602
00603
00604 if (!pPath->InkPath.InsertMoveTo(Coords[0]))
00605
00606 goto NoMemory;
00607 }
00608 else
00609
00610 goto EPSError;
00611 break;
00612
00613 case EPSC_matrix:
00614
00615
00616 Stack.Push((INT32) 0);
00617 break;
00618
00619 case EPSC_currentmatrix:
00620
00621
00622 break;
00623
00624 case EPSC_def:
00625
00626 if (!Stack.Discard(2))
00627 goto EPSError;
00628 break;
00629
00630 case EPSC_begin:
00631
00632 if (!Stack.Discard())
00633 goto EPSError;
00634 break;
00635
00636 default:
00637
00638 return EPSFilter::ProcessToken();
00639 }
00640
00641
00642
00643 return TRUE;
00644
00645
00646
00647
00648 EPSError:
00649 HandleEPSError();
00650 return FALSE;
00651
00652 NoMemory:
00653 HandleNoMemory();
00654 return FALSE;
00655 }
00656
00657
00658
00659
00660
00661
00662
00663
00664
00665
00666
00667
00668
00669
00670
00671 char *CorelEPSFilter::GetEPSCommand(EPSCommand Cmd)
00672 {
00673 INT32 i = 0;
00674 while (CorelCommands[i].Cmd != EPSC_Invalid)
00675 {
00676 if (CorelCommands[i].Cmd == Cmd)
00677 return CorelCommands[i].CmdStr;
00678
00679
00680 i++;
00681 }
00682
00683
00684 return EPSFilter::GetEPSCommand(Cmd);
00685 }
00686
00687
00688
00689
00690
00691
00692
00693
00694
00695
00696
00697
00698
00699
00700
00701
00702 BOOL CorelEPSFilter::DecodeCorelGradFill()
00703 {
00704 switch (GradFillInfo.FillType)
00705 {
00706 case 0:
00707 return DecodeLinearGradFill();
00708
00709 case 1:
00710 case 3:
00711 return DecodeRadialGradFill();
00712
00713 case 2:
00714 return DecodeConicalGradFill();
00715 }
00716
00717
00718 return TRUE;
00719 }
00720
00721
00722
00723
00724
00725
00726
00727
00728
00729
00730
00731
00732
00733
00734
00735
00736
00737 BOOL CorelEPSFilter::DecodeLinearGradFill()
00738 {
00739
00740
00741
00742
00743 DocCoord Start, End;
00744
00745
00746 DocRect BBox;
00747 CDRFilter::GetCorelBBox(pPath, &BBox);
00748
00749
00750 MILLIPOINT Width = BBox.Width();
00751 MILLIPOINT Height = BBox.Height();
00752
00753
00754 DocCoord Centre;
00755 Centre.x = BBox.lo.x + (Width / 2);
00756 Centre.y = BBox.lo.y + (Height / 2);
00757
00758
00759 double TotalArea = (double) Width * (double) Height;
00760
00761
00762 BOOL Mirror = FALSE;
00763 INT32 Angle = GradFillInfo.Angle;
00764
00765 if (Angle >= 180)
00766 {
00767 Angle -= 180;
00768 Mirror = TRUE;
00769 }
00770 else if (Angle < 0)
00771 {
00772 Angle += 180;
00773 Mirror = TRUE;
00774 }
00775
00776 Angle += 90;
00777
00778 if (Angle >= 180)
00779 {
00780 Angle -= 180;
00781 }
00782
00783
00784 double Radians = (((double) Angle) / 180.0) * PI;
00785 double TanTheta;
00786 if (Angle == 90)
00787 {
00788
00789
00790
00791 Start.x = BBox.lo.x;
00792 Start.y = Centre.y;
00793 End.x = BBox.hi.x;
00794 End.y = Centre.y;
00795
00796
00797 INT32 Padding = (Width * GradFillInfo.EdgePad) / 100;
00798 Start.x += Padding;
00799 End.x -= Padding;
00800 }
00801 else if (Angle == 0)
00802 {
00803
00804
00805
00806 Start.x = Centre.x;
00807 Start.y = BBox.lo.y;
00808 End.x = Centre.x;
00809 End.y = BBox.hi.y;
00810
00811
00812 INT32 Padding = (Height * GradFillInfo.EdgePad) / 100;
00813 Start.y += Padding;
00814 End.y -= Padding;
00815 }
00816 else
00817 {
00818 TanTheta = tan(Radians);
00819
00820
00821
00822
00823 MILLIPOINT TriWidth = (MILLIPOINT) ((double) Height / TanTheta);
00824
00825
00826 if (TriWidth < 0)
00827 TriWidth = -TriWidth;
00828 if (TriWidth > Width)
00829 TriWidth = Width;
00830
00831
00832 MILLIPOINT TriHeight = (MILLIPOINT) ((double) Width * TanTheta);
00833
00834
00835 if (TriHeight < 0)
00836 TriHeight = -TriHeight;
00837 if (TriHeight > Height)
00838 TriHeight = Height;
00839
00840
00841 MILLIPOINT StartC, EndC;
00842
00843
00844
00845 double Percentage = (50.0 * (double) TriWidth * (double) TriHeight) / TotalArea;
00846
00847 INT32 Diff = 0;
00848
00849
00850 if (((INT32) Percentage) >= GradFillInfo.EdgePad)
00851 {
00852
00853 TriHeight = (MILLIPOINT) sqrt(ABS(((double) GradFillInfo.EdgePad * TotalArea * TanTheta) / 100.0));
00854
00855 TriWidth = (MILLIPOINT) ((double) TriHeight / TanTheta);
00856 if (TriWidth < 0)
00857 TriWidth = -TriWidth;
00858
00859 ENSURE(TriWidth < Width, "Error in Corel Grad fill decoding logic");
00860 }
00861 else
00862 {
00863
00864 Percentage = (GradFillInfo.EdgePad - Percentage) / 2;
00865
00866
00867 if (TriWidth == Width)
00868 {
00869
00870 Diff = (MILLIPOINT) ((Percentage * Height) / 100.0);
00871 }
00872 else
00873 {
00874
00875 Diff = (MILLIPOINT) ((Percentage * Width) / 100.0);
00876 Diff = (MILLIPOINT) (Diff / tan(PI - Radians));
00877 Diff = ABS(Diff);
00878 }
00879 }
00880
00881
00882
00883 if (Angle == 90)
00884 {
00885
00886 }
00887 else if (Angle < 90)
00888 {
00889 StartC = (MILLIPOINT) (BBox.lo.y - ((BBox.hi.x - TriWidth) * TanTheta));
00890 EndC = (MILLIPOINT) (BBox.hi.y - ((BBox.lo.x + TriWidth) * TanTheta));
00891 }
00892 else
00893 {
00894 StartC = (MILLIPOINT) (BBox.lo.y - ((BBox.lo.x + TriWidth) * TanTheta));
00895 EndC = (MILLIPOINT) (BBox.hi.y - ((BBox.hi.x - TriWidth) * TanTheta));
00896 }
00897
00898
00899 StartC += Diff;
00900 EndC -= Diff;
00901
00902
00903
00904
00905
00906 double FillM = -1.00 / TanTheta;
00907 MILLIPOINT FillC = (MILLIPOINT) (Centre.y - (Centre.x * FillM));
00908
00909
00910
00911 Start.x = (MILLIPOINT) ( (FillC - StartC) / (TanTheta + (1.00 / TanTheta)) );
00912 Start.y = (MILLIPOINT) ((FillM * Start.x) + FillC);
00913
00914 End.x = (MILLIPOINT) ( (FillC - EndC) / (TanTheta + (1.00 / TanTheta)) );
00915 End.y = (MILLIPOINT) ((FillM * End.x) + FillC);
00916 }
00917
00918 if (Mirror)
00919 {
00920
00921 DocCoord Tmp = Start;
00922 Start = End;
00923 End = Tmp;
00924 }
00925
00926
00927 return SetLinearFill(StartColour, EndColour, Start, End);
00928 }
00929
00930
00931
00932
00933
00934
00935
00936
00937
00938
00939
00940
00941
00942
00943
00944
00945
00946
00947 BOOL CorelEPSFilter::DecodeRadialGradFill()
00948 {
00949
00950 DocCoord Start, End;
00951
00952
00953 DocRect BBox;
00954 CDRFilter::GetCorelBBox(pPath, &BBox);
00955
00956
00957 MILLIPOINT Width = BBox.Width();
00958 MILLIPOINT Height = BBox.Height();
00959
00960
00961
00962 double dWidth = Width;
00963 double dHeight = Height;
00964 INT32 Diagonal = (INT32)sqrt(dWidth*dWidth + dHeight*dHeight);
00965
00966
00967
00968 INT32 Edge = (Diagonal * (100 - (GradFillInfo.EdgePad * 2))) / 100;
00969
00970
00971
00972
00973 DocCoord Centre = DocCoord(BBox.lo.x + (Width / 2), BBox.lo.y + (Height / 2));
00974 INT32 OffX = (GradFillInfo.RotateX * Width) / 100;
00975 INT32 OffY = (GradFillInfo.RotateY * Height) / 100;
00976 Start.x = Centre.x + OffX;
00977 Start.y = Centre.y + OffY;
00978
00979
00980 double Radius = Edge / 2;
00981
00982
00983 double dOffX = OffX;
00984 double dOffY = OffY;
00985 double Dist = (INT32)sqrt(dOffX*dOffX + dOffY*dOffY);
00986
00987
00988 double BodgeFactor = 1 + (Dist / (double)(Diagonal / 2));
00989 Radius *= BodgeFactor;
00990
00991
00992 End.x = Start.x + ((MILLIPOINT) Radius);
00993 End.y = Start.y;
00994
00995
00996
00997
00998 return SetRadialFill(EndColour, StartColour, Start, End);
00999 }
01000
01001
01002
01003
01004
01005
01006
01007
01008
01009
01010
01011
01012
01013
01014
01015
01016 BOOL CorelEPSFilter::DecodeConicalGradFill()
01017 {
01018
01019
01020
01021 DocCoord Start, End;
01022
01023
01024 DocRect BBox;
01025 CDRFilter::GetCorelBBox(pPath, &BBox);
01026
01027
01028 MILLIPOINT Width = BBox.Width();
01029 MILLIPOINT Height = BBox.Height();
01030
01031
01032
01033
01034 Start.x = BBox.lo.x + (Width / 2);
01035 Start.y = BBox.lo.y + (Height / 2);
01036 Start.x += ((GradFillInfo.RotateX * Width) / 100);
01037 Start.y += ((GradFillInfo.RotateY * Height) / 100);
01038
01039
01040 double Radius = Width / 2;
01041
01042 double Theta = (((double)(GradFillInfo.Angle)) / 360.0) * (2 * PI);
01043
01044
01045 Theta = 0 - Theta;
01046
01047
01048 Theta -= PI / 2;
01049
01050
01051 while(Theta < 0)
01052 Theta += (2 * PI);
01053
01054
01055 double dx, dy;
01056
01057 dx = Radius * sin(Theta);
01058 dy = Radius * cos(Theta);
01059
01060 End.x = Start.x + (INT32)dx;
01061 End.y = Start.y + (INT32)dy;
01062
01063
01064
01065
01066 return SetConicalFill(EndColour, StartColour, Start, End);
01067 }
01068
01069
01070
01071
01072
01073
01074
01075
01076
01077
01078
01079
01080
01081
01082
01083
01084
01085
01086
01087
01088
01089
01090
01091
01092
01093 BOOL CorelEPSFilter::AddAttributes(NodeRenderableBounded *pNode, BOOL Stroked, BOOL Filled)
01094 {
01095
01096 if (GradFill)
01097 {
01098 GradFill = FALSE;
01099
01100 if (!DecodeCorelGradFill())
01101 return FALSE;
01102 }
01103
01104
01105 return EPSFilter::AddAttributes(pNode, Stroked, Filled);
01106 }
01107
01108
01109
01110 enum
01111 {
01112 EPSC_cd3_0k = EPSC_cd_Sentinel + 1,
01113 EPSC_cd3_0x,
01114 };
01115
01116
01117 CommandMap Corel3EPSFilter::Corel3Commands[] =
01118 {
01119 EPSC_cd3_0k, "@k",
01120 EPSC_cd3_0x, "@x",
01121
01122
01123 EPSC_Invalid, "Invalid"
01124 };
01125
01126
01127
01128
01129
01130
01131
01132
01133
01134
01135
01136
01137
01138 Corel3EPSFilter::Corel3EPSFilter()
01139 {
01140
01141 FilterID = FILTERID_COREL3_EPS;
01142 ImportMsgID = _R(IDT_IMPORTMSG_COREL3);
01143
01144 #ifndef STANDALONE
01145 Flags.CanImport = TRUE;
01146 Flags.CanExport = FALSE;
01147 #else
01148 Flags.CanImport = FALSE;
01149 Flags.CanExport = FALSE;
01150 #endif
01151 }
01152
01153
01154
01155
01156
01157
01158
01159
01160
01161
01162
01163
01164
01165
01166 BOOL Corel3EPSFilter::Init()
01167 {
01168
01169 pOILFilter = new Corel3EPSOILFilter(this);
01170 if (pOILFilter == NULL)
01171 return FALSE;
01172
01173
01174 FilterName.Load(_R(IDT_CORELEPS_FILTERNAME));
01175 FilterInfo.Load(_R(IDT_CORELEPS_FILTERINFO));
01176
01177
01178 return TRUE;
01179 }
01180
01181
01182
01183
01184
01185
01186
01187
01188
01189
01190
01191
01192
01193 INT32 Corel3EPSFilter::EPSHeaderIsOk(ADDR pFileHeader, UINT32 HeaderSize)
01194 {
01195
01196 if (camStrncmp((char *) pFileHeader, "%!PS-Adobe-2.0 EPSF", 19) != 0)
01197 {
01198
01199 return 0;
01200 }
01201
01202
01203 istrstream HeaderFile((char *) pFileHeader, HeaderSize);
01204 char Buffer[200];
01205 BOOL HaveCreatorString = FALSE;
01206
01207 UINT32 Lines = 0;
01208 while ((Lines < 20) && !HeaderFile.eof())
01209 {
01210 HeaderFile.getline(Buffer, 200);
01211 Lines++;
01212
01213 if (camStrncmp(Buffer, "%%Creator: CorelDRAW!", 21) == 0)
01214 {
01215 HaveCreatorString = TRUE;
01216 }
01217
01218
01219 if (camStrstr("Corel", Buffer) != NULL)
01220
01221 return 8;
01222
01223 if(camStrncmp(Buffer, "/wCorelDict", 11) == 0 && HaveCreatorString == TRUE)
01224 {
01225
01226 return 10;
01227 }
01228
01229
01230
01231 if (camStrncmp(Buffer, "%%Compression:", 14)==0)
01232 break;
01233 }
01234
01235
01236 return 5;
01237
01238
01239 #if 0
01240 if (camStrncmp(Buf, "% -------------- POSTSCRIPT PROLOG FOR CORELDRAW 3.X", 52) == 0)
01241 FoundProlog = TRUE;
01242 #endif
01243 }
01244
01245
01246
01247
01248
01249
01250
01251
01252
01253
01254
01255
01256
01257 void Corel3EPSFilter::LookUpToken()
01258 {
01259
01260 if (Token == EPSC_Comment)
01261 return;
01262
01263
01264
01265 INT32 i = 0;
01266 while (Corel3Commands[i].Cmd != EPSC_Invalid)
01267 {
01268 if (camStrcmp(TokenBuf, Corel3Commands[i].CmdStr) == 0)
01269 {
01270
01271 Token = Corel3Commands[i].Cmd;
01272 return;
01273 }
01274
01275 i++;
01276 }
01277
01278
01279 CorelEPSFilter::LookUpToken();
01280 }
01281
01282
01283
01284
01285
01286
01287
01288
01289
01290
01291
01292
01293
01294
01295
01296 BOOL Corel3EPSFilter::ProcessToken()
01297 {
01298
01299 PColourCMYK Col;
01300 DocCoord Coords[3];
01301 TintType Tint = TINT_NONE;
01302 FIXEDPOINT TintVal;
01303 String_64 ColName;
01304 double Padding, RotateX, RotateY;
01305
01306
01307 switch (Token)
01308 {
01309 case EPSC_cd3_0x:
01310 Tint = TINT_COREL;
01311 case EPSC_cd3_0k:
01312
01313 if (!Stack.Pop(&RotateY) || !Stack.Pop(&RotateX) ||
01314 !Stack.Pop(&Padding) || !Stack.Pop(&GradFillInfo.FillType) ||
01315 !Stack.Pop(&GradFillInfo.Angle))
01316 goto EPSError;
01317
01318
01319 GradFillInfo.EdgePad = (INT32) (Padding * 100.0);
01320 GradFillInfo.RotateX = (INT32) (RotateX * 100.0);
01321 GradFillInfo.RotateY = (INT32) (RotateY * 100.0);
01322
01323
01324 if (!Stack.PopColour(&Col, Tint, &TintVal, &ColName))
01325
01326 goto EPSError;
01327
01328 GetEPSColour(&EndColour, &Col, Tint, TintVal, &ColName);
01329
01330
01331
01332 if (!Stack.PopColour(&Col, Tint, &TintVal, &ColName))
01333
01334 goto EPSError;
01335
01336 GetEPSColour(&StartColour, &Col, Tint, TintVal, &ColName);
01337
01338
01339 GradFill = TRUE;
01340 break;
01341
01342 default:
01343 return CorelEPSFilter::ProcessToken();
01344 }
01345
01346
01347
01348 return TRUE;
01349
01350
01351
01352
01353 EPSError:
01354 HandleEPSError();
01355 return FALSE;
01356 #if 0
01357 NoMemory:
01358 HandleNoMemory();
01359 return FALSE;
01360 #endif
01361 }
01362
01363
01364
01365
01366
01367
01368
01369
01370
01371
01372
01373
01374
01375
01376
01377 char *Corel3EPSFilter::GetEPSCommand(EPSCommand Cmd)
01378 {
01379 INT32 i = 0;
01380 while (Corel3Commands[i].Cmd != EPSC_Invalid)
01381 {
01382 if (Corel3Commands[i].Cmd == Cmd)
01383 return Corel3Commands[i].CmdStr;
01384
01385
01386 i++;
01387 }
01388
01389
01390 return CorelEPSFilter::GetEPSCommand(Cmd);
01391 }
01392
01393
01394
01395
01396
01397
01398 enum
01399 {
01400 EPSC_cd4_0k = EPSC_cd_Sentinel + 1,
01401 EPSC_cd4_0x,
01402 EPSC_eoclip,
01403 EPSC_cd5_0gs,
01404 EPSC_cd5_0gr,
01405 EPSC_cd5_0np
01406 };
01407
01408
01409 CommandMap Corel4EPSFilter::Corel4Commands[] =
01410 {
01411 EPSC_cd4_0k, "@k",
01412 EPSC_cd4_0x, "@x",
01413 EPSC_eoclip, "eoclip",
01414 EPSC_cd5_0gs, "@gs",
01415 EPSC_cd5_0gr, "@gr",
01416 EPSC_cd5_0np, "@np",
01417
01418
01419 EPSC_Invalid, "Invalid"
01420 };
01421
01422
01423
01424
01425
01426
01427
01428
01429
01430
01431
01432
01433
01434 Corel4EPSFilter::Corel4EPSFilter()
01435 {
01436
01437 FilterID = FILTERID_COREL4_EPS;
01438 ImportMsgID = _R(IDT_IMPORTMSG_COREL4);
01439
01440 #ifndef STANDALONE
01441 Flags.CanImport = TRUE;
01442 Flags.CanExport = FALSE;
01443 #else
01444 Flags.CanImport = FALSE;
01445 Flags.CanExport = FALSE;
01446 #endif
01447 }
01448
01449
01450
01451
01452
01453
01454
01455
01456
01457
01458
01459
01460
01461
01462 BOOL Corel4EPSFilter::Init()
01463 {
01464
01465 pOILFilter = new Corel4EPSOILFilter(this);
01466 if (pOILFilter == NULL)
01467 return FALSE;
01468
01469
01470 FilterName.Load(_R(IDT_CORELEPS_FILTERNAME));
01471 FilterInfo.Load(_R(IDT_CORELEPS_FILTERINFO));
01472
01473
01474 return TRUE;
01475 }
01476
01477
01478
01479
01480
01481
01482
01483
01484
01485
01486
01487
01488
01489 INT32 Corel4EPSFilter::EPSHeaderIsOk(ADDR pFileHeader, UINT32 HeaderSize)
01490 {
01491
01492 if (camStrncmp((char *) pFileHeader, "%!PS-Adobe-2.0 EPSF-2.0", 23) != 0)
01493 {
01494
01495 return 0;
01496 }
01497
01498
01499
01500
01501
01502 istrstream HeaderFile((char *) pFileHeader, HeaderSize);
01503 char Buffer[200];
01504 BOOL HaveCreatorString = FALSE;
01505
01506 UINT32 Lines = 0;
01507 while ((Lines < 20) && !HeaderFile.eof())
01508 {
01509 HeaderFile.getline(Buffer, 200);
01510 Lines++;
01511
01512 if (camStrncmp(Buffer, "%%BeginResource: procset wCorel4Dict", 36) == 0)
01513
01514 return 10;
01515
01516 if ((camStrncmp(Buffer, "%%Creator:", 10) == 0) && (camStrclen(Buffer) <= 12))
01517 {
01518
01519 if (IsUserName("Tim"))
01520 TRACE( _T("Found blank creator field\n"));
01521
01522
01523
01524
01525 return 6;
01526 }
01527
01528 if ((camStrncmp(Buffer, "%%Creator: CorelDRAW!", 21) == 0) && (camStrclen(Buffer) <= 23))
01529 {
01530
01531 HaveCreatorString = TRUE;
01532 }
01533
01534 if(camStrncmp(Buffer, "/wCorel5Dict", 12) == 0 && HaveCreatorString)
01535 {
01536
01537 return 10;
01538 }
01539
01540 }
01541
01542
01543
01544 return 5;
01545
01546 }
01547
01548
01549
01550
01551
01552
01553
01554
01555
01556
01557
01558
01559
01560 void Corel4EPSFilter::LookUpToken()
01561 {
01562
01563
01564
01565
01566 if(Token == EPSC_Comment)
01567 {
01568
01569 if(camStrncmp(TokenBuf, "%SetClippingRegion", 17) == 0)
01570 Token = EPSC_q;
01571 else if(camStrncmp(TokenBuf, "%ClearClipping", 13) == 0)
01572 Token = EPSC_Q;
01573
01574 return;
01575 }
01576
01577
01578
01579 INT32 i = 0;
01580 while (Corel4Commands[i].Cmd != EPSC_Invalid)
01581 {
01582 if (camStrcmp(TokenBuf, Corel4Commands[i].CmdStr) == 0)
01583 {
01584
01585 Token = Corel4Commands[i].Cmd;
01586 return;
01587 }
01588
01589 i++;
01590 }
01591
01592
01593 CorelEPSFilter::LookUpToken();
01594 }
01595
01596
01597
01598
01599
01600
01601
01602
01603
01604
01605
01606
01607
01608
01609
01610 BOOL Corel4EPSFilter::ProcessToken()
01611 {
01612
01613 PColourCMYK Col;
01614 DocCoord Coords[3];
01615 TintType Tint = TINT_NONE;
01616 double Padding, RotateX, RotateY;
01617
01618
01619 switch (Token)
01620 {
01621 case EPSC_cd4_0x:
01622 Tint = TINT_COREL;
01623 case EPSC_cd4_0k:
01624
01625 if (!Stack.Pop(&RotateY) || !Stack.Pop(&RotateX) ||
01626 !Stack.Pop(&Padding) || !Stack.Pop(&GradFillInfo.FillType) ||
01627 !Stack.Pop(&GradFillInfo.Angle) || !Stack.Discard(3))
01628 goto EPSError;
01629
01630
01631
01632
01633
01634 GradFillInfo.EdgePad = (INT32) (Padding * 100.0);
01635 GradFillInfo.RotateX = (INT32) (RotateX * 100.0);
01636 GradFillInfo.RotateY = (INT32) (RotateY * 100.0);
01637
01638 if (Stack.GetType() != EPSTYPE_COMMAND)
01639 {
01640 if (IsUserName("Tim"))
01641 TRACE( _T("@x/@k: Expected ArrayEnd, found '%s'\n"), TokenBuf);
01642 goto EPSError;
01643 }
01644
01645 EPSCommand Cmd;
01646 Stack.PopCmd(&Cmd);
01647 if (Cmd != EPSC_ArrayEnd)
01648 {
01649 if (IsUserName("Tim"))
01650 TRACE( _T("@x/@k: Expected ArrayEnd, found '%s'\n"), GetEPSCommand(Cmd));
01651 goto EPSError;
01652 }
01653
01654
01655 if (!Stack.Discard())
01656 goto EPSError;
01657
01658
01659 if (!Stack.PopColour(&Col, Tint))
01660
01661 goto EPSError;
01662 EndColour.SetCMYKValue(&Col);
01663
01664
01665 if (!Stack.Discard())
01666 goto EPSError;
01667
01668
01669 if (!Stack.PopColour(&Col, Tint))
01670
01671 goto EPSError;
01672 StartColour.SetCMYKValue(&Col);
01673
01674
01675 if (Stack.IsEmpty())
01676 {
01677
01678 if (IsUserName("Tim"))
01679 TRACE( _T("@x/@k: Run out of operands\n"));
01680 goto EPSError;
01681 }
01682
01683 if (Stack.GetType() != EPSTYPE_COMMAND)
01684 {
01685 if (IsUserName("Tim"))
01686 TRACE( _T("@x/@k: Expected ArrayStart but found '%s'\n"), TokenBuf);
01687 goto EPSError;
01688 }
01689 else
01690 {
01691 EPSCommand Cmd = Stack.ReadCmd();
01692 if (!Stack.PopCmd(&Cmd) || Cmd != EPSC_ArrayStart)
01693 {
01694 if (IsUserName("Tim"))
01695 TRACE( _T("@x/@k: Expected ArrayStart, found '%s'\n"), GetEPSCommand(Cmd));
01696 goto EPSError;
01697 }
01698 }
01699
01700 GradFill = TRUE;
01701
01702 break;
01703
01704 case EPSC_eoclip:
01705
01706 EPSFlags.PathIsHidden = TRUE;
01707 Token = EPSC_W;
01708 return EPSFilter::ProcessToken();
01709 break;
01710
01711 case EPSC_cd5_0gs:
01712 return Import_gsave();
01713 break;
01714
01715 case EPSC_cd5_0gr:
01716 return Import_grestore();
01717 break;
01718
01719 case EPSC_cd5_0np:
01720
01721 if(pInkPath !=0)
01722 {
01723 if(!pInkPath->ClearPath())
01724 return FALSE;
01725 }
01726 break;
01727
01728 default:
01729 return CorelEPSFilter::ProcessToken();
01730 break;
01731 }
01732
01733
01734
01735 return TRUE;
01736
01737
01738
01739
01740 EPSError:
01741 HandleEPSError();
01742 return FALSE;
01743 #if 0
01744 NoMemory:
01745 HandleNoMemory();
01746 return FALSE;
01747 #endif
01748 }
01749
01750
01751
01752
01753
01754
01755
01756
01757
01758
01759
01760
01761
01762
01763
01764 char *Corel4EPSFilter::GetEPSCommand(EPSCommand Cmd)
01765 {
01766 INT32 i = 0;
01767 while (Corel4Commands[i].Cmd != EPSC_Invalid)
01768 {
01769 if (Corel4Commands[i].Cmd == Cmd)
01770 return Corel4Commands[i].CmdStr;
01771
01772
01773 i++;
01774 }
01775
01776
01777 return CorelEPSFilter::GetEPSCommand(Cmd);
01778 }
01779
01780