00001 
00002 
00003 
00004 
00005 
00006 
00007 
00008 
00009 
00010 
00011 
00012 
00013 
00014 
00015 
00016 
00017 
00018 
00019 
00020 
00021 
00022 
00023 
00024 
00025 
00026 
00027 
00028 
00029 
00030 
00031 
00032 
00033 
00034 
00035 
00036 
00037 
00038 
00039 
00040 
00041 
00042 
00043 
00044 
00045 
00046 
00047 
00048 
00049 
00050 
00051 
00052 
00053 
00054 
00055 
00056 
00057 
00058 
00059 
00060 
00061 
00062 
00063 
00064 
00065 
00066 
00067 
00068 
00069 
00070 
00071 
00072 
00073 
00074 
00075 
00076 
00077 
00078 
00079 
00080 
00081 
00082 
00083 
00084 
00085 
00086 
00087 
00088 
00089 
00090 
00091 
00092 
00093 
00094 
00095 
00096 
00097 
00098 
00099 
00100 
00101 
00102 
00103 
00104 
00105 
00106 
00107 #include "camtypes.h"
00108 
00109 #include "camconfig.h"
00110 
00111 
00112 
00113 
00114 
00115 
00116 
00117 #include "bitmpinf.h"
00118 #include "camelot.h"
00119 
00120 #include "camview.h"
00121 
00122 #include "colormgr.h"
00123 
00124 
00125 
00126 #include "devcolor.h"
00127 
00128 
00129 
00130 
00131 
00132 #include "f16spec.h"            
00133 
00134 
00135 
00136 
00137 #include "fuzzclip.h"
00138 
00139 #include "gbrush.h"             
00140 
00141 
00142 #include "XaDraw.h"             
00143 
00144 #include "gdrawcon.h"
00145 #include "gradtbl.h"
00146 
00147 
00148 
00149 #include "cstroke.h"            
00150 
00151 
00152 
00153 
00154 
00155 
00156 #include "grndprnt.h"
00157 #include "grndrgn.h"
00158 
00159 
00160 
00161 
00162 #include "moldpers.h"
00163 
00164 
00165 
00166 #include "osrndrgn.h"
00167 #include "palman.h"
00168 
00169 
00170 
00171 #include "princomp.h"
00172 #include "printctl.h"
00173 
00174 #include "qualattr.h"
00175 
00176 
00177 #include "oilbitmap.h"
00178 
00179 #include "fillramp.h"
00180 #include "bubbleid.h"
00181 #include "grndclik.h"
00182 
00183 #include <math.h>
00184 
00185 
00186 #include "offattr.h"
00187 #include "offscrn.h"
00188 
00189 
00190 #include "clipattr.h"   
00191 
00192 #include "maskedrr.h"
00193 #include "prdlgctl.h"
00194 
00195 #include "camprofile.h"
00196 #include "fillattr2.h"
00197 
00198 DECLARE_SOURCE("$Revision: 1699 $");
00199 
00200 
00201 
00202 CC_IMPLEMENT_DYNAMIC( GRenderRegion, RenderRegion )
00203 CC_IMPLEMENT_DYNCREATE(OpGDraw, Operation)
00204 
00205 #define new CAM_DEBUG_NEW
00206 
00207 
00208 
00209 #ifndef DIB_PAL_INDICES
00210 #define DIB_PAL_INDICES (2)
00211 #endif
00212 
00213 
00214 #ifdef _DEBUG
00215 
00216 
00217 
00218 #endif
00219 
00220 
00221 BOOL GRenderRegion::WantDoGDraw = TRUE;             
00222 UINT32 GRenderRegion::WantGDrawDepth;                   
00223 
00224 
00225 
00226 
00227 
00228 INT32  GRenderRegion::WhichTransparency = 0;            
00229 
00230 BOOL GRenderRegion::CanDoGDraw;                     
00231 
00232 
00233 
00234 
00235 BitmapConvertHint GRenderRegion::ScreenHinting;     
00236 
00237 INT32 GRenderRegion::ScreenDepth;                       
00238 INT32 GRenderRegion::ScreenWidth;                       
00239 INT32 GRenderRegion::ScreenHeight;                  
00240 INT32 GRenderRegion::LogPixelsX;
00241 INT32 GRenderRegion::LogPixelsY;
00242 
00243 GDrawContext *GRenderRegion::pRealGD = NULL;        
00244 
00245 GDrawContext *GRenderRegion::GD = NULL;             
00246 
00247 GDrawContext *GRenderRegion::ErrorDiffContext = NULL;   
00248 
00249 LPRGBQUAD GRenderRegion::Fixed256Palette;           
00250 
00251 
00252 
00253 
00254 
00255 INT32 GRenderRegion::ViewDither = 2;                    
00256 INT32  GRenderRegion::WhichDither = 2;              
00257 
00258 RealLogPalette GRenderRegion::ErrorDiffPalette =    
00259 {                                                   
00260     0x300,                                          
00261     256
00262 };
00263 
00264 static RealLogPalette StandardPalette = 
00265 {
00266     0x300,
00267     256
00268 };
00269 
00270 static BYTE NoTransTable[256];                      
00271 
00272 static BOOL ClippedPathIsValid;
00273 
00274 enum BlitModeType
00275 {
00276     BLITMODE_STRETCH,
00277     BLITMODE_SETDIBS,
00278     BLITMODE_BITBLT,
00279     BLITMODE_BADDDB
00280 } BlitMode;
00281 
00282 
00283 static INT32 LargeGradTables = 0;
00284       
00285 
00286 #define FILL_BITMAP 0
00287 
00288 
00289 
00290 
00291 
00292 
00293 
00294 
00295 
00296 
00297 
00298 
00299 
00300 UINT32 GRenderRegion::ClickTranspLimit = 255;
00301 
00302 
00303 
00304 
00305 
00306 
00307 
00308 
00309 
00310 
00311 
00312 
00313 BOOL GRenderRegion::HighQualityAA = FALSE;
00314 
00315 
00316 
00317 
00318 
00319 
00320 
00321 
00322 
00323 
00324 
00325 
00326 
00327 
00328 INT32 GRenderRegion::BitmapConversion = 2;
00329 
00330 
00331 
00332 
00333 
00334 
00335 
00336 
00337 
00338 
00339 
00340 
00341 
00342 
00343 
00344 
00345 
00346 
00347 
00348 
00349 
00350 
00351 
00352 
00353 
00354 
00355 
00356 
00357 
00358 
00359 
00360 
00361 
00362 
00363 
00364 
00365 
00366 
00367 
00368 
00369 
00370 
00371 
00372 
00373 
00374 
00375 
00376 
00377 
00378 
00379 
00380 
00381 
00382 
00383 
00384 
00385 
00386 
00387 
00388 
00389 
00390 
00391 
00392 
00393 
00394 
00395 
00396 
00397 
00398 
00399 
00400 
00401 
00402 
00403 
00404 
00405 
00406 
00407 
00408 
00409 
00410 
00411 
00412 
00413 
00414 
00415 
00416 
00417 
00418 
00419 
00420 
00421 
00422 
00423 
00424 
00425 
00426 
00427 
00428 
00429 
00430 
00431 
00432 
00433 
00434 
00435 
00436 
00437 
00438 
00439 
00440 
00441 
00442 
00443 
00445 
00446 
00447 
00448 
00449 #define REMEMBER_GDRAW  0
00450 
00451 #if REMEMBER_GDRAW
00452 
00453 static struct RemRR
00454 {
00455     GRenderRegion *RR;
00456     char *Where;
00457 } RememberList[256];                                        
00458 
00459 static INT32 RememberWhere = 0;
00460 
00461 static void DoRememberMe(GRenderRegion *lpG, char *name)
00462 {
00463     if (
00464         RememberWhere &&
00465         (RememberList[ RememberWhere-1 ].Where == name) &&  
00466         (RememberList[ RememberWhere-1 ].RR == lpG)
00467        )
00468         
00469         return;
00470 
00471     RememberList[ RememberWhere ].Where = name;
00472     RememberList[ RememberWhere ].RR = lpG;
00473 
00474     RememberWhere++;
00475     if (RememberWhere == 256)
00476         RememberWhere = 0;                                      
00477 
00478     #if REMEMBER_GDRAW==2
00479     TRACE( _T("%08lx %s\n"), lpG, name );
00480     #endif
00481 }
00482 
00483 static void DoRememberDump(GRenderRegion *lpG)
00484 {
00485     for (INT32 i=0; i<RememberWhere; i++)
00486         TRACE( _T("%08lx %s\n"), RememberList[i].RR, RememberList[i].Where);        
00487 }
00488 
00489 #define RememberMe(name)    DoRememberMe(this, name)
00490 #define RememberDump()      DoRememberDump(this)
00491 
00492 #else
00493 
00494 #define RememberMe(name)
00495 #define RememberDump()
00496 
00497 #endif
00498 
00499 
00500 
00501 
00502 
00503 
00504 
00505 
00506 
00507 
00508 
00509 
00510 
00511 
00512 
00513 
00514 
00515 
00516 BOOL GRenderRegion::Init( BOOL bFirstTime )
00517 {
00518     BOOL GDrawImpossible = FALSE;
00519 
00520     
00521 
00522     
00523     if (bFirstTime)
00524     {
00525         CanDoGDraw = FALSE;
00526 
00527         if (Camelot.DeclareSection( _T("DebugFlags"), 20))
00528         {
00529             Camelot.DeclarePref( NULL, _T("UseGdraw"), &WantDoGDraw, FALSE, TRUE );
00530             Camelot.DeclarePref( NULL, _T("GDrawDepth"), &WantGDrawDepth, 0, 32 );
00531 
00532 
00533 
00534 
00535             Camelot.DeclarePref( NULL, _T("WhichDither"), &WhichDither, 0, 20 );
00536 
00537 
00538 
00539 
00540         }
00541 
00542         if (Camelot.DeclareSection( _T("Screen"), 10))
00543         {
00544             Camelot.DeclarePref( NULL, _T("ClickTranspLimit"), &ClickTranspLimit, 0, 255 );
00545             
00546 
00547 
00548             Camelot.DeclarePref(NULL, _T("ViewDither"), &ViewDither, 0, 4);
00549         }
00550 
00551         if (Camelot.DeclareSection(_T("Rendering"), 20))
00552         {
00553             Camelot.DeclarePref( _T("Rendering"), _T("HighQualityAA"), &HighQualityAA, FALSE, TRUE );
00554             Camelot.DeclarePref( _T("Rendering"), _T("BitmapConversion"), &BitmapConversion, 0, 3 );
00555         }
00556 
00557         if (pRealGD == NULL)
00558             pRealGD = new GDrawAsm();                       
00559 
00560         
00561         for (INT32 i=0; i<256; i++)
00562             NoTransTable[i] = i;
00563     }
00564 
00565     
00566 
00567     
00568     
00569     DIBConvert::Init();
00570 
00571     ::wxDisplaySize(&ScreenWidth,&ScreenHeight);
00572     ScreenDepth = ::wxDisplayDepth();
00573     wxScreenDC dc;
00574     wxSize size = OSRenderRegion::GetFixedDCPPI(dc);
00575 PORTNOTE("other","Can't handle different DPIs, using X")
00576     LogPixelsX = size.x;
00577     LogPixelsY = size.y; 
00578     ERROR3IF(LogPixelsX != LogPixelsY, "Luke says non-square pixels are not supported");
00579 
00580 
00581 
00582     
00583     if (bFirstTime)
00584     {
00585         if (!pRealGD->Init())                           
00586         {
00587             GDrawImpossible = TRUE;
00588             CanDoGDraw = FALSE;
00589             Error::SetError( _R(IDW_BADGDRAW), NULL, 0 );
00590             InformWarning();                            
00591             Error::ClearError();                        
00592         }
00593         GD = pRealGD;
00594     }
00595 
00596 
00597 
00598 
00599 
00600 
00601 
00602 
00603 
00604 
00605     
00606 PORTNOTE("other","GRenderRegion::Init - Removed palette code")
00607 #ifndef EXCLUDE_FROM_XARALX
00608     if (
00609         ScreenDepth==8 &&               
00610         !WantNoPalette                  
00611        )
00612     {
00613         if (GetDeviceCaps( hdc, RASTERCAPS ) & RC_PALETTE )
00614             CanSetPalette = TRUE;
00615     }
00616 #endif
00617 
00618     ScreenHinting = CONVHINT_NONE;      
00619     if ( ScreenDepth<=8 )
00620         ScreenHinting = DIBUtil::CalcConvertHint(ScreenDepth,NULL);
00621     else
00622     {
00623         
00624         
00625     
00626     
00627     
00628     
00629     
00630         wxColour colour;
00631         dc.GetPixel(0,0,&colour);
00632         ScreenHinting = DIBUtil::CalcConvertHint(ScreenDepth,&dc);
00633         dc.SetPen(wxPen(colour));
00634         dc.DrawPoint(0,0);
00635     }
00636 
00637     if (
00638         !GDrawImpossible &&
00639         (
00640             ScreenDepth==1 ||
00641             ScreenDepth==4 ||
00642             ScreenDepth==8 ||                                   
00643             ScreenDepth==16 ||
00644             ScreenDepth==24 ||
00645             ScreenDepth==32
00646         )
00647        )
00648     {
00649         CanDoGDraw = TRUE;
00650 
00651 
00652 
00653 
00654 
00655 
00656 
00657 
00658         EnsurePalette(0);
00659         
00660         GD->SetStackSize(100*1024);
00661 
00662         if (ErrorDiffContext == NULL)
00663         {
00664             ErrorDiffContext = new GDrawAsm();          
00665 
00666             if (ErrorDiffContext)
00667                 ErrorDiffContext->Init();
00668         }
00669 
00670 
00671 
00672 
00673 
00674 
00675 
00676 
00677 
00678 
00679 
00680 
00681 
00682 
00683 
00684 
00685 
00686 
00687 
00688 
00689 
00690 
00691 
00692 
00693 
00694 
00695 
00696 
00697 
00698     }
00699 
00700 
00701 
00702 
00703 
00704 
00705 
00706 
00707 
00708 
00709 
00710 
00711 
00712 
00713 
00714 
00715 
00716 
00717 
00718 
00719 
00720 
00721 
00722 
00723 
00724 
00725 
00726 
00727 
00728 
00729 
00730 
00731 
00732 
00733 
00734 
00735     
00736     
00737     
00738 
00739     
00740 
00741 
00742 
00743 
00744 
00745 
00746 
00747 
00748 
00749     
00750 
00751 
00752 
00753     if (!Operation::RegisterOpDescriptor(
00754                         0,
00755                         _R(IDS_GDRAW),
00756                         CC_RUNTIME_CLASS(OpGDraw),
00757                         OPTOKEN_GDRAW,
00758                         OpGDraw::GetState,
00759                         0,  
00760                         _R(IDBBL_GDRAWOP),
00761                         0   
00762                         ))
00763         return FALSE; 
00764 
00765     if (!GBrush::InitGBrush( bFirstTime ))
00766         return FALSE;
00767 
00768     INT32 Flatness = INT32(MILLIPOINTS_PER_INCH/96 / 2);
00769     GD->SetFlatness( Flatness );
00770 
00771     return TRUE;
00772 }
00773 
00774 
00775 
00776 
00777 
00778 
00779 
00780 
00781 
00782 
00783 
00784 
00785 
00786 
00787 
00788 
00789 void GRenderRegion::DeInit()
00790 {
00791 
00792 
00793 
00794 
00795 
00796 
00797     ERROR3IF(GD != pRealGD, "GDraw context not restored in GRenderRegion::DeInit");
00798     
00799     GD = NULL;
00800 
00801     if (pRealGD)
00802     {
00803         delete pRealGD;
00804         pRealGD = NULL;
00805     }
00806 
00807     
00808     DIBConvert::DeInit();
00809 
00810     if (ErrorDiffContext != NULL)
00811     {
00812         delete ErrorDiffContext;
00813         ErrorDiffContext = NULL;
00814     }
00815 
00816 
00817 
00818     
00819 
00820     
00821     
00822     GBrush::DeinitGBrush();
00823 }
00824 
00825 
00826 #define DEBUG_BORDER    0
00827 
00828 
00829 
00830 
00831 
00832 
00833 
00834 
00835 
00836 
00837 
00838 
00839 
00840 
00841 
00842 
00843 
00844 
00845 
00846 
00847 
00848 
00849 
00850 GRenderRegion::GRenderRegion(DocRect ClipRegion, Matrix ConvertMatrix, FIXED16 ViewScale,
00851                                 UINT32 Depth, double dpi)
00852     : RenderRegion(ClipRegion, ConvertMatrix, ViewScale)
00853 {
00854     pBitmapInfo = NULL;
00855     pBits       = NULL;
00856 #if USE_wxBITMAP
00857     pBitmap     = NULL;
00858     pBitmapData = NULL;
00859 #endif
00860 
00861 
00862     
00863     
00864     if (dpi == 0.0)
00865         PixelsPerInch = (double)LogPixelsX;
00866     else
00867         PixelsPerInch = dpi;
00868     ERROR3IF(PixelsPerInch < 4.0,"GRenderRegion PixelsPerInch < 4 dpi, is this good?");
00869 
00870     hPalette = NULL;
00871     hPrevPalette = NULL;
00872     uBitmapDepth = Depth;
00873 
00874     UseSolidColours = FALSE;
00875     LocalBitmap = TRUE;                             
00876     m_bEnableConversion = TRUE;
00877     dScaledPixelWidth = 0.0;
00878 
00879     if (LocalBitmap)
00880     {
00881         WRect = wxRect(0,0,0,0);
00882 
00883         
00884         
00885 
00886         #if DEBUG_BORDER
00887         
00888         WRect.left += 2; WRect.width -= 4;
00889         WRect.top += 2; WRect.height -= 4;
00890         #endif
00891     }
00892     else
00893         ENSURE(FALSE, "Non local bitmap error");
00894 
00895     
00896     Timeslice = 500;
00897 
00898     
00899     DitherStyle8Bit = WhichDither;
00900 
00901     m_DoCompression = FALSE;
00902 
00903     m_bForceBitmapSmoothing = FALSE;
00904     m_ForcePrintingCaps = FALSE;
00905 
00906     
00907     GetRenderRegionCaps(&Caps);
00908 
00909     
00910     IsWrapped = FALSE;
00911 
00912     
00913     ForceInitBmpBits = FALSE;
00914 
00915     RememberMe("Constructor");
00916 }
00917 
00918 
00919 
00920 
00921 
00922 
00923 
00924 
00925 
00926 
00927 
00928 
00929 
00930 
00931 
00932 
00933 
00934 GRenderRegion::~GRenderRegion()
00935 {
00936 #ifdef RALPH
00937 #ifdef _DEBUG
00938     if(GetCurrentThreadId() == RalphDocument::GetImportingThreadID())
00939     {
00940         TRACE( _T("Whoop Whoop... GRenderRegion::~GRenderRegion called from load thread\n"));
00941         AfxDebugBreak();
00942     }
00943 #endif
00944 #endif
00945 
00946     if (RenderFlags.Rendering)
00947     {
00948         TRACE( _T("StopRender() was not called before destructor\n") );
00949         StopRender();
00950     }
00951 
00952 
00953 
00954     
00955     
00956     FreeStoredClipRegions();
00957 
00958     RememberMe("Destructor");
00959 }
00960 
00961 
00962 
00963 
00964 void GRenderRegion::FreeOffscreenState()
00965 {
00966     
00967     
00968     
00969     
00970     
00971 
00972     
00973     
00974     
00975     
00976     
00977     
00978 
00979     Capture* pCapture = NULL;
00980     while (GetTopCapture())
00981     {
00982         pCapture = GetTopCapture();
00983         m_CaptureStack.Pop();
00984 
00985         
00986         
00987         if (pCapture->IsMaster())
00988             SetRenderToCapture(pCapture, FALSE, FALSE);
00989         else
00990             pCapture->FreeDIB();
00991 
00992         delete pCapture;
00993     }
00994 
00995 #if USE_wxBITMAP
00996     FreeWxBitmap() ;
00997 #else
00998     if ( pBitmapInfo && pBits )
00999     {
01000         FreeLPBits( pBitmapInfo, pBits );
01001         pBitmapInfo = NULL;
01002         pBits = NULL;
01003     }
01004 #endif
01005 }
01006 
01007 BOOL GRenderRegion::CopyRenderInfo( const RenderRegion &Other)
01008 {
01009     RememberMe("CopyRenderInfo");
01010 
01011     if (!RenderRegion::CopyRenderInfo( Other ))
01012         return FALSE;
01013 
01014     ENSURE( Other.IsKindOf( CC_RUNTIME_CLASS(GRenderRegion) ) , "CopyRenderOther wrong class" );
01015 
01016     
01017     const GRenderRegion *GOther = (GRenderRegion*)&Other;
01018 
01019     
01020     LocalBitmap = GOther->LocalBitmap;
01021     if (LocalBitmap)
01022     {
01023         
01024         ScreenRect = wxRect(0,0,0,0);
01025     }
01026     else
01027     {
01028         
01029         WRect = GOther->WRect;
01030         ScreenRect = GOther->ScreenRect;
01031     }
01032 
01033     PixelsPerInch = GOther->PixelsPerInch;
01034     dScaledPixelWidth = GOther->dScaledPixelWidth;
01035     hPalette = GOther->hPalette;
01036     hPrevPalette = NULL;
01037 
01038     return TRUE;
01039 }
01040 
01041 
01042 
01043 
01044 
01045 
01046 
01047 
01048 
01049 void GRenderRegion::ResetRegion(DocRect &NewClipRect)
01050 {
01051 #ifdef _DEBUG
01052 
01053 
01054 
01055 #endif
01056 
01057     
01058     
01059     FreeOffscreenState();
01060 
01061     RenderRegion::ResetRegion(NewClipRect);
01062 }
01063 
01064 
01065 
01066 void GRenderRegion::InitBmpBits()
01067 {
01068     ENSURE(pBits,"Call to InitBmpBits with null bits pointer!");
01069     if(!pBits)
01070         return;
01071 
01072     LPBITMAPINFOHEADER bh = &pBitmapInfo->bmiHeader;
01073     BYTE* pSetBits = (BYTE*)pBits;
01074 
01075     BOOL UseInternalFormat = FALSE;
01076     if(m_DoCompression)
01077     {
01078         bh->biCompression=0x80000001;       
01079         UseInternalFormat = TRUE;
01080     }
01081 
01082     
01083     if(bh->biCompression==0x80000001)
01084         UseInternalFormat = TRUE;
01085 
01086     
01087     
01088     
01089     UINT32 BmpSize = GetDIBBitsSize( bh );
01090     UINT32 Index = 0;
01091 
01092     if(bh->biBitCount==32)
01093     {
01094         
01095         if(UseInternalFormat)
01096         {
01097 
01098             while(Index < BmpSize)
01099             {
01100                 
01101                 
01102 
01103                 pSetBits[Index++] = 0x00;
01104                 pSetBits[Index++] = 0x00;
01105                 pSetBits[Index++] = 0x00;
01106                 pSetBits[Index++] = 0xFF;
01107             }
01108         }
01109         else
01110         {
01111 
01112             while(Index < BmpSize)
01113             {
01114                 
01115                 pSetBits[Index++] = 0xFF;
01116                 pSetBits[Index++] = 0xFF;
01117                 pSetBits[Index++] = 0xFF;
01118                 pSetBits[Index++] = 0x00;
01119             }
01120         }
01121     }
01122     else
01123     {
01124 #if FILL_BITMAP
01125         
01126         memset( pBits, FILL_BITMAP+1, BmpSize );
01127 #else
01128         
01129         memset( pBits, 0xFF, BmpSize );
01130 #endif
01131     }
01132 }
01133 
01134 
01135 
01136 
01137 
01138 
01139 
01140 
01141 
01142 
01143 
01144 
01145 BOOL GRenderRegion::StartRender()
01146 {
01147     
01148     
01149     
01150     
01151     
01152     
01153     
01154     
01155     
01156     
01157     
01158     
01159     
01160     
01161     BOOL AllocatedNewBmp = FALSE;
01162 
01163     RememberMe("StartRender");
01164 
01165     
01166     if (!RenderRegion::StartRender())
01167         return FALSE;
01168 
01169 
01170     
01171     ENSURE(RenderFlags.Rendering == FALSE, "Initialise called whilst already rendering");
01172     
01173     
01174     
01175     if (RenderFlags.Rendering != false) return FALSE;
01176     
01177     TRACEUSER("Gavin",_T("GRenderRegion::StartRender - RenderFlags.Rendering = TRUE;\n"));
01178     RenderFlags.Rendering = TRUE;
01179 
01180     
01181     
01182     
01183     
01184     
01185     
01186     
01187     
01188     
01189     wxRect Rect;
01190     if (GetMasterCapture())
01191         Rect = CalculateWinRect(GetMasterCapture()->CaptureMatrix, GetMasterCapture()->CaptureRect, GetMasterCapture()->dPixelsPerInch);
01192     else
01193         Rect = CalculateWinRect(RenderMatrix, CurrentClipRect, PixelsPerInch);
01194 
01195     if (LocalBitmap)
01196     {
01197         ScreenRect = wxRect(0,0,0,0);
01198         
01199         const INT32 NewWidth  =  Rect.width;
01200         const INT32 OldWidth  = WRect.width;
01201         const INT32 NewHeight =  Rect.height;
01202         const INT32 OldHeight = WRect.height;
01203 
01204         
01205         
01206         
01207         
01208         
01209         
01210         
01211         if ( pBits!=NULL && pBitmapInfo!=NULL && (NewWidth!=OldWidth || NewHeight!=OldHeight) )
01212         {
01213             
01214             if (NewWidth == 0 || NewHeight == 0)
01215                 return FALSE;
01216 
01217             
01218             ERROR3IF((NewWidth < 0 || NewHeight < 0),"GRenderRegion::StartRender got a bad rectangle (Width/Height < 0)\n");
01219 
01220             ResetRegion(RegionRect);
01221             if (!RenderRegion::StartRender())
01222                 return FALSE;
01223 
01224             
01225 #if USE_wxBITMAP
01226             pBitmapInfo = AllocWxBitmap(NewWidth,NewHeight,uBitmapDepth);
01227 #else
01228             pBitmapInfo = GetLPBits(NewWidth, NewHeight, uBitmapDepth, &pBits);
01229 #endif
01230             if (pBitmapInfo==NULL)
01231             {
01232                 TRACE( _T("Growing GG failed\n"));
01233                 return FALSE;
01234             }
01235             AllocatedNewBmp = TRUE;
01236             GetMasterCapture()->SetDIB(pBitmapInfo, pBits);
01237         }
01238 
01239         
01240         WRect = Rect;
01241     }
01242     else
01243     {
01244         WRect = Rect;
01245         ScreenRect = WRect;
01246         if (RenderView != NULL)
01247         {
01248             CCamView *RenderWindow = RenderView->GetConnectionToOilView();
01249             if ( RenderWindow!=NULL && RenderWindow->GetFrame()!=NULL )
01250             {
01251 
01252                 wxPoint tl = ScreenRect.GetTopLeft();
01253                 wxPoint br = ScreenRect.GetBottomRight();
01254                 RenderWindow->GetFrame()->ClientToScreen(tl);
01255                 RenderWindow->GetFrame()->ClientToScreen(br);
01256                 ScreenRect = wxRect(tl,br);
01257             }
01258         }
01259         else
01260             ERROR2(FALSE, "No render view in GRenderRegion::StartRender()");
01261 
01262     }
01263 
01264     
01265     Capture* pNewMasterCapture = NULL;
01266 
01267     if (m_CaptureStack.Empty())
01268     {
01269         ERROR2IF(pBitmapInfo!=NULL, FALSE, "How has this region got a bitmap when the capture stack is empty?");
01270 
01271         pNewMasterCapture = new Capture(this, CAPTUREINFO(ctNESTABLE, cfMASTER | cfPIXWIDTHSCALE), RenderMatrix, CurrentClipRect, PixelsPerInch, CurrentColContext);
01272         if (pNewMasterCapture==NULL) return FALSE;
01273 
01274         m_CaptureStack.Push(pNewMasterCapture);
01275     }
01276 
01277 #ifdef _DEBUG
01278     else
01279     {
01280         
01281         Capture* pDebugCapture = GetTopCaptureBitmap();
01282         if (pDebugCapture)
01283         {
01284             ERROR3IF(pDebugCapture->CaptureRect != CurrentClipRect, "Wha?");
01285 
01286             ERROR3IF(pDebugCapture->dPixelsPerInch != PixelsPerInch, "Wha?");
01287         }
01288     }
01289 #endif
01290 
01291     if (pBitmapInfo==NULL)
01292     {
01293         ERROR2IF(GetMasterCapture()->dPixelsPerInch!=GetPixelsPerInch(), FALSE, "Master capture has different dpi than master bitmap");
01294 
01295         
01296 #if USE_wxBITMAP
01297         pBitmapInfo = AllocWxBitmap(WRect.width, WRect.height, uBitmapDepth);
01298 #else
01299         pBitmapInfo = GetLPBits(WRect.width, WRect.height, uBitmapDepth, &pBits);
01300 #endif
01301         if (pBitmapInfo==NULL)
01302         {
01303             ERROR3("Allocating GRenderRegion bitmap failed\n");
01304             return FALSE;
01305         }
01306 
01307         AllocatedNewBmp = TRUE;
01308         GetMasterCapture()->SetDIB(pBitmapInfo, pBits);
01309     }
01310 #ifdef _DEBUG
01311     else
01312     {
01313         
01314         ERROR3IF(GetTopCaptureBitmap()==NULL, "There must be at least ONE bitmap capture!");
01315     }
01316 #endif
01317 
01318     
01319     if (!StartRenderMiddle())
01320         return FALSE;
01321 
01322     
01323     
01324 
01325 
01326     
01327     if (AllocatedNewBmp || ForceInitBmpBits)
01328     {
01329         InitBmpBits();
01330     }
01331 
01332     
01333     ForceInitBmpBits = FALSE;
01334 
01335     
01336     
01337     
01338     if (RenderDC != NULL)
01339     {
01340 
01341 
01342 
01343 
01344 
01345 
01346 
01347         if (hPalette != NULL)
01348 
01349             hPrevPalette = PaletteManager::StartPaintPalette(RenderDC);
01350 
01351         if (uBitmapDepth == 8)
01352         {
01353             
01354             if ((DitherStyle8Bit != 0) && (DitherStyle8Bit != 3))
01355                 GetDrawContext()->SetDitherStyle((DitherStyle) DitherStyle8Bit);        
01356         }
01357 
01358 
01359 
01360 
01361 
01362   }
01363 
01364     
01365     
01366     
01367     
01368     
01369     
01370     SetRenderToCapture(GetTopCaptureBitmap(), TRUE);
01371 
01372     ENSURE(pBitmapInfo && pBits, "No bitmap to render into");
01373 
01374 
01375 
01376     return TRUE;
01377 }
01378 
01379 
01380 
01381 
01382 
01383 
01384 
01385 
01386 
01387 
01388 
01389 
01390 
01391 
01392 
01393 
01394 
01395 #if USE_wxBITMAP
01396 
01397 LPBITMAPINFO GRenderRegion::AllocWxBitmap( UINT32 Width, UINT32 Height, UINT32 Depth )
01398 {
01399     pBitmap = new wxBitmap(Width,Height,Depth);
01400     pBitmapData = new wxAlphaPixelData(*pBitmap);
01401 
01402     uLineSize = DIBUtil::ScanlineSize(Width,Depth);
01403     INT32 size = uLineSize*Height;
01404     if ( size==0 )
01405         size = 4;                                       
01406 
01407     size_t extras;
01408     INT32 used_cols = 0;
01409     switch (Depth)
01410     {
01411     case  1: extras =   2; used_cols =   2; break;
01412     case  4: extras =  16; used_cols =  16; break;
01413     case  8: extras = 256; used_cols = 256; break;
01414     case 16: extras =   3;                  break;
01415     case 24: extras =   0;                  break;
01416     case 32: extras =   3;                  break;
01417     default:
01418         ENSURE(FALSE, "Bad bitmap depth");
01419         return NULL;
01420     }
01421 
01422     LPBITMAPINFO pInfo;
01423     pInfo = (LPBITMAPINFO)CCMalloc(UINT32(sizeof(BITMAPINFO)+extras*sizeof(COLORREF)));
01424     if ( pInfo==NULL )
01425     {
01426         
01427         delete pBitmapData;
01428         delete pBitmap;
01429         pBitmapData = NULL;
01430         pBitmap     = NULL;
01431         return NULL;
01432     }
01433 
01434     pBits = (BYTE*)pBitmap->GetRawData(*pBitmapData,Depth);
01435     if ( pBitmapData->GetRowStride()<0 )
01436         pBits += pBitmapData->GetRowStride()*(Height-1);
01437     
01438     pInfo->bmiHeader.biSize             = sizeof(BITMAPINFOHEADER);
01439     pInfo->bmiHeader.biWidth            = Width;
01440     pInfo->bmiHeader.biHeight           = Height;
01441     pInfo->bmiHeader.biPlanes           = 1;
01442     pInfo->bmiHeader.biBitCount         = Depth;
01443     pInfo->bmiHeader.biCompression      = BI_RGB;
01444     pInfo->bmiHeader.biXPelsPerMeter    = 3780;             
01445     pInfo->bmiHeader.biYPelsPerMeter    = 3780;
01446     pInfo->bmiHeader.biClrUsed          = used_cols;
01447     pInfo->bmiHeader.biClrImportant     = 0;
01448     pInfo->bmiHeader.biSizeImage        = size;
01449 
01450     return pInfo;
01451 }
01452 
01453 #endif
01454 
01455 
01456 
01457 
01458 
01459 
01460 
01461 
01462 
01463 
01464 
01465 
01466 
01467 
01468 
01469 
01470 
01471 #if USE_wxBITMAP
01472 
01473 void GRenderRegion::FreeWxBitmap()
01474 {
01475     if ( pBits )
01476     {
01477         pBitmap->UngetRawData(*pBitmapData);
01478         delete pBitmap;
01479         delete pBitmapData;
01480         CCFree(pBitmapInfo);
01481         pBitmap     = NULL;
01482         pBits       = NULL;
01483         pBitmapData = NULL;
01484         pBitmapInfo = NULL;
01485     }
01486 }
01487 
01488 #endif
01489 
01490 
01491 
01492 
01493 
01494 
01495 
01496 
01497 
01498 
01499 
01500 
01501 
01502 
01503 
01504 
01505 
01506 
01507 
01508 WinRect GRenderRegion::CalculateWinRect( Matrix& RenderMatrix, const DocRect& docrect,
01509                                          const double dpi)
01510 {
01511     
01512     
01513     
01514     
01515     
01516     
01517     
01518     
01519     
01520     return OSRenderRegion::DocRectToWin( RenderMatrix, docrect, dpi );
01521 
01522 
01523 }
01524 
01525 WinRect GRenderRegion::CalculateWinRect( const DocRect& docrect )
01526 {
01527     return CalculateWinRect(RenderMatrix, docrect, PixelsPerInch );
01528 }
01529 
01530 
01531 
01532 
01533 
01534 
01535 
01536 
01537 
01538 
01539 
01540 
01541 
01542 
01543 
01544 BOOL GRenderRegion::StartRenderAfter( GMATRIX *GMat )
01545 {
01546     return TRUE;
01547 }
01548 
01549 
01550 
01551 
01552 
01553 
01554 
01555 
01556 
01557 
01558 
01559 
01560 
01561 
01562 
01563 BOOL GRenderRegion::StartRenderMiddle()
01564 {
01565     return TRUE;
01566 }
01567 
01568 
01569 
01570 
01571 
01572 
01573 
01574 
01575 
01576 
01577 
01578 
01579 
01580 
01581 
01582 
01583 
01584 
01585 
01586 
01587 BOOL GRenderRegion::StopRender()
01588 {
01589     RememberMe("StopRender");
01590 
01591     
01592     
01593     BOOL bHaveRendered = HaveRenderedSomething;
01594 
01595 #if 0
01596     if (HaveRenderedSomething)
01597     {
01598         TRACE( _T("GRR#  DebugClipRect = (%d, %d) - (%d, %d)\n"), CurrentClipRect.lo.x, CurrentClipRect.lo.y, CurrentClipRect.hi.x, CurrentClipRect.hi.y);
01599 
01600         DocRect TempRect(CurrentClipRect);
01601         TempRect.Inflate(-GetScaledPixelWidth());
01602         TRACE( _T("GRR#  Filling = (%d, %d) - (%d, %d)\n"), TempRect.lo.x, TempRect.lo.y, TempRect.hi.x, TempRect.hi.y);
01603         Path ClipPath;
01604         ClipPath.Initialise();
01605         ClipPath.CreatePathFromDocRect(&TempRect);
01606 
01607         SaveContext();
01608         SetLineColour(COLOUR_TRANS);
01609         SetFillColour(COLOUR_BLUE);
01610         DrawPath(&ClipPath);
01611         RestoreContext();
01612     }
01613 #endif
01614 #if 0
01615     {
01616         SaveContext();
01617 
01618         SetLineColour(COLOUR_TRANS);
01619         SetFillColour(COLOUR_BLUE);
01620 
01621         DocRect SmallRect(750, 750, 1500, 1500);
01622         Path ThePath;
01623         ThePath.Initialise();
01624         ThePath.CreatePathFromDocRect(&SmallRect);
01625 
01626         DrawPath(&ThePath);
01627         ThePath.Translate(50, 1500);
01628         DrawPath(&ThePath);
01629         ThePath.Translate(50, 1500);
01630         DrawPath(&ThePath);
01631         ThePath.Translate(50, 1500);
01632         DrawPath(&ThePath);
01633         ThePath.Translate(50, 1500);
01634         DrawPath(&ThePath);
01635         ThePath.Translate(50, 1500);
01636         DrawPath(&ThePath);
01637         ThePath.Translate(50, 1500);
01638         DrawPath(&ThePath);
01639         ThePath.Translate(50, 1500);
01640         DrawPath(&ThePath);
01641         ThePath.Translate(50, 1500);
01642         DrawPath(&ThePath);
01643         ThePath.Translate(50, 1500);
01644         DrawPath(&ThePath);
01645         ThePath.Translate(50, 1500);
01646         DrawPath(&ThePath);
01647         ThePath.Translate(50, 1500);
01648         DrawPath(&ThePath);
01649         ThePath.Translate(50, 1500);
01650         DrawPath(&ThePath);
01651         ThePath.Translate(50, 1500);
01652         DrawPath(&ThePath);
01653         ThePath.Translate(50, 1500);
01654         DrawPath(&ThePath);
01655         ThePath.Translate(50, 1500);
01656         DrawPath(&ThePath);
01657 
01658         RestoreContext();
01659     }
01660 #endif
01661     
01662 
01663     TRACEUSER("Gavin",_T("GRenderRegion::StopRender - RenderFlags.Rendering = FALSE;\n"));
01664     RenderFlags.Rendering = FALSE;
01665 
01666     
01667     
01668     
01669     if (pBitmapInfo)
01670     {
01671         if (MasterCaptureIsCurrent() && !TopCaptureIsDirect())
01672         {
01673             
01674             
01675             
01676 
01677             if (HaveRenderedSomething)
01678             {
01679                 
01680                 
01681                 
01682                 DisplayBits();
01683 
01684                 
01685                 SetClean(TRUE, FALSE);
01686             }
01687         }
01688         else
01689         {
01690             
01691             
01692             
01693             
01694             
01695             
01696             
01697             
01698             
01699             
01700             
01701             if (HaveRenderedSomething)
01702             {
01703                 
01704                 DisplayCurrentState();
01705 
01706                 
01707                 SetClean(TRUE, FALSE);
01708             }
01709         }
01710     }
01711     else
01712     {
01713         if(!IsWrapped)
01714             TRACE( _T("GRenderRegion::StopRender called with no bitmap\n"));
01715     }
01716 
01717     if (hPrevPalette)
01718         PaletteManager::StopPaintPalette(RenderDC, hPrevPalette);
01719 
01720     
01721     InnerRect.MakeEmpty();
01722     OuterRect.MakeEmpty();
01723 
01724     
01725     
01726     FreeStoredClipRegions();
01727 
01728     
01729     if (ScreenDepth == 8)
01730         GetDrawContext()->SetDitherStyle(DITHER_GREY_ORDERED);
01731 
01732     return bHaveRendered;
01733 }
01734 
01735 
01736 
01737 
01738 
01739 
01740 
01741 
01742 
01743 
01744 
01745 
01746 
01747 
01748 
01749 
01750 
01751 void GRenderRegion::DisplayCurrentState()
01752 {
01753     
01754     
01755     Capture* pTempCapture = new Capture(GetMasterCapture(), TRUE);
01756 
01757     if (pTempCapture)
01758     {
01759         
01760         SetRenderToCapture(pTempCapture);
01761 
01762         
01763         RenderCurrentCaptureState();
01764 
01765 #ifdef DEBUG_ATTACH_RENDERSTATE_BMP
01766 {
01767 
01768 WinBitmap* wBitmap          = new WinBitmap(pTempCapture->lpBitmapInfo, pTempCapture->lpBits);
01769 KernelBitmap* OffscreenBitmap   = new KernelBitmap(wBitmap,TRUE);
01770 OffscreenBitmap->AttachDebugCopyToCurrentDocument("Render State Bitmap");
01771 wBitmap->BMBytes = ((WinBitmap*)OILBitmap::Default)->BMBytes;
01772 delete OffscreenBitmap;
01773 }
01774 #endif
01775 
01776         
01777         DisplayBits(pTempCapture->lpBitmapInfo, pTempCapture->lpBits);
01778 
01779         
01780         SetRenderToCapture(GetTopCaptureBitmap());
01781 
01782         
01783         pTempCapture->FreeDIB();
01784         delete pTempCapture;
01785         pTempCapture = NULL;
01786     }
01787     else
01788     {
01789         
01790         
01791         DisplayBits();
01792     }
01793 }
01794                 
01795                 
01796                 
01797 
01798 
01799 
01800 
01801 
01802 
01803 
01804 
01805 
01806 
01807 
01808 
01809 
01810 
01811 
01812 void GRenderRegion::SetClean(BOOL bResetChangedBounds, BOOL FillWhite)
01813 {
01814     
01815     HaveRenderedSomething = FALSE;
01816     if (bResetChangedBounds)
01817         GetDrawContext()->ClearChangedBBox();
01818 }
01819 
01820 
01821 
01822 
01823 
01824 
01825 
01826 
01827 
01828 
01829 
01830 
01831 
01832 
01833 
01834 
01835 
01836 
01837 
01838 
01839 
01840 
01841 
01842 
01843 
01844 
01845 
01846 
01847 
01848 
01849 
01850 
01851 
01852 
01853 
01854 
01855 
01856 
01857 
01858 
01859 
01860 
01861 
01862 
01863 
01864 BOOL GRenderRegion::StrokePath( const DocCoord *Coords, const PathVerb *Verbs, UINT32 Count,
01865                                 const DocCoord *UnclippedCoords, const PathVerb *UnclippedVerbs, 
01866                                 UINT32 UnclippedCount,
01867                                 BOOL DrawArrows )
01868 {
01869     CapStyles Caps;
01870     JoinStyles Join;
01871 
01872     switch (RR_STARTCAP())
01873     {
01874         case LineCapRound:
01875             Caps = CAPS_ROUND;
01876             break;
01877         case LineCapSquare:
01878             Caps = CAPS_SQUARE;
01879             break;
01880         case LineCapButt:
01881             Caps = CAPS_BUTT;
01882             break;
01883         default:
01884             ENSURE(FALSE, "Bad startcap");
01885             Caps = CAPS_ROUND;
01886             break;
01887     }
01888     switch (RR_JOINTYPE())
01889     {
01890         case BevelledJoin:
01891             Join = JOIN_BEVEL;
01892             break;
01893         case MitreJoin:
01894             Join = JOIN_MITER;
01895             break;
01896         case RoundJoin:
01897             Join = JOIN_ROUND;
01898             break;
01899         default:
01900             ENSURE(FALSE, "bad jointype");
01901             Join = JOIN_ROUND;
01902             break;
01903     }
01904 
01905     BOOL StrokeOK = TRUE;
01906 
01907     
01908     
01909     
01910     DocCoord * pCopyCoords = NULL;
01911     if (UnclippedCount != 0)
01912     {
01913         pCopyCoords = (DocCoord *)(CCMalloc(sizeof(DocCoord) * UnclippedCount));
01914 
01915         for (UINT32 i = 0; i < UnclippedCount; i++)
01916         {
01917             pCopyCoords[i].x = UnclippedCoords[i].x;
01918             pCopyCoords[i].y = UnclippedCoords[i].y;
01919         }
01920     }
01921 
01922     BOOL bRenderedArrows = FALSE;
01923 
01924     
01925     
01926     
01927     if (DrawArrows && pCopyCoords)
01928     {
01929         bRenderedArrows = DrawPathArrowHeads((DocCoord*)pCopyCoords, (PathVerb*)UnclippedVerbs, UnclippedCount);
01930     }
01931 
01932     
01933     
01934     if (Count > 1 && pCopyCoords)
01935     {
01936         MILLIPOINT Width = RR_LINEWIDTH();
01937 
01938         if (RenderFlags.HitDetect)
01939         {
01940             
01941             if (Width < (ScaledPixelWidth*1))
01942                 Width = ScaledPixelWidth*1;
01943         }
01944         else if (RRQuality.GetQuality() == Quality::QualityGuideLayer)
01945         {
01946             SetDashPattern(SD_DASH1);
01947             DocColour* pCol = AttrQuality::GetColour();
01948             if (pCol != NULL)
01949                 SetGCol(*pCol);             
01950             else
01951             {
01952                 DocColour   colorRed(COLOUR_RED);
01953                 SetGCol( colorRed );
01954             }
01955             
01956             Width = ScaledPixelWidth;
01957             DrawArrows = FALSE;
01958         }
01959         else if (RRQuality.GetLineQuality() < Quality::FullLine)
01960         {
01961             
01962             Width = 0;
01963             DrawArrows = FALSE;
01964         }
01965         else if (RRQuality.GetAntialiasQuality() < Quality::FullAntialias)
01966         {
01967             
01968             
01969             if (Width < ScaledPixelWidth)
01970                 Width = 0;
01971         }
01972 
01973         DashType* pDashRec = NULL;
01974         DashType GavinDash;
01975 
01976         if ( Width > 0 && 
01977             (RRQuality.GetLineQuality() >= Quality::FullLine) && 
01978              RR_DASHPATTERN().Elements > 0)
01979         {
01980             INT32 Length = RR_DASHPATTERN().Elements;
01981 
01982             
01983             if (Length > 8) Length = 8;
01984 
01985 
01986             
01987             
01988             BOOL DoScale = RR_DASHPATTERN().ScaleWithLineWidth;
01989 
01990             FIXED16 Scale = DoScale ? (double(Width) / double(RR_DASHPATTERN().LineWidth)) : 1;
01991 
01992             GavinDash.Length = Length;
01993             GavinDash.Offset = LongMulFixed16(RR_DASHPATTERN().DashStart, Scale);
01994 
01995             for (INT32 el = 0; el < Length; el++)
01996             {
01997                 
01998                 GavinDash.Array[el] = LongMulFixed16(RR_DASHPATTERN().ElementData[el], Scale);
01999             }
02000 
02001             pDashRec = &GavinDash;
02002         }
02003 
02004         
02005         
02006         
02007         
02008 
02009         if (bRenderedArrows)
02010         {
02011             StrokeOK = GetDrawContext()->StrokePath( (POINT*)pCopyCoords, UnclippedVerbs, UnclippedCount, FALSE,
02012                                     Width, Caps, Join, pDashRec );
02013         }
02014         else
02015         {
02016             StrokeOK = GetDrawContext()->StrokePath( (POINT*)Coords, Verbs, Count, FALSE,
02017                                     Width, Caps, Join, pDashRec );
02018         }
02019     }
02020 
02021     if (pCopyCoords)
02022     {
02023         CCFree(pCopyCoords);
02024         pCopyCoords = NULL;
02025     }
02026 
02027     if (bRenderedArrows)
02028         return TRUE;
02029 
02030     return StrokeOK;
02031 }
02032 
02033 
02034 
02035 
02036 
02037 
02038 
02039 
02040 
02041 
02042 
02043 
02044 
02045 
02046 
02047 
02048 
02049 
02050 
02051 void GRenderRegion::DrawPathToOutputDevice(Path* PathToDraw, PathShape)
02052 {
02053     
02054 
02055 
02056 
02057 
02058 
02059     DWORD Style = 0;
02060     TranspGradTable TranspTable;
02061 
02062     
02063     DocCoord*   Coords;
02064     PathVerb*   Verbs;
02065     UINT32      NumCoords;
02066     DocCoord*   UnclippedCoords;
02067     PathVerb*   UnclippedVerbs;
02068     UINT32      UnclippedNumCoords;
02069 
02070     BOOL ShouldDeleteCoords = FALSE;
02071 
02072     
02073     UnclippedCoords     = PathToDraw->GetCoordArray();
02074     UnclippedVerbs      = PathToDraw->GetVerbArray();
02075     UnclippedNumCoords  = PathToDraw->GetNumCoords();
02076 
02077     ClippedPathIsValid = TRUE;
02078 
02079     
02080     SetupFuzzyClipRects();
02081 
02082     
02083     if (TryToFuzzyClip(PathToDraw, &Coords, &Verbs, &NumCoords))
02084     {
02085         
02086         
02087         
02088         
02089         
02090         
02091 
02092         if (NumCoords < 2)
02093         {
02094             ClippedPathIsValid = FALSE;
02095 
02096         }
02097         else
02098         {
02099 
02100 
02101 
02102 
02103 
02104 
02105 
02106 
02107 
02108 
02109 
02110 
02111 
02112 
02113 
02114 
02115 
02116 
02117 
02118 
02119 
02120 
02121 
02122 
02123 
02124 
02125 
02126 
02127 
02128 
02129         }
02130 
02131         
02132         ShouldDeleteCoords = TRUE;
02133     }
02134     else
02135     {
02136         
02137         Coords = PathToDraw->GetCoordArray();
02138         Verbs  = PathToDraw->GetVerbArray();
02139         NumCoords = PathToDraw->GetNumCoords();
02140     }
02141 
02142     enum Quality::Fill FillQuality = RRQuality.GetFillQuality();
02143 
02144     RememberMe("DrawPath");
02145     HaveRenderedSomething = TRUE;
02146 
02147     if ( PathToDraw->IsFilled )
02148     {
02149         BOOL ExtendedFill = FALSE;
02150         FillGeometryAttribute *pFillProvider 
02151             = (FillGeometryAttribute *) CurrentAttrs[ATTR_FILLGEOMETRY].pAttr;
02152 
02153         if ( 
02154             (pFillProvider->GetRuntimeClass() != CC_RUNTIME_CLASS(FlatFillAttribute)) &&
02155             (FillQuality >= Quality::Graduated) 
02156            )
02157             ExtendedFill = TRUE;
02158 
02159         if ( 
02160             (pFillProvider->GetRuntimeClass() == CC_RUNTIME_CLASS(BitmapFillAttribute)) &&
02161             (FillQuality >= Quality::Solid) 
02162            )
02163             ExtendedFill = TRUE;
02164 
02165         if ( 
02166             (pFillProvider->GetRuntimeClass() == CC_RUNTIME_CLASS(FractalFillAttribute)) &&
02167             (FillQuality >= Quality::Solid) 
02168            )
02169             ExtendedFill = TRUE;
02170 
02171         if (ExtendedFill)
02172         {
02173             
02174             if (RenderFlags.VeryMono)
02175             {
02176                 
02177                 
02178                 
02179                 if (pFillProvider->GetRuntimeClass() == CC_RUNTIME_CLASS(BitmapFillAttribute))
02180                 {
02181                     
02182                     KernelBitmap* pBitmap = pFillProvider->GetBitmap();
02183                     INT32 Index = 0;
02184 
02185                     if (pBitmap && (pBitmap->GetTransparencyIndex(&Index) || pBitmap->GetBPP()>=32))
02186                     {
02187                         
02188                         
02189                         if (!pFillProvider->RenderFill(this, PathToDraw))
02190                             ExtendedFill = FALSE;                           
02191                     }
02192                     else
02193                     {
02194                         ExtendedFill = FALSE;   
02195                     }
02196                 }
02197                 else
02198                 {
02199                     ExtendedFill = FALSE;       
02200                 }
02201             }
02202             else if (!pFillProvider->RenderFill(this, PathToDraw))
02203             {
02204                 ExtendedFill = FALSE;                                       
02205             }
02206         }
02207 
02208         if ( (!ExtendedFill) && 
02209              (FillQuality >= Quality::Solid)
02210            )
02211         {
02212             DocColour FlatColour = RR_FILLCOLOUR();
02213 
02214             if (RenderFlags.VeryMono && 
02215                 pFillProvider->GetRuntimeClass() == CC_RUNTIME_CLASS(BitmapFillAttribute))
02216             {
02217                 
02218                 
02219                 FlatColour = COLOUR_BLACK;
02220             }
02221 
02222             if (SetFillGCol(FlatColour))
02223             {
02224                 if (!RenderFlags.VeryMono && GetTransparencyFill(&TranspTable, &Style))
02225                 {
02226                     DocColour Col = RR_FILLCOLOUR();
02227                     COLORREF rgb = ConvertColourToTransScreenWord(CurrentColContext, &Col);
02228                     GetDrawContext()->SetTransparency(rgb, (TransparencyEnum)(Style>>8));
02229                 }
02230 
02231                 if (NumCoords > 1)
02232                 {
02233                     GetDrawContext()->FillPath( (POINT*)Coords, Verbs, NumCoords,
02234                                     (RR_WINDINGRULE()==EvenOddWinding) ? 0 : 1);
02235                 }
02236             }
02237         }
02238     }
02239 
02240     if ( PathToDraw->IsStroked )
02241     {
02242         
02243         BOOL DrawArrows = (RRQuality.GetLineQuality() >= Quality::FullLine) &&
02244                           !(RR_STARTARROW().IsNullArrow() && RR_ENDARROW().IsNullArrow()) &&
02245                           ArrowRec::DoesPathNeedArrowHeads(UnclippedCoords, UnclippedVerbs, UnclippedNumCoords);
02246 
02247         if ((FillQuality <= Quality::Bitmaps))
02248         {
02249             
02250             DocColour   colorBlk(COLOUR_BLACK);
02251             if ( SetGCol( colorBlk ) )
02252                 StrokePath( Coords, Verbs, NumCoords, 
02253                             UnclippedCoords, UnclippedVerbs, UnclippedNumCoords, DrawArrows );
02254         }
02255         else if (RenderFlags.VeryMono)
02256         {
02257             
02258             DocColour   colorBlk(COLOUR_BLACK);
02259             if ( !(RR_STROKECOLOUR().IsTransparent()) && SetGCol( colorBlk ) )
02260                 StrokePath( Coords, Verbs, NumCoords, 
02261                             UnclippedCoords, UnclippedVerbs, UnclippedNumCoords, DrawArrows );
02262         }
02263         else if ( SetGCol( RR_STROKECOLOUR() ) )
02264         {
02265                 StrokePath( Coords, Verbs, NumCoords, 
02266                             UnclippedCoords, UnclippedVerbs, UnclippedNumCoords, DrawArrows );
02267         }
02268     }
02269 
02270     
02271     if (ShouldDeleteCoords)
02272     {
02273         delete Coords;
02274         delete Verbs;
02275     }
02276 }
02277 
02278 
02279 
02280 
02281 
02282 
02283 
02284 
02285 
02286 
02287 
02288 
02289 
02290 
02291 
02292 
02293 
02294 
02295 
02296 
02297 
02298 
02299 
02300 
02301 
02302 void GRenderRegion::SetClipRegion(ClipRegionAttribute* pClipAttr, BOOL Temp)
02303 {
02304     RenderRegion::SetClipRegion(pClipAttr, Temp);
02305     ApplyCurrentClipRegion();
02306 }
02307 
02308 
02309 
02310 
02311 
02312 
02313 
02314 
02315 
02316 
02317 
02318 
02319 
02320 
02321 
02322 
02323 
02324 
02325 
02326 
02327 
02328 
02329 
02330 
02331 
02332 void GRenderRegion::RestoreClipRegion(ClipRegionAttribute* pClipAttr, BOOL Temp)
02333 {
02334     
02335     
02336     
02337     
02338     
02339     
02340 
02341 
02342     ClipRegionAttribute*    pOutGoingClipAttr   = RR_CLIPREGION();
02343     ClipRegionAttribute*    pInComingClipAttr   = NULL;
02344 
02345     
02346     RenderRegion::RestoreClipRegion(pClipAttr, Temp);
02347 
02348     
02349     pInComingClipAttr = RR_CLIPREGION();
02350     if (pInComingClipAttr != pOutGoingClipAttr &&
02351         pOutGoingClipAttr != NULL)
02352     {
02353 
02354 
02355 
02356 
02357 
02358 
02359 
02360 
02361         
02362         
02363         Capture* pBitCapture = GetTopCaptureBitmap();
02364         if (pBitCapture)
02365             pBitCapture->RemoveCachedClipRegion(pOutGoingClipAttr);
02366     }
02367 
02368     
02369     ApplyCurrentClipRegion();
02370 }
02371 
02372 
02373 
02374 
02375 
02376 
02377 
02378 
02379 
02380 
02381 
02382 
02383 
02384 
02385 
02386 
02387 
02388 
02389 
02390 
02391 
02392 BOOL GRenderRegion::ApplyCurrentClipRegion()
02393 {
02394 
02395 
02396     
02397     
02398     if (!RenderFlags.Rendering)
02399         return FALSE;
02400 
02401     
02402     
02403     
02404     
02405     
02406     
02407     
02408     
02409     
02410     
02411 
02412     
02413     BOOL            fSuccess    = FALSE;
02414     const REGION*   pClipRegion = NULL;
02415     ClipRegionAttribute* pClipAttr = RR_CLIPREGION();
02416 
02417     ERROR3IF(pClipAttr == NULL, "Doh! NULL ClipRegionAttribute in render region!");
02418 
02419     
02420     
02421     
02422     if (pClipAttr->GetClipPath() == NULL)
02423     {
02424         RECT BigRect;
02425         BigRect.bottom  = BigRect.left  = INT32_MIN;
02426         BigRect.top     = BigRect.right = INT32_MAX;
02427         fSuccess = GetDrawContext()->DeviceClipRectangle(&BigRect);
02428     }
02429 
02430     
02431     
02432     else
02433     {
02434 
02435 
02436 
02437 
02438 
02439         pClipRegion = GetTopCaptureBitmap()->GetCachedClipRegion(pClipAttr);
02440         if (pClipRegion==NULL)
02441         {
02442             pClipRegion = MakeClipRegionFromClipAttr(pClipAttr);
02443             GetTopCaptureBitmap()->SetCachedClipRegion(pClipAttr, pClipRegion);
02444         }
02445 
02446         fSuccess = GetDrawContext()->ClipRegion(pClipRegion);
02447     }
02448 
02449     return fSuccess;
02450 }
02451 
02452 
02453 
02454 
02455 
02456 
02457 
02458 
02459 
02460 
02461 
02462 
02463 
02464 
02465 
02466 
02467 
02468 
02469 
02470 
02471 BOOL GRenderRegion::RenderGradFillPath(Path *PathToDraw, GradFillAttribute *Fill)
02472 {
02473     DWORD Style = 0;
02474     TranspGradTable TranspTable;
02475 
02476     BOOL SpecialFill = FALSE;
02477 
02478     CCRuntimeClass *FillType = Fill->GetRuntimeClass();
02479 
02480 
02481     if (FillType == CC_RUNTIME_CLASS(RadialFillAttribute))
02482         Style = 1;
02483     else if (FillType == CC_RUNTIME_CLASS(LinearFillAttribute))
02484         Style = 0;
02485     else if (FillType == CC_RUNTIME_CLASS(ConicalFillAttribute))
02486         Style = 2;
02487     else if (FillType == CC_RUNTIME_CLASS(SquareFillAttribute))
02488         Style = 3;
02489     else if (FillType == CC_RUNTIME_CLASS(ThreeColFillAttribute))
02490         SpecialFill = TRUE;
02491     else if (FillType == CC_RUNTIME_CLASS(FourColFillAttribute))
02492         SpecialFill = TRUE;
02493     else
02494     {
02495         ERROR3("Unknown fill type");
02496         return FALSE;                               
02497     }
02498 
02499     if (uBitmapDepth == 32)
02500     {
02501         
02502         if (!GetTransparencyFill(&TranspTable, &Style))
02503             Style |= (WhichTransparency<<8);        
02504     }
02505 
02506     CProfileBiasGain DiagramMapper = Fill->GetProfile ();
02507 
02508     
02509     POINT A,B,C,D;
02510 
02511     DocCoord* StartPoint    = Fill->GetStartPoint();
02512     DocCoord* EndPoint      = Fill->GetEndPoint();
02513     DocCoord* EndPoint2     = Fill->GetEndPoint2();
02514     DocCoord* EndPoint3     = Fill->GetEndPoint3();
02515 
02516     A.x = (*StartPoint).x;  A.y = (*StartPoint).y;
02517     B.x = (*EndPoint).x;    B.y = (*EndPoint).y;
02518 
02519     if (EndPoint2 != NULL)
02520     {
02521         C.x = (*EndPoint2).x;   
02522         C.y = (*EndPoint2).y;
02523     }
02524 
02525     if (FillType==CC_RUNTIME_CLASS(LinearFillAttribute))
02526     {
02527         A.x = (*StartPoint).x;  A.y = (*StartPoint).y;
02528         B.x = (*EndPoint2).x;   B.y = (*EndPoint2).y;
02529         C.x = (*EndPoint).x;    C.y = (*EndPoint).y;
02530     }
02531     else if (FillType==CC_RUNTIME_CLASS(ConicalFillAttribute))
02532     {
02533         B.x = A.x - (B.x - A.x);
02534         B.y = A.y - (B.y - A.y);
02535     }
02536 
02537     BOOL Perspective = FALSE;
02538 
02539     
02540     if (Fill->IsPerspective())
02541     {
02542         Perspective = TRUE;
02543 
02544         POINT PGram[4];
02545 
02546         
02547         if (FillType==CC_RUNTIME_CLASS(LinearFillAttribute))
02548         {
02549             PGram[0].x = (*StartPoint).x;   PGram[0].y = (*StartPoint).y;
02550             PGram[1].x = (*EndPoint2).x;    PGram[1].y = (*EndPoint2).y;
02551             PGram[2].x = (*EndPoint3).x;    PGram[2].y = (*EndPoint3).y;
02552             PGram[3].x = (*EndPoint).x;     PGram[3].y = (*EndPoint).y;
02553         }
02554         else
02555         {
02556             PGram[0].x = A.x;               PGram[0].y = A.y;
02557             PGram[1].x = B.x;               PGram[1].y = B.y;
02558             PGram[2].x = (*EndPoint3).x;    PGram[2].y = (*EndPoint3).y;
02559             PGram[3].x = (*EndPoint2).x;    PGram[3].y = (*EndPoint2).y;
02560         }
02561 
02562         
02563 
02564         
02565         
02566         if (MouldPerspective::WillBeValid(PGram))
02567         {
02568             
02569             
02570             A.x = PGram[0].x;   A.y = PGram[0].y;
02571             B.x = PGram[1].x;   B.y = PGram[1].y;
02572             C.x = PGram[2].x;   C.y = PGram[2].y;
02573             D.x = PGram[3].x;   D.y = PGram[3].y;
02574         }
02575         else
02576         {
02577             
02578             Perspective = FALSE;
02579         }
02580     }
02581 
02582     
02583     GradTable Table(FALSE);
02584 
02585     INT32 Tiling = ((FillMappingAttribute*)CurrentAttrs[ATTR_FILLMAPPING].pAttr)->Repeat;
02586 
02587     if (SpecialFill)
02588     {
02589         
02590 
02591         if ((FillType != CC_RUNTIME_CLASS(ThreeColFillAttribute)) &&
02592             (FillType != CC_RUNTIME_CLASS(FourColFillAttribute)))
02593         {
02594             ERROR3("Unknown new fill type");
02595             return FALSE;                               
02596         }
02597 
02598         
02599         Style = Style & 0xFFFFFF00;
02600 
02601         
02602         if ((Style & 0xFF00) < 0x400)
02603             Style = (Style & 0xFF0000);
02604         
02605         
02606         
02607 
02608         PColourRGBT Result;
02609 
02610         CurrentColContext->ConvertColour(Fill->GetStartColour(), (ColourPacked *) &Result);
02611         COLORREF StartColour = RGB(Result.Red, Result.Green, Result.Blue);
02612 
02613         CurrentColContext->ConvertColour(Fill->GetEndColour(), (ColourPacked *) &Result);
02614         COLORREF EndColour = RGB(Result.Red, Result.Green, Result.Blue);
02615 
02616         CurrentColContext->ConvertColour(Fill->GetEndColour2(), (ColourPacked *) &Result);
02617         COLORREF EndColour2 = RGB(Result.Red, Result.Green, Result.Blue);
02618 
02619         if (FillType == CC_RUNTIME_CLASS(FourColFillAttribute))
02620             CurrentColContext->ConvertColour(Fill->GetEndColour3(), (ColourPacked *) &Result);
02621         COLORREF EndColour3 = RGB(Result.Red, Result.Green, Result.Blue);
02622 
02623         
02624 
02625 
02626 
02627 
02628 
02629 
02630 
02631         if (FillType == CC_RUNTIME_CLASS(ThreeColFillAttribute))
02632         {           
02633             
02634             
02635 
02636             if (Tiling == 1)    
02637                 Style |= 0;     
02638             else
02639                 Style |= 2;     
02640 
02641             
02642                                                         
02643 
02644             
02645             
02646                 if (Perspective)
02647                     GetDrawContext()->Set3WayGraduation4(Style, StartColour, EndColour, EndColour2,
02648                                             &A, &B, &C, &D);
02649                 else
02650                     GetDrawContext()->Set3WayGraduation(Style, StartColour, EndColour, EndColour2,
02651                                             &A, &B, &C);
02652             
02653             
02654             
02655             
02656             
02657 
02658             
02659         }
02660         else
02661         {
02662             
02663             
02664 
02665             if (Tiling == 1)    
02666                 Style |= 1;     
02667             else
02668                 Style |= 2;     
02669 
02670             
02671             if (Perspective)
02672                 GetDrawContext()->Set4WayGraduation4(Style, StartColour, EndColour, EndColour3, EndColour2,
02673                                         &A, &B, &C, &D);
02674             else
02675                 GetDrawContext()->Set4WayGraduation(Style, StartColour, EndColour, EndColour3, EndColour2,
02676                                         &A, &B, &C);
02677         }
02678     }
02679     else
02680     {
02681 
02682 #ifdef NEW_FEATURES
02683         if(Tiling == 4) Style |= 0x80;      
02684 #endif
02685 
02686         
02687         
02688         
02689         
02690         
02691         
02692         
02693         CProfileBiasGain DefaultBiasGain;           
02694                                                     
02695 
02696         if (DiagramMapper == DefaultBiasGain)       
02697         {
02698             
02699 
02700             ColourRamp *pColourRamp = Fill->GetColourRamp();
02701             if (pColourRamp)
02702             {
02703                 if (Tiling != 4)
02704                 {
02705                     Table.BuildTable(Fill->Colour, Fill->EndColour, pColourRamp, GetRenderView(), GetFillEffect(), LargeGradTables);
02706                 }
02707                 else
02708                 {
02709                     Table.BuildHighQualityRepeatTable(Fill->Colour, Fill->EndColour, pColourRamp, GetRenderView(), GetFillEffect());
02710                 }
02711             }
02712             else
02713             {
02714                 if (Tiling != 4)
02715                 {
02716                     Table.BuildTable(Fill->Colour, Fill->EndColour, GetRenderView(), GetFillEffect(), LargeGradTables);
02717                 }
02718                 else
02719                 {
02720                     Table.BuildHighQualityRepeatTable(Fill->Colour, Fill->EndColour, NULL, GetRenderView(), GetFillEffect());
02721                 }
02722             }
02723 
02724             if (Perspective)
02725                 GetDrawContext()->SetGraduation4( Style, Table.GetTable(), &A, &B, &C, &D );
02726             else
02727                 GetDrawContext()->SetGraduation( Style, Table.GetTable(), &A, &B, &C );
02728         }
02729         else
02730         {
02731             
02732 
02733             if (Tiling != 4)
02734             {
02735                 Table.BuildTable(Fill->Colour, Fill->EndColour, GetRenderView(), GetFillEffect(), DiagramMapper, LargeGradTables);
02736                 GetDrawContext()->SetGraduation( Style, Table.GetTable(), &A, &B, &C );
02737             }
02738             else
02739             {
02740                 Table.BuildHighQualityRepeatTable(Fill->Colour, Fill->EndColour, GetRenderView(), GetFillEffect(), DiagramMapper);
02741                 GetDrawContext()->SetGraduation( Style, Table.GetTable(), &A, &B, &C );
02742             }
02743             GetDrawContext()->SetGraduation( Style, Table.GetTable(), &A, &B, &C );
02744         }
02745     }
02746 
02747     
02748     DocCoord* Coords;
02749     PathVerb* Verbs;
02750     UINT32 TotalCoords;
02751     BOOL ShouldDeleteCoords = FALSE;
02752 
02753     
02754     if (TryToFuzzyClip(PathToDraw, &Coords, &Verbs, &TotalCoords))
02755     {
02756         
02757         ShouldDeleteCoords = TRUE;
02758     }
02759     else
02760     {
02761         
02762         Coords = PathToDraw->GetCoordArray();
02763         Verbs  = PathToDraw->GetVerbArray();
02764         TotalCoords = PathToDraw->GetNumCoords();
02765     }
02766 
02767     
02768     if (TotalCoords > 1)
02769         GetDrawContext()->FillPath( (POINT*)Coords, Verbs, TotalCoords, (RR_WINDINGRULE()==EvenOddWinding) ? 0 : 1 );
02770 
02771     
02772     if (ShouldDeleteCoords)
02773     {
02774         delete Coords;
02775         delete Verbs;
02776     }
02777 
02778     #if 0
02779     if (0)
02780     {
02781         
02782         GetDrawContext()->SetColour( RGB(0,0,0) );
02783          POINT Path[5];
02784         BYTE Verbs[] = { PT_MOVETO, PT_LINETO, PT_MOVETO, PT_LINETO, PT_LINETO };
02785         POINT D;
02786         D.x = (A.x+B.x)/2;
02787         D.y = (A.y+B.y)/2;
02788 
02789         Path[0] = A;
02790         Path[1] = B;
02791         Path[2] = A;
02792         Path[3] = C;
02793         Path[4] = D;
02794         GetDrawContext()->StrokePath( (LPPOINT)Path, Verbs, sizeof(Verbs), FALSE, 0, CAPS_ROUND, JOIN_ROUND, NULL );
02795     }
02796     #endif
02797     return TRUE;
02798 }
02799 
02800 
02801 
02802 
02804 
02805 
02806 
02808 
02809 INT32 PixelsPerMeterAtCurrentViewScale( FIXED16 Scale)
02810 {
02811     double  PixPerMetre =   PIXELS_PER_INCH * INCHES_PER_METRE;
02812             PixPerMetre *=  Scale.MakeDouble();
02813 
02814     return (INT32) (PixPerMetre + 0.5);
02815 }
02816 
02817 
02818 
02819 
02820 
02821 
02822 
02823 
02824 
02825 
02826 
02827 
02828 
02829 
02830 
02831 
02832 
02833 
02834 
02835 void GRenderRegion::SetOffscreen(OffscreenAttrValue* pAttr)
02836 {
02837     
02838     
02839     
02840     if (IsHitDetect())
02841         return;
02842 
02843     if (m_ForcePrintingCaps)
02844         return;
02845 
02846     
02847     RenderRegion::SetOffscreen(pAttr);
02848 }
02849 
02850 
02851 
02852 
02853 
02854 
02855 
02856 
02857 
02858 
02859 
02860 
02861 
02862 
02863 
02864 
02865 
02866 
02867 
02868 
02869 
02870 
02871 
02872 
02873 
02874 
02875 
02876 
02877 
02878 
02879 
02880 
02881 
02882 
02883 
02884 
02885 
02886 
02887 
02888 
02889 
02890 
02891 
02892 
02893 
02894 
02895 
02896 
02897 
02898 
02899 
02900 
02901 
02902 
02903 
02904 
02905 
02906 
02907 
02908 
02909 
02910 
02911 
02912 
02913 
02914 
02915 
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 
02942 
02943 
02944 
02945 
02946 
02947 
02948 
02949 
02950 
02951 
02952 
02953 
02954 
02955 
02956 
02957 
02958 
02959 
02960 
02961 
02962 
02963 
02964 
02965 
02966 
02967 
02968 
02969 
02970 
02971 
02972 
02973 
02974 
02975 
02976 
02977 
02978 
02979 
02980 
02981 
02982 
02983 
02984 
02985 
02986 
02987 
02988 
02989 
02990 
02991 
02992 
02993 
02994 
02995 
02996 
02997 
02998 
02999 
03000 
03001 
03002 
03003 
03004 
03005 
03006 
03007 
03008 
03009 
03010 
03011 
03012 
03013 
03014 
03015 
03016 
03017 
03018 
03019 
03020 
03021 
03022 
03023 
03024 
03025 
03026 
03027 
03028 
03029 
03030 
03031 
03032 
03033 void GRenderRegion::RestoreOffscreen(OffscreenAttrValue* pAttr)
03034 {
03035     if (m_ForcePrintingCaps)
03036         return;
03037 
03038     
03039     
03040     RenderRegion::RestoreOffscreen(pAttr);
03041 }
03042 
03043 
03044 
03045 
03046 
03047 
03048 
03049 
03050 
03051 
03052 
03053 
03054 
03055 
03056 
03057 
03058 
03059 
03060 
03061 
03062 
03063 
03064 
03065 
03066 
03067 
03068 
03069 
03070 
03071 
03072 
03073 
03074 
03075 
03076 
03077 
03078 BOOL GRenderRegion::RenderBitmapWithTransparency(
03079                                                  Path *pPath,
03080                                                  BitmapFillAttribute* pFill,
03081                                                  BitmapTranspFillAttribute* pTranspFill
03082                                                 )
03083 {
03084 
03085 
03086 
03087 
03088 
03089 
03090 
03091 
03092 
03093 
03094 
03095 
03096 
03097 
03098 
03099 
03100 
03101 
03102 
03103 
03104 
03105 
03106 
03107 
03108 
03109 
03110 
03111 
03112 
03113 
03114 
03115 
03116 
03117 
03118 
03119     
03120     FillMappingAttribute* pCurrentFillMapAttr = (FillMappingAttribute*)CurrentAttrs[ATTR_FILLMAPPING].pAttr;
03121 
03122     FillMappingAttribute FillMap;
03123     FillMap.Repeat = 1;
03124 
03125     CurrentAttrs[ATTR_FILLMAPPING].pAttr = (AttributeValue*)&FillMap;
03126 
03127 
03129     
03130     
03131     
03132     
03133 
03134     TranspFillAttribute* pCurrentTranspAttr = NULL;
03135     TranspFillMappingAttribute* pCurrentTranspMapAttr = NULL;
03136     TranspFillMappingAttribute TranspMap;
03137     TranspMap.Repeat = 1;
03138 
03139     if (pTranspFill != NULL)
03140     {
03141         pCurrentTranspAttr = RR_FILLTRANSP();
03142         pCurrentTranspMapAttr = (TranspFillMappingAttribute*)CurrentAttrs[ATTR_TRANSPFILLMAPPING].pAttr;
03143 
03144         CurrentAttrs[ATTR_TRANSPFILLGEOMETRY].pAttr = pTranspFill;
03145         CurrentAttrs[ATTR_TRANSPFILLMAPPING].pAttr = (AttributeValue*)&TranspMap;
03146     }
03147 
03148     BOOL res = RenderBitmapFill(pPath, pFill);
03149 
03150     
03151     CurrentAttrs[ATTR_FILLMAPPING].pAttr = pCurrentFillMapAttr;
03152     if (pTranspFill != NULL)
03153     {
03154         CurrentAttrs[ATTR_TRANSPFILLGEOMETRY].pAttr = pCurrentTranspAttr;
03155         CurrentAttrs[ATTR_TRANSPFILLMAPPING].pAttr = pCurrentTranspMapAttr;
03156     }
03157 
03158     return res;
03159 
03160 }
03161 
03163 
03164 
03165 
03166 
03167 
03168 
03169 
03170 
03171 
03172 
03173 
03174 
03175 
03176 
03177 
03178 
03179 
03180 
03181 
03182 
03183 
03184 
03185 
03186 BOOL GRenderRegion::IsScaledUp(FillGeometryAttribute *Fill)
03187 {
03188     
03189     BOOL bIsBitmapFill = (  (Fill->IsKindOf( CC_RUNTIME_CLASS(BitmapFillAttribute) ))
03190                         ||  (Fill->IsKindOf( CC_RUNTIME_CLASS(TranspFillAttribute) )));
03191 
03192     ERROR3IF( (!bIsBitmapFill), "GRenderRegion::IsScaledUp - Fill should be a bmp fill or a transp bmp fill" );
03193     if( !bIsBitmapFill ) return FALSE;
03194 
03195 
03196     
03197     DocCoord* pStartpoint   = Fill->GetStartPoint();
03198     DocCoord* pEndpoint     = Fill->GetEndPoint();
03199     DocCoord* pEndpoint2    = Fill->GetEndPoint2();
03200 
03201     
03202     UINT32 NewWidth = (UINT32)(0.5 + pStartpoint->Distance(*pEndpoint)  / GetScaledPixelWidth());
03203     UINT32 NewHeight    = (UINT32)(0.5 + pStartpoint->Distance(*pEndpoint2) / GetScaledPixelWidth());
03204 
03205     return (NewWidth > Fill->GetBitmap()->GetWidth() && NewHeight > Fill->GetBitmap()->GetHeight());
03206 }
03207 
03208 
03209 
03210 
03211 
03212 
03213 
03214 
03215 
03216 
03217 
03218 
03219 
03220 
03221 
03222 
03223 
03224 BOOL GRenderRegion::IsAt100Percent(FillGeometryAttribute *Fill)
03225 {
03226     
03227     BOOL bIsBitmapFill = (  (Fill->IsKindOf( CC_RUNTIME_CLASS(BitmapFillAttribute) ))
03228                         ||  (Fill->IsKindOf( CC_RUNTIME_CLASS(TranspFillAttribute) )));
03229 
03230     ERROR3IF( (!bIsBitmapFill), "GRenderRegion::IsAt100Percent - Fill should be a bmp fill or a transp bmp fill" );
03231     if( !bIsBitmapFill ) return FALSE;
03232 
03233 
03234     
03235     DocCoord* pStartpoint   = Fill->GetStartPoint();
03236     DocCoord* pEndpoint     = Fill->GetEndPoint();
03237     DocCoord* pEndpoint2    = Fill->GetEndPoint2();
03238 
03239     
03240     UINT32 NewWidth = (UINT32)(0.5 + pStartpoint->Distance(*pEndpoint)  / GetScaledPixelWidth());
03241     UINT32 NewHeight    = (UINT32)(0.5 + pStartpoint->Distance(*pEndpoint2) / GetScaledPixelWidth());
03242 
03243     return (NewWidth == Fill->GetBitmap()->GetWidth() && NewHeight == Fill->GetBitmap()->GetHeight());
03244 }
03245 
03246 
03247 
03248 
03249 
03250 
03251 
03252 
03253 
03254 
03255 
03256 
03257 
03258 
03259 
03260 
03261 
03262 BOOL GRenderRegion::IsDistorted(FillGeometryAttribute *Fill)
03263 {
03264     
03265     BOOL bIsBitmapFill = (  (Fill->IsKindOf( CC_RUNTIME_CLASS(BitmapFillAttribute) ))
03266                         ||  (Fill->IsKindOf( CC_RUNTIME_CLASS(TranspFillAttribute) )));
03267 
03268     ERROR3IF( (!bIsBitmapFill), "GRenderRegion::IsDistorted - Fill should be a bmp fill or a transp bmp fill" );
03269     if( !bIsBitmapFill ) return FALSE;
03270 
03271 
03272     
03273     DocCoord* pStartpoint   = Fill->GetStartPoint();
03274     DocCoord* pEndpoint     = Fill->GetEndPoint();
03275     DocCoord* pEndpoint2    = Fill->GetEndPoint2();
03276 
03277     
03278     
03279     
03280     
03281     
03282     
03283     
03284     
03285     
03286     
03287     
03288     
03289     
03290     
03291     
03292     
03293 
03294     ERROR3IF(GetScaledPixelWidth()==0, "Scaled pixel width is 0 in IsDistorted");
03295     if (GetScaledPixelWidth()==0)
03296         return TRUE;
03297     
03298     ERROR3IF(GetScaledPixelWidth()==0, "It's all gone wrong!");
03299     if (GetScaledPixelWidth()==0) return TRUE;                      
03300 
03301     UINT32 x0 = UINT32(0.5 + pStartpoint->x / GetScaledPixelWidth());
03302     UINT32 y0 = UINT32(0.5 + pStartpoint->y / GetScaledPixelWidth());
03303     UINT32 x1 = UINT32(0.5 + pEndpoint  ->x / GetScaledPixelWidth());
03304     UINT32 y1 = UINT32(0.5 + pEndpoint  ->y / GetScaledPixelWidth());
03305     UINT32 x2 = UINT32(0.5 + pEndpoint2 ->x / GetScaledPixelWidth());
03306     UINT32 y2 = UINT32(0.5 + pEndpoint2 ->y / GetScaledPixelWidth());
03307 
03308     
03309     
03310     
03311 
03312     return !((x0==x1 && y0==y2) || (x0==x2 && y0==y1));
03313 }
03314 
03315 
03316 
03317 
03318 
03319 
03320 
03321 
03322 
03323 
03324 
03325 
03326 
03327 
03328 
03329 
03330 
03331 
03332 
03333 
03334 
03335 
03336 
03337 
03338 
03339 BOOL GRenderRegion::NeedToSmooth(FillGeometryAttribute *Fill,BOOL bAlreadyScaled)
03340 {
03341     
03342     
03343     
03344 
03345     if (IsForcingBitmapSmoothing())
03346     {
03347         return TRUE;
03348     }
03349 
03350     
03351     
03352     
03353     if (Fill==NULL ||
03354         BitmapFillAttribute::m_doBitmapSmoothing == FALSE ||
03355         RRQuality.GetAntialiasQuality() < Quality::FullAntialias ||
03356         (Document::GetCurrent() && !(Document::GetCurrent())->GetBitmapSmoothing()) )
03357     {
03358         return FALSE;
03359     }
03360 
03361     
03362     BOOL bNot100Percent = ! (IsAt100Percent(Fill) || bAlreadyScaled);
03363     BOOL bNotScaledUp   = ! IsScaledUp(Fill);
03364     BOOL bIsDistorted = IsDistorted(Fill);
03365 
03366     
03367     
03368     if( Fill->GetBitmap()->GetInterpolation() )
03369     {
03370         
03371         return (bNot100Percent || bIsDistorted);
03372     }
03373     else
03374     {
03375         
03376         return ((bNot100Percent && bNotScaledUp) || ((!bNot100Percent) && bIsDistorted));
03377     }
03378 }
03379 
03380 
03381 
03382 
03383 
03384 
03385 
03386 
03387 
03388 
03389 
03390 
03391 
03392 
03393 
03394 
03395 
03396 
03397 
03398 BOOL GRenderRegion::SetSmoothingFlags(FillGeometryAttribute *Fill)
03399 {
03400     
03401     BOOL bNeedMaxQuality = (IsUsingSmoothedBitmaps() || IsPrinting());
03402 
03403     
03404     
03405     
03406     BOOL SetExtraSmoothFlag   = FALSE;
03407     BOOL SetTileFilteringFlag = FALSE;
03408 
03409     if( !bNeedMaxQuality )
03410     {
03411         
03412         
03413         
03414         
03415         SetExtraSmoothFlag = NeedToSmooth( Fill, FALSE  );
03416     }
03417     else
03418     {
03419         
03420         
03421         SetTileFilteringFlag = NeedToSmooth( Fill, FALSE );
03422     }
03423 
03424     
03425     Capture* pCapture = GetTopCapture();
03426     if (pCapture)
03427     {
03428         if (!SetExtraSmoothFlag) SetExtraSmoothFlag = pCapture->info.caFlags.BitmapSmoothing;
03429         if (!SetTileFilteringFlag) SetTileFilteringFlag = pCapture->info.caFlags.TileFiltering;
03430     }
03431 
03432     GetDrawContext()->SetTileSmoothingFlag(SetExtraSmoothFlag);
03433     GetDrawContext()->SetTileFilteringFlag(SetTileFilteringFlag);
03434 
03435     return TRUE;
03436 }
03437 
03438 
03439 
03440 
03441 
03442 
03443 
03444 
03445 
03446 
03447 
03448 
03449 
03450 
03451 
03452 
03453 
03454 BOOL GRenderRegion::RenderBitmapFill(Path *PathToDraw, BitmapFillAttribute* Fill)
03455 {
03456     if ( Fill==NULL || Fill->GetBitmap()==NULL || Fill->GetBitmap()->ActualBitmap==NULL)
03457         return FALSE;                                   
03458 
03459     ENSURE( Fill->GetBitmap()->ActualBitmap->IsKindOf( CC_RUNTIME_CLASS( CWxBitmap ) ),
03460                                                                 "Strange bitmapfill");
03461 
03462     INT32 bpp = Fill->GetBitmap()->GetBPP();
03463     CWxBitmap *WinBM = NULL;
03464     CWxBitmap *OrigWinBM = NULL;
03465 
03466 
03467 
03468 
03469 
03470 
03471 
03472 
03473 
03474 
03475 
03476 
03477 
03478 
03479 
03480 
03481 
03482 
03483 
03484 
03485 
03486 
03487 
03488 
03489 
03490 
03491 
03492 
03493       
03494         WinBM = (CWxBitmap*)Fill->GetBitmap()->ActualBitmap;
03495 
03496 
03497     if (WinBM == NULL || WinBM->BMInfo == NULL  || WinBM->BMBytes == NULL)
03498         return FALSE;
03499 
03500     
03501     POINT PGram[4];
03502     PGram[0].x = Fill->StartPoint.x; PGram[0].y = Fill->StartPoint.y;
03503     PGram[1].x = Fill->EndPoint.x;   PGram[1].y = Fill->EndPoint.y;
03504 
03505     BOOL Perspective = Fill->IsPerspective();
03506     if ( Perspective )
03507     {
03508         
03509         PGram[2].x = Fill->EndPoint3.x; PGram[2].y = Fill->EndPoint3.y;
03510         PGram[3].x = Fill->EndPoint2.x; PGram[3].y = Fill->EndPoint2.y;
03511 
03512         if ( !MouldPerspective::WillBeValid(PGram) )
03513         {
03514             Perspective = FALSE;
03515             TRACEUSER( "Will", _T("Bitmap Perspective points are Invalid !!\n"));
03516         }
03517     }
03518     if ( !Perspective )
03519     {
03520         PGram[2].x = Fill->EndPoint2.x;
03521         PGram[2].y = Fill->EndPoint2.y;
03522     }       
03523 
03524     
03525     COLORREF DefaultColour = 0xFFFFFFFF;
03526 
03527     DWORD Style = 0;
03528     TranspGradTable TranspTable;
03529 
03530     if (uBitmapDepth==32)
03531     {
03532         
03533         GetTransparencyFill(&TranspTable, &Style);
03534     }
03535     else
03536         Style = WhichTransparency<<8;
03537 
03538     INT32 Tiling = ((FillMappingAttribute*)CurrentAttrs[ATTR_FILLMAPPING].pAttr)->Repeat;
03539     Style |= Tiling;
03540 
03541     
03542     RGBQUAD *Palette = NULL;
03543 
03544     
03545     
03546 
03547 
03548 
03549 
03550 
03551 
03552 
03553 
03554 
03555 
03556 
03557 
03558 
03559 
03560 
03561 
03562 
03563 
03564 
03565 
03566 
03567 
03568 
03569 
03570 
03571 
03572 
03573 
03574     
03575     BYTE *BitmapBits = WinBM->BMBytes;
03576 
03577     if (bpp <= 8)
03578     {
03579         INT32 NumCols = 1<<bpp;
03580         
03581         for (INT32 i=0; i<NumCols; i++)
03582         {
03583             if (WinBM->BMInfo->bmiColors[i].rgbReserved == 0xFF)
03584             {
03585                 Style |= 0x008000;
03586 
03587                 if (RenderFlags.VeryMono)
03588                 {
03589                     
03590                     
03591                     
03592                     if (Palette == NULL)    
03593                         Palette = (RGBQUAD *) CCMalloc(256 * sizeof(RGBQUAD));
03594 
03595                     if (Palette != NULL)
03596                     {
03597                         
03598                         memset(Palette, 0, 256*sizeof(RGBQUAD));
03599                         
03600                         Palette[i].rgbRed       = 0xFF;
03601                         Palette[i].rgbGreen     = 0xFF;
03602                         Palette[i].rgbBlue      = 0xFF;
03603                         Palette[i].rgbReserved  = 0xFF;
03604                     }
03605                 }
03606                 break;
03607             }
03608         }
03609     }
03610 
03611     
03612     if ( Palette==NULL && bpp<=8 && !Fill->IsKindOf(CC_RUNTIME_CLASS(FractalFillAttribute)) &&
03613                                     !Fill->IsKindOf(CC_RUNTIME_CLASS(  NoiseFillAttribute)) )
03614         Palette = WinBM->BMInfo->bmiColors;
03615 
03616     LPBYTE pTranspTable = NULL;
03617     if ( uBitmapDepth==32 && bpp==32 )
03618     {
03619         
03620         
03621         pTranspTable = (LPBYTE) TranspTable.GetTable();         
03622                                                                 
03623         Style |= 0x004000;  
03624                             
03625     }
03626 
03627     BOOL bDoBitmapFill = TRUE;
03628 
03629     BOOL bClearBitmapConv = FALSE;
03630     BYTE* pSepTables = NULL;
03631 
03632 
03633 
03634 
03635 
03636 
03637     CWxBitmap* pNewBitmap = NULL;
03638     
03639     
03640     
03641     
03642     if (bpp > 8)    
03643     {
03644         
03645         if (CurrentColContext->GetColourPlate() != NULL &&
03646             !CurrentColContext->GetColourPlate()->IsDisabled())
03647         {
03648             
03649             if (CurrentColContext->GetColourPlate()->GetType() == COLOURPLATE_COMPOSITE)
03650             {
03651                 
03652                 
03653 PORTNOTE("cms", "DisabledXaraCMS")
03654 #ifndef EXCLUDE_FROM_XARALX
03655                 XaraCMS* lpCMSMan = GetApplication()->GetCMSManager();
03656                 if (lpCMSMan != NULL)
03657                 {
03658                     DWORD *MatchTable = lpCMSMan->GetPaperViewTable();
03659                     ERROR3IF(MatchTable == NULL, "Can't create/find colour matching table");
03660                     if (MatchTable != NULL)
03661                     {
03662                         GetDrawContext()->SetBitmapConversionTable((BGR *)MatchTable);
03663                         bClearBitmapConv = TRUE;
03664                         
03665                         
03666                         Style |= ((BitmapConversion & 3) << 27);
03667                         
03668                         
03669 
03670 
03671 
03672 
03673                     }
03674                 }
03675 #endif
03676             }
03677             else if (CurrentColContext->GetColourPlate()->GetType() == COLOURPLATE_SPOT)
03678             {
03679                 GetDrawContext()->SetColour(0xFFFFFF);
03680                 bDoBitmapFill = FALSE;
03681             }
03682             else if (CurrentColContext->GetColourPlate()->GetType() != COLOURPLATE_NONE)
03683             {
03684                 pSepTables = (BYTE *) CCMalloc(5 * 256 * sizeof(BYTE));
03685                 if (pSepTables != NULL)
03686                 {
03687                     String_256 PrintProfile;
03688 PORTNOTE("cms", "DisabledXaraCMS")
03689 #ifndef EXCLUDE_FROM_XARALX
03690                     XaraCMS* lpCMSMan = GetApplication()->GetCMSManager();
03691                     if (lpCMSMan)
03692                         lpCMSMan->GetPrinterProfile(&PrintProfile);
03693 #endif
03694                     ColourContextCMYK *cc = new ColourContextCMYK(RenderView, &PrintProfile);
03695                     if (cc->GetProfileTables(pSepTables))
03696                     {
03697                         
03698                         pNewBitmap = (CWxBitmap*)WinBM->MakeSeparatedCopy(RenderView->GetColourPlate(), pSepTables);
03699                         OrigWinBM = WinBM;                  
03700                         WinBM = pNewBitmap;                 
03701                         BitmapBits = WinBM->BMBytes;        
03702                     }
03703                     delete cc;
03704                 }
03705             }
03706         }
03707     }
03708 
03709     BOOL Result = FALSE; 
03710 
03711     if (bDoBitmapFill)
03712     {
03713         
03714         
03715         
03716 
03717         if ( Fill->GetStartColour()!=NULL && Fill->GetEndColour()!=NULL )
03718         {
03719             DocColour* pCS = Fill->GetStartColour();
03720             DocColour* pCE = Fill->GetEndColour  ();
03721             INT32 sr,sg,sb;
03722             INT32 er,eg,eb;
03723             pCS->GetRGBValue(&sr,&sg,&sb);
03724             pCE->GetRGBValue(&er,&eg,&eb);
03725             GetDrawContext()->SetContone(GetFillEffect()+1,RGB(sr,sg,sb),RGB(er,eg,eb));
03726         }
03727         else
03728             GetDrawContext()->SetContone(0);
03729 
03730         GetDrawContext()->SetBias(3,Fill->GetProfile().GetBias()) ;
03731         GetDrawContext()->SetGain(3,Fill->GetProfile().GetGain()) ;
03732         GetDrawContext()->SetOutputRange(3,0x00,0xFF) ;
03733 
03734         
03735         
03736         
03737 
03738         SetSmoothingFlags(Fill);
03739 
03740         
03741         
03742         
03743 
03744         
03745 
03746         if (Perspective)    
03747         {
03748             
03749             Result = GetDrawContext()->SetPerspectiveBitmapFill(
03750                             &(WinBM->BMInfo->bmiHeader),
03751                             BitmapBits,
03752                             Style,
03753                             PGram,
03754                             DefaultColour,
03755                             Palette,
03756                             NULL, NULL, NULL, pTranspTable,
03757                             0
03758                             );
03759         }
03760         else
03761         {
03762             
03763             Result = GetDrawContext()->SetBitmapFill(
03764                             &(WinBM->BMInfo->bmiHeader),
03765                             BitmapBits,
03766                             Style,
03767                             PGram,
03768                             DefaultColour,
03769                             Palette,
03770                             NULL, NULL, NULL, pTranspTable,
03771                             0
03772                             );
03773         }
03774     }
03775 
03776     
03777     DocCoord* Coords;
03778     PathVerb* Verbs;
03779     UINT32 TotalCoords;
03780     BOOL ShouldDeleteCoords = FALSE;
03781 
03782     
03783     if (TryToFuzzyClip(PathToDraw, &Coords, &Verbs, &TotalCoords))
03784     {
03785         
03786         ShouldDeleteCoords = TRUE;
03787     }
03788     else
03789     {
03790         
03791         Coords = PathToDraw->GetCoordArray();
03792         Verbs  = PathToDraw->GetVerbArray();
03793         TotalCoords = PathToDraw->GetNumCoords();
03794     }
03795 
03796     
03797     if (TotalCoords > 1)
03798         GetDrawContext()->FillPath( (POINT*)Coords, Verbs, TotalCoords, (RR_WINDINGRULE()==EvenOddWinding) ? 0 : 1 );
03799 
03800 PORTNOTE( "other", "m_pTempTransparencyBMPBits seems never to be used, removed by GAT" )
03801 #ifndef EXCLUDE_FROM_XARALX
03802     
03803     
03804     
03805     if (m_pTempTransparencyBMPBits)
03806     {
03807         CCFree (m_pTempTransparencyBMPBits);
03808         m_pTempTransparencyBMPBits = NULL;
03809     }
03810 #endif
03811 
03812     
03813     if (ShouldDeleteCoords)
03814     {
03815         delete Coords;
03816         delete Verbs;
03817     }
03818 
03819     if (pNewBitmap)
03820     {
03821         WinBM = OrigWinBM;
03822         delete pNewBitmap;
03823     }
03824 
03825 
03826 
03827 
03828 
03829 
03830 
03831 
03832     
03833     
03834     
03835     if (Palette != WinBM->BMInfo->bmiColors)
03836         CCFree(Palette);
03837 
03838     if (bClearBitmapConv)
03839         GetDrawContext()->SetBitmapConversionTable(NULL);
03840 
03841     if (pSepTables)
03842     {
03843         GetDrawContext()->SetSeparationTables();    
03844         CCFree(pSepTables);
03845     }
03846 
03847 
03848 
03849 
03850 
03851 
03852 
03853 
03854 
03855 
03856 
03857 
03858 
03859 
03860     
03861     SetSmoothingFlags(NULL);
03862 
03863     return TRUE;
03864 }
03865 
03866 
03867 
03868 
03869 
03870 
03871 
03872 
03873 
03874 
03875 
03876 
03877 
03878 
03879 
03880 
03881 
03882 
03883 
03884 
03885 
03886 
03887 
03888 BOOL GRenderRegion::GetTransparencyFill(TranspGradTable* pTranspTable, DWORD* Style)
03889 {
03890     if (uBitmapDepth != 32)
03891         return FALSE;       
03892 
03893     COLORREF StartTransp;
03894     COLORREF EndTransp;
03895     DWORD TransStyle = 0;
03896     BOOL SpecialFill = FALSE;
03897 
03898     
03899     TranspFillAttribute* TranspFill = RR_FILLTRANSP();
03900 
03901 
03902 
03903 
03904     
03905 
03906 
03907 
03908     StartTransp = 0;
03909 
03910     if (TranspFill->GetStartTransp() != NULL)
03911         StartTransp = *TranspFill->GetStartTransp();
03912 
03913     UINT32 tType = TranspFill->GetTranspType();
03914 
03915     
03916     CCRuntimeClass* FillType = TranspFill->GetRuntimeClass();
03917 
03918     
03919     
03920     if (FillType == CC_RUNTIME_CLASS(FlatTranspFillAttribute))
03921     {
03922         if (tType == TT_Mix && StartTransp == 0)
03923             return FALSE;       
03924 
03925         *Style |= (MapTranspTypeToGDraw(tType, FALSE)<<8);
03926         *Style |= (StartTransp<<16);
03927 
03928         return TRUE;
03929     }
03930     else if (FillType == CC_RUNTIME_CLASS(ThreeColTranspFillAttribute))
03931     {
03932         SpecialFill = TRUE;
03933     }
03934     else if (FillType == CC_RUNTIME_CLASS(FourColTranspFillAttribute))
03935     {
03936         SpecialFill = TRUE;
03937     }
03938     else if (TranspFill->IsKindOf(CC_RUNTIME_CLASS(BitmapTranspFillAttribute)))
03939     {
03940 
03941 
03942         
03943         return SetBitmapTransparencyFill((TranspFillAttribute*)TranspFill, Style, pTranspTable);
03944     }
03945 
03946     EndTransp = 255;
03947 
03948     if (TranspFill->GetEndTransp() != NULL)
03949         EndTransp = *TranspFill->GetEndTransp();
03950 
03951     
03952     
03953     
03954 
03955     
03956 
03957     
03958     
03959     
03960     
03961     
03962     
03963 
03964     CProfileBiasGain DefaultBiasGain;                               
03965     CProfileBiasGain DiagramMapper = TranspFill->GetProfile ();     
03966 
03967     INT32 Tiling = ((FillMappingAttribute*)CurrentAttrs[ATTR_TRANSPFILLMAPPING].pAttr)->Repeat;
03968 
03969     
03970     
03971     if (DiagramMapper == DefaultBiasGain)           
03972     {
03973         if (!SpecialFill)
03974         {
03975             TransparencyRamp *pTranspRamp = TranspFill->GetTranspRamp();
03976 
03977             if (Tiling != 4)
03978             {
03979                 pTranspTable->BuildTable(StartTransp, EndTransp, pTranspRamp);
03980             }
03981             else
03982             {
03983                 pTranspTable->BuildHighQualityRepeatTable(StartTransp, EndTransp, pTranspRamp);
03984             }
03985         }
03986     }
03987     else
03988     {
03989         if (!SpecialFill)
03990         {
03991             if (Tiling != 4)
03992             {
03993                 pTranspTable->BuildTable(StartTransp, EndTransp, DiagramMapper);
03994             }
03995             else
03996             {
03997                 pTranspTable->BuildHighQualityRepeatTable(StartTransp, EndTransp, DiagramMapper);
03998             }
03999         }
04000     }
04001 
04002 
04003 
04004     
04005     POINT TA,TB,TC,TD;
04006 
04007     DocCoord* StartPoint    = TranspFill->GetStartPoint();
04008     DocCoord* EndPoint      = TranspFill->GetEndPoint();
04009     DocCoord* EndPoint2     = TranspFill->GetEndPoint2();
04010     DocCoord* EndPoint3     = TranspFill->GetEndPoint3();
04011 
04012     if (StartPoint != NULL)
04013     {
04014         TA.x = (*StartPoint).x; 
04015         TA.y = (*StartPoint).y;
04016     }
04017 
04018     if (EndPoint != NULL)
04019     {
04020         TB.x = (*EndPoint).x;   
04021         TB.y = (*EndPoint).y;
04022     }
04023 
04024     if (EndPoint2 != NULL)
04025     {
04026         TC.x = (*EndPoint2).x;  
04027         TC.y = (*EndPoint2).y;
04028     }
04029 
04030     
04031     if (FillType == CC_RUNTIME_CLASS(RadialTranspFillAttribute))
04032     {
04033         TransStyle = 1;     
04034     }
04035     else if (FillType == CC_RUNTIME_CLASS(LinearTranspFillAttribute))
04036     {
04037         TransStyle = 0;     
04038 
04039         TA.x = (*StartPoint).x; TA.y = (*StartPoint).y;
04040         TB.x = (*EndPoint2).x;  TB.y = (*EndPoint2).y;
04041         TC.x = (*EndPoint).x;   TC.y = (*EndPoint).y;
04042     }
04043     else if (FillType == CC_RUNTIME_CLASS(ConicalTranspFillAttribute))
04044     {
04045         TransStyle = 2;     
04046 
04047         TB.x = TA.x - (TB.x - TA.x);
04048         TB.y = TA.y - (TB.y - TA.y);
04049     }
04050     else if (FillType == CC_RUNTIME_CLASS(SquareTranspFillAttribute))
04051     {
04052         TransStyle = 3;     
04053     }
04054 
04055 
04056     BOOL Perspective = FALSE;
04057 
04058     
04059     if (TranspFill->IsPerspective())
04060     {
04061         Perspective = TRUE;
04062 
04063         POINT PGram[4];
04064 
04065         
04066         if (FillType==CC_RUNTIME_CLASS(LinearTranspFillAttribute))
04067         {
04068             PGram[0].x = (*StartPoint).x;   PGram[0].y = (*StartPoint).y;
04069             PGram[1].x = (*EndPoint2).x;    PGram[1].y = (*EndPoint2).y;
04070             PGram[2].x = (*EndPoint3).x;    PGram[2].y = (*EndPoint3).y;
04071             PGram[3].x = (*EndPoint).x;     PGram[3].y = (*EndPoint).y;
04072         }
04073         else
04074         {
04075             PGram[0].x = TA.x;              PGram[0].y = TA.y;
04076             PGram[1].x = TB.x;              PGram[1].y = TB.y;
04077             PGram[2].x = (*EndPoint3).x;    PGram[2].y = (*EndPoint3).y;
04078             PGram[3].x = (*EndPoint2).x;    PGram[3].y = (*EndPoint2).y;
04079         }
04080 
04081         
04082         
04083         if (MouldPerspective::WillBeValid(PGram))
04084         {
04085             
04086             
04087             TA.x = PGram[0].x;  TA.y = PGram[0].y;
04088             TB.x = PGram[1].x;  TB.y = PGram[1].y;
04089             TC.x = PGram[2].x;  TC.y = PGram[2].y;
04090             TD.x = PGram[3].x;  TD.y = PGram[3].y;
04091         }
04092         else 
04093         {
04094             
04095             Perspective = FALSE;
04096         }
04097     }
04098 
04099     if (SpecialFill)
04100     {
04101         
04102 
04103         if ((FillType != CC_RUNTIME_CLASS(ThreeColTranspFillAttribute)) &&
04104             (FillType != CC_RUNTIME_CLASS(FourColTranspFillAttribute)))
04105         {
04106             ERROR3("Unknown new fill type");
04107             return FALSE;                               
04108         }
04109 
04110         BYTE StartTransp = *TranspFill->GetStartTransp();
04111         BYTE EndTransp = *TranspFill->GetEndTransp();
04112         BYTE EndTransp2 = *TranspFill->GetEndTransp2();
04113 
04114         BYTE EndTransp3 = 255;
04115         if (TranspFill->GetEndTransp3() != NULL)
04116             EndTransp3 = *TranspFill->GetEndTransp3();
04117 
04118         DWORD OurStyle = 0;
04119 
04120         if (FillType == CC_RUNTIME_CLASS(ThreeColTranspFillAttribute))
04121         {           
04122             
04123             
04124 
04125             if (Tiling == 1)
04126                 OurStyle |= 0;
04127             else
04128                 OurStyle |= 2;
04129 
04130             if (Perspective)
04131                 GetDrawContext()->SetTransparent3WayGraduation4(OurStyle, StartTransp, EndTransp, EndTransp2,
04132                                                     &TA, &TB, &TC, &TD);
04133             else
04134                 GetDrawContext()->SetTransparent3WayGraduation(OurStyle, StartTransp, EndTransp, EndTransp2,
04135                                                     &TA, &TB, &TC);
04136         }
04137         else
04138         {
04139             
04140 
04141             if (Tiling == 1)
04142                 OurStyle |= 1;
04143             else
04144                 OurStyle |= 2;
04145 
04146             
04147             if (Perspective)
04148                 GetDrawContext()->SetTransparent4WayGraduation4(OurStyle, StartTransp, EndTransp, EndTransp3, EndTransp2,
04149                                                     &TA, &TB, &TC, &TD);
04150             else
04151                 GetDrawContext()->SetTransparent4WayGraduation(OurStyle, StartTransp, EndTransp, EndTransp3, EndTransp2,
04152                                                     &TA, &TB, &TC);
04153         }
04154     }
04155     else
04156     {
04157 
04158 #ifdef NEW_FEATURES
04159         if(Tiling == 4)
04160             TransStyle |= 0x10000;
04161 #endif  
04162 
04163         if (Perspective)
04164             GetDrawContext()->SetTransparentGraduation4( TransStyle, pTranspTable, &TA, &TB, &TC, &TD );
04165         else
04166             GetDrawContext()->SetTransparentGraduation( TransStyle, pTranspTable, &TA, &TB, &TC );
04167     }
04168 
04169     
04170     
04171     *Style |= (MapTranspTypeToGDraw(tType, TRUE)<<8);
04172     return TRUE;
04173 }
04174 
04175 
04176 
04177 
04178 
04179 
04180 
04181 
04182 
04183 
04184 
04185 
04186 
04187 
04188 BOOL GRenderRegion::SetBitmapTransparencyFill(TranspFillAttribute* Fill, DWORD* Style,
04189                                               TranspGradTable* pTranspTable)
04190 {
04191     if (Fill->GetBitmap()->ActualBitmap == NULL)
04192         return FALSE;                                   
04193 
04194     ENSURE( Fill->GetBitmap()->ActualBitmap->IsKindOf( CC_RUNTIME_CLASS( CWxBitmap ) ),
04195                                                                 "Strange bitmapfill");
04196 
04197     UINT32 bpp = Fill->GetBitmap()->GetBPP();
04198     CWxBitmap *WinBM = (CWxBitmap*)Fill->GetBitmap()->ActualBitmap;
04199 
04200 
04201 
04202 
04203 
04204 
04205 
04206 
04207 
04208 
04209 
04210 
04211 
04212 
04213 
04214 
04215 
04216 
04217 
04218 
04219 
04220 
04221     if (WinBM == NULL || WinBM->BMInfo == NULL  || WinBM->BMBytes == NULL)
04222         return FALSE;
04223 
04224     INT32 StartTransp = 0;
04225     INT32 EndTransp = 0;
04226     if (Fill->GetStartTransp() != NULL)
04227         StartTransp = *Fill->GetStartTransp();
04228     if (Fill->GetEndTransp() != NULL)
04229         EndTransp = *Fill->GetEndTransp();
04230 
04231 
04232 
04233 
04234 
04235 
04236 
04237 
04238 
04239 
04240 
04241 
04242 
04243 
04244 
04245 
04246 
04247 
04248     BYTE aRamp[0x100];
04249     BYTE* pRamp = NULL;
04250     if ( bpp<=8 && !Fill->IsKindOf(CC_RUNTIME_CLASS(FractalTranspFillAttribute)) &&
04251                    !Fill->IsKindOf(CC_RUNTIME_CLASS(  NoiseTranspFillAttribute)) )
04252     {
04253         RGBQUAD* pPalette = WinBM->BMInfo->bmiColors;
04254         if ( pPalette )
04255         {
04256             for (INT32 i=0; i<1<<bpp; i++)
04257                 aRamp[i] = (pPalette[i].rgbRed  *0x4D4D4D+
04258                             pPalette[i].rgbGreen*0x979797+
04259                             pPalette[i].rgbBlue *0x1C1C1C) >> 24;
04260             pRamp = aRamp;
04261         }
04262     }
04263 
04264     
04265     POINT PGram[4];
04266     PGram[0].x = (*Fill->GetStartPoint()).x; 
04267     PGram[0].y = (*Fill->GetStartPoint()).y;
04268     PGram[1].x = (*Fill->GetEndPoint  ()).x;
04269     PGram[1].y = (*Fill->GetEndPoint  ()).y;
04270 
04271     BOOL Perspective = Fill->IsPerspective();
04272     if ( Perspective )
04273     {
04274         
04275         PGram[2].x = (*Fill->GetEndPoint3()).x;
04276         PGram[2].y = (*Fill->GetEndPoint3()).y;
04277         PGram[3].x = (*Fill->GetEndPoint2()).x;
04278         PGram[3].y = (*Fill->GetEndPoint2()).y;
04279 
04280         if ( !MouldPerspective::WillBeValid(PGram) )
04281         {
04282             Perspective = FALSE;
04283             TRACEUSER( "Will", _T("Bitmap Perspective points are Invalid !!\n"));
04284         }
04285     }
04286     if ( !Perspective )
04287     {
04288         PGram[2].x = (*Fill->GetEndPoint2()).x;
04289         PGram[2].y = (*Fill->GetEndPoint2()).y;
04290     }       
04291 
04292     
04293     COLORREF DefaultColour;
04294 
04295 
04296     DefaultColour = 0xFFFFFFFF;
04297 
04298     UINT32 tType = Fill->GetTranspType();
04299     DWORD TranspStyle = tType<<8;
04300 
04301 
04302     INT32 Tiling = 
04303         ((TranspFillMappingAttribute*)CurrentAttrs[ATTR_TRANSPFILLMAPPING].pAttr)->Repeat;
04304     TranspStyle |= Tiling;
04305 
04306     
04307     *Style |= (MapTranspTypeToGDraw(tType, TRUE)<<8);
04308 
04309     
04310     if ( bpp==32 && Fill->GetBitmap()->IsTransparent() )
04311         TranspStyle |= 0x8000;
04312 
04313     GetDrawContext()->SetBias(3,Fill->GetProfile().GetBias()) ;
04314     GetDrawContext()->SetGain(3,Fill->GetProfile().GetGain()) ;
04315     GetDrawContext()->SetOutputRange(3,StartTransp,EndTransp) ;
04316 
04317     
04318     
04319     
04320 
04321     SetSmoothingFlags(Fill);
04322 
04323     if (Perspective)    
04324     {
04325         GetDrawContext()->SetPerspectiveTransparentBitmapFill(
04326                             &(WinBM->BMInfo->bmiHeader),
04327                             WinBM->BMBytes,
04328                             TranspStyle,
04329                             PGram,
04330                             DefaultColour,
04331                             pRamp,
04332                             0
04333                             );
04334     }
04335     else
04336     {
04337         GetDrawContext()->SetTransparentBitmapFill(
04338                             &(WinBM->BMInfo->bmiHeader),
04339                             WinBM->BMBytes,
04340                             TranspStyle,
04341                             PGram,
04342                             DefaultColour,
04343                             pRamp,
04344                             0
04345                             );
04346     }
04347 
04348     
04349     SetSmoothingFlags(NULL);
04350 
04351     return TRUE;
04352 }
04353 
04354 
04355 
04356 
04357 
04358 
04359 
04360 
04361 
04362 
04363 
04364 
04365 
04366 
04367 BOOL GRenderRegion::SetFractalFill(ColourFillAttribute* Fill, DWORD* Style)
04368 {
04369     return FALSE;
04370 }
04371 
04372 
04373 
04374 
04375 
04376 
04377 
04378 
04379 
04380 
04381 
04382 
04383 
04384 
04385 BOOL GRenderRegion::SetFractalTransparencyFill(TranspFillAttribute* Fill, DWORD* Style)
04386 {
04387 
04388 
04389 
04390 
04391 
04392 
04393 
04394 
04395 
04396 
04397 
04398 
04399 
04400 
04401 
04402 
04403 
04404 
04405 
04406 
04407 
04408 
04409 
04410 
04411 
04412 
04413 
04414 
04415 
04416 
04417 
04418 
04419 
04420 
04421 
04422 
04423 
04424 
04425 
04426 
04427 
04428 
04429 
04430 
04431 
04432 
04433 
04434 
04435 
04436 
04437 
04438 
04439 
04440 
04441 
04442 
04443 
04444 
04445 
04446 
04447 
04448 
04449 
04450 
04451 
04452 
04453 
04454 
04455 
04456 
04457 
04458 
04459 
04460 
04461 
04462 
04463 
04464 
04465 
04466 
04467 
04468 
04469 
04470 
04471 
04472 
04473 
04474 
04475 
04476 
04477 
04478 
04479 
04480 
04481 
04482 
04483 
04484 
04485 
04486 
04487 
04488 
04489 
04490 
04491 
04492 
04493 
04494 
04495 
04496 
04497 
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     return TRUE;
04528 }
04529 
04530 
04531 
04532 
04533 
04534 
04535 
04536 
04537 
04538 
04539 
04540 
04541 
04542 
04543 
04544 
04545 
04546 
04547 
04548 void GRenderRegion::DrawRect(DocRect *RectToRender)
04549 {
04550     
04551     if ((!RenderComplexShapes) && (TestForComplexShape(&Caps)))
04552         return;
04553 
04554     
04555     
04556     
04557     if (!RectToRender->IsIntersectedWith(CurrentClipRect))
04558         return;
04559 
04560     
04561     DocRect DocDrawRect = RectToRender->Intersection(InnerRect);
04562     RECT    DrawRect;
04563     DrawRect.left   = DocDrawRect.lo.x;
04564     DrawRect.right  = DocDrawRect.hi.x;
04565     DrawRect.top    = DocDrawRect.hi.y;
04566     DrawRect.bottom = DocDrawRect.lo.y;
04567 
04568     RememberMe("DrawRect");
04569     HaveRenderedSomething = TRUE;
04570 
04571     
04572     if (SetFillGCol(RR_FILLCOLOUR()))
04573         GetDrawContext()->FillRectangle(&DrawRect);
04574 
04575     
04576     if (SetGCol(RR_STROKECOLOUR()))
04577     {
04578         
04579         static BYTE  Verbs[4] = {PT_MOVETO, PT_LINETO, PT_LINETO, PT_LINETO | PT_CLOSEFIGURE};
04580         DocCoord Coords[4];
04581 
04582         
04583         Coords[0].x = DocDrawRect.lo.x;
04584         Coords[0].y = DocDrawRect.lo.y;
04585 
04586         Coords[1].x = DocDrawRect.lo.x;
04587         Coords[1].y = DocDrawRect.hi.y;
04588 
04589         Coords[2].x = DocDrawRect.hi.x;
04590         Coords[2].y = DocDrawRect.hi.y;
04591 
04592         Coords[3].x = DocDrawRect.hi.x;
04593         Coords[3].y = DocDrawRect.lo.y;
04594 
04595         
04596         StrokePath(Coords, Verbs, 4,
04597                    Coords, Verbs, 4, FALSE);
04598     }
04599 }
04600 
04601 
04602 
04603 
04604 
04605 
04606 
04607 
04608 
04609 
04610 
04611 
04612 
04613 
04614 
04615 
04616 void GRenderRegion::DrawDragRect(DocRect *)
04617 {
04618     ENSURE(FALSE, "Gdraw cannot do DrawDragRect");
04619 }
04620 
04621 
04622 
04623 
04624 
04625 
04626 
04627 
04628 
04629 
04630 
04631 
04632 
04633 
04634 
04635 
04636 void GRenderRegion::DrawBlob(DocCoord p, BlobType type)
04637 {
04638     
04639     
04640     
04641     if (this->IsKindOf (CC_RUNTIME_CLASS (GRenderClick)))
04642     {
04643         return;
04644     }
04645 
04646     ENSURE( FALSE, "GDraw cannot do blobs");
04647 
04648     DocRect MyBlob;
04649 
04650     OSRenderRegion::GetBlobRect( ScaleFactor, p, type, &MyBlob);
04651     DrawRect( &MyBlob );
04652 }
04653 
04654 
04655 
04656 
04657 
04658 
04659 
04660 
04661 
04662 
04663 
04664 
04665 
04666 
04667 
04668 
04669 void GRenderRegion::DrawLine(const DocCoord &StartPoint, const DocCoord &EndPoint)
04670 {
04671     
04672     if ((!RenderComplexShapes) && (TestForComplexShape(&Caps)))
04673         return;
04674 
04675     RememberMe("DrawLine");
04676     HaveRenderedSomething = TRUE;
04677 
04678     
04679     if (!SetGCol( RR_STROKECOLOUR() ))
04680         return;
04681 
04682     
04683     static PathVerb Verbs[2] = {PT_MOVETO, PT_LINETO};
04684     DocCoord Coords[2];
04685     DocCoord ClippedCoords[2];
04686     PathVerb ClippedVerbs[2];
04687 
04688     Coords[0] = StartPoint;
04689     Coords[1] = EndPoint;
04690 
04691     
04692     size_t Worked = FuzzyClip( (PPOINT)Coords, Verbs, 2, FALSE, (RECT*)(&InnerRect), (RECT*)(&OuterRect),
04693                             (PPOINT)(ClippedCoords), ClippedVerbs, 2);
04694 
04695     
04696     if (Worked==(size_t)-1)
04697     {
04698         StrokePath( Coords, Verbs, 2,
04699                     Coords, Verbs, 2, TRUE);
04700     }
04701     else
04702     {
04703         StrokePath( ClippedCoords, ClippedVerbs, (UINT32)Worked, 
04704                     Coords, Verbs, 2, TRUE);
04705     }
04706 }
04707 
04708 
04709 
04710 
04711 
04712 
04713 
04714 
04715 
04716 
04717 
04718 
04719 
04720 
04721 
04722 
04723 void GRenderRegion::DrawBitmap(const DocCoord &Point, KernelBitmap* pBitmap)
04724 {
04725     if (pBitmap == NULL)
04726         return;
04727 
04728     ENSURE( pBitmap->ActualBitmap->IsKindOf( CC_RUNTIME_CLASS( CWxBitmap ) ),
04729                                                                 "Strange bitmapfill");
04730     CWxBitmap *WinBM = (CWxBitmap*)pBitmap->ActualBitmap;
04731 
04732     
04733     if (
04734         (WinBM->BMInfo==NULL) ||
04735         (WinBM->BMBytes==NULL)
04736        )
04737         return;
04738 
04739     INT32 PixelSize = CalcPixelWidth();
04740 
04741     BitmapInfo Info;
04742     BOOL GotInfo = pBitmap->ActualBitmap->GetInfo( &Info );
04743 
04744     
04745     INT32 Width  = GotInfo ? Info.PixelWidth  * PixelSize : 16 * PixelSize;
04746     INT32 Height = GotInfo ? Info.PixelHeight * PixelSize : 16 * PixelSize;
04747         
04748     
04749     POINT PGram[3];
04750     PGram[0].x = Point.x;               PGram[0].y = Point.y;
04751     PGram[1].x = Point.x + Width;       PGram[1].y = Point.y;
04752     PGram[2].x = Point.x;               PGram[2].y = Point.y + Height;
04753 
04754 
04755     
04756     RGBQUAD *Palette = NULL;
04757 
04758     
04759     
04760     ColourCorrectBitmap(NULL, WinBM->BMInfo, &Palette);
04761 
04762     
04763     if (Palette == NULL)
04764         Palette = WinBM->BMInfo->bmiColors;
04765 
04766     DWORD Style = 1;        
04767     BOOL bClearBitmapConv = FALSE;
04768 
04769     
04770     
04771     
04772 
04773     if (WinBM->GetBPP() > 8)    
04774     {
04775         
04776         if (CurrentColContext->GetColourPlate() != NULL &&
04777             !CurrentColContext->GetColourPlate()->IsDisabled() &&
04778             CurrentColContext->GetColourPlate()->GetType() == COLOURPLATE_COMPOSITE)
04779         {
04780             
04781             
04782 PORTNOTE("cms", "DisabledXaraCMS")
04783 #ifndef EXCLUDE_FROM_XARALX
04784             XaraCMS* lpCMSMan = GetApplication()->GetCMSManager();
04785             if (lpCMSMan != NULL)
04786             {
04787                 DWORD *MatchTable = lpCMSMan->GetPaperViewTable();
04788                 ERROR3IF(MatchTable == NULL, "Can't create/find colour matching table");
04789                 if (MatchTable != NULL)
04790                 {
04791                     GetDrawContext()->SetBitmapConversionTable((BGR *)MatchTable);
04792                     bClearBitmapConv = TRUE;
04793                     
04794                     
04795                     Style |= (BitmapConversion & 3) << 27;
04796                 }
04797             }
04798 #endif
04799         }
04800     }
04801 
04802     BYTE *BitmapBits = WinBM->BMBytes;
04803 
04804     
04805     GetDrawContext()->PlotBitmap(   &(WinBM->BMInfo->bmiHeader),
04806                     BitmapBits,
04807                     Style,
04808                     PGram,
04809                     Palette,
04810                     NULL, NULL, NULL,
04811                     NoTransTable
04812                     );
04813 
04814     
04815     
04816     
04817     if (Palette != WinBM->BMInfo->bmiColors)
04818         CCFree(Palette);
04819 
04820     if (bClearBitmapConv)
04821     {
04822         GetDrawContext()->SetBitmapConversionTable(NULL);
04823     }
04824 }
04825 
04826 
04827 
04828 
04829 
04830 
04831 
04832 
04833 
04834 
04835 
04836 
04837 
04838 
04839 
04840 
04841 
04842 
04843 void GRenderRegion::DrawBitmap(const DocRect& rect, KernelBitmap* pBitmap)
04844 {
04845     if (pBitmap == NULL)
04846         return;
04847 
04848     ENSURE( pBitmap->ActualBitmap->IsKindOf( CC_RUNTIME_CLASS( CWxBitmap ) ),
04849                                                                 "Strange bitmapfill");
04850     CWxBitmap *WinBM = (CWxBitmap*)pBitmap->ActualBitmap;
04851 
04852     
04853     if (
04854         (WinBM->BMInfo==NULL) ||
04855         (WinBM->BMBytes==NULL)
04856        )
04857         return;
04858 
04859 
04860 
04861     
04862     POINT PGram[3];
04863     PGram[0].x = rect.lo.x; PGram[0].y = rect.lo.y;
04864     PGram[1].x = rect.hi.x; PGram[1].y = rect.lo.y;
04865     PGram[2].x = rect.lo.x; PGram[2].y = rect.hi.y;
04866 
04867 
04868     
04869     RGBQUAD *Palette = NULL;
04870 
04871     
04872     
04873     ColourCorrectBitmap(NULL, WinBM->BMInfo, &Palette);
04874 
04875     
04876     if (Palette == NULL)
04877         Palette = WinBM->BMInfo->bmiColors;
04878 
04879     DWORD Style = 1;        
04880     BOOL bClearBitmapConv = FALSE;
04881 
04882     
04883     
04884     
04885     if (WinBM->GetBPP() > 8)    
04886     {
04887         
04888         if (CurrentColContext->GetColourPlate() != NULL &&
04889             !CurrentColContext->GetColourPlate()->IsDisabled() &&
04890             CurrentColContext->GetColourPlate()->GetType() == COLOURPLATE_COMPOSITE)
04891         {
04892             
04893             
04894 PORTNOTE("cms", "DisabledXaraCMS")
04895 #ifndef EXCLUDE_FROM_XARALX
04896             XaraCMS* lpCMSMan = GetApplication()->GetCMSManager();
04897             if (lpCMSMan != NULL)
04898             {
04899                 DWORD *MatchTable = lpCMSMan->GetPaperViewTable();
04900                 ERROR3IF(MatchTable == NULL, "Can't create/find colour matching table");
04901                 if (MatchTable != NULL)
04902                 {
04903                     GetDrawContext()->SetBitmapConversionTable((BGR *)MatchTable);
04904                     bClearBitmapConv = TRUE;
04905                     
04906                     
04907                     Style |= (BitmapConversion & 3) << 27;
04908                 }
04909             }
04910 #endif
04911         }
04912     }
04913     BYTE *BitmapBits = WinBM->BMBytes;
04914 
04915     
04916     GetDrawContext()->PlotBitmap(   &(WinBM->BMInfo->bmiHeader),
04917                     BitmapBits,
04918                     Style,
04919                     PGram,
04920                     Palette,
04921                     NULL, NULL, NULL,
04922                     NoTransTable
04923                     );
04924 
04925     
04926     
04927     
04928     if (Palette != WinBM->BMInfo->bmiColors)
04929         CCFree(Palette);
04930 
04931     if (bClearBitmapConv)
04932     {
04933         GetDrawContext()->SetBitmapConversionTable(NULL);
04934     }
04935 }
04936 
04937 
04938 
04939 
04940 
04941 
04942 
04943 
04944 
04945 
04946 
04947 
04948 
04949 
04950 
04951 
04952 
04953 
04954 
04955 void GRenderRegion::DrawBitmap(const DocCoord &Point, UINT32 BitmapID, UINT32 ToolID)
04956 {
04957     ERROR3IF( 0 != ToolID, "GRenderRegion::DrawBitmap can't cope with Tool resources yet" );
04958 
04959     KernelBitmap* pBitmap;
04960 
04961     
04962     OILBitmap* pOilBmp = OILBitmap::Create();
04963     if (pOilBmp == NULL)
04964         return;
04965 
04966     
04967     pOilBmp->LoadBitmap(BitmapID);
04968 
04969     
04970     pBitmap = new KernelBitmap(pOilBmp, TRUE);      
04971     if (pBitmap == NULL)
04972         return;
04973 
04974     
04975     DrawBitmap(Point, pBitmap);
04976 
04977     
04978     delete pBitmap;
04979 }
04980 
04981 
04982 
04983 
04984 
04985 
04986 
04987 
04988 
04989 
04990 
04991 
04992 
04993 
04994 
04995 
04996 
04997 
04998 
04999 
05000 
05001 
05002 
05003 
05004 
05005 
05006 
05007 
05008 
05009 
05010 
05011 
05012 
05013 void GRenderRegion::DrawFixedSystemText(StringBase *TheText, DocRect &BoundsRect, UINT32 uFormat)
05014 {
05015     wxString Text = (wxString)(TCHAR *)(*TheText);
05016 
05017     wxFont SaveFont=RenderDC->GetFont();
05018 
05019     wxFont FixedFont = wxSystemSettings::GetFont(wxSYS_DEFAULT_GUI_FONT);
05020     FixedFont.SetPointSize(8);
05021     RenderDC->SetFont(FixedFont);
05022 
05023     wxDC * pDC = RenderDC;
05024     wxSize DPI = OSRenderRegion::GetFixedDCPPI(*pDC);
05025 
05026 
05027 
05028 
05029     wxCoord w, h;
05030     RenderDC->GetTextExtent(Text, &w, &h);
05031 
05032     RenderDC->SetFont(SaveFont);
05033 
05034     INT32 PixelWidth = CalcScaledPixelWidth();
05035     
05036     ERROR3IF(PixelWidth == 0, "GRenderRegion::DrawFixedSystemText PixelWidth = 0");
05037     if (PixelWidth == 0)
05038         PixelWidth = 1;
05039 
05040     
05041     wxBitmap bitmap(w, h);
05042     wxMemoryDC MemDC;
05043     MemDC.SelectObject(bitmap);
05044     MemDC.SetFont(FixedFont);
05045 
05046     MemDC.SetBackgroundMode(wxSOLID);
05047 
05048     
05049     MemDC.SetTextForeground(RenderDC->GetTextForeground());
05050     MemDC.SetTextBackground(RenderDC->GetTextBackground());
05051 
05052     
05053     MemDC.DrawText((TCHAR *) (*TheText), 0, 0);
05054 
05055     KernelBitmap* pBitmap;
05056 
05057     
05058     OILBitmap* pOilBmp = OILBitmap::Create();
05059     if (pOilBmp == NULL)
05060         return;
05061 
05062     
05063     ((CWxBitmap *)pOilBmp)->CreateFromwxBitmap(&bitmap);
05064 
05065     
05066     pBitmap = new KernelBitmap(pOilBmp, TRUE);      
05067     if (pBitmap == NULL)
05068         return;
05069 
05070     
05071     INT32 Height = h * PixelWidth;
05072 
05073     DocCoord BottomLeft;
05074     BottomLeft.x = BoundsRect.lo.x;
05075     BottomLeft.y = (BoundsRect.lo.y + BoundsRect.Height()/2) - Height/2;
05076 
05077     GetDrawContext()->SetDefaultBitmapParameters();
05078     
05079     DrawBitmap(BottomLeft, pBitmap);
05080 
05081     
05082     delete pBitmap;
05083 
05084 }
05085 
05086 
05087 
05088 
05089 
05090 
05091 
05092 
05093 
05094 
05095 
05096 
05097 
05098 
05099 
05100 
05101 
05102 
05103 
05104 
05105 
05106 
05107 
05108 
05109 
05110 
05111 
05112 
05113 
05114 
05115 
05116 
05117 
05118 
05119 
05120 
05121 
05122 
05123 
05124 void GRenderRegion::SetFixedSystemTextColours(DocColour *TextCol, DocColour *Background)
05125 {
05126     if (TextCol != NULL)
05127     {
05128         COLORREF clr = ConvertColourToScreenWord(CurrentColContext, TextCol);
05129         RenderDC->SetTextForeground(clr);
05130     }
05131 
05132     if (Background != NULL)
05133     {
05134         COLORREF clr = ConvertColourToScreenWord(CurrentColContext, Background);
05135         RenderDC->SetTextBackground(clr);
05136     }
05137 }
05138 
05139 
05140 
05141 
05142 
05143 
05144 
05145 
05146 
05147 
05148 
05149 
05150 
05151 
05152 
05153 
05154 
05155 
05156 
05157 
05158 
05159 
05160 
05161 
05162 
05163 
05164 
05165 
05166 void GRenderRegion::GetFixedSystemTextSize(StringBase *TheText, DocRect *BoundsRect, double* atDpi)
05167 {
05168     ERROR3IF(TheText == NULL, "GRenderRegion::GetFixedSystemTextSize given a null text pointer");
05169     ERROR3IF(BoundsRect == NULL, "GRenderRegion::GetFixedSystemTextSize given a null bounds rect pointer");
05170     if(TheText == NULL || BoundsRect == NULL)
05171         return;
05172 
05173 
05174     wxString Text = (wxString)(TCHAR *)(*TheText);
05175 
05176     wxFont SaveFont=RenderDC->GetFont();
05177 
05178     wxFont FixedFont = wxSystemSettings::GetFont(wxSYS_DEFAULT_GUI_FONT);
05179     FixedFont.SetPointSize(8);
05180     RenderDC->SetFont(FixedFont);
05181 
05182     wxDC * pDC = RenderDC;
05183     wxSize DPI = OSRenderRegion::GetFixedDCPPI(*pDC);
05184     INT32 XDPI = DPI.GetWidth();
05185     INT32 YDPI = DPI.GetHeight();
05186     INT32 LineHeight = RenderDC->GetCharHeight();
05187 
05188     wxCoord w, h;
05189     RenderDC->GetTextExtent(Text, &w, &h);
05190 
05191     RenderDC->SetFont(SaveFont);
05192 
05193     
05194     
05195 
05196     *BoundsRect = DocRect(0, 0,
05197                           (INT32)(((double)(w) * IN_MP_VAL) / XDPI),
05198                           (INT32)(((double)LineHeight * IN_MP_VAL) / YDPI) );
05199 
05200 }
05201 
05202 
05203 
05204 
05205 
05206 
05207 
05208 
05209 
05210 
05211 
05212 
05213 
05214 
05215 
05216 BOOL GRenderRegion::DrawArrowHead(ArrowRec &ArrowToDraw,
05217                                   DocCoord &Centre, DocCoord &Direction)
05218 {
05219     
05220     return RenderRegion::DrawArrowHead(ArrowToDraw, Centre, Direction);
05221 }
05222 
05223 
05224 
05225 
05226 
05227 
05228 
05229 
05230 
05231 
05232 
05233 
05234 
05235 
05236 GMATRIX GRenderRegion::SetGavinMatrix(GMATRIX* GMat)
05237 {
05238     
05239     GMATRIX OldMatrix = CurrentGMatrix;
05240 
05241     
05242     if (!StartRenderAfter( GMat ))
05243         return OldMatrix;
05244 
05245     
05246 
05247     
05248     
05249     
05250     CurrentGMatrix.AX = GMat->AX;
05251     CurrentGMatrix.AY = GMat->AY;
05252     CurrentGMatrix.BX = GMat->BX;
05253     CurrentGMatrix.BY = GMat->BY;
05254     CurrentGMatrix.CX = GMat->CX;
05255     CurrentGMatrix.CY = GMat->CY;
05256 
05257     
05258     GetDrawContext()->SetMatrix( GMat );
05259 
05260     return OldMatrix;
05261 }
05262 
05263 
05264 
05265 
05266 
05267 
05268 
05269 
05270 
05271 
05272 
05273 
05274 
05275 
05276 
05277 
05278 
05279 
05280 GMATRIX GRenderRegion::MakeGavinMatrix(Matrix NewRenderMatrix, DocRect ClipRect, double dPixelsPerInch, BOOL bMasterCapture)
05281 {
05282     GMATRIX gmat;
05283     
05284     FIXED16 abcd[4];
05285     INT32 ef[2];
05286     NewRenderMatrix.GetComponents( abcd, ef );
05287 
05288     
05289     
05290     Matrix UnscrolledRender(abcd[0], abcd[1], abcd[2], abcd[3], 0, 0);
05291 
05292     
05293     
05294     
05295     
05296     
05297 
05298     
05299     const XLONG Mult = (INT32)(dPixelsPerInch*(double)(1 << FX) + 0.5);
05300 
05301     gmat.AX = ( (XLONG)abcd[0].GetRawLong() * Mult ) / XLONG(72000);
05302     gmat.AY = ( (XLONG)abcd[1].GetRawLong() * Mult ) / XLONG(72000);
05303     gmat.BX = ( (XLONG)abcd[2].GetRawLong() * Mult ) / XLONG(72000);
05304     gmat.BY = ( (XLONG)abcd[3].GetRawLong() * Mult ) / XLONG(72000);
05305 
05306 #if 0 //_DEBUG
05307     
05308     
05309     if ( !Error::IsUserName("Gavin") )
05310         if (dPixelsPerInch == floor(dPixelsPerInch))
05311         {
05312             INT32 pixelmp = (INT32)(72000.0 / dPixelsPerInch);
05313             if ((double)(72000/pixelmp) == dPixelsPerInch)
05314             {
05315                 if ( (((INT64)(ef[0])) % pixelmp) || (((INT64)(ef[1])) % pixelmp) )
05316                 {
05317 
05318                     TRACE(_T("***********************************************"));
05319                     TRACE(_T("** Render matrix on unaligned pixel boundary **"));
05320                     TRACE(_T("***********************************************"));
05321                 }
05322             }
05323         }
05324 #endif
05325 
05326     
05327     
05328     WinRect UnscrolledClip = OSRenderRegion::DocRectToWin(UnscrolledRender, ClipRect, dPixelsPerInch);
05329 
05330     
05331     
05332     
05333     INT32 xdisp = +UnscrolledClip.GetLeft();
05334     INT32 ydisp = -UnscrolledClip.GetBottomEx();
05335 
05336     
05337     
05338     gmat.CX = -( (XLONG)xdisp * (XLONG)(1<<(FX+16)) );
05339     gmat.CY = -( (XLONG)ydisp * (XLONG)(1<<(FX+16)) );
05340 
05341 
05342 
05343 
05344     return gmat;
05345 }
05346 
05347 
05348 
05349 
05350 
05351 
05352 
05353 
05354 
05355 
05356 
05357 
05358 
05359 
05360 
05361 
05362 
05363 BOOL GRenderRegion::SetGCol( DocColour &Col ) const
05364 {
05365     if ( Col.IsTransparent() )
05366         return FALSE;
05367 
05368     COLORREF rgbt;
05369     rgbt = ConvertColourToScreenWord(CurrentColContext, &Col);
05370 
05371     
05372     
05373     if (uBitmapDepth==32)
05374     {
05375         
05376         
05377         if ((RRQuality.GetLineQuality() >  Quality::BlackLine) && 
05378             (RRQuality.GetQuality()     != Quality::QualityGuideLayer))
05379         {
05380             DWORD Transp = *RR_STROKETRANSP()->GetStartTransp();
05381 
05382             DWORD Style = RR_STROKETRANSP()->GetTranspType();
05383 
05384             if (!(Style == 1 && Transp == 0))
05385             {
05386                 if (RenderFlags.HitDetect)
05387                     Style = T_REFLECTIVE;
05388 
05389                 rgbt |= Transp<<24;
05390                 GetDrawContext()->SetTransparency( rgbt, (TransparencyEnum)Style );
05391                 return(TRUE);
05392             }
05393         }
05394     }
05395 
05396     if (UseSolidColours)
05397     {
05398         
05399         
05400         DWORD GavinHint = DIBUtil::GetGavinBlitFormat(ScreenDepth, uBitmapDepth, ScreenHinting);
05401         GetDrawContext()->SetSolidColour( rgbt, ScreenDepth, GavinHint);
05402     }
05403     else
05404         GetDrawContext()->SetColour( rgbt );
05405 
05406     return TRUE;
05407 }
05408 
05409 
05410 
05411 
05412 
05413 
05414 
05415 
05416 
05417 
05418 
05419 
05420 
05421 
05422 
05423 
05424 
05425 BOOL GRenderRegion::SetFillGCol( DocColour &Col ) const
05426 {
05427     if ( Col.IsTransparent() )
05428         return FALSE;
05429 
05430     COLORREF rgbt;
05431 
05432     
05433     if (RenderFlags.VeryMono)
05434         rgbt = RGB(0,0,0);
05435     else
05436         rgbt = ConvertColourToScreenWord(CurrentColContext, &Col);
05437 
05438     if (UseSolidColours)
05439     {
05440         
05441         
05442         DWORD GavinHint = DIBUtil::GetGavinBlitFormat(ScreenDepth, uBitmapDepth, ScreenHinting);
05443         GetDrawContext()->SetSolidColour( rgbt, ScreenDepth, GavinHint);
05444     }
05445     else
05446         GetDrawContext()->SetColour( rgbt );
05447 
05448     return TRUE;
05449 }
05450 
05451 
05452 
05453 
05454 
05455 
05456 
05457 
05458 
05459 
05460 
05461 
05462 
05463 void GRenderRegion::SetSolidColours(BOOL SetSolid)
05464 {
05465     UseSolidColours = SetSolid;
05466 }
05467 
05468 
05469 
05470 
05471 
05472 
05473 
05474 
05475 
05476 
05477 
05478 
05479 
05480 
05481 MILLIPOINT GRenderRegion::CalcPixelWidth()
05482 {
05483     return MILLIPOINT( MILLIPOINTS_PER_INCH / PixelsPerInch);
05484 }
05485 
05486 
05487 
05488 
05489 
05490 
05491 
05492 
05493 
05494 
05495 
05496 
05497 
05498 
05499 double GRenderRegion::CalcPixelWidthDouble()
05500 {
05501     return MILLIPOINTS_PER_INCH / PixelsPerInch;
05502 }
05503 
05504 
05505 
05506 
05507 
05508 
05509 
05510 
05511 
05512 
05513 
05514 
05515 
05516 
05517 MILLIPOINT GRenderRegion::CalcScaledPixelWidth()
05518 {
05519     MILLIPOINT spw = (MILLIPOINT)( MILLIPOINTS_PER_INCH/(PixelsPerInch*ScaleFactor.MakeDouble()) + 0.5 );
05520     ERROR3IF(spw==0, "CalcScaledPixelWidth attempting to set a 0 value");
05521     return spw;
05522 }
05523 
05524 
05525 
05526 
05527 
05528 
05529 
05530 
05531 
05532 
05533 
05534 
05535 
05536 
05537 
05538 
05539 double GRenderRegion::CalcScaledPixelWidthDouble()
05540 {
05541     double spw = MILLIPOINTS_PER_INCH/(PixelsPerInch*ScaleFactor.MakeDouble());
05542     ERROR3IF(spw==0, "CalcScaledPixelWidthDOuble attempting to set a 0 value");
05543     return spw;
05544 }
05545 
05546 
05547 
05548 
05549 
05550 
05551 
05552 
05553 
05554 
05555 
05556 
05557 
05558 
05559 
05560 
05561 
05562 
05563 
05564 
05565 
05566 
05567 
05568 
05569 
05570 
05571 double GRenderRegion::GetScaledPixelWidthDouble()
05572 {
05573     return dScaledPixelWidth;
05574 }
05575 
05576 
05577 
05578 void GRenderRegion::InitClipping()
05579 {
05580     RememberMe("InitClipping");
05581 
05582     GetDrawContext()->ClipRectangle( (LPRECT)&CurrentClipRect );
05583     IsPaperRendered = FALSE;
05584 }
05585 
05586 void GRenderRegion::InitAttributes()
05587 {
05588 }
05589 
05590 void GRenderRegion::SetLineAttributes()
05591 {
05592 }
05593 
05594 void GRenderRegion::SetFillAttributes()
05595 {
05596 }
05597 
05598 void GRenderRegion::SetOSDrawingMode()
05599 {
05600     ENSURE( DrawingMode != DM_EORPEN, "Gdraw cannot EOR");
05601 }
05602 
05603 
05604 
05605 
05606 
05607 
05608 
05609 
05610 
05611 
05612 
05613 
05614 
05615 void GRenderRegion::SetQualityLevel()
05616 {
05617     const BOOL Anti = (RRQuality.GetAntialiasQuality() < Quality::FullAntialias) ? FALSE : TRUE;
05618     GetDrawContext()->SetAntialiasFlag( Anti );
05619 
05620     if (Anti)
05621     {
05622         GetDrawContext()->SetAntialiasQualityFlag(HighQualityAA);
05623     }
05624 
05625     
05626     
05627     
05628     INT32 Flatness = (INT32)((MILLIPOINTS_PER_INCH / PixelsPerInch) / 2);
05629     Flatness = LongDivFixed16( Flatness, ScaleFactor );
05630     if (Anti)
05631         Flatness /= 5;
05632     GetDrawContext()->SetFlatness( Flatness );
05633 }
05634 
05635 
05636 void GRenderRegion::Restore(RenderRegion*)
05637 {
05638 }
05639 
05640 
05641 
05642 
05643 
05644 
05645 
05646 
05647 
05648 
05649 
05650 
05651 
05652 
05653 
05654 
05655 
05656 
05657 BOOL GRenderRegion::AttachDevice(View* ViewToAttach, wxDC *pDC, Spread *pSpread, bool fOwned )
05658 {
05659     RememberMe("AttachDevice");
05660 
05661     
05662     BOOL Result = RenderRegion::AttachDevice( ViewToAttach, pDC, pSpread, fOwned );
05663 
05664     
05665     if (RenderView==NULL)
05666         CurrentColContext = ColourContext::GetGlobalDefault(COLOURMODEL_RGBT);
05667 
05668     
05669     return Result;
05670 }
05671 
05672 
05673 
05674 
05675 
05676 
05677 
05678 
05679 
05680 
05681 
05682 
05683 
05684 
05685 
05686 
05687 BOOL GRenderRegion::InitDevice()
05688 {
05689     ENSURE(MasterCaptureIsCurrent() || GetCaptureDepth()==0, "InitDevice called when captures running");
05690     RememberMe("InitDevice");
05691 
05692     
05693     BOOL Worked = RenderRegion::InitDevice();
05694 
05695     if (!Worked)
05696         return FALSE;
05697 
05698     
05699     if ( LocalBitmap && WRect==wxRect(0,0,0,0) )
05700     {
05701 
05702         WRect = OSRenderRegion::DocRectToWin( RenderMatrix, CurrentClipRect, PixelsPerInch );
05703     }
05704 
05705     
05706     ERROR2IF(WRect.width==0 || WRect.height==0, FALSE, "GRenderRegion::InitDevice was passed a rectangle with zero size");
05707     if (WRect.width == 0 || WRect.height == 0)
05708         return FALSE;
05709     
05710     
05711     ERROR2IF(WRect.width<0  || WRect.height<0 , FALSE, "GRenderRegion::InitDevice was passed a rectangle with -ve size");
05712     if (WRect.width < 0 || WRect.height < 0)
05713         return FALSE;
05714 
05715     
05716     SetClean(FALSE, FALSE);
05717 
05718     return TRUE;
05719 }
05720 
05721 
05722 
05723 
05724 
05725 
05726 
05727 
05728 
05729 
05730 
05731 
05732 
05733 
05734 
05735 
05736 
05737 
05738 
05739 
05740 
05741 RenderRegion* GRenderRegion::Create(DocRect ClipRegion, Matrix ConvertMatrix, FIXED16 ViewScale,
05742                                     RenderType rType, View* pView, BOOL bForce32BPP)
05743 {
05744     if (CanDoGDraw && WantDoGDraw)
05745     {
05746         if (rType==RENDERTYPE_SCREEN)
05747         {
05748 PORTNOTE("other","We no longer handle less than 32bit per pixel")
05749             UINT32 BitmapDepthWanted = 32; 
05750             if (WantGDrawDepth)
05751                 BitmapDepthWanted = WantGDrawDepth;                 
05752 
05753             
05754             
05755             if (pView != NULL)
05756             {
05757                 
05758                 
05759                 if (pView->RenderQuality.GetLineQuality() != Quality::BlackLine)
05760                 {
05761                     BitmapDepthWanted = 32;
05762                 }
05763 
05764                 
05765                 if (BitmapDepthWanted < 16)
05766                 {
05767                     if ((ViewDither == 0) || (ViewDither == 1) || (ViewDither == 3))
05768                         BitmapDepthWanted = 32;
05769                 }
05770             }
05771 
05772             
05773             if (bForce32BPP)
05774                 BitmapDepthWanted = 32;
05775 
05776             
05777             if (BitmapDepthWanted == 24)
05778                 BitmapDepthWanted = 32;
05779 
05780             GRenderRegion * pRegion = NULL;
05781 
05782 
05783 
05784 
05785 
05786 
05787 
05788 
05789 
05790 
05791                 pRegion = new GRenderDIB(ClipRegion, ConvertMatrix, ViewScale, BitmapDepthWanted, LogPixelsX);
05792 
05793             if ((pView != NULL) && (pRegion != NULL))
05794             {
05795                 
05796                 pRegion->SetDitherStyle8Bit(ViewDither);
05797 
05798                 
05799                 
05800             if (pView->GetColourPlate() != NULL && !pView->GetColourPlate()->IsDisabled())
05801                 {
05802                     ColourPlateType PlateType = pView->GetColourPlate()->GetType();
05803                     if (PlateType != COLOURPLATE_NONE && PlateType != COLOURPLATE_COMPOSITE)
05804                     {
05805                         
05806                         
05807 PORTNOTE("cms", "DisabledXaraCMS")
05808 #ifndef EXCLUDE_FROM_XARALX
05809                         XaraCMS* ptheCMS=GetApplication()->GetCMSManager();
05810                         if (ptheCMS != NULL)
05811                         {
05812                             String_256 PrintProfile;
05813                             ptheCMS->GetPrinterProfile(&PrintProfile);
05814                             ColourContext *pContext = new ColourContextCMYK(pView, &PrintProfile);
05815                             if (pContext)
05816                                 pView->SetColourContext(COLOURMODEL_CMYK, pContext);
05817                         }
05818 #endif
05819                         
05820                         UINT32 PrintType = CCPrintDialog::IsPostscript() ? 2 : 1;
05821                         pRegion->SetSimulatePrinting(PrintType);
05822                     }
05823                 }
05824             }
05825 
05826             
05827             return(pRegion);
05828         }
05829         else if ((rType==RENDERTYPE_PRINTER) || (rType==RENDERTYPE_PRINTER_PS))
05830         {
05831             
05832             
05833             UINT32 BitmapDepth = 32;
05834 
05835             
05836             Document* pDoc = pView->GetDoc();
05837 
05838             
05839             PrintComponent *pPrint = 
05840                 (PrintComponent *) pDoc->GetDocComponent(CC_RUNTIME_CLASS(PrintComponent));
05841             ERROR2IF(pPrint == NULL, NULL, "Unable to find PrintComponent in document.");
05842 
05843             PrintControl *pPrintControl = pPrint->GetPrintControl();
05844             ERROR2IF(pPrintControl == NULL, NULL, 
05845                      "Unable to find PrintControl object in document component.");
05846 
05847             
05848             INT32 PrintDPI = pPrintControl->GetDotsPerInch();
05849 
05850             return new GRenderPrint(ClipRegion, ConvertMatrix, ViewScale, 
05851                                     BitmapDepth, PrintDPI);
05852         }
05853     }
05854 
05855     return NULL;
05856 }
05857 
05858 
05859 
05860 
05861 
05862 
05863 
05864 
05865 
05866 
05867 
05868 
05869 
05870 
05871 
05872 
05873 
05874 
05875 void GRenderRegion::DisplayLtoHBitmap()
05876 {
05877     DWORD *rgb = (DWORD *)pBitmapInfo->bmiColors ;
05878 
05879     
05880     
05881 
05882     switch ( uBitmapDepth )
05883     {
05884         case 1 :
05885             *rgb++ = 0x000000 ;
05886             *rgb++ = 0xffffff ;
05887             break ;
05888         case 4 :
05889             *rgb++ = 0x000000 ; *rgb++ = 0x800000 ; *rgb++ = 0x008000 ; *rgb++ = 0x808000 ;
05890             *rgb++ = 0x000080 ; *rgb++ = 0x800080 ; *rgb++ = 0x008080 ; *rgb++ = 0x808080 ;
05891             *rgb++ = 0xc0c0c0 ; *rgb++ = 0xff0000 ; *rgb++ = 0x00ff00 ; *rgb++ = 0xffff00 ;
05892             *rgb++ = 0x0000ff ; *rgb++ = 0xff00ff ; *rgb++ = 0x00ffff ; *rgb++ = 0xffffff ;
05893             break ;
05894         case 16 :
05895             *rgb++ = 0x7c00 ;
05896             *rgb++ = 0x03e0 ;
05897             *rgb++ = 0x001f ;
05898             break ;
05899         case 32 :
05900             *rgb++ = 0x00ff0000 ;
05901             *rgb++ = 0x0000ff00 ;
05902             *rgb++ = 0x000000ff ;
05903             break ;
05904     }
05905 
05906     PlotBitmap( DIB_RGB_COLORS );
05907 }
05908 
05909 
05910 
05911 
05912 
05913 
05914 
05915 
05916 
05917 
05918 
05919 
05920 
05921 
05922 
05923 
05924 
05925 
05926 
05927 
05928 
05929 
05930 
05931 
05932 
05933 
05934 
05935 
05936 
05937 
05938 
05939 
05940 
05941 
05942 
05943 
05944 
05945 
05946 
05947 
05948 
05949 
05950 
05951 
05952 
05953 
05954 
05955 
05956 
05957 
05958 
05959 
05960 
05961 
05962 
05963 
05964 
05965 
05966 
05967 
05968 
05969 
05970 
05971 
05972 
05973 
05974 
05975 
05976 
05977 
05978 
05979 
05980 
05981 
05982 
05983 
05984 
05985 
05986 
05987 
05988 
05989 
05990 
05991 
05992 
05993 
05994 
05995 
05996 
05997 
05998 
05999 
06000 
06001 
06002 
06003 
06004 
06005 
06006 
06007 
06008 
06009 
06010 
06011 
06012 
06013 
06014 
06015 
06016 
06017 
06018 
06019 
06020 
06021 
06022 
06023 
06024 
06025 
06026 
06027 
06028 
06029 
06030 
06031 
06032 
06033 
06034 
06035 
06036 
06037 
06038 
06039 
06040 
06041 
06042 
06043 
06044 
06045 
06046 
06047 
06048 
06049 
06050 
06051 
06052 
06053 
06054 
06055 
06056 
06057 
06058 
06059 
06060 
06061 
06062 
06063 
06064 
06065 
06066 
06067 
06068 
06069 
06070 
06071 
06072 
06073 
06074 
06075 
06076 
06077 
06078 
06079 
06080 
06081 
06082 
06083 
06084 
06085 
06086 
06087 
06088 
06089 
06090 
06091 
06092 
06093 
06094 
06095 
06096 
06097 
06098 
06099 
06100 
06101 
06102 
06103 
06104 
06105 
06106 
06107 
06108 
06109 
06110 
06111 
06112 
06113 
06114 
06115 
06116 
06117 
06118 
06119 
06120 
06121 
06122 
06123 
06124 
06125 
06126 
06127 
06128 
06129 
06130 
06131 
06132 
06133 
06134 
06135 
06136 
06137 
06138 
06139 
06140 
06141 
06142 
06143 
06144 
06145 UINT32 GRenderRegion::SetPaletteEntries( LPBITMAPINFO lpBmi, wxDC* pOutputDC )
06146 {
06147     PORTNOTETRACE("other","GRenderRegion::SetPaletteEntries - do nothing");
06148 #ifndef EXCLUDE_FROM_XARALX
06149 #if WIN32
06150 
06151 
06152 
06153 
06154 #endif
06155 
06156     LPBITMAPINFOHEADER BitmapHeader = &lpBmi->bmiHeader;
06157     const INT32 Depth  = BitmapHeader->biBitCount;
06158 
06159     if (Depth > 8 )
06160     {
06161     
06162     
06163     }
06164 
06165     RGBQUAD *rgb = lpBmi->bmiColors;
06166     const size_t Count = 1<<Depth;
06167 
06168     if (Fixed256Palette)
06169     {
06170         
06171         memcpy(rgb, Fixed256Palette, sizeof(RGBQUAD) * 256);
06172         return(DIB_RGB_COLORS);
06173     }
06174 
06175     
06176     
06177     if (Count == 256)
06178     {
06179         if (ViewDither == 2)
06180             memcpy(rgb, &(StandardPalette.palPalEntry[0]), sizeof(PALETTEENTRY) * 256 );
06181         else
06182             memcpy(rgb, &(ErrorDiffPalette.palPalEntry[0]), sizeof(PALETTEENTRY) * 256 );
06183     }
06184     else
06185     {
06186         HDC hDC = ::GetDC(NULL);
06187         if (hDC != NULL)
06188         {
06189             GetSystemPaletteEntries(hDC,0,Count,(LPPALETTEENTRY) rgb);
06190             ::ReleaseDC(NULL, hDC);
06191         }
06192     }
06193 
06194     
06195     size_t i;
06196     for ( i=0 ; i<Count ; i++ )
06197     {
06198         BYTE t = rgb->rgbRed;
06199         rgb->rgbRed = rgb->rgbBlue;
06200         rgb->rgbBlue = t;
06201         rgb ++;
06202     }
06203 #endif
06204     return(DIB_RGB_COLORS);
06205 }
06206 
06207 
06208 
06209 #define TEST16BIT   0
06210 
06211 #if TEST16BIT
06212 
06213 #define C16(r,g,b)  (WORD) ( ((r>>3)<<10) | ((g>>3)<<5) | (b>>3) )
06214 
06215 
06216 static WORD ColDebugTable[32] =
06217 {
06218     C16(255,0,0),           
06219     C16(255,0,0),           
06220     C16(0,255,0),           
06221     C16(0,255,0),           
06222     C16(0,0,255),           
06223     C16(0,0,255),           
06224 
06225     C16(128,0,0),           
06226     C16(0,128,0),           
06227     C16(0,0,128),           
06228 
06229 
06230     C16(128,255,0),
06231     C16(128,128,0),
06232 
06233     C16(128,0,255),
06234     C16(128,0,128),
06235 
06236 
06237     C16(255,128,0),
06238     C16(128,128,0),
06239 
06240     C16(0,128,255),
06241     C16(0,128,128),
06242 
06243 
06244     C16(255,0,128),
06245     C16(128,0,128),
06246 
06247     C16(0,255,128),
06248     C16(0,128,128)
06249 
06250 
06251 };
06252 #endif
06253 
06254 
06255 
06256 
06257 
06258 
06259 
06260 
06261 
06262 
06263 
06264 
06265 
06266 
06267 
06268 
06269 
06270 
06271 
06272 
06273 
06274 
06275 void GRenderRegion::PlotBitmap( wxDC* hDC, UINT32 ColourFlag,
06276         INT32 Left,INT32 Top, UINT32 Width,UINT32 Height, wxPalette* hPalette, INT32 SourceLeft,INT32 SourceTop )
06277 {
06278     pBits=StaticPlotBitmap(hDC, ColourFlag, pBitmapInfo, pBits, Left, Top, Width, Height, hPalette, SourceLeft, SourceTop);
06279 }
06280 
06281 LPBYTE GRenderRegion::StaticPlotBitmap( wxDC* hDC, UINT32 ColourFlag,
06282         LPBITMAPINFO lpBitmapInfo, LPBYTE lpBits,
06283         INT32 Left,INT32 Top, UINT32 Width,UINT32 Height, wxPalette* hPalette, INT32 SourceLeft,INT32 SourceTop )
06284 {
06285     if( Width==0 || Height==0 )
06286         return lpBits;
06287 
06288     
06289     ERROR3IF((lpBitmapInfo->bmiHeader.biSize==0x00000000) 
06290 
06291 ,"Illegal BitmapInfo structure passed to PlotBitmap");
06292             
06293 
06294 
06295 
06296     CamProfile cp(CAMPROFILE_BLIT);
06297 
06298 #if !USE_wxBITMAP
06299 
06300     ERROR3IF(lpBitmapInfo->bmiHeader.biBitCount!=32,"Image must (currently) be 32bpp");
06301 
06302     wxBitmap Bitmap(Width,Height,32);
06303     wxAlphaPixelData BitmapData(Bitmap);
06304     
06305     
06306     
06307     DWORD* pSBuffer = 
06308             (DWORD*)lpBits + 
06309             lpBitmapInfo->bmiHeader.biWidth*(lpBitmapInfo->bmiHeader.biHeight-1-SourceTop) +
06310             SourceLeft;
06311     DWORD* pDBuffer = (DWORD*)Bitmap.GetRawData(BitmapData,32);
06312     DWORD* pDLine = pDBuffer;
06313     INT32 nStep = Width;
06314     if ( BitmapData.GetRowStride()<0 )
06315         nStep = -nStep;
06316     for( UINT32 y=0 ; y<Height ; ++y )
06317     {
06318         
06319         
06320         
06321         
06322         
06323 #if defined(__WXGTK__)
06324         for( UINT32 x=0; x<Width; ++x )
06325         {
06326             BYTE* pS = pBYTE(pSBuffer+x);
06327             BYTE* pD = pBYTE(pDLine  +x);
06328             pD[0] = pS[2];
06329             pD[1] = pS[1];
06330             pD[2] = pS[0];
06331             pD[3] = 0xFF;
06332         }
06333 #else
06334         for( UINT32 x=0; x<Width; ++x )
06335             pDLine[x] = pSBuffer[x];
06336 #endif
06337         pSBuffer -= lpBitmapInfo->bmiHeader.biWidth;
06338         pDLine += nStep;
06339     }
06340     if ( ScreenHinting==CONVHINT_FINAL16  ||
06341          ScreenHinting==CONVHINT_FINAL555 ||
06342          ScreenHinting==CONVHINT_FINAL565 ||
06343          ScreenHinting==CONVHINT_FINAL655 ||
06344          ScreenHinting==CONVHINT_FINAL664 )
06345     {
06346         BITMAPINFOHEADER Info = { sizeof(BITMAPINFOHEADER),Width,Height,1,32 } ;
06347         if ( nStep<0 )
06348             pDBuffer += (Height-1)*nStep;
06349         UINT32 uHint;
06350         switch (ScreenHinting)
06351         {
06352         case CONVHINT_FINAL565: uHint = 8+0; break;
06353         case CONVHINT_FINAL655: uHint = 8+1; break;
06354         case CONVHINT_FINAL664: uHint = 8+3; break;
06355         default:                uHint = 8+2; break;
06356         }
06357         GRenderRegion::GetStaticDrawContext()->ConvertBitmap(&Info,(BYTE*)pDBuffer,&Info,(BYTE*)pDBuffer,uHint);
06358     }
06359     Bitmap.UngetRawData(BitmapData) ;
06360 
06361 #ifdef _DEBUG
06362     
06363     if ((hDC->LogicalToDeviceX(wxCoord(72000)))!=wxCoord(72000))
06364     {
06365         ERROR3("X coordinate out");
06366     }
06367     if ((hDC->LogicalToDeviceY(wxCoord(72000)))!=wxCoord(72000))
06368     {
06369         ERROR3("Y coordinate out");
06370     }
06371 #endif
06372 
06373     {
06374 
06375         hDC->DrawBitmap(Bitmap,Left,Top) ;
06376     }
06377 
06378 #else
06379 
06380 #if defined(__WXGTK__)
06381     RGBT* pBuffer = (RGBT*)lpBits + pBitmapData->m_width*SourceTop + SourceLeft;
06382     for( UINT32 y=0 ; y<Height ; ++y )
06383     {
06384         
06385         
06386         
06387         
06388         
06389         for( UINT32 x=0; x<Width; ++x )
06390             pBuffer[x].Transparency = 0xFF;
06391         pBuffer += pBitmapData->m_width;
06392     }
06393 #endif
06394 
06395     BITMAPINFOHEADER Info = { sizeof(BITMAPINFOHEADER),Width,Height,1,32 } ;
06396 
06397     bool bIs16Bit = false ;
06398     UINT32 uHint = 8+2;
06399     if ( ScreenHinting==CONVHINT_FINAL16  ||
06400          ScreenHinting==CONVHINT_FINAL555 ||
06401          ScreenHinting==CONVHINT_FINAL565 ||
06402          ScreenHinting==CONVHINT_FINAL655 ||
06403          ScreenHinting==CONVHINT_FINAL664 )
06404     {
06405         switch (ScreenHinting)
06406         {
06407         case CONVHINT_FINAL565: uHint = 8+0; break;
06408         case CONVHINT_FINAL655: uHint = 8+1; break;
06409         case CONVHINT_FINAL664: uHint = 8+3; break;
06410         default:                             break;
06411         }
06412         bIs16Bit = true ;
06413     }
06414     if ( SourceLeft || SourceTop || Width!=pBitmap->GetWidth() || Height!=pBitmap->GetHeight() )
06415     {
06416         pBitmap->UngetRawData(*pBitmapData) ;
06417         wxBitmap bmp = pBitmap->GetSubBitmap( wxRect(SourceLeft,SourceTop,Width,Height) ) ;
06418         if ( bIs16Bit )
06419         {
06420             wxAlphaPixelData bmpData(bmp);
06421             BYTE* pData = (BYTE*)bmp.GetRawData(bmpData,32);
06422             if ( bmpData.GetRowStride()<0 )
06423                 pData += bmpData.GetRowStride()*(Height-1);
06424             GRenderRegion::GetStaticDrawContext()->ConvertBitmap(&Info,pData,&Info,pData,uHint);
06425             bmp.UngetRawData(bmpData) ;
06426         }
06427         {
06428 
06429             hDC->DrawBitmap(bmp,Left,Top);
06430         }
06431         TRACE( _T("DrawBitmap(%08x,%04x,%04x),%04x,%04x\n"),hDC,Left,Top,Width,Height);
06432     }
06433     else
06434     {
06435         if ( bIs16Bit )
06436             GRenderRegion::GetStaticDrawContext()->ConvertBitmap(&Info,lpBits,&Info,lpBits,uHint);
06437         pBitmap->UngetRawData(*pBitmapData) ;
06438         {
06439 
06440             hDC->DrawBitmap(*pBitmap,Left,Top) ;
06441         }
06442         TRACE( _T("DrawBitmap(%08x,%04x,%04x)\n"),hDC,Left,Top);
06443     }
06444 
06445     lpBits = (BYTE*)pBitmap->GetRawData(*pBitmapData,uBitmapDepth);
06446 #endif
06447     return lpBits;
06448 }
06449 
06450 
06451 
06452 
06453 
06454 
06455 
06456 
06457 
06458 
06459 
06460 
06461 
06462 
06463 
06464 
06465 
06466 
06467 void GRenderRegion::PlotBitmap( UINT32 ColourFlag )
06468 {
06469     RememberMe("PlotBitmap");
06470 
06471     #if REMEMBER_GDRAW==2
06472     TRACE( _T("Rect=(%d,%d,%d,%d) BM=%dx%d\n"),WRect.left,WRect.top,WRect.right,WRect.bottom,
06473                 lpBitmapInfo->bmiHeader.biWidth,
06474                 lpBitmapInfo->bmiHeader.biHeight
06475         );
06476     #endif
06477 
06478     #if FILL_BITMAP
06479     if (IsUserName("Andy") && (BitmapDepth==8) )
06480     {
06481         LPBYTE p = lpBits;
06482         
06483         const BYTE value = *p;
06484         INT32 i = (INT32)lpBitmapInfo->bmiHeader.biWidth;               
06485         while (i--)
06486         {
06487             if (*p != value)
06488                 break;
06489             p++;
06490         }
06491         if (i<0)
06492         {
06493             if (value==FILL_BITMAP)
06494             {
06495                 TRACE( _T("Got FILL_BITMAPed bitmap\n"));
06496                 RememberDump();
06497             }
06498             else if (value==FILL_BITMAP+1)
06499             {
06500                 TRACE( _T("Got FILL_BITMAPed bitmap+1 bitmap\n"));
06501                 RememberDump();
06502             }
06503         }
06504     }
06505     #endif
06506 
06507     #if 0
06508     {
06509         
06510         static INT32 BrushNum = 2;
06511         CBrush Brush;
06512 
06513         
06514         Brush.CreateHatchBrush( BrushNum, PALETTEINDEX( rand() & 0xFF ) );
06515 
06516         if (++BrushNum > 5)
06517             BrushNum = 2;
06518 
06519         RenderDC->FillRect( &WRect, &Brush );
06520     }
06521     #endif
06522 
06523     
06524     INT32 DestX = WRect.x;
06525     INT32 DestY = WRect.y;
06526     INT32 Width = WRect.width;
06527     INT32 Height= WRect.height;
06528 
06529     INT32 SourceX = ScreenRect.x;
06530     INT32 SourceY = ScreenRect.y;
06531 
06532     RECT UsedRect;
06533     if (GetDrawContext()->GetChangedBBox( &UsedRect ))
06534     {
06535 
06536         
06537         if ((UsedRect.right < UsedRect.left) ||
06538             (UsedRect.bottom< UsedRect.top ))
06539         {
06540             
06541             TRACE(_T("Bad ChangedBBox\n"));
06542             return;
06543         }
06544         else
06545         {
06546             
06547 
06548             
06549             
06550             
06551 
06552             const INT32 ChangeX = UsedRect.left;
06553             SourceX += ChangeX;
06554             DestX += ChangeX;
06555 
06556             INT32 ChangeY = Height - UsedRect.bottom;
06557             SourceY += ChangeY;
06558             DestY += ChangeY;
06559 
06560             Width  = UsedRect.right  - UsedRect.left;
06561             Height = UsedRect.bottom - UsedRect.top;
06562 
06563 
06564 
06565 
06566             
06567 
06568 
06569 
06570 
06571 
06572         }
06573     }
06574 
06575 
06576     
06577 
06578 
06579 
06580     PlotBitmap( RenderDC, ColourFlag, DestX,DestY, Width,Height, hPalette, SourceX,SourceY );
06581 }
06582 
06583 
06584 
06585 
06586 
06587 
06588 
06589 
06590 
06591 
06592 
06593 
06594 
06595 
06596 void GRenderRegion::Display1to1Bitmap()
06597 {
06598     UINT32 ColourFlag = DIB_RGB_COLORS ;
06599 
06600     DWORD *rgb = (DWORD *)pBitmapInfo->bmiColors ;
06601 
06602     switch (uBitmapDepth)
06603     {
06604         case 16:
06605             *rgb++ = 0x7c00 ;
06606             *rgb++ = 0x03e0 ;
06607             *rgb++ = 0x001f ;
06608             break;
06609     
06610         case 32:
06611             *rgb++ = 0x00ff0000 ;
06612             *rgb++ = 0x0000ff00 ;
06613             *rgb++ = 0x000000ff ;
06614             break;
06615 
06616         default:
06617             ColourFlag = SetPaletteEntries( pBitmapInfo, RenderDC );
06618             break;
06619     }
06620 
06621     PlotBitmap( ColourFlag );
06622 }
06623 
06624 
06625 
06626 
06627 
06628 
06629 
06630 
06631 
06632 
06633 
06634 
06635 
06636 
06637 
06638 
06639 const LOGPALETTE* GRenderRegion::GetRecommendedPalette()
06640 {
06641     
06642     
06643 
06644     const LOGPALETTE* lpPal = NULL;
06645 
06646 
06647     if (pRealGD == NULL)
06648         pRealGD = new GDrawAsm;
06649 
06650     if (pRealGD->Init())
06651     {
06652         
06653         
06654 
06655         
06656         
06657         PORTNOTETRACE("other","GRenderRegion::GetRecommendedPalette - removed palette code");
06658 #ifndef EXCLUDE_FROM_XARALX
06659         const INT32 ScreenDepth = ::wxDisplayDepth();
06660         lpPal = pRealGD->SelectPalette(0);
06661 
06662         
06663         if ((ScreenDepth!=8) ||
06664             !(GetDeviceCaps( hdc, RASTERCAPS ) & RC_PALETTE ) ||
06665             WantNoPalette)
06666 #endif
06667         {
06668             lpPal = NULL;
06669         }
06670     }
06671 
06672     GD = pRealGD;
06673 
06674     return(lpPal);
06675 }
06676 
06677 
06678 
06679 void GRenderRegion::DrawPixel(const DocCoord &Point)
06680 {
06681     
06682     if ((!RenderComplexShapes) && (TestForComplexShape(&Caps)))
06683         return;
06684 
06685     RememberMe("DrawPixel");
06686 
06687     if (!SetGCol(RR_STROKECOLOUR()))                
06688         return;
06689 
06690     POINT PlotMe;
06691     PlotMe.x = Point.x-(ScaledPixelWidth/2);        
06692     PlotMe.y = Point.y-(ScaledPixelWidth/2);        
06693     GetDrawContext()->FillPoint( &PlotMe );
06694 
06695     HaveRenderedSomething = TRUE;
06696 }
06697 
06698 
06699 
06700 
06701 
06702 
06703 
06704 
06705 
06706 
06707 
06708 
06709 
06710 
06711 
06712 void GRenderRegion::DrawCross(const DocCoord &Point, const UINT32 Size)
06713 {
06714     
06715     if ((!RenderComplexShapes) && (TestForComplexShape(&Caps)))
06716         return;
06717 
06718     RememberMe("DrawCross");
06719 
06720     if (!SetGCol(RR_STROKECOLOUR()))
06721         return;
06722 
06723     HaveRenderedSomething = TRUE;
06724 
06725     const INT32 Length = Size * ScaledPixelWidth;
06726 
06727     static PathVerb Verbs[] =
06728     {
06729         PT_MOVETO, PT_LINETO,
06730         PT_MOVETO, PT_LINETO
06731     };
06732     DocCoord Coords[4];
06733 
06734     DocCoord NewPoint = Point;
06735 
06736     Coords[0].x = NewPoint.x - Length;
06737     Coords[0].y = NewPoint.y;
06738     Coords[1].x = NewPoint.x + Length;
06739     Coords[1].y = NewPoint.y;
06740 
06741     Coords[2].x = NewPoint.x;
06742     Coords[2].y = NewPoint.y - Length;
06743     Coords[3].x = NewPoint.x;
06744     Coords[3].y = NewPoint.y + Length;
06745 
06746     GetDrawContext()->StrokePath( (POINT*)Coords, Verbs, sizeof(Verbs), FALSE,
06747                                             0, CAPS_BUTT, JOIN_MITER, NULL );
06748 }
06749 
06750 
06751 
06752 
06753 
06754 
06755 
06756 
06757 
06758 
06759 
06760 
06761 
06762 
06763 
06764 
06765 BOOL GRenderRegion::StrokePathAvailable()
06766 {
06767     return CanDoGDraw;
06768 
06769 }
06770 
06771 
06772 
06773 
06774 
06775 
06776 
06777 
06778 
06779 
06780 
06781 
06782 
06783 
06784 
06785 
06786 
06787 
06788 
06789 
06790 
06791 
06792 
06793 
06794 
06795 
06796 
06797 
06798 
06799 
06800 INT32 GRenderRegion::StrokePathToPath(
06801         CONST DocCoord *IPoints,
06802         CONST BYTE FAR *ITypes,
06803         size_t ILength,
06804         DocCoord *OPoints,
06805         BYTE  *OTypes,
06806         DWORD OLength,
06807         BOOL Close,
06808         DWORD LineWidth,
06809         DWORD Flattening,
06810         LineCapType LineCaps,
06811         JointType LineJoin,
06812         CONST DashType *Dash)
06813 {
06814     if (!CanDoGDraw)
06815         return -1;
06816 
06817     CapStyles CapS = (LineCaps==LineCapButt) ? CAPS_BUTT : (LineCaps==LineCapRound) ? CAPS_ROUND : CAPS_SQUARE;
06818     JoinStyles JoinS = (LineJoin==MitreJoin) ? JOIN_MITER : (LineJoin==RoundJoin) ? JOIN_ROUND : JOIN_BEVEL;
06819 
06820     DASH GDash = { 0, 0, { 0 } };
06821 
06822     if(Dash)
06823         memcpy(&GDash,Dash,sizeof(GDash));
06824 
06825     PPOINT SPoints = NULL;
06826     PBYTE STypes = NULL;
06827 
06828 
06829     GenStroke GStroke;
06830     INT32 Result = GStroke.StrokePathToPath((LPPOINT)IPoints, ITypes, (UINT32)ILength,
06831                                             &SPoints, &STypes,
06832                                             Close, LineWidth, (UINT32)(10<<16), Flattening,
06833                                             CapS, JoinS, &GDash);
06834 
06835     if (Result < 0)
06836         TRACE( _T("GDraw_StrokePtoP error=%lx\n"), 0 );
06837 
06838     
06839     if(Result > (INT32)OLength)
06840         return (INT32)OLength - Result;
06841 
06842     for (INT32 i = 0; i < Result; i++)
06843     {
06844         OPoints[i].x = SPoints[i].x;
06845         OPoints[i].y = SPoints[i].y;
06846         OTypes[i] = STypes[i];
06847     }
06848 
06849     delete SPoints;
06850     delete STypes;
06851 
06852     return Result;
06853 }
06854 
06855 
06856 
06857 
06858 
06859 
06860 
06861 
06862 
06863 
06864 
06865 
06866 
06867 
06868 
06869 
06870 
06871 
06872 
06873 
06874 
06875 
06876 
06877 
06878 
06879 
06880 
06881 
06882 
06883 void GRenderRegion::GColInit( wxDC* hdc, BOOL Force )
06884 {
06885     PORTNOTETRACE("other","GRenderRegion::GColInit - do nothing");
06886 #ifndef EXCLUDE_FROM_XARALX
06887     static PALETTEENTRY OldPal[260];
06888 
06889     
06890 
06891 
06892 
06893     if (hdc != NULL)
06894     {
06895         
06896         if (!(::GetDeviceCaps(hdc, RASTERCAPS) & RC_PALETTE))
06897             return;
06898         
06899         
06900         
06901         PALETTEENTRY NewPal[260];
06902 
06903         if (GetSystemPaletteEntries(hdc, 0, 256, NewPal) == 0)
06904         {
06905             TRACE( _T("GColInit() : GetSystemPaletteEntries failed %d\n"), GetLastError());
06906             return;
06907         }
06908 
06909         for (DWORD Index = 0; Index < 256; Index++)
06910             NewPal[Index].peFlags = 0;
06911 
06912         if (memcmp(NewPal, OldPal, sizeof(PALETTEENTRY) * 256) != 0)
06913         {
06914 
06915 
06916             
06917             
06918             memcpy(OldPal, NewPal, sizeof(PALETTEENTRY) * 256);
06919 
06920             
06921             PaletteManager::RedrawAllPalettedWindows();
06922         }
06923     }
06924     else
06925     {
06926 
06927         
06928         
06929         
06930         memset(OldPal, 0, sizeof(PALETTEENTRY) * 256);
06931     }
06932 #endif
06933 }
06934 
06935 
06936 
06937 
06938 
06939 
06940 
06941 
06942 
06943 
06944 
06945 
06946 
06947 
06948 
06949 
06950 void GRenderRegion::EnsurePalette(INT32 PaletteFlag)
06951 {
06952     if (PaletteFlag == -1)
06953     {
06954         PaletteFlag = 0;
06955         if ((WhichDither == 0) || (WhichDither == 3))
06956             PaletteFlag = 1;
06957     }
06958 
06959     const LOGPALETTE* pPalette = GetStaticDrawContext()->SelectPalette(PaletteFlag);
06960     if (pPalette != NULL)
06961         GetStaticDrawContext()->InitialiseWithPalette(pPalette);
06962 }
06963 
06964 
06965 
06966 
06967 
06968 
06969 
06970 
06971 
06972 
06973 
06974 
06975 
06976 
06977 
06978 
06979 void GRenderRegion::UpdateErrorDiffPalette(void)
06980 {
06981     if (ErrorDiffContext != NULL)
06982     {
06983         const LOGPALETTE* pPal = ErrorDiffContext->SelectPalette(1);
06984 
06985         if (pPal != NULL)
06986         {
06987             
06988             INT32 Length = 2 * sizeof(WORD) + (pPal->palNumEntries * sizeof(PALETTEENTRY));
06989 
06990             
06991             memcpy(&ErrorDiffPalette, pPal, Length);
06992 
06993             
06994             INT32* pEntry = (INT32*) &(ErrorDiffPalette.palPalEntry[0]);
06995             pEntry[8] = 0;
06996             pEntry[9] = 0;
06997             pEntry[246] = 0;
06998             pEntry[247] = 0;
06999 
07000             memcpy(&StandardPalette, &ErrorDiffPalette, Length);
07001 
07002 #ifdef RALPH
07003             
07004             for(INT32 i=10; i<=15; i++)
07005                 pEntry[i] = 0;
07006             for(i=24; i<=31; i++)
07007                 pEntry[i] = 0;
07008             for(i=224; i<=231; i++)
07009                 pEntry[i] = 0;
07010             for(i=240; i<=245; i++)
07011                 pEntry[i] = 0;          
07012 
07013 
07014 
07015 #if FALSE
07016             
07017             ErrorDiffContext->InitialiseWithPalette(GetErrorDiffPalette());
07018 #endif
07019             
07020             ((GDrawAsm*)ErrorDiffContext)->InitContext((GCONTEXT*)ErrorDiffContextData, 1);
07021 
07022 #else // ifdef RALPH
07023             
07024             ErrorDiffContext->InitialiseWithPalette(GetErrorDiffPalette());
07025 #endif
07026 
07027             
07028             ErrorDiffContext->SetStackSize(102400);
07029         }
07030     }
07031 }
07032 
07033 
07034 
07035 
07036 
07037 
07038 
07039 
07040 
07041 
07042 
07043 
07044 
07045 
07046 
07047 
07048 
07049  
07050 
07051 DWORD GRenderRegion::GetMaxBitmapWidth(void)
07052 {
07053     return XaDraw_GetMaxBitmapWidth();
07054 }
07055 
07056 
07057     
07058 
07059 
07060 
07061 
07062 
07063 
07064 
07065 
07066 
07067 
07068 
07069 
07070 
07071 
07072  
07073 
07074 DWORD GRenderRegion::GetMaxBitmapDepth(void)
07075 {
07076     return XaDraw_GetMaxBitmapDepth();
07077 }
07078 
07079 
07080 
07081 
07082 
07083 
07084 
07085 
07086 
07087 
07088 
07089 
07090 
07091 
07092 
07093 
07094 
07095 
07096 
07097 
07098 
07099 const REGION* GRenderRegion::MakeClipRegionFromClipAttr(ClipRegionAttribute* pClipAttr)
07100 {
07101     
07102     
07103     Path* pClipPath = pClipAttr->GetClipPath();
07104     if (pClipPath == NULL || pClipPath->GetNumCoords() < 2)
07105         return NULL;
07106 
07107 
07108 #ifdef _DEBUG
07109     if (!pClipPath->CheckPathValid())
07110         return NULL;
07111 #endif
07112 
07113     
07114     DWORD       Winding   = (RR_WINDINGRULE() == EvenOddWinding) ? 0 : 1;
07115     UINT32      NumCoords = pClipPath->GetNumCoords();
07116     DocCoord*   Coords    = pClipPath->GetCoordArray();
07117     PathVerb*   Verbs     = pClipPath->GetVerbArray();
07118 
07119     
07120 
07121     
07122     
07123     
07124     
07125     
07126     
07127     
07128     
07129     
07130     
07131     
07132     
07133     
07134     BYTE* pNewRegion        = NULL;
07135     UINT32  NumScans        = 500;      
07136     UINT32  nRegionLen      = NumScans * (RRQuality.GetAntialiasQuality() == Quality::FullAntialias ? 48 : 16);
07137     size_t  nMaxRegionLen   = 0x100000; 
07138     BOOL    bMadeRegion     = FALSE;
07139     for (INT32 attempts = 0; (nRegionLen < nMaxRegionLen) && !bMadeRegion; attempts ++)
07140     {
07141         
07142         pNewRegion = new BYTE[nRegionLen];
07143         if (pNewRegion == NULL)
07144         {
07145             
07146 #ifdef _DEBUG
07147             ERROR3( "Application has ran out of memory" );
07148 #endif
07149             return NULL;
07150         }
07151         memset(pNewRegion, 0, nRegionLen);
07152 
07153         
07154         
07155         if ( GetDrawContext()->MakeRegion(  (POINT*)Coords, Verbs, NumCoords,
07156                                             Winding, (REGION*)pNewRegion, nRegionLen) == -1 )
07157         {
07158             delete [] pNewRegion;
07159             pNewRegion  = NULL;
07160             nRegionLen *= 2;
07161         }
07162 
07163         
07164         else
07165         {
07166             bMadeRegion = TRUE;
07167         }
07168     }
07169 
07170     if (pNewRegion != NULL)
07171     {
07172         RECT r = ((REGION*)pNewRegion)->Rect;
07173         if (r.left  == 0 &&
07174             r.right == 0 &&
07175             r.bottom== 0 &&
07176             r.top   == 0)
07177         {
07178             if (RRQuality.GetAntialiasQuality() == Quality::FullAntialias)
07179                 ((REGION*)pNewRegion)->Type = 1;
07180             else
07181                 ((REGION*)pNewRegion)->Type = 0;
07182         }
07183     }
07184 
07185     return (REGION*)pNewRegion;
07186 }
07187 
07188 
07189 
07190 
07191 
07192 
07193 
07194 
07195 
07196 
07197 
07198 
07199 
07200 
07201 
07202 void GRenderRegion::SetDeepDIB(BOOL Value)
07203 {
07204 
07205 
07206 
07207 
07208 }
07209 
07210 
07211 
07212 
07213 
07214 
07215 
07216 
07217 
07218 
07219 
07220 
07221 
07222 
07223 
07224 
07225 void GRenderRegion::FreeStoredClipRegions()
07226 {
07227     
07228 
07229 
07230 
07231 
07232 
07233 
07234 
07235 
07236 
07237 
07238 
07239     ListT<Capture*>* pList = m_CaptureStack.GetListT();
07240     {
07241         Capture* pCapture = NULL;
07242         ListT<Capture*>::Iterator it = pList->End();
07243         INT32 nListSize = pList->Size();
07244         for (INT32 i = 0; i < nListSize; i++)
07245         {
07246             pCapture = *(--it);
07247 
07248             pCapture->RemoveAllCachedClipRegions();
07249         }
07250     }
07251 }
07252 
07253 
07254 
07255 
07256 
07257 
07258 
07259 
07260 
07261 
07262 
07263 
07264 
07265 
07266 
07267 
07268 
07269 
07270 
07271 void GRenderRegion::OffsetByHalfPixel()
07272 {
07273     
07274     INT32 OffsetX = (INT32)(0.5 + (0.5 * ScaledPixelWidth));
07275     INT32 OffsetY = (INT32)(0.5 + (0.5 * ScaledPixelWidth));
07276     RenderMatrix.translate(OffsetX, OffsetY);
07277 
07278 
07279 
07280 
07281 
07282 
07283     
07284     
07285     INT32   LEFTSHIFT   = FX + 15;
07286     CurrentGMatrix.CX -= (XLONG)(1<<LEFTSHIFT);
07287     CurrentGMatrix.CY -= (XLONG)(1<<LEFTSHIFT);
07288     GetDrawContext()->SetMatrix( &CurrentGMatrix );
07289 }
07290 
07291 
07292 
07293 
07294 
07295 
07296 
07297 
07298 
07299 
07300 
07301 
07302 
07303 
07304 
07305 void GRenderRegion::GetRenderRegionCaps(RRCaps* pCaps)
07306 {
07307     if (m_ForcePrintingCaps == 1)
07308     {
07309         
07310         pCaps->CanDoNothing();
07311         pCaps->GradFills = TRUE;
07312         pCaps->LineAttrs = TRUE;
07313         pCaps->ArrowHeads = TRUE;
07314         pCaps->DashPatterns = TRUE;
07315         pCaps->SimpleBitmaps = TRUE;
07316     }
07317     else if (m_ForcePrintingCaps == 2)
07318     {
07319         
07320         pCaps->CanDoNothing();
07321         pCaps->GradFills = TRUE;
07322         pCaps->SimpleBitmaps = TRUE;
07323         pCaps->ArbitraryBitmaps = TRUE;
07324         pCaps->ClippedSimpleBitmaps = TRUE;
07325         pCaps->ClippedArbitraryBitmaps = TRUE;
07326         pCaps->ClippedOutput = TRUE;
07327     }
07328     else
07329     {
07330         
07331         pCaps->CanDoAll();
07332     }
07333 }
07334 
07335 
07336 
07337 
07338 
07339 
07340 
07341 
07342 
07343 
07344 
07345 
07346 
07347 
07348 void GRenderRegion::SetSimulatePrinting(UINT32 PrintType)
07349 {
07350     m_ForcePrintingCaps = PrintType;
07351     if (PrintType)
07352         RenderFlags.Printing = TRUE;
07353 
07354     
07355     GetRenderRegionCaps(&Caps);
07356 }
07357 
07358 
07359 
07360 
07361 
07362 
07363 
07364 
07365 
07366 
07367 
07368 
07369 
07370 
07371 
07372 
07373 
07374 SlowJobResult GRenderRegion::DrawMaskedBitmap(const DocRect &Rect, KernelBitmap* pBitmap, 
07375                                       MaskedRenderRegion* pMask, ProgressDisplay *Progress)
07376 {
07377 
07378     
07379     
07380     if ((pBitmap==NULL) || (pMask==NULL))
07381         return SLOWJOB_FAILURE;
07382 
07383     
07384     
07385     
07386     if (pMask->FindCoverage(TRUE) == 0)
07387         return SLOWJOB_SUCCESS;
07388 
07389     
07390     if (pBitmap->ActualBitmap == NULL)
07391         return SLOWJOB_FAILURE;
07392 
07393     
07394     CWxBitmap *WinBM = (CWxBitmap*)pBitmap->ActualBitmap;
07395 
07396     
07397     if ((WinBM->BMInfo==NULL) || (WinBM->BMBytes==NULL))
07398         return SLOWJOB_FAILURE;
07399 
07400     
07401     INT32 Width  = WinBM->GetWidth();
07402     INT32 Height = WinBM->GetHeight();
07403 
07404     if ((Width == 0) || (Height == 0))
07405         
07406         return SLOWJOB_FAILURE;
07407 
07408     
07409     POINT PGram[3];
07410     PGram[0].x = Rect.lo.x; PGram[0].y = Rect.lo.y;
07411     PGram[1].x = Rect.hi.x; PGram[1].y = Rect.lo.y;
07412     PGram[2].x = Rect.lo.x; PGram[2].y = Rect.hi.y;
07413 
07414     
07415     RGBQUAD *Palette = NULL;
07416 
07417     
07418     
07419 
07420 
07421     
07422 
07423         Palette = WinBM->BMInfo->bmiColors;
07424 
07425     DWORD Style = 0x0040;       
07426 
07427     BOOL bForceToWhite = FALSE;
07428     BOOL bClearBitmapConv = FALSE;
07429     BYTE* pSepTables = NULL;
07430 
07431 
07432 
07433 
07434 
07435 
07436 
07437 
07438     
07439     
07440     
07441     if (WinBM->GetBPP() > 8)    
07442     {
07443         
07444         if (RenderView->GetColourPlate() != NULL &&
07445             !RenderView->GetColourPlate()->IsDisabled())
07446         {
07447             if (RenderView->GetColourPlate()->GetType() == COLOURPLATE_COMPOSITE)
07448             {
07449                 
07450                 
07451 PORTNOTE("cms", "Disabled XaraCMS")
07452 #ifndef EXCLUDE_FROM_XARALX
07453                 XaraCMS* lpCMSMan = GetApplication()->GetCMSManager();
07454                 if (lpCMSMan != NULL)
07455                 {
07456                     DWORD *MatchTable = lpCMSMan->GetPaperViewTable();
07457                     ERROR3IF(MatchTable == NULL, "Can't create/find colour matching table");
07458                     if (MatchTable != NULL)
07459                     {
07460                         GetDrawContext()->SetBitmapConversionTable((BGR *)MatchTable);
07461                         bClearBitmapConv = TRUE;
07462                         
07463                         
07464                         Style |= (BitmapConversion & 3) << 19;
07465                     }
07466                 }
07467 #endif
07468             }
07469             else if (RenderView->GetColourPlate()->GetType() == COLOURPLATE_SPOT)
07470             {
07471                 bForceToWhite = TRUE;
07472             }
07473             else if (RenderView->GetColourPlate()->GetType() != COLOURPLATE_NONE)
07474             {
07475 
07476                 pSepTables = (BYTE *) CCMalloc(5 * 256 * sizeof(BYTE));
07477                 if (pSepTables != NULL)
07478                 {
07479                     String_256 PrintProfile;
07480 PORTNOTE("cms", "Disabled XaraCMS")
07481 #ifndef EXCLUDE_FROM_XARALX
07482                     XaraCMS* lpCMSMan = GetApplication()->GetCMSManager();
07483                     if (lpCMSMan)
07484                         lpCMSMan->GetPrinterProfile(&PrintProfile);
07485 #endif
07486                     ColourContextCMYK *cc = new ColourContextCMYK(RenderView, &PrintProfile);
07487                     if (cc->GetProfileTables(pSepTables))
07488                     {
07489                         WinBM->ColourSeparate32to32(RenderView->GetColourPlate(), pSepTables);
07490                     }
07491                     delete cc;
07492                 }
07493             }
07494         }
07495     }
07496 
07497     if (bForceToWhite)
07498     {
07499         
07500         DWORD* pPixel = (DWORD*)WinBM->BMBytes;
07501         for (INT32 y = 0; y < Height; y++)
07502         {
07503             for (INT32 x = 0; x < Width; x++)
07504             {
07505                 *(pPixel++) = 0xFFFFFFFF;
07506             }
07507         }
07508 
07509         
07510         MaskRegion MaskInfo;
07511         pMask->GetFirstMaskRegion(&MaskInfo);
07512         while (MaskInfo.Length != 0)
07513         {
07514 
07515             pPixel = ((DWORD*)WinBM->BMBytes) + (MaskInfo.y * Width) + MaskInfo.x;
07516             for (INT32 x = 0; x < MaskInfo.Length; x++)
07517             {
07518                 *(pPixel++) = 0xFFFFFF;
07519             }
07520 
07521             
07522             pMask->GetNextMaskRegion(&MaskInfo);
07523         }
07524     }
07525     else
07526     {
07527         const RGBQUAD TOnly = {0, 0, 0, 0xFF}; ; 
07528         const DWORD DTOnly = *(DWORD *)(&TOnly);
07529         
07530         DWORD* pPixel = (DWORD*)WinBM->BMBytes;
07531         for (INT32 y = 0; y < Height; y++)
07532         {
07533             for (INT32 x = 0; x < Width; x++)
07534             {
07535                 *(pPixel++) |= DTOnly;
07536             }
07537         }
07538 
07539         
07540         MaskRegion MaskInfo;
07541         pMask->GetFirstMaskRegion(&MaskInfo);
07542         while (MaskInfo.Length != 0)
07543         {
07544 
07545             pPixel = ((DWORD*)WinBM->BMBytes) + (MaskInfo.y * Width) + MaskInfo.x;
07546             for (INT32 x = 0; x < MaskInfo.Length; x++)
07547             {
07548                 *(pPixel++) &= 0xFFFFFF;
07549             }
07550 
07551             
07552             pMask->GetNextMaskRegion(&MaskInfo);
07553         }
07554     }
07555 
07556     BYTE *BitmapBits = WinBM->BMBytes;
07557 
07558 
07559 
07560 
07561 
07562 
07563 
07564 
07565 
07566     
07567     GetDrawContext()->PlotBitmap(   &(WinBM->BMInfo->bmiHeader),
07568                     BitmapBits,
07569                     Style,
07570                     PGram,
07571                     Palette,
07572                     NULL, NULL, NULL,
07573                     NULL
07574                     );
07575 
07576     HaveRenderedSomething = TRUE;
07577 
07578     
07579     
07580     
07581     if (Palette != WinBM->BMInfo->bmiColors)
07582         CCFree(Palette);
07583 
07584     if (bClearBitmapConv)
07585     {
07586         GetDrawContext()->SetBitmapConversionTable(NULL);
07587     }
07588 
07589     if (pSepTables)
07590     {
07591         GetDrawContext()->SetSeparationTables();    
07592         CCFree(pSepTables);
07593     }
07594 
07595 
07596 
07597 
07598 
07599 
07600 
07601 
07602 
07603 
07604 
07605 
07606 
07607 
07608     return SLOWJOB_SUCCESS;
07609 }
07610 
07611 
07612 
07613 
07614 
07615 
07616 
07617 
07618 
07619 
07620 
07621 
07622 
07623 
07624 
07625 
07626 
07627 
07628 
07629 BOOL GRenderRegion::GrabBitmap(DocRect* rectGrab, LPBITMAPINFO* plpBitmapInfo, LPBYTE* plpBits)
07630 {
07631     
07632     LPBITMAPINFO    bmInfo = NULL;
07633     LPBYTE          bmBits = NULL;
07634 
07635     
07636     *rectGrab   = rectGrab->Intersection(CurrentClipRect);
07637     if (rectGrab->IsEmpty() || !rectGrab->IsValid())
07638         return FALSE;
07639 
07640     WinRect Rect = CalculateWinRect(RenderMatrix, *rectGrab, PixelsPerInch);
07641     UINT32 PixelWidth = Rect.width;
07642     UINT32 PixelHeight = Rect.height;
07643 
07644     bmInfo = AllocDIB( PixelWidth, PixelHeight, 32, &bmBits, NULL, FALSE); 
07645 
07646 
07647     if(!bmInfo || !bmBits)
07648     {
07649         ENSURE(FALSE,"GRenderRegion::GrabBitmap couldn't create bitmap.");
07650         return FALSE;
07651     }
07652 
07653     LPBITMAPINFOHEADER bh = &bmInfo->bmiHeader;
07654     bh->biCompression   = BI_RGB;                                               
07655     bh->biXPelsPerMeter = PixelsPerMeterAtCurrentViewScale(ScaleFactor);        
07656     bh->biYPelsPerMeter = PixelsPerMeterAtCurrentViewScale(ScaleFactor);        
07657 
07658     
07659     WinRect rectBack = CalculateWinRect(CurrentClipRect);
07660     WinRect rectWinGrab = CalculateWinRect(*rectGrab);
07661     INT32 left = rectWinGrab.x - rectBack.x;
07662     INT32 top = rectBack.GetBottom() - rectWinGrab.GetBottom();
07663     DIBUtil::CopyBitmapSection(pBitmapInfo, pBits, bmInfo, bmBits, top, left);
07664 
07665     *plpBitmapInfo = bmInfo;
07666     *plpBits = bmBits;
07667 
07668     
07669     
07670     
07671     DocRect rectPix = OSRenderRegion::WinRectToDoc(RenderMatrix, Rect, PixelsPerInch);
07672     ENSURE(rectPix.IsValid(), "Pixelised rect is not valid in GrabBitmap");
07673     *rectGrab = rectPix;
07674 
07675     return TRUE;
07676 }
07677 
07678 
07679 
07680 
07681 
07682 
07683 
07684 
07685 
07686 
07687 
07688 
07689 
07690 
07691 
07692 
07693 
07694 
07695 DocRect GRenderRegion::GetChangedRect()
07696 {
07697     RECT UsedRect;
07698     DocRect dr;
07699 
07700     
07701     
07702     
07703     BOOL ok = GetDrawContext()->GetChangedBBox(&UsedRect);
07704     if (!(ok &&
07705         (UsedRect.right > UsedRect.left) &&
07706         (UsedRect.bottom > UsedRect.top)
07707         )
07708        )
07709     {
07710         WinRect winr = WinRect(UsedRect.left, UsedRect.top, UsedRect.right, UsedRect.bottom);
07711         OilRect oilr = winr.ToOil( GetRenderView() );
07712         dr = oilr.ToDoc( GetRenderSpread(), GetRenderView() );
07713     }
07714 
07715     dr = OSRenderRegion::WinRectToDoc(RenderMatrix, WinRect(UsedRect.left, UsedRect.top, UsedRect.right, UsedRect.bottom), PixelsPerInch);
07716 
07717     return dr;
07718 }
07719 
07720 
07721 
07722 
07723 
07724 
07725 
07726 
07727 
07728 
07729 
07730 
07731 
07732 
07733 
07734 
07735 
07736 
07737 
07738 
07739 
07740 
07741 
07742 
07743 
07744 
07745 
07746 
07747 
07748 
07749 
07750 Capture* GRenderRegion::StartCapture(CCObject* pOwner,
07751                                  DocRect CaptureRect,
07752                                  CAPTUREINFO cinfo,
07753                                  BOOL bTransparent,
07754                                  BOOL bCaptureBackground,
07755                                  double dPPI,
07756                                  NodeRenderableInk* pDirectSupplier
07757                                  )
07758 {
07759     ENSURE(cinfo.caType==ctNESTABLE, "We only support nestable captures at the moment\n");
07760 
07761     
07762         
07763         
07764     
07765     
07766 
07767     
07768     
07769     Capture* pCurrentCapture = GetTopCapture();
07770     if (pCurrentCapture!=NULL && cinfo.caType==ctNESTABLE && !cinfo.caFlags.GrabRendered && pCurrentCapture->IsTransparent() && !bTransparent)
07771     {
07772         ChangeCapture(cinfo, bTransparent, bCaptureBackground);
07773     }
07774 
07775     
07776     
07777     
07778     Matrix CaptureMatrix;
07779     if (dPPI==0)
07780     {
07781 
07782 
07783         
07784         Capture* pCap = GetTopCaptureBitmap();
07785         ERROR2IF(pCap==NULL, NULL, "There MUST be a bitmap capture in the stack - the master capture at least");
07786         dPPI = pCap->dPixelsPerInch;
07787         cinfo.caFlags.CalcScaledPixWidth = pCap->info.caFlags.CalcScaledPixWidth;
07788 
07789         CaptureMatrix = RenderMatrix;
07790     }
07791     else
07792     {
07793         
07794         
07795         
07796         
07797 
07798     }
07799 
07800     ERROR3IF(cinfo.caFlags.CalcScaledPixWidth && dPPI!=GetTopCaptureBitmap()->dPixelsPerInch,
07801                 "StartCapture asked to calc ScaledPixelWidth when PPI differs from base PPI - are you sure about this?");
07802 
07803     ERROR3IF(cinfo.caFlags.CalcScaledPixWidth && dPPI!=GetTopCaptureBitmap()->dPixelsPerInch,
07804                 "StartCapture asked to compute scaled pixel width in capture when res differs from current res");
07805 
07806     
07807     
07808     
07809     ColourContext* pColContext = NULL;
07810     if (!cinfo.caFlags.Master)
07811     {
07812         BOOL bOldForce = RenderView->SetForceDefaultColourContexts();
07813         pColContext = RenderView->GetColourContext(COLOURMODEL_RGBT);
07814         RenderView->SetForceDefaultColourContexts(bOldForce);
07815     }
07816     else
07817     {
07818         
07819         pColContext = CurrentColContext;
07820     }
07821 
07822     
07823     Capture* pNewCapture = new Capture(pOwner, cinfo, CaptureMatrix, CaptureRect, dPPI, pColContext);
07824     ENSURE(!pNewCapture->IsMaster(), "Can only have one master capture!");
07825 
07826     
07827     
07828     if (pNewCapture && pNewCapture->info.caFlags.GrabRendered)
07829     {
07830         
07831         ENSURE(pNewCapture->lpBitmapInfo==NULL && pNewCapture->lpBits==NULL, "GrabRendered capture owns a bitmap!");
07832         m_CaptureStack.Push(pNewCapture);
07833         return pNewCapture;
07834     }
07835 
07836     
07837     
07838     
07839     
07840     
07841     if (pNewCapture && pNewCapture->info.caFlags.AllowDirect && pDirectSupplier)
07842     {
07843         BOOL bDirectCapture = SetupDirectCapture(pNewCapture, pDirectSupplier);
07844         if (bDirectCapture)
07845         {
07846             ENSURE(pNewCapture->lpBitmapInfo==NULL && pNewCapture->lpBits==NULL, "AllowDirectCapture capture owns a bitmap!");
07847             m_CaptureStack.Push(pNewCapture);
07848             return pNewCapture;
07849         }
07850     }
07851 
07852     
07853     
07854     LPBITMAPINFO    bmInfo = NULL;
07855     LPBYTE          bmBits = NULL;
07856 
07857     
07858     
07859     WinRect Rect = CalculateWinRect(CaptureMatrix, CaptureRect, dPPI);
07860     UINT32 PixelWidth = Rect.width;
07861     UINT32 PixelHeight = Rect.height;
07862     if (PixelWidth==0 || PixelHeight==0 || 
07863         PixelWidth*PixelHeight>256*1024*1024 ||
07864         PixelWidth >GetDrawContext()->GetMaxBitmapWidth() ||
07865         PixelHeight>GetDrawContext()->GetMaxBitmapDepth())
07866     {
07867         delete pNewCapture;
07868         return NULL;
07869     }
07870 
07871     
07872     
07873     
07874     DocRect rectPix = OSRenderRegion::WinRectToDoc(CaptureMatrix, Rect, dPPI);
07875     ENSURE(rectPix.IsValid(), "Pixelised rect is not valid in StopCapture");
07876     pNewCapture->CaptureRect = rectPix;
07877 
07878     bmInfo = AllocDIB(PixelWidth, PixelHeight, 32, &bmBits, NULL, FALSE);
07879     if (bmInfo==NULL || bmBits==NULL)
07880     {
07881         ENSURE(FALSE,"Couldn't create bitmap for offscreen rendering.");
07882         return NULL;
07883     }
07884 
07885 if (dPPI!=PixelsPerInch)
07886 {
07887     ENSURE(!bCaptureBackground, "Sorry StartCapture can't scale blit background into capture yet\n");
07888 
07889     double xppm = dPPI * INCHES_PER_METRE;
07890     double yppm = dPPI * INCHES_PER_METRE;
07891     bmInfo->bmiHeader.biXPelsPerMeter = (INT32)(xppm + 0.5);
07892     bmInfo->bmiHeader.biYPelsPerMeter = (INT32)(yppm + 0.5);
07893 }
07894 
07895     if (bTransparent)
07896         bmInfo->bmiHeader.biCompression = 0x80000001;
07897 
07898 
07899     pNewCapture->SetDIB(bmInfo, bmBits);
07900 
07901     
07902     if (bCaptureBackground && dPPI==PixelsPerInch)
07903     {
07904         
07905         WinRect rectBack = CalculateWinRect(CurrentClipRect);
07906         WinRect rectOffs = CalculateWinRect(CaptureRect);
07907         INT32 left = rectOffs.x - rectBack.x;
07908         INT32 top = rectBack.GetBottom() - rectOffs.GetBottom();
07909         DIBUtil::CopyBitmapSection(pBitmapInfo, pBits, pNewCapture->lpBitmapInfo, pNewCapture->lpBits, top, left);
07910     }
07911     else
07912     {
07913         BYTE* pSetBits = (BYTE*)pNewCapture->lpBits;
07914 
07915         
07916         
07917         UINT32 BmpSize = GetDIBBitsSize( &(pNewCapture->lpBitmapInfo->bmiHeader) );
07918         UINT32 Index = 0;
07919 
07920         ENSURE(pNewCapture->lpBitmapInfo->bmiHeader.biBitCount==32,"Non-32bpp bitmap in offscreen rendering!");
07921 
07922         if (bTransparent)
07923             while (Index < BmpSize)
07924             {
07925                 
07926                 
07927 
07928                 pSetBits[Index++] = 0x00;
07929                 pSetBits[Index++] = 0x00;
07930                 pSetBits[Index++] = 0x00;
07931                 pSetBits[Index++] = 0xFF;
07932             }
07933         else
07934             while (Index < BmpSize)
07935             {
07936                 
07937                 pSetBits[Index++] = 0xFF;
07938                 pSetBits[Index++] = 0xFF;
07939                 pSetBits[Index++] = 0xFF;
07940                 pSetBits[Index++] = 0x00;
07941             }
07942     }
07943 
07944     
07945     m_CaptureStack.Push(pNewCapture);
07946 
07947     
07948     SetRenderToCapture(pNewCapture);
07949 
07950     
07951     
07952     
07953     
07954     if (cinfo.caFlags.UnClip)
07955     {
07956         SaveContext();
07957         ClipRegionAttribute* pClipRegion = new ClipRegionAttribute();   
07958         if (pClipRegion)
07959         {
07960 
07961 
07962 
07963 
07964 
07965 
07966 
07967             SetClipRegion(pClipRegion, TRUE);       
07968         }
07969     }
07970 
07971     return pNewCapture;
07972 }
07973 
07974 
07975 
07976 
07977 
07978 
07979 
07980 
07981 
07982 
07983 
07984 
07985 
07986 
07987 
07988 
07989 
07990 
07991 
07992 
07993 
07994 
07995 
07996 
07997 
07998 BOOL GRenderRegion::StopCapture(CCObject* pOwner,
07999                                 BOOL bRender,
08000                                 BOOL bReleaseBitmap,
08001                                 LPBITMAPINFO* plpBitmapInfo,
08002                                 LPBYTE* plpBits,
08003                                 DocRect* pCaptureRect,
08004                                 Matrix* pmatTransform,
08005                                 double* pdResolution)
08006 {
08007     Capture* pCapture = GetTopCapture();
08008     if (pCapture==NULL)
08009         return FALSE;
08010 
08011     if (pCapture->IsMaster())
08012     {
08013         ERROR2(FALSE, "StopCapture called on the master capture!\n");
08014         return FALSE;
08015     }
08016 
08017     
08018     BOOL bOK = TRUE;
08019     if (pCapture->OwnsBitmap())
08020     {
08021         
08022         if (pCapture->IsUnclipped())
08023         {
08024             RestoreContext();
08025         }
08026 
08027         
08028         if (plpBitmapInfo && plpBits)
08029         {
08030             *plpBitmapInfo = NULL;
08031             *plpBits = NULL;
08032         }
08033 
08034         if (pCaptureRect)
08035         {
08036             *pCaptureRect = DocRect(0,0,0,0);
08037         }
08038 
08039         
08040         m_CaptureStack.Pop();
08041 
08042         
08043         SetRenderToCapture(GetTopCaptureBitmap(), TRUE);
08044 
08045         
08046         LPBITMAPINFO lpCapturedBitmapInfo = pCapture->lpBitmapInfo;
08047         LPBYTE lpCapturedBits = pCapture->lpBits;
08048         DocRect rectCaptured = pCapture->CaptureRect;
08049         ENSURE(rectCaptured.IsValid(), "Invalid rect in StopCapture");
08050 
08051         
08052         
08053         if (lpCapturedBitmapInfo && lpCapturedBits && lpCapturedBitmapInfo->bmiHeader.biCompression==0x80000001)
08054         {
08055             GetDrawContext()->ConvertBitmap(
08056                                         &lpCapturedBitmapInfo->bmiHeader, lpCapturedBits,
08057                                         &lpCapturedBitmapInfo->bmiHeader, lpCapturedBits,
08058                                         0
08059                                     );
08060             
08061         }
08062 
08063         
08064         if (plpBitmapInfo && plpBits && pCaptureRect && !bReleaseBitmap)
08065         {
08066             *plpBitmapInfo = lpCapturedBitmapInfo;
08067             *plpBits = lpCapturedBits;
08068             *pCaptureRect = rectCaptured;
08069         }
08070 
08071         
08072         if (bRender && lpCapturedBitmapInfo && lpCapturedBits)
08073         {
08074             
08075             
08076             RenderBits(lpCapturedBitmapInfo, lpCapturedBits, rectCaptured);
08077         }
08078 
08079         
08080         if (bReleaseBitmap)
08081             pCapture->FreeDIB();
08082 
08083         delete pCapture;
08084     }
08085     else
08086     {
08087         
08088         if (plpBitmapInfo && plpBits)
08089         {
08090             *plpBitmapInfo = NULL;
08091             *plpBits = NULL;
08092         }
08093 
08094         
08095         if (pCaptureRect && plpBitmapInfo && plpBits && pCapture->info.caFlags.GrabRendered)
08096         {
08097             ENSURE(pCaptureRect->IsValid(), "Invalid rect in StopCapture");
08098 
08099             
08100             
08101             
08102             
08103             
08104             
08105             
08106             
08107             Capture* pMasterCapture = GetMasterCapture();
08108             ENSURE(pMasterCapture, "Can't find master capture!");
08109             if (pMasterCapture->pColContext == ColourContext::GetGlobalDefault(COLOURMODEL_RGBT))
08110                 bOK = GrabBitmap(pCaptureRect, plpBitmapInfo, plpBits);         
08111             else
08112                 bOK = FALSE;
08113         }
08114 
08115         NodeRenderableInk* pSupplier = pCapture->GetDirectSupplier();
08116         if (pCapture->info.caFlags.Direct && pSupplier)
08117         {
08118             bOK = pSupplier->GetDirectBitmap(this, plpBitmapInfo, plpBits, pCaptureRect, pmatTransform, pdResolution);
08119         }
08120 
08121         
08122         
08123         m_CaptureStack.Pop();
08124 
08125         delete pCapture;
08126     }
08127 
08128 #ifdef DEBUG_ATTACH_CAPTURED_BMP
08129 {
08130     if (*plpBitmapInfo && *plpBits)
08131     {
08132         
08133         CWxBitmap* wBitmap          = new CWxBitmap(*plpBitmapInfo, *plpBits);
08134         KernelBitmap* OffscreenBitmap   = new KernelBitmap(wBitmap,TRUE);
08135         OffscreenBitmap->AttachDebugCopyToCurrentDocument("Captured Bitmap");
08136         wBitmap->BMBytes = ((CWxBitmap*)OILBitmap::Default)->BMBytes;
08137         delete OffscreenBitmap;
08138     }
08139 }
08140 #endif
08141 
08142     
08143     if (MasterCaptureIsCurrent())
08144     {
08145         
08146         
08147         RECT bbox;
08148         bbox.left = 0;
08149         bbox.right = WRect.width;
08150         bbox.top = 0;
08151         bbox.bottom = WRect.height; 
08152 
08153         if (!GetDrawContext()->SetChangedBBox(&bbox))
08154         {
08155             ERROR3("GDraw_SetChangedBBox failed");
08156         }
08157     }
08158 
08159     return bOK;
08160 }
08161 
08162     
08163     
08164     
08165 
08166 
08167 
08168 
08169 
08170 
08171 
08172 
08173 
08174 
08175 
08176 
08177 
08178 
08179 BOOL GRenderRegion::ChangeCapture(CAPTUREINFO cinfo,
08180                                 BOOL bTransparent,
08181                                 BOOL bCaptureBackground)
08182 {
08183     
08184     
08185     
08186     
08187     
08188     Capture* pCurrentCapture = GetTopCapture();
08189     if (pCurrentCapture==NULL)
08190         return FALSE;
08191 
08192     if (pCurrentCapture->IsMaster())
08193     {
08194         ENSURE(m_CaptureStack.Size()==1, "Master Capture not bottom capture in ChangeCapture");
08195         return FALSE;
08196     }
08197 
08198     
08199     
08200     if (bTransparent == pCurrentCapture->IsTransparent())
08201         return TRUE;
08202 
08203     ERROR2IF(bTransparent, FALSE, "ChangeCapture doesn't cope with changing UP to transparency yet");
08204 
08205     
08206     ListT<Capture*>* pList = m_CaptureStack.GetListT();
08207 
08208     {
08209         
08210         
08211         Capture* pCapture = NULL;
08212         ListT<Capture*>::Iterator it = pList->End();
08213         INT32 nListSize = pList->Size();
08214         for (INT32 i = 0; i < nListSize; i++)
08215         {
08216             pCapture = *(--it);
08217 
08218             
08219             if (pCapture->IsTransparent() && pCapture->info.caFlags.LockedTransparent)
08220                 return TRUE;
08221 
08222             
08223             if (pCapture->IsMaster() && pCapture->IsTransparent())
08224                 return TRUE;
08225         }
08226     }
08227 
08228     {
08229         
08230         
08231         Capture* pCapture = NULL;
08232         ListT<Capture*>::Iterator it = pList->End();
08233         INT32 nListSize = pList->Size();
08234         for (INT32 i = 0; i < nListSize; i++)
08235         {
08236             pCapture = *(--it);
08237 
08238             
08239             if (pCapture->IsMaster())
08240                 break;
08241             if (!pCapture->IsTransparent())
08242                 break;
08243 
08244             
08245             if (pCapture->info.caFlags.CollapseToMaster)
08246             {
08247                 
08248                 
08249                 Capture* pPrevCapture = GetTopCaptureBitmap(pCapture);
08250                 ENSURE(pPrevCapture, "Failed to find parent capture with bitmap!");
08251                 ENSURE(pPrevCapture->OwnsBitmap(), "At least one parent capture should own a bitmap!");
08252 
08253                 
08254                 if (pCapture->info.caFlags.UnClip)
08255                 {
08256                     RestoreContext();
08257                     pCapture->info.caFlags.UnClip = FALSE;
08258                 }
08259 
08260                 SetRenderToCapture(pPrevCapture);
08261 
08262                 LPBITMAPINFO lpCapturedBitmapInfo = pCapture->lpBitmapInfo;
08263                 LPBYTE lpCapturedBits = pCapture->lpBits;
08264                 DocRect rectCaptured = pCapture->CaptureRect;
08265 
08266                 
08267                 
08268                 if (lpCapturedBitmapInfo && lpCapturedBits && lpCapturedBitmapInfo->bmiHeader.biCompression==0x80000001)
08269                 {
08270                     GetDrawContext()->ConvertBitmap(
08271                                                 &lpCapturedBitmapInfo->bmiHeader, lpCapturedBits,
08272                                                 &lpCapturedBitmapInfo->bmiHeader, lpCapturedBits,
08273                                                 0
08274                                             );
08275                 }
08276 
08277                 
08278                 if (lpCapturedBitmapInfo && lpCapturedBits)
08279                 {
08280                     RenderBits(lpCapturedBitmapInfo, lpCapturedBits, rectCaptured);
08281                 }
08282 
08283                 
08284                 pCapture->FreeDIB();
08285             }
08286             else if (pCapture->info.caFlags.LockedTransparent)
08287             {
08288                 
08289                 
08290                 
08291                 
08292                 
08293                 ERROR3("Shouldn't get here!");
08294                 break;
08295             }
08296             else
08297             {
08298                 
08299                 
08300                 
08301                 
08302                 
08303                 
08304 
08305                 
08306                 Capture* pNewCapture = new Capture(pCapture, TRUE);
08307                 pNewCapture->SetTransparent(FALSE);
08308 
08309                 
08310                 SetRenderToCapture(pNewCapture);
08311                 RenderCurrentCaptureState(TRUE);
08312 
08313 #ifdef DEBUG_ATTACH_TCHANGE_BMP
08314 {
08315     
08316     CWxBitmap* wBitmap          = new CWxBitmap(pNewCapture->lpBitmapInfo, pNewCapture->lpBits);
08317     KernelBitmap* OffscreenBitmap   = new KernelBitmap(wBitmap,TRUE);
08318     OffscreenBitmap->AttachDebugCopyToCurrentDocument("Transp Change Capture Bitmap");
08319     wBitmap->BMBytes = ((CWxBitmap*)OILBitmap::Default)->BMBytes;
08320     delete OffscreenBitmap;
08321 }
08322 #endif
08323                 
08324                 ENSURE(!pNewCapture->IsMaster(), "Can only have one master capture!");
08325                 ListT<Capture*>::Iterator itCap = it;       
08326                 it = pList->Insert(itCap, pNewCapture);         
08327                 pList->Erase(itCap);                        
08328 
08329                 pCapture->FreeDIB();
08330                 delete pCapture;
08331             }
08332         }
08333     }
08334 
08335     SetRenderToCapture(GetTopCaptureBitmap());
08336 
08337     
08338     if (MasterCaptureIsCurrent())
08339     {
08340         
08341         
08342         RECT bbox;
08343         bbox.left = 0;
08344         bbox.right = WRect.width;
08345         bbox.top = 0;
08346         bbox.bottom = WRect.height; 
08347 
08348         if (!GetDrawContext()->SetChangedBBox(&bbox))
08349         {
08350             ERROR3("GDraw_SetChangedBBox failed");
08351         }
08352     }
08353 
08354     return TRUE;
08355 }
08356 
08357 
08358 
08359 
08360 
08361 
08362 
08363 
08364 
08365 
08366 
08367 
08368 
08369 
08370 
08371 
08372 
08373 
08374 BOOL GRenderRegion::SetupDirectCapture(Capture* pNewCapture, NodeRenderableInk* pSupplier)
08375 {
08376     
08377     ERROR2IF(pNewCapture->info.caFlags.Master, FALSE, "Can't set Master capture for Direct capturing!");
08378 
08379     if (pSupplier==NULL || !pSupplier->CanSupplyDirectBitmap())
08380         return FALSE;
08381 
08382     
08383     pNewCapture->info.caFlags.Direct = TRUE;
08384     pNewCapture->SetDirectSupplier(pSupplier);
08385     return TRUE;
08386 }
08387 
08388 
08389 
08390 
08391 
08392 
08393 
08394 
08395 
08396 
08397 
08398 
08399 
08400 
08401 
08402 
08403 
08404 
08405 
08406 BOOL GRenderRegion::RenderCurrentCaptureState(BOOL bStartFromMaster)
08407 {
08408     if (MasterCaptureIsCurrent() && !TopCaptureIsDirect())
08409     {
08410         return FALSE;
08411     }
08412 
08413     
08414     
08415     
08416 
08417     {
08418         
08419         LPBITMAPINFO lpCapturedBitmapInfo = pBitmapInfo;
08420         LPBYTE lpCapturedBits = pBits;
08421         DocRect rectCaptured = CurrentClipRect;
08422 
08423         
08424         
08425         
08426         Capture* pCapture = NULL;
08427         ListT<Capture*>* pList = m_CaptureStack.GetListT();
08428 
08429         ListT<Capture*>::Iterator it = pList->Begin();
08430         INT32 nListSize = pList->Size();
08431         for (INT32 i = 0; i < nListSize; i++)
08432         {
08433             pCapture = *(it++);
08434 
08435             NodeRenderableInk* pSupplier = pCapture->GetDirectSupplier();
08436             if (pCapture->info.caFlags.Direct && pSupplier )
08437             {
08438                 
08439                 
08440                 
08441                 
08442                 pSupplier->RenderDirectBitmapState(this);
08443             }
08444             else
08445             {
08446                 if (pCapture && pCapture->OwnsBitmap() && (i>0 || bStartFromMaster))
08447                 {
08448                     lpCapturedBitmapInfo = pCapture->lpBitmapInfo;
08449                     lpCapturedBits = pCapture->lpBits;
08450                     rectCaptured = pCapture->CaptureRect;
08451 
08452                     
08453                     
08454                     
08455                     if (lpCapturedBitmapInfo && lpCapturedBits && lpCapturedBitmapInfo->bmiHeader.biCompression==0x80000001)
08456                     {
08457                         
08458                         DIBUtil::CopyBitmap(lpCapturedBitmapInfo, lpCapturedBits, &lpCapturedBitmapInfo, &lpCapturedBits);
08459                         lpCapturedBitmapInfo->bmiHeader.biCompression = 0x80000001;     
08460 
08461                         GetDrawContext()->ConvertBitmap(
08462                                                     &lpCapturedBitmapInfo->bmiHeader, lpCapturedBits,
08463                                                     &lpCapturedBitmapInfo->bmiHeader, lpCapturedBits,
08464                                                     0
08465                                                 );
08466                         
08467                         if (lpCapturedBitmapInfo && lpCapturedBits)
08468                         {
08469 TRACEUSER( "Phil", _T("RCCS: Rendering Collapsed %x %s\n"), pCapture, pCapture->GetRuntimeClass()->m_lpszClassName);
08470                             RenderBits(lpCapturedBitmapInfo, lpCapturedBits, rectCaptured);
08471                         }
08472 
08473                         
08474 						::FreeDIB(lpCapturedBitmapInfo, lpCapturedBits, NULL, FALSE);
08475                     }
08476                     else
08477                     {
08478                         
08479                         if (lpCapturedBitmapInfo && lpCapturedBits)
08480                         {
08481 TRACEUSER( "Phil", _T("RCCS: Rendering non-transp %x %s\n"), pCapture, pCapture->GetRuntimeClass()->m_lpszClassName);
08482                             RenderBits(lpCapturedBitmapInfo, lpCapturedBits, rectCaptured);
08483                         }
08484                     }
08485                 }
08486             }
08487         }
08488     }
08489 
08490     
08491 
08492 
08493     
08494     RECT bbox;
08495     bbox.left = 0;
08496     bbox.right = WRect.width;
08497     bbox.top = 0;
08498     bbox.bottom = WRect.height; 
08499 
08500     if (!GetDrawContext()->SetChangedBBox(&bbox))
08501     {
08502         ERROR3("GDraw_SetChangedBBox failed");
08503     }
08504 
08505     return TRUE;
08506 }
08507 
08508 
08509 
08510 
08511 
08512 
08513 
08514 
08515 
08516 
08517 
08518 
08519 
08520 
08521 
08522 
08523 
08524 
08525 Capture* GRenderRegion::GetTopCaptureBitmap(Capture* pFromCapture) const
08526 {
08527     const ListT<Capture*>* pList = m_CaptureStack.GetListT();
08528 
08529     Capture* pCapture = NULL;
08530     ListT<Capture*>::ConstIterator it = pList->End();
08531     INT32 nListSize = pList->Size();
08532     INT32 i=0;
08533 
08534     if (pFromCapture)
08535     {
08536         for (i = 0; i < nListSize; i++)
08537         {
08538             pCapture = *(--it);
08539             if (pCapture == pFromCapture)
08540                 break;
08541         }
08542     }
08543 
08544     for (; i < nListSize; i++)
08545     {
08546         pCapture = *(--it);
08547         if (pCapture->OwnsBitmap())
08548             return pCapture;
08549     }
08550 
08551     return NULL;
08552 }
08553 
08554 
08555 
08556 
08557 
08558 
08559 
08560 
08561 
08562 
08563 
08564 
08565 
08566 
08567 
08568 
08569 
08570 #ifdef _DEBUG
08571 BOOL GRenderRegion::DumpCaptureStack()
08572 {
08573     if (m_CaptureStack.Empty())
08574     {
08575         return FALSE;
08576     }
08577 
08578     TRACE( _T("Capture stack:\n"));
08579 
08580 
08581 
08582     DocRect rectCaptured = CurrentClipRect;
08583 
08584     Capture* pCapture = m_CaptureStack.Top();
08585     ListT<Capture*>* pList = m_CaptureStack.GetListT();
08586 
08587     ListT<Capture*>::Iterator it = pList->End();
08588     INT32 nListSize = pList->Size();
08589     for (INT32 i = 0; i < nListSize; i++)
08590     {
08591         pCapture = *(--it);
08592 
08593 
08594 
08595 
08596     }
08597 
08598     return TRUE;
08599 }
08600 #endif
08601 
08602 
08603 
08604 
08605 
08606 
08607 
08608 
08609 
08610 
08611 
08612 
08613 
08614 
08615 
08616 
08617 
08618 
08619 
08620 
08621 BOOL GRenderRegion::SetRenderToCapture(Capture* pCapture, BOOL ApplyClipRegion, BOOL bSetBitmap)
08622 {
08623     ERROR2IF(pCapture==NULL, FALSE, "SetRenderToCapture passed NULL capture pointer");
08624     
08625     
08626     
08627     if (pCapture->lpBitmapInfo && pCapture->lpBits && bSetBitmap)
08628     {
08629         LPBITMAPINFOHEADER pbmiHeader = &(pCapture->lpBitmapInfo->bmiHeader);
08630 
08631         
08632         
08633 
08634 
08635 
08636 
08637 
08638         if (pbmiHeader->biWidth!=0 && pbmiHeader->biHeight!=0 && pbmiHeader->biBitCount!=0)
08639         {
08640             
08641 
08642 
08643             if (!GetDrawContext()->SetBitmap(pbmiHeader, pCapture->lpBits))
08644             {
08645                 ERROR3("GDraw_SetDIBitmap failed");
08646                 return FALSE;
08647             }
08648         }
08649     }
08650 
08651     
08652     
08653     
08654     
08655     
08656     if (pBitmapInfo != pCapture->lpBitmapInfo || pBits != pCapture->lpBits)
08657         CurrentClipRect = pCapture->CaptureRect;
08658 
08659     RenderMatrix    = pCapture->CaptureMatrix;
08660     GMATRIX gmat = MakeGavinMatrix(RenderMatrix, CurrentClipRect, pCapture->dPixelsPerInch, pCapture->IsMaster());
08661     SetGavinMatrix(&gmat);
08662 
08663     if (!GetDrawContext()->SetMatrix(&gmat))
08664     {
08665         ERROR3("GDraw_SetMatrix failed");
08666         return FALSE;
08667     }
08668 
08669     pBitmapInfo     = pCapture->lpBitmapInfo;
08670     pBits           = pCapture->lpBits;
08671     CurrentColContext = pCapture->pColContext;
08672     RenderView->SetForceDefaultColourContexts(!pCapture->IsMaster());
08673     PixelsPerInch   = pCapture->dPixelsPerInch;
08674 
08675     
08676     
08677     PixelWidth      = CalcPixelWidth();
08678     ScaledPixelWidth = PixelWidth;
08679     dScaledPixelWidth = CalcPixelWidthDouble();
08680 
08681     
08682     
08683     if (pCapture->lpBitmapInfo && pCapture->lpBits && bSetBitmap)
08684     {
08685         if (pCapture->info.caFlags.CalcScaledPixWidth || pCapture->info.caFlags.Master)
08686         {
08687             ScaledPixelWidth = CalcScaledPixelWidth();
08688             dScaledPixelWidth = CalcScaledPixelWidthDouble();
08689         }
08690     }
08691 
08692     
08693 
08694 
08695 
08696     
08697     SetupFuzzyClipRects();
08698 
08699     
08700 
08701 
08702         
08703         
08704         
08705         
08706         if ( !GetDrawContext()->ClipRectangle((LPRECT)&pCapture->CaptureRect) )
08707         {
08708             ERROR3("GDraw_ClipRectangle failed");
08709             return FALSE;
08710         }
08711 
08712 
08713 
08714         
08715         ApplyCurrentClipRegion();
08716 
08717 
08718     
08719     BOOL bHintStrokedLines = (pCapture->info.caFlags.Master || pCapture->dPixelsPerInch==GetMasterCapture()->dPixelsPerInch);
08720 
08721     SetQualityLevel();
08722     GetDrawContext()->SetHintingFlag(bHintStrokedLines);
08723     GetDrawContext()->SetDashAdjustmentFlag(FALSE);
08724 
08725     
08726     
08727     POINT DocOrigin, OSOrigin;
08728     DocOrigin.x = 0;
08729     DocOrigin.y = 0;
08730 
08731     
08732     GetDrawContext()->TransformPath( &DocOrigin, &OSOrigin, 1, &gmat );
08733 
08734     
08735     
08736     const INT32 BrushX = OSOrigin.x >> FX;
08737     const INT32 BrushY = -(OSOrigin.y >> FX);                   
08738 
08739     GetDrawContext()->SetHalftoneOrigin( BrushX, BrushY );
08740 
08741     if (pCapture->info.caFlags.QualityNormal)
08742     {
08743         
08744         this->SetDefaultQuality();
08745     }
08746 
08747     
08748     SetSmoothingFlags(NULL);
08749 
08750     return TRUE;
08751 }
08752 
08753 
08754 
08755 
08756 
08757 
08758 
08759 
08760 
08761 
08762 
08763 
08764 
08765 
08766 
08767 
08768 
08769 
08770 
08771 
08772 
08773 
08774 
08775 
08776 static BOOL TC[40] = {
08777                         TRUE,       
08778                         TRUE,       
08779                         FALSE,      
08780                         FALSE,      
08781                         TRUE,       
08782                         FALSE,      
08783                         FALSE,      
08784                         TRUE,       
08785                         FALSE,      
08786                         FALSE,      
08787                         FALSE,      
08788                         FALSE,      
08789                         FALSE,      
08790                         FALSE,      
08791                         FALSE,      
08792                         FALSE,      
08793                         FALSE,      
08794                         FALSE,      
08795                         FALSE,      
08796                         TRUE,       
08797                         TRUE,       
08798                         TRUE,       
08799                         TRUE,       
08800                         TRUE,       
08801                         TRUE,       
08802                         TRUE,       
08803                         TRUE,       
08804                         TRUE,       
08805                         FALSE,      
08806                         FALSE,      
08807                         FALSE,      
08808                         FALSE,      
08809                         FALSE,      
08810                         FALSE,      
08811                         TRUE,       
08812                         TRUE,       
08813                         TRUE,       
08814                         TRUE,       
08815                         TRUE,       
08816                         TRUE,       
08817                       };
08818 
08819 BOOL GRenderRegion::TranspTypeIsRGBTCompatible(UINT32 ttype) const
08820 {
08821     
08822     TransparencyEnum gType = MapTranspTypeToGDraw(ttype, FALSE);        
08823     return TC[gType];
08824 }
08825 
08826 
08827 
08828 
08829 
08830 
08831 
08832 
08833 
08834 
08835 
08836 
08837 
08838 
08839 
08840 
08841 
08842 
08843 
08844 TransparencyEnum GRenderRegion::MapTranspTypeToGDraw(UINT32 ttype, BOOL bGraduated) const
08845 {
08846     if (ttype == 0)
08847         return T_NONE;
08848 
08849     if (bGraduated)
08850     {
08851         if (RenderFlags.HitDetect)
08852             return (enum TransparencyEnum) (T_GRAD_REFLECTIVE);
08853 
08854         if (ttype <= TT_Bleach)
08855         {
08856             
08857             
08858             return (enum TransparencyEnum) (ttype-TT_Mix + T_GRAD_REFLECTIVE);
08859         }
08860 
08861         if (ttype >= TT_CONTRAST && ttype <= TT_BEVEL)
08862         {
08863             
08864             
08865             return (enum TransparencyEnum) (ttype-TT_CONTRAST + T_GRAD_CONTRAST);
08866         }
08867     }
08868     else
08869     {
08870         if (RenderFlags.HitDetect)
08871             return (enum TransparencyEnum) (T_FLAT_REFLECTIVE);
08872 
08873         if (ttype <= TT_Bleach)
08874         {
08875             
08876             
08877             return (enum TransparencyEnum) (ttype-TT_Mix + T_FLAT_REFLECTIVE);
08878         }
08879 
08880         if (ttype >= TT_CONTRAST && ttype <= TT_BEVEL)
08881         {
08882             
08883             
08884             return (enum TransparencyEnum) (ttype-TT_CONTRAST + T_FLAT_CONTRAST);
08885         }
08886     }
08887 
08888     ERROR3("Invalid transp type");
08889     return T_NONE;
08890 }
08891 
08892 
08893 
08894 
08895 #ifdef _DEBUG
08896 void GRenderRegion::DebugTrace()
08897 {
08898 
08899 }
08900 #endif
08901 
08902 
08903 
08904 
08905 
08906 
08907 
08908 
08909 
08910 
08911 
08912 
08913 
08914 
08915 
08916 
08917 
08918 
08919 
08920 
08921 void GRenderRegion::SetBitmapPointers(LPBITMAPINFO bi, LPBYTE by)
08922 {
08923     Capture* pCapture = GetTopCaptureBitmap();
08924     ENSURE(pCapture, "SetBitmapPointers being called while there are no captures!\n");
08925     if (pCapture)
08926     {
08927         ENSURE(pCapture->IsMaster(), "SetBitmapPointers being called while child Captures are running\n");
08928         if (pCapture->IsMaster())
08929         {
08930             pCapture->SetDIB(bi, by);
08931         }
08932     }
08933 
08934     pBitmapInfo = bi;
08935     pBits = by;
08936 }
08937     
08938     
08939     
08940 
08941 
08942 
08943 
08944 
08945 
08946 
08947 
08948 
08949 
08950 
08951 
08952 
08953 
08954 BOOL GRenderRegion::GetBitmapPointers(LPBITMAPINFO* ppInfo, LPBYTE* ppBits, BOOL bCorrectTransparency)
08955 {
08956     Capture* pCapture = GetMasterCapture();
08957     ERROR2IF(!pCapture || !pCapture->IsMaster(), FALSE, "GetBitmapPointers can't find master capture!\n");
08958 
08959     if (bCorrectTransparency && pBitmapInfo->bmiHeader.biCompression==0x80000001)
08960     {
08961         GetDrawContext()->ConvertBitmap(&pBitmapInfo->bmiHeader, pBits,
08962                                         &pBitmapInfo->bmiHeader, pBits,
08963                                         0);
08964     }
08965 
08966     *ppInfo = pBitmapInfo;
08967     *ppBits = pBits;
08968 
08969     return TRUE;
08970 }
08971     
08972     
08973     
08974 
08975 
08976 
08977 
08978 
08979 
08980 
08981 
08982 
08983 
08984 
08985 
08986 
08987 
08988 
08989 
08990 
08991 
08992 
08993 void OpGDraw::Do(OpDescriptor*)
08994 {
08995     GRenderRegion::WantDoGDraw ^= TRUE;
08996 
08997     
08998     ListItem* pItem = Camelot.Documents.GetHead();
08999     while (pItem != NULL)
09000     {
09001         ((Document*) pItem)->ForceRedraw();
09002         pItem = Camelot.Documents.GetNext(pItem);
09003     }
09004 
09005     End();
09006 }
09007 
09008 
09009 
09010 
09011 
09012 
09013 
09014 
09015 
09016 
09017 
09018 
09019 
09020 
09021 
09022 
09023 OpGDraw::OpGDraw()
09024 {
09025 }
09026 
09027 
09028 
09029 
09030 
09031 
09032 
09033 
09034 
09035 
09036 
09037 
09038 
09039 
09040 
09041 
09042 OpState OpGDraw::GetState(String_256*, OpDescriptor*)
09043 {
09044     OpState OpSt;
09045 
09046     if (!GRenderRegion::CanDoGDraw)
09047     {
09048         OpSt.Greyed = TRUE;
09049         return OpSt;
09050     }
09051 
09052     if (GRenderRegion::WantDoGDraw)
09053         OpSt.Ticked = TRUE;
09054 
09055     return OpSt;
09056 }