зеркало из https://github.com/mozilla/gecko-dev.git
Bug 404519 - "some margin and edges twips/app units confusion" [p=reg@freebsd.org (Jeremy Lea) / chpe@gnome.org (Christian Persch) r+sr=roc a1.9=schrep]
This commit is contained in:
Родитель
c3f9cef3e2
Коммит
66a7aaf1b0
|
@ -862,8 +862,8 @@ DocumentViewerImpl::InitInternal(nsIWidget* aParentWidget,
|
|||
mPresContext->GetPrintSettings()->GetEffectivePageSize(&pageWidth,
|
||||
&pageHeight);
|
||||
mPresContext->SetPageSize(
|
||||
nsSize(mPresContext->TwipsToAppUnits(pageWidth),
|
||||
mPresContext->TwipsToAppUnits(pageHeight)));
|
||||
nsSize(mPresContext->TwipsToAppUnits(NSToIntFloor(pageWidth)),
|
||||
mPresContext->TwipsToAppUnits(NSToIntFloor(pageHeight))));
|
||||
mPresContext->SetIsRootPaginatedDocument(PR_TRUE);
|
||||
mPresContext->SetPageScale(1.0f);
|
||||
}
|
||||
|
@ -3131,7 +3131,7 @@ NS_IMETHODIMP DocumentViewerImpl::SizeToContent()
|
|||
docShellAsItem->GetTreeOwner(getter_AddRefs(treeOwner));
|
||||
NS_ENSURE_TRUE(treeOwner, NS_ERROR_FAILURE);
|
||||
|
||||
/* presContext's size was calculated in twips and has already been
|
||||
/* presContext's size was calculated in app units and has already been
|
||||
rounded to the equivalent pixels (so the width/height calculation
|
||||
we just performed was probably exact, though it was based on
|
||||
values already rounded during ResizeReflow). In a surprising
|
||||
|
@ -3668,11 +3668,12 @@ DocumentViewerImpl::PrintPreviewNavigate(PRInt16 aType, PRInt32 aPageNum)
|
|||
}
|
||||
|
||||
if (fndPageFrame && scrollableView) {
|
||||
nscoord deadSpaceGap = 0;
|
||||
nscoord deadSpaceGapTwips = 0;
|
||||
nsIPageSequenceFrame * sqf;
|
||||
if (NS_SUCCEEDED(CallQueryInterface(seqFrame, &sqf))) {
|
||||
sqf->GetDeadSpaceValue(&deadSpaceGap);
|
||||
sqf->GetDeadSpaceValue(&deadSpaceGapTwips);
|
||||
}
|
||||
nscoord deadSpaceGap = mPresContext->TwipsToAppUnits(deadSpaceGapTwips);
|
||||
|
||||
// scroll so that top of page (plus the gray area) is at the top of the scroll area
|
||||
scrollableView->ScrollTo(0, fndPageFrame->GetPosition().y-deadSpaceGap, PR_TRUE);
|
||||
|
|
|
@ -115,7 +115,7 @@ nsSimplePageSequenceFrame::nsSimplePageSequenceFrame(nsStyleContext* aContext) :
|
|||
mSelectionHeight(-1),
|
||||
mYSelOffset(0)
|
||||
{
|
||||
nscoord halfInch = NS_INCHES_TO_TWIPS(0.5);
|
||||
nscoord halfInch = PresContext()->TwipsToAppUnits(NS_INCHES_TO_TWIPS(0.5));
|
||||
mMargin.SizeTo(halfInch, halfInch, halfInch, halfInch);
|
||||
|
||||
// XXX Unsafe to assume successful allocation
|
||||
|
@ -161,21 +161,6 @@ nsSimplePageSequenceFrame::CreateContinuingPageFrame(nsPresContext* aPresContext
|
|||
CreateContinuingFrame(aPresContext, aPageFrame, this, aContinuingPage);
|
||||
}
|
||||
|
||||
void
|
||||
nsSimplePageSequenceFrame::GetEdgePaperMargin(nsMargin& aMargin)
|
||||
{
|
||||
if (NS_SUCCEEDED(mPageData->mPrintSettings->GetEdgeInTwips(aMargin))) {
|
||||
nscoord inchInTwips = NS_INCHES_TO_TWIPS(1.0);
|
||||
// sanity check the values. an inch is still probably excessive
|
||||
aMargin.top = PR_MIN(PR_MAX(aMargin.top, 0), inchInTwips);
|
||||
aMargin.bottom = PR_MIN(PR_MAX(aMargin.bottom, 0), inchInTwips);
|
||||
aMargin.left = PR_MIN(PR_MAX(aMargin.left, 0), inchInTwips);
|
||||
aMargin.right = PR_MIN(PR_MAX(aMargin.right, 0), inchInTwips);
|
||||
} else {
|
||||
aMargin.SizeTo(0, 0, 0, 0);
|
||||
}
|
||||
}
|
||||
|
||||
NS_IMETHODIMP
|
||||
nsSimplePageSequenceFrame::Reflow(nsPresContext* aPresContext,
|
||||
nsHTMLReflowMetrics& aDesiredSize,
|
||||
|
@ -211,7 +196,7 @@ nsSimplePageSequenceFrame::Reflow(nsPresContext* aPresContext,
|
|||
mPageData->mPrintSettings = aPresContext->GetPrintSettings();
|
||||
}
|
||||
|
||||
// now get out margins
|
||||
// now get out margins & edges
|
||||
if (mPageData->mPrintSettings) {
|
||||
nsMargin marginTwips;
|
||||
mPageData->mPrintSettings->GetMarginInTwips(marginTwips);
|
||||
|
@ -222,6 +207,22 @@ nsSimplePageSequenceFrame::Reflow(nsPresContext* aPresContext,
|
|||
PRInt16 printType;
|
||||
mPageData->mPrintSettings->GetPrintRange(&printType);
|
||||
mPrintRangeType = printType;
|
||||
|
||||
nsMargin edgeTwips;
|
||||
mPageData->mPrintSettings->GetEdgeInTwips(edgeTwips);
|
||||
|
||||
// sanity check the values. an inch is still probably excessive
|
||||
nscoord inchInTwips = NS_INCHES_TO_TWIPS(1.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 =
|
||||
nsMargin(aPresContext->TwipsToAppUnits(edgeTwips.left),
|
||||
aPresContext->TwipsToAppUnits(edgeTwips.top),
|
||||
aPresContext->TwipsToAppUnits(edgeTwips.right),
|
||||
aPresContext->TwipsToAppUnits(edgeTwips.bottom));
|
||||
}
|
||||
|
||||
// *** Special Override ***
|
||||
|
@ -236,18 +237,19 @@ nsSimplePageSequenceFrame::Reflow(nsPresContext* aPresContext,
|
|||
|
||||
// Compute the size of each page and the x coordinate that each page will
|
||||
// be placed at
|
||||
GetEdgePaperMargin(mPageData->mEdgePaperMargin);
|
||||
nscoord extraThreshold = PR_MAX(pageSize.width, pageSize.height)/10;
|
||||
PRInt32 gapInTwips = nsContentUtils::GetIntPref("print.print_extra_margin");
|
||||
gapInTwips = PR_MAX(0, gapInTwips);
|
||||
|
||||
gapInTwips = PR_MAX(gapInTwips, 0);
|
||||
gapInTwips = PR_MIN(gapInTwips, extraThreshold); // clamp to 1/10 of the largest dim of the page
|
||||
|
||||
nscoord extraGap = nscoord(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(&deadSpaceGap);
|
||||
if (isPrintPreview) {
|
||||
nscoord deadSpaceGapTwips;
|
||||
GetDeadSpaceValue(&deadSpaceGapTwips);
|
||||
deadSpaceGap = aPresContext->TwipsToAppUnits(gapInTwips);
|
||||
}
|
||||
|
||||
nsMargin extraMargin(0,0,0,0);
|
||||
nsSize shadowSize(0,0);
|
||||
|
@ -488,9 +490,7 @@ nsSimplePageSequenceFrame::StartPrint(nsPresContext* aPresContext,
|
|||
if (mDoingPageRange) {
|
||||
// XXX because of the hack for making the selection all print on one page
|
||||
// we must make sure that the page is sized correctly before printing.
|
||||
PRInt32 width, height;
|
||||
width = aPresContext->GetPageSize().width;
|
||||
height = aPresContext->GetPageSize().height;
|
||||
nscoord height = aPresContext->GetPageSize().height;
|
||||
|
||||
PRInt32 pageNum = 1;
|
||||
nscoord y = 0;//mMargin.top;
|
||||
|
@ -588,14 +588,14 @@ nsSimplePageSequenceFrame::PrintNextPage()
|
|||
// currently this does not work for IFrames
|
||||
// I will soon improve this to work with IFrames
|
||||
PRBool continuePrinting = PR_TRUE;
|
||||
PRInt32 width, height;
|
||||
nscoord width, height;
|
||||
width = PresContext()->GetPageSize().width;
|
||||
height = PresContext()->GetPageSize().height;
|
||||
height -= mMargin.top + mMargin.bottom;
|
||||
width -= mMargin.left + mMargin.right;
|
||||
nscoord selectionY = height;
|
||||
nsIFrame* conFrame = mCurrentPageFrame->GetFirstChild(nsnull);
|
||||
if (mSelectionHeight > -1) {
|
||||
if (mSelectionHeight >= 0) {
|
||||
conFrame->SetPosition(conFrame->GetPosition() + nsPoint(0, -mYSelOffset));
|
||||
}
|
||||
|
||||
|
@ -625,7 +625,7 @@ nsSimplePageSequenceFrame::PrintNextPage()
|
|||
nsLayoutUtils::PaintFrame(renderingContext, mCurrentPageFrame,
|
||||
drawingRegion, NS_RGBA(0,0,0,0));
|
||||
|
||||
if (mSelectionHeight > -1 && selectionY < mSelectionHeight) {
|
||||
if (mSelectionHeight >= 0 && selectionY < mSelectionHeight) {
|
||||
selectionY += height;
|
||||
printedPageNum++;
|
||||
pf->SetPageNumInfo(printedPageNum, mTotalPages);
|
||||
|
|
|
@ -149,8 +149,6 @@ protected:
|
|||
void SetDateTimeStr(PRUnichar * aDateTimeStr);
|
||||
void SetPageNumberFormat(PRUnichar * aFormatStr, PRBool aForPageNumOnly);
|
||||
|
||||
void GetEdgePaperMargin(nsMargin& aMargin);
|
||||
|
||||
NS_IMETHOD_(nsrefcnt) AddRef(void) {return nsContainerFrame::AddRef();}
|
||||
NS_IMETHOD_(nsrefcnt) Release(void) {return nsContainerFrame::Release();}
|
||||
|
||||
|
|
|
@ -1803,7 +1803,7 @@ nsPrintEngine::ReflowPrintObject(nsPrintObject * aPO)
|
|||
documentIsTopLevel = PR_FALSE;
|
||||
// presshell exists because parent is printable
|
||||
} else {
|
||||
PRInt32 pageWidth, pageHeight;
|
||||
nscoord pageWidth, pageHeight;
|
||||
mPrt->mPrintDC->GetDeviceSurfaceDimensions(pageWidth, pageHeight);
|
||||
adjSize = nsSize(pageWidth, pageHeight);
|
||||
documentIsTopLevel = PR_TRUE;
|
||||
|
@ -1921,11 +1921,11 @@ nsPrintEngine::ReflowPrintObject(nsPrintObject * aPO)
|
|||
aPO->mPresContext->SetIsRootPaginatedDocument(documentIsTopLevel);
|
||||
aPO->mPresContext->SetPageScale(aPO->mZoomRatio);
|
||||
// Calculate scale factor from printer to screen
|
||||
PRInt32 printDPI = mPrt->mPrintDC->AppUnitsPerInch() /
|
||||
mPrt->mPrintDC->AppUnitsPerDevPixel();
|
||||
PRInt32 screenDPI = mDeviceContext->AppUnitsPerInch() /
|
||||
mDeviceContext->AppUnitsPerDevPixel();
|
||||
aPO->mPresContext->SetPrintPreviewScale(float(screenDPI) / float(printDPI));
|
||||
float printDPI = float(mPrt->mPrintDC->AppUnitsPerInch()) /
|
||||
float(mPrt->mPrintDC->AppUnitsPerDevPixel());
|
||||
float screenDPI = float(mDeviceContext->AppUnitsPerInch()) /
|
||||
float(mDeviceContext->AppUnitsPerDevPixel());
|
||||
aPO->mPresContext->SetPrintPreviewScale(screenDPI / printDPI);
|
||||
|
||||
rv = aPO->mPresShell->InitialReflow(adjSize.width, adjSize.height);
|
||||
|
||||
|
@ -2160,24 +2160,27 @@ nsPrintEngine::DoPrint(nsPrintObject * aPO)
|
|||
if (NS_SUCCEEDED(rv)) {
|
||||
mPrt->mPrintSettings->SetStartPageRange(startPageNum);
|
||||
mPrt->mPrintSettings->SetEndPageRange(endPageNum);
|
||||
nsMargin margin(0,0,0,0);
|
||||
mPrt->mPrintSettings->GetMarginInTwips(margin);
|
||||
nsMargin marginTwips(0,0,0,0);
|
||||
mPrt->mPrintSettings->GetMarginInTwips(marginTwips);
|
||||
nsMargin margin(poPresContext->TwipsToAppUnits(marginTwips.left),
|
||||
poPresContext->TwipsToAppUnits(marginTwips.top),
|
||||
poPresContext->TwipsToAppUnits(marginTwips.right),
|
||||
poPresContext->TwipsToAppUnits(marginTwips.bottom));
|
||||
|
||||
if (startPageNum == endPageNum) {
|
||||
{
|
||||
nsPresContext* presContext = poPresShell->GetPresContext();
|
||||
startRect.y -= presContext->TwipsToAppUnits(margin.top);
|
||||
endRect.y -= presContext->TwipsToAppUnits(margin.top);
|
||||
startRect.y -= margin.top;
|
||||
endRect.y -= margin.top;
|
||||
// XXX This is temporary fix for printing more than one page of a selection
|
||||
pageSequence->SetSelectionHeight(startRect.y, endRect.y+endRect.height-startRect.y);
|
||||
|
||||
// calc total pages by getting calculating the selection's height
|
||||
// and then dividing it by how page content frames will fit.
|
||||
nscoord selectionHgt = endRect.y + endRect.height - startRect.y;
|
||||
PRInt32 pageWidth, pageHeight;
|
||||
nscoord pageWidth, pageHeight;
|
||||
mPrt->mPrintDC->GetDeviceSurfaceDimensions(pageWidth, pageHeight);
|
||||
pageHeight -= margin.top + margin.bottom;
|
||||
PRInt32 totalPages = PRInt32((float(selectionHgt) / float(pageHeight))+0.99);
|
||||
PRInt32 totalPages = NSToIntCeil(float(selectionHgt) / float(pageHeight));
|
||||
pageSequence->SetTotalNumPages(totalPages);
|
||||
}
|
||||
}
|
||||
|
|
Загрузка…
Ссылка в новой задаче