CreateStyleSet(mDocument,&mPrintSS);
CreateStyleSet(printDoc,&mPrintSS);
DocumentViewerImpl::Print(PRBool aSilent,FILE *aFile, nsIPrintListener *aPrintListener){nsCOMPtr<nsIWebShell>                 webContainer;nsCOMPtr<nsIDeviceContextSpecFactory> factory;PRInt32                               width,height;  nsComponentManager::CreateInstance(kDeviceContextSpecFactoryCID,                                      nsnull,                                     NS_GET_IID(nsIDeviceContextSpecFactory),                                     (void **)getter_AddRefs(factory));  if (factory) {#ifdef DEBUG_dcone    printf("PRINT JOB STARTING\n");#endif    nsIDeviceContextSpec *devspec = nsnull;    nsCOMPtr<nsIDeviceContext> dx;    mPrintDC = nsnull;    mFilePointer = aFile;    factory->CreateDeviceContextSpec(nsnull, devspec, aSilent);    if (nsnull != devspec) {      mPresContext->GetDeviceContext(getter_AddRefs(dx));      nsresult rv = dx->GetDeviceContextFor(devspec, mPrintDC);       if (NS_SUCCEEDED(rv)) {        NS_RELEASE(devspec);        // Get the webshell for this documentviewer        webContainer = do_QueryInterface(mContainer);        if(webContainer) {          // load the document and do the initial reflow on the entire document          nsCOMPtr<nsIPrintContext> printcon;          rv = NS_NewPrintContext(getter_AddRefs(printcon));          if (NS_FAILED(rv)) {            return rv;          } else {            rv = printcon->QueryInterface(NS_GET_IID(nsIPresContext), (void**)&mPrintPC);            if (NS_FAILED(rv)) {              return rv;            }          }                    mPrintDC->GetDeviceSurfaceDimensions(width,height);          mPrintPC->Init(mPrintDC);          mPrintPC->SetContainer(webContainer);          CreateStyleSet(mDocument,&mPrintSS);          rv = NS_NewPresShell(&mPrintPS);          if(NS_FAILED(rv)){            return rv;          }                    rv = nsComponentManager::CreateInstance(kViewManagerCID, nsnull, NS_GET_IID(nsIViewManager),(void**)&mPrintVM);          if(NS_FAILED(rv)) {            return rv;          }          rv = mPrintVM->Init(mPrintDC);          if(NS_FAILED(rv)) {            return rv;          }          rv = nsComponentManager::CreateInstance(kViewCID, nsnull, NS_GET_IID(nsIView),(void**)&mPrintView);          if(NS_FAILED(rv)) {            return rv;          }                    nsRect  tbounds = nsRect(0,0,width,height);          rv = mPrintView->Init(mPrintVM,tbounds,nsnull);          if(NS_FAILED(rv)) {            return rv;          }          // setup hierarchical relationship in view manager          mPrintVM->SetRootView(mPrintView);          mPrintPS->Init(mDocument,mPrintPC,mPrintVM,mPrintSS);          nsCOMPtr<nsIImageGroup> imageGroup;          mPrintPC->GetImageGroup(getter_AddRefs(imageGroup));          if (imageGroup) {            imageGroup->AddObserver(this);          }          mPrintPS->InitialReflow(width,height);#ifdef DEBUG_dcone          float   a1,a2;          PRInt32 i1,i2;          printf("CRITICAL PRINTING INFORMATION\n");          printf("PRESSHELL(%x)  PRESCONTEXT(%x)\nVIEWMANAGER(%x) VIEW(%x)\n",              mPrintPS, mPrintPC,mPrintDC,mPrintVM,mPrintView);                    // DEVICE CONTEXT INFORMATION from PresContext          printf("DeviceContext of Presentation Context(%x)\n",dx);          dx->GetDevUnitsToTwips(a1);          dx->GetTwipsToDevUnits(a2);          printf("    DevToTwips = %f TwipToDev = %f\n",a1,a2);          dx->GetAppUnitsToDevUnits(a1);          dx->GetDevUnitsToAppUnits(a2);          printf("    AppUnitsToDev = %f DevUnitsToApp = %f\n",a1,a2);          dx->GetCanonicalPixelScale(a1);          printf("    GetCanonicalPixelScale = %f\n",a1);          dx->GetScrollBarDimensions(a1, a2);          printf("    ScrollBar x = %f y = %f\n",a1,a2);          dx->GetZoom(a1);          printf("    Zoom = %f\n",a1);          dx->GetDepth((PRUint32&)i1);          printf("    Depth = %d\n",i1);          dx->GetDeviceSurfaceDimensions(i1,i2);          printf("    DeviceDimension w = %d h = %d\n",i1,i2);          // DEVICE CONTEXT INFORMATION          printf("DeviceContext created for print(%x)\n",mPrintDC);          mPrintDC->GetDevUnitsToTwips(a1);          mPrintDC->GetTwipsToDevUnits(a2);          printf("    DevToTwips = %f TwipToDev = %f\n",a1,a2);          mPrintDC->GetAppUnitsToDevUnits(a1);          mPrintDC->GetDevUnitsToAppUnits(a2);          printf("    AppUnitsToDev = %f DevUnitsToApp = %f\n",a1,a2);          mPrintDC->GetCanonicalPixelScale(a1);          printf("    GetCanonicalPixelScale = %f\n",a1);          mPrintDC->GetScrollBarDimensions(a1, a2);          printf("    ScrollBar x = %f y = %f\n",a1,a2);          mPrintDC->GetZoom(a1);          printf("    Zoom = %f\n",a1);          mPrintDC->GetDepth((PRUint32&)i1);          printf("    Depth = %d\n",i1);          mPrintDC->GetDeviceSurfaceDimensions(i1,i2);          printf("    DeviceDimension w = %d h = %d\n",i1,i2);#endif          // Print listener setup...          if (aPrintListener)          {            mPrintListener = aPrintListener;            mPrintListener->OnStartPrinting();              /* RICHIE mPrintListener->OnProgressPrinting(PRUint32 aProgress, PRUint32 aProgressMax); */          }          //          // The mIsPrinting flag is set when the ImageGroup observer is          // notified that images must be loaded as a result of the           // InitialReflow...          //          if(!mIsPrinting){            DocumentReadyForPrinting();#ifdef DEBUG_dcone            printf("PRINT JOB ENDING, OBSERVER WAS NOT CALLED\n");#endif          } else {            // use the observer mechanism to finish the printing#ifdef DEBUG_dcone            printf("PRINTING OBSERVER STARTED\n");#endif          }        }      }          }    else    {      return NS_ERROR_FAILURE;    }  }  return NS_OK;}