void nsPrintSettingsGTK::InitUnwriteableMargin() { mUnwriteableMargin.SizeTo( NS_INCHES_TO_TWIPS(gtk_page_setup_get_left_margin(mPageSetup, GTK_UNIT_INCH)), NS_INCHES_TO_TWIPS(gtk_page_setup_get_top_margin(mPageSetup, GTK_UNIT_INCH)), NS_INCHES_TO_TWIPS(gtk_page_setup_get_right_margin(mPageSetup, GTK_UNIT_INCH)), NS_INCHES_TO_TWIPS(gtk_page_setup_get_bottom_margin(mPageSetup, GTK_UNIT_INCH)) ); }
//---------------------------------------------------------------------------------- // Map an incoming size to a Windows Native enum in the DevMode static void MapPaperSizeToNativeEnum(LPDEVMODEW aDevMode, int16_t aType, double aW, double aH) { #ifdef DEBUG_rods BOOL doingOrientation = aDevMode->dmFields & DM_ORIENTATION; BOOL doingPaperSize = aDevMode->dmFields & DM_PAPERSIZE; BOOL doingPaperLength = aDevMode->dmFields & DM_PAPERLENGTH; BOOL doingPaperWidth = aDevMode->dmFields & DM_PAPERWIDTH; #endif const double kThreshold = 0.05; for (int32_t i=0;i<kNumPaperSizes;i++) { double width = kPaperSizes[i].mWidth; double height = kPaperSizes[i].mHeight; if (aW < width+kThreshold && aW > width-kThreshold && aH < height+kThreshold && aH > height-kThreshold) { aDevMode->dmPaperSize = kPaperSizes[i].mPaperSize; aDevMode->dmFields &= ~DM_PAPERLENGTH; aDevMode->dmFields &= ~DM_PAPERWIDTH; aDevMode->dmFields |= DM_PAPERSIZE; return; } } short width = 0; short height = 0; if (aType == nsIPrintSettings::kPaperSizeInches) { width = short(NS_TWIPS_TO_MILLIMETERS(NS_INCHES_TO_TWIPS(float(aW))) / 10); height = short(NS_TWIPS_TO_MILLIMETERS(NS_INCHES_TO_TWIPS(float(aH))) / 10); } else if (aType == nsIPrintSettings::kPaperSizeMillimeters) { width = short(aW / 10.0); height = short(aH / 10.0); } else { return; // don't set anything } // width and height is in aDevMode->dmPaperSize = 0; aDevMode->dmPaperWidth = width; aDevMode->dmPaperLength = height; aDevMode->dmFields |= DM_PAPERSIZE; aDevMode->dmFields |= DM_PAPERLENGTH; aDevMode->dmFields |= DM_PAPERWIDTH; }
NS_IMETHODIMP nsPrintSettings::SetUnwriteableMarginBottom(double aUnwriteableMarginBottom) { if (aUnwriteableMarginBottom >= 0.0) { mUnwriteableMargin.bottom = NS_INCHES_TO_TWIPS(aUnwriteableMarginBottom); } return NS_OK; }
NS_IMETHODIMP nsPrintSettings::SetUnwriteableMarginRight(double aUnwriteableMarginRight) { if (aUnwriteableMarginRight >= 0.0) { mUnwriteableMargin.right = NS_INCHES_TO_TWIPS(aUnwriteableMarginRight); } return NS_OK; }
NS_IMETHODIMP nsPrintSettingsGTK::GetEffectivePageSize(double *aWidth, double *aHeight) { *aWidth = NS_INCHES_TO_TWIPS(gtk_paper_size_get_width(mPaperSize, GTK_UNIT_INCH)); *aHeight = NS_INCHES_TO_TWIPS(gtk_paper_size_get_height(mPaperSize, GTK_UNIT_INCH)); GtkPageOrientation gtkOrient = gtk_page_setup_get_orientation(mPageSetup); if (gtkOrient == GTK_PAGE_ORIENTATION_LANDSCAPE || gtkOrient == GTK_PAGE_ORIENTATION_REVERSE_LANDSCAPE) { double temp = *aWidth; *aWidth = *aHeight; *aHeight = temp; } return NS_OK; }
NS_IMETHODIMP nsPrintSettings::SetUnwriteableMarginTop(double aUnwriteableMarginTop) { if (aUnwriteableMarginTop >= 0.0) { mUnwriteableMargin.top = NS_INCHES_TO_TWIPS(aUnwriteableMarginTop); } return NS_OK; }
void nsPrintOptions::ReadInchesToTwipsPref(const char * aPrefId, PRInt32& aTwips, const char * aMarginPref) { if (!mPrefBranch) { return; } char * str = nsnull; nsresult rv = mPrefBranch->GetCharPref(aPrefId, &str); if (NS_FAILED(rv) || !str) rv = mPrefBranch->GetCharPref(aMarginPref, &str); if (NS_SUCCEEDED(rv) && str) { nsAutoString justStr; justStr.AssignWithConversion(str); PRInt32 errCode; float inches = justStr.ToFloat(&errCode); if (NS_SUCCEEDED(errCode)) { aTwips = NS_INCHES_TO_TWIPS(inches); } else { aTwips = 0; } nsMemory::Free(str); } }
/** --------------------------------------------------- * See documentation in nsPrintOptionsImpl.h */ NS_IMETHODIMP nsPrintSettings::GetEffectivePageSize(double *aWidth, double *aHeight) { if (mPaperSizeUnit == kPaperSizeInches) { *aWidth = NS_INCHES_TO_TWIPS(float(mPaperWidth)); *aHeight = NS_INCHES_TO_TWIPS(float(mPaperHeight)); } else { *aWidth = NS_MILLIMETERS_TO_TWIPS(float(mPaperWidth)); *aHeight = NS_MILLIMETERS_TO_TWIPS(float(mPaperHeight)); } if (kLandscapeOrientation == mOrientation) { double temp = *aWidth; *aWidth = *aHeight; *aHeight = temp; } return NS_OK; }
/** --------------------------------------------------- * See documentation in nsPrintSettingsImpl.h * @update 6/21/00 dwc */ nsPrintSettings::nsPrintSettings() : mPrintOptions(0L), mPrintRange(kRangeAllPages), mStartPageNum(1), mEndPageNum(1), mScaling(1.0), mPrintBGColors(PR_FALSE), mPrintBGImages(PR_FALSE), mPrintFrameTypeUsage(kUseInternalDefault), mPrintFrameType(kFramesAsIs), mHowToEnableFrameUI(kFrameEnableNone), mIsCancelled(PR_FALSE), mPrintSilent(PR_FALSE), mPrintPreview(PR_FALSE), mShrinkToFit(PR_TRUE), mShowPrintProgress(PR_TRUE), mPrintPageDelay(500), mPaperData(0), mPaperSizeType(kPaperSizeDefined), mPaperWidth(8.5), mPaperHeight(11.0), mPaperSizeUnit(kPaperSizeInches), mPrintReversed(PR_FALSE), mPrintInColor(PR_TRUE), mOrientation(kPortraitOrientation), mDownloadFonts(PR_FALSE), mNumCopies(1), mPrintToFile(PR_FALSE), mOutputFormat(kOutputFormatNative), mIsInitedFromPrinter(PR_FALSE), mIsInitedFromPrefs(PR_FALSE) { /* member initializers and constructor code */ PRInt32 marginWidth = NS_INCHES_TO_TWIPS(DEFAULT_MARGIN_WIDTH); mMargin.SizeTo(marginWidth, marginWidth, marginWidth, marginWidth); mEdge.SizeTo(0, 0, 0, 0); mUnwriteableMargin.SizeTo(0,0,0,0); mPrintOptions = kPrintOddPages | kPrintEvenPages; mHeaderStrs[0].AssignLiteral("&T"); mHeaderStrs[2].AssignLiteral("&U"); mFooterStrs[0].AssignLiteral("&PT"); // Use &P (Page Num Only) or &PT (Page Num of Page Total) mFooterStrs[2].AssignLiteral("&D"); }
void nsPrintOptions::ReadInchesIntToTwipsPref(const char * aPrefId, PRInt32& aTwips, const char * aMarginPref) { if (!mPrefBranch) { return; } PRInt32 value; nsresult rv = mPrefBranch->GetIntPref(aPrefId, &value); if (NS_FAILED(rv)) { rv = mPrefBranch->GetIntPref(aMarginPref, &value); } if (NS_SUCCEEDED(rv)) { aTwips = NS_INCHES_TO_TWIPS(float(value)/100.0f); } else { aTwips = 0; } }
nsSimplePageSequenceFrame::nsSimplePageSequenceFrame(nsStyleContext* aContext) : nsContainerFrame(aContext), mTotalPages(-1), mSelectionHeight(-1), mYSelOffset(0) { nscoord halfInch = PresContext()->CSSTwipsToAppUnits(NS_INCHES_TO_TWIPS(0.5)); mMargin.SizeTo(halfInch, halfInch, halfInch, halfInch); // XXX Unsafe to assume successful allocation mPageData = new nsSharedPageData(); mPageData->mHeadFootFont = new nsFont(*PresContext()->GetDefaultFont(kGenericFont_serif)); mPageData->mHeadFootFont->size = nsPresContext::CSSPointsToAppUnits(10); nsresult rv; mPageData->mPrintOptions = do_GetService(sPrintOptionsContractID, &rv); // Doing this here so we only have to go get these formats once SetPageNumberFormat("pagenumber", "%1$d", PR_TRUE); SetPageNumberFormat("pageofpages", "%1$d of %2$d", PR_FALSE); }
NS_IMETHODIMP nsPrintSettings::SetEdgeRight(double aEdgeRight) { mEdge.right = NS_INCHES_TO_TWIPS(float(aEdgeRight)); return NS_OK; }
/** * This will either read in the generic prefs (not specific to a printer) * or read the prefs in using the printer name to qualify. * It is either "print.attr_name" or "print.printer_HPLasr5.attr_name" */ nsresult nsPrintOptions::ReadPrefs(nsIPrintSettings* aPS, const nsAString& aPrinterName, PRUint32 aFlags) { NS_ENSURE_STATE(mPrefBranch); NS_ENSURE_ARG_POINTER(aPS); if (aFlags & nsIPrintSettings::kInitSaveMargins) { PRInt32 halfInch = NS_INCHES_TO_TWIPS(0.5); nsIntMargin margin(halfInch, halfInch, halfInch, halfInch); ReadInchesToTwipsPref(GetPrefName(kMarginTop, aPrinterName), margin.top, kMarginTop); DUMP_INT(kReadStr, kMarginTop, margin.top); ReadInchesToTwipsPref(GetPrefName(kMarginLeft, aPrinterName), margin.left, kMarginLeft); DUMP_INT(kReadStr, kMarginLeft, margin.left); ReadInchesToTwipsPref(GetPrefName(kMarginBottom, aPrinterName), margin.bottom, kMarginBottom); DUMP_INT(kReadStr, kMarginBottom, margin.bottom); ReadInchesToTwipsPref(GetPrefName(kMarginRight, aPrinterName), margin.right, kMarginRight); DUMP_INT(kReadStr, kMarginRight, margin.right); aPS->SetMarginInTwips(margin); } if (aFlags & nsIPrintSettings::kInitSaveEdges) { nsIntMargin margin(0,0,0,0); ReadInchesIntToTwipsPref(GetPrefName(kEdgeTop, aPrinterName), margin.top, kEdgeTop); DUMP_INT(kReadStr, kEdgeTop, margin.top); ReadInchesIntToTwipsPref(GetPrefName(kEdgeLeft, aPrinterName), margin.left, kEdgeLeft); DUMP_INT(kReadStr, kEdgeLeft, margin.left); ReadInchesIntToTwipsPref(GetPrefName(kEdgeBottom, aPrinterName), margin.bottom, kEdgeBottom); DUMP_INT(kReadStr, kEdgeBottom, margin.bottom); ReadInchesIntToTwipsPref(GetPrefName(kEdgeRight, aPrinterName), margin.right, kEdgeRight); DUMP_INT(kReadStr, kEdgeRight, margin.right); aPS->SetEdgeInTwips(margin); } if (aFlags & nsIPrintSettings::kInitSaveUnwriteableMargins) { nsIntMargin margin; ReadInchesIntToTwipsPref(GetPrefName(kUnwriteableMarginTop, aPrinterName), margin.top, kUnwriteableMarginTop); DUMP_INT(kReadStr, kUnwriteableMarginTop, margin.top); ReadInchesIntToTwipsPref(GetPrefName(kUnwriteableMarginLeft, aPrinterName), margin.left, kUnwriteableMarginLeft); DUMP_INT(kReadStr, kUnwriteableMarginLeft, margin.left); ReadInchesIntToTwipsPref(GetPrefName(kUnwriteableMarginBottom, aPrinterName), margin.bottom, kUnwriteableMarginBottom); DUMP_INT(kReadStr, kUnwriteableMarginBottom, margin.bottom); ReadInchesIntToTwipsPref(GetPrefName(kUnwriteableMarginRight, aPrinterName), margin.right, kUnwriteableMarginRight); DUMP_INT(kReadStr, kUnwriteableMarginRight, margin.right); aPS->SetUnwriteableMarginInTwips(margin); } PRBool b; nsAutoString str; PRInt32 iVal; double dbl; #define GETBOOLPREF(_prefname, _retval) \ NS_SUCCEEDED( \ mPrefBranch->GetBoolPref( \ GetPrefName(_prefname, aPrinterName), _retval \ ) \ ) #define GETSTRPREF(_prefname, _retval) \ NS_SUCCEEDED( \ ReadPrefString( \ GetPrefName(_prefname, aPrinterName), _retval \ ) \ ) #define GETINTPREF(_prefname, _retval) \ NS_SUCCEEDED( \ mPrefBranch->GetIntPref( \ GetPrefName(_prefname, aPrinterName), _retval \ ) \ ) #define GETDBLPREF(_prefname, _retval) \ NS_SUCCEEDED( \ ReadPrefDouble( \ GetPrefName(_prefname, aPrinterName), _retval \ ) \ ) // Paper size prefs are read as a group if (aFlags & nsIPrintSettings::kInitSavePaperSize) { PRInt32 sizeUnit, sizeType; double width, height; PRBool success = GETINTPREF(kPrintPaperSizeUnit, &sizeUnit) && GETINTPREF(kPrintPaperSizeType, &sizeType) && GETDBLPREF(kPrintPaperWidth, width) && GETDBLPREF(kPrintPaperHeight, height) && GETSTRPREF(kPrintPaperName, str); // Bug 315687: Sanity check paper size to avoid paper size values in // mm when the size unit flag is inches. The value 100 is arbitrary // and can be changed. if (success) { success = (sizeUnit != nsIPrintSettings::kPaperSizeInches) || (width < 100.0) || (height < 100.0); } if (success) { aPS->SetPaperSizeUnit(sizeUnit); DUMP_INT(kReadStr, kPrintPaperSizeUnit, sizeUnit); aPS->SetPaperSizeType(sizeType); DUMP_INT(kReadStr, kPrintPaperSizeType, sizeType); aPS->SetPaperWidth(width); DUMP_DBL(kReadStr, kPrintPaperWidth, width); aPS->SetPaperHeight(height); DUMP_DBL(kReadStr, kPrintPaperHeight, height); aPS->SetPaperName(str.get()); DUMP_STR(kReadStr, kPrintPaperName, str.get()); } } if (aFlags & nsIPrintSettings::kInitSaveOddEvenPages) { if (GETBOOLPREF(kPrintEvenPages, &b)) { aPS->SetPrintOptions(nsIPrintSettings::kPrintEvenPages, b); DUMP_BOOL(kReadStr, kPrintEvenPages, b); } } if (aFlags & nsIPrintSettings::kInitSaveOddEvenPages) { if (GETBOOLPREF(kPrintOddPages, &b)) { aPS->SetPrintOptions(nsIPrintSettings::kPrintOddPages, b); DUMP_BOOL(kReadStr, kPrintOddPages, b); } } if (aFlags & nsIPrintSettings::kInitSaveHeaderLeft) { if (GETSTRPREF(kPrintHeaderStrLeft, str)) { aPS->SetHeaderStrLeft(str.get()); DUMP_STR(kReadStr, kPrintHeaderStrLeft, str.get()); } } if (aFlags & nsIPrintSettings::kInitSaveHeaderCenter) { if (GETSTRPREF(kPrintHeaderStrCenter, str)) { aPS->SetHeaderStrCenter(str.get()); DUMP_STR(kReadStr, kPrintHeaderStrCenter, str.get()); } } if (aFlags & nsIPrintSettings::kInitSaveHeaderRight) { if (GETSTRPREF(kPrintHeaderStrRight, str)) { aPS->SetHeaderStrRight(str.get()); DUMP_STR(kReadStr, kPrintHeaderStrRight, str.get()); } } if (aFlags & nsIPrintSettings::kInitSaveFooterLeft) { if (GETSTRPREF(kPrintFooterStrLeft, str)) { aPS->SetFooterStrLeft(str.get()); DUMP_STR(kReadStr, kPrintFooterStrLeft, str.get()); } } if (aFlags & nsIPrintSettings::kInitSaveFooterCenter) { if (GETSTRPREF(kPrintFooterStrCenter, str)) { aPS->SetFooterStrCenter(str.get()); DUMP_STR(kReadStr, kPrintFooterStrCenter, str.get()); } } if (aFlags & nsIPrintSettings::kInitSaveFooterRight) { if (GETSTRPREF(kPrintFooterStrRight, str)) { aPS->SetFooterStrRight(str.get()); DUMP_STR(kReadStr, kPrintFooterStrRight, str.get()); } } if (aFlags & nsIPrintSettings::kInitSaveBGColors) { if (GETBOOLPREF(kPrintBGColors, &b)) { aPS->SetPrintBGColors(b); DUMP_BOOL(kReadStr, kPrintBGColors, b); } } if (aFlags & nsIPrintSettings::kInitSaveBGImages) { if (GETBOOLPREF(kPrintBGImages, &b)) { aPS->SetPrintBGImages(b); DUMP_BOOL(kReadStr, kPrintBGImages, b); } } if (aFlags & nsIPrintSettings::kInitSaveReversed) { if (GETBOOLPREF(kPrintReversed, &b)) { aPS->SetPrintReversed(b); DUMP_BOOL(kReadStr, kPrintReversed, b); } } if (aFlags & nsIPrintSettings::kInitSaveInColor) { if (GETBOOLPREF(kPrintInColor, &b)) { aPS->SetPrintInColor(b); DUMP_BOOL(kReadStr, kPrintInColor, b); } } if (aFlags & nsIPrintSettings::kInitSavePlexName) { if (GETSTRPREF(kPrintPlexName, str)) { aPS->SetPlexName(str.get()); DUMP_STR(kReadStr, kPrintPlexName, str.get()); } } if (aFlags & nsIPrintSettings::kInitSavePaperData) { if (GETINTPREF(kPrintPaperData, &iVal)) { aPS->SetPaperData(iVal); DUMP_INT(kReadStr, kPrintPaperData, iVal); } } if (aFlags & nsIPrintSettings::kInitSaveColorspace) { if (GETSTRPREF(kPrintColorspace, str)) { aPS->SetColorspace(str.get()); DUMP_STR(kReadStr, kPrintColorspace, str.get()); } } if (aFlags & nsIPrintSettings::kInitSaveResolutionName) { if (GETSTRPREF(kPrintResolutionName, str)) { aPS->SetResolutionName(str.get()); DUMP_STR(kReadStr, kPrintResolutionName, str.get()); } } if (aFlags & nsIPrintSettings::kInitSaveDownloadFonts) { if (GETBOOLPREF(kPrintDownloadFonts, &b)) { aPS->SetDownloadFonts(b); DUMP_BOOL(kReadStr, kPrintDownloadFonts, b); } } if (aFlags & nsIPrintSettings::kInitSaveOrientation) { if (GETINTPREF(kPrintOrientation, &iVal)) { aPS->SetOrientation(iVal); DUMP_INT(kReadStr, kPrintOrientation, iVal); } } if (aFlags & nsIPrintSettings::kInitSavePrintCommand) { if (GETSTRPREF(kPrintCommand, str)) { aPS->SetPrintCommand(str.get()); DUMP_STR(kReadStr, kPrintCommand, str.get()); } } if (aFlags & nsIPrintSettings::kInitSavePrintToFile) { if (GETBOOLPREF(kPrintToFile, &b)) { aPS->SetPrintToFile(b); DUMP_BOOL(kReadStr, kPrintToFile, b); } } if (aFlags & nsIPrintSettings::kInitSaveToFileName) { if (GETSTRPREF(kPrintToFileName, str)) { aPS->SetToFileName(str.get()); DUMP_STR(kReadStr, kPrintToFileName, str.get()); } } if (aFlags & nsIPrintSettings::kInitSavePageDelay) { if (GETINTPREF(kPrintPageDelay, &iVal)) { aPS->SetPrintPageDelay(iVal); DUMP_INT(kReadStr, kPrintPageDelay, iVal); } } if (aFlags & nsIPrintSettings::kInitSaveShrinkToFit) { if (GETBOOLPREF(kPrintShrinkToFit, &b)) { aPS->SetShrinkToFit(b); DUMP_BOOL(kReadStr, kPrintShrinkToFit, b); } } if (aFlags & nsIPrintSettings::kInitSaveScaling) { if (GETDBLPREF(kPrintScaling, dbl)) { aPS->SetScaling(dbl); DUMP_DBL(kReadStr, kPrintScaling, dbl); } } // Not Reading In: // Number of Copies return NS_OK; }
NS_IMETHODIMP nsSimplePageSequenceFrame::Reflow(nsPresContext* aPresContext, nsHTMLReflowMetrics& aDesiredSize, const nsHTMLReflowState& aReflowState, nsReflowStatus& aStatus) { NS_PRECONDITION(aPresContext->IsRootPaginatedDocument(), "A Page Sequence is only for real pages"); DO_GLOBAL_REFLOW_COUNT("nsSimplePageSequenceFrame"); DISPLAY_REFLOW(aPresContext, this, aReflowState, aDesiredSize, aStatus); NS_FRAME_TRACE_REFLOW_IN("nsSimplePageSequenceFrame::Reflow"); aStatus = NS_FRAME_COMPLETE; // we're always complete // Don't do incremental reflow until we've taught tables how to do // it right in paginated mode. if (!(GetStateBits() & NS_FRAME_FIRST_REFLOW)) { // Return our desired size aDesiredSize.height = mSize.height; aDesiredSize.width = mSize.width; aDesiredSize.mOverflowArea = nsRect(0, 0, aDesiredSize.width, aDesiredSize.height); FinishAndStoreOverflow(&aDesiredSize); return NS_OK; } PRBool isPrintPreview = aPresContext->Type() == nsPresContext::eContext_PrintPreview; // See if we can get a Print Settings from the Context if (!mPageData->mPrintSettings && aPresContext->Medium() == nsGkAtoms::print) { mPageData->mPrintSettings = aPresContext->GetPrintSettings(); } // now get out margins & edges if (mPageData->mPrintSettings) { nsMargin unwriteableTwips; mPageData->mPrintSettings->GetUnwriteableMarginInTwips(unwriteableTwips); NS_ASSERTION(unwriteableTwips.left >= 0 && unwriteableTwips.top >= 0 && unwriteableTwips.right >= 0 && unwriteableTwips.bottom >= 0, "Unwriteable twips should be non-negative"); nsMargin marginTwips; mPageData->mPrintSettings->GetMarginInTwips(marginTwips); mMargin = aPresContext->TwipsToAppUnits(marginTwips + unwriteableTwips); PRInt16 printType; mPageData->mPrintSettings->GetPrintRange(&printType); mPrintRangeType = printType; nsMargin edgeTwips; mPageData->mPrintSettings->GetEdgeInTwips(edgeTwips); // sanity check the values. three inches are sometimes needed nscoord inchInTwips = NS_INCHES_TO_TWIPS(3.0); edgeTwips.top = PR_MIN(PR_MAX(edgeTwips.top, 0), inchInTwips); edgeTwips.bottom = PR_MIN(PR_MAX(edgeTwips.bottom, 0), inchInTwips); edgeTwips.left = PR_MIN(PR_MAX(edgeTwips.left, 0), inchInTwips); edgeTwips.right = PR_MIN(PR_MAX(edgeTwips.right, 0), inchInTwips); mPageData->mEdgePaperMargin = aPresContext->TwipsToAppUnits(edgeTwips + unwriteableTwips); } // *** Special Override *** // If this is a sub-sdoc (meaning it doesn't take the whole page) // and if this Document is in the upper left hand corner // we need to suppress the top margin or it will reflow too small nsSize pageSize = aPresContext->GetPageSize(); mPageData->mReflowSize = pageSize; // If we're printing a selection, we need to reflow with // unconstrained height, to make sure we'll get to the selection // even if it's beyond the first page of content. if (nsIPrintSettings::kRangeSelection == mPrintRangeType) { mPageData->mReflowSize.height = NS_UNCONSTRAINEDSIZE; } mPageData->mReflowMargin = mMargin; // Compute the size of each page and the x coordinate that each page will // be placed at nscoord extraThreshold = PR_MAX(pageSize.width, pageSize.height)/10; PRInt32 gapInTwips = nsContentUtils::GetIntPref("print.print_extra_margin"); gapInTwips = PR_MAX(0, gapInTwips); nscoord extraGap = aPresContext->TwipsToAppUnits(gapInTwips); extraGap = PR_MIN(extraGap, extraThreshold); // clamp to 1/10 of the largest dim of the page nscoord deadSpaceGap = 0; if (isPrintPreview) { GetDeadSpaceValue(&gapInTwips); deadSpaceGap = aPresContext->TwipsToAppUnits(gapInTwips); } nsMargin extraMargin(0,0,0,0); nsSize shadowSize(0,0); if (aPresContext->IsScreen()) { extraMargin.SizeTo(extraGap, extraGap, extraGap, extraGap); nscoord fourPixels = nsPresContext::CSSPixelsToAppUnits(4); shadowSize.SizeTo(fourPixels, fourPixels); } mPageData->mShadowSize = shadowSize; mPageData->mExtraMargin = extraMargin; const nscoord x = deadSpaceGap; nscoord y = deadSpaceGap;// Running y-offset for each page nsSize availSize(pageSize.width + shadowSize.width + extraMargin.LeftRight(), pageSize.height + shadowSize.height + extraMargin.TopBottom()); // Tile the pages vertically nsHTMLReflowMetrics kidSize; for (nsIFrame* kidFrame = mFrames.FirstChild(); nsnull != kidFrame; ) { // Set the shared data into the page frame before reflow nsPageFrame * pf = static_cast<nsPageFrame*>(kidFrame); pf->SetSharedPageData(mPageData); // Reflow the page nsHTMLReflowState kidReflowState(aPresContext, aReflowState, kidFrame, availSize); nsReflowStatus status; kidReflowState.SetComputedWidth(kidReflowState.availableWidth); //kidReflowState.SetComputedHeight(kidReflowState.availableHeight); PR_PL(("AV W: %d H: %d\n", kidReflowState.availableWidth, kidReflowState.availableHeight)); // Place and size the page. If the page is narrower than our // max width then center it horizontally ReflowChild(kidFrame, aPresContext, kidSize, kidReflowState, x, y, 0, status); FinishReflowChild(kidFrame, aPresContext, nsnull, kidSize, x, y, 0); y += kidSize.height; // Leave a slight gap between the pages y += deadSpaceGap; // Is the page complete? nsIFrame* kidNextInFlow = kidFrame->GetNextInFlow(); if (NS_FRAME_IS_FULLY_COMPLETE(status)) { NS_ASSERTION(nsnull == kidNextInFlow, "bad child flow list"); } else if (nsnull == kidNextInFlow) { // The page isn't complete and it doesn't have a next-in-flow, so // create a continuing page nsIFrame* continuingPage; nsresult rv = CreateContinuingPageFrame(aPresContext, kidFrame, &continuingPage); if (NS_FAILED(rv)) { break; } // Add it to our child list kidFrame->SetNextSibling(continuingPage); } // Get the next page kidFrame = kidFrame->GetNextSibling(); } // Get Total Page Count nsIFrame* page; PRInt32 pageTot = 0; for (page = mFrames.FirstChild(); page; page = page->GetNextSibling()) { pageTot++; } // Set Page Number Info PRInt32 pageNum = 1; for (page = mFrames.FirstChild(); page; page = page->GetNextSibling()) { nsPageFrame * pf = static_cast<nsPageFrame*>(page); if (pf != nsnull) { pf->SetPageNumInfo(pageNum, pageTot); } pageNum++; } // Create current Date/Time String if (!mDateFormatter) mDateFormatter = do_CreateInstance(NS_DATETIMEFORMAT_CONTRACTID); #ifndef WINCE NS_ENSURE_TRUE(mDateFormatter, NS_ERROR_FAILURE); nsAutoString formattedDateString; time_t ltime; time( <ime ); if (NS_SUCCEEDED(mDateFormatter->FormatTime(nsnull /* nsILocale* locale */, kDateFormatShort, kTimeFormatNoSeconds, ltime, formattedDateString))) { PRUnichar * uStr = ToNewUnicode(formattedDateString); SetDateTimeStr(uStr); // memory will be freed } #endif // Return our desired size // Adjustr the reflow size by PrintPreviewScale so the scrollbars end up the // correct size aDesiredSize.height = y * PresContext()->GetPrintPreviewScale(); // includes page heights and dead space aDesiredSize.width = (x + availSize.width + deadSpaceGap) * PresContext()->GetPrintPreviewScale(); aDesiredSize.mOverflowArea = nsRect(0, 0, aDesiredSize.width, aDesiredSize.height); FinishAndStoreOverflow(&aDesiredSize); // cache the size so we can set the desired size // for the other reflows that happen mSize.width = aDesiredSize.width; mSize.height = aDesiredSize.height; NS_FRAME_TRACE_REFLOW_OUT("nsSimplePageSequeceFrame::Reflow", aStatus); NS_FRAME_SET_TRUNCATION(aStatus, aReflowState, aDesiredSize); return NS_OK; }
NS_IMETHODIMP nsPrintSettings::SetMarginTop(double aMarginTop) { mMargin.top = NS_INCHES_TO_TWIPS(float(aMarginTop)); return NS_OK; }
NS_IMETHODIMP nsPrintSettings::SetMarginBottom(double aMarginBottom) { mMargin.bottom = NS_INCHES_TO_TWIPS(float(aMarginBottom)); return NS_OK; }
NS_IMETHODIMP nsPrintSettings::SetMarginRight(double aMarginRight) { mMargin.right = NS_INCHES_TO_TWIPS(float(aMarginRight)); return NS_OK; }
NS_IMETHODIMP nsPrintSettings::SetEdgeTop(double aEdgeTop) { mEdge.top = NS_INCHES_TO_TWIPS(float(aEdgeTop)); return NS_OK; }
NS_IMETHODIMP nsPrintSettings::SetEdgeBottom(double aEdgeBottom) { mEdge.bottom = NS_INCHES_TO_TWIPS(float(aEdgeBottom)); return NS_OK; }