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 #include "camtypes.h"
00103 
00104 
00105 #include <ctype.h>
00106 
00107 
00108 #include "bitfilt.h"
00109 #include "ccdc.h"
00110 #include "colcomp.h"
00111 #include "csrstack.h"
00112 
00113 
00114 
00115 
00116 
00117 #include "prvwflt.h"
00118 #ifndef WEBSTER
00119 
00120 #endif //WEBSTER
00121 
00122 
00123 #include "layer.h"
00124 #include "lineattr.h"
00125 #include "nativeps.h"   
00126 #include "nodeelip.h"
00127 #include "nodepath.h"
00128 #include "noderect.h"
00129 
00130 #include "page.h"
00131 #include "paper.h"
00132 
00133 
00134 #include "progress.h"        
00135 
00136 
00137 #include "saveeps.h"
00138 #include "sglayer.h"
00139 #include "sprdmsg.h"
00140 
00141 
00142 
00143 #include "gclips.h"
00144 #include "nodetxts.h"
00145 #include "nodetxtl.h"
00146 #include "nodershp.h"
00147 
00148 #include "insertnd.h"
00149 #include "fontman.h"
00150 #include "guides.h"
00151 
00152 
00153 #include "moldshap.h"
00154 #include "ai_bmp.h"
00155 
00156 #include "epscdef.h"
00157 #include "nodetext.h"
00158 
00159 DECLARE_SOURCE("$Revision: 1668 $");
00160 
00161 CC_IMPLEMENT_DYNAMIC(EPSFilter, VectorFilter);
00162 CC_IMPLEMENT_MEMDUMP(RangeList, List);
00163 CC_IMPLEMENT_MEMDUMP(EPSClipContext, List);
00164 CC_IMPLEMENT_MEMDUMP(EPSClipContextItem, ListItem);
00165 
00166 #define new CAM_DEBUG_NEW
00167 
00168 
00169 INT32 EPSFilter::XSEPSExportPSType = 2;
00170 INT32 EPSFilter::XSEPSExportDPI  = 200;
00171 BOOL EPSFilter::XSEPSExportTextAsCurves = FALSE;
00172 
00173 
00174 
00175 
00176 
00177 
00178 
00179 
00180 
00181 
00182 
00183 
00184 class RangeListItem : public ListItem
00185 {
00186     CC_DECLARE_MEMDUMP(RangeListItem)
00187 
00188 public:
00189     RangeListItem(Node *pFirst, Node *pLast);
00190     BOOL IsLayer;
00191     Range TheRange;
00192     Layer *TheLayer;
00193 };
00194 
00195 CC_IMPLEMENT_MEMDUMP(RangeListItem, ListItem)
00196 
00197 
00198 
00199 
00200 
00201 
00202 
00203 
00204 
00205 
00206 
00207 
00208 
00209 RangeListItem::RangeListItem(Node *pFirst, Node *pLast)
00210 {
00211     
00212     if(pFirst == pLast && IS_A(pFirst, Layer))
00213     {
00214         
00215         TheLayer = (Layer *)pFirst;
00216         IsLayer = TRUE;
00217     }
00218     else
00219     {
00220         
00221         
00222         
00223         RangeControl Flags;
00224         Flags.Selected = TRUE;
00225         Flags.Unselected = TRUE;
00226 
00227         
00228         Range Tmp(pFirst, pLast, Flags);
00229         TheRange = Tmp;
00230         IsLayer = FALSE;
00231     }
00232 }
00233 
00234 
00235 
00236 
00237 
00238 
00239 
00240 
00241 
00242 
00243 
00244 
00245 
00246 
00247 
00248 
00249 BOOL RangeList::AddRange(Node *pFirst, Node *pLast)
00250 {
00251     
00252     RangeListItem *pItem = new RangeListItem(pFirst, pLast);
00253     if (pItem == NULL)
00254         
00255         return FALSE;
00256 
00257     
00258     AddTail(pItem);
00259     return TRUE;
00260 }
00261 
00262 
00263 
00264 
00265 
00266 
00267 
00268 
00269 
00270 
00271 
00272 
00273 
00274 
00275 
00276 
00277 
00278 DocRect RangeList::GetBoundingRect()
00279 {
00280     
00281     DocRect RangeBBox;
00282 
00283     
00284     RangeListItem *pItem = (RangeListItem *) GetHead();
00285 
00286     while (pItem != NULL)
00287     {
00288         
00289         if(pItem->IsLayer)
00290         {
00291             
00292 
00293             
00294             RangeBBox = RangeBBox.Union(pItem->TheLayer->GetBoundingRect(TRUE));
00295         }
00296         else
00297         {
00298             
00299             Node *pNode = pItem->TheRange.FindFirst();
00300 
00301             while (pNode != NULL)
00302             {
00303                 
00304                 if (pNode->IsBounded())
00305                 {
00306                     
00307                     NodeRenderableBounded *pNodeBounded = (NodeRenderableBounded *) pNode;
00308 
00309                     
00310                     
00311                     
00312                     
00313                     
00314                     
00315                     RangeBBox = RangeBBox.Union(pNodeBounded->GetBoundingRect(TRUE));
00316                 }
00317                 else
00318                 {
00319                     ENSURE(FALSE, "Found a non-renderable node in the import range");
00320                 }
00321 
00322                 
00323                 pNode = pItem->TheRange.FindNext(pNode);
00324             }
00325         }
00326 
00327         
00328         pItem = (RangeListItem *) GetNext(pItem);
00329     }
00330 
00331     
00332     return RangeBBox;
00333 }
00334 
00335 
00336 
00337 
00338 
00339 
00340 
00341 
00342 
00343 
00344 
00345 
00346 
00347 
00348 void RangeList::Transform(TransformBase& Trans)
00349 {
00350     
00351     RangeListItem *pItem = (RangeListItem *) GetHead();
00352 
00353     while (pItem != NULL)
00354     {
00355         if(pItem->IsLayer)
00356         {
00357             pItem->TheLayer->Transform(Trans);
00358         }
00359         else
00360         {
00361             
00362             Node *pNode = pItem->TheRange.FindFirst();
00363 
00364             while (pNode != NULL)
00365             {
00366                 
00367                 if (pNode->IS_KIND_OF(NodeRenderable))
00368                 {
00369                     
00370                     NodeRenderable *pNodeRenderable = (NodeRenderable *) pNode;
00371                     pNodeRenderable->Transform(Trans);
00372                 }
00373                 else
00374                 {
00375                     ENSURE(FALSE, "Found a non-renderable node in the import range");
00376                 }
00377 
00378                 
00379                 pNode = pItem->TheRange.FindNext(pNode);
00380             }
00381         }
00382 
00383         
00384         pItem = (RangeListItem *) GetNext(pItem);
00385     }
00386 }
00387 
00388 
00389 
00390 
00391 
00392 
00393 
00394 
00395 
00396 
00397 
00398 
00399 
00400 EPSClipContextItem::EPSClipContextItem(INT32 TheContextLevel, Path *pNewClipPath)
00401 {
00402     ContextLevel = TheContextLevel;
00403     pClipPath = pNewClipPath;
00404 
00405     
00406     ComplexRegionLevel = 0;
00407 }
00408 
00409 
00410 
00411 
00412 
00413 
00414 
00415 
00416 
00417 
00418 
00419 
00420 
00421 EPSClipContextItem::~EPSClipContextItem()
00422 {
00423     delete pClipPath;
00424 }
00425 
00426 
00427 
00428 
00429 
00430 
00431 
00432 
00433 
00434 
00435 
00436 EPSClipContext::EPSClipContext()
00437 {
00438     ContextLevel = 0;
00439     ComplexRegionLevel = 0;
00440 
00441     
00442     pCachedClipPath = NULL;
00443     CacheIsValid = TRUE;
00444 
00445     
00446     ClippingFlags = 2 | CLIPPING_CLIP_WINDING;
00447 }
00448 
00449 
00450 
00451 
00452 
00453 
00454 
00455 
00456 
00457 
00458 
00459 
00460 
00461 
00462 
00463 void EPSClipContext::SaveContext()
00464 {
00465     ContextLevel++;
00466 }
00467 
00468 
00469 
00470 
00471 
00472 
00473 
00474 
00475 
00476 
00477 
00478 
00479 
00480 
00481 BOOL EPSClipContext::RestoreContext()
00482 {
00483     
00484     CacheIsValid = FALSE;
00485 
00486     
00487     ERROR2IF(ContextLevel == 0, FALSE, "Unbalanced call to EPSClipContext::RestoreContext()");
00488 
00489     
00490     ContextLevel--;
00491 
00492     
00493     EPSClipContextItem *pItem = (EPSClipContextItem *) GetTail();
00494 
00495     while ((pItem != NULL) && (pItem->ContextLevel > ContextLevel))
00496     {
00497         delete RemoveTail();
00498         
00499         
00500         pItem = (EPSClipContextItem *) GetTail();
00501     }
00502 
00503     
00504     return TRUE;
00505 }
00506 
00507 
00508 
00509 
00510 
00511 
00512 
00513 
00514 
00515 
00516 
00517 
00518 
00519 
00520 
00521 
00522 
00523 
00524 
00525 
00526 BOOL EPSClipContext::StartComplexClipRegion()
00527 {
00528     
00529     ComplexRegionLevel++;
00530 
00531     
00532     
00533     EPSClipContextItem *pItem = new EPSClipContextItem(ContextLevel, NULL);
00534     if (pItem == NULL)
00535         
00536         return FALSE;
00537 
00538     
00539     pItem->ComplexRegionLevel = ComplexRegionLevel;
00540 
00541     
00542     AddTail(pItem);
00543 
00544     
00545     return TRUE;
00546 }
00547 
00548 
00549 
00550 
00551 
00552 
00553 
00554 
00555 
00556 
00557 
00558 
00559 
00560 
00561 
00562 
00563 BOOL EPSClipContext::EndComplexClipRegion()
00564 {
00565     ERROR2IF(ComplexRegionLevel == 0, FALSE, 
00566              "Unbalanced call to EPSClipContext::EndComplexClipRegion()");
00567 
00568     
00569     ComplexRegionLevel--;
00570 
00571     
00572     return TRUE;
00573 }
00574 
00575 
00576 
00577 
00578 
00579 
00580 
00581 
00582 
00583 
00584 
00585 
00586 
00587 
00588 
00589 
00590 
00591 BOOL EPSClipContext::AddNewClippingPath(Path *pNewClipPath)
00592 {
00593     
00594     CacheIsValid = FALSE;
00595 
00596     
00597     BOOL SimpleCopy = FALSE;
00598 
00599     EPSClipContextItem *pItem = NULL;
00600 
00601     if (ComplexRegionLevel > 0)
00602     {
00603         
00604 
00605         
00606         pItem = (EPSClipContextItem *) GetTail();
00607         if (pItem->pClipPath == NULL)
00608         {
00609             
00610             SimpleCopy = TRUE;
00611         }
00612         else
00613         {
00614             
00615             if (!pItem->pClipPath->MergeTwoPaths(*pNewClipPath))
00616                 
00617                 return FALSE;
00618         }
00619     }
00620     else
00621     {
00622         
00623         pItem = new EPSClipContextItem(ContextLevel, NULL);
00624 
00625         if (pItem == NULL)
00626             
00627             return FALSE;
00628 
00629         
00630         AddTail(pItem);
00631 
00632         
00633         SimpleCopy = TRUE;
00634     }
00635 
00636     
00637     if (SimpleCopy)
00638     {
00639         
00640         ERROR2IF(pItem == NULL, FALSE, "No clipping item found!");
00641 
00642         
00643         pItem->pClipPath = new Path;
00644 
00645         if (pItem->pClipPath == NULL)
00646             
00647             return FALSE;
00648 
00649         
00650         if ( pNewClipPath != NULL &&
00651              !pItem->pClipPath->Initialise ( pNewClipPath->GetNumCoords () + 3, 12 ) )
00652         {
00653             
00654             return FALSE;
00655         }
00656 
00657         if (!pItem->pClipPath->CopyPathDataFrom(pNewClipPath))
00658             
00659             
00660             ERROR2(FALSE, "Unexpected out-of-space error when copying clipping path");
00661     }
00662 
00663     
00664     return TRUE;
00665 }
00666 
00667 
00668 
00669 
00670 
00671 
00672 
00673 
00674 
00675 
00676 
00677 
00678 
00679 
00680 
00681 
00682 
00683 
00684 BOOL EPSClipContext::ClipPathToRegion(Path *pPathToClip)
00685 {
00686     
00687     if (GetClipRegion() == NULL)
00688         
00689         return TRUE;
00690 
00691     
00692     ERROR2IF(!CacheIsValid, FALSE, 
00693              "Could not get valid clipping path in EPSClipContext::ClipPathToRegion()");
00694 
00695     
00696     
00697     
00698     if (pCachedClipPath->ClipPathToPath(*pPathToClip, pPathToClip, ClippingFlags, 
00699                                         128, 256, 256) == -1)
00700     {
00701         
00702         return FALSE;
00703     }
00704 
00705     
00706     
00707     pPathToClip->InitialiseFlags();
00708 
00709     
00710     return TRUE;
00711 }
00712 
00713 
00714 
00715 
00716 
00717 
00718 
00719 
00720 
00721 
00722 
00723 
00724 
00725 
00726 
00727 Path *EPSClipContext::GetClipRegion()
00728 {
00729     if (!CacheIsValid)
00730     {
00731         
00732         
00733         if (pCachedClipPath == NULL)
00734         {
00735             pCachedClipPath = new Path;
00736 
00737             if (pCachedClipPath == NULL)
00738                 
00739                 return NULL;
00740 
00741             if (!pCachedClipPath->Initialise(12, 12))
00742                 
00743                 return NULL;
00744         }
00745         else
00746         {
00747             
00748             pCachedClipPath->ClearPath();
00749         }
00750 
00751         
00752         
00753         EPSClipContextItem *pItem = (EPSClipContextItem *) GetHead();
00754 
00755         while (pItem != NULL)
00756         {
00757             if (pItem->pClipPath != NULL)
00758             {
00759                 
00760                 if (pCachedClipPath->GetNumCoords() > 0)
00761                 {
00762                     
00763                     if (pItem->pClipPath->ClipPathToPath(*pCachedClipPath, pCachedClipPath, 
00764                                                          2 | CLIPPING_CLIP_WINDING, 
00765                                                          128, 256, 256) == -1)
00766                     {
00767                         
00768                         return FALSE;
00769                     }
00770                 }
00771                 else
00772                 {
00773                     
00774                     if (!pCachedClipPath->MakeSpaceInPath(pItem->pClipPath->GetNumCoords() + 3))
00775                         
00776                         return FALSE;
00777 
00778                     if (!pCachedClipPath->CopyPathDataFrom(pItem->pClipPath))
00779                         
00780                         
00781                         ERROR2(FALSE, "Unexpected out-of-space error when copying clipping path");
00782                 }
00783             }
00784 
00785             
00786             pItem = (EPSClipContextItem *) GetNext(pItem);
00787         }
00788 
00789         
00790         if (pCachedClipPath->GetNumCoords() == 0)
00791         {
00792             
00793             delete pCachedClipPath;
00794             pCachedClipPath = NULL;
00795         }
00796 
00797         
00798         CacheIsValid = TRUE;
00799     }
00800 
00801     
00802     return pCachedClipPath;
00803 }
00804 
00805 
00806 
00807 CommandMap EPSFilter::Commands[] =
00808 {
00809     
00810     { EPSC_l,       _T("l") },
00811     { EPSC_c,       _T("c") },
00812     { EPSC_m,       _T("m") },
00813     { EPSC_L,       _T("L") },
00814     { EPSC_C,       _T("C") },
00815     { EPSC_v,       _T("v") },
00816     { EPSC_V,       _T("V") },
00817     { EPSC_y,       _T("y") },
00818     { EPSC_Y,       _T("Y") },
00819 
00820     
00821     { EPSC_g,       _T("g") },
00822     { EPSC_G,       _T("G") },
00823     { EPSC_k,       _T("k") },
00824     { EPSC_K,       _T("K") },
00825     { EPSC_x,       _T("x") },
00826     { EPSC_X,       _T("X") },
00827     { EPSC_p,       _T("p") },
00828     { EPSC_P,       _T("P") },
00829     
00830     
00831     { EPSC_N,       _T("N") },
00832     { EPSC_n,       _T("n") },
00833     { EPSC_F,       _T("F") },
00834     { EPSC_f,       _T("f") },
00835     { EPSC_S,       _T("S") },
00836     { EPSC_s,       _T("s") },
00837     { EPSC_B,       _T("B") },
00838     { EPSC_b,       _T("b") },
00839     { EPSC__u,      _T("*u") },
00840     { EPSC__U,      _T("*U") },
00841 
00842     
00843     { EPSC_u,       _T("u") },
00844     { EPSC_U,       _T("U") },
00845     
00846     
00847     { EPSC_A,       _T("A") },
00848     { EPSC_d,       _T("d") },
00849     { EPSC_i,       _T("i") },
00850     { EPSC_D,       _T("D") },
00851     { EPSC_j,       _T("j") },
00852     { EPSC_J,       _T("J") },
00853     { EPSC_M,       _T("M") },
00854     { EPSC_w,       _T("w") },
00855 
00856     
00857     { EPSC_ArrayStart,_T("[") },
00858     { EPSC_ArrayEnd,_T("]") },
00859     { EPSC_Slash,   _T("/") },
00860 
00861     
00862     { EPSC_O,       _T("O") },
00863     { EPSC_R,       _T("R") },
00864 
00865     
00866     { EPSC_q,       _T("q") },
00867     { EPSC_Q,       _T("Q") },
00868     { EPSC_H,       _T("H") },
00869     { EPSC_h,       _T("h") },
00870     { EPSC_W,       _T("W") },
00871     
00872     
00873     { EPSC_To,      _T("To") },
00874     { EPSC_TO,      _T("TO") },
00875     { EPSC_Tp,      _T("Tp") },
00876     { EPSC_TP,      _T("TP") },
00877 
00878     
00879     { EPSC_Tm,      _T("Tm") },
00880     { EPSC_Td,      _T("Td") },
00881     { EPSC_T_,      _T("T*") },
00882     { EPSC_TR,      _T("TR") },
00883 
00884     
00885     { EPSC_Tr,      _T("Tr") },
00886     { EPSC_Tf,      _T("Tf") },
00887     { EPSC_Ta,      _T("Ta") },
00888     { EPSC_Tl,      _T("Tl") },
00889     { EPSC_Tt,      _T("Tt") },
00890     { EPSC_TW,      _T("TW") },
00891     { EPSC_Tw,      _T("Tw") },
00892     { EPSC_TC,      _T("TC") },
00893     { EPSC_Tc,      _T("Tc") },
00894     { EPSC_Ts,      _T("Ts") },
00895     { EPSC_Ti,      _T("Ti") },
00896     { EPSC_Tz,      _T("Tz") },
00897     { EPSC_TA,      _T("TA") },
00898     { EPSC_Tq,      _T("Tq") },
00899 
00900     
00901     { EPSC_Tx,      _T("Tx") },
00902     { EPSC_Tj,      _T("Tj") },
00903     { EPSC_TX,      _T("TX") },
00904     { EPSC_Tk,      _T("Tk") },
00905     { EPSC_TK,      _T("TK") },
00906     { EPSC_Tplus,   _T("T+") },
00907     { EPSC_Tminus,  _T("T-") },
00908 
00909     
00910     { EPSC_showpage,_T("showpage") },
00911     { EPSC_end,     _T("end") },
00912     { EPSC_ctx,     _T("ctx") },
00913     { EPSC_ctex,    _T("ctex") },
00914 
00915     { EPSC_Invalid, _T("Invalid") },
00916 
00917     { EPSC_Name,    _T("Name") },
00918     { EPSC_Integer, _T("Integer") },
00919     { EPSC_Double,  _T("Double") },
00920     { EPSC_FixedPoint,_T("FixedPt") },
00921     { EPSC_String,  _T("String") },
00922     { EPSC_Comment, _T("Comment") },
00923     { EPSC_EOL,     _T("EOL") },
00924     { EPSC_EOF,     _T("EOF") }
00925 };
00926 
00927 
00928 RangeList EPSFilter::ImportRange;
00929 
00930 
00931 
00932 
00933 
00934 
00935 
00936 
00937 
00938 
00939 
00940 
00941 
00942 EPSFilter::EPSFilter()
00943 {
00944     ImportMsgID = _R(IDT_IMPORTMSG_AI);
00945     Flags.CanImport = TRUE;
00946     
00947 #ifdef WEBSTER
00948     Flags.CanExport = FALSE;
00949 #else
00950     Flags.CanExport = TRUE;
00951 #endif //WEBSTER
00952     FilterID = FILTERID_AIEPS;
00953 
00954 #ifndef DO_EXPORT
00955     Flags.CanExport = FALSE;
00956 #endif
00957 
00958     EPSFile = NULL;
00959     TokenBuf = NULL;
00960     pColours = NULL;
00961 
00962     ExportDCPtr = NULL;
00963     ExportRegion = NULL;
00964     ExportMsgID = _R(IDT_EXPORTMSG_AI);
00965 
00966     AdjustOrigin = TRUE;
00967     SupportsLayers = TRUE;
00968 
00969     
00970     EPSStart = 0;
00971     EPSEnd = 0;
00972     PreviewStart = 0;
00973     PreviewEnd = 0;
00974 
00975     TextComment[0] = 0;
00976     TextComment[1] = 0;
00977     TextComment[2] = 1;
00978 
00979     
00980     
00981     FontFlags.Bold = FALSE;
00982     FontFlags.Italic = FALSE;
00983 
00984     
00985     
00986     ClassOfFont = FC_TRUETYPE;
00987     
00988     
00989     NewMouldThreshold = MOULD_V1THRESHOLD;
00990 
00991     
00992     EPS_Group   =   FALSE;
00993 
00994     
00995     EndOfEPS    = 0;
00996 
00997     
00998     EPSComments.Add ( _T("%%BeginProlog"),          _T("%%EndProlog"),          TRUE,   0 );
00999     EPSComments.Add ( _T("%%BeginSetup"),           _T("%%EndSetup"),           TRUE,   0 );
01000     EPSComments.Add ( _T("%%BeginDocument"),        _T("%%EndDocument"),        FALSE,  0 );
01001     EPSComments.Add ( _T("%%BeginPageSetup"),       _T("%%EndPageSetup"),       FALSE,  0 );
01002     EPSComments.Add ( _T("%%BeginDefaults"),        _T("%%EndDefaults"),        FALSE,  0 );
01003     EPSComments.Add ( _T("%%BeginEmulation"),       _T("%%EndEmulation"),       FALSE,  0 );
01004     EPSComments.Add ( _T("%%BeginPreview"),         _T("%%EndPreview"),         FALSE,  0 );
01005     EPSComments.Add ( _T("%%BeginFeature"),         _T("%%EndFeature"),         FALSE,  0 );
01006     EPSComments.Add ( _T("%%BeginFile"),            _T("%%EndFile"),            FALSE,  0 );
01007     EPSComments.Add ( _T("%%BeginFont"),            _T("%%EndFont"),            FALSE,  0 );
01008     EPSComments.Add ( _T("%%BeginProcSet"),         _T("%%EndProcSet"),         FALSE,  0 );
01009     EPSComments.Add ( _T("%%BeginResource"),        _T("%%EndResource"),        FALSE,  0 );
01010     EPSComments.Add ( _T("%%BeginCustomColor"),     _T("%%EndCustomColor"),     FALSE,  0 );
01011     EPSComments.Add ( _T("%%BeginProcessColor"),    _T("%%EndProcessColor"),    FALSE,  0 );
01012 }
01013 
01014 
01015 
01016 
01017 
01018 
01019 
01020 
01021 
01022 
01023 
01024 
01025 
01026 
01027 BOOL EPSFilter::Init()
01028 {
01029     
01030     
01031     ENSURE(FALSE, "Base EPSFilter class called! Do not use this!");
01032     return FALSE;
01033 }
01034 
01035 
01036 
01037 
01038 
01039 
01040 
01041 
01042 
01043 
01044 
01045 
01046 
01047 BOOL EPSFilter::InitPrefs()
01048 {
01049 #ifndef STANDALONE
01050 
01051     
01052     Camelot.DeclareSection(_T("EPS"), 5);
01053     Camelot.DeclarePref(NULL, _T("ExportPSType"), &XSEPSExportPSType, 0, 2); 
01054     Camelot.DeclarePref(NULL, _T("ExportDPI"), &XSEPSExportDPI, 10, 600); 
01055     Camelot.DeclarePref(NULL, _T("ExportTextAsCurves"), &XSEPSExportTextAsCurves); 
01056 
01057     
01058     
01059     Camelot.DeclareSection( _T("EPSFontMapping"), 50);
01060 
01061     static const TCHAR FontMappings[][2][30] = 
01062     {
01063         
01064 
01065         
01066         
01067         
01068         { _T("Times-New-Roman"),            _T("Times-Roman")                   },
01069         { _T("Times-New-Roman-Bold"),       _T("Times-Bold")                    },
01070         { _T("Times-New-Roman-Italic"),     _T("Times-Italic")                  },
01071         { _T("Times-New-Roman-BoldItalic"), _T("Times-BoldItalic")              },
01072         { _T("Arial"),                      _T("Helvetica")                     },
01073         { _T("Arial-Bold"),                 _T("Helvetica-Bold")                },
01074         { _T("Arial-Italic"),               _T("Helvetica-Oblique")             },
01075         { _T("Arial-BoldItalic"),           _T("Helvetica-BoldOblique")         },
01076         { _T("Courier-New"),                _T("Courier")                       },
01077         { _T("Courier-New-Bold"),           _T("Courier-Bold")                  },
01078         { _T("Courier-New-Italic"),         _T("Courier-Oblique")               },
01079         { _T("Courier-New-BoldItalic"),     _T("Courier-BoldOblique")           },
01080         { _T("Michael"),                    _T("Palatino-Roman")                },
01081         { _T("Michael-Bold"),               _T("Palatino-Bold")                 },
01082         { _T("Michael-Italic"),             _T("Palatino-Italic")               },
01083         { _T("Michael-BoldItalic"),         _T("Palatino-BoldItalic")           },
01084         { _T("NewSchbook"),                 _T("NewCenturySchlbk-Roman")        },
01085         { _T("NewSchbook-Bold"),            _T("NewCenturySchlbk-Bold")         },
01086         { _T("NewSchbook-Italic"),          _T("NewCenturySchlbk-Italic")       },
01087         { _T("NewSchbook-BoldItalic"),      _T("NewCenturySchlbk-BoldItalic")   },
01088         { _T("ZapfDingbatsBT"),             _T("ZapfDingbats")                  },
01089         { _T("Symbol"),                     _T("Symbol")                        },
01090 
01091 #if 0
01092         
01093         { _T(""),                           _T("AvantGarde-Book")               },
01094         { _T(""),                           _T("AvantGarde-Demi")               },
01095         { _T(""),                           _T("AvantGarde-BookOblique")        },
01096         { _T(""),                           _T("AvantGarde-DemiOblique")        },
01097         { _T(""),                           _T("Bookman-Light")                 },
01098         { _T(""),                           _T("Bookman-Demi")                  },
01099         { _T(""),                           _T("Bookman-LightItalic")           },
01100         { _T(""),                           _T("Bookman-DemiItalic")            },
01101         { _T(""),                           _T("ZapfChancery-MediumItalic")     },
01102 #endif
01103 
01104         
01105         { _T(""),                           _T("")                              }
01106     };
01107 
01108     
01109     INT32 i = 0;
01110     while (camStrclen(FontMappings[i][0]) > 0)
01111     {
01112         Camelot.SetPrefDirect( _T("EPSFontMapping"), 
01113                               (TCHAR *) &FontMappings[i][0][0], 
01114                               &FontMappings[i][1][0]); 
01115         i++;
01116     }
01117 
01118 #endif
01119 
01120     
01121     return TRUE;
01122 }
01123 
01124 
01125 const INT32 TokenBufSize = 256;
01126 
01127 
01128 
01129 
01130 
01131 
01132 
01133 
01134 
01135 
01136 
01137 
01138 
01139 
01140 
01141 
01142 BOOL EPSFilter::PrepareToImport()
01143 {
01144     if (!SetUpCurrentAttrs())
01145         return FALSE;
01146 
01147     
01148     if (!ImportInfo.pOp->DoStartSelOp(FALSE))
01149         return FALSE;
01150 
01151     
01152     if (EPSFile == NULL)
01153         return FALSE;
01154 
01155     
01156     EPSFile->InitLexer();
01157     EPSFile->SetDelimiters("()<>[]{}/%");
01158     EPSFile->SetCommentMarker('%');
01159     EPSFile->SetStringDelimiters("()");
01160 
01161     TokenBuf = EPSFile->GetTokenBuf();
01162     Token = EPSC_Invalid;
01163 
01164     EPSFlags.ComplexPath = 0;
01165     EPSFlags.StrokeComplexPath = FALSE;
01166     EPSFlags.NoAttributes = FALSE;
01167     EPSFlags.EPSErrorEncountered = FALSE;
01168     EPSFlags.AddToNewLayer = FALSE;
01169     EPSFlags.PathIsHidden = FALSE;
01170 
01171     ThePathType = PATH_NORMAL;
01172 
01173 
01174     
01175     
01176     
01177 #ifndef WEBSTER
01178     
01179     
01180     
01181     if (SupportsLayers && TheDocument->IsImporting())
01182     {
01183         
01184         
01185         
01186         ERROR2IF(ImportInfo.pSpread == NULL,FALSE,"EPSFilter::PrepareToImport No spread");
01187         Layer * pFrame = ImportInfo.pSpread->FindFirstFrameLayer();
01188         if (pFrame == NULL)
01189             UseLayers = TRUE;   
01190         else
01191             UseLayers = FALSE;  
01192     }
01193     else
01194         UseLayers = SupportsLayers && Filter::ImportWithLayers;
01195 #else
01196     
01197     if ( SupportsLayers &&
01198         (!TheDocument->IsImporting() && Filter::OpenWithLayers) ||
01199         (TheDocument->IsImporting() && Filter::ImportWithLayers)
01200         )
01201         UseLayers = TRUE;
01202     else
01203         UseLayers = FALSE;
01204 #endif // WEBSTER
01205 
01206     
01207     pPath = NULL;
01208     pInkPath = NULL;
01209 
01210     
01211     ImportRange.DeleteAll();
01212     pFirstNodeInRange = NULL;
01213     pLastNodeInRange  = NULL;
01214 
01215     
01216     GroupNesting = 0;
01217     MaskedGroupNesting = 0;
01218 
01219     
01220     InvalidPathFound = FALSE;
01221 
01222     
01223     TheDocument->EPSStartImport(this);
01224     DocComponent *pComponent = TheDocument->EnumerateDocComponents(NULL);
01225 
01226     while (pComponent != NULL)
01227     {
01228         
01229         pComponent->EPSStartImport(this);
01230 
01231         
01232         if (pComponent->GetRuntimeClass() == CC_RUNTIME_CLASS(ColourListComponent))
01233             pColours = (ColourListComponent *) pComponent;
01234 
01235         
01236         pComponent = TheDocument->EnumerateDocComponents(pComponent);
01237     }
01238         
01239     ENSURE(pColours != NULL, "Didn't find a colour list component!");
01240     if (pColours == NULL)
01241         
01242         return FALSE;
01243 
01244     
01245     return TRUE;
01246 }
01247 
01248 
01249 
01250 
01251 
01252 
01253 
01254 
01255 
01256 
01257 
01258 
01259 
01260 
01261 
01262 
01263 
01264 void EPSFilter::CleanUpAfterImport(BOOL Successful)
01265 {
01266     DeleteCurrentAttrs();
01267 
01268     
01269     EPSFile->DeinitLexer();
01270     EPSFile = NULL;
01271     TokenBuf = NULL;
01272 
01273     
01274     TRACEUSER( "Ben", _T("Entries on GraphicStateStack = %d\n"), GraphicStateStack.GetCount());
01275     GraphicStateStack.DeleteAll();
01276 
01277     
01278     pColours = NULL;
01279 
01280     
01281     TheDocument->EPSEndImport(this, Successful);
01282     DocComponent *pComponent = TheDocument->EnumerateDocComponents(NULL);
01283 
01284     while (pComponent != NULL)
01285     {
01286         
01287         pComponent->EPSEndImport(this, Successful);
01288 
01289         
01290         pComponent = TheDocument->EnumerateDocComponents(pComponent);
01291     }
01292 
01293     
01294     if (Successful) 
01295     {
01296         LayerSGallery::MakeTopLayerActive(ImportInfo.pSpread);
01297         BROADCAST_TO_ALL(SpreadMsg(ImportInfo.pSpread,SpreadMsg::LAYERCHANGES));
01298     }
01299 
01300     
01301     
01302     
01303     if (0 && InvalidPathFound)
01304         InformWarning(_R(IDT_IMPORT_BAD_PATH_FOUND));
01305 
01306     
01307     ImportRange.DeleteAll();
01308 
01309     TheDocument->PostImport();
01310 }
01311 
01312 
01313 
01314 
01315 
01316 
01317 
01318 
01319 
01320 
01321 
01322 
01323 
01324 
01325 
01326 
01327 
01328 
01329 
01330 
01331 
01332 INT32 EPSFilter::HowCompatible(PathName& Filename, ADDR HeaderStart, 
01333                              UINT32 HeaderSize, UINT32 FileSize)
01334 {
01335 PORTNOTE("byteorder", "TODO: Check byte ordering")
01336     return EPSHeaderIsOk(HeaderStart, HeaderSize);
01337 }
01338 
01339 
01340 
01341 
01342 
01343 
01344 
01345 
01346 
01347 
01348 
01349 
01350 
01351 
01352 
01353 
01354 
01355 
01356 
01357 
01358 
01359 
01360 
01361 BOOL EPSFilter::IsDefaultDocRequired(const TCHAR* pcszPathName)
01362 {
01363     return TRUE;
01364 }   
01365 
01366 
01367 
01368 
01369 
01370 
01371 
01372 
01373 
01374 
01375 
01376 
01377 
01378 
01379 
01380 
01381 
01382 
01383 INT32 EPSFilter::EPSHeaderIsOk(ADDR pFileHeader, UINT32 HeaderSize)
01384 {
01385     
01386 
01387     
01388     if (strncmp((char *) pFileHeader, "%!PS-Adobe", 10) != 0)
01389     {
01390         
01391         return 0;
01392     }
01393 
01394     
01395     std::istringstream HeaderFile((char *) pFileHeader, ios_base::in );
01396     char Buffer[200];
01397 
01398     UINT32 Lines = 0;
01399     while ((Lines < 20) && !HeaderFile.eof())
01400     {
01401         HeaderFile.getline(Buffer, 200);
01402         Lines++;
01403 
01404         
01405         
01406         if (strncmp(Buffer, "%%Creator: Adobe Illustrator", 28) == 0)
01407             
01408             return 8;
01409 
01410         if (strncmp(Buffer, "%%Creator:", 10) == 0)
01411         {
01412             
01413             if (strstr(Buffer, "Illustrator") != NULL)
01414                 return 9;
01415             else
01416                 break;
01417         }
01418 
01419         
01420         
01421         if (strncmp(Buffer, "%%Compression:", 14)==0)
01422             break;
01423     }
01424 
01425     
01426     
01427     return 5;
01428 }
01429 
01430 
01431 
01432 
01433 
01434 
01435 
01436 
01437 
01438 
01439 
01440 
01441 
01442 
01443 
01444 
01445 
01446 
01447 
01448 
01449 
01450 
01451 
01452 
01453 
01454 
01455 
01456 
01457 
01458 
01459 
01460 
01461 
01462 
01463 
01464 BOOL EPSFilter::DoImport(SelOperation *Op, CCLexFile* pFile, 
01465                          Document* DestDoc, BOOL AutoChosen, ImportPosition* Pos,
01466                          KernelBitmap** ppImportedBitmap, DocCoord* pPosTranslate, String_256* URL)
01467 {
01468     
01469     TheDocument = DestDoc;
01470 
01471     
01472     ImportInfo.pOp = Op;
01473     ImportInfo.Pos = Pos;
01474     ImportInfo.pSpread = NULL;
01475 
01476     
01477     EPSFile = pFile;
01478 
01479     
01480     if ( pFile->IS_KIND_OF ( CCStreamFile ) )
01481     {
01482         
01483         
01484         
01485         char Buf[4];
01486         
01487         
01488         memset(Buf, 0, 4);
01489 
01490         
01491         pFile->read(Buf, 4);
01492 
01493         
01494         if ((Buf[0]=='\xC5') && (Buf[1]=='\xD0') && (Buf[2]=='\xD3') && (Buf[3]=='\xC6'))
01495         {
01496             
01497             FilePos StartOfEPS  = 0;
01498             EndOfEPS            = 0;
01499 
01500             pFile->read(&StartOfEPS, 4);
01501             TRACEUSER( "Rik", _T("EPS Starts at %ld\n"), StartOfEPS);
01502 
01503             
01504             pFile->read ( &EndOfEPS, 4 );
01505 
01506             EndOfEPS += StartOfEPS;
01507 
01508             
01509             pFile->seekIn(StartOfEPS, ios::beg);
01510         }
01511         else
01512         {
01513             
01514             pFile->seekIn(0, ios::beg);
01515 
01516             EndOfEPS = pFile->Size ();
01517         }
01518     }
01519 
01520     
01521     Spread *pSpread;
01522 
01523     if (Pos == NULL)
01524     {
01525         
01526         pSpread = GetFirstSpread(DestDoc);
01527     }
01528     else
01529     {
01530         
01531         pSpread = Pos->pSpread;
01532     }
01533 
01534     
01535     ImportInfo.pSpread = pSpread;
01536 
01537     
01538     if (!PrepareToImport())
01539     {
01540         
01541         CleanUpAfterImport(FALSE);
01542         return FALSE;
01543     }
01544 
01545     pLayer = pSpread->FindActiveLayer();
01546 
01547     
01548     SpreadRect = pSpread->GetPasteboardRect();
01549     pSpread->DocCoordToSpreadCoord(&SpreadRect);
01550 
01551     
01552     
01553     
01554 
01555     
01556     
01557     NodeGroup *pEPSGroup = NULL;
01558     if (UseLayers)
01559     {
01560         EPSFlags.AddToNewLayer = FALSE;
01561         pNode = (Node *) pLayer;
01562     }
01563     else
01564     {
01565         pEPSGroup = new NodeGroup;
01566         ERRORIF(pEPSGroup == NULL, _R(IDT_EPS_NOMEMORY), FALSE);
01567         pNode = pEPSGroup;
01568     }
01569         
01570     
01571     Stack.SetCoordScaleFactor(EPSScaleFactor);
01572 
01573     if (Pos == NULL)
01574     {   
01575         
01576         Page *pPage = pSpread->FindFirstPageInSpread(); 
01577         ERROR3IF(pPage == NULL, "Spread has no pages"); 
01578 
01579         
01580         if (pPage)
01581         {
01582             DocRect PageRect = pPage->GetPageRect();
01583             Stack.SetCoordOrigin(PageRect.lo);
01584         }
01585     }
01586     else
01587     {
01588         
01589         Stack.SetCoordOrigin(Pos->Position);
01590     }
01591     
01592     
01593     EPSFlags.ComplexPath = 0;
01594 
01595     
01596     
01597 
01598     
01599     INT32 filesize = EPSFile->Size();
01600     if (filesize == -1)
01601     {
01602         TRACEUSER("JustinF", _T("Couldn't take size of the EPS file\n"));
01603         return FALSE;
01604     }
01605 
01606     
01607     LastProgressUpdate = 0;
01608 
01609     
01610     
01611     String_64 ImportMessage = GetImportProgressString(EPSFile, GetImportMsgID());
01612     BeginSlowJob(filesize, TRUE, &ImportMessage);
01613 
01614     
01615     do
01616     {
01617         GetToken();
01618     }
01619     while (HandleToken() && (!EPSFlags.EPSErrorEncountered) && (!EPSFile->eof()));
01620 
01621     
01622     BOOL Ok = (GroupNesting == 0) && 
01623               (MaskedGroupNesting == 0) && 
01624               (EPSFile->eof() && !EPSFile->fail());
01625 
01626     #if _DEBUG
01627     Stack.Dump(this);
01628     #endif
01629     
01630     
01631     
01632     if (!Ok)
01633     {
01634         
01635         if (UseLayers)
01636         {
01637             
01638             if (pNode!=NULL)
01639             {
01640                 
01641                 
01642                 
01643 
01644                 
01645                 
01646                 pNode = NULL;
01647             }
01648         }
01649         else
01650         {
01651             
01652             if (pEPSGroup!=NULL)
01653             {
01654                 pEPSGroup->CascadeDelete();
01655                 
01656                 pEPSGroup = NULL;
01657             }
01658         }
01659 
01660         
01661         
01662         
01663         
01664         CleanUpAfterImport(FALSE);
01665 
01666         
01667         TheDocument = NULL;
01668 
01669         Op->FailAndExecute();
01670                 
01671         
01672         EndSlowJob();
01673 #if !defined(EXCLUDE_FROM_RALPH)
01674         DialogBarOp::UpdateStateOfAllBars();
01675 #endif
01676         return FALSE;
01677     }
01678 
01679     
01680     BOOL Success = AttachAllNodes();
01681 
01682     
01683     
01684     
01685     
01686     
01687     
01688     
01689     
01690 
01691     
01692 
01693         
01694         
01695         
01696         
01697 
01698 
01699     
01700     CleanUpAfterImport(TRUE);
01701 
01702     
01703     TheDocument = NULL;
01704 
01705     
01706     EndSlowJob();
01707 #if !defined(EXCLUDE_FROM_RALPH)
01708     DialogBarOp::UpdateStateOfAllBars();
01709 #endif
01710     return Success;
01711 }
01712 
01713 
01714 
01715 
01716 
01717 
01718 
01719 
01720 
01721 
01722 
01723 
01724 
01725 
01726 
01727 
01728 
01729 BOOL EPSFilter::HandleToken()
01730 {
01731 
01732 
01733     
01734     if ((Token != EPSC_EOL) && (Token != EPSC_EOF))
01735     {
01736         
01737         
01738         if (!ProcessToken())
01739             return FALSE;
01740     }
01741     else
01742     {
01743         
01744         
01745         INT32 CharsRead = EPSFile->GetCharsRead();
01746 
01747         if (CharsRead > (LastProgressUpdate + 2048))
01748         {
01749             if (!ContinueSlowJob(CharsRead))
01750             {
01751                 
01752                 ERROR(_R(IDT_IMPORT_USERABORT), FALSE);
01753             }
01754 
01755             
01756             LastProgressUpdate = CharsRead;
01757         }
01758     }
01759 
01760     
01761     return TRUE;
01762 }
01763 
01764 
01765 
01766 
01767 
01768 
01769 
01770 
01771 
01772 
01773 
01774 
01775 
01776 
01777 
01778 
01779 
01780 
01781 void EPSFilter::DecodeToken()
01782 {
01783     
01784     
01785     
01786     ENSURE(camStrcmp(TokenBuf,_T("}bd")) != 0, "Found a }bd token!");
01787         
01788     
01789     if (Token == EPSC_Comment)
01790     {
01791         LookUpToken();
01792         return;
01793     }
01794 
01795     
01796     INT32 i = 0;
01797 
01798     
01799     BOOL FoundDot = FALSE;
01800 
01801     
01802     
01803     
01804     BOOL Number = TRUE;
01805 
01806     
01807     
01808     
01809     BOOL FoundFloatingPoint = FALSE;
01810     INT32 Precision = 0;
01811 
01812     
01813 
01814     while (TokenBuf[i] != 0)
01815     {
01816         TCHAR c = TokenBuf[i];
01817         
01818         if (c == '.')
01819         {
01820             if (FoundDot)
01821             {
01822                 
01823                 Number = FALSE;
01824                 break;
01825             }
01826             else
01827             {
01828                 
01829                 FoundDot = TRUE;
01830             }
01831         }
01832         else
01833         {
01834             if (FoundDot)
01835             {
01836                 
01837                 if (isdigit(c))
01838                 {
01839                     Precision++;
01840                     if (Precision > 3)
01841                         FoundFloatingPoint = TRUE;
01842                 }
01843                 else
01844                 {
01845                     
01846                     if ((c == 'e') || (c == 'E'))
01847                     {
01848                         
01849                         FoundFloatingPoint = TRUE;
01850                     }
01851                     else if ((c != '-') && (c != '+'))
01852                     {
01853                         
01854                         Number = FALSE;
01855                         break;
01856                     }
01857                 }
01858             }
01859             else if (!isdigit(c) && (c != '-') && (c != '+'))
01860             {
01861                 
01862                 Number = FALSE;
01863                 break;
01864             }
01865         }
01866         
01867         i++;
01868     }
01869     
01870     if (Number)
01871     {
01872         
01873         if (FoundFloatingPoint)
01874         {
01875             
01876             Token = EPSC_Double;
01877             TokenData.Double=0.0;
01878             camSscanf(TokenBuf,_T("%lf"),&TokenData.Double);
01879         }
01880         else if (FoundDot)
01881         {
01882             
01883             Token = EPSC_FixedPoint;
01884             TokenData.FixedPoint.FromAscii(TokenBuf);
01885         }
01886         else
01887         {
01888             
01889             Token = EPSC_Integer;
01890             TokenData.Long=0;
01891             camSscanf(TokenBuf,_T("%d"),&TokenData.Long);
01892         }
01893 
01894         return; 
01895     }
01896     
01897     
01898     LookUpToken();
01899 }
01900 
01901 
01902 
01903 
01904 
01905 
01906 
01907 
01908 
01909 
01910 
01911 
01912 
01913 
01914 void EPSFilter::LookUpToken()
01915 {
01916     
01917     if (Token == EPSC_Comment)
01918         return;
01919 
01920     
01921     
01922     INT32 i = 0;
01923     while (Commands[i].Cmd != EPSC_Invalid)
01924     {
01925         if (camStrcmp(TokenBuf, Commands[i].CmdStr) == 0)
01926         {
01927             
01928             Token = Commands[i].Cmd;
01929             return;
01930         }
01931         
01932         i++;
01933     }
01934 
01935     
01936     Token = EPSC_Name;
01937 }
01938 
01939 
01940 
01941 
01942 
01943 
01944 
01945 
01946 
01947 
01948 
01949 
01950 
01951 
01952 
01953 
01954 
01955 BOOL EPSFilter::GetToken()
01956 {
01957     
01958     Token = EPSC_Invalid;
01959 
01960     
01961     if ( !EPSFile->IsCompressionSet () && EPSFile->tell () > EndOfEPS )
01962     {
01963         
01964         EPSFile->seekIn ( 0, ios::end );
01965     }
01966 
01967     if (!EPSFile->GetToken())
01968         return FALSE;
01969 
01970     
01971     switch (EPSFile->GetTokenType())
01972     {
01973         case TOKEN_EOF:
01974             return TRUE; 
01975 
01976         case TOKEN_EOL:
01977             Token = EPSC_EOL;
01978             return TRUE;
01979 
01980         case TOKEN_STRING:
01981             Token = EPSC_String;
01982             return TRUE;
01983 
01984         case TOKEN_COMMENT:
01985             Token = EPSC_Comment;
01986             break; 
01987 
01988         default:
01989             break;
01990     }
01991 
01992     ENSURE((EPSFile->GetTokenType() == TOKEN_NORMAL) || (EPSFile->GetTokenType() == TOKEN_COMMENT), 
01993            "Bad token type in EPSFilter::GetToken()");
01994     
01995     
01996     DecodeToken();
01997 
01998     
01999     return TRUE;
02000 }
02001 
02002 
02003 
02004 
02005 
02006 
02007 
02008 
02009 
02010 
02011 
02012 
02013 
02014 
02015 
02016 
02017 
02018 
02019 
02020 BOOL EPSFilter::GetLineToken()
02021 {
02022     Token = EPSC_Invalid;
02023 
02024     
02025     if ( !EPSFile->IsCompressionSet () && EPSFile->tell () > EndOfEPS )
02026     {
02027         
02028         EPSFile->seekIn ( 0, ios::end );
02029     }
02030 
02031     if (!EPSFile->GetLineToken())
02032         return FALSE;
02033 
02034     
02035     switch (EPSFile->GetTokenType())
02036     {
02037         case TOKEN_EOF:
02038             return TRUE; 
02039 
02040         case TOKEN_EOL:
02041             Token = EPSC_EOL;
02042             return TRUE;
02043 
02044         case TOKEN_STRING:
02045             Token = EPSC_String;
02046             return TRUE;
02047 
02048         case TOKEN_COMMENT:
02049             
02050             
02051             Token = EPSC_Comment;
02052             DecodeToken();
02053             return TRUE;
02054 
02055         default:
02056             break;
02057     }
02058 
02059     ENSURE((EPSFile->GetTokenType() == TOKEN_NORMAL) || 
02060            (EPSFile->GetTokenType() == TOKEN_LINE), 
02061            "Bad token type in EPSFilter::GetLineToken()");
02062     
02063     
02064     DecodeToken();
02065 
02066     
02067     return TRUE;
02068 }
02069 
02070 
02071 
02072 
02073 
02074 
02075 
02076 
02077 
02078 
02079 
02080 
02081 
02082 
02083 
02084 
02085 
02086 
02087 
02088 BOOL EPSFilter::AddNewNode(Node *pNewNode)
02089 {
02090     if ((EPSFlags.AddToNewLayer) || (!UseLayers))
02091     {
02092         
02093         pNewNode->AttachNode(pNode, LASTCHILD);
02094 
02095         if (pNewNode->IsBounded())
02096         {
02097             
02098             NodeRenderableBounded *pBounded = (NodeRenderableBounded *) pNewNode;
02099             pBounded->InvalidateBoundingRect();
02100         }
02101     }
02102     else
02103     {
02104         
02105         
02106         return InsertNewNode(pNewNode);
02107     }
02108 
02109     
02110     return TRUE;
02111 }
02112 
02113 
02114 
02115 
02116 
02117 
02118 
02119 
02120 
02121 
02122 
02123 
02124 
02125 
02126 
02127 
02128 
02129 
02130 
02131 BOOL EPSFilter::InsertNewNode(Node *pNewNode)
02132 {
02133     
02134     ENSURE(pNewNode->IS_KIND_OF(NodeRenderableBounded), 
02135            "Trying to add a non-bounded node while importing!");
02136     NodeRenderableBounded *pNodeBounded = (NodeRenderableBounded *) pNewNode;
02137     
02138     
02139     if (pNodeBounded == (NodeRenderableBounded *) pLayer)
02140     {
02141         
02142         ENSURE(pNode == ImportInfo.pSpread, "Not adding layer to correct spread!");
02143     }
02144 
02145     
02146     BOOL Success = FALSE;
02147     BOOL ReadyToInsert = TRUE;
02148 
02149     
02150     
02151     if (!pNewNode->IS_KIND_OF(Layer))
02152     {
02153         
02154         if (!MakeSureLayerExists(TheDocument))
02155         {
02156             
02157             ReadyToInsert = FALSE;
02158         }
02159         else
02160         {
02161             
02162             
02163             if (pNode==NULL)
02164             {
02165                 
02166                 Spread* pSpread = ImportInfo.pSpread;
02167                 if (pSpread!=NULL)
02168                     pNode = (Node*) pSpread->FindActiveLayer();
02169             }
02170         }
02171     }
02172 
02173     
02174     if (ReadyToInsert)
02175     {
02176         
02177         
02178         if (UseLayers)
02179         {
02180             
02181             Success = ImportInfo.pOp->DoInsertNewNode(pNodeBounded, pNode, LASTCHILD,
02182                                                       FALSE, FALSE, FALSE);
02183 
02184             
02185             if (pFirstNodeInRange == NULL)
02186                 pFirstNodeInRange = pNodeBounded;
02187 
02188             
02189             
02190             
02191             if (pNodeBounded->FindParent()->IS_KIND_OF(Layer))
02192                 pLastNodeInRange = pNodeBounded;
02193         }
02194         else
02195         {
02196             
02197             
02198             
02199             Success = ImportInfo.pOp->DoInsertNewNode(pNodeBounded, ImportInfo.pSpread,
02200                                                       FALSE);
02201         }
02202     }
02203 
02204     
02205     
02206     if ((!Success) || (!pNewNode->OptimiseAttributes()))
02207     {
02208         
02209         pNewNode->CascadeDelete();
02210         delete pNewNode;
02211 
02212         
02213         ImportInfo.pOp->FailAndExecute(); 
02214         return FALSE; 
02215     }
02216 
02217     
02218     return TRUE;
02219 }
02220 
02221 
02222 
02223 
02224 
02225 
02226 
02227 
02228 
02229 
02230 
02231 
02232 
02233 
02234 
02235 
02236 
02237 BOOL EPSFilter::AttachAllNodes()
02238 {
02239     BOOL Success = TRUE;
02240     NodeGroup *pGroup=NULL;
02241 
02242     if (UseLayers)
02243     {
02244         
02245         if (EPSFlags.AddToNewLayer)
02246         {
02247             
02248 
02249             
02250             EPSFlags.AddToNewLayer = FALSE;
02251             Node *pLayer = pNode;
02252             pNode = ImportInfo.pSpread;
02253 
02254             
02255             Success = AddNewNode(pLayer);
02256 
02257             
02258             if (Success)
02259                 ImportRange.AddRange(pLayer, pLayer);
02260         }
02261         else if (pFirstNodeInRange != NULL)
02262         {
02263             
02264             
02265             ImportRange.AddRange(pFirstNodeInRange, pLastNodeInRange);
02266             pFirstNodeInRange = NULL;
02267             pLastNodeInRange  = NULL;
02268         }
02269     }
02270     else
02271     {
02272         
02273         pGroup = (NodeGroup *) pNode;
02274         pNode = (Node *) pLayer;
02275 
02276         Success = InsertNewNode(pGroup);
02277     }
02278 
02279     if (!Success)
02280         return FALSE;
02281 
02282     
02283     DocRect BoundsRect;
02284 
02285     if (UseLayers)
02286         BoundsRect = ImportRange.GetBoundingRect();
02287     else
02288         BoundsRect = pGroup->GetBoundingRect(TRUE);
02289 
02290     
02291     Coord Offset;
02292 
02293     if (GetDragAndDropTranslation(ImportInfo.Pos, BoundsRect, &Offset))
02294     {
02295         Trans2DMatrix Xlate(Offset.x, Offset.y);
02296 
02297         if (UseLayers)
02298         {
02299             
02300             ImportRange.Transform(Xlate);
02301 
02302             
02303             BoundsRect.Translate(Offset.x, Offset.y);
02304         }
02305         else
02306         {
02307             
02308             pGroup->Transform(Xlate);
02309         }
02310     }
02311 
02312     
02313 
02314     if (UseLayers)
02315     {
02316         
02317         Success = ImportInfo.pOp->DoInvalidateRegion(ImportInfo.pSpread, BoundsRect);
02318     }
02319     else
02320     {
02321         
02322         
02323         Success = ImportInfo.pOp->DoInvalidateNodeRegion(pGroup, TRUE, FALSE);
02324     }
02325 
02326     if (!Success)
02327     {
02328         
02329         return FALSE;
02330     }
02331 
02332     
02333     TheDocument->ResetInsertionPosition();
02334 
02335     return Success;
02336 }
02337 
02338 
02339 
02340 
02341 
02342 
02343 
02344 
02345 
02346 
02347 
02348 
02349 
02350 
02351 
02352 
02353 
02354 
02355 
02356 BOOL EPSFilter::UseLayer ( String_256& LayerName,
02357                            BOOL GuideLayer )
02358 {
02359     
02360     if ( AddLayer ( LayerName, GuideLayer ) != NULL )
02361     {
02362         
02363         return TRUE;
02364     }
02365     else
02366     {
02367         
02368         return FALSE;
02369     }
02370 }
02371 
02372 
02373 
02374 
02375 
02376 
02377 
02378 
02379 
02380 
02381 
02382 
02383 
02384 
02385 
02386 
02387 
02388 
02389 Layer* EPSFilter::AddLayer ( String_256& LayerName,
02390                              BOOL GuideLayer )
02391 {
02392     
02393     if (EPSFlags.AddToNewLayer)
02394     {
02395         
02396         EPSFlags.AddToNewLayer = FALSE;
02397         pNode = ImportInfo.pSpread;
02398         if (!InsertNewNode((Node *) pLayer))
02399             return FALSE;
02400 
02401         
02402         ImportRange.AddRange(pLayer, pLayer);
02403     }
02404     else if (pFirstNodeInRange != NULL)
02405     {
02406         
02407         
02408         ImportRange.AddRange(pFirstNodeInRange, pLastNodeInRange);
02409         pFirstNodeInRange = NULL;
02410         pLastNodeInRange  = NULL;
02411     }
02412 
02413     
02414     String_256 NewLayerName = LayerName;
02415     MakeLayerNameUnique(NewLayerName, ImportInfo.pSpread);
02416 
02417     
02418     if (GuideLayer)
02419     {
02420 #if !defined(EXCLUDE_FROM_RALPH)
02421 
02422 
02423         pLayer = Layer::CreateGuideLayer();
02424 #else
02425         ERROR3("EPSFilter::UseLayer GuideLayer == TRUE - whoop whoop ! BAD !");
02426 #endif
02427     }
02428     else
02429         pLayer = new Layer;
02430 
02431     ERRORIF(pLayer == NULL, _R(IDT_EPS_NOMEMORY), FALSE);
02432     pLayer->SetLayerID(NewLayerName);
02433     EPSFlags.AddToNewLayer = TRUE;
02434 
02435     
02436     pNode = (Node *) pLayer;
02437 
02438     
02439     return pLayer;
02440 }
02441 
02442 
02443 
02444 
02445 
02446 
02447 
02448 
02449 
02450 
02451 
02452 
02453 
02454 
02455 
02456 
02457 
02458 
02459 
02460 
02461 
02462 
02463 
02464 
02465 
02466 
02467 
02468 void EPSFilter::MakeLayerNameUnique(String_256& LayerName, Spread *pSpread)
02469 {
02470     BOOL TriedImported = FALSE;
02471     UINT32 Number = 2;
02472     String_256 NewName = LayerName;
02473     
02474     Layer *pFirstLayer = pSpread->FindFirstLayer();
02475     Layer *pLayer = pFirstLayer;
02476 
02477     while (pLayer != NULL)
02478     {
02479         
02480         LayerStatus Status = pLayer->GetLayerStatus();
02481 
02482         
02483         if (Status.StringLayerID == NewName)
02484         {
02485             
02486             if (TriedImported)
02487             {
02488                 
02489                 TCHAR NumBuf[10];
02490                 camSprintf(NumBuf, TEXT(" %d"), Number);
02491                 NewName = LayerName;
02492                 NewName += NumBuf;
02493 
02494                 
02495                 Number++;
02496             }
02497             else
02498             {
02499                 
02500                 NewName.Load(_R(IDS_K_EPSFILTER_IMPORTED));
02501                 NewName += LayerName;
02502                 TriedImported = TRUE;
02503             }
02504 
02505             
02506             pLayer = pFirstLayer;
02507         }
02508         else
02509         {
02510             
02511             pLayer = pLayer->FindNextLayer();
02512         }
02513     }
02514 
02515     
02516     LayerName = NewName;
02517 }
02518 
02519 
02520 
02521 
02522 
02523 
02524 
02525 
02526 
02527 
02528 
02529 
02530 
02531 
02532 
02533 
02534 
02535 
02536 
02537 BOOL EPSFilter::StartGroup()
02538 {
02539     
02540     NodeGroup *pGroup = new NodeGroup;
02541     ERRORIF(pGroup == NULL, _R(IDT_EPS_NOMEMORY), FALSE);
02542 
02543     
02544     if (!AddNewNode(pGroup))
02545         return FALSE;
02546 
02547     
02548     pNode = pGroup;
02549 
02550     
02551     return TRUE;
02552 }
02553 
02554 
02555 
02556 
02557 
02558 
02559 
02560 
02561 
02562 
02563 
02564 
02565 
02566 
02567 
02568 
02569 
02570 
02571 
02572 
02573 
02574 
02575 BOOL EPSFilter::EndGroup(BOOL Masked)
02576 {
02577     
02578     ENSURE(pNode->IsKindOf(CC_RUNTIME_CLASS(NodeGroup)), "No group in EPSFilter::EndGroup");
02579     
02580     
02581 
02582     
02583     if(Masked)
02584     {
02585         
02586         if(!MaskedGroupEnding())
02587             return FALSE;           
02588     }
02589 
02590     
02591     Node *pGroup = pNode;
02592 
02593     
02594     pNode = pNode->FindParent();
02595     ENSURE(pNode != NULL, "Group has no parent in ProcessGroup()");
02596 
02597     
02598     Node *pChild = pGroup->FindFirstChild();
02599     if (pChild == NULL)
02600     {
02601         
02602         if(pFirstNodeInRange == pGroup)
02603             pFirstNodeInRange = 0;
02604 
02605         
02606         
02607         
02608         
02609         
02610         if (!ImportInfo.pOp->DoHideNode(pGroup, TRUE))
02611             return FALSE;
02612     } else {
02613         
02614         if(!ValidateGroup(pGroup))
02615             return FALSE;
02616     }
02617 
02618     
02619     if (Masked)
02620     {
02621         MaskedGroupNesting--;
02622 
02623         if (!ClipRegion.RestoreContext())
02624             
02625             return FALSE;
02626     }
02627     else
02628         GroupNesting--;
02629 
02630     return TRUE;
02631 }
02632 
02633 
02634 
02635 
02636 
02637 
02638 
02639 
02640 
02641 
02642 
02643 
02644 
02645 
02646 
02647 
02648 BOOL EPSFilter::ValidateGroup(Node *pGroup)
02649 {
02650     return TRUE;
02651 }
02652 
02653 
02654 
02655 
02656 
02657 
02658 
02659 
02660 
02661 
02662 
02663 
02664 
02665 
02666 
02667 
02668 BOOL EPSFilter::MaskedGroupEnding()
02669 {
02670     EPS_Group = FALSE;
02671     return TRUE;
02672 }
02673 
02674 
02675 
02676 
02677 
02678 
02679 
02680 
02681 
02682 
02683 
02684 
02685 
02686 
02687 
02688 
02689 
02690 
02691 
02692 
02693 
02694 
02695 BOOL EPSFilter::AddAttributes(NodeRenderableBounded *pNode, BOOL Stroked, BOOL Filled)
02696 {
02697     DocColour OldCol;
02698 
02699     
02700     if (!Stroked)
02701     {
02702         StrokeColourAttribute *pAttr = 
02703             (StrokeColourAttribute *) CurrentAttrs[ATTR_STROKECOLOUR].pAttr;
02704 
02705         OldCol = pAttr->Colour;
02706         DocColour trans(COLOUR_TRANS);
02707         if (!SetLineColour(trans))
02708             return FALSE;
02709     }
02710 
02711     
02712     if (!Filled) 
02713     {
02714         CurrentAttrs[ATTR_FILLGEOMETRY].Ignore = TRUE;
02715     }
02716 
02717     
02718     BOOL Result = AttributeManager::ApplyBasedOnDefaults(pNode, CurrentAttrs);
02719 
02720     
02721     if (!Stroked)
02722         
02723         SetLineColour(OldCol);
02724 
02725     
02726     CurrentAttrs[ATTR_FILLGEOMETRY].Ignore = FALSE;
02727 
02728     
02729     SetPathFilled(TRUE);
02730 
02731     
02732     return Result;
02733 }
02734 
02735 
02736 
02737 
02738 
02739 
02740 
02741 
02742 
02743 
02744 
02745 
02746 
02747 
02748 
02749 
02750 
02751 
02752 
02753 
02754 
02755 
02756 
02757 
02758 
02759 
02760 
02761 
02762 
02763 void EPSFilter::GetEPSColour(DocColour *DestCol, 
02764                              PColourCMYK *pCMYK, 
02765                              TintType Tint, FIXEDPOINT TintVal, 
02766                              String_64 *ColName)
02767 {
02768     IndexedColour *pIndexed = NULL;
02769 
02770     
02771     DestCol->SetCMYKValue(pCMYK);
02772 
02773     
02774     
02775     
02776     
02777     
02778     
02779     BOOL IsNamed = ColName ? (ColName->CompareTo(ImmediateColourFudgeyBodgeName) != 0) : FALSE;
02780 
02781     if (((Tint == TINT_ILLUSTRATOR) || (Tint == TINT_COREL)) && IsNamed)
02782     {
02783         if (ColName->Length() > 0)
02784         {
02785             
02786             pIndexed = pColours->FindNamedColour((TCHAR *) (*ColName), DestCol, 
02787                                                  (TintVal * 100) / FixedPointScale);
02788 
02789             if (!pIndexed)
02790             {
02791                 TRACEUSER("Tim", _T("Unable to find named colour: %s\n"), (TCHAR *) (*ColName));
02792             }
02793         }
02794         else
02795         {
02796             
02797             
02798             
02799             
02800             
02801             DocColour TransCol(COLOUR_TRANS);
02802             (*DestCol) = TransCol;
02803         }
02804     }
02805     else
02806     {
02807         
02808         
02809         
02810         
02811         
02812         
02813         
02814         if (Filter::AddUnnamedColours)
02815         {
02816             pIndexed = pColours->FindNamedColour(String_64(_R(IDS_K_EPSFILTER_UNNAMED)), DestCol, 100, TRUE);
02817 
02818             if (!pIndexed)
02819             {
02820                 TRACEUSER("Tim", _T("Unable to construct an unnamed colour\n"));
02821             }
02822         }
02823     }
02824 
02825     if (pIndexed != NULL)
02826     {
02827         
02828         DestCol->MakeRefToIndexedColour(pIndexed);
02829     }
02830 
02831     
02832 }
02833 
02834 
02835 
02836 
02837 
02838 
02839 
02840 
02841 
02842 
02843 
02844 
02845 
02846 
02847 
02848 
02849 
02850 
02851 
02852 
02853 
02854 
02855 
02856 
02857 
02858 
02859 
02860 void EPSFilter::GetEPSColourRGB (DocColour *DestCol, 
02861                                 INT32 red, INT32 green, INT32 blue, 
02862                                  TintType Tint, FIXEDPOINT TintVal, 
02863                                  String_64 *ColName)
02864 {
02865     IndexedColour *pIndexed = NULL;
02866 
02867     
02868     DestCol->SetRGBValue(red, green, blue);
02869 
02870     
02871     
02872     
02873     
02874     
02875     
02876     BOOL IsNamed = ColName ? (ColName->CompareTo(ImmediateColourFudgeyBodgeName) != 0) : FALSE;
02877 
02878     if (((Tint == TINT_ILLUSTRATOR) || (Tint == TINT_COREL)) && IsNamed)
02879     {
02880         if (ColName->Length() > 0)
02881         {
02882             
02883             pIndexed = pColours->FindNamedColour((TCHAR *) (*ColName), DestCol, 
02884                                                  (TintVal * 100) / FixedPointScale);
02885         }
02886         else
02887         {
02888             
02889             
02890             
02891             
02892             
02893             DocColour TransCol(COLOUR_TRANS);
02894             (*DestCol) = TransCol;
02895         }
02896     }
02897     else
02898     {
02899         
02900         
02901         
02902         
02903         
02904         
02905         
02906         if (Filter::AddUnnamedColours)
02907         {
02908             pIndexed = pColours->FindNamedColour(String_64(_R(IDS_K_EPSFILTER_UNNAMED)), DestCol, 100, TRUE);
02909         }
02910     }
02911 
02912     if (pIndexed != NULL)
02913     {
02914         
02915         DestCol->MakeRefToIndexedColour(pIndexed);
02916     }
02917 
02918     
02919 }
02920 
02921 
02922 
02923 
02924 
02925 
02926 
02927 
02928 
02929 
02930 
02931 
02932 
02933 
02934 
02935 
02936 
02937 
02938 
02939 
02940     
02941 BOOL EPSFilter::ProcessToken()
02942 {
02943     
02944     DocCoord    Coords[3];
02945     PColourCMYK Col;
02946     DocColour   DocCol;
02947     double      Double;
02948     DocRect     BoundingRect;
02949     PathFlags   Flags;
02950     TintType    Tint = TINT_NONE;
02951     FIXEDPOINT  TintVal;
02952     LineCapType LineCap;
02953     JointType   JoinType;
02954     INT32       ArraySize;
02955     INT32       Array[8];
02956     DashRec     Dash;
02957     INT32       Long;
02958     String_64   ColName;
02959 
02960     
02961     switch (Token)
02962     {
02963         case EPSC_showpage:
02964             
02965             break;
02966 
02967         case EPSC_end:
02968             
02969             break;
02970 
02971         
02972         case EPSC_A:
02973             TRACE(_T("Ignoring graphics state token\n"));
02974             if (!Stack.Discard())
02975                 goto EPSError;
02976             break;
02977 
02978         case EPSC_i:
02979             TRACE(_T("Ignoring token i\n"));
02980             if (!Stack.Discard())
02981                 goto EPSError;
02982             break;
02983 
02984         case EPSC_D:
02985             TRACE(_T("Ignoring token D\n"));
02986             if (!Stack.Discard())
02987                 goto EPSError;
02988             break;
02989 
02990         case EPSC_M:
02991             
02992             if (Stack.Pop(&Double))
02993             {
02994                 
02995                 
02996                 if (!SetMitreLimit((MILLIPOINT) (Double * EPSScaleFactor)))
02997                     goto NoMemory;
02998             }
02999             else    
03000                 goto EPSError;
03001             break;
03002 
03003 
03004         
03005         
03006         
03007         case EPSC_u:
03008             GroupNesting++;
03009             return ProcessGroup();
03010             
03011         
03012         case EPSC_U:
03013             
03014             goto EPSError;
03015             
03016         
03017         
03018         case EPSC_g:
03019             if (Stack.PopGrayScale(&Col))
03020             {
03021                 
03022                 DocCol.SetCMYKValue(&Col);
03023                 if (!SetFillColour(DocCol))
03024                     goto NoMemory;
03025             }
03026             else
03027                 
03028                 goto EPSError;
03029             break;
03030 
03031         case EPSC_G:
03032             if (Stack.PopGrayScale(&Col))
03033             {
03034                 
03035                 DocCol.SetCMYKValue(&Col);
03036                 if (!SetLineColour(DocCol))
03037                     goto NoMemory;
03038             }
03039             else
03040                 
03041                 goto EPSError;
03042             break;
03043 
03044         case EPSC_p:
03045         case EPSC_P:
03046             
03047             TRACE(_T("Ignoring token p(P)\n"));
03048             if ( !Stack.DiscardArray() || !Stack.Discard(10) )
03049                 goto EPSError;
03050             break;
03051 
03052 
03053         case EPSC_x:
03054         case EPSC_X:
03055             Tint = TINT_ILLUSTRATOR;
03056         case EPSC_k:
03057         case EPSC_K:
03058             
03059             if (Stack.PopColour(&Col, Tint, &TintVal, &ColName))
03060             {
03061                 GetEPSColour(&DocCol, &Col, Tint, TintVal, &ColName);
03062 
03063                 
03064                 if ((Token == EPSC_x) || (Token == EPSC_k))
03065                 {
03066                     if (!SetFillColour(DocCol))
03067                         goto NoMemory;
03068                 }
03069                 else
03070                 {
03071                     if (!SetLineColour(DocCol))
03072                         goto NoMemory;
03073                 }
03074             }
03075             else    
03076                 
03077                 goto EPSError;
03078             break;
03079 
03080         
03081         
03082         case EPSC_O:
03083 
03084             TRACE(_T("Ignoring token O\n"));
03085             if (!Stack.Discard())
03086                 goto EPSError;
03087             break;
03088             
03089         case EPSC_R:
03090 
03091             TRACE(_T("Ignoring token R\n"));
03092             if (!Stack.Discard())
03093                 goto EPSError;
03094             break;
03095             
03096         case EPSC_w:
03097             
03098             if (Stack.Pop(&Double))
03099             {
03100                 
03101                 
03102                 if (!SetLineWidth((MILLIPOINT) (Double * EPSScaleFactor)))
03103                     goto NoMemory;
03104             }
03105             else    
03106                 goto EPSError;
03107             break;
03108             
03109         case EPSC_j:
03110             
03111             if (!Stack.Pop(&Long))
03112                 goto EPSError;
03113 
03114             
03115             switch (Long)
03116             {
03117                 case 0:     JoinType = MitreJoin;       break;
03118                 case 1:     JoinType = RoundJoin;       break;
03119                 case 2:     JoinType = BevelledJoin;    break;
03120                 
03121                 default:    goto EPSError;
03122             }
03123 
03124             
03125             if (!SetJoinType(JoinType))
03126                 goto NoMemory;
03127             break;
03128             
03129         case EPSC_J:
03130             
03131             if (!Stack.Pop(&Long))
03132                 goto EPSError;
03133 
03134             
03135             switch (Long)
03136             {
03137                 case 0:     LineCap = LineCapButt;      break;
03138                 case 1:     LineCap = LineCapRound;     break;
03139                 case 2:     LineCap = LineCapSquare;    break;
03140                 
03141                 default:    goto EPSError;
03142             }
03143 
03144             
03145             if (!SetLineCap(LineCap))
03146                 goto NoMemory;
03147             break;
03148             
03149         case EPSC_d:
03150             
03151             if (!Stack.Pop(&Double))
03152                 goto EPSError;
03153 
03154             TRACEUSER( "Will", _T("Importing dash pattern\n"));
03155             
03156             
03157             Dash.DashStart = (MILLIPOINT) (Double * EPSScaleFactor);
03158 
03159             
03160             ArraySize = 8;  
03161             if (!Stack.PopArray(Array, &ArraySize))
03162                 goto EPSError;
03163 
03164             Dash.Elements = ArraySize;
03165             Dash.ElementData = Array;
03166 
03167             
03168             
03169             Dash.ScaleWithLineWidth = FALSE;
03170 
03171             
03172             if (!SetDashPattern(Dash))
03173                 goto NoMemory;
03174             break;
03175             
03176         
03177         
03178         
03179         
03180         
03181         case EPSC_m:
03182             
03183             if (Stack.PopCoordPair(&Coords[0]))
03184             {
03185                 if ((ThePathType != PATH_DISCARD) && (ThePathType != PATH_DISCARD_STICKY))
03186                 {
03187                     if ((pPath == NULL) && (pInkPath == NULL))
03188                     {
03189                         
03190 
03191                         
03192                         switch (ThePathType)
03193                         {
03194                             case PATH_NORMAL:
03195                                 pPath = new NodePath;
03196                                 break;
03197                     
03198                             case PATH_RECT:
03199                                 pPath = (NodePath *) new NodeRect;
03200                                 break;
03201                     
03202                             case PATH_ELLIPSE:
03203                                 pPath = (NodePath *) new NodeEllipse;
03204                                 break;
03205 
03206                             case PATH_MANGLED:
03207                                 pPath = new NodePath;
03208                                 if (pPath)
03209                                     pPath->SetMangled(TRUE);
03210                                 break;
03211                             
03212                             default:
03213                                 ENSURE(FALSE, "Unknown path type in EPS filter!");
03214                                 goto EPSError;
03215                         }
03216 
03217                         
03218                         EPSFlags.NoAttributes = TRUE;
03219                     
03220                         if ((pPath == NULL) || (!pPath->SetUpPath()))
03221                             
03222                             goto NoMemory;
03223                     
03224                         
03225                         pPath->InkPath.FindStartOfPath();
03226 
03227                         
03228                         pInkPath = &pPath->InkPath;
03229                     }
03230 
03231                     else if (EPSFlags.PathIsHidden)
03232                     {
03233                         
03234                         
03235                         
03236                         pInkPath->ClearPath();
03237                     }
03238 
03239                     
03240                     
03241                     
03242                     
03243                     
03244                     if (!pInkPath->InsertMoveTo(Coords[0]))
03245                     {
03246                         
03247                         goto NoMemory;
03248                     }
03249                 }
03250             }
03251             else
03252                 
03253                 goto EPSError;
03254             break;
03255 
03256         
03257         case EPSC_l:
03258         case EPSC_L:
03259             
03260             if (Stack.PopCoordPair(&Coords[0]))
03261             {
03262                 if ((ThePathType != PATH_DISCARD) && (ThePathType != PATH_DISCARD_STICKY))
03263                 {
03264                     if (pInkPath == NULL)
03265                         
03266                         goto EPSError;
03267                 
03268                     if (Token == EPSC_l)
03269                         Flags.IsSmooth = TRUE;
03270                     if (!pInkPath->InsertLineTo(Coords[0], &Flags))
03271                         
03272                         goto NoMemory;
03273                 }
03274             }
03275             else
03276                 
03277                 goto EPSError;
03278             break;
03279 
03280         
03281         case EPSC_c:
03282         case EPSC_C:
03283             
03284             if (Stack.PopCoordPair(&Coords[2]) &&
03285                 Stack.PopCoordPair(&Coords[1]) &&
03286                 Stack.PopCoordPair(&Coords[0]))
03287             {
03288                 if ((ThePathType != PATH_DISCARD) && (ThePathType != PATH_DISCARD_STICKY))
03289                 {
03290                     if (pInkPath == NULL)
03291                         
03292                         goto EPSError;
03293                 
03294                     if (Token == EPSC_c)
03295                         Flags.IsSmooth = TRUE;
03296                     if (!pInkPath->InsertCurveTo(Coords[0], Coords[1], Coords[2], &Flags))
03297                         
03298                         goto NoMemory;
03299                 }
03300             }
03301             else
03302                 
03303                 goto EPSError;
03304             break;
03305             
03306         
03307         
03308         case EPSC_v:
03309         case EPSC_V:
03310             
03311             if (Stack.PopCoordPair(&Coords[2]) &&
03312                 Stack.PopCoordPair(&Coords[1]))
03313             {
03314                 if ((ThePathType != PATH_DISCARD) && (ThePathType != PATH_DISCARD_STICKY))
03315                 {
03316                     if (pInkPath == NULL)
03317                         
03318                         goto EPSError;
03319                 
03320                     if (Token == EPSC_v)
03321                         Flags.IsSmooth = TRUE;
03322                     
03323                     
03324                     INT32 index = pInkPath->GetNumCoords();
03325                     DocCoord* pCoord = pInkPath->GetCoordArray();
03326                     Coords[0] = pCoord[index-1];
03327                     if (!pInkPath->InsertCurveTo(Coords[0], Coords[1], Coords[2], &Flags))
03328                         
03329                         goto NoMemory;
03330                 }
03331             }
03332             else
03333                 
03334                 goto EPSError;
03335             break;
03336             
03337         case EPSC_y:
03338         case EPSC_Y:
03339             
03340             if (Stack.PopCoordPair(&Coords[2]) &&
03341                 Stack.PopCoordPair(&Coords[0]))
03342             {
03343                 if ((ThePathType != PATH_DISCARD) && (ThePathType != PATH_DISCARD_STICKY))
03344                 {
03345                     if (pInkPath == NULL)
03346                         
03347                         goto EPSError;
03348                 
03349                     if (Token == EPSC_y)
03350                         Flags.IsSmooth = TRUE;
03351                     if (!pInkPath->InsertCurveTo(Coords[0], Coords[2], Coords[2], &Flags))
03352                         
03353                         goto NoMemory;
03354                 }
03355             }
03356             else
03357                 
03358                 goto EPSError;
03359             break;
03360 
03361         case EPSC_S:
03362         case EPSC_b:
03363         case EPSC_B:
03364         case EPSC_f:
03365         case EPSC_F:
03366         case EPSC_s:
03367             
03368             if ( !ProcessEndOfPath () )
03369                 goto NoMemory;
03370             break;
03371             
03372         
03373         case EPSC_h:
03374         case EPSC_H:
03375             
03376             EPSFlags.PathIsHidden = TRUE;
03377 
03378             
03379             if (Token == EPSC_h)
03380             {
03381                 if (!pPath->InkPath.CloseSubPath())
03382                     
03383                     goto NoMemory;
03384 
03385                 
03386                 pPath->InkPath.IsFilled = TRUE;
03387             }
03388             break;
03389 
03390         
03391         case EPSC_n:
03392         case EPSC_N:
03393             
03394             if ( !ProcessUnfilledPath () )
03395                 goto NoMemory;
03396             break;
03397             
03398         case EPSC__u:  
03399             if ((EPSFlags.ComplexPath != 0) && !EPS_Group)
03400                 
03401                 
03402                 goto EPSError;
03403 
03404             if(EPS_Group && (EPSFlags.ComplexPath == 0))
03405                 ClipRegion.StartComplexClipRegion();
03406     
03407             
03408             
03409 
03410             EPSFlags.ComplexPath++;
03411             
03412 
03413             
03414             EPSFlags.StrokeComplexPath = FALSE;
03415             break;
03416             
03417         case EPSC__U:  
03418             if (EPSFlags.ComplexPath == 0)
03419                 
03420                 goto EPSError;
03421             
03422             
03423             EPSFlags.ComplexPath--;
03424             if(EPSFlags.ComplexPath <= 0)
03425             {
03426                 EPSFlags.ComplexPath = 0;
03427 
03428                 if(EPS_Group)
03429                     ClipRegion.EndComplexClipRegion();
03430 
03431                 if ((ThePathType != PATH_DISCARD) && (ThePathType != PATH_DISCARD_STICKY))
03432                 {
03433                     if (pPath == NULL)
03434                         
03435                         goto EPSError;
03436     
03437                     
03438                     if (!pPath->InkPath.EnsureValid())
03439                     {
03440                         
03441                         delete pPath;
03442                         InvalidPathFound = TRUE;
03443                     }
03444                     else
03445                     {
03446                         
03447                         if (!ClipRegion.ClipPathToRegion(&pPath->InkPath))
03448                             
03449                             goto NoMemory;
03450     
03451                         
03452                         pPath->InvalidateBoundingRect();
03453         
03454                         
03455                         if (EPSFlags.NoAttributes)
03456                         {
03457                             if (!AddAttributes(pPath, EPSFlags.StrokeComplexPath, pPath->InkPath.IsFilled))
03458                                 goto NoMemory;
03459                             EPSFlags.NoAttributes = FALSE;
03460                         }
03461         
03462                         
03463                         if (!AddNewNode(pPath))
03464                                 goto NoMemory;
03465                     }
03466             
03467                     
03468                     
03469                     pPath = NULL;
03470                     pInkPath = NULL;
03471                 }
03472             }
03473 
03474             break;
03475 
03476 
03477         
03478 
03479         case EPSC_q:
03480             
03481             ClipRegion.SaveContext();
03482 
03483             
03484             EPS_Group   =   TRUE;
03485 
03486             
03487             MaskedGroupNesting++;
03488             return (ProcessGroup());
03489             
03490         case EPSC_Q:
03491             
03492             goto EPSError;
03493 
03494         case EPSC_W:
03495             
03496             if (pInkPath == NULL)
03497                 
03498                 goto EPSError;
03499 
03500             if (!ClipRegion.AddNewClippingPath(pInkPath))
03501                 
03502                 return FALSE;
03503 
03504             break;
03505             
03506 
03507         
03508         case EPSC_To:
03509             return ProcessText();
03510             break;
03511             
03512         case EPSC_TO:
03513             TRACE(_T("Ignoring token TO\n"));
03514             break;
03515             
03516         case EPSC_Tp:
03517             TRACE(_T("Ignoring token Tp\n"));
03518             if (!Stack.Discard(7))
03519                 goto EPSError;
03520             break;
03521             
03522         case EPSC_TP:
03523             TRACE(_T("Ignoring token TP\n"));
03524             break;
03525             
03526         case EPSC_Tm:
03527             TRACE(_T("Ignoring token Tm\n"));
03528             if (!Stack.Discard(6))
03529                 goto EPSError;
03530             break;
03531             
03532         case EPSC_Td:
03533             TRACE(_T("Ignoring token Td\n"));
03534             if (!Stack.Discard(2))
03535                 goto EPSError;
03536             break;
03537             
03538         case EPSC_T_:
03539             TRACE(_T("Ignoring token T\n"));
03540             break;
03541             
03542         case EPSC_TR:
03543             TRACE(_T("Ignoring token TR\n"));
03544             if (!Stack.Discard(8))
03545                 goto EPSError;
03546             break;
03547 
03548         
03549         case EPSC_Tr:
03550         case EPSC_Ta:
03551         case EPSC_Tt:
03552         case EPSC_Tw:
03553         case EPSC_Tc:
03554         case EPSC_Ts:
03555         case EPSC_Tz:
03556         case EPSC_TA:
03557         case EPSC_Tq:
03558             TRACE(_T("Ignoring text attribute token\n"));
03559             if (!Stack.Discard())
03560                 goto EPSError;
03561             break;
03562 
03563         case EPSC_Tf:
03564         case EPSC_Tl:
03565             TRACE(_T("Ignoring token Tf/Tl\n"));
03566             if (!Stack.Discard(2))
03567                 goto EPSError;
03568             break;
03569 
03570         case EPSC_TW:
03571         case EPSC_TC:
03572         case EPSC_Ti:
03573             TRACE(_T("Ignoring text token\n"));
03574             if (!Stack.Discard(3))
03575                 goto EPSError;
03576             break;
03577 
03578 
03579         
03580         case EPSC_Tx:
03581         case EPSC_Tj:
03582         case EPSC_TX:
03583             TRACE(_T("Ignoring text body tokens\n"));
03584             if (!Stack.Discard())
03585                 goto EPSError;
03586             break;
03587             
03588         case EPSC_Tk:
03589         case EPSC_TK:
03590             TRACE(_T("Ignoring token Tk(K)\n"));
03591             if (!Stack.Discard(2))
03592                 goto EPSError;
03593             break;
03594             
03595         case EPSC_Tplus:
03596         case EPSC_Tminus:
03597             TRACE(_T("Ignoring token T+/T-\n"));
03598             break;
03599             
03600         
03601         
03602         case EPSC_Name:
03603             return Stack.Push(TokenBuf, TRUE);
03604             
03605         case EPSC_ArrayStart:
03606         case EPSC_ArrayEnd:
03607             return Stack.Push(Token);
03608         
03609         case EPSC_Slash:
03610             
03611             break;
03612                 
03613         case EPSC_Integer:
03614             return Stack.Push(TokenData.Long);
03615             
03616         case EPSC_Double:
03617             return Stack.Push(TokenData.Double);
03618             
03619         case EPSC_FixedPoint:
03620             return Stack.Push(TokenData.FixedPoint);
03621             
03622         case EPSC_String:
03623             return Stack.Push(TokenBuf);
03624             
03625         case EPSC_Comment:
03626             return ProcessComment();
03627             
03628         default:
03629             
03630             goto EPSError;
03631     }
03632 
03633 
03634     
03635     return TRUE;
03636     
03637     
03638     
03639     
03640 EPSError:
03641     HandleEPSError();
03642     return FALSE;
03643     
03644 NoMemory:
03645     HandleNoMemory();
03646     return FALSE;
03647     
03648     
03649 }
03650 
03651 
03652 
03653 
03654 
03655 
03656 
03657 
03658 
03659 
03660 
03661 
03662 
03663 
03664 BOOL EPSFilter::ProcessEndOfPath ( void )
03665 {
03666     
03667     EPSFlags.PathIsHidden = FALSE;
03668 
03669     if (ThePathType == PATH_DISCARD)
03670     {
03671         
03672         ThePathType = PATH_NORMAL;
03673         return TRUE;
03674     }
03675     
03676     if (ThePathType == PATH_DISCARD_STICKY)
03677         
03678         return TRUE;
03679 
03680     ENSURE((ThePathType == PATH_NORMAL) || 
03681            (ThePathType == PATH_RECT) || 
03682            (ThePathType == PATH_ELLIPSE) ||
03683            (ThePathType == PATH_MANGLED), "No path in stroke!");
03684                 
03685     
03686     
03687     if (pPath == NULL)
03688         return TRUE;
03689 
03690     
03691     if ((Token == EPSC_s) || (Token == EPSC_b) || (Token == EPSC_f))
03692     {
03693         if (!pPath->InkPath.CloseSubPath())
03694             
03695             return FALSE;
03696 
03697         
03698         pPath->InkPath.IsFilled = TRUE;
03699     }
03700                     
03701     
03702     if ((Token == EPSC_b) || 
03703         (Token == EPSC_B) || 
03704         (Token == EPSC_F) || 
03705         (Token == EPSC_f))
03706     {
03707         
03708         pPath->InkPath.IsFilled = TRUE;
03709         SetPathFilled(TRUE);
03710     }
03711     else
03712     {
03713         SetPathFilled(FALSE);
03714     }
03715 
03716     
03717     
03718 
03719     
03720     
03721     BOOL InsertQuickShape = FALSE;
03722     NodeRegularShape* pQuickShape = NULL;
03723 
03724     switch (ThePathType)
03725     {
03726         case PATH_RECT:
03727             pQuickShape = new NodeRegularShape;
03728             if (pQuickShape != NULL)
03729             {
03730                 if (ProcessRectangle((NodeRect*)pPath, pQuickShape))
03731                     InsertQuickShape = TRUE;
03732                 else
03733                 {
03734                     
03735                     delete pQuickShape;
03736                     NodeRect* OldRect = (NodeRect*)pPath;
03737                     pPath = new NodePath();
03738                     if ((pPath == NULL) || !pPath->InkPath.Initialise(OldRect->InkPath.GetNumCoords()))
03739                         return TRUE;
03740                     pPath->InkPath.CopyPathDataFrom(&OldRect->InkPath);
03741                     delete OldRect;
03742                 }
03743             }
03744             else
03745             {
03746                 return FALSE;
03747             }
03748             break;
03749 
03750         case PATH_ELLIPSE:
03751             pQuickShape = new NodeRegularShape;
03752             if (pQuickShape != NULL)
03753             {
03754                 if (ProcessEllipse((NodeEllipse*)pPath, pQuickShape))
03755                     InsertQuickShape = TRUE;
03756                 else
03757                 {
03758                     
03759                     delete pQuickShape;
03760                     NodeEllipse* OldElip = (NodeEllipse*)pPath;
03761                     pPath = new NodePath();
03762                     if ((pPath == NULL) || !pPath->InkPath.Initialise(OldElip->InkPath.GetNumCoords()))
03763                         return FALSE;
03764                     pPath->InkPath.CopyPathDataFrom(&OldElip->InkPath);
03765                     delete OldElip;
03766                 }
03767             }
03768             else
03769             {
03770                 return FALSE;
03771             }
03772             break;
03773 
03774         default:
03775             break;
03776     }
03777 
03778     if (EPSFlags.ComplexPath == 0)
03779     {
03780         
03781         if (InsertQuickShape)
03782         {
03783             
03784             pQuickShape->InvalidateBoundingRect();
03785             pQuickShape->InvalidateCache();
03786                     
03787             
03788             if (EPSFlags.NoAttributes)
03789             {
03790                 if (!AddAttributes(pQuickShape, (Token != EPSC_f) && (Token != EPSC_F), pPath->InkPath.IsFilled))
03791                     return FALSE;
03792 
03793                 EPSFlags.NoAttributes = FALSE;
03794             }
03795 
03796             delete pPath;   
03797         
03798             
03799             if (!AddNewNode(pQuickShape))
03800                 return FALSE;
03801         }
03802         else
03803         {
03804             
03805             if (!pPath->InkPath.EnsureValid())
03806             {
03807                 
03808                 delete pPath;
03809                 InvalidPathFound = TRUE;
03810             }
03811             else
03812             {
03813                 
03814 
03815                 
03816                 if (!ClipRegion.ClipPathToRegion(&pPath->InkPath))
03817                     
03818                     return FALSE;
03819 
03820                 
03821                 
03822                 if (pPath->InkPath.EnsureValid ())
03823                 {
03824                     
03825                     pPath->InvalidateBoundingRect();
03826                         
03827                     
03828                     if (EPSFlags.NoAttributes)
03829                     {
03830                         if (!AddAttributes(pPath, (Token != EPSC_f) && (Token != EPSC_F), pPath->InkPath.IsFilled))
03831                             return FALSE;
03832                         EPSFlags.NoAttributes = FALSE;
03833                     }
03834             
03835                     
03836                     if (!AddNewNode(pPath))
03837                         return FALSE;
03838                 }
03839                 else
03840                 {
03841                     delete pPath;
03842                     InvalidPathFound = TRUE;
03843                 }
03844             }
03845         }
03846 
03847         
03848         
03849         pPath = NULL;
03850         pInkPath = NULL;
03851     }
03852     else
03853         EPSFlags.StrokeComplexPath = (Token != EPSC_f) && (Token != EPSC_F);
03854 
03855     
03856     ThePathType = PATH_NORMAL;
03857 
03858     
03859     return TRUE;
03860 }
03861 
03862 
03863 
03864 
03865 
03866 
03867 
03868 
03869 
03870 
03871 
03872 
03873 
03874 
03875 BOOL EPSFilter::ProcessUnfilledPath ( void )
03876 {
03877     
03878     EPSFlags.PathIsHidden = FALSE;
03879 
03880     if (ThePathType == PATH_DISCARD)
03881     {
03882         
03883         ThePathType = PATH_NORMAL;
03884         return TRUE;
03885     }
03886     
03887     if (ThePathType == PATH_DISCARD_STICKY)
03888         
03889         return TRUE;
03890 
03891     ENSURE((ThePathType == PATH_NORMAL) || 
03892            (ThePathType == PATH_RECT) || 
03893            (ThePathType == PATH_ELLIPSE) ||
03894            (ThePathType == PATH_MANGLED), "No path in hide!");
03895     
03896     
03897     if (pPath == NULL)
03898         return TRUE;
03899 
03900     
03901     if ((Token == EPSC_h) || (Token == EPSC_n))
03902     {
03903         if (!pPath->InkPath.CloseSubPath())
03904             
03905             return FALSE;
03906 
03907         
03908         pPath->InkPath.IsFilled = TRUE;
03909     }
03910                     
03911     
03912     SetPathFilled(FALSE);
03913         
03914     
03915     if (EPSFlags.NoAttributes)
03916     {
03917         
03918         if (!AddAttributes(pPath, FALSE, pPath->InkPath.IsFilled))
03919             return FALSE;
03920         EPSFlags.NoAttributes = FALSE;
03921     }
03922         
03923     
03924     if (ThePathType == PATH_RECT)
03925     {
03926         
03927         NodeRect *pRect = (NodeRect *) pPath;
03928         ENSURE(pRect->InkPath.GetNumCoords() == 5, 
03929                "Bad rectangle path in EPS import!");
03930 
03931         
03932         DocCoord *Points = pRect->InkPath.GetCoordArray();
03933         for (INT32 i = 0; i <= 3; i++)
03934             pRect->Parallel[i] = Points[i];
03935     }
03936     else if (ThePathType == PATH_ELLIPSE)
03937     {
03938         
03939         NodeEllipse *pEllipse = (NodeEllipse *) pPath;
03940         ENSURE(pEllipse->InkPath.GetNumCoords() == 13, 
03941                "Bad ellipse path in EPS import!");
03942 
03943         
03944         for (INT32 i = 0; i <= 3; i++)
03945             pEllipse->Parallel[i] = ShapeBBox[i];
03946     }
03947 
03948     if (EPSFlags.ComplexPath == 0)
03949     {
03950         
03951 
03952         
03953         if (!pPath->InkPath.EnsureValid())
03954         {
03955             
03956             delete pPath;
03957             InvalidPathFound = TRUE;
03958         }
03959         else
03960         {
03961             
03962             pPath->InvalidateBoundingRect();
03963         
03964             
03965             if (!AddNewNode(pPath))
03966                 return FALSE;
03967         }
03968 
03969         
03970         
03971         pPath = NULL;
03972         pInkPath = NULL;
03973     }
03974     else
03975         EPSFlags.StrokeComplexPath = FALSE;
03976 
03977     
03978     ThePathType = PATH_NORMAL;
03979 
03980     
03981     return TRUE;
03982 }
03983 
03984 
03985 
03986 
03987 
03988 
03989 
03990 
03991 
03992 
03993 
03994 
03995 
03996 
03997 
03998 
03999 BOOL EPSFilter::ProcessComment(BOOL BypassDocComponents)
04000 {
04001     if ((camStrncmp(TokenBuf, _T("%%Trailer"), 9) == 0) ||
04002         (camStrncmp(TokenBuf, _T("%%PageTrailer"), 13) == 0))
04003     {
04004         ProcessEPSTrailer();
04005     }
04006     else if (camStrncmp(TokenBuf, _T("%%BoundingBox:"), 14) == 0)
04007     {
04008         ProcessBoundingBox();
04009     }
04010     else
04011     {
04012         
04013         INT32               Index           = 0;
04014         BOOL            FoundComment    = FALSE;
04015         EPSCommentDef   Comments;
04016 
04017         for(;;)
04018         {
04019             Comments = EPSComments.ReturnElement ( Index );
04020             INT32 StartLen = camStrclen( Comments.StartMarker );
04021 
04022             if (StartLen == 0)
04023             {
04024                 
04025                 break;
04026             }
04027 
04028             if (camStrncmp(TokenBuf, Comments.StartMarker, StartLen) == 0)
04029             {
04030                 FoundComment = TRUE;
04031                 break;
04032             }
04033 
04034             
04035             Index++;
04036         }
04037 
04038         if (FoundComment)
04039         {
04040             
04041             INT32 EndLen = camStrclen(Comments.EndMarker);
04042 
04043             do
04044             {
04045                 GetLineToken();
04046 
04047                 if (Token == EPSC_Comment)
04048                 {
04049                     if (camStrncmp(TokenBuf, Comments.EndMarker, EndLen) == 0)
04050                     {
04051                         
04052                         break;
04053                     }
04054 
04055                     
04056                     
04057                     if ((camStrncmp(TokenBuf, _T("%%EndProlog"), 11) == 0) ||
04058                         (camStrncmp(TokenBuf, _T("%%EndSetup"), 10) == 0))
04059                     {
04060                         
04061                         
04062                         
04063                         
04064                         
04065                         EPSFile->UngetToken();
04066                         break;
04067                     }
04068 
04069 
04070                     
04071                     if (Comments.ProcessContents)
04072                     {
04073                         
04074                         
04075                         ProcessEPSComment();
04076                     }
04077                     else
04078                     {
04079                         
04080                         
04081                         ProcessComment(TRUE);
04082                     }
04083                 }
04084 
04085                 if (EPSFlags.EPSErrorEncountered)
04086                     return FALSE;
04087             }
04088             while (!EPSFile->eof());
04089         }
04090         else if (!BypassDocComponents)
04091         {
04092             
04093             ProcessEPSComment();
04094         }
04095     }
04096 
04097     return TRUE;
04098 }
04099 
04100 
04101 
04102 
04103 
04104 
04105 
04106 
04107 
04108 
04109 
04110 
04111 
04112 
04113 
04114 
04115 
04116 
04117 
04118 BOOL EPSFilter::ProcessFilterComment()
04119 {
04120     
04121     if (camStrncmp(TokenBuf, _T("%%XSScript"), 10) == 0)
04122     {
04123         TextComment[0]=2;
04124         return TRUE;
04125     }
04126     return FALSE;
04127 }
04128 
04129 
04130 
04131 
04132 
04133 
04134 
04135 
04136 
04137 
04138 
04139 
04140 
04141 
04142 
04143 BOOL EPSFilter::ProcessEPSComment()
04144 {
04145     
04146     if (ProcessFilterComment())
04147         
04148         return TRUE;
04149 
04150     
04151     DocComponent *pComponent = NULL;
04152     ProcessEPSResult Result = EPSCommentUnknown;
04153 
04154     
04155     Result = TheDocument->ProcessEPSComment(this, TokenBuf);
04156 
04157     
04158     if (Result == EPSCommentUnknown)
04159         pComponent = TheDocument->EnumerateDocComponents(NULL);
04160 
04161     while (pComponent != NULL)
04162     {
04163         
04164         Result = pComponent->ProcessEPSComment(this, TokenBuf);
04165         
04166         if (Result != EPSCommentUnknown)
04167             
04168             break;
04169 
04170         
04171         pComponent = TheDocument->EnumerateDocComponents(pComponent);
04172     }
04173 
04174     
04175     
04176     BOOL Recognised = Result != EPSCommentUnknown;
04177 
04178     
04179     do
04180     {
04181         
04182         GetToken();
04183 
04184         if ((Token != EPSC_Comment) || (camStrncmp(TokenBuf, _T("%%+"), 3) != 0))
04185         {
04186             
04187             if (Result == EPSCommentOK)
04188             {
04189                 
04190                 if (pComponent==NULL)
04191                     TheDocument->EndOfEPSComment(this);
04192                 else
04193                     pComponent->EndOfEPSComment(this);
04194             }
04195 
04196             
04197             EPSFile->UngetToken();
04198 
04199             break;
04200         }
04201 
04202         
04203         if (Result == EPSCommentOK)
04204         {
04205             
04206             if (pComponent==NULL)
04207                 Result = TheDocument->ProcessEPSComment(this, TokenBuf);
04208             else
04209                 Result = pComponent->ProcessEPSComment(this, TokenBuf);
04210         }
04211         else
04212         {
04213             
04214             
04215             
04216         }
04217     } while (!EPSFile->eof());
04218 
04219     
04220     return (Recognised);
04221 }
04222 
04223 
04224 
04225 
04226 
04227 
04228 
04229 
04230 
04231 
04232 
04233 
04234 
04235 
04236 BOOL EPSFilter::ProcessEPSTrailer()
04237 {
04238     BOOL Result = FALSE;
04239 
04240     
04241     
04242     
04243     do
04244     {
04245         GetToken();
04246 
04247         
04248         if ((Token == EPSC_Comment) && (TokenBuf[1] == '%'))
04249         {   
04250             Result = TRUE;
04251             break;
04252         }
04253 
04254     } while (!EPSFile->eof());
04255 
04256     
04257     EPSFile->UngetToken();
04258 
04259     return Result;
04260 }
04261 
04262 
04263 
04264 
04265 
04266 
04267 
04268 
04269 
04270 
04271 
04272 
04273 
04274 
04275 BOOL EPSFilter::ProcessBoundingBox()
04276 {
04277     
04278     if (!AdjustOrigin)
04279         
04280         return TRUE;
04281 
04282     
04283     DocRect BBox;
04284 
04285     
04286     TCHAR BBoxStr[50];
04287     camStrncpy(BBoxStr, TokenBuf + 14, 50);
04288 
04289     
04290     TCHAR *Next = BBoxStr;
04291     TCHAR *Num;
04292 
04293     Num=Next;
04294     while(*Next && (*Next!=_T(' ')))
04295         Next++;
04296     if (*Next)
04297         *(Next++)=0;
04298     if (!Num || !*Num)
04299         
04300         return TRUE;
04301     BBox.lo.x = 0;
04302     camSscanf(Num, _T("%d"), &BBox.lo.x);
04303     BBox.lo.x *= 1000;
04304 
04305     Num=Next;
04306     while(*Next && (*Next!=_T(' ')))
04307         Next++;
04308     if (*Next)
04309         *(Next++)=0;
04310     if (!Num || !*Num)
04311         
04312         return TRUE;
04313     BBox.lo.y = 0;
04314     camSscanf(Num, _T("%d"), &BBox.lo.y);
04315     BBox.lo.y *= 1000;
04316 
04317     Num=Next;
04318     while(*Next && (*Next!=_T(' ')))
04319         Next++;
04320     if (*Next)
04321         *(Next++)=0;
04322     if (!Num || !*Num)
04323         
04324         return TRUE;
04325     BBox.hi.x = 0;
04326     camSscanf(Num, _T("%d"), &BBox.hi.x);
04327     BBox.hi.x *= 1000;
04328 
04329     Num=Next;
04330     while(*Next && (*Next!=_T(' ')))
04331         Next++;
04332     if (*Next)
04333         *(Next++)=0;
04334     if (!Num || !*Num)
04335         
04336         return TRUE;
04337     BBox.hi.y = 0;
04338     camSscanf(Num, _T("%d"), &BBox.hi.y);
04339     BBox.hi.y *= 1000;
04340 
04341     
04342     if (!SpreadRect.ContainsRect(BBox))
04343         
04344         Stack.TranslateCoordOrigin(-BBox.lo.x, -BBox.lo.y);
04345 
04346     
04347     return TRUE;
04348 }
04349 
04350 
04351 
04352 
04353 
04354 
04355 
04356 
04357 
04358 
04359 
04360 
04361 
04362 
04363 void EPSFilter::HandleEPSError()
04364 {
04365     
04366     TRACE( _T("EPS syntax error at token <%s> (line %ld, TCHAR %d)\n"), 
04367           TokenBuf, EPSFile->GetLineNumber(), EPSFile->GetCharOffset());
04368 
04369     
04370     if (pPath != NULL)
04371     {
04372         pPath->CascadeDelete();
04373         pPath = NULL;
04374     }
04375     else
04376     {
04377         delete pInkPath;
04378     }
04379 
04380     pInkPath = NULL;
04381     
04382     
04383     
04384     Stack.DeleteAll ();
04385 
04386     
04387     EPSFlags.EPSErrorEncountered = TRUE;
04388 
04389     
04390     String_256 ErrMsg;
04391     ErrMsg.MakeMsg(_R(IDT_EPS_BADSYNTAX), EPSFile->GetLineNumber(), EPSFile->GetCharOffset());
04392     Error::SetError(_R(IDT_EPS_BADSYNTAX), (TCHAR *) ErrMsg, 0);
04393 }
04394 
04395 
04396 
04397 
04398 
04399 
04400 
04401 
04402 
04403 
04404 
04405 
04406 
04407 void EPSFilter::HandleNoMemory()
04408 {
04409     
04410     if (pPath != NULL)
04411     {
04412         pPath->CascadeDelete();
04413         pPath = NULL;
04414     }
04415     else
04416     {
04417         delete pInkPath;
04418     }
04419 
04420     pInkPath = NULL;
04421         
04422     
04423     if (Error::GetErrorNumber() == _R(IDS_OUT_OF_MEMORY))
04424         Error::SetError(_R(IDT_EPS_NOMEMORY));
04425     else
04426         
04427         HandleEPSError();
04428 }
04429 
04430 
04431 
04432 
04433 
04434 
04435 
04436 
04437 
04438 
04439 
04440 
04441 
04442 BOOL EPSFilter::ProcessGroup()
04443 {
04444     if (!StartGroup())
04445         return FALSE;
04446 
04447     
04448     do
04449     {
04450         GetToken();
04451 
04452         
04453         if ((Token == EPSC_U) || (Token == EPSC_Q))
04454         {
04455             return EndGroup(Token == EPSC_Q);
04456         }
04457     }
04458     
04459     while (HandleToken() && (!EPSFile->eof()));
04460 
04461     if (EPSFile->eof())
04462     {
04463         
04464         HandleEPSError();
04465     }
04466 
04467     
04468     return FALSE;
04469 }
04470 
04471 
04472 
04473 
04474 
04475 
04476 
04477 
04478 
04479 
04480 
04481 
04482 
04483 
04484 TCHAR *EPSFilter::GetEPSCommand(EPSCommand Cmd)
04485 {
04486     INT32 i = 0;
04487     while (Commands[i].Cmd != EPSC_Invalid)
04488     {
04489         if (Commands[i].Cmd == Cmd)
04490             return Commands[i].CmdStr;
04491 
04492         
04493         i++;
04494     }
04495 
04496     
04497     return Commands[i].CmdStr;
04498 }
04499 
04500 
04501 
04502 
04503 
04504 
04505 
04506 
04507 
04508 
04509 
04510 
04511 
04512 
04513 
04514 
04515 
04516 
04517 
04518 
04519 
04520 
04521 
04522 
04523 
04524 
04525 
04526 
04527 BOOL EPSFilter::ExportBinaryHeader(CCLexFile* pFile)
04528 {
04529 #ifdef DO_EXPORT
04530     
04531     TCHAR Buf[30];
04532 
04533     
04534     memset(Buf, 0, 30);
04535 
04536     
04537     
04538     Buf[0] = '\xC5';
04539     Buf[1] = '\xD0';
04540     Buf[2] = '\xD3';
04541     Buf[3] = '\xC6';
04542 
04543     
04544     Buf[28] = '\xFF';
04545     Buf[29] = '\xFF';
04546     
04547     
04548     if (pFile->write(Buf, 30).fail())
04549         return FALSE;
04550 
04551 #endif
04552     
04553     return TRUE;
04554 }
04555 
04556 
04557 
04558 
04559 
04560 
04561 
04562 
04563 
04564 
04565 
04566 
04567 
04568 
04569 
04570 
04571 BOOL EPSFilter::CorrectBinaryHeader(CCLexFile* pFile)
04572 {
04573 #ifdef DO_EXPORT
04574     INT32 Length = 0;
04575     INT32 Zero = 0;
04576 
04577     
04578     
04579     pFile->seek(4);
04580 
04581     
04582     if (pFile->write(&EPSStart, 4).fail())
04583         return FALSE;
04584 
04585     
04586     Length = EPSEnd - EPSStart;
04587     if (pFile->write(&Length, 4).fail())
04588         return FALSE;
04589 
04590     
04591     if (pFile->write(&Zero, 4).fail())
04592         return FALSE;
04593 
04594     
04595     if (pFile->write(&Zero, 4).fail())
04596         return FALSE;
04597 
04598     
04599     if (pFile->write(&PreviewStart, 4).fail())
04600         return FALSE;
04601 
04602     
04603     Length = PreviewEnd - PreviewStart;
04604     if (pFile->write(&Length, 4).fail())
04605         return FALSE;
04606 #endif
04607     
04608     return TRUE;
04609 }
04610 
04611 
04612 
04613 
04614 
04615 
04616 
04617 
04618 
04619 
04620 
04621 
04622 BOOL EPSFilter::WriteEPSProlog()
04623 {
04624     return TRUE;
04625 }
04626 
04627 
04628 
04629 
04630 
04631 
04632 
04633 
04634 
04635 
04636 
04637 
04638 BOOL EPSFilter::WriteEPSSetup()
04639 {
04640     return TRUE;
04641 }
04642 
04643 
04644 
04645 
04646 
04647 
04648 
04649 
04650 
04651 
04652 
04653 
04654 BOOL EPSFilter::WriteEPSComments()
04655 {
04656     return TRUE;
04657 }
04658 
04659 
04660 
04661 
04662 
04663 
04664 
04665 
04666 
04667 
04668 
04669 
04670 BOOL EPSFilter::WriteScript()
04671 {
04672     return TRUE;
04673 }
04674 
04675 
04676 
04677 
04678 
04679 
04680 
04681 
04682 
04683 
04684 
04685 
04686 
04687 BOOL EPSFilter::NeedsPrintComponents ()
04688 {
04689     
04690     return TRUE;
04691 }
04692 
04693 
04694 
04695 
04696 
04697 
04698 
04699 
04700 
04701 
04702 
04703 
04704 
04705 
04706 
04707 
04708 
04709 
04710 EPSExportDC* EPSFilter::CreateExportDC()
04711 {
04712 #ifdef DO_EXPORT
04713     
04714     return new EPSExportDC(this);
04715 #else
04716     return NULL;
04717 #endif
04718 }
04719 
04720 
04721 
04722 
04723 
04724 
04725 
04726 
04727 
04728 
04729 
04730 
04731 
04732 
04733 
04734 
04735 BOOL EPSFilter::GetExportOptions( )
04736 {
04737     
04738     return TRUE;
04739 }
04740 
04741 
04742 
04743 
04744 
04745 
04746 
04747 
04748 
04749 
04750 
04751 
04752 
04753 
04754 
04755 
04756 
04757 
04758 BOOL EPSFilter::PrepareToExport(CCLexFile* pFile, Spread* pSpread)
04759 {
04760 #ifdef DO_EXPORT
04761     
04762     ExportDCPtr = CreateExportDC();
04763 
04764     if (ExportDCPtr == NULL)
04765         return FALSE;
04766 
04767     try
04768     {
04769         ExportDCPtr->Init(pFile);
04770     }
04771     catch(CFileException)
04772     {
04773         
04774         return FALSE;
04775     }
04776 
04777     
04778     Page *pPage = pSpread->FindFirstPageInSpread(); 
04779     ENSURE(pPage != NULL, "Spread has no pages");
04780     ERRORIF(pPage == NULL, _R(IDT_DOC_BADSTRUCTURE), FALSE);
04781 
04782     
04783     DocRect PageRect = pPage->GetPageRect();
04784     ExportDCPtr->SetOrigin(PageRect.lo);
04785 
04786     
04787 
04788     
04789     DocRect NullClipRect;
04790     NullClipRect.MakeEmpty();
04791 
04792     if (IS_A(this, EPSFilter))
04793     {
04794         
04795         Matrix Identity;
04796 
04797         
04798         FIXED16 Scale(1);
04799 
04800         
04801         ExportRegion = new EPSRenderRegion(NullClipRect, Identity, Scale);
04802         if (ExportRegion == NULL)
04803             return FALSE;
04804 
04805         
04806         ExportRegion->AttachDevice(DocView::GetSelected(), ExportDCPtr->GetDC(), pSpread);
04807     }
04808 
04809     
04810     DocComponent *pComponent = TheDocument->EnumerateDocComponents(NULL);
04811 
04812     while (pComponent != NULL)
04813     {
04814         
04815         pComponent->EPSStartExport(this);
04816 
04817         
04818         pComponent = TheDocument->EnumerateDocComponents(pComponent);
04819     }
04820 #endif      
04821     
04822     return TRUE;
04823 };
04824 
04825 
04826 
04827 
04828 
04829 
04830 
04831 
04832 
04833 
04834 
04835 
04836 
04837 
04838 
04839 void EPSFilter::CleanUpAfterExport()
04840 {
04841 #ifdef DO_EXPORT
04842     
04843     if (ExportDCPtr!=NULL)
04844         delete ExportDCPtr;
04845     ExportDCPtr = NULL;
04846 
04847     if (ExportRegion!=NULL)
04848         delete ExportRegion;
04849     ExportRegion = NULL;
04850 
04851     
04852     DocComponent *pComponent = TheDocument->EnumerateDocComponents(NULL);
04853 
04854     while (pComponent != NULL)
04855     {
04856         
04857         pComponent->EPSEndExport(this);
04858 
04859         
04860         pComponent = TheDocument->EnumerateDocComponents(pComponent);
04861     }
04862 #endif
04863 }
04864 
04865 
04866 
04867 
04868 
04869 
04870 
04871 
04872 
04873 
04874 
04875 
04876 
04877 
04878 
04879 
04880 
04881 
04882 
04883 
04884 BOOL EPSFilter::DoExport(Operation* pOp, CCLexFile* pFile, PathName* pPath, Document* pDoc,
04885                          BOOL ShowOptions)
04886 {
04887 #ifdef DO_EXPORT
04888     
04889     BOOL ok = GetExportOptions();
04890     if (!ok)
04891     {
04892         
04893         
04894         Error::SetError(_R(IDN_USER_CANCELLED),0);
04895         return FALSE;
04896     }
04897 
04898     
04899     
04900     
04901     if (!pFile->isOpen())
04902     {
04903         if (pFile->IsKindOf(CC_RUNTIME_CLASS(CCDiskFile)))
04904         {
04905             ok = OpenExportFile((CCDiskFile*) pFile, pPath);
04906             if (!ok)
04907                 return FALSE;
04908         }
04909         else
04910         {
04911             TRACEUSER( "JustinF", _T("Tried to open non-CCDiskFile in EPSFilter::DoExport\n"));
04912             return FALSE;
04913         }
04914     }
04915     
04916     
04917     Filter* pFilter = NULL;
04918 
04919     if (WantPreviewBmp)
04920     {
04921         
04922         
04923         
04924         
04925         pFilter = Filter::GetFirst();
04926 
04927         
04928         
04929         
04930         while ((pFilter != NULL) && (pFilter->FilterID != FILTERID_PREVIEW_TIFF))
04931         {
04932             
04933             pFilter = Filter::GetNext(pFilter);
04934         }
04935 
04936         
04937         if ( pFilter!=NULL )
04938         {
04939             
04940             EPSStart = 0;
04941             EPSEnd = 0;
04942             PreviewStart = 0;
04943             PreviewEnd = 0;
04944 
04945             
04946             if (!ExportBinaryHeader(pFile))
04947             {
04948                 CleanUpAfterExport();
04949                 return FALSE;
04950             }
04951 
04952             
04953             
04954             INT32 OldPreviewSize = PreviewFilter::PreviewBitmapSize;
04955 
04956             if (IS_KIND_OF(CamelotNativeEPSFilter))
04957             {
04958                 
04959                 PreviewFilter::PreviewBitmapSize = 96000;
04960             }
04961 
04962             
04963             BaseBitmapFilter* pBitmapFilter = static_cast<BaseBitmapFilter*> ( pFilter );
04964             pBitmapFilter->SetPreviewBitmap(TRUE);
04965             PreviewStart = pFile->tell();
04966 
04967             
04968             if (!pBitmapFilter->DoExport(pOp, pFile, pPath, pDoc, TRUE))
04969             {
04970                 
04971                 
04972                 pFile->seek(PreviewStart);
04973 
04974                 
04975                 PreviewStart = 0;
04976                 PreviewEnd = 0;
04977             }
04978             else
04979             {
04980                 
04981                 PreviewEnd = pFile->tell();
04982             }
04983 
04984             
04985             EPSStart = pFile->tell();
04986 
04987             
04988             pBitmapFilter->SetPreviewBitmap(FALSE);
04989             
04990             if (IS_KIND_OF(CamelotNativeEPSFilter))
04991             {
04992                 
04993                 PreviewFilter::PreviewBitmapSize = OldPreviewSize;
04994             }
04995         }
04996     }
04997 
04998     
04999     TheDocument = pDoc;
05000 
05001     
05002 PORTNOTE("spread", "Multi-spread warning!")
05003     Spread *pSpread = GetFirstSpread(pDoc);
05004 
05005     
05006     if (!PrepareToExport(pFile, pSpread))
05007     {
05008         CleanUpAfterExport();
05009         return FALSE;
05010     }
05011 
05012     
05013     if (!ExportRender(ExportRegion))
05014     {
05015         CleanUpAfterExport();
05016         return FALSE;
05017     }
05018 
05019     
05020     CleanUpAfterExport();
05021 
05022     
05023     TheDocument = NULL;
05024 
05025     
05026     if ((WantPreviewBmp) && (pFilter!=NULL))
05027     {
05028         
05029         EPSEnd = pFile->tell();
05030 
05031         
05032         
05033         
05034         
05035         INT32 Length = EPSEnd - EPSStart;
05036         if (Length < 1024)
05037         {
05038             const TCHAR PadChar = '\n';
05039             
05040             FilePos CurrentPosition = pFile->tell();
05041             while ((CurrentPosition - EPSEnd) < 1024)
05042             {
05043                 if (pFile->put(PadChar).fail())
05044                     break;
05045                 CurrentPosition = pFile->tell();    
05046             }
05047             
05048         }
05049 
05050         
05051         if (!CorrectBinaryHeader(pFile))
05052         {
05053             ERROR1(FALSE, _R(IDT_EXPORT_INTERNAL_ERR));
05054         }
05055 
05056         
05057         RemoveMessage(pFile);
05058     }
05059 #endif
05060     return TRUE;
05061 }
05062 
05063 
05064 
05065 
05066 
05067 
05068 
05069 
05070 
05071 
05072 
05073 
05074 
05075 
05076 void EPSFilter::RemoveMessage(CCLexFile* pFile)
05077 {
05078 #ifdef DO_EXPORT
05079     
05080     TCHAR Message[] =  _T("1992 ACCUSOFT INC, ALL RIGHTS RESERVED");
05081     String_64 Replace(_T("Xara Studio, Xara Studio, Xara Studio."));
05082     INT32 Length = camStrlen(Message);
05083     TCHAR Ch = 0;
05084     FilePos StartOfStr = 0;
05085 
05086     try
05087     {
05088         
05089         if (pFile->seekIn(PreviewStart, ios::beg).fail())
05090             return;
05091 
05092         
05093         INT32 CharsToSearch = PreviewEnd - PreviewStart;
05094         INT32 MatchedChars = 0;
05095         
05096         
05097         char cch;
05098         pFile->get(cch);
05099         Ch=TCHAR(cch); 
05100         while ((!pFile->eof()) && (!pFile->fail()) && (MatchedChars<Length) && (CharsToSearch>0))
05101         {
05102             
05103             CharsToSearch--;
05104 
05105             
05106             if (Ch==Message[MatchedChars])
05107             {
05108                 
05109                 if (MatchedChars==0)
05110                 {
05111                     
05112                     
05113                     StartOfStr = pFile->tell() - 1;
05114                 }
05115 
05116                 
05117                 MatchedChars++;
05118             }
05119             else
05120             {
05121                 
05122                 MatchedChars=0;
05123             }
05124 
05125             
05126             char cch;
05127             pFile->get(cch);
05128             Ch=TCHAR(cch); 
05129         }
05130 
05131         
05132         if (MatchedChars==Length)
05133         {
05134             
05135             pFile->seek(StartOfStr);
05136             pFile->write(Replace);
05137             TRACEUSER( "Rik", _T("Replaced copyright\n"));
05138         }
05139     }
05140 
05141     catch(CFileException)
05142     {
05143         
05144         return;
05145     }
05146     
05147 #endif
05148 }
05149 
05150 
05151 
05152 
05153 
05154 
05155 
05156 
05157 
05158 
05159 
05160 
05161 
05162 
05163 
05164 
05165 
05166 
05167 
05168 
05169 
05170 
05171 INT32 EPSFilter::ImportBinary(ADDR pData, INT32 Length)
05172 {
05173     do
05174     {
05175         
05176         if (!EPSFile->GetHexToken())
05177             return FALSE;
05178 
05179         INT32 CharsRead = EPSFile->GetCharsRead();
05180 
05181         if (CharsRead > (LastProgressUpdate + 2048))
05182         {
05183             if (!ContinueSlowJob(CharsRead))
05184             {
05185                 
05186                 ERROR(_R(IDT_IMPORT_USERABORT), FALSE);
05187             }
05188             else
05189             {
05190                 LastProgressUpdate = CharsRead;
05191             }
05192         }
05193 
05194         
05195         if (EPSFile->GetTokenType() == TOKEN_STRING)
05196             
05197             break;
05198 
05199         
05200         INT32 nBytes = DecodeHexString(pData, Length);
05201 
05202         if (nBytes == -1)
05203         {
05204             
05205             ENSURE(FALSE, "Error in EPS hex data");
05206             break;
05207         }
05208 
05209         pData += nBytes;
05210         Length -= nBytes;
05211     }
05212     while ((Length > 0) && !EPSFile->eof());
05213 
05214     if (Length == 0)
05215         
05216         return TRUE;
05217     
05218     
05219     ENSURE(FALSE, "Error importing binary data from EPS file");
05220     return FALSE;
05221 }
05222 
05223 
05224 
05225 
05226 
05227 
05228 
05229 
05230 
05231 
05232 
05233 
05234 
05235 
05236 
05237 
05238 
05239 
05240 
05241 
05242 INT32 EPSFilter::DecodeHexString(ADDR pData, INT32 Length, INT32 nStart)
05243 {
05244     INT32 TokenLen = camStrlen(TokenBuf + nStart);
05245     INT32 Ofs = 0;
05246 
05247     
05248     ENSURE((TokenLen & 1) == 0, "Bad hex string length in DecodeHexString");
05249 
05250     
05251     INT32 MaxOfs = Length * 2;
05252 
05253     
05254     for (INT32 i = nStart; (i < TokenLen) && (i < MaxOfs); i += 2)
05255     {
05256         TCHAR Ch = camToupper(TokenBuf[i]);
05257         BYTE Byte;
05258 
05259         
05260         if ((Ch >= '0') && (Ch <= '9'))
05261         {
05262             Byte = (BYTE) (Ch - '0');
05263         }
05264         else if ((Ch >= 'A') && (Ch <= 'F'))
05265         {
05266             Byte = (BYTE) (Ch - 'A') + 10;
05267         }
05268         else
05269         {
05270             
05271             return -1;
05272         }
05273 
05274         Ch = camToupper(TokenBuf[i+1]);
05275         Byte <<= 4;
05276             
05277         
05278         if ((Ch >= '0') && (Ch <= '9'))
05279         {
05280             Byte |= (BYTE) (Ch - '0');
05281         }
05282         else if ((Ch >= 'A') && (Ch <= 'F'))
05283         {
05284             Byte |= (BYTE) (Ch - 'A') + 10;
05285         }
05286         else
05287         {
05288             
05289             return -1;
05290         }
05291 
05292         pData[Ofs++] = Byte;
05293     }
05294 
05295     
05296     return Ofs;
05297 }
05298 
05299 
05300 
05301 
05302 
05303 
05304 
05305 
05306 
05307 
05308 
05309 
05310 
05311 
05312 
05313 BOOL EPSFilter::ResetImportOrigin()
05314 {
05315     
05316     Page *pPage = ImportInfo.pSpread->FindFirstPageInSpread(); 
05317     ERROR2IF(pPage==NULL, FALSE, "Spread has no pages");
05318 
05319     
05320     DocRect PageRect = pPage->GetPageRect();
05321     Stack.SetCoordOrigin(PageRect.lo);
05322 
05323     
05324     return TRUE;
05325 }
05326 
05327 
05328 
05329 
05330 
05331 
05332 
05333 
05334 
05335 
05336 
05337 
05338 
05339 
05340 BOOL EPSFilter::ResetImportOrigin(DocCoord NewOrigin)
05341 {
05342     Stack.SetCoordOrigin(NewOrigin);
05343 
05344     
05345     return TRUE;
05346 }
05347 
05348 
05349 
05350 
05351 
05352 
05353 
05354 
05355 
05356 
05357 
05358 
05359 
05360 
05361 
05362 BOOL EPSFilter::ProcessText()
05363 {
05364     INT32 Type;
05365     Stack.Pop(&Type);
05366     Node *OldPos = pNode;
05367     BOOL PastAnEOL = FALSE;
05368 
05369     
05370     if ((Type!=0) && (Type!=2))
05371         return TRUE;
05372 
05373     
05374     Matrix StoryMat;
05375     if (!GetStoryMatrix(&StoryMat))
05376     {
05377         HandleEPSError();
05378         return FALSE;
05379     }   
05380 
05381     
05382     TextStory *TheStory = new TextStory();  
05383     AddNewNode(TheStory);
05384 
05385     
05386     TheStory->SetStoryMatrix(StoryMat);
05387 
05388     
05389     pNode = TheStory;
05390 
05391     while (!EPSFile->eof())
05392     {
05393         GetToken();
05394 
05395         switch (Token)
05396         {
05397             
05398             case EPSC_To:   
05399             {
05400                 ERROR2RAW("Bad Error in EPS .. TextObject inside TextObject !");
05401                 goto error;
05402             }
05403 
05404             
05405             case EPSC_TO:   
05406             {
05407                 if (!TheStory->AttachCaretAttributes())
05408                     goto error;
05409 
05410                 
05411                 TextLine * pLine = TheStory->FindLastLine ();
05412                 if (!pLine->FindEOLNode ())
05413                 {
05414                     EOLNode* pEOL = new EOLNode(); 
05415                     if (!AddNewNode(pEOL))
05416                         goto error;
05417                 }
05418 
05419                 pNode = OldPos;
05420                 return TRUE;
05421             }
05422 
05423             
05424             case EPSC_Tr:
05425             {
05426                 INT32 Style;
05427                 if (!Stack.Pop(&Style))
05428                     goto error;
05429                 
05430                 switch (Style)
05431                 {
05432                     case 0: 
05433                             SetStrokeColourNone();
05434                             break;
05435                     case 1: 
05436                             SetFillColourNone();
05437                             break;
05438                     case 2: 
05439                             break;
05440                     case 3: 
05441                             SetStrokeColourNone();
05442                             SetFillColourNone();
05443                             break;
05444                 }
05445                 break;
05446             }
05447 
05448             case EPSC_Tx:
05449             case EPSC_Tj:
05450             case EPSC_TX:   
05451             {                   
05452                 
05453                 if (PastAnEOL)
05454                 {
05455                     MakeNewTextLine(TheStory);
05456                     PastAnEOL = FALSE;
05457                 }
05458 
05459                 String_256 Text;
05460 
05461                 if (!Stack.Pop(&Text))
05462                     goto error;
05463 
05464                 TCHAR * buf = (TCHAR*)Text;
05465                 INT32 len = Text.Length();
05466             
05467                 TextChar* pCh = NULL;
05468                 
05469                 for ( INT32 i = 0; i < len; i++)
05470                 {
05471                     
05472                     if (buf[i]==_T('\r'))
05473                     {
05474                         PastAnEOL = TRUE;
05475 
05476                         EOLNode* pEOL = new EOLNode(); 
05477                         if (!AddNewNode(pEOL))
05478                             goto error;
05479 
05480                         if (!AttributeManager::ApplyBasedOnDefaults(pEOL,CurrentAttrs))
05481                             goto error;
05482                     }
05483                     
05484                     
05485                     
05486                     else if (Token != EPSC_TX)
05487                     {
05488                         
05489                         pCh = new TextChar();
05490                         if (pCh == NULL)
05491                             goto error;
05492 
05493                         pCh->SetUnicodeValue((WCHAR)buf[i]);
05494 
05495                         
05496                         if (!SetPathFilled(TRUE))
05497                             goto error;
05498 
05499                         if(!AddNewNode(pCh))
05500                             goto error;
05501 
05502                         if (!AttributeManager::ApplyBasedOnDefaults(pCh,CurrentAttrs))
05503                             goto error;
05504                     }
05505                 }
05506 
05507                 
05508                 break;
05509             }
05510 
05511 
05512             case EPSC_T_:
05513             {                   
05514                 
05515                 
05516                 
05517                 
05518 
05519                 break;
05520             }
05521 
05522             
05523             case EPSC_TP:   
05524             {
05525                 if (!MakeNewTextLine(TheStory))
05526                     goto error;
05527 
05528                 CaretNode* pCaret = new CaretNode(); 
05529                 if (!AddNewNode(pCaret))
05530                     goto error;
05531 
05532                 break;
05533             }
05534             
05535             
05536             case EPSC_Tz:   
05537             {
05538                 double Aspect;
05539                 if (!Stack.Pop(&Aspect))
05540                     goto error;
05541                 if (!SetTextAspectRatio(FIXED16(Aspect/100.0))) 
05542                     goto error;
05543                 break;
05544             }
05545             
05546             
05547             case EPSC_Tt:   
05548             {
05549                 INT32 Tracking;
05550                 if (!Stack.Pop(&Tracking))
05551                     goto error;
05552                 if (!SetTextTracking(Tracking))
05553                     goto error;
05554                 break;
05555             }
05556 
05557             case EPSC_Ta:   
05558             {
05559                 Justification JustVal=JLEFT;
05560                 INT32 Justify;
05561                 if (!Stack.Pop(&Justify))
05562                     goto error;
05563                 switch (Justify)
05564                 {
05565                 case 0:
05566                     JustVal = JLEFT; 
05567                     break;
05568                 case 2:
05569                     JustVal = JRIGHT; 
05570                     break;
05571                 case 1:
05572                     JustVal = JCENTRE; 
05573                     break;
05574                 case 3:
05575                     JustVal = JFULL; 
05576                     break;
05577                 }
05578                 if (!SetTextJustification(JustVal))
05579                     goto error;
05580                 break;
05581             }
05582 
05583             
05584             case EPSC_Tl:
05585             {
05586                 double lineLead, paraLead;
05587                     
05588                 if (!Stack.Pop(¶Lead))
05589                     goto error;
05590                 
05591                 if (!Stack.Pop(&lineLead))
05592                     goto error;
05593                 
05594                 
05595                 INT32 lead = (INT32)(lineLead*1000);
05596 
05597                 if (!SetTextLineSpacing(1,0,lead,0))
05598                     goto error;
05599                 
05600                 break;
05601             }
05602             
05603             
05604             
05605             case EPSC_Tk:   
05606             {
05607 
05608                 
05609                 if (PastAnEOL)
05610                 {
05611                     MakeNewTextLine(TheStory);
05612                     PastAnEOL = FALSE;
05613                 }
05614 
05615                 INT32 AutoKern;
05616                 DocCoord KernValue;
05617 
05618                 KernCode* pKernCode = new KernCode(); 
05619                 if (!pKernCode)
05620                     goto error;
05621 
05622                 if (!Stack.Pop(&KernValue.x))
05623                     goto error;
05624 
05625                 if (!Stack.Pop(&AutoKern))
05626                     goto error;
05627 
05628                 pKernCode->SetValue(KernValue); 
05629 
05630                 if (!AddNewNode(pKernCode))
05631                     goto error;
05632 
05633                 if (!AttributeManager::ApplyBasedOnDefaults(pKernCode,CurrentAttrs))
05634                     goto error;
05635 
05636                 break;
05637             }
05638 
05639             
05640             case EPSC_Ts:   
05641             {
05642                 double BaseShift;
05643 
05644                 if (!Stack.Pop(&BaseShift))
05645                     goto error;
05646 
05647                 INT32 RealShift = (INT32)(BaseShift*1000+0.5);
05648 
05649                 if (TextComment[0]>0)
05650                 {
05651                     TextComment[1]=RealShift;
05652                     TextComment[0]--;
05653                     if (TextComment[0]==0)
05654                     {
05655                         if (!SetTextScript(TextComment[1], TextComment[2]))
05656                             goto error;
05657                         TextComment[1]=0;
05658                         TextComment[2]=0;
05659                     }
05660                 }
05661                 else
05662                 {
05663                     if (!SetTextBaseLine(RealShift))
05664                         goto error;
05665                 }
05666                 break;
05667             }
05668             
05669             
05670             case EPSC_Tf:   
05671             {
05672                 String_64 EncodedName;
05673                 double FSize;
05674 
05675                 
05676                 if (!Stack.Pop(&FSize))
05677                     goto error;
05678 
05679                 
05680                 
05681                 
05682                 
05683                 
05684                 if ( !Stack.Pop ( &EncodedName ) )
05685                 {
05686                     
05687                     
05688                     
05689 
05690                     
05691                     if ( !Stack.Pop ( &FSize ) )
05692                         goto error;
05693 
05694                     
05695                     if ( !Stack.Pop ( &EncodedName ) )
05696                         goto error;
05697                 }
05698 
05699                 
05700                 INT32 MillFSize = (INT32)(FSize*1000+0.5);
05701 
05702                 
05703                 if (TextComment[0]>0)
05704                 {
05705                     TextComment[2]=MillFSize;
05706                     TextComment[0]--;   
05707                     if (TextComment[0]==0)
05708                     {
05709                         if (!SetTextScript(TextComment[1], TextComment[2]))
05710                             goto error;
05711                         TextComment[1]=0;
05712                         TextComment[2]=0;
05713                     }
05714                 }
05715                 else
05716                 {
05717                     if (!SetTextFont(&EncodedName, MillFSize))
05718                         goto error;
05719                 }
05720                 break;
05721             }
05722 
05723             
05724             
05725             
05726             
05727             
05728             
05729             
05730             
05731             
05732 
05733             case EPSC_ctx:
05734             {
05735                 INT32 numc=0, ch, i, buff[256];
05736                 TextChar* pCh = NULL;
05737 
05738                 
05739                 if (PastAnEOL)
05740                 {
05741                     MakeNewTextLine(TheStory);
05742                     PastAnEOL = FALSE;
05743                 }
05744 
05745                 
05746                 if (!Stack.Pop(&numc))
05747                     goto error;
05748 
05749                 if (numc>255)
05750                     goto error;
05751 
05752                 for (i=0; i<numc; i++)
05753                 {
05754                     if (!Stack.Pop(&ch))
05755                         goto error;
05756 
05757                     buff[i]=ch;
05758                 }
05759 
05760                 for (i=(numc-1); i>=0; i--)
05761                 {
05762                     
05763                     pCh = new TextChar();
05764                     if (pCh == NULL)
05765                         goto error;
05766 
05767                     pCh->SetUnicodeValue((WCHAR)buff[i]);
05768 
05769                     
05770                     if (!SetPathFilled(TRUE))
05771                         goto error;
05772 
05773                     if (!AddNewNode(pCh))
05774                         goto error;
05775 
05776                     if (!AttributeManager::ApplyBasedOnDefaults(pCh,CurrentAttrs))
05777                         goto error;
05778                 }
05779             
05780                 break;
05781             }
05782 
05783             case EPSC_ctex:
05784             {
05785                 
05786                 INT32 version;
05787 
05788                 if (!Stack.Pop(&version))
05789                     goto error;
05790 
05791                 switch (version)
05792                 {
05793                     case 0:
05794                         double Scale,Aspect,Rotation,Shear;
05795                         INT32 AsShapes, WordWrapping;
05796                         MILLIPOINT StoryWidth;
05797                         
05798                         if (!Stack.Pop(&AsShapes))
05799                             goto error;
05800                         if (!Stack.Pop(&Shear))
05801                             goto error;
05802                         if (!Stack.Pop(&Rotation))
05803                             goto error;
05804                         if (!Stack.Pop(&Aspect))
05805                             goto error;
05806                         if (!Stack.Pop(&Scale))
05807                             goto error;
05808                         if (!Stack.Pop(&StoryWidth))
05809                             StoryWidth = 0;
05810                         if (!Stack.Pop(&WordWrapping))
05811                             WordWrapping = FALSE;
05812 
05813                         
05814                         TheStory->SetWordWrapping(WordWrapping);
05815                         TheStory->SetStoryWidth(StoryWidth);
05816                         TheStory->SetCharsScale(Scale);
05817                         TheStory->SetCharsAspect(Aspect);
05818                         TheStory->SetCharsRotation(Rotation);
05819                         TheStory->SetCharsShear(Shear);
05820                         TheStory->SetPrintingAsShapes(AsShapes);
05821 
05822                         break;
05823 
05824                     default:
05825                         
05826                         if (!Stack.Discard())
05827                             goto error;
05828                 }
05829 
05830                 break;
05831             }
05832 
05833             default:
05834                 if (!HandleToken())
05835                     goto error;
05836                 break;
05837         }
05838     }
05839 
05840 error:
05841     pNode = OldPos; 
05842 
05843     HandleEPSError();
05844     return FALSE;
05845 }
05846 
05847 
05848 
05849 
05850 
05851 
05852 
05853 
05854 
05855 
05856 
05857 
05858 
05859 
05860 
05861 
05862 BOOL EPSFilter::GetStoryMatrix(Matrix* pMatrix)
05863 {
05864     while (!EPSFile->eof())
05865     {
05866         GetToken();
05867 
05868         
05869         switch (Token)
05870         {
05871             case EPSC_Tp:   
05872             {
05873                 INT32 StartDist;
05874                 if (!Stack.Pop(&StartDist))
05875                     return FALSE;
05876 
05877                 if (!Stack.Pop(pMatrix, FALSE))
05878                     return FALSE;
05879 
05880                 
05881                 
05882                 ProcessTextMatrix(pMatrix);
05883 
05884                 return TRUE;                        
05885             }
05886             default:
05887                 if(!HandleToken())
05888                     return FALSE;
05889                 break;
05890         }
05891     }
05892 
05893     HandleEPSError();
05894     return FALSE;
05895 }
05896 
05897 
05898 
05899 
05900 
05901 
05902 
05903 
05904 
05905 
05906 
05907 
05908 
05909 
05910 
05911 void EPSFilter::ProcessTextMatrix(Matrix* pMatrix)
05912 {
05913     
05914 }
05915 
05916 
05917 
05918 
05919 
05920 
05921 
05922 
05923 
05924 
05925 
05926 
05927 
05928 BOOL EPSFilter::MakeNewTextLine(Node * pParent)
05929 {
05930     pNode = pParent;
05931     TextLine* pTextLine = new TextLine(); 
05932     if(!AddNewNode(pTextLine))
05933         return FALSE;
05934     
05935     pNode = pTextLine;
05936     return TRUE;
05937 }
05938 
05939 
05940 
05941 
05942 
05943 
05944 
05945 
05946 
05947 
05948 
05949 
05950 
05951 
05952 
05953 
05954 
05955 
05956 BOOL EPSFilter::SetStrokeColourNone()
05957 {
05958     
05959     ENSURE(CurrentAttrs != NULL, "No current attributes in filter!");
05960 
05961     
05962     
05963     if (!CurrentAttrs[ATTR_STROKECOLOUR].Temp)
05964     {
05965         
05966         CurrentAttrs[ATTR_STROKECOLOUR].pAttr = new StrokeColourAttribute();
05967         if (CurrentAttrs[ATTR_STROKECOLOUR].pAttr == NULL)
05968             return FALSE;
05969         CurrentAttrs[ATTR_STROKECOLOUR].Temp = TRUE;
05970     }
05971 
05972     
05973     StrokeColourAttribute* pLineCol = (StrokeColourAttribute*)CurrentAttrs[ATTR_STROKECOLOUR].pAttr;
05974     DocColour none(COLOUR_NONE);
05975     pLineCol->SetStartColour(&none);
05976     
05977     return TRUE;
05978 }
05979 
05980 
05981 
05982 
05983 
05984 
05985 
05986 
05987 
05988 
05989 
05990 
05991 
05992 
05993 
05994 
05995 BOOL EPSFilter::SetFillColourNone()
05996 {
05997     
05998     ENSURE(CurrentAttrs != NULL, "No current attributes in filter!");
05999 
06000     
06001     
06002     if (!CurrentAttrs[ATTR_FILLGEOMETRY].Temp)
06003     {
06004         
06005         CurrentAttrs[ATTR_FILLGEOMETRY].pAttr = new FlatFillAttribute();
06006         if (CurrentAttrs[ATTR_FILLGEOMETRY].pAttr == NULL)
06007             return FALSE;
06008         CurrentAttrs[ATTR_FILLGEOMETRY].Temp = TRUE;
06009     }
06010 
06011     
06012     FlatFillAttribute* pFillCol = (FlatFillAttribute*)CurrentAttrs[ATTR_FILLGEOMETRY].pAttr;
06013     DocColour none(COLOUR_NONE);
06014     pFillCol->SetStartColour(&none);
06015     
06016     return TRUE;
06017 }
06018 
06019 
06020 
06021 
06022 
06023 
06024 
06025 
06026 
06027 
06028 
06029 
06030 
06031 
06032 
06033 
06034 
06035 BOOL EPSFilter::ProcessRectangle(NodeRect* pRect, NodeRegularShape* pQuickShape)
06036 {
06037     BOOL ok = TRUE;
06038 
06039     if ((pRect != NULL) && (pQuickShape != NULL) && (pRect->InkPath.GetNumCoords() == 5))
06040     {
06041         if (ok)
06042             ok = pQuickShape->SetUpShape();
06043         DocCoord *Points = pRect->InkPath.GetCoordArray();
06044         if (ok && pQuickShape->MakeRectangle((INT32)(Points[0].Distance(Points[1])),
06045                                         (INT32)(Points[1].Distance(Points[2])),0))
06046         {
06047             
06048             
06049             DocCoord Centre = DocCoord::OneHalf(Points[0], Points[2]);
06050             DocCoord RenderMajor = DocCoord::OneHalf(Points[0], Points[1]);
06051 
06052             double RotAngle = atan2((double)RenderMajor.y-Centre.y,(double)RenderMajor.x-Centre.x) - (PI/2);
06053             
06054 
06055             Matrix  mat( ANGLE( RotAngle * ( 180 / PI ) ) );
06056             Trans2DMatrix TransMat( mat );
06057             TransMat *= Trans2DMatrix(Centre.x,Centre.y);
06058             pQuickShape->Transform(TransMat);
06059         }
06060         else
06061         {
06062             ERROR3("MakeRectangle failed");
06063             ok = FALSE;
06064         }
06065     }
06066     else
06067     {
06068         ERROR3("Bad rectangle path in EPS import!");
06069         ok = FALSE;
06070     }
06071 
06072     return ok;
06073 }
06074 
06075 
06076 
06077 
06078 
06079 
06080 
06081 
06082 
06083 
06084 
06085 
06086 
06087 
06088 
06089 
06090 
06091 BOOL EPSFilter::ProcessEllipse(NodeEllipse* pEllipse, NodeRegularShape* pQuickShape)
06092 {
06093     BOOL ok = TRUE;
06094 
06095     if ((pEllipse != NULL) && (pQuickShape != NULL) && (pEllipse->InkPath.GetNumCoords() == 13))
06096     {
06097         if (ok)
06098             ok = pQuickShape->SetUpShape();
06099         const DocCoord Centre = DocCoord::OneHalf(ShapeBBox[0], ShapeBBox[2]);
06100         const double Height = DocCoord::DistanceFromLine(ShapeBBox[0], ShapeBBox[1], Centre);
06101         const double Width = DocCoord::DistanceFromLine(ShapeBBox[1], ShapeBBox[2], Centre);
06102 
06103         if (ok && pQuickShape->MakeEllipse((INT32)Width, (INT32)Height))
06104         {
06105             
06106             
06107             DocCoord RenderMajor = DocCoord::OneHalf(ShapeBBox[0], ShapeBBox[1]);
06108 
06109             double RotAngle = atan2((double)RenderMajor.y-Centre.y,(double)RenderMajor.x-Centre.x) - (PI/2);
06110             
06111 
06112             Matrix mat( ANGLE( RotAngle * ( 180 / PI ) ) );
06113             Trans2DMatrix TransMat( mat );
06114             TransMat *= Trans2DMatrix(Centre.x,Centre.y);
06115             pQuickShape->Transform(TransMat);
06116         }
06117         else
06118         {
06119             ERROR3("MakeEllipse failed");
06120             ok = FALSE;
06121         }
06122     }
06123     else
06124     {
06125         ERROR3("Bad ellipse path in EPS import!");
06126         ok = FALSE;
06127     }
06128 
06129     return ok;
06130 }
06131 
06132 
06133 
06134 
06135 
06136 
06137 
06138 
06139 
06140 
06141 
06142 
06143 class EPSSavedGraphicState : public ListItem
06144 {
06145     CC_DECLARE_MEMDUMP(EPSSavedGraphicState);
06146 
06147 public:
06148     EPSSavedGraphicState();
06149     ~EPSSavedGraphicState();
06150     BOOL Setup();
06151 
06152 public:
06153     NodePath *pPath;
06154     INT32 ThePathType;
06155     AttributeEntry *Attrs;
06156     EPSFlagsDefn EPSFlags;
06157 };
06158 
06159 CC_IMPLEMENT_MEMDUMP(EPSSavedGraphicState, ListItem)
06160 
06161 
06162 
06163 
06164 
06165 
06166 
06167 
06168 
06169 
06170 
06171 
06172 
06173 
06174 EPSSavedGraphicState::EPSSavedGraphicState()
06175 {
06176     pPath = 0;
06177     Attrs = 0;
06178 }
06179 
06180 
06181 
06182 
06183 
06184 
06185 
06186 
06187 
06188 
06189 
06190 
06191 
06192 
06193 
06194 BOOL EPSSavedGraphicState::Setup()
06195 {
06196     
06197     INT32 NumAttrs = AttributeManager::GetNumAttributes();
06198 
06199     
06200     Attrs = new AttributeEntry[NumAttrs];
06201 
06202     
06203     for (INT32 i = 0; i < NumAttrs; i++)
06204     {
06205         Attrs[i].pAttr = 0;
06206         Attrs[i].Temp = FALSE;
06207         Attrs[i].Ignore = FALSE;
06208     }
06209 
06210     
06211     return TRUE;
06212 }
06213 
06214 
06215 
06216 
06217 
06218 
06219 
06220 
06221 
06222 
06223 
06224 
06225 
06226 
06227 
06228 EPSSavedGraphicState::~EPSSavedGraphicState()
06229 {
06230     if(pPath != 0)
06231     {
06232         pPath->CascadeDelete();
06233         delete pPath;
06234     }
06235 
06236     if(Attrs != 0)
06237     {
06238         
06239         INT32 NumAttrs = AttributeManager::GetNumAttributes();
06240 
06241         
06242         for (INT32 i = 0; i < NumAttrs; i++)
06243         {
06244             if((Attrs[i].pAttr != 0) && (Attrs[i].Temp == TRUE))
06245                 delete Attrs[i].pAttr;
06246         }
06247 
06248         
06249         delete [] Attrs;
06250     }
06251 }
06252 
06253 
06254 
06255 
06256 
06257 
06258 
06259 
06260 
06261 
06262 
06263 
06264 
06265 
06266 
06267 BOOL EPSFilter::Import_gsave()
06268 {
06269     
06270     EPSSavedGraphicState *State = new EPSSavedGraphicState;
06271 
06272     if(State == 0 || !State->Setup())
06273     {
06274         delete State;
06275         return FALSE;
06276     }
06277 
06278     
06279     if(pPath != 0)
06280     {
06281         if(!pPath->NodeCopy((Node **)&State->pPath))
06282         {
06283             delete State;
06284             return FALSE;
06285         }
06286     }
06287     else
06288     {
06289         State->pPath = 0;
06290     }
06291 
06292 
06293     State->ThePathType = ThePathType;
06294 
06295     
06296     State->EPSFlags = EPSFlags;
06297 
06298     
06299 
06300     
06301     INT32 NumAttrs = AttributeManager::GetNumAttributes();
06302 
06303     
06304     for (INT32 i = 0; i < NumAttrs; i++)
06305     {
06306         if(CurrentAttrs[i].pAttr != 0)
06307         {
06308             if(CurrentAttrs[i].Temp)
06309             {
06310                 
06311                 CCRuntimeClass* ObjectType = CurrentAttrs[i].pAttr->GetRuntimeClass();
06312                 AttributeValue* AttrClone = (AttributeValue*)ObjectType->CreateObject();
06313 
06314                 if(AttrClone == 0)
06315                 {
06316                     delete State;
06317                     return FALSE;
06318                 }
06319 
06320                 AttrClone->SimpleCopy(CurrentAttrs[i].pAttr);
06321 
06322                 
06323                 State->Attrs[i].pAttr = AttrClone;
06324             }
06325             else
06326             {
06327                 State->Attrs[i].pAttr = CurrentAttrs[i].pAttr;
06328             }
06329         }
06330         else
06331         {
06332             State->Attrs[i].pAttr = 0;
06333         }
06334         State->Attrs[i].Temp = CurrentAttrs[i].Temp;
06335         State->Attrs[i].Ignore = CurrentAttrs[i].Ignore;
06336     }
06337 
06338     
06339     GraphicStateStack.AddTail(State);
06340 
06341     return TRUE;
06342 }
06343 
06344 
06345 
06346 
06347 
06348 
06349 
06350 
06351 
06352 
06353 
06354 
06355 
06356 
06357 
06358 BOOL EPSFilter::Import_grestore()
06359 {
06360     
06361     EPSSavedGraphicState *State = (EPSSavedGraphicState *)GraphicStateStack.GetTail();
06362 
06363     if(State == 0)
06364     {
06365         
06366         return FALSE;
06367     }
06368 
06369     
06370     if(pPath != 0)
06371     {
06372         pPath->CascadeDelete();
06373         delete pPath;
06374         pPath = 0;
06375         pInkPath = 0;
06376     }
06377     pPath = State->pPath;
06378     State->pPath = 0;
06379     ThePathType = (EPSFilter::PathType)State->ThePathType;
06380     if(pPath != 0)
06381     {
06382         pInkPath = &pPath->InkPath;
06383     }
06384     else
06385     {
06386         pInkPath = 0;
06387     }
06388 
06389     
06390     EPSFlags = State->EPSFlags;
06391 
06392     
06393     
06394     INT32 NumAttrs = AttributeManager::GetNumAttributes();
06395 
06396     
06397     for (INT32 i = 0; i < NumAttrs; i++)
06398     {
06399         
06400         if(CurrentAttrs[i].Temp && CurrentAttrs[i].pAttr != 0)
06401         {
06402             delete CurrentAttrs[i].pAttr;
06403             CurrentAttrs[i].pAttr = 0;
06404         }
06405             
06406         
06407         CurrentAttrs[i].pAttr = State->Attrs[i].pAttr;
06408         State->Attrs[i].pAttr = 0;
06409         
06410         CurrentAttrs[i].Temp = State->Attrs[i].Temp;    
06411         CurrentAttrs[i].Ignore = State->Attrs[i].Ignore;
06412     }
06413 
06414     
06415     delete GraphicStateStack.RemoveItem(State);
06416 
06417     return TRUE;
06418 }