Implements Print FrameAsIs and other frame printing options

Bug 7201 r=dcone sr=attinasi
This commit is contained in:
rods%netscape.com 2001-04-12 13:04:29 +00:00
Родитель ecfeda55c2
Коммит f439ddf0c3
28 изменённых файлов: 4643 добавлений и 1966 удалений

Разница между файлами не показана из-за своего большого размера Загрузить разницу

Просмотреть файл

@ -71,14 +71,16 @@ interface nsIPrintOptions : nsISupports
const short kLetterPaperSize = 0;
const short kLegalPaperSize = 1;
const short kExecutivePaperSize = 2;
const short kA4PaperSize = 3;
const short kA3PaperSize = 3;
const short kA4PaperSize = 4;
/**
* Print Frame Constants
*/
const short kFramesAsIs = 0;
const short kSelectedFrame = 1;
const short kEachFrameSep = 2;
const short kNoFrames = 0;
const short kFramesAsIs = 1;
const short kSelectedFrame = 2;
const short kEachFrameSep = 3;
const short kFrameEnableNone = 0;
const short kFrameEnableAll = 1;

Просмотреть файл

@ -48,6 +48,7 @@ static NS_DEFINE_CID(kPrintOptionsCID, NS_PRINTOPTIONS_CID);
NS_IMPL_ISUPPORTS1(nsDeviceContextSpecFactoryWin, nsIDeviceContextSpecFactory)
NS_IMETHODIMP nsDeviceContextSpecFactoryWin :: Init(void)
{
return NS_OK;
@ -93,18 +94,18 @@ UINT CALLBACK PrintHookProc(HWND hdlg, UINT uiMsg, WPARAM wParam, LPARAM lParam)
}
if (howToEnableFrameUI == nsIPrintOptions::kFrameEnableAll) {
SetRadio(hdlg, rad4, PR_FALSE, PR_FALSE); // XXX this is just temporary (should be enabled)
SetRadio(hdlg, rad5, PR_TRUE);
SetRadio(hdlg, rad4, PR_TRUE);
SetRadio(hdlg, rad5, PR_FALSE);
SetRadio(hdlg, rad6, PR_FALSE);
// set default so user doesn't have to actually press on it
gFrameSelectedRadioBtn = rad5;
gFrameSelectedRadioBtn = rad4;
} else if (howToEnableFrameUI == nsIPrintOptions::kFrameEnableAsIsAndEach) {
SetRadio(hdlg, rad4, PR_FALSE, PR_FALSE); // XXX this is just temporary (should be enabled)
SetRadio(hdlg, rad4, PR_TRUE);
SetRadio(hdlg, rad5, PR_FALSE, PR_FALSE);
SetRadio(hdlg, rad6, PR_TRUE);
SetRadio(hdlg, rad6, PR_FALSE);
// set default so user doesn't have to actually press on it
gFrameSelectedRadioBtn = rad6;
gFrameSelectedRadioBtn = rad4;
} else { // nsIPrintOptions::kFrameEnableNone
@ -171,7 +172,7 @@ NS_IMETHODIMP nsDeviceContextSpecFactoryWin :: CreateDeviceContextSpec(nsIWidget
if(PR_TRUE == aQuiet){
prntdlg.Flags = PD_ALLPAGES | PD_RETURNDEFAULT;
prntdlg.Flags = PD_ALLPAGES | PD_RETURNDEFAULT | PD_RETURNIC | PD_USEDEVMODECOPIESANDCOLLATE;
}
BOOL res = ::PrintDlg(&prntdlg);
@ -206,18 +207,22 @@ NS_IMETHODIMP nsDeviceContextSpecFactoryWin :: CreateDeviceContextSpec(nsIWidget
printService->SetPrintRange(nsIPrintOptions::kRangeAllPages);
}
// check to see about the frame radio buttons
switch (gFrameSelectedRadioBtn) {
case rad4:
printService->SetPrintFrameType(nsIPrintOptions::kFramesAsIs);
break;
case rad5:
printService->SetPrintFrameType(nsIPrintOptions::kSelectedFrame);
break;
case rad6:
printService->SetPrintFrameType(nsIPrintOptions::kEachFrameSep);
break;
} // switch
if (howToEnableFrameUI != nsIPrintOptions::kFrameEnableNone) {
// check to see about the frame radio buttons
switch (gFrameSelectedRadioBtn) {
case rad4:
printService->SetPrintFrameType(nsIPrintOptions::kFramesAsIs);
break;
case rad5:
printService->SetPrintFrameType(nsIPrintOptions::kSelectedFrame);
break;
case rad6:
printService->SetPrintFrameType(nsIPrintOptions::kEachFrameSep);
break;
} // switch
} else {
printService->SetPrintFrameType(nsIPrintOptions::kNoFrames);
}
}

Разница между файлами не показана из-за своего большого размера Загрузить разницу

Просмотреть файл

@ -349,14 +349,24 @@ public:
NS_IMETHOD IsPaginated(PRBool* aResult) = 0;
/**
* Return the page width if this is a paginated context.
* Gets the rect for the page Dimimensions,
* this includes X,Y Offsets which are used to determine
* the inclusion of margins
* Also, indicates whether the size has been overridden
*
* @param aActualRect returns the size of the actual device/surface
* @param aRect returns the adjusted size
*/
NS_IMETHOD GetPageWidth(nscoord* aResult) = 0;
NS_IMETHOD GetPageDim(nsRect* aActualRect, nsRect* aAdjRect) = 0;
/**
* Return the page height if this is a paginated context
* Sets the "adjusted" rect for the page Dimimensions,
* this includes X,Y Offsets which are used to determine
* the inclusion of margins
*
* @param aRect returns the adjusted size
*/
NS_IMETHOD GetPageHeight(nscoord* aResult) = 0;
NS_IMETHOD SetPageDim(nsRect* aRect) = 0;
NS_IMETHOD GetPixelsToTwips(float* aResult) const = 0;

Просмотреть файл

@ -24,6 +24,7 @@
#include "nslayout.h"
#include "nsISupports.h"
#include "nsRect.h"
class nsIPresContext;
class nsIPrintOptions;
@ -128,6 +129,15 @@ public:
NS_IMETHOD IsDoingPrintRange(PRBool* aDoing) = 0;
NS_IMETHOD GetPrintRange(PRInt32* aFromPage, PRInt32* aToPage) = 0;
NS_IMETHOD SkipPageBegin() = 0;
NS_IMETHOD SkipPageEnd() = 0;
NS_IMETHOD DoPageEnd(nsIPresContext* aPresContext) = 0;
NS_IMETHOD GetPrintThisPage(PRBool* aPrintThisPage) = 0;
NS_IMETHOD SetOffset(nscoord aX, nscoord aY) = 0;
NS_IMETHOD SuppressHeadersAndFooters(PRBool aDoSup) = 0;
NS_IMETHOD SetClipRect(nsIPresContext* aPresContext, nsRect* aSize) = 0;
private:
NS_IMETHOD_(nsrefcnt) AddRef(void) = 0;
NS_IMETHOD_(nsrefcnt) Release(void) = 0;

Просмотреть файл

@ -349,14 +349,24 @@ public:
NS_IMETHOD IsPaginated(PRBool* aResult) = 0;
/**
* Return the page width if this is a paginated context.
* Gets the rect for the page Dimimensions,
* this includes X,Y Offsets which are used to determine
* the inclusion of margins
* Also, indicates whether the size has been overridden
*
* @param aActualRect returns the size of the actual device/surface
* @param aRect returns the adjusted size
*/
NS_IMETHOD GetPageWidth(nscoord* aResult) = 0;
NS_IMETHOD GetPageDim(nsRect* aActualRect, nsRect* aAdjRect) = 0;
/**
* Return the page height if this is a paginated context
* Sets the "adjusted" rect for the page Dimimensions,
* this includes X,Y Offsets which are used to determine
* the inclusion of margins
*
* @param aRect returns the adjusted size
*/
NS_IMETHOD GetPageHeight(nscoord* aResult) = 0;
NS_IMETHOD SetPageDim(nsRect* aRect) = 0;
NS_IMETHOD GetPixelsToTwips(float* aResult) const = 0;

Просмотреть файл

@ -349,14 +349,24 @@ public:
NS_IMETHOD IsPaginated(PRBool* aResult) = 0;
/**
* Return the page width if this is a paginated context.
* Gets the rect for the page Dimimensions,
* this includes X,Y Offsets which are used to determine
* the inclusion of margins
* Also, indicates whether the size has been overridden
*
* @param aActualRect returns the size of the actual device/surface
* @param aRect returns the adjusted size
*/
NS_IMETHOD GetPageWidth(nscoord* aResult) = 0;
NS_IMETHOD GetPageDim(nsRect* aActualRect, nsRect* aAdjRect) = 0;
/**
* Return the page height if this is a paginated context
* Sets the "adjusted" rect for the page Dimimensions,
* this includes X,Y Offsets which are used to determine
* the inclusion of margins
*
* @param aRect returns the adjusted size
*/
NS_IMETHOD GetPageHeight(nscoord* aResult) = 0;
NS_IMETHOD SetPageDim(nsRect* aRect) = 0;
NS_IMETHOD GetPixelsToTwips(float* aResult) const = 0;

Просмотреть файл

@ -31,8 +31,8 @@ public:
NS_IMETHOD GetMedium(nsIAtom** aMedium);
NS_IMETHOD IsPaginated(PRBool* aResult);
NS_IMETHOD GetPageWidth(nscoord* aResult);
NS_IMETHOD GetPageHeight(nscoord* aResult);
NS_IMETHOD GetPageDim(nsRect* aActualRect, nsRect* aAdjRect);
NS_IMETHOD SetPageDim(nsRect* aRect);
};
GalleyContext::GalleyContext()
@ -67,25 +67,20 @@ GalleyContext::IsPaginated(PRBool* aResult)
}
NS_IMETHODIMP
GalleyContext::GetPageWidth(nscoord* aResult)
GalleyContext::GetPageDim(nsRect* aActualRect, nsRect* aAdjRect)
{
NS_PRECONDITION(nsnull != aResult, "null ptr");
if (nsnull == aResult) {
return NS_ERROR_NULL_POINTER;
}
*aResult = 0;
return NS_OK;
NS_ENSURE_ARG_POINTER(aActualRect);
NS_ENSURE_ARG_POINTER(aAdjRect);
aActualRect->SetRect(0, 0, 0, 0);
aAdjRect->SetRect(0, 0, 0, 0);
return NS_ERROR_FAILURE;
}
NS_IMETHODIMP
GalleyContext::GetPageHeight(nscoord* aResult)
GalleyContext::SetPageDim(nsRect* aPageDim)
{
NS_PRECONDITION(nsnull != aResult, "null ptr");
if (nsnull == aResult) {
return NS_ERROR_NULL_POINTER;
}
*aResult = 0;
return NS_OK;
NS_ENSURE_ARG_POINTER(aPageDim);
return NS_ERROR_FAILURE;
}
NS_LAYOUT nsresult

Просмотреть файл

@ -151,8 +151,8 @@ public:
NS_IMETHOD GetVisibleArea(nsRect& aResult);
NS_IMETHOD SetVisibleArea(const nsRect& r);
NS_IMETHOD IsPaginated(PRBool* aResult) = 0;
NS_IMETHOD GetPageWidth(nscoord* aResult) = 0;
NS_IMETHOD GetPageHeight(nscoord* aResult) = 0;
NS_IMETHOD GetPageDim(nsRect* aActualRect, nsRect* aAdjRect) = 0;
NS_IMETHOD SetPageDim(nsRect* aRect) = 0;
NS_IMETHOD GetPixelsToTwips(float* aResult) const;
NS_IMETHOD GetTwipsToPixels(float* aResult) const;
NS_IMETHOD GetScaledPixelsToTwips(float* aScale) const;

Просмотреть файл

