nsresult rv; nsCOMPtr<nsIPrintOptions> printService = do_GetService(kPrintOptionsCID, &rv);   aActualRect->width  = (nscoord) NS_INCHES_TO_TWIPS(8.5); aActualRect->height = (nscoord) NS_INCHES_TO_TWIPS(11); if (NS_SUCCEEDED(rv) && printService) { PRInt32 paperSize = nsIPrintOptions::kLetterPaperSize; printService->GetPaperSize(&paperSize); switch (paperSize) { case nsIPrintOptions::kLegalPaperSize : aActualRect->width  = (nscoord) NS_INCHES_TO_TWIPS(8.5); aActualRect->height = (nscoord) NS_INCHES_TO_TWIPS(14); break;  case nsIPrintOptions::kExecutivePaperSize : aActualRect->width  = (nscoord) NS_INCHES_TO_TWIPS(7.5); aActualRect->height = (nscoord) NS_INCHES_TO_TWIPS(10.5); break;  case nsIPrintOptions::kA3PaperSize : aActualRect->width  = (nscoord) NS_MILLIMETERS_TO_TWIPS(297); aActualRect->height = (nscoord) NS_MILLIMETERS_TO_TWIPS(420); break;  case nsIPrintOptions::kA4PaperSize : aActualRect->width  = (nscoord) NS_MILLIMETERS_TO_TWIPS(210); aActualRect->height = (nscoord) NS_MILLIMETERS_TO_TWIPS(297); break;  } PRInt32 orientation = nsIPrintOptions::kPortraitOrientation; printService->GetOrientation(&orientation); if (orientation == nsIPrintOptions::kLandscapeOrientation) {  nscoord temp; temp = aActualRect->width; aActualRect->width = aActualRect->height; aActualRect->height = temp; }
PRInt32 width,height; if (NS_SUCCEEDED(mDeviceContext->GetDeviceSurfaceDimensions(width, height))) { aActualRect->SetRect(0, 0, width, height);
PrintPreviewContext::GetPageDim(nsRect* aActualRect, nsRect* aAdjRect){  NS_ENSURE_ARG_POINTER(aActualRect);  NS_ENSURE_ARG_POINTER(aAdjRect);  // XXX maybe we get the size of the default printer instead  nsresult rv;  nsCOMPtr<nsIPrintOptions> printService =            do_GetService(kPrintOptionsCID, &rv);  // Setting what would be the "default" case here, because  // getting the PrintService could fail  aActualRect->width  = (nscoord) NS_INCHES_TO_TWIPS(8.5);  aActualRect->height = (nscoord) NS_INCHES_TO_TWIPS(11);  if (NS_SUCCEEDED(rv) && printService) {    PRInt32 paperSize = nsIPrintOptions::kLetterPaperSize;     printService->GetPaperSize(&paperSize);    switch (paperSize) {      case nsIPrintOptions::kLegalPaperSize :        aActualRect->width  = (nscoord) NS_INCHES_TO_TWIPS(8.5);        aActualRect->height = (nscoord) NS_INCHES_TO_TWIPS(14);        break;      case nsIPrintOptions::kExecutivePaperSize :        aActualRect->width  = (nscoord) NS_INCHES_TO_TWIPS(7.5);        aActualRect->height = (nscoord) NS_INCHES_TO_TWIPS(10.5);        break;      case nsIPrintOptions::kA3PaperSize :        aActualRect->width  = (nscoord) NS_MILLIMETERS_TO_TWIPS(297);        aActualRect->height = (nscoord) NS_MILLIMETERS_TO_TWIPS(420);        break;      case nsIPrintOptions::kA4PaperSize :        aActualRect->width  = (nscoord) NS_MILLIMETERS_TO_TWIPS(210);        aActualRect->height = (nscoord) NS_MILLIMETERS_TO_TWIPS(297);        break;    } // switch     PRInt32 orientation = nsIPrintOptions::kPortraitOrientation;    printService->GetOrientation(&orientation);    if (orientation == nsIPrintOptions::kLandscapeOrientation) {      // swap      nscoord temp;      temp = aActualRect->width;      aActualRect->width = aActualRect->height;      aActualRect->height = temp;    }  }#ifdef NS_DEBUG  if (UseFakePageSize()) {    // For testing purposes make the page width smaller than the visible area    float sbWidth, sbHeight;    mDeviceContext->GetScrollBarDimensions(sbWidth, sbHeight);    nscoord sbar = NSToCoordRound(sbWidth);    aActualRect->width  = mVisibleArea.width - sbar - 2*100;    aActualRect->height = mVisibleArea.height * 60 / 100;  }#endif  *aAdjRect = mPageDim;  return NS_OK;}