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 "cameleps.h"
00107
00108 #include "nodepath.h"
00109
00110
00111
00112 #include "ccdc.h"
00113
00114 #include "page.h"
00115
00116 #include "bitmpinf.h"
00117
00118 #include "nodebmp.h"
00119 #include "fracfill.h"
00120
00121 #include "nodeblnd.h"
00122 #include "nodebldr.h"
00123 #include "nodershp.h"
00124 #include "nodemold.h"
00125 #include "ndmldgrp.h"
00126 #include "nodemldr.h"
00127 #include "ndmldpth.h"
00128 #include "nodeshap.h"
00129
00130 #include "grndbmp.h"
00131 #include "camview.h"
00132
00133 #include "opgrad.h"
00134 #include "oilfiles.h"
00135 #include "ndoptmz.h"
00136 #include "ndtxtpth.h"
00137 #include "maskedrr.h"
00138 #include "oilbitmap.h"
00139
00140 #include "native.h"
00141 #include "nativeps.h"
00142 #include "psdc.h"
00143 #include "osrndrgn.h"
00144 #include "prdlgctl.h"
00145 #include "progress.h"
00146 #include "textfuns.h"
00147
00148
00149
00150
00151 #include "fontman.h"
00152 #include "guides.h"
00153 #include "snap.h"
00154
00155 #include "layer.h"
00156 #include "colormgr.h"
00157 #include "attrmap.h"
00158 #include "colplate.h"
00159
00160
00161
00162 #include "xsepsops.h"
00163 #include "ctrlhelp.h"
00164
00165 #include "unicdman.h"
00166
00167 DECLARE_SOURCE("$Revision: 1431 $");
00168
00169 #define new CAM_DEBUG_NEW
00170
00171
00172 CC_IMPLEMENT_DYNAMIC(CamelotEPSFilter, ArtWorksEPSFilter)
00173
00174
00175
00176 typedef enum
00177 {
00178 FILLEFFECT_FADE,
00179 FILLEFFECT_RAINBOW,
00180 FILLEFFECT_ALTRAINBOW
00181 } TranspFillEffectType;
00182
00183
00184
00185
00186 CommandMap CamelotEPSFilter::CamelotCommands[] =
00187 {
00188
00189 { EPSC_cx, _T("cx") },
00190 { EPSC_cX, _T("cX") },
00191 { EPSC_ck, _T("ck") },
00192 { EPSC_cK, _T("cK") },
00193
00194
00195 { EPSC_cst, _T("cst") },
00196
00197
00198 { EPSC_csah, _T("csah") },
00199 { EPSC_ceah, _T("ceah") },
00200
00201
00202 { EPSC_cdp, _T("cdp") },
00203
00204
00205 { EPSC_cbm, _T("cbm") },
00206 { EPSC_csbm, _T("csbm") },
00207 { EPSC_cebm, _T("cebm") },
00208
00209
00210 { EPSC_caz, _T("caz") },
00211 { EPSC_cax, _T("cax") },
00212
00213
00214 { EPSC_cxt, _T("cxt") },
00215
00216
00217 { EPSC_cxe, _T("cxe") },
00218
00219
00220 { EPSC_cxm, _T("cxm") },
00221
00222
00223 { EPSC_cxmt, _T("cxmt") },
00224
00225
00226 { EPSC_csbd, _T("csbd") },
00227 { EPSC_cebd, _T("cebd") },
00228 { EPSC_csbr, _T("csbr") },
00229 { EPSC_cebr, _T("cebr") },
00230
00231
00232 { EPSC_csrs, _T("csrs") },
00233 { EPSC_crsp, _T("crsp") },
00234 { EPSC_crstm, _T("crstm") },
00235 { EPSC_crsp1, _T("crsp1") },
00236 { EPSC_crsp2, _T("crsp2") },
00237 { EPSC_cers, _T("cers") },
00238
00239
00240 { EPSC_csev, _T("csev") },
00241 { EPSC_ceev, _T("ceev") },
00242 { EPSC_cspr, _T("cspr") },
00243 { EPSC_cepr, _T("cepr") },
00244 { EPSC_csmp, _T("csmp") },
00245 { EPSC_cemp, _T("cemp") },
00246 { EPSC_csso, _T("csso") },
00247 { EPSC_ceso, _T("ceso") },
00248 { EPSC_csdo, _T("csdo") },
00249 { EPSC_cedo, _T("cedo") },
00250
00251
00252 { EPSC_ctf, _T("ctf") },
00253 { EPSC_ctb, _T("ctb") },
00254 { EPSC_cti, _T("cti") },
00255 { EPSC_cts, _T("cts") },
00256 { EPSC_ctp, _T("ctp") },
00257 { EPSC_ctls, _T("ctls") },
00258
00259 { EPSC_cso, _T("cso") },
00260 { EPSC_ceo, _T("ceo") },
00261 { EPSC_cfft, _T("cfft") },
00262 { EPSC_cftf, _T("cftf") },
00263 { EPSC_cbot, _T("cbot") },
00264
00265 { EPSC_cpal, _T("cpal") },
00266
00267
00268 { EPSC_glyr, _T("glyr") },
00269 { EPSC_glne, _T("glne") },
00270
00271 { EPSC_cmth, _T("cmth") },
00272
00273 { EPSC_cag, _T("cag") },
00274
00275 { EPSC_cbti, _T("cbti") },
00276
00277
00278 { EPSC_Invalid, _T("Invalid") }
00279 };
00280
00281
00282
00283
00284
00285
00286
00287
00288
00289
00290
00291
00292
00293 CamelotEPSFilter::CamelotEPSFilter()
00294 {
00295
00296 FilterNameID = _R(IDT_CAMEPS_FILTERNAME);
00297 FilterInfoID = _R(IDT_CAMEPS_FILTERINFO);
00298 ImportMsgID = _R(IDT_IMPORTMSG_CAMELOT);
00299 ExportMsgID = _R(IDT_EXPORTMSG_CAMEPS);
00300
00301 FilterID = FILTERID_CAMELOT_EPS;
00302
00303 #ifndef STANDALONE
00304 Flags.CanImport = TRUE;
00305
00306 #ifdef WEBSTER
00307 Flags.CanExport = FALSE;
00308 #else
00309 Flags.CanExport = TRUE;
00310 #endif //WEBSTER
00311 #else
00312 Flags.CanImport = FALSE;
00313 Flags.CanExport = FALSE;
00314 #endif
00315
00316
00317
00318 AdjustOrigin = FALSE;
00319
00320 }
00321
00322
00323
00324
00325
00326
00327
00328
00329
00330
00331
00332
00333
00334
00335 BOOL CamelotEPSFilter::Init()
00336 {
00337
00338 pOILFilter = new CamelotEPSOILFilter(this);
00339 if (pOILFilter == NULL)
00340 return FALSE;
00341
00342
00343 FilterName.Load(FilterNameID);
00344 FilterInfo.Load(FilterInfoID);
00345
00346
00347 return TRUE;
00348 }
00349
00350
00351
00352
00353
00354
00355
00356
00357
00358
00359
00360
00361
00362
00363
00364 BOOL CamelotEPSFilter::CanIncludePreviewBmp()
00365 {
00366 return TRUE;
00367 }
00368
00369
00370
00371
00372
00373
00374
00375
00376
00377
00378
00379
00380
00381
00382
00383
00384
00385
00386
00387
00388
00389 BOOL CamelotEPSFilter::IsDefaultDocRequired(const TCHAR* pcszPathName)
00390 {
00391
00392 return FALSE;
00393 }
00394
00395
00396
00397
00398
00399
00400
00401
00402
00403
00404
00405
00406
00407
00408 INT32 CamelotEPSFilter::EPSHeaderIsOk(ADDR pFileHeader, UINT32 HeaderSize)
00409 {
00410
00411
00412 if (strncmp((char *) pFileHeader, "%!PS-Adobe-2.0 EPSF-1.2", 23) != 0)
00413 {
00414
00415 return 0;
00416 }
00417
00418
00419 istringstream HeaderFile( (char*)pFileHeader );
00420 char Buffer[200];
00421
00422 UINT32 Lines = 0;
00423 while ((Lines < 20) && !HeaderFile.eof())
00424 {
00425 HeaderFile.getline(Buffer, 200);
00426 Lines++;
00427
00428
00429 if (strncmp(Buffer, "%%Creator: Camelot", 18) == 0)
00430 {
00431
00432 return 10;
00433 }
00434
00435 else if (strncmp (Buffer, "%%Creator: Xara X", 17) == 0)
00436 {
00437
00438 return 10;
00439 }
00440
00441
00442
00443 if (strncmp(Buffer, "%%Compression:", 14)==0)
00444 break;
00445 }
00446
00447
00448
00449 return 5;
00450 }
00451
00452
00453
00454
00455
00456
00457
00458
00459
00460
00461
00462
00463
00464
00465
00466 BOOL CamelotEPSFilter::PrepareToImport()
00467 {
00468 if(IS_A(this, CamelotEPSFilter))
00469 {
00470
00471 PathName Path;
00472 String_256 FileName;
00473 BOOL HaveName = FALSE;
00474 if(EPSFile->IsKindOf(CC_RUNTIME_CLASS(CCDiskFile)))
00475 {
00476 CCDiskFile *DF = (CCDiskFile *)EPSFile;
00477
00478 Path = DF->GetPathName();
00479 FileName = Path.GetFileName();
00480 HaveName = TRUE;
00481 }
00482 String_256 ErrMsg;
00483 if(HaveName)
00484 {
00485 String_256 ErrMsg;
00486 ErrMsg.MakeMsg(_R(IDE_LOADCAMELOTEPSITHINKNOTNAMED), (TCHAR *)FileName);
00487 Error::SetError(0, ErrMsg, 0);
00488 }
00489 else
00490 {
00491 Error::SetError(_R(IDE_LOADCAMELOTEPSITHINKNOT));
00492 }
00493 return FALSE;
00494 }
00495 else
00496 {
00497
00498 if (!ArtWorksEPSFilter::PrepareToImport())
00499 return FALSE;
00500
00501
00502 m_PendingBitmap = PENDING_BITMAP_NONE;
00503 BitmapTransparencyIndex = -1;
00504 pBitmap = FALSE;
00505 pRegularShape = NULL;
00506 }
00507
00508 return TRUE;
00509 }
00510
00511
00512
00513
00514
00515
00516
00517
00518
00519
00520
00521
00522
00523
00524 void CamelotEPSFilter::CleanUpAfterImport(BOOL Successful)
00525 {
00526 if(IS_A(this, CamelotEPSFilter))
00527 return;
00528
00529 ArtWorksEPSFilter::CleanUpAfterImport(Successful);
00530 }
00531
00532
00533
00534
00535
00536
00537
00538
00539
00540
00541
00542
00543
00544
00545
00546
00547
00548 BOOL CamelotEPSFilter::GetExportOptions( )
00549 {
00550 #if !defined(EXCLUDE_FROM_RALPH)
00551 OpDescriptor* pOpDesc = OpDescriptor::FindOpDescriptor(CC_RUNTIME_CLASS(XSEPSExportOptions));
00552 if ( pOpDesc )
00553 pOpDesc->Invoke();
00554
00555 return !XSEPSExportOptions::Aborted;
00556 #endif
00557 return TRUE;
00558 }
00559
00560
00561
00562
00563
00564
00565
00566
00567
00568
00569
00570
00571
00572
00573
00574
00575
00576
00577 BOOL CamelotEPSFilter::PrepareToExport(CCLexFile* pFile, Spread* pSpread)
00578 {
00579 #if !defined(EXCLUDE_FROM_RALPH)
00580
00581 if (!EPSFilter::PrepareToExport(pFile, pSpread))
00582 return FALSE;
00583
00584
00585 ExportDCPtr->SetFullAccuracy(TRUE);
00586
00587
00588 if (IS_A(this, CamelotEPSFilter))
00589 {
00590
00591 DocRect NullClipRect;
00592 NullClipRect.MakeEmpty();
00593
00594
00595 Matrix Identity;
00596
00597
00598 FIXED16 Scale(1);
00599
00600 ExportRegion = new CamelotEPSRenderRegion(NullClipRect, Identity, Scale);
00601 if (ExportRegion == NULL)
00602 return FALSE;
00603
00604
00605 ExportRegion->AttachDevice(DocView::GetSelected(), ExportDCPtr->GetDC(), pSpread);
00606 }
00607 #endif
00608
00609 return TRUE;
00610 };
00611
00612
00613
00614
00615
00616
00617
00618
00619
00620
00621
00622
00623
00624
00625 void CamelotEPSFilter::LookUpToken()
00626 {
00627
00628 if (Token == EPSC_Comment)
00629 return;
00630
00631
00632
00633 INT32 i = 0;
00634 while (CamelotCommands[i].Cmd != EPSC_Invalid)
00635 {
00636 if (camStrcmp(TokenBuf, CamelotCommands[i].CmdStr) == 0)
00637 {
00638
00639 Token = CamelotCommands[i].Cmd;
00640 return;
00641 }
00642
00643 i++;
00644 }
00645
00646
00647 ArtWorksEPSFilter::LookUpToken();
00648 }
00649
00650
00651
00652
00653
00654
00655
00656
00657
00658
00659
00660
00661
00662
00663
00664
00665 BOOL CamelotEPSFilter::ProcessToken()
00666 {
00667
00668 String_64 ColName;
00669 PColourCMYK Col;
00670 TintType Tint = TINT_NONE;
00671 FIXEDPOINT TintVal;
00672 DocCoord StartPoint,
00673 EndPoint;
00674 PathFlags Flags;
00675 INT32 ObjectNesting = 0;
00676
00677 DocCoord BmpCoords[4];
00678 INT32 i;
00679
00680
00681 static NodeBitmap *pBitmapObject = NULL;
00682
00683
00684 switch (Token)
00685 {
00686 case EPSC_cso:
00687 INT32 ObjectID;
00688 if (!Stack.Pop(&ObjectID))
00689 goto EPSError;
00690
00691 switch (ObjectID)
00692 {
00693 case EOTAG_FONTFLAGS:
00694 {
00695 if (!ProcessFontFlags())
00696 goto EPSError;
00697 }
00698 break;
00699
00700 case EOTAG_BITMAPFLAGS:
00701 {
00702 if (!ProcessBitmapFlags())
00703 goto EPSError;
00704 }
00705 break;
00706
00707 case EOTAG_TEXTWRAPPED:
00708 {
00709 if (!FindEndOfTag())
00710 goto EPSError;
00711 }
00712 break;
00713
00714 case EOTAG_FONTTYPE:
00715 {
00716 if (!ProcessFontType())
00717 goto EPSError;
00718 }
00719 break;
00720
00721 case EOTAG_GUIDELAYER:
00722 case EOTAG_GUIDELINE:
00723 break;
00724
00725 case EOTAG_MOULDTHRESHOLD:
00726 {
00727 if (!ProcessMouldThreshold())
00728 goto EPSError;
00729 }
00730 break;
00731
00732
00733 default:
00734 {
00735
00736 ERROR1RAW(_R(IDE_UNKNOWN_EPSOBJECT));
00737 ObjectNesting++;
00738 do
00739 {
00740 if (!GetToken())
00741 goto EPSError;
00742
00743 LexTokenType Type = EPSFile->GetTokenType();
00744 if ((Type != TOKEN_EOL) && (Type != TOKEN_EOF))
00745 {
00746 if (camStrcmp(TokenBuf, _T("cso")) == 0)
00747 {
00748 ObjectNesting++;
00749 }
00750 else if (camStrcmp(TokenBuf, _T("ceo")) == 0)
00751 {
00752 ObjectNesting--;
00753 }
00754 }
00755 }
00756 while (ObjectNesting > 0);
00757 }
00758 break;
00759 }
00760
00761 break;
00762
00763 case EPSC_ceo:
00764 break;
00765
00766
00767
00768 case EPSC_cx:
00769 case EPSC_cX:
00770 case EPSC_ck:
00771 case EPSC_cK:
00772 break;
00773
00774
00775 case EPSC_cax:
00776
00777 Tint = TINT_ILLUSTRATOR;
00778 case EPSC_caz:
00779 {
00780 DocColour StartColour, EndColour;
00781 DocCoord StartPoint, EndPoint, EndPoint2;
00782 CamelotEPSFillType FillType;
00783
00784
00785 INT32 Seed;
00786 double Graininess, Gravity, Squash;
00787 UINT32 DPI;
00788 INT32 Tileable;
00789
00790
00791 if (!Stack.Pop((INT32*) &FillType))
00792 goto EPSError;
00793
00794 TRACEUSER( "Will", _T("Importing Fill, Type=%d\n"),FillType);
00795
00796 if (FillType == CAMEPS_FILL_FRACTAL)
00797 {
00798
00799
00800 INT32 SubType;
00801
00802 if (!Stack.Pop(&SubType))
00803 goto EPSError;
00804
00805
00806 Tileable = FALSE;
00807
00808
00809
00810 if (SubType != 0)
00811 {
00812 if (SubType == 1)
00813 {
00814
00815 if (!Stack.Pop(&Tileable))
00816 goto EPSError;
00817 }
00818 else
00819 {
00820 ERROR2RAW("Bad fractal fill sub-type");
00821 goto EPSError;
00822 }
00823 }
00824
00825
00826 if (!Stack.Pop(&DPI) ||
00827 !Stack.Pop(&Squash) ||
00828 !Stack.Pop(&Gravity) ||
00829 !Stack.Pop(&Graininess) ||
00830 !Stack.Pop(&Seed))
00831 {
00832
00833 goto EPSError;
00834 }
00835 }
00836
00837
00838 if ((FillType == CAMEPS_FILL_ELLIPTICAL) ||
00839 (FillType == CAMEPS_FILL_BITMAP) ||
00840 (FillType == CAMEPS_FILL_FRACTAL) ||
00841 (FillType == CAMEPS_FILL_NEWBITMAP) ||
00842 (FillType == CAMEPS_FILL_NEWLINEAR))
00843 {
00844 if (!Stack.PopCoordPair(&EndPoint2))
00845 goto EPSError;
00846 }
00847
00848
00849 if (!Stack.PopCoordPair(&EndPoint) || !Stack.PopCoordPair(&StartPoint))
00850 goto EPSError;
00851
00852
00853 if (FillType != CAMEPS_FILL_BITMAP)
00854 {
00855 if (!Stack.PopColour(&Col, Tint, &TintVal, &ColName))
00856
00857 goto EPSError;
00858
00859 GetEPSColour(&EndColour, &Col, Tint, TintVal, &ColName);
00860
00861 if (!Stack.PopColour(&Col, Tint, &TintVal, &ColName))
00862
00863 goto EPSError;
00864
00865 GetEPSColour(&StartColour, &Col, Tint, TintVal, &ColName);
00866 }
00867
00868 switch (FillType)
00869 {
00870
00871 case CAMEPS_FILL_LINEAR:
00872 if (!SetLinearFill(StartColour, EndColour, StartPoint, EndPoint))
00873 goto NoMemory;
00874 break;
00875
00876 case CAMEPS_FILL_NEWLINEAR:
00877 if (!SetLinearFill(StartColour, EndColour, StartPoint, EndPoint, &EndPoint2))
00878 goto NoMemory;
00879 break;
00880
00881 case CAMEPS_FILL_ELLIPTICAL:
00882 if (!SetRadialFill(StartColour, EndColour, StartPoint, EndPoint, EndPoint2))
00883 goto NoMemory;
00884 break;
00885
00886 case CAMEPS_FILL_CIRCULAR:
00887 if (!SetRadialFill(StartColour, EndColour, StartPoint, EndPoint))
00888 goto NoMemory;
00889 break;
00890
00891 case CAMEPS_FILL_CONICAL:
00892 if (!SetConicalFill(StartColour, EndColour, StartPoint, EndPoint))
00893 goto NoMemory;
00894 break;
00895
00896 case CAMEPS_FILL_BITMAP:
00897
00898
00899
00900 if (m_PendingBitmap != PENDING_BITMAP_OBJECT_FILL)
00901 m_PendingBitmap = PENDING_BITMAP_FILL;
00902
00903 BitmapAttrs.Coords[0] = StartPoint;
00904 BitmapAttrs.Coords[1] = EndPoint;
00905 BitmapAttrs.Coords[2] = EndPoint2;
00906
00907 BitmapAttrs.StartCol = COLOUR_NONE;
00908 BitmapAttrs.EndCol = COLOUR_NONE;
00909 break;
00910
00911 case CAMEPS_FILL_NEWBITMAP:
00912 m_PendingBitmap = PENDING_BITMAP_FILL;
00913 BitmapAttrs.Coords[0] = StartPoint;
00914 BitmapAttrs.Coords[1] = EndPoint;
00915 BitmapAttrs.Coords[2] = EndPoint2;
00916
00917 BitmapAttrs.StartCol = StartColour;
00918 BitmapAttrs.EndCol = EndColour;
00919 break;
00920
00921 case CAMEPS_FILL_FRACTAL:
00922 if (!SetFractalFill(StartColour, EndColour,
00923 StartPoint, EndPoint, EndPoint2,
00924 Seed, Graininess, Gravity, Squash, DPI, Tileable))
00925 goto NoMemory;
00926 break;
00927
00928 default:
00929 ENSURE(FALSE, "Unknown fill type found!");
00930 break;
00931 }
00932
00933 break;
00934 }
00935
00936
00937 case EPSC_cxe:
00938 {
00939 INT32 EffectType;
00940
00941
00942 if (!Stack.Pop(&EffectType))
00943 goto EPSError;
00944
00945
00946 switch (EffectType)
00947 {
00948 case FILLEFFECT_FADE:
00949 if (!SetFadeFillEffect())
00950 goto NoMemory;
00951 break;
00952
00953 case FILLEFFECT_RAINBOW:
00954 if (!SetRainbowFillEffect())
00955 goto NoMemory;
00956 break;
00957
00958 case FILLEFFECT_ALTRAINBOW:
00959 if (!SetAltRainbowFillEffect())
00960 goto NoMemory;
00961 break;
00962
00963 default:
00964 ERROR3_PF(("Unknown fill effect type (%d) in EPS", EffectType));
00965 }
00966 break;
00967 }
00968
00969 case EPSC_cxm:
00970 {
00971 INT32 MappingType;
00972 INT32 Repeat;
00973
00974
00975 if (!Stack.Pop(&MappingType))
00976 goto EPSError;
00977
00978 if (MappingType != 0)
00979 {
00980 ERROR2RAW("Bad mapping type in EPS");
00981 goto EPSError;
00982 }
00983
00984
00985 if (!Stack.Pop(&Repeat))
00986 goto EPSError;
00987
00988 if ((Repeat < 1) || (Repeat > 3))
00989 {
00990 ERROR2RAW("Bad mapping type in EPS");
00991 goto EPSError;
00992 }
00993
00994
00995 if (Token == EPSC_cxm)
00996 {
00997 if (!SetLinearFillMapping(Repeat))
00998 goto NoMemory;
00999 }
01000 else
01001 {
01002 if (!SetLinearTranspFillMapping(Repeat))
01003 goto NoMemory;
01004 }
01005
01006 break;
01007 }
01008
01009 case EPSC_csbm:
01010
01011 if (!ReadBitmap())
01012 return FALSE;
01013 break;
01014
01015 case EPSC_cebm:
01016
01017 switch (m_PendingBitmap)
01018 {
01019 case PENDING_BITMAP_FILL:
01020
01021
01022 if (!SetBitmapFill(pBitmap,
01023 BitmapAttrs.Coords[0],
01024 BitmapAttrs.Coords[1],
01025 BitmapAttrs.Coords[2],
01026 &BitmapAttrs.StartCol,
01027 &BitmapAttrs.EndCol))
01028 return FALSE;
01029
01030
01031 BitmapAttrs.StartCol = COLOUR_NONE;
01032 BitmapAttrs.EndCol = COLOUR_NONE;
01033
01034
01035
01036 pBitmap = NULL;
01037 break;
01038
01039 case PENDING_BITMAP_TRANSPFILL:
01040
01041
01042 if (!SetBitmapTranspFill(BitmapAttrs.TranspType, pBitmap,
01043 BitmapAttrs.Coords[0],
01044 BitmapAttrs.Coords[1],
01045 BitmapAttrs.Coords[2],
01046 BitmapAttrs.Transp,
01047 BitmapAttrs.EndTransp))
01048 return FALSE;
01049
01050
01051
01052 pBitmap = NULL;
01053 break;
01054
01055 case PENDING_BITMAP_OBJECT_FILL:
01056
01057
01058
01059
01060
01061
01062
01063 pBitmapObject = new NodeBitmap;
01064 if ((pBitmapObject == NULL) || (!pBitmapObject->SetUpPath(12,12)))
01065 goto EPSError;
01066
01067
01068
01069 while (!EPSFile->eof())
01070 {
01071 GetToken();
01072
01073
01074 switch (Token)
01075 {
01076 case EPSC_Integer:
01077 Stack.Push(TokenData.Long);
01078 break;
01079
01080 case EPSC_Double:
01081 Stack.Push(TokenData.Double);
01082 break;
01083
01084 case EPSC_FixedPoint:
01085 Stack.Push(TokenData.FixedPoint);
01086 break;
01087 }
01088
01089
01090 if (Token == EPSC_F)
01091 break;
01092 }
01093
01094 Stack.Discard(2);
01095
01096
01097 for (i = 3; i >= 0; i--)
01098 {
01099 if (!Stack.PopCoordPair(&BmpCoords[i]))
01100 goto EPSError;
01101 pBitmapObject->Parallel[i] = BmpCoords[i];
01102 }
01103
01104
01105 pBitmapObject->InkPath.InsertMoveTo(BmpCoords[0]);
01106
01107 for (i = 1; i <= 3; i++)
01108 pBitmapObject->InkPath.InsertLineTo(BmpCoords[i]);
01109
01110 pBitmapObject->InkPath.InsertLineTo(BmpCoords[0]);
01111 pBitmapObject->InkPath.CloseSubPath();
01112
01113
01114 SetPathFilled(FALSE);
01115
01116
01117
01118 case PENDING_BITMAP_OBJECT:
01119 {
01120
01121
01122
01123 if (pBitmapObject == NULL)
01124
01125 goto EPSError;
01126
01127 pBitmapObject->GetBitmapRef()->Attach(pBitmap, GetDocument());
01128 if (pBitmapObject->GetBitmap() != pBitmap)
01129 {
01130
01131 delete pBitmap;
01132 }
01133
01134 pBitmap = NULL;
01135
01136 AttributeValue* pOldLineColour = NULL;
01137 AttributeValue* pOldLineWidth = NULL;
01138
01139 if (m_PendingBitmap == PENDING_BITMAP_OBJECT_FILL)
01140 {
01141
01142
01143
01144
01145
01146
01147 pOldLineColour = CurrentAttrs[ATTR_STROKECOLOUR].pAttr;
01148
01149
01150 StrokeColourAttribute* pLineCol = new StrokeColourAttribute;
01151 if (pLineCol == NULL)
01152 goto NoMemory;
01153
01154 DocColour colorNone( COLOUR_NONE );
01155 pLineCol->SetStartColour( &colorNone );
01156
01157 CurrentAttrs[ATTR_STROKECOLOUR].pAttr = pLineCol;
01158 }
01159
01160 pOldLineWidth = CurrentAttrs[ATTR_LINEWIDTH].pAttr;
01161
01162
01163 LineWidthAttribute* pLineWidth = new LineWidthAttribute;
01164 if (pLineWidth == NULL)
01165 goto NoMemory;
01166
01167 pLineWidth->LineWidth = 0;
01168
01169 CurrentAttrs[ATTR_LINEWIDTH].pAttr = pLineWidth;
01170
01171
01172 BOOL Success = AttributeManager::ApplyBasedOnDefaults(pBitmapObject,
01173 CurrentAttrs);
01174
01175
01176 if (!Success)
01177 {
01178
01179 delete pBitmapObject;
01180 pBitmapObject = NULL;
01181 goto NoMemory;
01182 }
01183
01184
01185 pBitmapObject->InvalidateBoundingRect();
01186 AddNewNode(pBitmapObject);
01187
01188
01189 SetPathFilled(TRUE);
01190
01191 if (pOldLineColour != NULL)
01192 {
01193 delete CurrentAttrs[ATTR_STROKECOLOUR].pAttr;
01194
01195
01196 CurrentAttrs[ATTR_STROKECOLOUR].pAttr = pOldLineColour;
01197 }
01198
01199 if (pOldLineWidth != NULL)
01200 {
01201 delete CurrentAttrs[ATTR_LINEWIDTH].pAttr;
01202
01203
01204 CurrentAttrs[ATTR_LINEWIDTH].pAttr = pOldLineWidth;
01205 }
01206
01207
01208
01209 pBitmap = NULL;
01210 pBitmapObject = NULL;
01211 break;
01212 }
01213
01214 case PENDING_BITMAP_POOLITEM:
01215 {
01216
01217 TRACEUSER( "Rik", _T("What do you know, its a Pool Item\n"));
01218 BitmapPoolAttach(pBitmap);
01219 pBitmap = NULL;
01220 break;
01221 }
01222
01223 default:
01224 ENSURE(FALSE, "Found a bitmap but don't know what to do with it!");
01225 delete pBitmap;
01226 pBitmap = NULL;
01227 goto EPSError;
01228 break;
01229 }
01230
01231 m_PendingBitmap = PENDING_BITMAP_NONE;
01232 BitmapTransparencyIndex = -1;
01233 break;
01234
01235 case EPSC_cbm:
01236 {
01237
01238 pBitmapObject = new NodeBitmap;
01239 if ((pBitmapObject == NULL) || (!pBitmapObject->SetUpPath(12,12)))
01240 return FALSE;
01241
01242
01243 DocCoord Coords[4];
01244
01245
01246 INT32 i;
01247 for ( i = 3; i >= 0; i--)
01248 {
01249 if (!Stack.PopCoordPair(&Coords[i]))
01250 goto EPSError;
01251 pBitmapObject->Parallel[i] = Coords[i];
01252 }
01253
01254
01255 pBitmapObject->InkPath.InsertMoveTo(Coords[0]);
01256
01257 for (i = 1; i <= 3; i++)
01258 pBitmapObject->InkPath.InsertLineTo(Coords[i]);
01259
01260 pBitmapObject->InkPath.InsertLineTo(Coords[0]);
01261 pBitmapObject->InkPath.CloseSubPath();
01262
01263
01264
01265
01266 m_PendingBitmap = PENDING_BITMAP_OBJECT;
01267
01268 break;
01269 }
01270
01271 case EPSC_cbmp:
01272
01273 goto EPSError;
01274
01275
01276 case EPSC_csbd:
01277 return ProcessBlend();
01278
01279 case EPSC_cebd:
01280 goto EPSError;
01281
01282 case EPSC_csbr:
01283 return ProcessBlender();
01284
01285 case EPSC_cebr:
01286 goto EPSError;
01287
01288
01289 case EPSC_csrs:
01290 return ProcessRegularShape();
01291
01292 case EPSC_cers:
01293 goto EPSError;
01294
01295 case EPSC_crsp:
01296 return ProcessRegularShapeParams();
01297
01298 case EPSC_crstm:
01299 {
01300 if (pRegularShape == NULL)
01301 goto EPSError;
01302
01303
01304 Matrix TheMatrix;
01305 if (!Stack.Pop(&TheMatrix, FALSE))
01306 goto EPSError;
01307
01308 pRegularShape->SetTransformMatrix(&TheMatrix);
01309 break;
01310 }
01311
01312 case EPSC_crsp1:
01313 {
01314 if ((pRegularShape == NULL) || (pInkPath == NULL))
01315 goto EPSError;
01316
01317
01318
01319 pRegularShape->EdgePath1.ClearPath();
01320 if (!pRegularShape->EdgePath1.CopyPathDataFrom(pInkPath))
01321 goto NoMemory;
01322
01323 pInkPath->ClearPath();
01324 break;
01325 }
01326
01327 case EPSC_crsp2:
01328 {
01329 if ((pRegularShape == NULL) || (pInkPath == NULL))
01330 goto EPSError;
01331
01332
01333
01334 pRegularShape->EdgePath2.ClearPath();
01335 if (!pRegularShape->EdgePath2.CopyPathDataFrom(pInkPath))
01336 goto NoMemory;
01337
01338
01339 delete pInkPath;
01340 pInkPath = NULL;
01341 break;
01342 }
01343
01344
01345 case EPSC_csev:
01346 return ProcessEnvelope();
01347
01348 case EPSC_cspr:
01349 return ProcessPerspective();
01350
01351
01352 case EPSC_glyr:
01353 return ProcessGuideLayer();
01354
01355 case EPSC_glne:
01356 return ProcessGuideline();
01357
01358 case EPSC_cag:
01359
01360 goto EPSError;
01361
01362 default:
01363
01364 return ArtWorksEPSFilter::ProcessToken();
01365 }
01366
01367
01368
01369 return TRUE;
01370
01371
01372
01373
01374 EPSError:
01375 HandleEPSError();
01376 return FALSE;
01377
01378 NoMemory:
01379 HandleNoMemory();
01380 return FALSE;
01381 }
01382
01383
01384
01385
01386
01387
01388
01389
01390
01391
01392
01393
01394
01395
01396
01397
01398
01399 TCHAR *CamelotEPSFilter::GetEPSCommand(EPSCommand Cmd)
01400 {
01401 INT32 i = 0;
01402 while (CamelotCommands[i].Cmd != EPSC_Invalid)
01403 {
01404 if (CamelotCommands[i].Cmd == Cmd)
01405 return CamelotCommands[i].CmdStr;
01406
01407
01408 i++;
01409 }
01410
01411
01412 return ArtWorksEPSFilter::GetEPSCommand(Cmd);
01413 }
01414
01415
01416
01417
01418
01419
01420
01421
01422
01423
01424
01425
01426
01427
01428
01429
01430
01431
01432 BOOL CamelotEPSFilter::ReadBitmap()
01433 {
01434
01435 INT32 BitmapType;
01436 if (!Stack.Pop(&BitmapType) || (BitmapType != 0))
01437 {
01438
01439 ENSURE(BitmapType == 0, "Unknown bitmap type in EPS!");
01440 HandleEPSError();
01441 return FALSE;
01442 }
01443
01444
01445
01446
01447 BitmapInfo Info;
01448 String_256 BitmapName;
01449 if (!Stack.PopCoord(&Info.RecommendedHeight) || !Stack.PopCoord(&Info.RecommendedWidth) ||
01450 !Stack.Pop(&Info.NumPaletteEntries) || !Stack.Pop(&Info.PixelDepth) ||
01451 !Stack.Pop(&Info.PixelHeight) || !Stack.Pop(&Info.PixelWidth) ||
01452 !Stack.Pop(&BitmapName))
01453 {
01454
01455 HandleEPSError();
01456 return FALSE;
01457 }
01458
01459 BOOL IsNew;
01460 BOOL ImportOk = KernelBitmap::ImportBitmap(this, &Info, BitmapType,
01461 &pBitmap, &IsNew);
01462 if (ImportOk && IsNew)
01463 {
01464
01465 pBitmap->ActualBitmap->SetName(BitmapName);
01466
01467
01468 if (BitmapTransparencyIndex >= 0)
01469 {
01470 TRACEUSER( "Will", _T("Imported bitmap with Transparent Index %d\n"), BitmapTransparencyIndex);
01471 }
01472
01473 pBitmap->SetTransparencyIndex(BitmapTransparencyIndex);
01474 }
01475
01476 return ImportOk;
01477 }
01478
01479
01480
01481
01482
01483
01484
01485
01486
01487
01488
01489
01490
01491
01492
01493
01494 void CamelotEPSFilter::BitmapPoolAttach(KernelBitmap* pBitmap)
01495 {
01496
01497
01498 if (pBitmap!=NULL)
01499 delete pBitmap;
01500 }
01501
01502
01503
01504
01505
01506
01507
01508
01509
01510
01511
01512
01513
01514
01515
01516
01517
01518
01519
01520 BOOL CamelotEPSFilter::ExportBitmap(KernelBitmap& TheBitmap)
01521 {
01522 #if !defined(EXCLUDE_FROM_RALPH)
01523 BitmapInfo Info;
01524 String_256 BitmapName;
01525
01526
01527
01528 if (TheBitmap.ActualBitmap->GetBPP() <= 8)
01529 {
01530 INT32 TransparencyIndex;
01531
01532 if (TheBitmap.ActualBitmap->GetTransparencyIndex(&TransparencyIndex))
01533 {
01534 TRACEUSER( "Will", _T("Exporting bitmap with Transparent Index %d\n"), TransparencyIndex);
01535
01536 ExportDCPtr->OutputValue((INT32) EOTAG_BITMAPFLAGS);
01537 ExportDCPtr->OutputToken(_T("cso"));
01538
01539 ExportDCPtr->OutputValue((INT32) TransparencyIndex);
01540 ExportDCPtr->OutputToken(_T("cbti"));
01541
01542 ExportDCPtr->OutputToken(_T("ceo"));
01543 ExportDCPtr->OutputNewLine();
01544 }
01545 }
01546
01547
01548 TheBitmap.ActualBitmap->GetInfo(&Info);
01549 BitmapName = TheBitmap.ActualBitmap->GetName();
01550
01551
01552 ExportDCPtr->OutputString((TCHAR*)BitmapName);
01553 ExportDCPtr->OutputValue((UINT32) Info.PixelWidth);
01554 ExportDCPtr->OutputValue((UINT32) Info.PixelHeight);
01555 ExportDCPtr->OutputValue((UINT32) Info.PixelDepth);
01556 ExportDCPtr->OutputValue((UINT32) Info.NumPaletteEntries);
01557 ExportDCPtr->OutputUserSpaceValue(Info.RecommendedWidth);
01558 ExportDCPtr->OutputUserSpaceValue(Info.RecommendedHeight);
01559
01560
01561
01562 ExportDCPtr->OutputToken(_T("0"));
01563
01564
01565 ExportDCPtr->OutputToken(_T("csbm"));
01566 ExportDCPtr->OutputNewLine();
01567
01568
01569 TheBitmap.ActualBitmap->ExportBitmap(ExportRegion);
01570
01571
01572 ExportDCPtr->OutputToken(_T("cebm"));
01573 ExportDCPtr->OutputNewLine();
01574 #endif
01575
01576 return TRUE;
01577 }
01578
01579
01580
01581
01582
01583
01584
01585
01586
01587
01588
01589
01590
01591
01592
01593 BOOL CamelotEPSFilter::ProcessFontFlags()
01594 {
01595 FontFlags.Bold = FALSE;
01596 FontFlags.Italic = FALSE;
01597
01598 while (!EPSFile->eof())
01599 {
01600 GetToken();
01601
01602
01603 switch (Token)
01604 {
01605 case EPSC_ceo:
01606
01607 return TRUE;
01608 break;
01609
01610 case EPSC_cfft:
01611
01612
01613 FontFlags.Bold = TRUE;
01614 FontFlags.Italic = TRUE;
01615 break;
01616
01617 default:
01618
01619 if (!HandleToken())
01620 return FALSE;
01621 break;
01622 }
01623 }
01624
01625 HandleEPSError();
01626 return FALSE;
01627 }
01628
01629
01630
01631
01632
01633
01634
01635
01636
01637
01638
01639
01640
01641
01642
01643 BOOL CamelotEPSFilter::ProcessFontType()
01644 {
01645 EPSFilter::ClassOfFont = FC_TRUETYPE;
01646
01647 while (!EPSFile->eof())
01648 {
01649 GetToken();
01650
01651
01652 switch (Token)
01653 {
01654 case EPSC_ceo:
01655
01656 return TRUE;
01657 break;
01658
01659 case EPSC_cftf:
01660 {
01661
01662 INT32 Type;
01663 FontClass actclass;
01664
01665 if (!Stack.Pop(&Type))
01666 {
01667 HandleEPSError();
01668 return FALSE;
01669 }
01670
01671 if (FONTMANAGER->LegalFontClass(Type, actclass))
01672 EPSFilter::ClassOfFont = actclass;
01673
01674 }
01675 break;
01676
01677 default:
01678
01679 if (!HandleToken())
01680 return FALSE;
01681 break;
01682 }
01683 }
01684
01685 HandleEPSError();
01686 return FALSE;
01687 }
01688
01689
01690
01691
01692
01693
01694
01695
01696
01697
01698
01699
01700
01701
01702
01703 BOOL CamelotEPSFilter::FindEndOfTag()
01704 {
01705
01706 while (!EPSFile->eof())
01707 {
01708 GetToken();
01709 switch (Token)
01710 {
01711 case EPSC_ceo:
01712 return TRUE;
01713 break;
01714
01715 default:
01716 if (!HandleToken())
01717 return FALSE;
01718 break;
01719 }
01720 }
01721 HandleEPSError();
01722 return FALSE;
01723 }
01724
01725
01726
01727
01728
01729
01730
01731
01732
01733
01734
01735
01736
01737
01738
01739
01740
01741
01742
01743
01744
01745 BOOL CamelotEPSFilter::ProcessBitmapFlags()
01746 {
01747
01748 while (!EPSFile->eof())
01749 {
01750 GetToken();
01751
01752
01753 switch (Token)
01754 {
01755 case EPSC_ceo:
01756
01757 return TRUE;
01758 break;
01759
01760 case EPSC_cbot:
01761
01762
01763 m_PendingBitmap = PENDING_BITMAP_OBJECT_FILL;
01764 break;
01765
01766 case EPSC_cbti:
01767
01768 INT32 Index;
01769
01770 if (!Stack.Pop(&Index))
01771 {
01772 HandleEPSError();
01773 return FALSE;
01774 }
01775
01776 BitmapTransparencyIndex = Index;
01777 break;
01778
01779 default:
01780
01781 if (!HandleToken())
01782 return FALSE;
01783 break;
01784 }
01785 }
01786
01787 HandleEPSError();
01788 return FALSE;
01789 }
01790
01791
01792
01793
01794
01795
01796
01797
01798
01799
01800
01801
01802
01803 BOOL CamelotEPSFilter::ProcessBlend()
01804 {
01805 if (!StartBlend())
01806 return FALSE;
01807
01808
01809 do
01810 {
01811 GetToken();
01812
01813
01814 if (Token == EPSC_cebd)
01815 {
01816 return EndBlend();
01817 }
01818 }
01819
01820 while (HandleToken() && (!EPSFile->eof()));
01821
01822 if (EPSFile->eof())
01823 {
01824
01825 HandleEPSError();
01826 }
01827
01828
01829 return FALSE;
01830 }
01831
01832
01833
01834
01835
01836
01837
01838
01839
01840
01841
01842
01843
01844
01845
01846
01847
01848 BOOL CamelotEPSFilter::StartBlend()
01849 {
01850 INT32 NumBlendSteps,Version,OneToOne,NotAntialiased,ColBlendType;
01851 INT32 Reserved3,Reserved2,Reserved1;
01852
01853
01854 if (!Stack.Pop(&Version))
01855 return FALSE;
01856
01857
01858 ERROR1IF(Version != 1,FALSE,_R(IDT_EPS_BADSYNTAX));
01859
01860
01861 if (!Stack.Pop(&NumBlendSteps) ||
01862 !Stack.Pop(&NotAntialiased) ||
01863 !Stack.Pop(&OneToOne) ||
01864 !Stack.Pop(&ColBlendType) ||
01865 !Stack.Pop(&Reserved3) ||
01866 !Stack.Pop(&Reserved2) ||
01867 !Stack.Pop(&Reserved1))
01868 {
01869 return FALSE;
01870 }
01871
01872
01873 NodeBlend *pNodeBlend = new NodeBlend;
01874 ERROR1IF(pNodeBlend == NULL, FALSE, _R(IDT_EPS_NOMEMORY));
01875
01876
01877 if (!AddNewNode(pNodeBlend))
01878 return FALSE;
01879
01880
01881 pNodeBlend->SetOneToOne(OneToOne);
01882 pNodeBlend->SetNotAntialiased(NotAntialiased);
01883 pNodeBlend->SetNumBlendSteps(NumBlendSteps);
01884 pNodeBlend->SetColourBlendType((ColourBlendType)ColBlendType);
01885
01886
01887 pNode = pNodeBlend;
01888
01889
01890 return TRUE;
01891 }
01892
01893
01894
01895
01896
01897
01898
01899
01900
01901
01902
01903
01904
01905
01906
01907
01908
01909
01910
01911
01912 BOOL CamelotEPSFilter::EndBlend()
01913 {
01914
01915 ENSURE(pNode->IsKindOf(CC_RUNTIME_CLASS(NodeBlend)), "No blend in CamelotEPSFilter::EndBlend");
01916
01917
01918 Node* pNodeBlend = pNode;
01919 Node* pChildNode = pNode->FindFirstChild();
01920
01921
01922 pNode = pNodeBlend->FindParent();
01923 ENSURE(pNode != NULL, "Blend has no parent in ProcessBlend()");
01924
01925
01926 UINT32 BlenderCount=0;
01927 while (pChildNode != NULL)
01928 {
01929 if (IS_A(pChildNode,NodeBlender))
01930 {
01931 NodeBlender* pNodeBlender = (NodeBlender*)pChildNode;
01932
01933
01934 INT32 PathIndexStart = pNodeBlender->GetPathIndexStart();
01935 INT32 PathIndexEnd = pNodeBlender->GetPathIndexEnd();
01936 INT32 ObjIndexStart = pNodeBlender->GetObjIndexStart();
01937 INT32 ObjIndexEnd = pNodeBlender->GetObjIndexEnd();
01938
01939
01940 NodeRenderableInk* pNodeStart = pNodeBlender->FindObjIndexedNode(ObjIndexStart);
01941 NodeRenderableInk* pNodeEnd = pNodeBlender->FindObjIndexedNode(ObjIndexEnd);
01942
01943
01944 if (pNodeStart == NULL || pNodeEnd == NULL)
01945 return FALSE;
01946
01947
01948 if (!pNodeBlender->Initialise(pNodeStart,pNodeEnd,PathIndexStart,PathIndexEnd,ImportInfo.pOp,NULL,TRUE))
01949 return FALSE;
01950
01951 BlenderCount++;
01952 }
01953 pChildNode = pChildNode->FindNext();
01954 }
01955
01956 if (BlenderCount == 0)
01957 {
01958 ERROR3("Imported Blend node doesn't contain any blender nodes");
01959 if (!ImportInfo.pOp->DoHideNode(pNodeBlend, TRUE))
01960 return FALSE;
01961 }
01962
01963 return TRUE;
01964 }
01965
01966
01967
01968
01969
01970
01971
01972
01973
01974
01975
01976
01977
01978
01979 BOOL CamelotEPSFilter::ProcessBlender()
01980 {
01981 if (!StartBlender())
01982 return FALSE;
01983
01984
01985 do
01986 {
01987 GetToken();
01988
01989
01990 if (Token == EPSC_cebr)
01991 {
01992 return EndBlender();
01993 }
01994 }
01995
01996 while (HandleToken() && (!EPSFile->eof()));
01997
01998 if (EPSFile->eof())
01999 {
02000
02001 HandleEPSError();
02002 }
02003
02004
02005 return FALSE;
02006 }
02007
02008
02009
02010
02011
02012
02013
02014
02015
02016
02017
02018
02019
02020
02021
02022
02023 BOOL CamelotEPSFilter::StartBlender()
02024 {
02025 INT32 ObjIndexStart,ObjIndexEnd,PathIndexStart,PathIndexEnd;
02026 INT32 Reserved1,Reserved2,Reserved3,Reserved4;
02027
02028
02029 if (!Stack.Pop(&PathIndexEnd) ||
02030 !Stack.Pop(&PathIndexStart) ||
02031 !Stack.Pop(&ObjIndexEnd) ||
02032 !Stack.Pop(&ObjIndexStart) ||
02033 !Stack.Pop(&Reserved4) ||
02034 !Stack.Pop(&Reserved3) ||
02035 !Stack.Pop(&Reserved2) ||
02036 !Stack.Pop(&Reserved1))
02037 {
02038 return FALSE;
02039 }
02040
02041
02042 NodeBlender *pNodeBlender = new NodeBlender;
02043 ERRORIF(pNodeBlender == NULL, _R(IDT_EPS_NOMEMORY), FALSE);
02044
02045
02046 if (!AddNewNode(pNodeBlender))
02047 return FALSE;
02048
02049
02050 pNodeBlender->SetObjIndexStart(ObjIndexStart);
02051 pNodeBlender->SetObjIndexEnd (ObjIndexEnd);
02052 pNodeBlender->SetPathIndexStart(PathIndexStart);
02053 pNodeBlender->SetPathIndexEnd (PathIndexEnd);
02054
02055
02056 ThePathType = PATH_DISCARD_STICKY;
02057
02058
02059 return TRUE;
02060 }
02061
02062
02063
02064
02065
02066
02067
02068
02069
02070
02071
02072
02073
02074
02075
02076
02077 BOOL CamelotEPSFilter::EndBlender()
02078 {
02079 ThePathType = PATH_NORMAL;
02080 return TRUE;
02081 }
02082
02083
02084
02085
02086
02087
02088
02089
02090
02091
02092
02093
02094
02095
02096
02097 BOOL CamelotEPSFilter::ProcessRegularShape()
02098 {
02099
02100
02101 pRegularShape = new NodeRegularShape;
02102 if (pRegularShape == NULL)
02103 return FALSE;
02104
02105 if (!pRegularShape->SetUpShape())
02106 {
02107 delete pRegularShape;
02108 pRegularShape = NULL;
02109 return FALSE;
02110 }
02111
02112
02113 if (!AddNewNode(pRegularShape))
02114 {
02115 pRegularShape = NULL;
02116 return FALSE;
02117 }
02118
02119
02120 ERROR3IF(pInkPath != NULL, "Already creating an InkPath object in regular shape");
02121 pInkPath = new Path;
02122 if (pInkPath == NULL)
02123 return FALSE;
02124
02125
02126
02127 if (!pInkPath->Initialise())
02128 {
02129 delete pInkPath;
02130 pInkPath = NULL;
02131 delete pRegularShape;
02132 pRegularShape = NULL;
02133 return FALSE;
02134 }
02135
02136 pInkPath->FindStartOfPath();
02137
02138
02139 do
02140 {
02141 GetToken();
02142
02143
02144 if (Token == EPSC_cers)
02145 {
02146 if (pInkPath != NULL)
02147 {
02148
02149 HandleEPSError();
02150 return FALSE;
02151 }
02152
02153
02154 if (!AddAttributes(pRegularShape, RegularShapeIsStroked, RegularShapeIsFilled))
02155 {
02156 HandleNoMemory();
02157 return FALSE;
02158 }
02159
02160
02161 pRegularShape->InvalidateCache();
02162 pRegularShape->InvalidateBoundingRect();
02163
02164 pRegularShape = NULL;
02165 return TRUE;
02166 }
02167 }
02168
02169 while (HandleToken() && (!EPSFile->eof()));
02170
02171 if (EPSFile->eof())
02172 {
02173
02174 HandleEPSError();
02175 }
02176
02177
02178 return FALSE;
02179 }
02180
02181
02182
02183
02184
02185
02186
02187
02188
02189
02190
02191
02192
02193
02194 BOOL CamelotEPSFilter::ProcessRegularShapeParams()
02195 {
02196
02197 if (pRegularShape == NULL)
02198 {
02199 HandleEPSError();
02200 return FALSE;
02201 }
02202
02203 UINT32 NumSides;
02204 INT32 Circular;
02205 INT32 Stellated;
02206 INT32 PrimaryCurvature;
02207 INT32 StellationCurvature;
02208 double StellRadiusToPrimary;
02209 double PrimaryCurveToPrimary;
02210 double StellCurveToStell;
02211 double StellOffsetRatio;
02212 DocCoord UTCentrePoint;
02213 DocCoord UTMajorAxes;
02214 DocCoord UTMinorAxes;
02215
02216
02217 INT32 StrokedFlag;
02218 INT32 FilledFlag;
02219
02220
02221 if (!Stack.Pop(&StrokedFlag) ||
02222 !Stack.Pop(&FilledFlag) ||
02223 !Stack.PopCoordPair(&UTMinorAxes) ||
02224 !Stack.PopCoordPair(&UTMajorAxes) ||
02225 !Stack.PopCoordPair(&UTCentrePoint) ||
02226 !Stack.Pop(&StellOffsetRatio) ||
02227 !Stack.Pop(&StellCurveToStell) ||
02228 !Stack.Pop(&PrimaryCurveToPrimary) ||
02229 !Stack.Pop(&StellRadiusToPrimary) ||
02230 !Stack.Pop(&StellationCurvature) ||
02231 !Stack.Pop(&PrimaryCurvature) ||
02232 !Stack.Pop(&Stellated) ||
02233 !Stack.Pop(&Circular) ||
02234 !Stack.Pop(&NumSides))
02235 {
02236 HandleEPSError();
02237 return FALSE;
02238 }
02239 else
02240 {
02241 RegularShapeIsStroked = StrokedFlag;
02242 RegularShapeIsFilled = FilledFlag;
02243 }
02244
02245
02246 SetPathFilled(RegularShapeIsFilled);
02247
02248
02249 pRegularShape->SetNumSides(NumSides);
02250 pRegularShape->SetCircular(Circular);
02251 pRegularShape->SetStellated(Stellated);
02252 pRegularShape->SetPrimaryCurvature(PrimaryCurvature);
02253 pRegularShape->SetStellationCurvature(StellationCurvature);
02254 pRegularShape->SetStellRadiusToPrimary(StellRadiusToPrimary);
02255 pRegularShape->SetPrimaryCurveToPrimary(PrimaryCurveToPrimary);
02256 pRegularShape->SetStellCurveToStell(StellCurveToStell);
02257 pRegularShape->SetStellationRatio(StellOffsetRatio);
02258 pRegularShape->SetCentrePoint(UTCentrePoint);
02259 pRegularShape->SetMajorAxes(UTMajorAxes);
02260 pRegularShape->SetMinorAxes(UTMinorAxes);
02261
02262
02263 return TRUE;
02264 }
02265
02266
02267
02268
02269
02270
02271
02272
02273
02274
02275
02276
02277
02278
02279
02280 BOOL CamelotEPSFilter::ProcessEnvelope()
02281 {
02282
02283 if (!StartMould(MOULDSPACE_ENVELOPE))
02284 return FALSE;
02285
02286 if (ProcessMould())
02287
02288 return EndMould();
02289
02290 if (EPSFile->eof())
02291 {
02292
02293 HandleEPSError();
02294 }
02295
02296
02297 return FALSE;
02298 }
02299
02300
02301
02302
02303
02304
02305
02306
02307
02308
02309
02310
02311
02312
02313
02314 BOOL CamelotEPSFilter::ProcessPerspective()
02315 {
02316
02317 if (!StartMould(MOULDSPACE_PERSPECTIVE))
02318 return FALSE;
02319
02320
02321 if (ProcessMould())
02322 return EndMould();
02323
02324 if (EPSFile->eof())
02325 {
02326
02327 HandleEPSError();
02328 }
02329
02330
02331 return FALSE;
02332 }
02333
02334
02335
02336
02337
02338
02339
02340
02341
02342
02343
02344
02345
02346
02347
02348
02349
02350
02351
02352
02353
02354 BOOL CamelotEPSFilter::StartMould(MouldSpace mSpace)
02355 {
02356
02357 INT32 version;
02358 if (!Stack.Pop(&version))
02359 return FALSE;
02360
02361
02362 if (version!=100)
02363 return FALSE;
02364
02365
02366 NodeMould* pMouldParent = new NodeMould;
02367 ERROR1IF(pMouldParent == NULL, FALSE, _R(IDT_EPS_NOMEMORY));
02368
02369
02370 if (!pMouldParent->CreateGeometry(mSpace))
02371 {
02372 delete pMouldParent;
02373 return FALSE;
02374 }
02375
02376 if (!AddNewNode(pMouldParent))
02377 {
02378 HandleNoMemory();
02379 return FALSE;
02380 }
02381
02382
02383 pNode = pMouldParent;
02384
02385
02386 EPSFilter::NewMouldThreshold = MOULD_V1THRESHOLD;
02387
02388
02389 return TRUE;
02390 }
02391
02392
02393
02394
02395
02396
02397
02398
02399
02400
02401
02402
02403
02404
02405
02406
02407
02408 BOOL CamelotEPSFilter::EndMould()
02409 {
02410
02411 ERROR3IF(!pNode->IsKindOf(CC_RUNTIME_CLASS(NodeMould)), "No MouldParent in CamelotEPSFilter::EndMould");
02412
02413
02414 NodeMould* pNodeMould = (NodeMould*)pNode;
02415
02416 pNode = pNode->FindParent();
02417 ERROR3IF(pNode==NULL, "No parent of mould in CamelotEPSFilter::EndMould");
02418
02419
02420
02421
02422 pNodeMould->GetGeometry()->SetThreshold(EPSFilter::NewMouldThreshold);
02423
02424
02425 NodeMouldPath* pNodeMouldPath = (NodeMouldPath*)pNodeMould->FindFirstChild(CC_RUNTIME_CLASS(NodeMouldPath));
02426 NodeMouldGroup* pNodeMouldGroup = (NodeMouldGroup*)pNodeMould->FindFirstChild(CC_RUNTIME_CLASS(NodeMouldGroup));
02427
02428 if (pNodeMouldPath==NULL || pNodeMouldGroup==NULL)
02429 {
02430
02431 pNodeMould->CascadeDelete();
02432 }
02433
02434
02435
02436 RemoveUnwantedAttributes(pNodeMould);
02437
02438
02439 return TRUE;
02440 }
02441
02442
02443
02444
02445
02446
02447
02448
02449
02450
02451
02452
02453
02454
02455
02456
02457
02458 BOOL CamelotEPSFilter::RemoveUnwantedAttributes(NodeMould* pNodeMould)
02459 {
02460
02461
02462
02463
02464
02465
02466
02467
02468
02469
02470
02471 NodeMouldGroup* pNdMldGrp = (NodeMouldGroup*)pNodeMould->FindFirstChild(CC_RUNTIME_CLASS(NodeMouldGroup));
02472 if (pNdMldGrp==NULL)
02473 return FALSE;
02474
02475
02476 CCAttrMap AttrMap(30);
02477 CCRuntimeClass* pTypeInfo;
02478 void* pDummy;
02479
02480 BuildSubtreeAttrMap(&AttrMap, pNdMldGrp);
02481
02482 Node *qNode, *pNode = pNodeMould->FindFirstChild();
02483 while (pNode)
02484 {
02485 qNode = pNode->FindNext();
02486 if (pNode->IsAnAttribute())
02487 {
02488 NodeAttribute* pAttrib = (NodeAttribute*)pNode;
02489 pTypeInfo = pAttrib->GetAttributeType();
02490 if (AttrMap.Lookup(pTypeInfo, pDummy))
02491 {
02492 pNode->UnlinkNodeFromTree();
02493 delete pNode;
02494 }
02495 }
02496 pNode = qNode;
02497 }
02498
02499 return TRUE;
02500 }
02501
02502
02503
02504
02505
02506
02507
02508
02509
02510
02511
02512
02513
02514
02515
02516
02517
02518
02519 void CamelotEPSFilter::BuildSubtreeAttrMap(CCAttrMap *pAttribMap, Node* pParent)
02520 {
02521 CCRuntimeClass* pTypeInfo;
02522 void* pDummy;
02523
02524 Node* qNode = pParent->FindFirstChild();
02525 while (qNode)
02526 {
02527 if (qNode->IsAnAttribute())
02528 {
02529 NodeAttribute* pAttrib = (NodeAttribute*)qNode;
02530 pTypeInfo = pAttrib->GetAttributeType();
02531 if (!pAttribMap->Lookup(pTypeInfo, pDummy))
02532 pAttribMap->SetAt(pTypeInfo, qNode);
02533 }
02534
02535 if (qNode->FindFirstChild())
02536 {
02537 BuildSubtreeAttrMap(pAttribMap, qNode);
02538 }
02539
02540 qNode = qNode->FindNext();
02541 }
02542 }
02543
02544
02545
02546
02547
02548
02549
02550
02551
02552
02553
02554
02555
02556
02557
02558
02559
02560
02561 BOOL CamelotEPSFilter::ProcessMould()
02562 {
02563
02564 SnapShotCurrentAttrs();
02565
02566
02567 BOOL success=ProcessMouldTokens();
02568
02569
02570 DeleteSnapShot();
02571
02572 return success;
02573 }
02574
02575
02576
02577
02578
02579
02580
02581
02582
02583
02584
02585
02586
02587
02588
02589
02590
02591
02592 BOOL CamelotEPSFilter::ProcessMouldTokens()
02593 {
02594
02595 while (!EPSFile->eof())
02596 {
02597 GetToken();
02598
02599
02600 switch (Token)
02601 {
02602 case EPSC_ceev:
02603 case EPSC_cepr:
02604
02605 return TRUE;
02606 break;
02607
02608 case EPSC_csmp:
02609
02610
02611 if (!ProcessMouldShape())
02612 return FALSE;
02613 break;
02614
02615 case EPSC_csso:
02616 {
02617
02618
02619
02620 PushCurrentAttrsBasedOnSnapShot();
02621
02622
02623 BOOL Success = ProcessMouldSourceObjs();
02624
02625
02626 PopCurrentAttrsBasedOnSnapShot();
02627
02628 if (!Success)
02629 return FALSE;
02630 }
02631 break;
02632
02633 case EPSC_csdo:
02634
02635 if (!ProcessMouldDestinObjs())
02636 return FALSE;
02637 break;
02638
02639 default:
02640
02641 if (!HandleToken())
02642 return FALSE;
02643 break;
02644 }
02645 }
02646
02647 HandleEPSError();
02648 return FALSE;
02649 }
02650
02651
02652
02653
02654
02655
02656
02657
02658
02659
02660
02661
02662
02663
02664
02665
02666
02667
02668
02669
02670
02671 BOOL CamelotEPSFilter::ProcessMouldThreshold()
02672 {
02673 EPSFilter::NewMouldThreshold = MOULD_V1THRESHOLD;
02674
02675 while (!EPSFile->eof())
02676 {
02677 GetToken();
02678 switch (Token)
02679 {
02680 case EPSC_ceo:
02681 {
02682
02683 return TRUE;
02684 }
02685 break;
02686
02687 case EPSC_cmth:
02688 {
02689 INT32 Threshold;
02690 if (!Stack.Pop(&Threshold))
02691 {
02692 HandleEPSError();
02693 return FALSE;
02694 }
02695 EPSFilter::NewMouldThreshold = Threshold;
02696 }
02697 break;
02698
02699 default:
02700 {
02701
02702 if (!HandleToken())
02703 return FALSE;
02704 }
02705 break;
02706 }
02707 }
02708
02709 HandleEPSError();
02710 return FALSE;
02711 }
02712
02713
02714
02715
02716
02717
02718
02719
02720
02721
02722
02723
02724
02725
02726
02727
02728
02729
02730 BOOL CamelotEPSFilter::ProcessMouldShape()
02731 {
02732
02733 if (!IS_A(pNode,NodeMould)) return FALSE;
02734 NodeMould* pNodeMould = (NodeMould*)pNode;
02735
02736 Path TempPath;
02737 if (!TempPath.Initialise(24,12))
02738 return FALSE;
02739
02740 BOOL done = FALSE;
02741
02742 while (!done && (!EPSFile->eof()))
02743 {
02744 GetToken();
02745
02746 switch (Token)
02747 {
02748
02749 case EPSC_m:
02750 if (!ReadSimplePath(&TempPath))
02751 return FALSE;
02752 break;
02753
02754 case EPSC_cemp:
02755 done=TRUE;
02756 break;
02757
02758 default:
02759
02760 if (!HandleToken())
02761 return FALSE;
02762 break;
02763 }
02764 }
02765
02766 if (EPSFile->eof())
02767 {
02768 HandleEPSError();
02769 return FALSE;
02770 }
02771
02772
02773
02774 UINT32 errID;
02775 if (!pNodeMould->GetGeometry()->Validate(&TempPath,errID))
02776 {
02777
02778 Path* pPath = NULL;
02779 INT32 Corners[4] = {0, 3, 6, 9};
02780 if (!pNodeMould->GetGeometry()->MakeValidFrom(&pPath, &TempPath, Corners))
02781 return FALSE;
02782 if (!TempPath.CloneFrom(*pPath))
02783 {
02784 delete pPath;
02785 return FALSE;
02786 }
02787 delete pPath;
02788 }
02789
02790
02791 NodeMouldPath* pNodeMPath = pNodeMould->CreateNewMouldShape(&TempPath,NULL,ImportInfo.pOp);
02792 if (pNodeMPath==NULL)
02793 return FALSE;
02794
02795
02796 if (!AddNewNode(pNodeMPath))
02797 {
02798 delete pNodeMPath;
02799 return FALSE;
02800 }
02801
02802
02803
02804
02805
02806
02807
02808
02809
02810
02811
02812
02813
02814
02815
02816
02817
02818
02819
02820
02821
02822
02823
02824 if (!ApplyChangedAttrs(pNodeMould))
02825 return FALSE;
02826
02827
02828 return TRUE;
02829 }
02830
02831
02832
02833
02834
02835
02836
02837
02838
02839
02840
02841
02842
02843
02844
02845
02846
02847
02848
02849
02850 BOOL CamelotEPSFilter::ReadSimplePath(Path* TempPath)
02851 {
02852 DocCoord Ta,Tb,Tc;
02853 PathFlags flags;
02854 flags.IsSelected = FALSE;
02855 BOOL ok, done = FALSE;
02856
02857
02858 if (!Stack.PopCoordPair(&Ta))
02859 return FALSE;
02860
02861
02862 TempPath->ClearPath(FALSE);
02863
02864
02865 if (!TempPath->AddMoveTo(Ta, &flags))
02866 return FALSE;
02867
02868
02869 while (!done && (!EPSFile->eof()))
02870 {
02871 GetToken();
02872
02873 switch (Token)
02874 {
02875 case EPSC_l:
02876
02877 ok = Stack.PopCoordPair(&Ta);
02878 if (ok) ok = TempPath->AddLineTo(Ta, &flags);
02879 break;
02880
02881 case EPSC_c:
02882
02883 ok = Stack.PopCoordPair(&Tc);
02884 if (ok) ok = Stack.PopCoordPair(&Tb);
02885 if (ok) ok = Stack.PopCoordPair(&Ta);
02886 if (ok) ok = TempPath->AddCurveTo(Ta,Tb,Tc,&flags);
02887 break;
02888
02889 case EPSC_s: case EPSC_f: case EPSC_b: case EPSC_h: case EPSC_n:
02890 case EPSC_S: case EPSC_F: case EPSC_B: case EPSC_H: case EPSC_N:
02891
02892 ok = TempPath->CloseSubPath();
02893 done = TRUE;
02894 break;
02895
02896 default:
02897
02898 ok = HandleToken();
02899 break;
02900 }
02901
02902
02903 if (!ok) return FALSE;
02904 }
02905
02906
02907 return TRUE;
02908 }
02909
02910
02911
02912
02913
02914
02915
02916
02917
02918
02919
02920
02921
02922
02923
02924 BOOL CamelotEPSFilter::ProcessMouldSourceObjs()
02925 {
02926
02927 ERROR3IF(!pNode->IsKindOf(CC_RUNTIME_CLASS(NodeMould)), "No MouldParent in CamelotEPSFilter::ProcessMouldSourceObjs");
02928 NodeMould* pNodeMould = (NodeMould*)pNode;
02929
02930
02931 NodeMouldGroup* pMouldGroup = pNodeMould->CreateNewMouldGroup(ImportInfo.pOp);
02932 if (pMouldGroup==NULL)
02933 return FALSE;
02934
02935 if (!AddNewNode(pMouldGroup))
02936 {
02937 delete pMouldGroup;
02938 return FALSE;
02939 }
02940
02941
02942 Node* pOldPos = pNode;
02943 pNode = pMouldGroup;
02944
02945
02946 BOOL done = FALSE;
02947 while (!done && (!EPSFile->eof()))
02948 {
02949 GetToken();
02950 if (!(done=(Token==EPSC_ceso)))
02951 {
02952 if (!HandleToken())
02953 {
02954 pNode=pOldPos;
02955 return FALSE;
02956 }
02957 }
02958 }
02959
02960
02961 pNode = pOldPos;
02962
02963 if (EPSFile->eof())
02964 {
02965 HandleEPSError();
02966 return FALSE;
02967 }
02968
02969 return TRUE;
02970 }
02971
02972
02973
02974
02975
02976
02977
02978
02979
02980
02981
02982
02983
02984
02985
02986
02987
02988 BOOL CamelotEPSFilter::ProcessMouldDestinObjs()
02989 {
02990
02991 ERROR3IF(!pNode->IsKindOf(CC_RUNTIME_CLASS(NodeMould)), "No MouldParent in CamelotEPSFilter::ProcessMouldDestinObjs");
02992 NodeMould* pNodeMould = (NodeMould*)pNode;
02993
02994
02995 NodeMoulder* pMoulder = pNodeMould->CreateNewMoulder(ImportInfo.pOp);
02996 if (!pMoulder)
02997 return FALSE;
02998
02999
03000 if (!AddNewNode(pMoulder))
03001 return FALSE;
03002
03003
03004 Node* pOldPos=pNode;
03005 pNode=pMoulder;
03006
03007
03008 BOOL done=FALSE;
03009 while (!done && (!EPSFile->eof()))
03010 {
03011 GetToken();
03012 if (!(done=(Token==EPSC_cedo)))
03013 {
03014 if (!HandleToken())
03015 {
03016 pNode=pOldPos;
03017 return FALSE;
03018 }
03019 }
03020 }
03021
03022
03023 pNode=pOldPos;
03024
03025 if (EPSFile->eof())
03026 {
03027 HandleEPSError();
03028 return FALSE;
03029 }
03030
03031 return TRUE;
03032 }
03033
03034
03035
03036
03037
03038
03039
03040
03041
03042
03043
03044
03045
03046
03047 BOOL CamelotEPSFilter::ProcessGuideLayer()
03048 {
03049 String_64 GuideColourName;
03050 PColourCMYK CMYK;
03051 FIXEDPOINT TintVal;
03052
03053 String_256 LayerName;
03054 INT32 Visible;
03055 INT32 Locked;
03056 INT32 Foreground;
03057 INT32 Printable;
03058
03059
03060 if (!Stack.PopColour(&CMYK, TINT_ILLUSTRATOR, &TintVal, &GuideColourName) ||
03061 !Stack.Pop(&Locked) ||
03062 !Stack.Pop(&Printable) ||
03063 !Stack.Pop(&Visible) ||
03064 !Stack.Pop(&Foreground) ||
03065 !Stack.Pop(&LayerName))
03066 {
03067 return FALSE;
03068 }
03069
03070 #if defined(EXCLUDE_FROM_RALPH)
03071
03072 #else
03073 if (Filter::ImportWithLayers)
03074 {
03075
03076 UseLayer(LayerName,TRUE);
03077
03078
03079
03080 if (EPSFlags.AddToNewLayer)
03081 {
03082
03083
03084
03085 Printable = Foreground;
03086
03087
03088
03089
03090
03091
03092 pLayer->SetLocked(!(Locked == 0));
03093
03094
03095 pLayer->SetPrintable(!(Printable == 0));
03096
03097
03098 pLayer->SetBackground(Foreground == 0);
03099
03100 DocColour Col;
03101
03102 GetEPSColour(&Col,&CMYK,TINT_ILLUSTRATOR,TintVal,&GuideColourName);
03103 IndexedColour* pIndexedColour = Col.FindParentIndexedColour();
03104 pLayer->SetGuideColour(pIndexedColour);
03105 }
03106 }
03107 #endif
03108 return TRUE;
03109 }
03110
03111
03112
03113
03114
03115
03116
03117
03118
03119
03120
03121
03122
03123 BOOL CamelotEPSFilter::ProcessGuideline()
03124 {
03125 INT32 Type, Ordinate;
03126
03127
03128 if (!Stack.Pop(&Type) ||
03129 !Stack.Pop(&Ordinate))
03130 {
03131 return FALSE;
03132 }
03133
03134 #ifdef WEBSTER
03135
03136
03137
03138 if (!Filter::ImportWithLayers)
03139 return TRUE;
03140 #endif
03141
03142 NodeGuideline* pGuideline = new NodeGuideline;
03143 ERROR1IF(pGuideline == NULL, FALSE, _R(IDT_EPS_NOMEMORY));
03144
03145
03146 if (!AddNewNode(pGuideline))
03147 return FALSE;
03148
03149 pGuideline->SetType(GuidelineType(Type));
03150 pGuideline->SetOrdinate(Ordinate);
03151
03152 return TRUE;
03153 }
03154
03156
03157
03158
03159
03160
03161
03162
03163
03164
03165
03166
03167
03168
03169 EPSFontCache::EPSFontCache()
03170 {
03171
03172 Valid = FALSE;
03173 };
03174
03175 #if !defined(EXCLUDE_FROM_RALPH)
03176
03178
03179
03180 CC_IMPLEMENT_DYNAMIC(CamelotEPSRenderRegion, ArtWorksEPSRenderRegion)
03181
03182
03183
03184
03185
03186
03187
03188
03189
03190
03191
03192
03193
03194 CamelotEPSRenderRegion::CamelotEPSRenderRegion(DocRect ClipRect,
03195 Matrix ConvertMatrix,
03196 FIXED16 ViewScale)
03197 : ArtWorksEPSRenderRegion(ClipRect, ConvertMatrix, ViewScale)
03198 {
03199 CreatorString = _T("Xara X");
03200
03201 SepTables = NULL;
03202 }
03203
03204
03205
03206
03207
03208
03209
03210
03211
03212
03213
03214
03215
03216 CamelotEPSRenderRegion::~CamelotEPSRenderRegion()
03217 {
03218 if (SepTables != NULL)
03219 {
03220 CCFree(SepTables);
03221 SepTables = NULL;
03222 }
03223 }
03224
03225
03226
03227
03228
03229
03230
03231
03232
03233
03234
03235
03236
03237
03238
03239 BOOL CamelotEPSRenderRegion::StartRender()
03240 {
03241
03242
03243
03244
03245
03246
03247
03248
03249
03250
03251 if (!EPSRenderRegion::StartRender())
03252 return FALSE;
03253
03254 InitAttributes ();
03255
03256 return TRUE;
03257 }
03258
03259
03260
03261
03262
03263
03264
03265
03266
03267
03268
03269
03270 BOOL CamelotEPSRenderRegion::StopRender()
03271 {
03272
03273
03274
03275
03276 if (!IS_A(this, NativeRenderRegion))
03277 {
03278
03279
03280
03281
03282 FontInfo.Valid = 0;
03283 }
03284
03285 if (SepTables != NULL)
03286 {
03287 CCFree(SepTables);
03288 SepTables = NULL;
03289 }
03290
03291 DeInitAttributes ();
03292
03293 return TRUE;
03294 }
03295
03296
03297
03298
03299
03300
03301
03302
03303
03304
03305
03306
03307
03308
03309
03310
03311 void CamelotEPSRenderRegion::GetRenderRegionCaps(RRCaps* pCaps)
03312 {
03313
03314 pCaps->CanDoNothing();
03315 pCaps->GradFills = TRUE;
03316 pCaps->SimpleBitmaps = TRUE;
03317 pCaps->ArbitraryBitmaps = TRUE;
03318 pCaps->ClippedSimpleBitmaps = TRUE;
03319 pCaps->ClippedArbitraryBitmaps = TRUE;
03320 pCaps->ClippedOutput = TRUE;
03321 }
03322
03323
03324
03325
03326
03327
03328
03329
03330
03331
03332
03333
03334
03335
03336 void CamelotEPSRenderRegion::GetValidPathAttributes()
03337 {
03338 KernelDC *pDC = (KernelDC*)CCDC::ConvertFromNativeDC(RenderDC);
03339
03340 FillGeometryAttribute *pFillAttr =
03341 (FillGeometryAttribute *) CurrentAttrs[ATTR_FILLGEOMETRY].pAttr;
03342
03343 if (pFillAttr->IsKindOf(CC_RUNTIME_CLASS(GradFillAttribute)) &&
03344 SetLastOutputAttribute(ATTR_FILLGEOMETRY))
03345 {
03346
03347 if (!pFillAttr->IsASquareFill() && !pFillAttr->IsAThreeColFill())
03348 {
03349
03350 if (
03351 !pFillAttr->IsKindOf(CC_RUNTIME_CLASS(BitmapFillAttribute)) )
03352 {
03353
03354
03355
03356 GradFillAttribute *pGradFillAttr = (GradFillAttribute *) pFillAttr;
03357
03358
03359 BOOL UnnamedColours = FALSE;
03360 BOOL GreyFill = FALSE;
03361
03362
03363
03364
03365
03366
03367
03368
03369
03370
03371
03372
03373
03374
03375
03376
03377
03378
03379
03380
03381
03382
03383
03384
03385
03386
03387
03388
03389
03390
03391
03392
03393
03394
03395
03396
03397
03398
03399 ColourContext* pContext;
03400 ColourPlate* pSeparation;
03401 GetOutputColourPlate(COLOURMODEL_CMYK, &pContext, &pSeparation);
03402
03403 if (pSeparation!=NULL)
03404 {
03405 DocColour *Start, *End;
03406 Start = &(pGradFillAttr->Colour);
03407 End = &(pGradFillAttr->EndColour);
03408 BOOL StartIsSpot = (Start->GetSpotParent() != NULL);
03409 BOOL EndIsSpot = (End->GetSpotParent() != NULL);
03410
03411
03412 GreyFill = (pSeparation->GetType() == COLOURPLATE_SPOT);
03413
03414
03415
03416 GreyFill = (GreyFill || StartIsSpot || EndIsSpot);
03417
03418 if (!GreyFill)
03419 {
03420
03421
03422 GreyFill = ( Start->GetColourModel() == COLOURMODEL_CMYK ) &&
03423 ( End->GetColourModel() == COLOURMODEL_CMYK );
03424
03425 if (GreyFill)
03426 {
03427
03428 UINT32 filleffect;
03429 BOOL exists = GetCurrFillEffect(filleffect);
03430 GreyFill = (!exists || filleffect == FILLEFFECT_FADE);
03431 }
03432 }
03433 }
03434
03435
03436
03437
03438 if (GreyFill)
03439 {
03440 UnnamedColours = TRUE;
03441
03442
03443
03444 PColourCMYK sCMYK, eCMYK;
03445
03446 pGradFillAttr->Colour.GetCMYKValue(pContext, &sCMYK);
03447 pGradFillAttr->EndColour.GetCMYKValue(pContext, &eCMYK);
03448
03449
03450 ERROR3IF( (sCMYK.Cyan!=0 || sCMYK.Magenta!=0 || sCMYK.Yellow!=0 ||
03451 eCMYK.Cyan!=0 || eCMYK.Magenta!=0 || eCMYK.Yellow!=0) ,
03452 "Not a mono plate during export of CMYK gradfills (CAMEPSRndRgn::GetValidPathAttributes())" );
03453
03454
03455 BOOL ok = pDC->OutputColourValue(255 - sCMYK.Key);
03456 ok = ok && pDC->OutputColourValue(255 - eCMYK.Key);
03457
03458 ERROR3IF(!ok, "Disc buffer failure during gradfill output in GetValidPathAttributes");
03459 }
03460 else
03461 {
03462
03463
03464 UnnamedColours = OutputGradFillColours( &(pGradFillAttr->Colour), &(pGradFillAttr->EndColour) );
03465 }
03466
03467
03468 pDC->OutputCoord(pGradFillAttr->StartPoint);
03469 pDC->OutputCoord(pGradFillAttr->EndPoint);
03470
03471
03472
03473 if (pFillAttr->IsKindOf(CC_RUNTIME_CLASS(LinearFillAttribute)))
03474 {
03475 LinearFillAttribute *pLinearFillAttr = (LinearFillAttribute *) pFillAttr;
03476
03477 DocCoord* Start = pFillAttr->GetStartPoint();
03478 DocCoord* End = pFillAttr->GetEndPoint();
03479 DocCoord* End2 = pFillAttr->GetEndPoint2();
03480
03481 if (AreLinesPerpendicular(Start, End, End2))
03482 {
03483 TRACEUSER( "Will", _T("Exporting Simple Linear Fill\n"));
03484 pDC->OutputValue((INT32) CAMEPS_FILL_LINEAR);
03485 }
03486 else
03487 {
03488 TRACEUSER( "Will", _T("Exporting New Style Linear Fill\n"));
03489 pDC->OutputCoord(pLinearFillAttr->EndPoint2);
03490 pDC->OutputValue((INT32) CAMEPS_FILL_NEWLINEAR);
03491 }
03492 }
03493 else if (pFillAttr->IsKindOf(CC_RUNTIME_CLASS(RadialFillAttribute)))
03494 {
03495
03496 RadialFillAttribute *pRadialFillAttr = (RadialFillAttribute *) pFillAttr;
03497 if (pRadialFillAttr->IsElliptical())
03498 {
03499
03500 pDC->OutputCoord(pRadialFillAttr->EndPoint2);
03501 pDC->OutputValue((INT32) CAMEPS_FILL_ELLIPTICAL);
03502 }
03503 else
03504 {
03505
03506 pDC->OutputValue((INT32) CAMEPS_FILL_CIRCULAR);
03507 }
03508 }
03509 else if (pFillAttr->IsKindOf(CC_RUNTIME_CLASS(ConicalFillAttribute)))
03510 {
03511 pDC->OutputValue((INT32) CAMEPS_FILL_CONICAL);
03512 }
03513 else
03514 {
03515
03516 ENSURE(FALSE, "Unsupported grad fill encountered while exporting");
03517 EPSRenderRegion::GetValidPathAttributes();
03518 return;
03519 }
03520
03521
03522 if (UnnamedColours)
03523 {
03524 if (GreyFill)
03525 pDC->OutputToken(_T("cag"));
03526 else
03527 pDC->OutputToken(_T("caz"));
03528 }
03529 else
03530 {
03531 pDC->OutputToken(_T("cax"));
03532 }
03533 pDC->OutputNewLine();
03534 }
03535 else if (
03536 (pFillAttr->IsKindOf(CC_RUNTIME_CLASS(FractalFillAttribute)) ||
03537 pFillAttr->IsKindOf(CC_RUNTIME_CLASS(NoiseFillAttribute))) &&
03538 Caps.BitmapFills
03539 )
03540 {
03541
03542
03543
03544
03545
03546
03547
03548
03549 BitmapFillAttribute *pFill = (BitmapFillAttribute *) pFillAttr;
03550
03551
03552
03553 BOOL UnnamedColours = FALSE;
03554 ColourContext *cc = NULL;
03555
03556
03557
03558 if ((pFill->Colour.FindParentIndexedColour() == NULL) &&
03559 (pFill->EndColour.FindParentIndexedColour() == NULL))
03560 {
03561
03562 cc = ColourManager::GetColourContext(COLOURMODEL_CMYK, GetRenderView());
03563 ERROR3IF(cc == NULL, "No CMYK colour context - somethings' seriously broken");
03564 }
03565 else
03566 {
03567 cc = NULL;
03568 }
03569
03570
03571 UnnamedColours = OutputGradFillColours (&(pFill->Colour), &(pFill->EndColour), cc);
03572
03573
03574 pDC->OutputCoord(pFill->StartPoint);
03575 pDC->OutputCoord(pFill->EndPoint);
03576 pDC->OutputCoord(pFill->EndPoint2);
03577
03578
03579
03580
03581
03582
03583
03584 pDC->OutputValue(pFill->GetSeed());
03585 pDC->OutputReal(pFill->GetGraininess().MakeDouble());
03586 pDC->OutputReal(pFill->GetGravity().MakeDouble());
03587 pDC->OutputReal(pFill->GetSquash().MakeDouble());
03588
03589
03590 UINT32 DPI = pFill->GetFractalDPI();
03591 pDC->OutputValue(DPI);
03592
03593
03594 pDC->OutputValue((INT32) (pFill->GetTileable()));
03595
03596
03597 pDC->OutputToken(_T("1"));
03598
03599
03600 pDC->OutputValue((INT32) CAMEPS_FILL_FRACTAL);
03601
03602 if (UnnamedColours)
03603 pDC->OutputToken(_T("caz"));
03604 else
03605 pDC->OutputToken(_T("cax"));
03606 pDC->OutputNewLine();
03607 }
03608 else if (pFillAttr->IsKindOf(CC_RUNTIME_CLASS(BitmapFillAttribute)) && Caps.BitmapFills)
03609 {
03610
03611 BitmapFillAttribute *pBitmapFill = (BitmapFillAttribute *) pFillAttr;
03612 ERROR3IF(pBitmapFill->GetBitmap() == NULL, "Bitmap fill has no bitmap");
03613
03614 if (pBitmapFill->GetBitmap())
03615 {
03616
03617
03618 BOOL UnnamedColours = FALSE;
03619 BOOL HasColours = ((pBitmapFill->GetStartColour() != NULL) &&
03620 (pBitmapFill->GetEndColour() != NULL));
03621
03622 if (HasColours)
03623 {
03624
03625
03626 ColourContext *cc = NULL;
03627
03628 if ((pBitmapFill->Colour.FindParentIndexedColour() == NULL) &&
03629 (pBitmapFill->EndColour.FindParentIndexedColour() == NULL))
03630 {
03631
03632 cc = ColourManager::GetColourContext(COLOURMODEL_CMYK, GetRenderView());
03633 ERROR3IF(cc == NULL, "No CMYK colour context - somethings' seriously broken");
03634 }
03635 else
03636 {
03637
03638 cc = NULL;
03639 }
03640
03641
03642 UnnamedColours = OutputGradFillColours (&(pBitmapFill->Colour),
03643 &(pBitmapFill->EndColour),
03644 cc);
03645 }
03646
03647 pDC->OutputCoord(pBitmapFill->StartPoint);
03648 pDC->OutputCoord(pBitmapFill->EndPoint);
03649 pDC->OutputCoord(pBitmapFill->EndPoint2);
03650
03651 if (HasColours)
03652 pDC->OutputValue((INT32) CAMEPS_FILL_NEWBITMAP);
03653 else
03654 pDC->OutputValue((INT32) CAMEPS_FILL_BITMAP);
03655
03656 if (UnnamedColours)
03657 pDC->OutputToken(_T("caz"));
03658 else
03659 pDC->OutputToken(_T("cax"));
03660
03661 pDC->OutputNewLine();
03662
03663
03664 ExportDC *pExportDC = (ExportDC *) pDC;
03665 pExportDC->GetParentFilter()->ExportBitmap(*pBitmapFill->GetBitmap());
03666 }
03667 }
03668 }
03669 }
03670
03671 if (SetLastOutputAttribute(ATTR_FILLEFFECT))
03672 {
03673 UINT32 EffectType;
03674 GetCurrFillEffect(EffectType);
03675
03676
03677 pDC->OutputValue(EffectType);
03678
03679
03680 pDC->OutputToken(_T("cxe"));
03681 pDC->OutputNewLine();
03682 }
03683
03684 if (SetLastOutputAttribute(ATTR_FILLMAPPING))
03685 {
03686
03687 FillMappingAttribute *pFillAttr =
03688 (FillMappingAttribute *) CurrentAttrs[ATTR_FILLMAPPING].pAttr;
03689
03690
03691 INT32 MappingType = pFillAttr->Repeat;
03692
03693 #ifdef _DEBUG
03694 if(MappingType == 4) MappingType = 2;
03695 #endif
03696 ERROR3IF((MappingType < 1) || (MappingType > 3), "Illegal fill mapping value!");
03697
03698
03699 pDC->OutputValue((UINT32) MappingType);
03700
03701
03702 pDC->OutputToken(_T("0"));
03703
03704
03705 pDC->OutputToken(_T("cxm"));
03706 pDC->OutputNewLine();
03707 }
03708
03709 if (SetLastOutputAttribute(ATTR_WINDINGRULE))
03710 {
03711 WindingRuleAttribute *pWindingRuleAttr =
03712 (WindingRuleAttribute *) CurrentAttrs[ATTR_WINDINGRULE].pAttr;
03713
03714 switch (pWindingRuleAttr->WindingRule)
03715 {
03716 case NonZeroWinding:
03717
03718 pDC->OutputToken(_T("0"));
03719 pDC->OutputToken(_T("awr"));
03720 pDC->OutputNewLine();
03721 break;
03722
03723 case EvenOddWinding:
03724
03725 pDC->OutputToken(_T("1"));
03726 pDC->OutputToken(_T("awr"));
03727 pDC->OutputNewLine();
03728 break;
03729
03730 case NegativeWinding:
03731 case PositiveWinding:
03732
03733 break;
03734
03735 default:
03736 ERROR3("Unknown winding rule encountered while exporting.");
03737 break;
03738
03739 }
03740 }
03741
03742
03743
03744
03745 EPSRenderRegion::GetValidPathAttributes();
03746 }
03747
03748
03749
03750
03751
03752
03753
03754
03755
03756
03757
03758
03759
03760
03761
03762
03763
03764
03765
03766
03767
03768
03769
03770 BOOL CamelotEPSRenderRegion::OutputGradFillColours(DocColour* StartCol, DocColour* EndCol, ColourContext* pContext)
03771 {
03772 KernelDC *pDC = (KernelDC*)CCDC::ConvertFromNativeDC(RenderDC);
03773 bool outputNames = FALSE;
03774
03775 if ((StartCol->FindParentIndexedColour() == NULL) &&
03776 (EndCol->FindParentIndexedColour() == NULL))
03777 {
03778
03779 outputNames = FALSE;
03780 }
03781 else
03782 {
03783
03784 outputNames = TRUE;
03785 }
03786
03787
03788 INT32 red = 0;
03789 INT32 green = 0;
03790 INT32 blue = 0;
03791
03792
03793 StartCol->GetRGBValue (&red, &green, &blue);
03794 pDC->OutputColourValue (red);
03795 pDC->OutputColourValue (green);
03796 pDC->OutputColourValue (blue);
03797
03798 if (outputNames)
03799 {
03800
03801 pDC->OutputColourName (StartCol);
03802
03803
03804
03805 pDC->OutputValue ((INT32)0);
03806 }
03807
03808
03809 EndCol->GetRGBValue (&red, &green, &blue);
03810 pDC->OutputColourValue(red);
03811 pDC->OutputColourValue(green);
03812 pDC->OutputColourValue(blue);
03813
03814 if (outputNames)
03815 {
03816
03817 pDC->OutputColourName (EndCol);
03818
03819
03820
03821 pDC->OutputValue ((INT32)0);
03822 }
03823
03824
03825 return (!outputNames);
03826 }
03827
03828
03829
03830
03831
03832
03833
03834
03835
03836
03837
03838
03839
03840
03841
03842
03843
03844 BOOL CamelotEPSRenderRegion::GetCurrFillEffect(UINT32& EffectType)
03845 {
03846
03847 EffectType = FILLEFFECT_FADE;
03848
03849 FillEffectAttribute *pFillAttr = (FillEffectAttribute *) CurrentAttrs[ATTR_FILLEFFECT].pAttr;
03850 if (pFillAttr==NULL)
03851 return FALSE;
03852
03853 if (pFillAttr->IsKindOf(CC_RUNTIME_CLASS(FillEffectFadeAttribute)))
03854 {
03855 EffectType = FILLEFFECT_FADE;
03856 }
03857 else if (pFillAttr->IsKindOf(CC_RUNTIME_CLASS(FillEffectRainbowAttribute)))
03858 {
03859 EffectType = FILLEFFECT_RAINBOW;
03860 }
03861 else if (pFillAttr->IsKindOf(CC_RUNTIME_CLASS(FillEffectAltRainbowAttribute)))
03862 {
03863 EffectType = FILLEFFECT_ALTRAINBOW;
03864 }
03865 else
03866 {
03867 ERROR3("Illegal fill effect type!");
03868 }
03869
03870 return TRUE;
03871 }
03872
03873
03874
03875
03876
03877
03878
03879
03880
03881
03882
03883
03884
03885
03886
03887 BOOL CamelotEPSRenderRegion::WriteEPSBoundingBox ( void )
03888 {
03889
03890 return EPSRenderRegion::WriteEPSBoundingBox ();
03891 }
03892
03893
03894
03895
03896
03897
03898
03899
03900
03901
03902
03903
03904
03905
03906
03907
03908
03909
03910 BOOL CamelotEPSRenderRegion::WriteProlog(KernelDC *pDC)
03911 {
03912
03913 CCResTextFile PrologFile;
03914
03915
03916 if (!PrologFile.open(_R(IDM_PS_PROLOG), _R(IDT_PS_RES)))
03917 {
03918
03919 ERROR2(FALSE, "Could not get at PostScript resource!");
03920 }
03921
03922
03923 pDC->OutputNewLine();
03924 pDC->OutputToken(_T("%%BeginResource: procset XaraStudio1Dict"));
03925 pDC->OutputNewLine();
03926 pDC->OutputToken(_T("% Copyright (c) 1995,1996 Xara Ltd"));
03927 pDC->OutputNewLine();
03928
03929
03930 pDC->OutputToken(_T("/XaraStudio1Dict 300 dict def XaraStudio1Dict begin"));
03931 pDC->OutputNewLine();
03932
03933
03934 String_256 LineBuf;
03935 TCHAR *pBuf = (TCHAR *) LineBuf;
03936
03937 while (!PrologFile.read(&LineBuf).eof())
03938 {
03939
03940 pDC->OutputTCHARAsChar(pBuf, LineBuf.Length());
03941 pDC->OutputNewLine();
03942 }
03943
03944
03945 PrologFile.close();
03946
03947
03948
03949 WriteSepFunctions(pDC);
03950
03951
03952 pDC->OutputToken(_T("end"));
03953 pDC->OutputNewLine();
03954 pDC->OutputToken(_T("%%EndResource"));
03955 pDC->OutputNewLine();
03956
03957 return TRUE;
03958 }
03959
03960
03961
03962
03963
03964
03965
03966
03967
03968
03969
03970
03971
03972
03973
03974
03975
03976
03977 BOOL CamelotEPSRenderRegion::WriteSetup(KernelDC *pDC)
03978 {
03979
03980 CCResTextFile SetupFile;
03981
03982
03983 if (!SetupFile.open(_R(IDM_PS_SETUP), _R(IDT_PS_RES)))
03984 {
03985
03986 ERROR2(FALSE, "Could not get at PostScript resource!");
03987 }
03988
03989
03990 pDC->OutputToken(_T("save XaraStudio1Dict begin"));
03991 pDC->OutputNewLine();
03992
03993
03994 String_256 LineBuf;
03995 TCHAR *pBuf = (TCHAR *) LineBuf;
03996
03997 while (!SetupFile.read(&LineBuf).eof())
03998 {
03999
04000 pDC->OutputTCHARAsChar(pBuf, LineBuf.Length());
04001 pDC->OutputNewLine();
04002 }
04003
04004
04005 SetupFile.close();
04006
04007 return TRUE;
04008 }
04009
04010
04011
04012
04013
04014
04015
04016
04017
04018
04019
04020
04021
04022
04023
04024 BOOL CamelotEPSRenderRegion::WriteEPSTrailerComments ( void )
04025 {
04026
04027
04028
04029 KernelDC *pDC = (KernelDC*)CCDC::ConvertFromNativeDC(RenderDC);
04030 pDC->OutputToken(_T("end restore"));
04031 pDC->OutputNewLine();
04032
04033
04034 return EPSRenderRegion::WriteEPSTrailerComments ();
04035 }
04036
04037
04038
04039
04040
04041
04042
04043
04044
04045
04046
04047
04048
04049
04050
04051
04052
04053
04054
04055
04056
04057
04058
04059
04060
04061
04062
04063
04064
04065
04066
04067
04068
04069
04070
04071
04072
04073
04074
04075
04076
04077
04078
04079
04080
04081
04082
04083
04084
04085
04086
04087
04088
04089
04090
04091
04092
04093
04094
04095
04096
04097
04098
04099
04100 void CamelotEPSRenderRegion::ColourSeparateScanline24(BYTE *DestBuffer, BYTE *SrcBuffer,
04101 INT32 PixelWidth)
04102 {
04103 ERROR3IF(DestBuffer == NULL || SrcBuffer == NULL || PixelWidth < 1, _T("Illegal params"));
04104 ERROR3IF(SepTables == NULL, _T("No separation tables!?"));
04105 ERROR3IF(CurrentColContext->GetColourPlate() == NULL,
04106 _T("The separation ColourPlate has gone missing!"));
04107
04108
04109
04110 BYTE Temp;
04111 #define TEMPMAX(R,G,B) \
04112 { \
04113 Temp = ((R) > (G)) ? (R) : (G); \
04114 Temp = (Temp > (B)) ? Temp : (B); \
04115 }
04116
04117
04118
04119 INT32 i;
04120 BYTE Ink;
04121
04122 BYTE *UCR = SepTables + 768 + 255;
04123
04124
04125
04126 PORTNOTE("cms", "Disabled colour separations");
04127 #ifndef EXCLUDE_FROM_XARALX
04128 BOOL PrintRGBBlackAsKey=XaraCMS::PrintRGBBlackAsKey;
04129 #else
04130 BOOL PrintRGBBlackAsKey=TRUE;
04131 #endif
04132
04133
04134 switch (CurrentColContext->GetColourPlate()->GetType())
04135 {
04136 case COLOURPLATE_CYAN:
04137 {
04138 BYTE *LUT = SepTables + 0;
04139
04140 for (i = 0; i < PixelWidth * 3; i += 3)
04141 {
04142 TEMPMAX(SrcBuffer[i], SrcBuffer[i+1], SrcBuffer[i+2]);
04143
04144 if (!PrintRGBBlackAsKey || Temp > 0)
04145 {
04146 Ink = 255 - SrcBuffer[i];
04147
04148
04149
04150
04151 if ((UINT32)Ink>(UINT32)UCR[-Temp])
04152 Ink -= UCR[-Temp];
04153 else
04154 Ink = 0;
04155
04156 Ink = LUT[Ink];
04157
04158 DestBuffer[i] = DestBuffer[i+1] = DestBuffer[i+2] = 255 - Ink;
04159 }
04160 else
04161 {
04162 DestBuffer[i] = DestBuffer[i+1] = DestBuffer[i+2] = 255;
04163 }
04164 }
04165 }
04166 break;
04167
04168
04169 case COLOURPLATE_MAGENTA:
04170 {
04171 BYTE *LUT = SepTables + 256;
04172
04173 for (i = 0; i < PixelWidth * 3; i += 3)
04174 {
04175 TEMPMAX(SrcBuffer[i], SrcBuffer[i+1], SrcBuffer[i+2]);
04176
04177 if (!PrintRGBBlackAsKey || Temp > 0)
04178 {
04179 Ink = 255 - SrcBuffer[i+1];
04180
04181
04182
04183
04184 if ((UINT32)Ink>(UINT32)UCR[-Temp])
04185 Ink -= UCR[-Temp];
04186 else
04187 Ink = 0;
04188
04189 Ink = LUT[Ink];
04190
04191 DestBuffer[i] = DestBuffer[i+1] = DestBuffer[i+2] = 255 - Ink;
04192 }
04193 else
04194 {
04195 DestBuffer[i] = DestBuffer[i+1] = DestBuffer[i+2] = 255;
04196 }
04197 }
04198 }
04199 break;
04200
04201
04202 case COLOURPLATE_YELLOW:
04203 {
04204 BYTE *LUT = SepTables + 512;
04205
04206 for (i = 0; i < PixelWidth * 3; i += 3)
04207 {
04208 TEMPMAX(SrcBuffer[i], SrcBuffer[i+1], SrcBuffer[i+2]);
04209
04210 if (!PrintRGBBlackAsKey || Temp > 0)
04211 {
04212 Ink = 255 - SrcBuffer[i+2];
04213
04214
04215
04216
04217 if ((UINT32)Ink>(UINT32)UCR[-Temp])
04218 Ink -= UCR[-Temp];
04219 else
04220 Ink = 0;
04221
04222 Ink = LUT[Ink];
04223
04224 DestBuffer[i] = DestBuffer[i+1] = DestBuffer[i+2] = 255 - Ink;
04225 }
04226 else
04227 {
04228 DestBuffer[i] = DestBuffer[i+1] = DestBuffer[i+2] = 255;
04229 }
04230 }
04231 }
04232 break;
04233
04234
04235 case COLOURPLATE_KEY:
04236 {
04237 BYTE *BGT = SepTables + 1024;
04238
04239 for (i = 0; i < PixelWidth * 3; i += 3)
04240 {
04241
04242 TEMPMAX(SrcBuffer[i], SrcBuffer[i+1], SrcBuffer[i+2]);
04243
04244 if (!PrintRGBBlackAsKey || Temp > 0)
04245 {
04246
04247 Ink = BGT[255 - Temp];
04248
04249 DestBuffer[i] = DestBuffer[i+1] = DestBuffer[i+2] = 255 - Ink;
04250 }
04251 else
04252 {
04253 DestBuffer[i] = DestBuffer[i+1] = DestBuffer[i+2] = 0;
04254 }
04255 }
04256 }
04257 break;
04258
04259
04260 case COLOURPLATE_SPOT:
04261
04262
04263 for (i = 0; i < PixelWidth * 3; i += 3)
04264 DestBuffer[i] = DestBuffer[i+1] = DestBuffer[i+2] = 255;
04265 break;
04266
04267
04268 default:
04269 ERROR3(_T("Unsupported separation plate!"));
04270 break;
04271 }
04272
04273
04274 #undef TEMPMAX
04275 }
04276
04277
04278
04279
04280
04281
04282
04283
04284
04285
04286
04287
04288
04289
04290
04291
04292
04293
04294
04295
04296
04297
04298
04299 SlowJobResult CamelotEPSRenderRegion::DrawMaskedBitmap(const DocRect &Rect, KernelBitmap* pBitmap,
04300 MaskedRenderRegion* pMask,
04301 ProgressDisplay *Progress)
04302 {
04303 #ifndef STANDALONE
04304
04305 KernelDC *pDC = (KernelDC*)CCDC::ConvertFromNativeDC(RenderDC);
04306
04307
04308 if ((pBitmap==NULL) || (pMask==NULL))
04309 return SLOWJOB_FAILURE;
04310
04311
04312 BOOL IsCamelotEPS = IS_A(this, CamelotEPSRenderRegion);
04313
04314
04315
04316
04317 if (pMask->FindCoverage(TRUE) == 0)
04318 return SLOWJOB_SUCCESS;
04319
04320
04321 if (pBitmap->ActualBitmap == NULL)
04322 return SLOWJOB_FAILURE;
04323
04324
04325 CWxBitmap *WinBM = (CWxBitmap*)pBitmap->ActualBitmap;
04326
04327
04328 if ((WinBM->BMInfo==NULL) || (WinBM->BMBytes==NULL))
04329 return SLOWJOB_FAILURE;
04330
04331
04332 INT32 Width = WinBM->GetWidth();
04333 INT32 Height = WinBM->GetHeight();
04334
04335 if ((Width == 0) || (Height == 0))
04336
04337 return SLOWJOB_FAILURE;
04338
04339
04340
04341 INT32 BitmapDepth = WinBM->GetBPP();
04342 if (BitmapDepth == 32)
04343 {
04344
04345
04346
04347
04348 const INT32 ScanlineBytes = WinBM->GetScanlineSize();
04349
04350
04351 const INT32 DestlineBytes = DIBUtil::ScanlineSize(Width, 24);
04352
04353
04354 LPBYTE OriginalBuffer = WinBM->BMBytes;
04355 LPBYTE ConvertedBuffer = WinBM->BMBytes;
04356
04357 INT32 i;
04358 for (i=0; i<Height; i++)
04359 {
04360 DIBUtil::Convert32to24(Width, OriginalBuffer, ConvertedBuffer);
04361 OriginalBuffer += ScanlineBytes;
04362 ConvertedBuffer += DestlineBytes;
04363 }
04364
04365
04366 WinBM->BMInfo->bmiHeader.biSizeImage = DestlineBytes * Height;
04367 WinBM->BMInfo->bmiHeader.biBitCount = 24;
04368 BitmapDepth = 24;
04369
04370
04371
04372 OriginalBuffer = WinBM->BMBytes;
04373
04374 for (i=0; i<Height; i++)
04375 {
04376 ConvertedBuffer = OriginalBuffer;
04377 for (INT32 j=0; j<Width; j++)
04378 {
04379
04380 BYTE Temp = ConvertedBuffer[0];
04381 ConvertedBuffer[0] = ConvertedBuffer[2];
04382 ConvertedBuffer[2] = Temp;
04383 ConvertedBuffer += 3;
04384 }
04385
04386 OriginalBuffer += DestlineBytes;
04387 }
04388 }
04389
04390
04391 ERROR3IF(BitmapDepth!=24, _T("Non 24bpp bitmap found in DrawMaskedBitmap"));
04392
04393
04394
04395 INT32 SrcDpi = pMask->FindMaskDpi();
04396 INT32 DestDpi = SrcDpi;
04397 BOOL UseLevel2 = FALSE;
04398
04399 if (IsCamelotEPS)
04400 {
04401
04402 DestDpi = 72000;
04403
04404
04405 if (EPSFilter::XSEPSExportPSType == 2)
04406 UseLevel2 = TRUE;
04407 }
04408 else
04409 {
04410
04411 if (RenderDC!=NULL)
04412 DestDpi = RenderDC->GetPPI().GetWidth();
04413
04414 #ifndef WEBSTER
04415
04416 if (IsPrinting())
04417 {
04418
04419 CCPrintInfo *pInfo = CCPrintInfo::GetCurrent();
04420 if (pInfo != NULL)
04421 {
04422 PrintControl *pPrCtrl = pInfo->GetPrintControl();
04423 ERROR3IF(pPrCtrl == NULL, _T("Unexpected NULL pointer"));
04424
04425 if (pPrCtrl->GetPSLevel() == PSLEVEL_2)
04426
04427 UseLevel2 = TRUE;
04428 }
04429 }
04430 #endif //webster
04431 }
04432
04433
04434 double Ratio = DestDpi;
04435 Ratio = Ratio/SrcDpi;
04436 TRACEUSER( "Rik", _T("Src = %ld, Dest = %ld, Ratio = %f\n"), SrcDpi, DestDpi, Ratio);
04437
04438
04439 DocRect ClipRect = pMask->GetClipRect();
04440 POINT Origin;
04441
04442 if (IsCamelotEPS)
04443 {
04444
04445 Origin.x = ClipRect.lo.x;
04446 Origin.y = ClipRect.lo.y;
04447 }
04448 else
04449 {
04450
04451 WinRect WinClipRect = OSRenderRegion::DocRectToWin(RenderMatrix, ClipRect, DestDpi);
04452 Origin.x = WinClipRect.GetLeft();
04453 Origin.y = WinClipRect.GetBottom();
04454 }
04455
04456
04457 if (Progress!=NULL)
04458 Progress->StartBitmapPhaseBand(Height);
04459
04460
04461 LPBITMAPINFO TempBitmapInfo = NULL;
04462 LPBYTE TempBitmapBytes = NULL;
04463
04464
04465 TempBitmapInfo = AllocDIB(Width, 1, BitmapDepth, &TempBitmapBytes);
04466 if (TempBitmapInfo==NULL)
04467 return SLOWJOB_FAILURE;
04468
04469
04470 BYTE *pRGBBuf = (BYTE *) CCMalloc(Width);
04471 ERROR2IF(pRGBBuf == NULL, SLOWJOB_FAILURE, _T("No memory for RGB buffer"));
04472
04473
04474 INT32 ScanLineBytes = DIBUtil::ScanlineSize(Width, BitmapDepth);
04475 INT32 BytesPerPixel = 3;
04476
04477
04478 LPBYTE SrcBuffer = WinBM->BMBytes;
04479 LPBYTE DestBuffer = TempBitmapBytes;
04480
04481
04482
04483
04484 if (SepTables == NULL && RenderView->GetColourPlate() != NULL && !RenderView->GetColourPlate()->IsDisabled())
04485 {
04486
04487
04488 ColourContextCMYK *cc = (ColourContextCMYK *)RenderView->GetColourContext(COLOURMODEL_CMYK);
04489 if (cc != NULL)
04490 {
04491 SepTables = (BYTE *) CCMalloc(5 * 256 * sizeof(BYTE));
04492 if (SepTables != NULL)
04493 {
04494 if (!cc->GetProfileTables(SepTables))
04495 {
04496 CCFree(SepTables);
04497 SepTables = NULL;
04498 }
04499 }
04500 }
04501
04502 ERROR3IF(SepTables == NULL, _T("Can't generate separation tables in CamelotEPSRenderRegion"));
04503 }
04504
04505
04506 MaskRegion MaskInfo;
04507 pMask->GetFirstMaskRegion(&MaskInfo);
04508 try
04509 {
04510 while (MaskInfo.Length!=0)
04511 {
04512
04513 SrcBuffer = WinBM->BMBytes;
04514 SrcBuffer += ScanLineBytes * MaskInfo.y;
04515 SrcBuffer += MaskInfo.x*BytesPerPixel;
04516 INT32 RegionWidth = MaskInfo.Length;
04517
04518
04519 TempBitmapInfo->bmiHeader.biWidth = RegionWidth;
04520 TempBitmapInfo->bmiHeader.biSizeImage = (RegionWidth*BytesPerPixel);
04521
04522
04523 if (SepTables == NULL)
04524 {
04525
04526 memcpy(DestBuffer, SrcBuffer, RegionWidth*BytesPerPixel);
04527 }
04528 else
04529 {
04530
04531
04532 ERROR3IF(BytesPerPixel != 3, _T("non-24bpp scanline unsupported"));
04533 ColourSeparateScanline24(DestBuffer, SrcBuffer, RegionWidth);
04534 }
04535
04536
04537 INT32 DestX = Origin.x + INT32(ceil(MaskInfo.x*Ratio));
04538 INT32 DestY = Origin.y;
04539
04540
04541
04542 if (IsCamelotEPS)
04543 DestY += INT32(ceil((MaskInfo.y+1)*Ratio));
04544 else
04545 DestY -= INT32(ceil((MaskInfo.y+1)*Ratio));
04546
04547 INT32 DestWidth = INT32(ceil(RegionWidth*Ratio));
04548 INT32 DestHeight = INT32(ceil(1*Ratio));
04549
04550 pDC->OutputToken(_T("sv"));
04551 pDC->OutputValue(RegionWidth);
04552 pDC->OutputToken(_T("1"));
04553
04554
04555 if (IsCamelotEPS)
04556 {
04557
04558 pDC->OutputUserSpaceValue(DestWidth);
04559 pDC->OutputUserSpaceValue(DestHeight);
04560
04561 DocCoord Dest(DestX, DestY);
04562 pDC->OutputCoord(Dest);
04563 }
04564 else
04565 {
04566
04567 pDC->OutputValue(DestWidth);
04568 pDC->OutputValue(DestHeight);
04569 pDC->OutputValue(DestX);
04570 pDC->OutputValue(DestY);
04571 }
04572
04573
04574 if (UseLevel2)
04575 pDC->OutputToken(_T("2"));
04576 else
04577 pDC->OutputToken(_T("1"));
04578
04579
04580 if (SepTables == NULL)
04581 pDC->OutputToken(_T("cbsl"));
04582 else
04583 pDC->OutputToken(_T("gbsl"));
04584
04585
04586
04587 if (UseLevel2)
04588 {
04589
04590
04591
04592
04593
04594
04595 const INT32 NumStreams = (SepTables == NULL) ? 3 : 1;
04596
04597 for (INT32 i = 0; i < NumStreams; i++)
04598 {
04599 ERROR3IF(RegionWidth > Width, _T("I didn't allocate enough memory!"));
04600
04601
04602 for (INT32 j = 0; j < RegionWidth; j++)
04603 {
04604 pRGBBuf[j] = TempBitmapBytes[(j * 3) + i];
04605 }
04606
04607
04608 if (!pDC->StartASCII85Output(TRUE))
04609
04610 return SLOWJOB_FAILURE;
04611
04612
04613 pDC->OutputASCII85(pRGBBuf, RegionWidth);
04614
04615 if (!pDC->EndASCII85Output())
04616
04617 return SLOWJOB_FAILURE;
04618 }
04619 }
04620 else
04621 {
04622
04623 if (SepTables != NULL)
04624 {
04625
04626 for (INT32 j = 0; j < RegionWidth; j++)
04627 pRGBBuf[j] = TempBitmapBytes[j * 3];
04628 pDC->OutputRawBinary(pRGBBuf, RegionWidth, 1);
04629 }
04630 else
04631 {
04632
04633 pDC->OutputRawBinary(TempBitmapBytes, RegionWidth * 3, 1);
04634 }
04635 }
04636
04637 pDC->OutputToken(_T("rs"));
04638 pDC->OutputNewLine();
04639
04640
04641 if ((Progress!=NULL) && (!Progress->BitmapPhaseBandRenderedTo(MaskInfo.y)))
04642 {
04643
04644 FreeDIB(TempBitmapInfo, TempBitmapBytes);
04645
04646 return SLOWJOB_USERABORT;
04647 }
04648
04649
04650 pMask->GetNextMaskRegion(&MaskInfo);
04651 }
04652 }
04653 catch(CFileException)
04654 {
04655 FreeDIB(TempBitmapInfo, TempBitmapBytes);
04656
04657 if (UseLevel2)
04658 CCFree(pRGBBuf);
04659
04660 return SLOWJOB_FAILURE;
04661 }
04662
04663
04664
04665 TempBitmapInfo->bmiHeader.biSizeImage = (Width*3);
04666 TempBitmapInfo->bmiHeader.biWidth = Width;
04667
04668
04669 FreeDIB(TempBitmapInfo, TempBitmapBytes);
04670
04671
04672 CCFree(pRGBBuf);
04673 #endif
04674
04675
04676 return SLOWJOB_SUCCESS;
04677 }
04678
04679
04680
04681
04682
04683
04684
04685
04686
04687
04688
04689
04690
04691
04692
04693
04694
04695 BOOL CamelotEPSRenderRegion::RenderChar(WCHAR ch, Matrix* pMatrix)
04696 {
04697 #ifndef STANDALONE
04698
04699
04700 if ((ch > 255) || EPSFilter::XSEPSExportTextAsCurves)
04701 return RenderRegion::RenderChar(ch, pMatrix);
04702
04703
04704 GetValidPathAttributes();
04705
04706
04707 Matrix matrix;
04708 if (GetCharAttributeMatrix(&matrix)==FALSE)
04709 return FALSE;
04710 if (pMatrix)
04711 matrix*=*pMatrix;
04712
04713
04714
04715 FIXED16 abcd[4];
04716 INT32 ef[2];
04717 matrix.GetComponents(abcd, ef);
04718
04719 if ((abcd[1] == FIXED16(0)) && (abcd[2] == FIXED16(0)) && (abcd[0] == abcd[3]))
04720 {
04721
04722
04723
04724 MILLIPOINT ReferenceSize = TextManager::GetDefaultHeight();
04725 MILLIPOINT Height = ReferenceSize * abcd[3];
04726
04727 if (!SelectNewFont(RR_TXTFONTTYPEFACE(), RR_TXTBOLD(), RR_TXTITALIC(), Height))
04728 {
04729
04730 return FALSE;
04731 }
04732 }
04733 else
04734 {
04735
04736 if (!SelectNewFont(RR_TXTFONTTYPEFACE(), RR_TXTBOLD(), RR_TXTITALIC(), abcd))
04737 {
04738
04739 return FALSE;
04740 }
04741 }
04742
04743
04744 KernelDC *pKernelDC = (KernelDC*)CCDC::ConvertFromNativeDC(RenderDC);
04745
04746
04747
04748
04749
04750 char cBuffer[3];
04751
04752
04753 UINT32 uiCharNumber = UnicodeManager::UnicodeToMultiByte(ch);
04754
04755
04756
04757
04758 UnicodeManager::DecomposeMultiBytes(uiCharNumber, (BYTE*) &cBuffer[0], (BYTE*) &cBuffer[1]);
04759
04760
04761 cBuffer[2]=0;
04762
04763
04764
04765
04766
04767
04768
04769
04770
04771
04772
04773
04774 TCHAR tcBuffer[3];
04775 tcBuffer[0]=cBuffer[0];
04776 tcBuffer[1]=cBuffer[1];
04777 tcBuffer[2]=cBuffer[2];
04778
04779 if (tcBuffer[0]==0)
04780
04781
04782
04783 pKernelDC->OutputString(&tcBuffer[1]);
04784 else
04785
04786
04787
04788 pKernelDC->OutputString(&tcBuffer[0]);
04789
04790
04791
04792
04793 DocCoord DocPos(ef[0], ef[1]);
04794 pKernelDC->OutputCoord(DocPos);
04795
04796
04797 BOOL FlatFill = IS_A(CurrentAttrs[ATTR_FILLGEOMETRY].pAttr, FlatFillAttribute);
04798 BOOL Stroked = !RR_STROKECOLOUR().IsTransparent();
04799
04800
04801
04802 BOOL Filled = !FlatFill || (!RR_FILLCOLOUR().IsTransparent());
04803
04804 if (FlatFill && Filled && !Stroked)
04805 {
04806
04807 pKernelDC->OutputToken(_T("t"));
04808 }
04809 else
04810 {
04811
04812 if (Stroked)
04813 {
04814 if (Filled)
04815
04816 pKernelDC->OutputToken(_T("tb"));
04817 else
04818
04819 pKernelDC->OutputToken(_T("ts"));
04820 }
04821 else
04822 {
04823
04824 pKernelDC->OutputToken(_T("tf"));
04825 }
04826 }
04827
04828 #endif
04829
04830 return TRUE;
04831 }
04832
04833
04834
04835
04836
04837
04838
04839
04840
04841
04842
04843
04844
04845
04846 void CamelotEPSRenderRegion::ConditionalSuicide ( void )
04847 {
04848
04849 }
04850
04851
04852
04853
04854
04855
04856
04857
04858
04859
04860
04861
04862
04863
04864 BOOL CamelotEPSRenderRegion::NeedsPrintComponents ( void )
04865 {
04866
04867 return TRUE;
04868 }
04869
04870
04871
04872
04873
04874
04875
04876
04877
04878
04879
04880
04881
04882
04883
04884
04885
04886
04887
04888
04889 BOOL CamelotEPSRenderRegion::SelectNewFont ( WORD Typeface,
04890 BOOL Bold,
04891 BOOL Italic,
04892 MILLIPOINT Size )
04893 {
04894 #ifndef STANDALONE
04895
04896
04897
04898 if ((FontInfo.Valid && !FontInfo.Complex) &&
04899 (FontInfo.Typeface == Typeface) &&
04900 (FontInfo.Bold == Bold) &&
04901 (FontInfo.Italic == Italic) &&
04902 (FontInfo.Size == Size))
04903 {
04904
04905 TRACEUSER( "Tim", _T("Using the cached font\n"));
04906 return TRUE;
04907 }
04908
04909
04910
04911
04912 String_64 FontName;
04913 if (!FONTMANAGER->GetFontName(Typeface, FontName))
04914 return FALSE;
04915
04916
04917 String_64 Encoded;
04918 INT32 Styles = 0;
04919 if (Bold)
04920 Styles += 1;
04921 if (Italic)
04922 Styles += 2;
04923 FONTMANAGER->EncodeFontName(FontName, Encoded, Styles);
04924
04925
04926 String_256 MappedFontName;
04927 if (!Camelot.GetPrefDirect(_T("EPSFontMapping"), (TCHAR *) Encoded, &MappedFontName))
04928 {
04929
04930 if (Bold)
04931 {
04932 if (Italic)
04933 MappedFontName.Load(_R(IDS_K_CAMEPS_MAPFNAMEBI));
04934 else
04935 MappedFontName.Load(_R(IDS_K_CAMEPS_MAPFNAMEB));
04936 }
04937 else
04938 {
04939 if (Italic)
04940 MappedFontName.Load(_R(IDS_K_CAMEPS_MAPFNAMEI));
04941 else
04942 MappedFontName.Load(_R(IDS_K_CAMEPS_MAPFNAME));
04943 }
04944 }
04945
04946
04947
04948
04949 MILLIPOINT CorrectedSize = Size;
04950 MILLIPOINT Remainder = Size % 1000;
04951 if ((Remainder <= 2) || (Remainder >= 998))
04952
04953 CorrectedSize = ((Size + 500) / 1000) * 1000;
04954
04955
04956 KernelDC *pKernelDC = (KernelDC*)CCDC::ConvertFromNativeDC(RenderDC);
04957 String_8 Slash(TEXT("/"));
04958 MappedFontName.Insert(Slash, 0);
04959 pKernelDC->OutputToken((TCHAR *) MappedFontName);
04960 pKernelDC->OutputUserSpaceValue(CorrectedSize);
04961 pKernelDC->OutputToken(_T("sf"));
04962
04963
04964 FontInfo.Valid = TRUE;
04965 FontInfo.Complex = FALSE;
04966 FontInfo.Typeface = Typeface;
04967 FontInfo.Bold = Bold;
04968 FontInfo.Italic = Italic;
04969 FontInfo.Size = Size;
04970
04971 #endif
04972
04973
04974 return TRUE;
04975 }
04976
04977
04978
04979 BOOL CamelotEPSRenderRegion::SelectNewFont(WORD Typeface, BOOL Bold, BOOL Italic, FIXED16 *abcd)
04980 {
04981 #ifndef STANDALONE
04982
04983
04984
04985
04986 if ((FontInfo.Valid && FontInfo.Complex) &&
04987 (FontInfo.Typeface == Typeface) &&
04988 (FontInfo.Bold == Bold) &&
04989 (FontInfo.Italic == Italic) &&
04990 (FontInfo.a == abcd[0]) &&
04991 (FontInfo.b == abcd[1]) &&
04992 (FontInfo.c == abcd[2]) &&
04993 (FontInfo.d == abcd[3]))
04994 {
04995
04996 TRACEUSER( "Tim", _T("Using the cached font\n"));
04997 return TRUE;
04998 }
04999
05000
05001
05002
05003
05004
05005
05006 String_64 FontName;
05007 if (!FONTMANAGER->GetFontName(Typeface, FontName))
05008 return FALSE;
05009
05010
05011 String_64 Encoded;
05012 INT32 Styles = 0;
05013 if (Bold)
05014 Styles += 1;
05015 if (Italic)
05016 Styles += 2;
05017 FONTMANAGER->EncodeFontName(FontName, Encoded, Styles);
05018
05019
05020 String_256 MappedFontName;
05021 if (!Camelot.GetPrefDirect(_T("EPSFontMapping"), (TCHAR *) Encoded, &MappedFontName))
05022 {
05023
05024 if (Bold)
05025 {
05026 if (Italic)
05027 MappedFontName.Load(_R(IDS_K_CAMEPS_MAPFNAMEBI2));
05028 else
05029 MappedFontName.Load(_R(IDS_K_CAMEPS_MAPFNAMEB2));
05030 }
05031 else
05032 {
05033 if (Italic)
05034 MappedFontName.Load(_R(IDS_K_CAMEPS_MAPFNAMEI2));
05035 else
05036 MappedFontName.Load(_R(IDS_K_CAMEPS_MAPFNAME2));
05037 }
05038 }
05039
05040
05041 KernelDC *pKernelDC = (KernelDC*)CCDC::ConvertFromNativeDC(RenderDC);
05042 String_8 Slash(TEXT("/"));
05043 MappedFontName.Insert(Slash, 0);
05044 pKernelDC->OutputToken((TCHAR *) MappedFontName);
05045
05046
05047
05048 double ScaleFactor = TextManager::GetDefaultHeight() / 1000.0;
05049 TCHAR MatrixBuf[100];
05050 camSprintf(MatrixBuf, _T("[%.3f %.3f %.3f %.3f 0 0]"),
05051 (double) (abcd[0].MakeDouble() * ScaleFactor),
05052 (double) (abcd[1].MakeDouble() * ScaleFactor),
05053 (double) (abcd[2].MakeDouble() * ScaleFactor),
05054 (double) (abcd[3].MakeDouble() * ScaleFactor));
05055
05056 pKernelDC->OutputToken(MatrixBuf);
05057
05058
05059 pKernelDC->OutputToken(_T("sf"));
05060
05061
05062 FontInfo.Valid = TRUE;
05063 FontInfo.Complex = TRUE;
05064 FontInfo.Typeface = Typeface;
05065 FontInfo.Bold = Bold;
05066 FontInfo.Italic = Italic;
05067 FontInfo.a = abcd[0];
05068 FontInfo.b = abcd[1];
05069 FontInfo.c = abcd[2];
05070 FontInfo.d = abcd[3];
05071
05072 #endif
05073
05074
05075 return TRUE;
05076 }
05077
05078
05079
05080
05081
05082
05083
05084
05085
05086
05087
05088
05089
05090
05091
05092
05093
05094
05095
05096
05097
05098 BOOL CamelotEPSRenderRegion::DrawTransformedBitmap(NodeBitmap *pNodeBitmap)
05099 {
05100
05101 if ((!RenderComplexShapes) && (TestForComplexShape(&Caps)))
05102 return TRUE;
05103
05104 if ((!RenderComplexShapes) && (pNodeBitmap->NeedsTransparency()))
05105 return TRUE;
05106
05107 DocCoord *Coords = pNodeBitmap->InkPath.GetCoordArray();
05108
05109
05110 OILBitmap *TheBitmap = pNodeBitmap->GetBitmap()->ActualBitmap;
05111
05112
05113 DocColour *StartCol = NULL,
05114 *EndCol = NULL;
05115
05116 if (!RR_STROKECOLOUR().IsTransparent())
05117 {
05118
05119 StartCol = &(RR_STROKECOLOUR());
05120 EndCol = &(RR_FILLCOLOUR());
05121 }
05122
05123
05124 return DrawParallelogramBitmap(Coords, TheBitmap, GetFillEffect(), StartCol, EndCol);
05125 }
05126
05127
05128
05129
05130
05131
05132
05133
05134
05135
05136
05137
05138
05139
05140
05141
05142
05143
05144
05145
05146
05147
05148
05149
05150
05151
05152
05153
05154
05155
05156
05157
05158
05159
05160
05161
05162
05163
05164
05165 BOOL CamelotEPSRenderRegion::DrawParallelogramBitmap(DocCoord *Coords, OILBitmap *pBitmap,
05166 EFFECTTYPE Effect,
05167 DocColour *StartCol, DocColour *EndCol)
05168 {
05169
05170 if ((!RenderComplexShapes) && (TestForComplexShape(&Caps)))
05171 return TRUE;
05172
05173
05174 if (StartCol != NULL && StartCol->IsTransparent() && EndCol != NULL && EndCol->IsTransparent())
05175 return(TRUE);
05176
05177
05178 BitmapInfo BMInfo;
05179 if (!pBitmap->GetInfo(&BMInfo))
05180 {
05181 ERROR3("Bitmap GetInfo failed");
05182
05183 return FALSE;
05184 }
05185
05186
05187 INT32 Width = BMInfo.PixelWidth;
05188 INT32 Height = BMInfo.PixelHeight;
05189
05190 if ((Width == 0) || (Height == 0))
05191 {
05192
05193 ERROR3("Bitmap width/height is 0");
05194 return FALSE;
05195 }
05196
05197
05198 BOOL IsCamelotEPS = IS_A(this, CamelotEPSRenderRegion);
05199
05200
05201 BOOL IsContoned = (StartCol != NULL) && (EndCol != NULL);
05202 if (IsContoned)
05203 {
05204 if (pBitmap->GetGreyscaleVersion() != NULL)
05205 {
05206 pBitmap = pBitmap->GetGreyscaleVersion();
05207 if (!pBitmap->GetInfo(&BMInfo))
05208 {
05209 ERROR3("Bitmap GetInfo failed");
05210
05211 return FALSE;
05212 }
05213 }
05214 }
05215
05216
05217 BOOL UseLevel2 = FALSE;
05218
05219 if (IsCamelotEPS)
05220 {
05221
05222 if (EPSFilter::XSEPSExportPSType == 2)
05223 UseLevel2 = TRUE;
05224 }
05225
05226 #ifndef WEBSTER
05227 else if (IsPrinting())
05228 {
05229 #ifndef STANDALONE
05230
05231 CCPrintInfo *pInfo = CCPrintInfo::GetCurrent();
05232 if (pInfo != NULL)
05233 {
05234 PrintControl *pPrCtrl = pInfo->GetPrintControl();
05235 if (pPrCtrl->GetPSLevel() == PSLEVEL_2)
05236
05237 UseLevel2 = TRUE;
05238 }
05239 #else
05240 ERROR2(FALSE,"CamelotEPSRenderRegion::DrawParallelogramBitmap trying to print in Viewer version!")
05241 #endif
05242 }
05243
05244 #endif //webster
05245
05246
05247
05248
05249
05250 KernelDC *pDC = (KernelDC*)CCDC::ConvertFromNativeDC(RenderDC);
05251
05252 pDC->OutputToken(_T("sv"));
05253
05254
05255 pDC->OutputValue(Width);
05256 pDC->OutputValue(Height);
05257
05258
05259 INT32 BytesPerScanline;
05260
05261
05262
05263
05264
05265 if (!IsContoned && SepTables == NULL && RenderView->GetColourPlate() != NULL)
05266 {
05267 ColourContextCMYK *cc = (ColourContextCMYK *)RenderView->GetColourContext(COLOURMODEL_CMYK);
05268 if (cc != NULL)
05269 {
05270 SepTables = (BYTE *) CCMalloc(5 * 256 * sizeof(BYTE));
05271 if (SepTables != NULL)
05272 {
05273 if (!cc->GetProfileTables(SepTables))
05274 {
05275 CCFree(SepTables);
05276 SepTables = NULL;
05277 }
05278 }
05279 }
05280
05281 ERROR3IF(SepTables == NULL, "Can't generate separation tables in CamelotEPSRenderRegion");
05282 }
05283
05284 if (SepTables != NULL && !IsContoned)
05285 {
05286
05287 pDC->OutputValue((INT32)8);
05288 BytesPerScanline = Width;
05289 }
05290 else
05291 {
05292
05293 switch (BMInfo.PixelDepth)
05294 {
05295 case 1:
05296 case 8:
05297 pDC->OutputValue((INT32) BMInfo.PixelDepth);
05298 BytesPerScanline = ((BMInfo.PixelDepth * Width) + 7) / 8;
05299 break;
05300
05301 case 4:
05302
05303
05304 pDC->OutputValue((INT32) 8);
05305 BytesPerScanline = Width;
05306 break;
05307
05308 case 24:
05309 case 32:
05310
05311 pDC->OutputValue((INT32) 24);
05312 BytesPerScanline = 3 * Width;
05313 break;
05314
05315 default:
05316
05317 ERROR3("Unsupported bitmap depth in CamelotEPSRenderRegion::DrawParallelogramBitmap");
05318 return FALSE;
05319 }
05320 }
05321
05322
05323 pDC->OutputValue(BytesPerScanline);
05324
05325
05326
05327
05328 pDC->OutputToken(_T("["));
05329
05330
05331
05332
05333 double a[2],b[2],c[2],d[2], e[2], f[2];
05334
05335
05336 double UnitSize;
05337 if (IsCamelotEPS)
05338 {
05339
05340
05341 UnitSize = 1000;
05342 }
05343 else
05344 {
05345
05346 FIXED16 fxPixelSize;
05347 RenderView->GetPixelSize(&fxPixelSize, &fxPixelSize);
05348 UnitSize = fxPixelSize.MakeDouble();
05349 }
05350
05351
05352
05353 double dWidth = (double) Width;
05354 double dHeight = (double) Height;
05355
05356 DocCoord DCOrigin = pDC->GetOrigin();
05357
05358 if (IsCamelotEPS)
05359 {
05360 dWidth *= UnitSize;
05361 dHeight *= UnitSize;
05362 a[0] = ((double) (Coords[2].x - Coords[3].x)) / dWidth;
05363 b[0] = ((double) (Coords[2].y - Coords[3].y)) / dWidth;
05364 c[0] = ((double) (Coords[0].x - Coords[3].x)) / dHeight;
05365 d[0] = ((double) (Coords[0].y - Coords[3].y)) / dHeight;
05366 e[0] = ((double) (Coords[3].x - DCOrigin.x)) / UnitSize;
05367 f[0] = ((double) (Coords[3].y - DCOrigin.y)) / UnitSize;
05368 }
05369 else
05370 {
05371 ERROR3IF(!pDC->IsKindOf(CC_RUNTIME_CLASS(PSPrintDC)), "KernelDC is not a PSPrintDC - how did that happen?");
05372
05373 PSPrintDC *pPSDC = (PSPrintDC *) pDC;
05374
05375 WinCoord PSCoords[3];
05376 for (INT32 i = 0; i <= 3; i++)
05377 PSCoords[i] = pPSDC->TransformCoord(Coords[i]);
05378
05379 a[0] = ((double) (PSCoords[2].x - PSCoords[3].x)) / dWidth;
05380 b[0] = ((double) (PSCoords[2].y - PSCoords[3].y)) / dWidth;
05381 c[0] = ((double) (PSCoords[0].x - PSCoords[3].x)) / dHeight;
05382 d[0] = ((double) (PSCoords[0].y - PSCoords[3].y)) / dHeight;
05383 e[0] = (double) PSCoords[3].x;
05384 f[0] = (double) PSCoords[3].y;
05385 }
05386
05387
05388 double Det = a[0] * d[0] - b[0] * c[0];
05389
05390 if (Det==0.0)
05391 {
05392
05393
05394 ERROR3("Matrix Inversion Failed - Tried to Invert a non-invertable matrix" );
05395 return FALSE;
05396 }
05397
05398
05399
05400
05401
05402
05403
05404 a[1] = d[0] / Det;
05405 b[1] = -b[0] / Det;
05406 c[1] = -c[0] / Det;
05407 d[1] = a[0] / Det;
05408 e[1] = ((c[0] * f[0]) - (e[0] * d[0])) / Det ;
05409 f[1] = -(((a[0] * f[0]) - (e[0] * b[0])) / Det);
05410
05411 pDC->OutputReal(a[1]);
05412 pDC->OutputReal(b[1]);
05413 pDC->OutputReal(c[1]);
05414 pDC->OutputReal(d[1]);
05415
05416 if (IsCamelotEPS)
05417 {
05418
05419 pDC->OutputUserSpaceValue((MILLIPOINT) (e[1] * 1000.0));
05420 pDC->OutputUserSpaceValue((MILLIPOINT) (f[1] * 1000.0));
05421 }
05422 else
05423 {
05424
05425 pDC->OutputReal(e[1]);
05426 pDC->OutputReal(f[1]);
05427 }
05428
05429 pDC->OutputToken(_T("]"));
05430
05431
05432 pDC->OutputToken(_T("false"));
05433 pDC->OutputToken(_T("false"));
05434
05435
05436 if (UseLevel2)
05437
05438 pDC->OutputToken(_T("3"));
05439 else
05440
05441 pDC->OutputToken(_T("1"));
05442
05443
05444 pDC->OutputToken(_T("beginimage"));
05445
05446 if (SepTables != NULL && !IsContoned)
05447 {
05448
05449
05450
05451
05452
05453
05454 if (!pBitmap->ExportSeparatedPalette(this))
05455 {
05456 ERROR3("ExportSeparatedPalette failed");
05457 return FALSE;
05458 }
05459
05460 pDC->OutputToken(_T("doclutimage"));
05461
05462 pDC->OutputNewLine();
05463
05464
05465 if (!pBitmap->ExportSeparatedData(this, SepTables))
05466 {
05467 ERROR3("ExportSeparatedData failed");
05468 return FALSE;
05469 }
05470 }
05471 else
05472 {
05473
05474
05475 switch (BMInfo.PixelDepth)
05476 {
05477 case 1:
05478
05479 if (IsContoned)
05480 {
05481
05482
05483
05484
05485
05486
05487 Document *pDoc = RenderView->GetDoc();
05488 if (pDoc == NULL)
05489 {
05490 ERROR3("No document when rendering");
05491
05492 return FALSE;
05493 }
05494
05495
05496 ColourContext *pContext = CurrentColContext;
05497 if (pContext == NULL)
05498 {
05499 ERROR3("No Colour context when rendering");
05500 return(FALSE);
05501 }
05502
05503 ERROR3IF(pContext->GetColourModel() != COLOURMODEL_RGBT,
05504 "RGB output context expected in EPS rendering");
05505 ColourRGBT Result;
05506
05507 if (IsContoned)
05508 pContext->ConvertColour((DocColour *) StartCol, (ColourGeneric *)&Result);
05509 else
05510 {
05511 DocColour Black(0L, 0L, 0L);
05512 pContext->ConvertColour(&Black, (ColourGeneric *)&Result);
05513 }
05514
05515 pDC->OutputReal(Result.Red.MakeDouble());
05516 pDC->OutputReal(Result.Green.MakeDouble());
05517 pDC->OutputReal(Result.Blue.MakeDouble());
05518
05519 if (IsContoned)
05520 pContext->ConvertColour((DocColour *) EndCol, (ColourGeneric *)&Result);
05521 else
05522 {
05523 DocColour White(255L, 255L, 255L);
05524 pContext->ConvertColour(&White, (ColourGeneric *)&Result);
05525 }
05526
05527 pDC->OutputReal(Result.Red.MakeDouble());
05528 pDC->OutputReal(Result.Green.MakeDouble());
05529 pDC->OutputReal(Result.Blue.MakeDouble());
05530
05531
05532 pDC->OutputToken(_T("1bitcopyimage"));
05533 }
05534 else
05535 {
05536
05537 pDC->OutputToken(_T("1bitbwcopyimage"));
05538 }
05539 break;
05540
05541 case 4:
05542 case 8:
05543 if (IsContoned)
05544 {
05545
05546 if (!pBitmap->BuildContonePalette(*StartCol, *EndCol, Effect, RenderView))
05547 {
05548 ERROR3("Contoned palette failed");
05549
05550 return FALSE;
05551 }
05552
05553 BOOL Success = pBitmap->ExportContonePalette(this);
05554
05555
05556 pBitmap->DestroyContonePalette();
05557
05558
05559 if (!Success)
05560 {
05561 ERROR3("Contoned palette export failed");
05562 return FALSE;
05563 }
05564
05565
05566 pDC->OutputToken(_T("doclutimage"));
05567 }
05568 else if (BMInfo.NumPaletteEntries > 0)
05569 {
05570
05571 if (!pBitmap->ExportBitmapPalette(this))
05572 {
05573 ERROR3("ExportBitmapPalette failed");
05574 return FALSE;
05575 }
05576
05577
05578 pDC->OutputToken(_T("doclutimage"));
05579 }
05580 else
05581 {
05582
05583
05584
05585 pDC->OutputToken(_T("doimage"));
05586 }
05587 break;
05588
05589 case 24:
05590 case 32:
05591 pDC->OutputToken(_T("do24image"));
05592 break;
05593
05594 default:
05595
05596 ERROR3("Unsupported bitmap depth");
05597 return FALSE;
05598 }
05599
05600 pDC->OutputNewLine();
05601
05602
05603 if (!pBitmap->ExportBitmapData(this))
05604 {
05605 ERROR3("ExportBitmapData failed");
05606 return FALSE;
05607 }
05608 }
05609
05610
05611 pDC->OutputNewLine();
05612 pDC->OutputToken(_T("endimage"));
05613
05614 pDC->OutputToken(_T("rs"));
05615 pDC->OutputNewLine();
05616
05617 return TRUE;
05618 }
05619
05620
05621
05622
05623
05624
05625
05626
05627
05628
05629
05630
05631
05632
05633
05634 void CamelotEPSRenderRegion::DrawPathToOutputDevice(Path *DrawPath, PathShape)
05635 {
05636
05637 if ((!RenderComplexShapes) && (TestForComplexShape(&Caps)))
05638 return;
05639
05640
05641 BOOL Renderable = (IS_A(this, CamelotEPSRenderRegion) || IsPrinting());
05642
05643 if (Renderable)
05644 {
05645
05646
05647
05648 ColourFillAttribute* pFillAttr = (ColourFillAttribute*) CurrentAttrs[ATTR_FILLGEOMETRY].pAttr;
05649
05650
05651 if (pFillAttr->IS_KIND_OF(BitmapFillAttribute))
05652 {
05653 FillMappingAttribute* pMapAttr = (FillMappingAttribute*) CurrentAttrs[ATTR_FILLMAPPING].pAttr;
05654 if (pMapAttr->Repeat == 1)
05655 {
05656
05657 DrawClippedBitmap(DrawPath);
05658 return;
05659 }
05660 }
05661 }
05662
05663 ExportPath(DrawPath, FALSE);
05664
05665
05666 if (!Caps.ArrowHeads)
05667 {
05668
05669 DrawPathArrowHeads(DrawPath->GetCoordArray(),
05670 DrawPath->GetVerbArray(),
05671 DrawPath->GetNumCoords());
05672 }
05673 }
05674
05675
05676
05677
05678
05679
05680
05681
05682
05683
05684
05685
05686
05687
05688
05689
05690
05691 BOOL CamelotEPSRenderRegion::DrawClippedBitmap(Path *DrawPath)
05692 {
05693
05694 KernelDC *pDC = (KernelDC*)CCDC::ConvertFromNativeDC(RenderDC);
05695
05696
05697
05698
05699
05700
05701
05702 GetValidPathAttributes();
05703
05704
05705 ExportPath(DrawPath, TRUE, TRUE);
05706
05707
05708 pDC->OutputToken(_T("gs"));
05709
05710
05711
05712 if (RR_WINDINGRULE() == EvenOddWinding)
05713 pDC->OutputToken(TEXT("eoclip"));
05714 else
05715 pDC->OutputToken(TEXT("clip"));
05716
05717
05718 BitmapFillAttribute* pFillAttr = (BitmapFillAttribute*) CurrentAttrs[ATTR_FILLGEOMETRY].pAttr;
05719 DocCoord Coords[4];
05720 Coords[3] = *(pFillAttr->GetStartPoint());
05721 Coords[2] = *(pFillAttr->GetEndPoint());
05722 Coords[0] = *(pFillAttr->GetEndPoint2());
05723
05724
05725
05726 Coords[1].x = Coords[0].x + (Coords[2].x - Coords[3].x);
05727 Coords[1].y = Coords[0].y + (Coords[2].y - Coords[3].y);
05728
05729
05730 KernelBitmap *pKernelBitmap = pFillAttr->GetBitmap();
05731 if (pKernelBitmap == NULL)
05732 return FALSE;
05733
05734
05735 if (!DrawParallelogramBitmap(Coords, pKernelBitmap->ActualBitmap, GetFillEffect(),
05736 pFillAttr->GetStartColour(), pFillAttr->GetEndColour()))
05737 return FALSE;
05738
05739
05740 pDC->OutputToken(_T("gr"));
05741
05742
05743 TCHAR PathType[2] = _T("N");
05744
05745 if (!RR_STROKECOLOUR().IsTransparent())
05746 {
05747
05748 PathType[0] = 'S';
05749 }
05750
05751 PathVerb* Verbs = DrawPath->GetVerbArray();
05752 INT32 NumCoords = DrawPath->GetNumCoords();
05753
05754 if (Verbs[NumCoords - 1] & PT_CLOSEFIGURE)
05755
05756 PathType[0] = tolower(PathType[0]);
05757
05758
05759 pDC->OutputToken(PathType);
05760 pDC->OutputNewLine();
05761
05762
05763 return TRUE;
05764 }
05765
05766
05767
05768
05769
05770
05771
05772
05773
05774
05775
05776
05777
05778
05779
05780 BOOL CamelotEPSRenderRegion::WriteNewLine ( void )
05781 {
05782
05783
05784 return TRUE;
05785 }
05786
05787
05788
05789
05790
05791
05792
05793
05794
05795
05796
05797
05798
05799
05800
05801
05802 void CamelotEPSRenderRegion::OutputStrokeColour ()
05803 {
05804 EPSRenderRegion::OutputStrokeColour ();
05805 }
05806
05807
05808
05809
05810
05811
05812
05813
05814
05815
05816
05817
05818
05819
05820
05821
05822 void CamelotEPSRenderRegion::OutputFillColour ()
05823 {
05824 EPSRenderRegion::OutputFillColour ();
05825 }
05826
05827 #endif