@ -44,11 +44,14 @@ public:
NS_IMETHOD GetMedium(nsIAtom** aMedium);
NS_IMETHOD IsPaginated(PRBool* aResult);
NS_IMETHOD GetPageWidth(nscoord* aResult);
NS_IMETHOD GetPageHeight(nscoord* aResult);
NS_IMETHOD GetPageDim(nsRect* aActualRect, nsRect* aAdjRect);
NS_IMETHOD SetPageDim(nsRect* aRect);
protected:
nsRect mPageDim;
};
PrintContext::PrintContext()
PrintContext::PrintContext() :
mPageDim(0,0,0,0)
{
}
@ -80,10 +83,7 @@ PrintContext::QueryInterface(REFNSIID aIID, void** aInstancePtr)
NS_IMETHODIMP
PrintContext::GetMedium(nsIAtom** aResult)
{
NS_PRECONDITION(nsnull != aResult, "null ptr");
if (nsnull == aResult) {
return NS_ERROR_NULL_POINTER;
}
NS_ENSURE_ARG_POINTER(aResult);
*aResult = nsLayoutAtoms::print;
NS_ADDREF(*aResult);
return NS_OK;
@ -92,48 +92,34 @@ PrintContext::GetMedium(nsIAtom** aResult)
NS_IMETHODIMP
PrintContext::IsPaginated(PRBool* aResult)
{
NS_PRECONDITION(nsnull != aResult, "null ptr");
if (nsnull == aResult) {
return NS_ERROR_NULL_POINTER;
}
NS_ENSURE_ARG_POINTER(aResult);
*aResult = PR_TRUE;
return NS_OK;
}
NS_IMETHODIMP
PrintContext::GetPageWidth(nscoord* aResult)
PrintContext::GetPageDim(nsRect* aActualRect, nsRect* aAdjRect)
{
PRInt32 width,height;
NS_ENSURE_ARG_POINTER(aActualRect);
NS_ENSURE_ARG_POINTER(aAdjRect);
NS_PRECONDITION(nsnull != aResult, "null ptr");
if (nsnull == aResult) {
return NS_ERROR_NULL_POINTER;
PRInt32 width,height;
if (NS_SUCCEEDED(mDeviceContext->GetDeviceSurfaceDimensions(width, height))) {
aActualRect->SetRect(0, 0, width, height);
}
mDeviceContext->GetDeviceSurfaceDimensions(width,height);
// a xp margin can be added here
*aResult = width;
*aAdjRect = mPageDim;
return NS_OK;
}
NS_IMETHODIMP
PrintContext::GetPageHeight(nscoord* aResult)
PrintContext::SetPageDim(nsRect* aPageDim)
{
PRInt32 width,height;
NS_PRECONDITION(nsnull != aResult, "null ptr");
if (nsnull == aResult) {
return NS_ERROR_NULL_POINTER;
}
mDeviceContext->GetDeviceSurfaceDimensions(width,height);
// a xp margin or header/footer space can be added here
*aResult = height;
NS_ENSURE_ARG_POINTER(aPageDim);
mPageDim = *aPageDim;
return NS_OK;
}
NS_LAYOUT nsresult
NS_NewPrintContext(nsIPrintContext** aInstancePtrResult)
{

Просмотреть файл

@ -28,6 +28,11 @@
#include "nsLayoutAtoms.h"
#include "prlog.h"
// Print Options
#include "nsIPrintOptions.h"
#include "nsGfxCIID.h"
#include "nsIServiceManager.h"
static NS_DEFINE_CID(kPrintOptionsCID, NS_PRINTOPTIONS_CID);
class PrintPreviewContext : public nsPresContext {
public:
@ -36,12 +41,14 @@ public:
NS_IMETHOD GetMedium(nsIAtom** aMedium);
NS_IMETHOD IsPaginated(PRBool* aResult);
NS_IMETHOD GetPageWidth(nscoord* aResult);
NS_IMETHOD GetPageHeight(nscoord* aResult);
NS_IMETHOD GetPageDim(nsRect* aActualRect, nsRect* aAdjRect);
NS_IMETHOD SetPageDim(nsRect* aRect);
#ifdef NS_DEBUG
static PRBool UseFakePageSize();
#endif
protected:
nsRect mPageDim;
};
#ifdef NS_DEBUG
@ -60,7 +67,8 @@ PrintPreviewContext::UseFakePageSize()
}
#endif
PrintPreviewContext::PrintPreviewContext()
PrintPreviewContext::PrintPreviewContext() :
mPageDim(-1,-1,-1,-1)
{
}
@ -71,10 +79,7 @@ PrintPreviewContext::~PrintPreviewContext()
NS_IMETHODIMP
PrintPreviewContext::GetMedium(nsIAtom** aResult)
{
NS_PRECONDITION(nsnull != aResult, "null ptr");
if (nsnull == aResult) {
return NS_ERROR_NULL_POINTER;
}
NS_ENSURE_ARG_POINTER(aResult);
*aResult = nsLayoutAtoms::print;
NS_ADDREF(*aResult);
return NS_OK;
@ -83,57 +88,71 @@ PrintPreviewContext::GetMedium(nsIAtom** aResult)
NS_IMETHODIMP
PrintPreviewContext::IsPaginated(PRBool* aResult)
{
NS_PRECONDITION(nsnull != aResult, "null ptr");
if (nsnull == aResult) {
return NS_ERROR_NULL_POINTER;
}
NS_ENSURE_ARG_POINTER(aResult);
*aResult = PR_TRUE;
return NS_OK;
}
NS_IMETHODIMP
PrintPreviewContext::GetPageWidth(nscoord* aResult)
PrintPreviewContext::GetPageDim(nsRect* aActualRect, nsRect* aAdjRect)
{
NS_PRECONDITION(nsnull != aResult, "null ptr");
if (nsnull == aResult) {
return NS_ERROR_NULL_POINTER;
NS_ENSURE_ARG_POINTER(aActualRect);
NS_ENSURE_ARG_POINTER(aAdjRect);
// XXX maybe we get the size of the default printer instead
nsresult rv;
NS_WITH_SERVICE(nsIPrintOptions, printService, 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
}
#ifdef NS_DEBUG
if (UseFakePageSize()) {
// For testing purposes make the page width smaller than the visible
// area
// For testing purposes make the page width smaller than the visible area
float sbWidth, sbHeight;
mDeviceContext->GetScrollBarDimensions(sbWidth, sbHeight);
nscoord sbar = NSToCoordRound(sbWidth);
*aResult = mVisibleArea.width - sbar - 2*100;
return NS_OK;
aActualRect->width = mVisibleArea.width - sbar - 2*100;
aActualRect->height = mVisibleArea.height * 60 / 100;
}
#endif
*aAdjRect = mPageDim;
// XXX assumes a 1/2 margin around all sides
*aResult = (nscoord) NS_INCHES_TO_TWIPS(7.5);
return NS_OK;
}
NS_IMETHODIMP
PrintPreviewContext::GetPageHeight(nscoord* aResult)
PrintPreviewContext::SetPageDim(nsRect* aPageDim)
{
NS_PRECONDITION(nsnull != aResult, "null ptr");
if (nsnull == aResult) {
return NS_ERROR_NULL_POINTER;
}
#ifdef NS_DEBUG
if (UseFakePageSize()) {
// For testing purposes make the page height 60% of the visible area
*aResult = mVisibleArea.height * 60 / 100;
return NS_OK;
}
#endif
// XXX assumes a 1/2 margin around all sides
*aResult = (nscoord) NS_INCHES_TO_TWIPS(10);
NS_ENSURE_ARG_POINTER(aPageDim);
mPageDim = *aPageDim;
return NS_OK;
}

Просмотреть файл

@ -24,6 +24,7 @@
#include "nslayout.h"
#include "nsISupports.h"
#include "nsRect.h"
class nsIPresContext;
class nsIPrintOptions;
@ -128,6 +129,15 @@ public:
NS_IMETHOD IsDoingPrintRange(PRBool* aDoing) = 0;
NS_IMETHOD GetPrintRange(PRInt32* aFromPage, PRInt32* aToPage) = 0;
NS_IMETHOD SkipPageBegin() = 0;
NS_IMETHOD SkipPageEnd() = 0;
NS_IMETHOD DoPageEnd(nsIPresContext* aPresContext) = 0;
NS_IMETHOD GetPrintThisPage(PRBool* aPrintThisPage) = 0;
NS_IMETHOD SetOffset(nscoord aX, nscoord aY) = 0;
NS_IMETHOD SuppressHeadersAndFooters(PRBool aDoSup) = 0;
NS_IMETHOD SetClipRect(nsIPresContext* aPresContext, nsRect* aSize) = 0;
private:
NS_IMETHOD_(nsrefcnt) AddRef(void) = 0;
NS_IMETHOD_(nsrefcnt) Release(void) = 0;

Просмотреть файл

@ -53,6 +53,24 @@ static NS_DEFINE_CID(kLocaleServiceCID, NS_LOCALESERVICE_CID);
// tstaic data members
PRUnichar * nsPageFrame::mPageNumFormat = nsnull;
#if defined(DEBUG_rods) || defined(DEBUG_dcone)
#define DEBUG_PRINTING
#endif
#ifdef DEBUG_PRINTING
#define PRINT_DEBUG_MSG1(_msg1) fprintf(mDebugFD, (_msg1))
#define PRINT_DEBUG_MSG2(_msg1, _msg2) fprintf(mDebugFD, (_msg1), (_msg2))
#define PRINT_DEBUG_MSG3(_msg1, _msg2, _msg3) fprintf(mDebugFD, (_msg1), (_msg2), (_msg3))
#define PRINT_DEBUG_MSG4(_msg1, _msg2, _msg3, _msg4) fprintf(mDebugFD, (_msg1), (_msg2), (_msg3), (_msg4))
#define PRINT_DEBUG_MSG5(_msg1, _msg2, _msg3, _msg4, _msg5) fprintf(mDebugFD, (_msg1), (_msg2), (_msg3), (_msg4), (_msg5))
#else //--------------
#define PRINT_DEBUG_MSG1(_msg)
#define PRINT_DEBUG_MSG2(_msg1, _msg2)
#define PRINT_DEBUG_MSG3(_msg1, _msg2, _msg3)
#define PRINT_DEBUG_MSG4(_msg1, _msg2, _msg3, _msg4)
#define PRINT_DEBUG_MSG5(_msg1, _msg2, _msg3, _msg4, _msg5)
#endif
nsresult
NS_NewPageFrame(nsIPresShell* aPresShell, nsIFrame** aNewFrame)
{
@ -69,8 +87,14 @@ NS_NewPageFrame(nsIPresShell* aPresShell, nsIFrame** aNewFrame)
}
nsPageFrame::nsPageFrame() :
mHeadFootFont(nsnull)
mHeadFootFont(nsnull),
mSupressHF(PR_FALSE),
mClipRect(-1, -1, -1, -1)
{
#ifdef NS_DEBUG
mDebugFD = stdout;
#endif
}
nsPageFrame::~nsPageFrame()
@ -174,11 +198,15 @@ NS_METHOD nsPageFrame::Reflow(nsIPresContext* aPresContext,
NS_ASSERTION(nsnull == childNextInFlow, "bad child flow list");
}
}
PRINT_DEBUG_MSG2("PageFrame::Reflow %p ", this);
PRINT_DEBUG_MSG5("[%d,%d][%d,%d]\n", aDesiredSize.width, aDesiredSize.height, aReflowState.availableWidth, aReflowState.availableHeight);
// Return our desired size
aDesiredSize.width = aReflowState.availableWidth;
aDesiredSize.height = aReflowState.availableHeight;
}
PRINT_DEBUG_MSG2("PageFrame::Reflow %p ", this);
PRINT_DEBUG_MSG3("[%d,%d]\n", aReflowState.availableWidth, aReflowState.availableHeight);
return NS_OK;
}
@ -254,6 +282,7 @@ nsPageFrame::DrawHeaderFooter(nsIRenderingContext& aRenderingContext,
nscoord aHeight,
PRBool aUseHalfThePage)
{
// first make sure we have a vaild string and that the height of the
// text will fit in the margin
if (aStr.Length() > 0 &&
@ -300,6 +329,25 @@ nsPageFrame::DrawHeaderFooter(nsIRenderingContext& aRenderingContext,
aRenderingContext.SetClipRect(rect, nsClipCombine_kReplace, clipEmpty);
aRenderingContext.DrawString(str, x, y);
aRenderingContext.PopState(clipEmpty);
#ifdef DEBUG_PRINTING
PRINT_DEBUG_MSG2("Page: %p", this);
char * s = str.ToNewCString();
if (s) {
PRINT_DEBUG_MSG2(" [%s]", s);
nsMemory::Free(s);
}
char justStr[64];
switch (aJust) {
case nsIPrintOptions::kJustLeft:strcpy(justStr, "Left");break;
case nsIPrintOptions::kJustCenter:strcpy(justStr, "Center");break;
case nsIPrintOptions::kJustRight:strcpy(justStr, "Right");break;
} // switch
PRINT_DEBUG_MSG2(" HF: %s ", aHeaderFooter==eHeader?"Header":"Footer");
PRINT_DEBUG_MSG2(" JST: %s ", justStr);
PRINT_DEBUG_MSG3(" x,y: %d,%d", x, y);
PRINT_DEBUG_MSG2(" Hgt: %d ", aHeight);
PRINT_DEBUG_MSG2(" Half: %s\n", aUseHalfThePage?"Yes":"No");
#endif
}
}
@ -310,9 +358,30 @@ nsPageFrame::Paint(nsIPresContext* aPresContext,
const nsRect& aDirtyRect,
nsFramePaintLayer aWhichLayer)
{
aRenderingContext.PushState();
PRBool clipEmpty;
if (mClipRect.width != -1 || mClipRect.height != -1) {
#ifdef DEBUG_PRINTING
if (NS_FRAME_PAINT_LAYER_FOREGROUND == aWhichLayer) {
printf("*** ClipRect: %5d,%5d,%5d,%5d\n", mClipRect.x, mClipRect.y, mClipRect.width, mClipRect.height);
}
#endif
mClipRect.x = 0;
mClipRect.y = 0;
aRenderingContext.SetClipRect(mClipRect, nsClipCombine_kReplace, clipEmpty);
}
nsresult rv = nsContainerFrame::Paint(aPresContext, aRenderingContext, aDirtyRect, aWhichLayer);
#if defined(DEBUG_rods) || defined(DEBUG_dcone)
if (NS_FRAME_PAINT_LAYER_FOREGROUND == aWhichLayer) {
nsRect r;
fprintf(mDebugFD, "PF::Paint -> %p SupHF: %s Rect: [%5d,%5d,%5d,%5d]\n", this,
mSupressHF?"Yes":"No", mRect.x, mRect.y, mRect.width, mRect.height);
}
#endif
if (NS_FRAME_PAINT_LAYER_FOREGROUND == aWhichLayer && !mSupressHF) {
// get the current margin
mPrintOptions->GetMarginInTwips(mMargin);
@ -325,9 +394,9 @@ nsPageFrame::Paint(nsIPresContext* aPresContext,
aPresContext->GetPixelsToTwips(&p2t);
rect.Deflate(NSToCoordRound(p2t), NSToCoordRound(p2t));
aRenderingContext.SetColor(NS_RGB(0, 0, 0));
//aRenderingContext.DrawRect(rect);
aRenderingContext.DrawRect(rect);
rect.Inflate(NSToCoordRound(p2t), NSToCoordRound(p2t));
printf("SPSF::PaintChild -> Painting Frame %p Page No: %d\n", this, mPageNum);
fprintf(mDebugFD, "PageFr::PaintChild -> Painting Frame %p Page No: %d\n", this, mPageNum);
#endif
// use the whole page
rect.width += mMargin.left + mMargin.right;
@ -419,6 +488,7 @@ nsPageFrame::Paint(nsIPresContext* aPresContext,
}
aRenderingContext.PopState(clipEmpty);
return rv;
}
@ -441,7 +511,7 @@ void
nsPageFrame::SetPageNumInfo(PRInt32 aPageNumber, PRInt32 aTotalPages)
{
mPageNum = aPageNumber;
mTotNumPages = aTotalPages;
mTotNumPages = aTotalPages;
}

Просмотреть файл

@ -50,9 +50,11 @@ public:
*/
NS_IMETHOD GetFrameType(nsIAtom** aType) const;
#ifdef DEBUG
#ifdef NS_DEBUG
// Debugging
NS_IMETHOD GetFrameName(nsString& aResult) const;
void SetDebugFD(FILE* aFD) { mDebugFD = aFD; }
FILE * mDebugFD;
#endif
//////////////////
@ -65,6 +67,9 @@ public:
// Tell the page which page number it is out of how many
virtual void SetPageNumInfo(PRInt32 aPageNumber, PRInt32 aTotalPages);
virtual void SuppressHeadersAndFooters(PRBool aDoSup) { mSupressHF = aDoSup; }
virtual void SetClipRect(nsRect* aClipRect) { mClipRect = *aClipRect; }
// This is class is now responsible for freeing the memory
static void SetPageNumberFormat(PRUnichar * aFormatStr);
@ -98,6 +103,9 @@ protected:
nsMargin mMargin;
nsFont * mHeadFootFont;
PRPackedBool mSupressHF;
nsRect mClipRect;
static PRUnichar * mPageNumFormat;
};

Просмотреть файл

@ -50,6 +50,24 @@
static NS_DEFINE_CID(kPrintOptionsCID, NS_PRINTOPTIONS_CID);
//
#if defined(DEBUG_rods) || defined(DEBUG_dcone)
#define DEBUG_PRINTING
#endif
#ifdef DEBUG_PRINTING
#define PRINT_DEBUG_MSG1(_msg1) fprintf(mDebugFD, (_msg1))
#define PRINT_DEBUG_MSG2(_msg1, _msg2) fprintf(mDebugFD, (_msg1), (_msg2))
#define PRINT_DEBUG_MSG3(_msg1, _msg2, _msg3) fprintf(mDebugFD, (_msg1), (_msg2), (_msg3))
#define PRINT_DEBUG_MSG4(_msg1, _msg2, _msg3, _msg4) fprintf(mDebugFD, (_msg1), (_msg2), (_msg3), (_msg4))
#define PRINT_DEBUG_MSG5(_msg1, _msg2, _msg3, _msg4, _msg5) fprintf(mDebugFD, (_msg1), (_msg2), (_msg3), (_msg4), (_msg5))
#else //--------------
#define PRINT_DEBUG_MSG1(_msg)
#define PRINT_DEBUG_MSG2(_msg1, _msg2)
#define PRINT_DEBUG_MSG3(_msg1, _msg2, _msg3)
#define PRINT_DEBUG_MSG4(_msg1, _msg2, _msg3, _msg4)
#define PRINT_DEBUG_MSG5(_msg1, _msg2, _msg3, _msg4, _msg5)
#endif
nsresult
NS_NewSimplePageSequenceFrame(nsIPresShell* aPresShell, nsIFrame** aNewFrame)
{
@ -83,7 +101,14 @@ nsSimplePageSequenceFrame::nsSimplePageSequenceFrame() :
printService->GetPrintRange(&printType);
mIsPrintingSelection = nsIPrintOptions::kRangeSelection == printType;
}
mSkipPageBegin = PR_FALSE;
mSkipPageEnd = PR_FALSE;
mPrintThisPage = PR_FALSE;
mOffsetX = 0;
mOffsetY = 0;
#ifdef NS_DEBUG
mDebugFD = stdout;
#endif
}
nsSimplePageSequenceFrame::~nsSimplePageSequenceFrame()
@ -247,9 +272,28 @@ nsSimplePageSequenceFrame::Reflow(nsIPresContext* aPresContext,
// Compute the size of each page and the x coordinate that each page will
// be placed at
nsSize pageSize;
aPresContext->GetPageWidth(&pageSize.width);
aPresContext->GetPageHeight(&pageSize.height);
nsRect pageSize;
nsRect adjSize;
aPresContext->GetPageDim(&pageSize, &adjSize);
PRBool suppressLeftMargin = PR_FALSE;
PRBool suppressRightMargin = PR_FALSE;
PRBool suppressTopMargin = PR_FALSE;
PRBool suppressBottomMargin = PR_FALSE;
if (pageSize != adjSize &&
(adjSize.x != 0 || adjSize.y != 0 || adjSize.width != 0 || adjSize.height != 0)) {
suppressLeftMargin = pageSize.x != adjSize.x;
suppressTopMargin = pageSize.y != adjSize.y;
if (pageSize.width != adjSize.width) {
suppressRightMargin = PR_TRUE;
pageSize.width = adjSize.width;
}
if (pageSize.height != adjSize.height) {
suppressBottomMargin = PR_TRUE;
pageSize.height = adjSize.height;
}
}
// XXX - Hack Alert
// OK, so ther eis a selection, we will print the entire selection
@ -261,10 +305,15 @@ nsSimplePageSequenceFrame::Reflow(nsIPresContext* aPresContext,
pageSize.height = 0x0FFFFFFF;
}
nscoord x = mMargin.left;
// only use this local margin for sizing,
// not for positioning
nsMargin margin(suppressLeftMargin?0:mMargin.left,
suppressTopMargin?0:mMargin.top,
suppressRightMargin?0:mMargin.right,
suppressBottomMargin?0:mMargin.bottom);
// Running y-offset for each page
nscoord y = mMargin.top;
nscoord x = mMargin.left;
nscoord y = mMargin.top;// Running y-offset for each page
// See if it's an incremental reflow command
if (eReflowReason_Incremental == aReflowState.reason) {
@ -279,11 +328,12 @@ nsSimplePageSequenceFrame::Reflow(nsIPresContext* aPresContext,
nsHTMLReflowMetrics kidSize(nsnull);
for (nsIFrame* kidFrame = mFrames.FirstChild(); nsnull != kidFrame; ) {
// Reflow the page
nsSize availSize(pageSize.width, pageSize.height);
nsHTMLReflowState kidReflowState(aPresContext, aReflowState, kidFrame,
pageSize, reflowReason);
availSize, reflowReason);
nsReflowStatus status;
kidReflowState.availableWidth = pageSize.width - mMargin.left - mMargin.right;
kidReflowState.availableHeight = pageSize.height - mMargin.top - mMargin.bottom;
kidReflowState.availableWidth = pageSize.width - margin.left - margin.right;
kidReflowState.availableHeight = pageSize.height - margin.top - margin.bottom;
kidReflowState.mComputedWidth = kidReflowState.availableWidth;
//kidReflowState.mComputedHeight = kidReflowState.availableHeight;
@ -371,272 +421,8 @@ nsSimplePageSequenceFrame::Print(nsIPresContext* aPresContext,
nsIPrintOptions* aPrintOptions,
nsIPrintStatusCallback* aStatusCallback)
{
NS_ENSURE_ARG_POINTER(aPresContext);
NS_ENSURE_ARG_POINTER(aPrintOptions);
PRInt32 printRangeType;
PRInt32 fromPageNum;
PRInt32 toPageNum;
PRBool printEvenPages, printOddPages;
PRInt16 printType;
aPrintOptions->GetPrintRange(&printType);
printRangeType = printType;
aPrintOptions->GetStartPageRange(&fromPageNum);
aPrintOptions->GetEndPageRange(&toPageNum);
aPrintOptions->GetMarginInTwips(mMargin);
aPrintOptions->GetPrintOptions(nsIPrintOptions::kOptPrintEvenPages, &printEvenPages);
aPrintOptions->GetPrintOptions(nsIPrintOptions::kOptPrintOddPages, &printOddPages);
PRBool doingPageRange = nsIPrintOptions::kRangeSpecifiedPageRange == printRangeType ||
nsIPrintOptions::kRangeSelection == printRangeType;
// If printing a range of pages make sure at least the starting page
// number is valid
PRInt32 totalPages = mFrames.GetLength();
if (doingPageRange) {
if (fromPageNum > totalPages) {
return NS_ERROR_INVALID_ARG;
}
}
// Begin printing of the document
nsCOMPtr<nsIDeviceContext> dc;
aPresContext->GetDeviceContext(getter_AddRefs(dc));
nsCOMPtr<nsIPresShell> presShell;
aPresContext->GetShell(getter_AddRefs(presShell));
nsCOMPtr<nsIViewManager> vm;
presShell->GetViewManager(getter_AddRefs(vm));
nsresult rv = NS_OK;
#if defined(DEBUG_rods) || defined(DEBUG_dcone)
{
nsIView * seqView;
GetView(aPresContext, &seqView);
nsRect rect;
GetRect(rect);
printf("Seq Frame: - %d,%d,%d,%d ", rect.x, rect.y, rect.width, rect.height);
printf("view: %p ", seqView);
nsRect viewRect;
if (seqView) {
seqView->GetBounds(viewRect);
printf(" %d,%d,%d,%d", viewRect.x, viewRect.y, viewRect.width, viewRect.height);
}
printf("\n");
}
{
PRInt32 pageNum = 1;
for (nsIFrame* page = mFrames.FirstChild(); nsnull != page; page->GetNextSibling(&page)) {
nsIView* view;
page->GetView(aPresContext, &view);
NS_ASSERTION(nsnull != view, "no page view");
nsRect rect;
page->GetRect(rect);
nsRect viewRect;
view->GetBounds(viewRect);
printf("Page: %d - %d,%d,%d,%d ", pageNum, rect.x, rect.y, rect.width, rect.height);
printf(" %d,%d,%d,%d\n", viewRect.x, viewRect.y, viewRect.width, viewRect.height);
pageNum++;
}
}
printf("***** Setting aPresContext %p is painting selection %d\n", aPresContext, nsIPrintOptions::kRangeSelection == printRangeType);
#endif
// Determine if we are rendering only the selection
aPresContext->SetIsRenderingOnlySelection(nsIPrintOptions::kRangeSelection == printRangeType);
if (doingPageRange) {
// 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;
dc->GetDeviceSurfaceDimensions(width,height);
height -= mMargin.top + mMargin.bottom;
PRInt32 pageNum = 1;
nscoord y = mMargin.top;
for (nsIFrame* page = mFrames.FirstChild(); nsnull != page; page->GetNextSibling(&page)) {
nsIView* view;
page->GetView(aPresContext, &view);
NS_ASSERTION(nsnull != view, "no page view");
if (pageNum < fromPageNum || pageNum > toPageNum) {
// XXX Doesn't seem like we need to do this
// because we ask only the pages we want to print
//view->SetVisibility(nsViewVisibility_kHide);
} else {
nsRect rect;
page->GetRect(rect);
rect.y = y;
rect.height = height;
page->SetRect(aPresContext, rect);
nsRect viewRect;
view->GetBounds(viewRect);
viewRect.y = y;
viewRect.height = height;
view->SetBounds(viewRect);
y += rect.height + mMargin.top + mMargin.bottom;
}
pageNum++;
}
// adjust total number of pages
if (nsIPrintOptions::kRangeSelection == printRangeType) {
totalPages = toPageNum - fromPageNum + 1;
} else {
totalPages = pageNum - 1;
}
}
// XXX - This wouldn't have to be done each time
// but it isn't that expensive and this the best place
// to have access to a localized file properties file
//
// Note: because this is done here it makes a little bit harder
// to have UI for setting the header/footer font name and size
//
// Get default font name and size to be used for the headers and footers
nsAutoString fontName;
rv = nsFormControlHelper::GetLocalizedString(PRINTING_PROPERTIES, "fontname", fontName);
if (NS_FAILED(rv)) {
fontName.AssignWithConversion("serif");
}
nsAutoString fontSizeStr;
nscoord pointSize = 10;;
rv = nsFormControlHelper::GetLocalizedString(PRINTING_PROPERTIES, "fontsize", fontSizeStr);
if (NS_SUCCEEDED(rv)) {
PRInt32 errCode;
pointSize = fontSizeStr.ToInteger(&errCode);
if (NS_FAILED(errCode)) {
pointSize = 10;
}
}
aPrintOptions->SetFontNamePointSize(fontName, pointSize);
// Now go get the Localized Page Formating String
PRBool doingPageTotals = PR_TRUE;
aPrintOptions->GetPrintOptions(nsIPrintOptions::kOptPrintPageTotal, &doingPageTotals);
nsAutoString pageFormatStr;
rv = nsFormControlHelper::GetLocalizedString(PRINTING_PROPERTIES,
doingPageTotals?"pageofpages":"pagenumber",
pageFormatStr);
if (NS_FAILED(rv)) { // back stop formatting
pageFormatStr.AssignWithConversion(doingPageTotals?"%ld of %ld":"%ld");
}
// Sets the format into a static data memeber which will own the memory and free it
nsPageFrame::SetPageNumberFormat(pageFormatStr.ToNewUnicode());
// Print each specified page
// pageNum keeps track of the current page and what pages are printing
//
// printedPageNum keeps track of the current page number to be printed
// Note: When print al the pages or a page range the printed page shows the
// actual page number, when printing selection it prints the page number starting
// with the first page of the selection. For example if the user has a
// selection that starts on page 2 and ends on page 3, the page numbers when
// print are 1 and then two (which is different than printing a page range, where
// the page numbers would have been 2 and then 3)
PRInt32 pageNum = 1;
PRInt32 printedPageNum = 1;
for (nsIFrame* page = mFrames.FirstChild(); nsnull != page; page->GetNextSibling(&page)) {
// See whether we should print this page
PRBool printThisPage = PR_TRUE;
// If printing a range of pages check whether the page number is in the
// range of pages to print
if (doingPageRange) {
if (pageNum < fromPageNum) {
printThisPage = PR_FALSE;
} else if (pageNum > toPageNum) {
break;
}
}
// Check for printing of odd and even pages
if (pageNum & 0x1) {
if (!printOddPages) {
printThisPage = PR_FALSE; // don't print odd numbered page
}
} else {
if (!printEvenPages) {
printThisPage = PR_FALSE; // don't print even numbered page
}
}
if (printThisPage) {
// Start printing of the page
if (!SendStatusNotification(aStatusCallback, pageNum, totalPages,
ePrintStatus_StartPage)) {
rv = NS_ERROR_ABORT;
break;
}
rv = dc->BeginPage();
if (NS_FAILED(rv)) {
if (nsnull != aStatusCallback) {
aStatusCallback->OnError(ePrintError_Error);
}
break;
}
// cast the frame to be a page frame
nsPageFrame * pf = NS_STATIC_CAST(nsPageFrame*, page);
if (pf != nsnull) {
pf->SetPrintOptions(aPrintOptions);
pf->SetPageNumInfo(printedPageNum, totalPages);
}
// Print the page
nsIView* view;
page->GetView(aPresContext, &view);
NS_ASSERTION(nsnull != view, "no page view");
#if defined(DEBUG_rods) || defined(DEBUG_dcone)
{
char * fontname = fontName.ToNewCString();
printf("SPSF::Paint -> FontName[%s] Point Size: %d\n", fontname, pointSize);
nsMemory::Free(fontname);
printf("SPSF::Paint -> PageNo: %d View: %p\n", pageNum, view);
}
#endif
vm->Display(view, mMargin.left, mMargin.top);
// this view was printed and since display set the origin
// 0,0 there is a danger that this view can be printed again
// If it is a sibling to another page/view. Setting the visibility
// to hide will keep this page from printing again - dwc
//
// XXX Doesn't seem like we need to do this anymore
//view->SetVisibility(nsViewVisibility_kHide);
// Finish printing of the page
if (!SendStatusNotification(aStatusCallback, pageNum, totalPages,
ePrintStatus_EndPage)) {
rv = NS_ERROR_ABORT;
break;
}
rv = dc->EndPage();
if (NS_FAILED(rv)) {
if (nsnull != aStatusCallback) {
aStatusCallback->OnError(ePrintError_Error);
}
break;
}
}
if (nsIPrintOptions::kRangeSelection != printRangeType ||
(nsIPrintOptions::kRangeSelection == printRangeType && printThisPage)) {
printedPageNum++;
}
pageNum++;
}
return rv;
NS_ASSERTION(0, "No longer being used.");
return NS_ERROR_FAILURE;
}
NS_IMETHODIMP
@ -736,14 +522,14 @@ nsSimplePageSequenceFrame::StartPrint(nsIPresContext* aPresContext,
GetView(aPresContext, &seqView);
nsRect rect;
GetRect(rect);
printf("Seq Frame: - %d,%d,%d,%d ", rect.x, rect.y, rect.width, rect.height);
printf("view: %p ", seqView);
fprintf(mDebugFD, "Seq Frame: %p - [%5d,%5d,%5d,%5d] ", this, rect.x, rect.y, rect.width, rect.height);
fprintf(mDebugFD, "view: %p ", seqView);
nsRect viewRect;
if (seqView) {
seqView->GetBounds(viewRect);
printf(" %d,%d,%d,%d", viewRect.x, viewRect.y, viewRect.width, viewRect.height);
fprintf(mDebugFD, " [%5d,%5d,%5d,%5d]", viewRect.x, viewRect.y, viewRect.width, viewRect.height);
}
printf("\n");
fprintf(mDebugFD, "\n");
}
{
@ -756,12 +542,12 @@ nsSimplePageSequenceFrame::StartPrint(nsIPresContext* aPresContext,
page->GetRect(rect);
nsRect viewRect;
view->GetBounds(viewRect);
printf("Page: %d - %d,%d,%d,%d ", pageNum, rect.x, rect.y, rect.width, rect.height);
printf(" %d,%d,%d,%d\n", viewRect.x, viewRect.y, viewRect.width, viewRect.height);
fprintf(mDebugFD, " Page: %p No: %d - [%5d,%5d,%5d,%5d] ", page, pageNum, rect.x, rect.y, rect.width, rect.height);
fprintf(mDebugFD, " [%5d,%5d,%5d,%5d]\n", viewRect.x, viewRect.y, viewRect.width, viewRect.height);
pageNum++;
}
}
printf("***** Setting aPresContext %p is painting selection %d\n", aPresContext, nsIPrintOptions::kRangeSelection == mPrintRangeType);
//printf("***** Setting aPresContext %p is painting selection %d\n", aPresContext, nsIPrintOptions::kRangeSelection == mPrintRangeType);
#endif
// Determine if we are rendering only the selection
@ -901,13 +687,13 @@ nsSimplePageSequenceFrame::PrintNextPage(nsIPresContext* aPresContext,
nsresult rv = NS_OK;
// See whether we should print this page
PRBool printThisPage = PR_TRUE;
mPrintThisPage = PR_TRUE;
// If printing a range of pages check whether the page number is in the
// range of pages to print
if (mDoingPageRange) {
if (mPageNum < mFromPageNum) {
printThisPage = PR_FALSE;
mPrintThisPage = PR_FALSE;
} else if (mPageNum > mToPageNum) {
mPageNum++;
mCurrentPageFrame = nsnull;
@ -918,18 +704,21 @@ nsSimplePageSequenceFrame::PrintNextPage(nsIPresContext* aPresContext,
// Check for printing of odd and even pages
if (mPageNum & 0x1) {
if (!printOddPages) {
printThisPage = PR_FALSE; // don't print odd numbered page
mPrintThisPage = PR_FALSE; // don't print odd numbered page
}
} else {
if (!printEvenPages) {
printThisPage = PR_FALSE; // don't print even numbered page
mPrintThisPage = PR_FALSE; // don't print even numbered page
}
}
if (printThisPage) {
rv = dc->BeginPage();
if (NS_FAILED(rv)) {
return rv;
if (mPrintThisPage) {
if (!mSkipPageBegin) {
PRINT_DEBUG_MSG1("\n***************** BeginPage *****************\n");
rv = dc->BeginPage();
if (NS_FAILED(rv)) {
return rv;
}
}
// cast the frame to be a page frame
@ -944,12 +733,11 @@ nsSimplePageSequenceFrame::PrintNextPage(nsIPresContext* aPresContext,
mCurrentPageFrame->GetView(aPresContext, &view);
NS_ASSERTION(nsnull != view, "no page view");
#if defined(DEBUG_rods) || defined(DEBUG_dcone)
{
printf("SPSF::Paint(Async) -> PageNo: %d View: %p\n", mPageNum, view);
}
#endif
vm->Display(view, mMargin.left, mMargin.top);
PRINT_DEBUG_MSG4("SeqFr::Paint -> %p PageNo: %d View: %p", pf, mPageNum, view);
PRINT_DEBUG_MSG3(" At: %d,%d\n", mMargin.left+mOffsetX, mMargin.top+mOffsetY);
vm->Display(view, mMargin.left+mOffsetX, mMargin.top+mOffsetY);
// this view was printed and since display set the origin
@ -960,20 +748,87 @@ nsSimplePageSequenceFrame::PrintNextPage(nsIPresContext* aPresContext,
// XXX Doesn't seem like we need to do this anymore
//view->SetVisibility(nsViewVisibility_kHide);
rv = dc->EndPage();
if (!mSkipPageEnd) {
PRINT_DEBUG_MSG1("***************** End Page (PrintNextPage) *****************\n");
rv = dc->EndPage();
if (NS_FAILED(rv)) {
return rv;
}
}
}
if (!mSkipPageEnd) {
if (nsIPrintOptions::kRangeSelection != mPrintRangeType ||
(nsIPrintOptions::kRangeSelection == mPrintRangeType && mPrintThisPage)) {
mPrintedPageNum++;
}
mPageNum++;
rv = mCurrentPageFrame->GetNextSibling(&mCurrentPageFrame);
}
return rv;
}
NS_IMETHODIMP
nsSimplePageSequenceFrame::DoPageEnd(nsIPresContext* aPresContext)
{
if (mPrintThisPage) {
nsCOMPtr<nsIDeviceContext> dc;
aPresContext->GetDeviceContext(getter_AddRefs(dc));
NS_ASSERTION(dc, "nsIDeviceContext can't be NULL!");
PRINT_DEBUG_MSG1("***************** End Page (DoPageEnd) *****************\n");
nsresult rv = dc->EndPage();
if (NS_FAILED(rv)) {
return rv;
}
}
if (nsIPrintOptions::kRangeSelection != mPrintRangeType ||
(nsIPrintOptions::kRangeSelection == mPrintRangeType && printThisPage)) {
(nsIPrintOptions::kRangeSelection == mPrintRangeType && mPrintThisPage)) {
mPrintedPageNum++;
}
mPageNum++;
rv = mCurrentPageFrame->GetNextSibling(&mCurrentPageFrame);
return rv;
return mCurrentPageFrame->GetNextSibling(&mCurrentPageFrame);
}
NS_IMETHODIMP
nsSimplePageSequenceFrame::SuppressHeadersAndFooters(PRBool aDoSup)
{
for (nsIFrame* f = mFrames.FirstChild(); f != nsnull; f->GetNextSibling(&f)) {
nsPageFrame * pf = NS_STATIC_CAST(nsPageFrame*, f);
if (pf != nsnull) {
pf->SuppressHeadersAndFooters(aDoSup);
}
}
return NS_OK;
}
NS_IMETHODIMP
nsSimplePageSequenceFrame::SetClipRect(nsIPresContext* aPresContext, nsRect* aRect)
{
for (nsIFrame* f = mFrames.FirstChild(); f != nsnull; f->GetNextSibling(&f)) {
nsPageFrame * pf = NS_STATIC_CAST(nsPageFrame*, f);
if (pf != nsnull) {
pf->SetClipRect(aRect);
}
}
return NS_OK;
}
#ifdef NS_DEBUG
NS_IMETHODIMP
nsSimplePageSequenceFrame::SetDebugFD(FILE* aFD)
{
mDebugFD = aFD;
for (nsIFrame* f = mFrames.FirstChild(); f != nsnull; f->GetNextSibling(&f)) {
nsPageFrame * pf = NS_STATIC_CAST(nsPageFrame*, f);
if (pf != nsnull) {
pf->SetDebugFD(aFD);
}
}
return NS_OK;
}
#endif

Просмотреть файл

@ -57,10 +57,19 @@ public:
NS_IMETHOD GetNumPages(PRInt32* aNumPages);
NS_IMETHOD IsDoingPrintRange(PRBool* aDoing);
NS_IMETHOD GetPrintRange(PRInt32* aFromPage, PRInt32* aToPage);
NS_IMETHOD SkipPageBegin() { mSkipPageBegin = PR_TRUE; return NS_OK; }
NS_IMETHOD SkipPageEnd() { mSkipPageEnd = PR_TRUE; return NS_OK; }
NS_IMETHOD DoPageEnd(nsIPresContext* aPresContext);
NS_IMETHOD GetPrintThisPage(PRBool* aPrintThisPage) { *aPrintThisPage = mPrintThisPage; return NS_OK; }
NS_IMETHOD SetOffset(nscoord aX, nscoord aY) { mOffsetX = aX; mOffsetY = aY; return NS_OK; }
NS_IMETHOD SuppressHeadersAndFooters(PRBool aDoSup);
NS_IMETHOD SetClipRect(nsIPresContext* aPresContext, nsRect* aSize);
#ifdef DEBUG
#ifdef NS_DEBUG
// Debugging
NS_IMETHOD GetFrameName(nsString& aResult) const;
NS_IMETHOD SetDebugFD(FILE* aFD);
FILE * mDebugFD;
#endif
protected:
@ -94,6 +103,13 @@ protected:
PRInt32 mPrintRangeType;
PRInt32 mFromPageNum;
PRInt32 mToPageNum;
PRPackedBool mSkipPageBegin;
PRPackedBool mSkipPageEnd;
PRPackedBool mPrintThisPage;
PRPackedBool mSupressHF;
nscoord mOffsetX;
nscoord mOffsetY;
};

Просмотреть файл

@ -53,6 +53,24 @@ static NS_DEFINE_CID(kLocaleServiceCID, NS_LOCALESERVICE_CID);
// tstaic data members
PRUnichar * nsPageFrame::mPageNumFormat = nsnull;
#if defined(DEBUG_rods) || defined(DEBUG_dcone)
#define DEBUG_PRINTING
#endif
#ifdef DEBUG_PRINTING
#define PRINT_DEBUG_MSG1(_msg1) fprintf(mDebugFD, (_msg1))
#define PRINT_DEBUG_MSG2(_msg1, _msg2) fprintf(mDebugFD, (_msg1), (_msg2))
#define PRINT_DEBUG_MSG3(_msg1, _msg2, _msg3) fprintf(mDebugFD, (_msg1), (_msg2), (_msg3))
#define PRINT_DEBUG_MSG4(_msg1, _msg2, _msg3, _msg4) fprintf(mDebugFD, (_msg1), (_msg2), (_msg3), (_msg4))
#define PRINT_DEBUG_MSG5(_msg1, _msg2, _msg3, _msg4, _msg5) fprintf(mDebugFD, (_msg1), (_msg2), (_msg3), (_msg4), (_msg5))
#else //--------------
#define PRINT_DEBUG_MSG1(_msg)
#define PRINT_DEBUG_MSG2(_msg1, _msg2)
#define PRINT_DEBUG_MSG3(_msg1, _msg2, _msg3)
#define PRINT_DEBUG_MSG4(_msg1, _msg2, _msg3, _msg4)
#define PRINT_DEBUG_MSG5(_msg1, _msg2, _msg3, _msg4, _msg5)
#endif
nsresult
NS_NewPageFrame(nsIPresShell* aPresShell, nsIFrame** aNewFrame)
{
@ -69,8 +87,14 @@ NS_NewPageFrame(nsIPresShell* aPresShell, nsIFrame** aNewFrame)
}
nsPageFrame::nsPageFrame() :
mHeadFootFont(nsnull)
mHeadFootFont(nsnull),
mSupressHF(PR_FALSE),
mClipRect(-1, -1, -1, -1)
{
#ifdef NS_DEBUG
mDebugFD = stdout;
#endif
}
nsPageFrame::~nsPageFrame()
@ -174,11 +198,15 @@ NS_METHOD nsPageFrame::Reflow(nsIPresContext* aPresContext,
NS_ASSERTION(nsnull == childNextInFlow, "bad child flow list");
}
}
PRINT_DEBUG_MSG2("PageFrame::Reflow %p ", this);
PRINT_DEBUG_MSG5("[%d,%d][%d,%d]\n", aDesiredSize.width, aDesiredSize.height, aReflowState.availableWidth, aReflowState.availableHeight);
// Return our desired size
aDesiredSize.width = aReflowState.availableWidth;
aDesiredSize.height = aReflowState.availableHeight;
}
PRINT_DEBUG_MSG2("PageFrame::Reflow %p ", this);
PRINT_DEBUG_MSG3("[%d,%d]\n", aReflowState.availableWidth, aReflowState.availableHeight);
return NS_OK;
}
@ -254,6 +282,7 @@ nsPageFrame::DrawHeaderFooter(nsIRenderingContext& aRenderingContext,
nscoord aHeight,
PRBool aUseHalfThePage)
{
// first make sure we have a vaild string and that the height of the
// text will fit in the margin
if (aStr.Length() > 0 &&
@ -300,6 +329,25 @@ nsPageFrame::DrawHeaderFooter(nsIRenderingContext& aRenderingContext,
aRenderingContext.SetClipRect(rect, nsClipCombine_kReplace, clipEmpty);
aRenderingContext.DrawString(str, x, y);
aRenderingContext.PopState(clipEmpty);
#ifdef DEBUG_PRINTING
PRINT_DEBUG_MSG2("Page: %p", this);
char * s = str.ToNewCString();
if (s) {
PRINT_DEBUG_MSG2(" [%s]", s);
nsMemory::Free(s);
}
char justStr[64];
switch (aJust) {
case nsIPrintOptions::kJustLeft:strcpy(justStr, "Left");break;
case nsIPrintOptions::kJustCenter:strcpy(justStr, "Center");break;
case nsIPrintOptions::kJustRight:strcpy(justStr, "Right");break;
} // switch
PRINT_DEBUG_MSG2(" HF: %s ", aHeaderFooter==eHeader?"Header":"Footer");
PRINT_DEBUG_MSG2(" JST: %s ", justStr);
PRINT_DEBUG_MSG3(" x,y: %d,%d", x, y);
PRINT_DEBUG_MSG2(" Hgt: %d ", aHeight);
PRINT_DEBUG_MSG2(" Half: %s\n", aUseHalfThePage?"Yes":"No");
#endif
}
}
@ -310,9 +358,30 @@ nsPageFrame::Paint(nsIPresContext* aPresContext,
const nsRect& aDirtyRect,
nsFramePaintLayer aWhichLayer)
{
aRenderingContext.PushState();
PRBool clipEmpty;
if (mClipRect.width != -1 || mClipRect.height != -1) {
#ifdef DEBUG_PRINTING
if (NS_FRAME_PAINT_LAYER_FOREGROUND == aWhichLayer) {
printf("*** ClipRect: %5d,%5d,%5d,%5d\n", mClipRect.x, mClipRect.y, mClipRect.width, mClipRect.height);
}
#endif
mClipRect.x = 0;
mClipRect.y = 0;
aRenderingContext.SetClipRect(mClipRect, nsClipCombine_kReplace, clipEmpty);
}
nsresult rv = nsContainerFrame::Paint(aPresContext, aRenderingContext, aDirtyRect, aWhichLayer);
#if defined(DEBUG_rods) || defined(DEBUG_dcone)
if (NS_FRAME_PAINT_LAYER_FOREGROUND == aWhichLayer) {
nsRect r;
fprintf(mDebugFD, "PF::Paint -> %p SupHF: %s Rect: [%5d,%5d,%5d,%5d]\n", this,
mSupressHF?"Yes":"No", mRect.x, mRect.y, mRect.width, mRect.height);
}
#endif
if (NS_FRAME_PAINT_LAYER_FOREGROUND == aWhichLayer && !mSupressHF) {
// get the current margin
mPrintOptions->GetMarginInTwips(mMargin);
@ -325,9 +394,9 @@ nsPageFrame::Paint(nsIPresContext* aPresContext,
aPresContext->GetPixelsToTwips(&p2t);
rect.Deflate(NSToCoordRound(p2t), NSToCoordRound(p2t));
aRenderingContext.SetColor(NS_RGB(0, 0, 0));
//aRenderingContext.DrawRect(rect);
aRenderingContext.DrawRect(rect);
rect.Inflate(NSToCoordRound(p2t), NSToCoordRound(p2t));
printf("SPSF::PaintChild -> Painting Frame %p Page No: %d\n", this, mPageNum);
fprintf(mDebugFD, "PageFr::PaintChild -> Painting Frame %p Page No: %d\n", this, mPageNum);
#endif
// use the whole page
rect.width += mMargin.left + mMargin.right;
@ -419,6 +488,7 @@ nsPageFrame::Paint(nsIPresContext* aPresContext,
}
aRenderingContext.PopState(clipEmpty);
return rv;
}
@ -441,7 +511,7 @@ void
nsPageFrame::SetPageNumInfo(PRInt32 aPageNumber, PRInt32 aTotalPages)
{
mPageNum = aPageNumber;
mTotNumPages = aTotalPages;
mTotNumPages = aTotalPages;
}

Просмотреть файл

@ -50,9 +50,11 @@ public:
*/
NS_IMETHOD GetFrameType(nsIAtom** aType) const;
#ifdef DEBUG
#ifdef NS_DEBUG
// Debugging
NS_IMETHOD GetFrameName(nsString& aResult) const;
void SetDebugFD(FILE* aFD) { mDebugFD = aFD; }
FILE * mDebugFD;
#endif
//////////////////
@ -65,6 +67,9 @@ public:
// Tell the page which page number it is out of how many
virtual void SetPageNumInfo(PRInt32 aPageNumber, PRInt32 aTotalPages);
virtual void SuppressHeadersAndFooters(PRBool aDoSup) { mSupressHF = aDoSup; }
virtual void SetClipRect(nsRect* aClipRect) { mClipRect = *aClipRect; }
// This is class is now responsible for freeing the memory
static void SetPageNumberFormat(PRUnichar * aFormatStr);
@ -98,6 +103,9 @@ protected:
nsMargin mMargin;
nsFont * mHeadFootFont;
PRPackedBool mSupressHF;
nsRect mClipRect;
static PRUnichar * mPageNumFormat;
};

Просмотреть файл

@ -50,6 +50,24 @@
static NS_DEFINE_CID(kPrintOptionsCID, NS_PRINTOPTIONS_CID);
//
#if defined(DEBUG_rods) || defined(DEBUG_dcone)
#define DEBUG_PRINTING
#endif
#ifdef DEBUG_PRINTING
#define PRINT_DEBUG_MSG1(_msg1) fprintf(mDebugFD, (_msg1))
#define PRINT_DEBUG_MSG2(_msg1, _msg2) fprintf(mDebugFD, (_msg1), (_msg2))
#define PRINT_DEBUG_MSG3(_msg1, _msg2, _msg3) fprintf(mDebugFD, (_msg1), (_msg2), (_msg3))
#define PRINT_DEBUG_MSG4(_msg1, _msg2, _msg3, _msg4) fprintf(mDebugFD, (_msg1), (_msg2), (_msg3), (_msg4))
#define PRINT_DEBUG_MSG5(_msg1, _msg2, _msg3, _msg4, _msg5) fprintf(mDebugFD, (_msg1), (_msg2), (_msg3), (_msg4), (_msg5))
#else //--------------
#define PRINT_DEBUG_MSG1(_msg)
#define PRINT_DEBUG_MSG2(_msg1, _msg2)
#define PRINT_DEBUG_MSG3(_msg1, _msg2, _msg3)
#define PRINT_DEBUG_MSG4(_msg1, _msg2, _msg3, _msg4)
#define PRINT_DEBUG_MSG5(_msg1, _msg2, _msg3, _msg4, _msg5)
#endif
nsresult
NS_NewSimplePageSequenceFrame(nsIPresShell* aPresShell, nsIFrame** aNewFrame)
{
@ -83,7 +101,14 @@ nsSimplePageSequenceFrame::nsSimplePageSequenceFrame() :
printService->GetPrintRange(&printType);
mIsPrintingSelection = nsIPrintOptions::kRangeSelection == printType;
}
mSkipPageBegin = PR_FALSE;
mSkipPageEnd = PR_FALSE;
mPrintThisPage = PR_FALSE;
mOffsetX = 0;
mOffsetY = 0;
#ifdef NS_DEBUG
mDebugFD = stdout;
#endif
}
nsSimplePageSequenceFrame::~nsSimplePageSequenceFrame()
@ -247,9 +272,28 @@ nsSimplePageSequenceFrame::Reflow(nsIPresContext* aPresContext,
// Compute the size of each page and the x coordinate that each page will
// be placed at
nsSize pageSize;
aPresContext->GetPageWidth(&pageSize.width);
aPresContext->GetPageHeight(&pageSize.height);
nsRect pageSize;
nsRect adjSize;
aPresContext->GetPageDim(&pageSize, &adjSize);
PRBool suppressLeftMargin = PR_FALSE;
PRBool suppressRightMargin = PR_FALSE;
PRBool suppressTopMargin = PR_FALSE;
PRBool suppressBottomMargin = PR_FALSE;
if (pageSize != adjSize &&
(adjSize.x != 0 || adjSize.y != 0 || adjSize.width != 0 || adjSize.height != 0)) {
suppressLeftMargin = pageSize.x != adjSize.x;
suppressTopMargin = pageSize.y != adjSize.y;
if (pageSize.width != adjSize.width) {
suppressRightMargin = PR_TRUE;
pageSize.width = adjSize.width;
}
if (pageSize.height != adjSize.height) {
suppressBottomMargin = PR_TRUE;
pageSize.height = adjSize.height;
}
}
// XXX - Hack Alert
// OK, so ther eis a selection, we will print the entire selection
@ -261,10 +305,15 @@ nsSimplePageSequenceFrame::Reflow(nsIPresContext* aPresContext,
pageSize.height = 0x0FFFFFFF;
}
nscoord x = mMargin.left;
// only use this local margin for sizing,
// not for positioning
nsMargin margin(suppressLeftMargin?0:mMargin.left,
suppressTopMargin?0:mMargin.top,
suppressRightMargin?0:mMargin.right,
suppressBottomMargin?0:mMargin.bottom);
// Running y-offset for each page
nscoord y = mMargin.top;
nscoord x = mMargin.left;
nscoord y = mMargin.top;// Running y-offset for each page
// See if it's an incremental reflow command
if (eReflowReason_Incremental == aReflowState.reason) {
@ -279,11 +328,12 @@ nsSimplePageSequenceFrame::Reflow(nsIPresContext* aPresContext,
nsHTMLReflowMetrics kidSize(nsnull);
for (nsIFrame* kidFrame = mFrames.FirstChild(); nsnull != kidFrame; ) {
// Reflow the page
nsSize availSize(pageSize.width, pageSize.height);
nsHTMLReflowState kidReflowState(aPresContext, aReflowState, kidFrame,
pageSize, reflowReason);
availSize, reflowReason);
nsReflowStatus status;
kidReflowState.availableWidth = pageSize.width - mMargin.left - mMargin.right;
kidReflowState.availableHeight = pageSize.height - mMargin.top - mMargin.bottom;
kidReflowState.availableWidth = pageSize.width - margin.left - margin.right;
kidReflowState.availableHeight = pageSize.height - margin.top - margin.bottom;
kidReflowState.mComputedWidth = kidReflowState.availableWidth;
//kidReflowState.mComputedHeight = kidReflowState.availableHeight;
@ -371,272 +421,8 @@ nsSimplePageSequenceFrame::Print(nsIPresContext* aPresContext,
nsIPrintOptions* aPrintOptions,
nsIPrintStatusCallback* aStatusCallback)
{
NS_ENSURE_ARG_POINTER(aPresContext);
NS_ENSURE_ARG_POINTER(aPrintOptions);
PRInt32 printRangeType;
PRInt32 fromPageNum;
PRInt32 toPageNum;
PRBool printEvenPages, printOddPages;
PRInt16 printType;
aPrintOptions->GetPrintRange(&printType);
printRangeType = printType;
aPrintOptions->GetStartPageRange(&fromPageNum);
aPrintOptions->GetEndPageRange(&toPageNum);
aPrintOptions->GetMarginInTwips(mMargin);
aPrintOptions->GetPrintOptions(nsIPrintOptions::kOptPrintEvenPages, &printEvenPages);
aPrintOptions->GetPrintOptions(nsIPrintOptions::kOptPrintOddPages, &printOddPages);
PRBool doingPageRange = nsIPrintOptions::kRangeSpecifiedPageRange == printRangeType ||
nsIPrintOptions::kRangeSelection == printRangeType;
// If printing a range of pages make sure at least the starting page
// number is valid
PRInt32 totalPages = mFrames.GetLength();
if (doingPageRange) {
if (fromPageNum > totalPages) {
return NS_ERROR_INVALID_ARG;
}
}
// Begin printing of the document
nsCOMPtr<nsIDeviceContext> dc;
aPresContext->GetDeviceContext(getter_AddRefs(dc));
nsCOMPtr<nsIPresShell> presShell;
aPresContext->GetShell(getter_AddRefs(presShell));
nsCOMPtr<nsIViewManager> vm;
presShell->GetViewManager(getter_AddRefs(vm));
nsresult rv = NS_OK;
#if defined(DEBUG_rods) || defined(DEBUG_dcone)
{
nsIView * seqView;
GetView(aPresContext, &seqView);
nsRect rect;
GetRect(rect);
printf("Seq Frame: - %d,%d,%d,%d ", rect.x, rect.y, rect.width, rect.height);
printf("view: %p ", seqView);
nsRect viewRect;
if (seqView) {
seqView->GetBounds(viewRect);
printf(" %d,%d,%d,%d", viewRect.x, viewRect.y, viewRect.width, viewRect.height);
}
printf("\n");
}
{
PRInt32 pageNum = 1;
for (nsIFrame* page = mFrames.FirstChild(); nsnull != page; page->GetNextSibling(&page)) {
nsIView* view;
page->GetView(aPresContext, &view);
NS_ASSERTION(nsnull != view, "no page view");
nsRect rect;
page->GetRect(rect);
nsRect viewRect;
view->GetBounds(viewRect);
printf("Page: %d - %d,%d,%d,%d ", pageNum, rect.x, rect.y, rect.width, rect.height);
printf(" %d,%d,%d,%d\n", viewRect.x, viewRect.y, viewRect.width, viewRect.height);
pageNum++;
}
}
printf("***** Setting aPresContext %p is painting selection %d\n", aPresContext, nsIPrintOptions::kRangeSelection == printRangeType);
#endif
// Determine if we are rendering only the selection
aPresContext->SetIsRenderingOnlySelection(nsIPrintOptions::kRangeSelection == printRangeType);
if (doingPageRange) {
// 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;
dc->GetDeviceSurfaceDimensions(width,height);
height -= mMargin.top + mMargin.bottom;
PRInt32 pageNum = 1;
nscoord y = mMargin.top;
for (nsIFrame* page = mFrames.FirstChild(); nsnull != page; page->GetNextSibling(&page)) {
nsIView* view;
page->GetView(aPresContext, &view);
NS_ASSERTION(nsnull != view, "no page view");
if (pageNum < fromPageNum || pageNum > toPageNum) {
// XXX Doesn't seem like we need to do this
// because we ask only the pages we want to print
//view->SetVisibility(nsViewVisibility_kHide);
} else {
nsRect rect;
page->GetRect(rect);
rect.y = y;
rect.height = height;
page->SetRect(aPresContext, rect);
nsRect viewRect;
view->GetBounds(viewRect);
viewRect.y = y;
viewRect.height = height;
view->SetBounds(viewRect);
y += rect.height + mMargin.top + mMargin.bottom;
}
pageNum++;
}
// adjust total number of pages
if (nsIPrintOptions::kRangeSelection == printRangeType) {
totalPages = toPageNum - fromPageNum + 1;
} else {
totalPages = pageNum - 1;
}
}
// XXX - This wouldn't have to be done each time
// but it isn't that expensive and this the best place
// to have access to a localized file properties file
//
// Note: because this is done here it makes a little bit harder
// to have UI for setting the header/footer font name and size
//
// Get default font name and size to be used for the headers and footers
nsAutoString fontName;
rv = nsFormControlHelper::GetLocalizedString(PRINTING_PROPERTIES, "fontname", fontName);
if (NS_FAILED(rv)) {
fontName.AssignWithConversion("serif");
}
nsAutoString fontSizeStr;
nscoord pointSize = 10;;
rv = nsFormControlHelper::GetLocalizedString(PRINTING_PROPERTIES, "fontsize", fontSizeStr);
if (NS_SUCCEEDED(rv)) {
PRInt32 errCode;
pointSize = fontSizeStr.ToInteger(&errCode);
if (NS_FAILED(errCode)) {
pointSize = 10;
}
}
aPrintOptions->SetFontNamePointSize(fontName, pointSize);
// Now go get the Localized Page Formating String
PRBool doingPageTotals = PR_TRUE;
aPrintOptions->GetPrintOptions(nsIPrintOptions::kOptPrintPageTotal, &doingPageTotals);
nsAutoString pageFormatStr;
rv = nsFormControlHelper::GetLocalizedString(PRINTING_PROPERTIES,
doingPageTotals?"pageofpages":"pagenumber",
pageFormatStr);
if (NS_FAILED(rv)) { // back stop formatting
pageFormatStr.AssignWithConversion(doingPageTotals?"%ld of %ld":"%ld");
}
// Sets the format into a static data memeber which will own the memory and free it
nsPageFrame::SetPageNumberFormat(pageFormatStr.ToNewUnicode());
// Print each specified page
// pageNum keeps track of the current page and what pages are printing
//
// printedPageNum keeps track of the current page number to be printed
// Note: When print al the pages or a page range the printed page shows the
// actual page number, when printing selection it prints the page number starting
// with the first page of the selection. For example if the user has a
// selection that starts on page 2 and ends on page 3, the page numbers when
// print are 1 and then two (which is different than printing a page range, where
// the page numbers would have been 2 and then 3)
PRInt32 pageNum = 1;
PRInt32 printedPageNum = 1;
for (nsIFrame* page = mFrames.FirstChild(); nsnull != page; page->GetNextSibling(&page)) {
// See whether we should print this page
PRBool printThisPage = PR_TRUE;
// If printing a range of pages check whether the page number is in the
// range of pages to print
if (doingPageRange) {
if (pageNum < fromPageNum) {
printThisPage = PR_FALSE;
} else if (pageNum > toPageNum) {
break;
}
}
// Check for printing of odd and even pages
if (pageNum & 0x1) {
if (!printOddPages) {
printThisPage = PR_FALSE; // don't print odd numbered page
}
} else {
if (!printEvenPages) {
printThisPage = PR_FALSE; // don't print even numbered page
}
}
if (printThisPage) {
// Start printing of the page
if (!SendStatusNotification(aStatusCallback, pageNum, totalPages,
ePrintStatus_StartPage)) {
rv = NS_ERROR_ABORT;
break;
}
rv = dc->BeginPage();
if (NS_FAILED(rv)) {
if (nsnull != aStatusCallback) {
aStatusCallback->OnError(ePrintError_Error);
}
break;
}
// cast the frame to be a page frame
nsPageFrame * pf = NS_STATIC_CAST(nsPageFrame*, page);
if (pf != nsnull) {
pf->SetPrintOptions(aPrintOptions);
pf->SetPageNumInfo(printedPageNum, totalPages);
}
// Print the page
nsIView* view;
page->GetView(aPresContext, &view);
NS_ASSERTION(nsnull != view, "no page view");
#if defined(DEBUG_rods) || defined(DEBUG_dcone)
{
char * fontname = fontName.ToNewCString();
printf("SPSF::Paint -> FontName[%s] Point Size: %d\n", fontname, pointSize);
nsMemory::Free(fontname);
printf("SPSF::Paint -> PageNo: %d View: %p\n", pageNum, view);
}
#endif
vm->Display(view, mMargin.left, mMargin.top);
// this view was printed and since display set the origin
// 0,0 there is a danger that this view can be printed again
// If it is a sibling to another page/view. Setting the visibility
// to hide will keep this page from printing again - dwc
//
// XXX Doesn't seem like we need to do this anymore
//view->SetVisibility(nsViewVisibility_kHide);
// Finish printing of the page
if (!SendStatusNotification(aStatusCallback, pageNum, totalPages,
ePrintStatus_EndPage)) {
rv = NS_ERROR_ABORT;
break;
}
rv = dc->EndPage();
if (NS_FAILED(rv)) {
if (nsnull != aStatusCallback) {
aStatusCallback->OnError(ePrintError_Error);
}
break;
}
}
if (nsIPrintOptions::kRangeSelection != printRangeType ||
(nsIPrintOptions::kRangeSelection == printRangeType && printThisPage)) {
printedPageNum++;
}
pageNum++;
}
return rv;
NS_ASSERTION(0, "No longer being used.");
return NS_ERROR_FAILURE;
}
NS_IMETHODIMP
@ -736,14 +522,14 @@ nsSimplePageSequenceFrame::StartPrint(nsIPresContext* aPresContext,
GetView(aPresContext, &seqView);
nsRect rect;
GetRect(rect);
printf("Seq Frame: - %d,%d,%d,%d ", rect.x, rect.y, rect.width, rect.height);
printf("view: %p ", seqView);
fprintf(mDebugFD, "Seq Frame: %p - [%5d,%5d,%5d,%5d] ", this, rect.x, rect.y, rect.width, rect.height);
fprintf(mDebugFD, "view: %p ", seqView);
nsRect viewRect;
if (seqView) {
seqView->GetBounds(viewRect);
printf(" %d,%d,%d,%d", viewRect.x, viewRect.y, viewRect.width, viewRect.height);
fprintf(mDebugFD, " [%5d,%5d,%5d,%5d]", viewRect.x, viewRect.y, viewRect.width, viewRect.height);
}
printf("\n");
fprintf(mDebugFD, "\n");
}
{
@ -756,12 +542,12 @@ nsSimplePageSequenceFrame::StartPrint(nsIPresContext* aPresContext,
page->GetRect(rect);
nsRect viewRect;
view->GetBounds(viewRect);
printf("Page: %d - %d,%d,%d,%d ", pageNum, rect.x, rect.y, rect.width, rect.height);
printf(" %d,%d,%d,%d\n", viewRect.x, viewRect.y, viewRect.width, viewRect.height);
fprintf(mDebugFD, " Page: %p No: %d - [%5d,%5d,%5d,%5d] ", page, pageNum, rect.x, rect.y, rect.width, rect.height);
fprintf(mDebugFD, " [%5d,%5d,%5d,%5d]\n", viewRect.x, viewRect.y, viewRect.width, viewRect.height);
pageNum++;
}
}
printf("***** Setting aPresContext %p is painting selection %d\n", aPresContext, nsIPrintOptions::kRangeSelection == mPrintRangeType);
//printf("***** Setting aPresContext %p is painting selection %d\n", aPresContext, nsIPrintOptions::kRangeSelection == mPrintRangeType);
#endif
// Determine if we are rendering only the selection
@ -901,13 +687,13 @@ nsSimplePageSequenceFrame::PrintNextPage(nsIPresContext* aPresContext,
nsresult rv = NS_OK;
// See whether we should print this page
PRBool printThisPage = PR_TRUE;
mPrintThisPage = PR_TRUE;
// If printing a range of pages check whether the page number is in the
// range of pages to print
if (mDoingPageRange) {
if (mPageNum < mFromPageNum) {
printThisPage = PR_FALSE;
mPrintThisPage = PR_FALSE;
} else if (mPageNum > mToPageNum) {
mPageNum++;
mCurrentPageFrame = nsnull;
@ -918,18 +704,21 @@ nsSimplePageSequenceFrame::PrintNextPage(nsIPresContext* aPresContext,
// Check for printing of odd and even pages
if (mPageNum & 0x1) {
if (!printOddPages) {
printThisPage = PR_FALSE; // don't print odd numbered page
mPrintThisPage = PR_FALSE; // don't print odd numbered page
}
} else {
if (!printEvenPages) {
printThisPage = PR_FALSE; // don't print even numbered page
mPrintThisPage = PR_FALSE; // don't print even numbered page
}
}
if (printThisPage) {
rv = dc->BeginPage();
if (NS_FAILED(rv)) {
return rv;
if (mPrintThisPage) {
if (!mSkipPageBegin) {
PRINT_DEBUG_MSG1("\n***************** BeginPage *****************\n");
rv = dc->BeginPage();
if (NS_FAILED(rv)) {
return rv;
}
}
// cast the frame to be a page frame
@ -944,12 +733,11 @@ nsSimplePageSequenceFrame::PrintNextPage(nsIPresContext* aPresContext,
mCurrentPageFrame->GetView(aPresContext, &view);
NS_ASSERTION(nsnull != view, "no page view");
#if defined(DEBUG_rods) || defined(DEBUG_dcone)
{
printf("SPSF::Paint(Async) -> PageNo: %d View: %p\n", mPageNum, view);
}
#endif
vm->Display(view, mMargin.left, mMargin.top);
PRINT_DEBUG_MSG4("SeqFr::Paint -> %p PageNo: %d View: %p", pf, mPageNum, view);
PRINT_DEBUG_MSG3(" At: %d,%d\n", mMargin.left+mOffsetX, mMargin.top+mOffsetY);
vm->Display(view, mMargin.left+mOffsetX, mMargin.top+mOffsetY);
// this view was printed and since display set the origin
@ -960,20 +748,87 @@ nsSimplePageSequenceFrame::PrintNextPage(nsIPresContext* aPresContext,
// XXX Doesn't seem like we need to do this anymore
//view->SetVisibility(nsViewVisibility_kHide);
rv = dc->EndPage();
if (!mSkipPageEnd) {
PRINT_DEBUG_MSG1("***************** End Page (PrintNextPage) *****************\n");
rv = dc->EndPage();
if (NS_FAILED(rv)) {
return rv;
}
}
}
if (!mSkipPageEnd) {
if (nsIPrintOptions::kRangeSelection != mPrintRangeType ||
(nsIPrintOptions::kRangeSelection == mPrintRangeType && mPrintThisPage)) {
mPrintedPageNum++;
}
mPageNum++;
rv = mCurrentPageFrame->GetNextSibling(&mCurrentPageFrame);
}
return rv;
}
NS_IMETHODIMP
nsSimplePageSequenceFrame::DoPageEnd(nsIPresContext* aPresContext)
{
if (mPrintThisPage) {
nsCOMPtr<nsIDeviceContext> dc;
aPresContext->GetDeviceContext(getter_AddRefs(dc));
NS_ASSERTION(dc, "nsIDeviceContext can't be NULL!");
PRINT_DEBUG_MSG1("***************** End Page (DoPageEnd) *****************\n");
nsresult rv = dc->EndPage();
if (NS_FAILED(rv)) {
return rv;
}
}
if (nsIPrintOptions::kRangeSelection != mPrintRangeType ||
(nsIPrintOptions::kRangeSelection == mPrintRangeType && printThisPage)) {
(nsIPrintOptions::kRangeSelection == mPrintRangeType && mPrintThisPage)) {
mPrintedPageNum++;
}
mPageNum++;
rv = mCurrentPageFrame->GetNextSibling(&mCurrentPageFrame);
return rv;
return mCurrentPageFrame->GetNextSibling(&mCurrentPageFrame);
}
NS_IMETHODIMP
nsSimplePageSequenceFrame::SuppressHeadersAndFooters(PRBool aDoSup)
{
for (nsIFrame* f = mFrames.FirstChild(); f != nsnull; f->GetNextSibling(&f)) {
nsPageFrame * pf = NS_STATIC_CAST(nsPageFrame*, f);
if (pf != nsnull) {
pf->SuppressHeadersAndFooters(aDoSup);
}
}
return NS_OK;
}
NS_IMETHODIMP
nsSimplePageSequenceFrame::SetClipRect(nsIPresContext* aPresContext, nsRect* aRect)
{
for (nsIFrame* f = mFrames.FirstChild(); f != nsnull; f->GetNextSibling(&f)) {
nsPageFrame * pf = NS_STATIC_CAST(nsPageFrame*, f);
if (pf != nsnull) {
pf->SetClipRect(aRect);
}
}
return NS_OK;
}
#ifdef NS_DEBUG
NS_IMETHODIMP
nsSimplePageSequenceFrame::SetDebugFD(FILE* aFD)
{
mDebugFD = aFD;
for (nsIFrame* f = mFrames.FirstChild(); f != nsnull; f->GetNextSibling(&f)) {
nsPageFrame * pf = NS_STATIC_CAST(nsPageFrame*, f);
if (pf != nsnull) {
pf->SetDebugFD(aFD);
}
}
return NS_OK;
}
#endif

Просмотреть файл

@ -57,10 +57,19 @@ public:
NS_IMETHOD GetNumPages(PRInt32* aNumPages);
NS_IMETHOD IsDoingPrintRange(PRBool* aDoing);
NS_IMETHOD GetPrintRange(PRInt32* aFromPage, PRInt32* aToPage);
NS_IMETHOD SkipPageBegin() { mSkipPageBegin = PR_TRUE; return NS_OK; }
NS_IMETHOD SkipPageEnd() { mSkipPageEnd = PR_TRUE; return NS_OK; }
NS_IMETHOD DoPageEnd(nsIPresContext* aPresContext);
NS_IMETHOD GetPrintThisPage(PRBool* aPrintThisPage) { *aPrintThisPage = mPrintThisPage; return NS_OK; }
NS_IMETHOD SetOffset(nscoord aX, nscoord aY) { mOffsetX = aX; mOffsetY = aY; return NS_OK; }
NS_IMETHOD SuppressHeadersAndFooters(PRBool aDoSup);
NS_IMETHOD SetClipRect(nsIPresContext* aPresContext, nsRect* aSize);
#ifdef DEBUG
#ifdef NS_DEBUG
// Debugging
NS_IMETHOD GetFrameName(nsString& aResult) const;
NS_IMETHOD SetDebugFD(FILE* aFD);
FILE * mDebugFD;
#endif
protected:
@ -94,6 +103,13 @@ protected:
PRInt32 mPrintRangeType;
PRInt32 mFromPageNum;
PRInt32 mToPageNum;
PRPackedBool mSkipPageBegin;
PRPackedBool mSkipPageEnd;
PRPackedBool mPrintThisPage;
PRPackedBool mSupressHF;
nscoord mOffsetX;
nscoord mOffsetY;
};

Просмотреть файл

@ -3009,14 +3009,15 @@ nsTableFrame::ReflowChildren(nsIPresContext* aPresContext,
// set the repeatablility of headers and footers in the original table during its first reflow
// the repeatability of header and footers on continued tables is handled when they are created
if (isPaginated && !mPrevInFlow && (NS_UNCONSTRAINEDSIZE == aReflowState.availSize.height)) {
nscoord pageHeight;
aPresContext->GetPageHeight(&pageHeight);
nsRect actualRect;
nsRect adjRect;
aPresContext->GetPageDim(&actualRect, &adjRect);
// don't repeat the thead or tfoot unless it is < 25% of the page height
if (thead) {
thead->SetRepeatable(IsRepeatable(*thead, pageHeight));
thead->SetRepeatable(IsRepeatable(*thead, actualRect.height));
}
if (tfoot) {
tfoot->SetRepeatable(IsRepeatable(*tfoot, pageHeight));
tfoot->SetRepeatable(IsRepeatable(*tfoot, actualRect.height));
}
}

Просмотреть файл

@ -823,8 +823,10 @@ nsTableRowGroupFrame::SplitRowGroup(nsIPresContext* aPresContext,
nsRect bounds;
rowFrame->GetRect(bounds);
if (bounds.YMost() > availHeight) {
nscoord pageHeight;
aPresContext->GetPageHeight(&pageHeight);
nsRect actualRect;
nsRect adjRect;
aPresContext->GetPageDim(&actualRect, &adjRect);
nscoord pageHeight = actualRect.height;
// reflow the row in the availabe space and have it split if it is the 1st
// row or there is at least 20% of the current page available
if (!prevRowFrame || (availHeight - heightTaken > pageHeight / 5)) {

Просмотреть файл

@ -3009,14 +3009,15 @@ nsTableFrame::ReflowChildren(nsIPresContext* aPresContext,
// set the repeatablility of headers and footers in the original table during its first reflow
// the repeatability of header and footers on continued tables is handled when they are created
if (isPaginated && !mPrevInFlow && (NS_UNCONSTRAINEDSIZE == aReflowState.availSize.height)) {
nscoord pageHeight;
aPresContext->GetPageHeight(&pageHeight);
nsRect actualRect;
nsRect adjRect;
aPresContext->GetPageDim(&actualRect, &adjRect);
// don't repeat the thead or tfoot unless it is < 25% of the page height
if (thead) {
thead->SetRepeatable(IsRepeatable(*thead, pageHeight));
thead->SetRepeatable(IsRepeatable(*thead, actualRect.height));
}
if (tfoot) {
tfoot->SetRepeatable(IsRepeatable(*tfoot, pageHeight));
tfoot->SetRepeatable(IsRepeatable(*tfoot, actualRect.height));
}
}

Просмотреть файл

@ -823,8 +823,10 @@ nsTableRowGroupFrame::SplitRowGroup(nsIPresContext* aPresContext,
nsRect bounds;
rowFrame->GetRect(bounds);
if (bounds.YMost() > availHeight) {
nscoord pageHeight;
aPresContext->GetPageHeight(&pageHeight);
nsRect actualRect;
nsRect adjRect;
aPresContext->GetPageDim(&actualRect, &adjRect);
nscoord pageHeight = actualRect.height;
// reflow the row in the availabe space and have it split if it is the 1st
// row or there is at least 20% of the current page available
if (!prevRowFrame || (availHeight - heightTaken > pageHeight / 5)) {

Просмотреть файл

@ -65,7 +65,7 @@ function initDialog()
dialog.topageInput = document.getElementById("topageInput");
dialog.topageLabel = document.getElementById("topageLabel");
dialog.aslayedoutRadio = document.getElementById("aslayedoutRadio");
dialog.aslaidoutRadio = document.getElementById("aslaidoutRadio");
dialog.selectedframeRadio = document.getElementById("selectedframeRadio");
dialog.eachframesepRadio = document.getElementById("eachframesepRadio");
dialog.printrangeGroupLabel = document.getElementById("printrangeGroupLabel");
@ -126,9 +126,9 @@ function doPrintToFile( value )
}
//---------------------------------------------------
function doPrintRange( value )
function doPrintRange( inx )
{
if ( value) {
if ( inx == 1 ) {
dialog.frompageInput.removeAttribute("disabled");
dialog.frompageLabel.removeAttribute("disabled");
dialog.topageInput.removeAttribute("disabled");
@ -277,9 +277,7 @@ function loadDialog()
// print frame
if (print_howToEnableUI == gPrintOptInterface.kFrameEnableAll) {
// XXX this is just temporary until we have impemented "AsIs"
dialog.aslayedoutRadio.setAttribute("disabled","true" );
//dialog.aslayedoutRadio.removeAttribute("disabled");
dialog.aslaidoutRadio.removeAttribute("disabled");
dialog.selectedframeRadio.removeAttribute("disabled");
dialog.eachframesepRadio.removeAttribute("disabled");
@ -289,9 +287,7 @@ function loadDialog()
dialog.selectedframeRadio.checked = true;
} else if (print_howToEnableUI == gPrintOptInterface.kFrameEnableAsIsAndEach) {
// XXX this is just temporary until we have impemented "AsIs"
dialog.aslayedoutRadio.setAttribute("disabled","true" );
//dialog.aslayedoutRadio.removeAttribute("disabled"); //enable
dialog.aslaidoutRadio.removeAttribute("disabled"); //enable
dialog.selectedframeRadio.setAttribute("disabled","true" ); // disable
dialog.eachframesepRadio.removeAttribute("disabled"); // enable
@ -301,7 +297,7 @@ function loadDialog()
dialog.eachframesepRadio.checked = true;
} else {
dialog.aslayedoutRadio.setAttribute("disabled","true" );
dialog.aslaidoutRadio.setAttribute("disabled","true" );
dialog.selectedframeRadio.setAttribute("disabled","true" );
dialog.eachframesepRadio.setAttribute("disabled","true" );
dialog.printrangeGroupLabel.setAttribute("disabled","true" );
@ -341,10 +337,12 @@ function onOK()
var print_paper_size = 0;
if (printService) {
var print_howToEnableUI = gPrintOptInterface.kFrameEnableNone;
printService.printToFile = dialog.fileRadio.checked;
printService.printReversed = dialog.lastRadio.checked;
printService.printInColor = dialog.colorRadio.checked;
print_howToEnableUI = printService.howToEnableFrameUI;
if (dialog.letterRadio.checked) {
print_paper_size = gPrintOptInterface.kLetterPaperSize;
@ -376,15 +374,17 @@ function onOK()
printService.startPageRange = dialog.frompageInput.value;
printService.endPageRange = dialog.topageInput.value;
var frametype;
if (dialog.aslayedoutRadio.checked) {
frametype = gPrintOptInterface.kFramesAsIs;
} else if (dialog.selectedframeRadio.checked) {
frametype = gPrintOptInterface.kSelectedFrame;
} else if (dialog.eachframesepRadio.checked) {
frametype = gPrintOptInterface.kEachFrameSep;
} else {
frametype = gPrintOptInterface.kSelectedFrame;
var frametype = gPrintOptInterface.kNoFrames;
if (print_howToEnableUI != gPrintOptInterface.kFrameEnableNone) {
if (dialog.aslaidoutRadio.checked) {
frametype = gPrintOptInterface.kFramesAsIs;
} else if (dialog.selectedframeRadio.checked) {
frametype = gPrintOptInterface.kSelectedFrame;
} else if (dialog.eachframesepRadio.checked) {
frametype = gPrintOptInterface.kEachFrameSep;
} else {
frametype = gPrintOptInterface.kSelectedFrame;
}
}
printService.printFrameType = frametype;
} else {

Просмотреть файл

@ -90,21 +90,21 @@ Contributor(s): Masaki Katakai <katakai@japan.sun.com>
<row>
<text class="label" value="&printrangeGroup.label;" flex ="1"/>
<radiogroup id="printrangeGroup" orient="vertical">
<radio group = "printrangeGroup" id = "allpagesRadio" label = "&allpagesRadio.label;" onclick = "doPrintRange(!document.getElementById('rangeRadio').checked);"/>
<radio group = "printrangeGroup" id = "allpagesRadio" label = "&allpagesRadio.label;" onclick = "doPrintRange(0);"/>
<box orient="horizontal" autostretch="never">
<radio group = "printrangeGroup" id = "rangeRadio" label = "&rangeRadio.label;" onclick = "doPrintRange(!this.checked);"/>
<radio group = "printrangeGroup" id = "rangeRadio" label = "&rangeRadio.label;" onclick = "doPrintRange(1);"/>
<text class = "label" id = "frompageLabel" for = "frompageInput" value = "&frompageInput.label;" />
<textbox id = "frompageInput" style = "width:5em;" onkeyup="checkValid(this.id)"/>
<text class = "label" id = "topageLabel" for = "topageInput" value = "&topageInput.label;" />
<textbox id = "topageInput" style = "width:5em;" onkeyup="checkValid(this.id)"/>
</box>
<radio group = "printrangeGroup" id = "selectionRadio" label = "&selectionRadio.label;" onclick = "doPrintRange(!document.getElementById('rangeRadio').checked);"/>
<radio group = "printrangeGroup" id = "selectionRadio" label = "&selectionRadio.label;" onclick = "doPrintRange(2);"/>
</radiogroup>
</row>
<row>
<text class="label" value="&printframeGroup.label;" id="printrangeGroupLabel" flex ="1"/>
<radiogroup id="printrangeGroup" orient="vertical">
<radio group = "printrangeGroup" id = "aslayedoutRadio" label = "&aslayedoutRadio.label;" />
<radio group = "printrangeGroup" id = "aslaidoutRadio" label = "&aslaidoutRadio.label;" />
<radio group = "printrangeGroup" id = "selectedframeRadio" label = "&selectedframeRadio.label;" />
<radio group = "printrangeGroup" id = "eachframesepRadio" label = "&eachframesepRadio.label;" />
</radiogroup>
@ -143,6 +143,6 @@ Contributor(s): Masaki Katakai <katakai@japan.sun.com>
<!-- Places to overlay common dialog buttons and keyset -->
<box id="okCancelButtons"/>
<keyset id="dialogKeys"/>
<keyset id="keyset"/>
</window>

Просмотреть файл

@ -36,7 +36,7 @@
<!ENTITY selectionRadio.label "Selection">
<!ENTITY printframeGroup.label "Print Frames:">
<!ENTITY aslayedoutRadio.label "As laid out on the screen">
<!ENTITY aslaidoutRadio.label "As laid out on the screen">
<!ENTITY selectedframeRadio.label "The selected frame">
<!ENTITY eachframesepRadio.label "Each frame separately">