Back to index

lightning-sunbird  0.9+nobinonly
nsDeviceContextPh.cpp
Go to the documentation of this file.
00001 /* -*- Mode: C++; tab-width: 2; indent-tabs-mode: nil; c-basic-offset: 2 -*- */
00002 /* ***** BEGIN LICENSE BLOCK *****
00003  * Version: MPL 1.1/GPL 2.0/LGPL 2.1
00004  *
00005  * The contents of this file are subject to the Mozilla Public License Version
00006  * 1.1 (the "License"); you may not use this file except in compliance with
00007  * the License. You may obtain a copy of the License at
00008  * http://www.mozilla.org/MPL/
00009  *
00010  * Software distributed under the License is distributed on an "AS IS" basis,
00011  * WITHOUT WARRANTY OF ANY KIND, either express or implied. See the License
00012  * for the specific language governing rights and limitations under the
00013  * License.
00014  *
00015  * The Original Code is mozilla.org code.
00016  *
00017  * The Initial Developer of the Original Code is
00018  * Netscape Communications Corporation.
00019  * Portions created by the Initial Developer are Copyright (C) 1998
00020  * the Initial Developer. All Rights Reserved.
00021  *
00022  * Contributor(s):
00023  *
00024  * Alternatively, the contents of this file may be used under the terms of
00025  * either of the GNU General Public License Version 2 or later (the "GPL"),
00026  * or the GNU Lesser General Public License Version 2.1 or later (the "LGPL"),
00027  * in which case the provisions of the GPL or the LGPL are applicable instead
00028  * of those above. If you wish to allow use of your version of this file only
00029  * under the terms of either the GPL or the LGPL, and not to allow others to
00030  * use your version of this file under the terms of the MPL, indicate your
00031  * decision by deleting the provisions above and replace them with the notice
00032  * and other provisions required by the GPL or the LGPL. If you do not delete
00033  * the provisions above, a recipient may use your version of this file under
00034  * the terms of any one of the MPL, the GPL or the LGPL.
00035  *
00036  * ***** END LICENSE BLOCK ***** */
00037 
00038 #include <math.h>
00039 
00040 #include "nspr.h"
00041 #include "nsIPref.h"
00042 #include "nsIServiceManager.h"
00043 #include "nsCRT.h"
00044 #include "nsReadableUtils.h"
00045 
00046 #include "nsDeviceContextPh.h"
00047 #include "nsRenderingContextPh.h"
00048 #include "nsDeviceContextSpecPh.h"
00049 #include "nsHashtable.h"
00050 
00051 #include "nsPhGfxLog.h"
00052 
00053 static NS_DEFINE_CID(kPrefCID, NS_PREF_CID);
00054 
00055 #define NS_TO_PH_RGB(ns) (ns & 0xff) << 16 | (ns & 0xff00) | ((ns >> 16) & 0xff)
00056 
00057 nscoord nsDeviceContextPh::mDpi = 96;
00058 
00059 static nsHashtable* mFontLoadCache = nsnull;
00060 
00061 nsDeviceContextPh :: nsDeviceContextPh( )
00062   : DeviceContextImpl()
00063   {
00064   mTwipsToPixels = 1.0;
00065   mPixelsToTwips = 1.0;
00066   mDepth = 0 ;
00067   mSurface = NULL;
00068   mPixelScale = 1.0f;
00069   mWidthFloat = 0.0f;
00070   mHeightFloat = 0.0f;
00071 
00072   /* These *MUST* be -1 */
00073   mWidth = -1;
00074   mHeight = -1;
00075 
00076   mSpec = nsnull;
00077   mDC = nsnull;
00078        mGC = nsnull;
00079 
00080        mIsPrintingStart = 0;
00081        }
00082 
00083 nsDeviceContextPh :: ~nsDeviceContextPh( ) {
00084   nsDrawingSurfacePh *surf = (nsDrawingSurfacePh *)mSurface;
00085 
00086   NS_IF_RELEASE(surf);    //this clears the surf pointer...
00087   mSurface = nsnull;
00088 
00089        if( mGC ) PgDestroyGC( mGC ); /* we are always the owners of this gc */
00090 
00091        if( mFontLoadCache ) { 
00092 #ifdef DEBUG_Adrian
00093 printf( "\n\n\n!!!!!!!!!!!!!!!!! ~nsDeviceContextPh is unloading the mFontLoadCache!!!!!!!!!!!!!!!!!!!\n\n" );
00094 #endif
00095               delete mFontLoadCache;
00096               mFontLoadCache = nsnull;
00097               }
00098        NS_IF_RELEASE( mSpec );
00099        }
00100 
00101 NS_IMETHODIMP nsDeviceContextPh :: Init( nsNativeWidget aWidget ) {
00102     
00103   CommonInit(NULL);
00104  
00105   // Call my base class
00106   return DeviceContextImpl::Init( aWidget );
00107        }
00108 
00109 
00110 /* Called for Printing */
00111 nsresult nsDeviceContextPh :: Init( nsNativeDeviceContext aContext, nsIDeviceContext *aOrigContext ) {
00112   float origscale, newscale, t2d, a2d;
00113     
00114   mDC = aContext;
00115 
00116   CommonInit(mDC);
00117 
00118   newscale = TwipsToDevUnits();
00119   origscale = aOrigContext->AppUnitsToDevUnits();
00120   
00121   mPixelScale = newscale / origscale;
00122 
00123   t2d = aOrigContext->TwipsToDevUnits();
00124   a2d = aOrigContext->AppUnitsToDevUnits();
00125 
00126   mAppUnitsToDevUnits = (a2d / t2d) * mTwipsToPixels;
00127   mDevUnitsToAppUnits = 1.0f / mAppUnitsToDevUnits;
00128 
00129        int w, h;
00130        GetPrinterRect( &w, &h );
00131        mWidthFloat = w;
00132        mHeightFloat = h;
00133 
00134        /* Call Base Class */
00135        DeviceContextImpl::CommonInit( );
00136 
00137        return NS_OK;
00138        }
00139 
00140 void nsDeviceContextPh :: GetPrinterRect( int *width, int *height ) {
00141        PhDim_t dim;
00142        const PhDim_t *psize;
00143        const PhRect_t       *non_print;
00144        PhRect_t      rect, margins;
00145        const char *orientation = 0;
00146        int                  tmp;
00147        PpPrintContext_t *pc = ((nsDeviceContextSpecPh *)mSpec)->GetPrintContext();
00148        
00149        memset( &rect, 0, sizeof(rect));
00150        memset( &margins, 0, sizeof(margins));
00151 
00152        PpPrintGetPC(pc, Pp_PC_PAPER_SIZE, (const void **)&psize );
00153        PpPrintGetPC(pc, Pp_PC_NONPRINT_MARGINS, (const void **)&non_print );
00154        dim.w = (psize->w - ( non_print->ul.x + non_print->lr.x )) * 100 / 1000;
00155        dim.h = (psize->h - ( non_print->ul.x + non_print->lr.x )) * 100 / 1000;
00156 
00157        PpPrintGetPC(pc, Pp_PC_ORIENTATION, (const void **)&orientation );
00158 
00159        if( *orientation ) {
00160               tmp = dim.w;
00161               dim.w = dim.h;
00162               dim.h = tmp;
00163               }
00164 
00165        /* set these to 0 since we do the margins */
00166        PpPrintSetPC(pc, INITIAL_PC, 0 , Pp_PC_MARGINS, &rect ); 
00167        PpPrintSetPC(pc, INITIAL_PC, 0 , Pp_PC_SOURCE_SIZE, &dim );
00168 
00169        *width = dim.w;
00170        *height = dim.h;
00171        }
00172 
00173 
00174 void nsDeviceContextPh :: CommonInit( nsNativeDeviceContext aDC ) {
00175   PRInt32           aWidth, aHeight;
00176   static int        initialized = 0;
00177 
00178 
00179        if( !mScreenManager ) mScreenManager = do_GetService("@mozilla.org/gfx/screenmanager;1");
00180 
00181   if( !initialized ) {
00182     initialized = 1;
00183     // Set prefVal the value of the preference "layout.css.dpi"
00184     // or -1 if we can't get it.
00185     // If it's negative, we pretend it's not set.
00186     // If it's 0, it means force use of the operating system's logical resolution.
00187     // If it's positive, we use it as the logical resolution
00188     PRInt32 prefVal = -1;
00189     nsresult res;
00190 
00191     nsCOMPtr<nsIPref> prefs(do_GetService(kPrefCID, &res));
00192     if( NS_SUCCEEDED( res ) && prefs ) {
00193       res = prefs->GetIntPref("layout.css.dpi", &prefVal);
00194       if( NS_FAILED( res ) ) {
00195         prefVal = 96;
00196        }
00197 
00198       prefs->RegisterCallback( "layout.css.dpi", prefChanged, (void *)this );
00199       if( prefVal >0 ) mDpi = prefVal;
00200        }
00201        }
00202 
00203   SetDPI( mDpi );
00204 
00205        GetDisplayInfo(aWidth, aHeight, mDepth);
00206 
00207        /* Turn off virtual console support... */
00208        mWidthFloat  = (float) aWidth;
00209        mHeightFloat = (float) aHeight;
00210     
00211   /* Revisit: the scroll bar sizes is a gross guess based on Phab */
00212   mScrollbarHeight = 17;
00213   mScrollbarWidth  = 17;
00214        }
00215 
00216 NS_IMETHODIMP nsDeviceContextPh :: CreateRenderingContext( nsIRenderingContext *&aContext ) {
00217 
00218 #ifdef NS_PRINT_PREVIEW
00219        // Defer to Alt when there is one
00220        if(mAltDC && ((mUseAltDC & kUseAltDCFor_CREATERC_PAINT) || (mUseAltDC & kUseAltDCFor_CREATERC_REFLOW))) {
00221               return mAltDC->CreateRenderingContext(aContext);
00222               }
00223 #endif
00224 
00225   nsIRenderingContext *pContext;
00226   nsresult             rv;
00227   nsDrawingSurfacePh  *surf;
00228    
00229        pContext = new nsRenderingContextPh();
00230        
00231        if( nsnull != pContext ) {
00232          NS_ADDREF(pContext);
00233 
00234          surf = new nsDrawingSurfacePh();
00235          if( nsnull != surf ) {
00236                      PpPrintContext_t *pc = ((nsDeviceContextSpecPh *)mSpec)->GetPrintContext();
00237                      mGC = PgCreateGC( 0 );
00238                      rv = surf->Init( (PhDrawContext_t*)pc, mGC );
00239                      if( NS_OK == rv ) rv = pContext->Init(this, surf);
00240                      else rv = NS_ERROR_OUT_OF_MEMORY;
00241                      }
00242               }
00243        else rv = NS_ERROR_OUT_OF_MEMORY;
00244 
00245        if( NS_OK != rv ) NS_IF_RELEASE( pContext );
00246 
00247        aContext = pContext;
00248        return rv;
00249        }
00250 
00251 
00252 static char *FaceMessageFont, *FaceMenuFont, *FaceBalloonFont, *FaceGeneralFont;
00253 static int SizeMessageFont, SizeMenuFont, SizeBalloonFont, SizeGeneralFont;
00254 static short StyleMessageFont, StyleMenuFont, StyleBalloonFont, StyleGeneralFont;
00255 static short WeightMessageFont, WeightMenuFont, WeightBalloonFont, WeightGeneralFont;
00256 static int InitSystemFonts;
00257 
00258 /* load the file /usr/share/mozilla/system_fonts */
00259 int nsDeviceContextPh :: ReadSystemFonts( ) const
00260 {
00261        FILE *fp;
00262        char buffer[512];
00263 
00264        fp = fopen( "/usr/share/mozilla/system_fonts", "r" );
00265        if( !fp ) return -1;
00266 
00267        while ( fgets( buffer, 512, fp ) != NULL ) {
00268               int len, code;
00269               char *p, **face;
00270               int *size;
00271               short *style, *weight;
00272 
00273               /* skip comments and blank lines */
00274               if( buffer[0] == '#' || buffer[0] == ' ' || buffer[0] == '\n' ) continue;
00275               len = strlen( buffer );
00276               if( len<3 ) continue;
00277 
00278               if( buffer[len-1] == '\n' ) buffer[ len-1 ] = 0;
00279 
00280               code = buffer[0] << 8 | buffer[1];
00281               p = &buffer[2];
00282               switch( code ) {
00283                      case 'h=':
00284                             if( !strcmp( p, "General" ) ) {
00285                                    style = &StyleGeneralFont;
00286                                    face = &FaceGeneralFont;
00287                                    weight = &WeightGeneralFont;
00288                                    size = &SizeGeneralFont;
00289                                    }
00290                             else if( !strcmp( p, "Message" ) ) {
00291                                    style = &StyleMessageFont;
00292                                    face = &FaceMessageFont;
00293                                    weight = &WeightMessageFont;
00294                                    size = &SizeMessageFont;
00295                                    }
00296                             else if( !strcmp( p, "Menu" ) ) {
00297                                    style = &StyleMenuFont;
00298                                    face = &FaceMenuFont;
00299                                    weight = &WeightMenuFont;
00300                                    size = &SizeMenuFont;
00301                                    }
00302                             else if( !strcmp( p, "Balloon" ) ) {
00303                                    style = &StyleBalloonFont;
00304                                    face = &FaceBalloonFont;
00305                                    weight = &WeightBalloonFont;
00306                                    size = &SizeBalloonFont;
00307                                    }
00308                             break;
00309                      case 'f=':
00310                             *face = strdup( p );
00311                             break;
00312                      case 's=':
00313                             *size = atoi( p );
00314                             break;
00315                      case 'w=':
00316                             *weight = 0;
00317                             if( strstr( p, "bold" ) )
00318                                    *weight = NS_FONT_WEIGHT_BOLD;
00319                             else
00320                                    *weight = NS_FONT_WEIGHT_NORMAL;
00321                             break;
00322                      case 'S=':
00323                             *style = 0;
00324                             if( strstr( p, "italic" ) )
00325                                    *style = NS_FONT_STYLE_ITALIC;
00326                             else
00327                                    *style = NS_FONT_STYLE_NORMAL;
00328                             if( strstr( p, "antialias" ) )
00329                                    *style |= NS_FONT_STYLE_ANTIALIAS;
00330 
00331                             break;
00332                      }
00333               }
00334 
00335        fclose( fp );
00336 
00337        return 0;
00338 }
00339 
00340 void nsDeviceContextPh :: DefaultSystemFonts( ) const
00341 {
00342        FaceMessageFont = "MessageFont";
00343        SizeMessageFont = 8;
00344        StyleMessageFont = NS_FONT_STYLE_NORMAL;
00345        WeightMessageFont = NS_FONT_WEIGHT_NORMAL;
00346 
00347        FaceMenuFont = "MenuFont";
00348        SizeMenuFont = 8;
00349        StyleMenuFont = NS_FONT_STYLE_NORMAL;
00350        WeightMenuFont = NS_FONT_WEIGHT_NORMAL;
00351 
00352        FaceBalloonFont = "BalloonFont";
00353        SizeBalloonFont = 8;
00354        StyleBalloonFont = NS_FONT_STYLE_NORMAL;
00355        WeightBalloonFont = NS_FONT_WEIGHT_NORMAL;
00356 
00357        FaceGeneralFont = "TextFont";
00358        SizeGeneralFont = 8;
00359        StyleGeneralFont = NS_FONT_STYLE_NORMAL;
00360        WeightGeneralFont = NS_FONT_WEIGHT_NORMAL;
00361 }
00362 
00363 NS_IMETHODIMP nsDeviceContextPh :: GetSystemFont( nsSystemFontID aID, nsFont *aFont) const
00364 {
00365 
00366        if( !InitSystemFonts ) {
00367               InitSystemFonts = 1;
00368               DefaultSystemFonts( );
00369               ReadSystemFonts( );
00370               }
00371 
00372        aFont->decorations = NS_FONT_DECORATION_NONE;
00373 
00374   switch (aID) {
00375     case eSystemFont_Caption:      // css2
00376               case eSystemFont_Icon:
00377               case eSystemFont_SmallCaption:
00378               case eSystemFont_StatusBar:
00379               case eSystemFont_Window:       // css3
00380               case eSystemFont_Document:
00381               case eSystemFont_Workspace:
00382               case eSystemFont_Desktop:
00383               case eSystemFont_Info:
00384               case eSystemFont_Dialog:
00385               case eSystemFont_Button:
00386               case eSystemFont_PullDownMenu:
00387               case eSystemFont_List:
00388               case eSystemFont_Field:
00389               case eSystemFont_Widget:
00390               aFont->name.AssignWithConversion( FaceGeneralFont );
00391                      aFont->style = StyleGeneralFont;
00392                      aFont->weight = WeightGeneralFont;
00393                      aFont->size = SizeGeneralFont / ( mAppUnitsToDevUnits * 0.68 ); /* see nsFontMetricsPh::Init */
00394                      break;
00395               case eSystemFont_MessageBox:
00396                      aFont->name.AssignWithConversion( FaceMessageFont );
00397                      aFont->style = StyleMessageFont;
00398                      aFont->weight = WeightMessageFont;
00399                      aFont->size = SizeMessageFont / ( mAppUnitsToDevUnits * 0.68 ); /* see nsFontMetricsPh::Init */
00400                      break;
00401               case eSystemFont_Tooltips:     // moz
00402                      aFont->name.AssignWithConversion( FaceBalloonFont );
00403                      aFont->style = StyleBalloonFont;
00404                      aFont->weight = WeightBalloonFont;
00405                      aFont->size = SizeBalloonFont / ( mAppUnitsToDevUnits * 0.68 ); /* see nsFontMetricsPh::Init */
00406                      break;
00407               case eSystemFont_Menu:
00408                      aFont->name.AssignWithConversion( FaceMenuFont );
00409                      aFont->style = StyleMenuFont;
00410                      aFont->weight = WeightMenuFont;
00411                      aFont->size = SizeMenuFont / ( mAppUnitsToDevUnits * 0.68 ); /* see nsFontMetricsPh::Init */
00412                      break;
00413        }
00414 
00415   aFont->systemFont = PR_TRUE;
00416 
00417   return NS_OK;
00418 }
00419 
00420 
00421 NS_IMETHODIMP nsDeviceContextPh :: CheckFontExistence( const nsString& aFontName ) {
00422   char *fontName = ToNewCString(aFontName);
00423 
00424   if( fontName ) {
00425 
00426 #ifdef DEBUG_Adrian
00427 printf( "\tCheckFontExistence for fontName=%s\n", fontName );
00428 #endif
00429 
00430               nsCStringKey key( fontName );
00431               if( !mFontLoadCache ) mFontLoadCache = new nsHashtable();
00432               else {
00433                      int value = ( int ) mFontLoadCache->Get( &key );
00434                      if( value == 1 ) { /* the font exists and you already asked this before */
00435                             delete [] fontName;
00436 #ifdef DEBUG_Adrian
00437 printf( "\t\tFound it in cache it exists\n" );
00438 #endif
00439                             return NS_OK;
00440                             }
00441                      else if( value == 2 ) { /* the font doesn't exist and you already asked this before */
00442                             delete [] fontName;
00443 #ifdef DEBUG_Adrian
00444 printf( "\t\tFound it in cache it doesnt exist\n" );
00445 #endif
00446                             return NS_ERROR_FAILURE;
00447                             }
00448                      /* else you didn't ask this before */
00449 #ifdef DEBUG_Adrian
00450 printf( "\t\t Not Found in cache\n" );
00451 #endif
00452                      }
00453 
00454               /* here either the mFontLoadCache was not allocated ( first time ) or this is the first time you ask about it */
00455               
00456        nsresult res;
00457               if( PfFindFont( (char *)fontName, 0, 0 ) ) {
00458                      mFontLoadCache->Put( &key, (void*)1 );
00459                      res = NS_OK;
00460                      }
00461               else {
00462                      mFontLoadCache->Put( &key, (void*)2 );
00463                      res = NS_ERROR_FAILURE;
00464                      }
00465               delete [] fontName;
00466               return res;
00467               }
00468 
00469        return NS_ERROR_FAILURE;
00470        }
00471 
00472 
00473 NS_IMETHODIMP nsDeviceContextPh :: GetDeviceSurfaceDimensions( PRInt32 &aWidth, PRInt32 &aHeight ) {
00474 
00475 #ifdef NS_PRINT_PREVIEW
00476        // Defer to Alt when there is one
00477        if (mAltDC && (mUseAltDC & kUseAltDCFor_SURFACE_DIM)) {
00478               return mAltDC->GetDeviceSurfaceDimensions(aWidth, aHeight);
00479               }
00480 #endif
00481 
00482   if( mWidth == -1 ) mWidth = NSToIntRound(mWidthFloat * mDevUnitsToAppUnits);
00483   if( mHeight == -1 ) mHeight = NSToIntRound(mHeightFloat * mDevUnitsToAppUnits);
00484 
00485   aWidth = mWidth;
00486   aHeight = mHeight;
00487 
00488   return NS_OK;
00489        }
00490 
00491 NS_IMETHODIMP nsDeviceContextPh::GetRect( nsRect &aRect ) {
00492        if( mScreenManager ) {
00493     nsCOMPtr<nsIScreen> screen;
00494     mScreenManager->GetPrimaryScreen( getter_AddRefs( screen ) );
00495     screen->GetRect(&aRect.x, &aRect.y, &aRect.width, &aRect.height);
00496     aRect.x = NSToIntRound(mDevUnitsToAppUnits * aRect.x);
00497     aRect.y = NSToIntRound(mDevUnitsToAppUnits * aRect.y);
00498     aRect.width = NSToIntRound(mDevUnitsToAppUnits * aRect.width);
00499     aRect.height = NSToIntRound(mDevUnitsToAppUnits * aRect.height);
00500               }
00501        else {
00502        PRInt32 width, height;
00503        GetDeviceSurfaceDimensions( width, height );
00504        aRect.x = 0;
00505        aRect.y = 0;
00506        aRect.width = width;
00507        aRect.height = height;
00508               }
00509   return NS_OK;
00510        }
00511 
00512 NS_IMETHODIMP nsDeviceContextPh :: GetDeviceContextFor( nsIDeviceContextSpec *aDevice, nsIDeviceContext *&aContext ) {
00513        nsDeviceContextPh* devConPh = new nsDeviceContextPh(); //ref count 0
00514        if (devConPh != nsnull) {
00515               // this will ref count it
00516        nsresult rv = devConPh->QueryInterface(NS_GET_IID(nsIDeviceContext), (void**)&aContext);
00517               NS_ASSERTION(NS_SUCCEEDED(rv), "This has to support nsIDeviceContext");
00518        } else {
00519            return NS_ERROR_OUT_OF_MEMORY;
00520        }
00521 
00522        devConPh->mSpec = aDevice;
00523        NS_ADDREF(aDevice);
00524        return devConPh->Init(NULL, this);
00525        }
00526 
00527 nsresult nsDeviceContextPh::SetDPI( PRInt32 aDpi ) {
00528   const int pt2t = 82;//72
00529 
00530   mDpi = aDpi;
00531 
00532   // make p2t a nice round number - this prevents rounding problems
00533   mPixelsToTwips = float(NSToIntRound(float(NSIntPointsToTwips(pt2t)) / float(aDpi)));
00534   mTwipsToPixels = 1.0f / mPixelsToTwips;
00535   // XXX need to reflow all documents
00536   return NS_OK;
00537        }
00538 
00539 int nsDeviceContextPh::prefChanged( const char *aPref, void *aClosure ) {
00540   nsDeviceContextPh *context = (nsDeviceContextPh*)aClosure;
00541   nsresult rv;
00542 
00543   if( nsCRT::strcmp(aPref, "layout.css.dpi")==0 )  {
00544     PRInt32 dpi;
00545     nsCOMPtr<nsIPref> prefs(do_GetService(kPrefCID, &rv));
00546     rv = prefs->GetIntPref(aPref, &dpi);
00547     if( NS_SUCCEEDED( rv ) ) context->SetDPI( dpi ); 
00548               }
00549   return 0;
00550        }
00551 
00552 NS_IMETHODIMP nsDeviceContextPh :: BeginDocument(PRUnichar *t, PRUnichar* aPrintToFileName, PRInt32 aStartPage, PRInt32 aEndPage) {
00553        if( mSpec ) {
00554               PpPrintContext_t *pc = ((nsDeviceContextSpecPh *)mSpec)->GetPrintContext();
00555               PpStartJob(pc);
00556               mIsPrintingStart = 1;
00557               }
00558        return NS_OK;
00559        }
00560 
00561 NS_IMETHODIMP nsDeviceContextPh :: EndDocument( void ) {
00562        if( mSpec ) {
00563        PpPrintContext_t *pc = ((nsDeviceContextSpecPh *)mSpec)->GetPrintContext();
00564        PpEndJob(pc);
00565               }
00566   return NS_OK;
00567        }
00568 
00569 NS_IMETHODIMP nsDeviceContextPh :: AbortDocument( void ) {
00570   return EndDocument();
00571        }
00572 
00573 NS_IMETHODIMP nsDeviceContextPh :: BeginPage( void ) {
00574        if( mSpec ) {
00575               PpPrintContext_t *pc = ((nsDeviceContextSpecPh *)mSpec)->GetPrintContext();
00576               PpContinueJob( pc );
00577               if( !mIsPrintingStart ) PpPrintNewPage( pc );
00578               mIsPrintingStart = 0;
00579               }
00580        return NS_OK;
00581        }
00582 
00583 NS_IMETHODIMP nsDeviceContextPh :: EndPage( void ) {
00584        if( mSpec ) {
00585               PpPrintContext_t *pc = ((nsDeviceContextSpecPh *)mSpec)->GetPrintContext();
00586               PpSuspendJob(pc);
00587               }
00588        return NS_OK;
00589        }
00590 
00591 /*
00592  Get the size and color depth of the display
00593  */
00594 nsresult nsDeviceContextPh :: GetDisplayInfo( PRInt32 &aWidth, PRInt32 &aHeight, PRUint32 &aDepth ) {
00595   nsresult                         res = NS_ERROR_FAILURE;
00596   PhSysInfo_t       SysInfo;
00597   PhRect_t          rect;
00598   char              *p = NULL;
00599   int               inp_grp;
00600   PhRid_t           rid;
00601 
00602   /* Initialize variables */
00603   aWidth  = 0;
00604   aHeight = 0;
00605   aDepth  = 0;
00606   
00607        /* Get the Screen Size and Depth*/
00608        p = getenv("PHIG");
00609        if( p ) inp_grp = atoi( p );
00610        else inp_grp = 1;
00611 
00612        PhQueryRids( 0, 0, inp_grp, Ph_GRAFX_REGION, 0, 0, 0, &rid, 1 );
00613        PhWindowQueryVisible( Ph_QUERY_IG_POINTER, 0, inp_grp, &rect );
00614        aWidth  = rect.lr.x - rect.ul.x + 1;
00615        aHeight = rect.lr.y - rect.ul.y + 1;  
00616 
00617        /* Get the System Info for the RID */
00618        if( PhQuerySystemInfo( rid, NULL, &SysInfo ) ) {
00619               /* Make sure the "color_bits" field is valid */
00620               if( SysInfo.gfx.valid_fields & Ph_GFX_COLOR_BITS ) {
00621                      aDepth = SysInfo.gfx.color_bits;
00622                      res = NS_OK;
00623                      }
00624               }
00625   return res;
00626        }