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
Родитель 3167410fab
Коммит be33a15835
28 изменённых файлов: 4643 добавлений и 1966 удалений

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

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

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

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

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

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

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

@ -349,14 +349,24 @@ public:
NS_IMETHOD IsPaginated(PRBool* aResult) = 0; 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; NS_IMETHOD GetPixelsToTwips(float* aResult) const = 0;

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

@ -24,6 +24,7 @@
#include "nslayout.h" #include "nslayout.h"
#include "nsISupports.h" #include "nsISupports.h"
#include "nsRect.h"
class nsIPresContext; class nsIPresContext;
class nsIPrintOptions; class nsIPrintOptions;
@ -128,6 +129,15 @@ public:
NS_IMETHOD IsDoingPrintRange(PRBool* aDoing) = 0; NS_IMETHOD IsDoingPrintRange(PRBool* aDoing) = 0;
NS_IMETHOD GetPrintRange(PRInt32* aFromPage, PRInt32* aToPage) = 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: private:
NS_IMETHOD_(nsrefcnt) AddRef(void) = 0; NS_IMETHOD_(nsrefcnt) AddRef(void) = 0;
NS_IMETHOD_(nsrefcnt) Release(void) = 0; NS_IMETHOD_(nsrefcnt) Release(void) = 0;

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

@ -349,14 +349,24 @@ public:
NS_IMETHOD IsPaginated(PRBool* aResult) = 0; 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; NS_IMETHOD GetPixelsToTwips(float* aResult) const = 0;

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

@ -349,14 +349,24 @@ public:
NS_IMETHOD IsPaginated(PRBool* aResult) = 0; 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; NS_IMETHOD GetPixelsToTwips(float* aResult) const = 0;

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

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

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

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

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

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

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

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

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

@ -24,6 +24,7 @@
#include "nslayout.h" #include "nslayout.h"
#include "nsISupports.h" #include "nsISupports.h"
#include "nsRect.h"
class nsIPresContext; class nsIPresContext;
class nsIPrintOptions; class nsIPrintOptions;
@ -128,6 +129,15 @@ public:
NS_IMETHOD IsDoingPrintRange(PRBool* aDoing) = 0; NS_IMETHOD IsDoingPrintRange(PRBool* aDoing) = 0;
NS_IMETHOD GetPrintRange(PRInt32* aFromPage, PRInt32* aToPage) = 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: private:
NS_IMETHOD_(nsrefcnt) AddRef(void) = 0; NS_IMETHOD_(nsrefcnt) AddRef(void) = 0;
NS_IMETHOD_(nsrefcnt) Release(void) = 0; NS_IMETHOD_(nsrefcnt) Release(void) = 0;

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

@ -53,6 +53,24 @@ static NS_DEFINE_CID(kLocaleServiceCID, NS_LOCALESERVICE_CID);
// tstaic data members // tstaic data members
PRUnichar * nsPageFrame::mPageNumFormat = nsnull; 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 nsresult
NS_NewPageFrame(nsIPresShell* aPresShell, nsIFrame** aNewFrame) NS_NewPageFrame(nsIPresShell* aPresShell, nsIFrame** aNewFrame)
{ {
@ -69,8 +87,14 @@ NS_NewPageFrame(nsIPresShell* aPresShell, nsIFrame** aNewFrame)
} }
nsPageFrame::nsPageFrame() : nsPageFrame::nsPageFrame() :
mHeadFootFont(nsnull) mHeadFootFont(nsnull),
mSupressHF(PR_FALSE),
mClipRect(-1, -1, -1, -1)
{ {
#ifdef NS_DEBUG
mDebugFD = stdout;
#endif
} }
nsPageFrame::~nsPageFrame() nsPageFrame::~nsPageFrame()
@ -174,11 +198,15 @@ NS_METHOD nsPageFrame::Reflow(nsIPresContext* aPresContext,
NS_ASSERTION(nsnull == childNextInFlow, "bad child flow list"); 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 // Return our desired size
aDesiredSize.width = aReflowState.availableWidth; aDesiredSize.width = aReflowState.availableWidth;
aDesiredSize.height = aReflowState.availableHeight; aDesiredSize.height = aReflowState.availableHeight;
} }
PRINT_DEBUG_MSG2("PageFrame::Reflow %p ", this);
PRINT_DEBUG_MSG3("[%d,%d]\n", aReflowState.availableWidth, aReflowState.availableHeight);
return NS_OK; return NS_OK;
} }
@ -254,6 +282,7 @@ nsPageFrame::DrawHeaderFooter(nsIRenderingContext& aRenderingContext,
nscoord aHeight, nscoord aHeight,
PRBool aUseHalfThePage) PRBool aUseHalfThePage)
{ {
// first make sure we have a vaild string and that the height of the // first make sure we have a vaild string and that the height of the
// text will fit in the margin // text will fit in the margin
if (aStr.Length() > 0 && if (aStr.Length() > 0 &&
@ -300,6 +329,25 @@ nsPageFrame::DrawHeaderFooter(nsIRenderingContext& aRenderingContext,
aRenderingContext.SetClipRect(rect, nsClipCombine_kReplace, clipEmpty); aRenderingContext.SetClipRect(rect, nsClipCombine_kReplace, clipEmpty);
aRenderingContext.DrawString(str, x, y); aRenderingContext.DrawString(str, x, y);
aRenderingContext.PopState(clipEmpty); 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, const nsRect& aDirtyRect,
nsFramePaintLayer aWhichLayer) 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); nsresult rv = nsContainerFrame::Paint(aPresContext, aRenderingContext, aDirtyRect, aWhichLayer);
#if defined(DEBUG_rods) || defined(DEBUG_dcone)
if (NS_FRAME_PAINT_LAYER_FOREGROUND == aWhichLayer) { 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 // get the current margin
mPrintOptions->GetMarginInTwips(mMargin); mPrintOptions->GetMarginInTwips(mMargin);
@ -325,9 +394,9 @@ nsPageFrame::Paint(nsIPresContext* aPresContext,
aPresContext->GetPixelsToTwips(&p2t); aPresContext->GetPixelsToTwips(&p2t);
rect.Deflate(NSToCoordRound(p2t), NSToCoordRound(p2t)); rect.Deflate(NSToCoordRound(p2t), NSToCoordRound(p2t));
aRenderingContext.SetColor(NS_RGB(0, 0, 0)); aRenderingContext.SetColor(NS_RGB(0, 0, 0));
//aRenderingContext.DrawRect(rect); aRenderingContext.DrawRect(rect);
rect.Inflate(NSToCoordRound(p2t), NSToCoordRound(p2t)); 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 #endif
// use the whole page // use the whole page
rect.width += mMargin.left + mMargin.right; rect.width += mMargin.left + mMargin.right;
@ -419,6 +488,7 @@ nsPageFrame::Paint(nsIPresContext* aPresContext,
} }
aRenderingContext.PopState(clipEmpty);
return rv; return rv;
} }
@ -441,7 +511,7 @@ void
nsPageFrame::SetPageNumInfo(PRInt32 aPageNumber, PRInt32 aTotalPages) nsPageFrame::SetPageNumInfo(PRInt32 aPageNumber, PRInt32 aTotalPages)
{ {
mPageNum = aPageNumber; mPageNum = aPageNumber;
mTotNumPages = aTotalPages; mTotNumPages = aTotalPages;
} }

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

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

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

@ -50,6 +50,24 @@
static NS_DEFINE_CID(kPrintOptionsCID, NS_PRINTOPTIONS_CID); 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 nsresult
NS_NewSimplePageSequenceFrame(nsIPresShell* aPresShell, nsIFrame** aNewFrame) NS_NewSimplePageSequenceFrame(nsIPresShell* aPresShell, nsIFrame** aNewFrame)
{ {
@ -83,7 +101,14 @@ nsSimplePageSequenceFrame::nsSimplePageSequenceFrame() :
printService->GetPrintRange(&printType); printService->GetPrintRange(&printType);
mIsPrintingSelection = nsIPrintOptions::kRangeSelection == 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() nsSimplePageSequenceFrame::~nsSimplePageSequenceFrame()
@ -247,9 +272,28 @@ nsSimplePageSequenceFrame::Reflow(nsIPresContext* aPresContext,
// Compute the size of each page and the x coordinate that each page will // Compute the size of each page and the x coordinate that each page will
// be placed at // be placed at
nsSize pageSize; nsRect pageSize;
aPresContext->GetPageWidth(&pageSize.width); nsRect adjSize;
aPresContext->GetPageHeight(&pageSize.height); 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 // XXX - Hack Alert
// OK, so ther eis a selection, we will print the entire selection // OK, so ther eis a selection, we will print the entire selection
@ -261,10 +305,15 @@ nsSimplePageSequenceFrame::Reflow(nsIPresContext* aPresContext,
pageSize.height = 0x0FFFFFFF; 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 x = mMargin.left;
nscoord y = mMargin.top; nscoord y = mMargin.top;// Running y-offset for each page
// See if it's an incremental reflow command // See if it's an incremental reflow command
if (eReflowReason_Incremental == aReflowState.reason) { if (eReflowReason_Incremental == aReflowState.reason) {
@ -279,11 +328,12 @@ nsSimplePageSequenceFrame::Reflow(nsIPresContext* aPresContext,
nsHTMLReflowMetrics kidSize(nsnull); nsHTMLReflowMetrics kidSize(nsnull);
for (nsIFrame* kidFrame = mFrames.FirstChild(); nsnull != kidFrame; ) { for (nsIFrame* kidFrame = mFrames.FirstChild(); nsnull != kidFrame; ) {
// Reflow the page // Reflow the page
nsSize availSize(pageSize.width, pageSize.height);
nsHTMLReflowState kidReflowState(aPresContext, aReflowState, kidFrame, nsHTMLReflowState kidReflowState(aPresContext, aReflowState, kidFrame,
pageSize, reflowReason); availSize, reflowReason);
nsReflowStatus status; nsReflowStatus status;
kidReflowState.availableWidth = pageSize.width - mMargin.left - mMargin.right; kidReflowState.availableWidth = pageSize.width - margin.left - margin.right;
kidReflowState.availableHeight = pageSize.height - mMargin.top - mMargin.bottom; kidReflowState.availableHeight = pageSize.height - margin.top - margin.bottom;
kidReflowState.mComputedWidth = kidReflowState.availableWidth; kidReflowState.mComputedWidth = kidReflowState.availableWidth;
//kidReflowState.mComputedHeight = kidReflowState.availableHeight; //kidReflowState.mComputedHeight = kidReflowState.availableHeight;
@ -371,272 +421,8 @@ nsSimplePageSequenceFrame::Print(nsIPresContext* aPresContext,
nsIPrintOptions* aPrintOptions, nsIPrintOptions* aPrintOptions,
nsIPrintStatusCallback* aStatusCallback) nsIPrintStatusCallback* aStatusCallback)
{ {
NS_ENSURE_ARG_POINTER(aPresContext); NS_ASSERTION(0, "No longer being used.");
NS_ENSURE_ARG_POINTER(aPrintOptions); return NS_ERROR_FAILURE;
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_IMETHODIMP NS_IMETHODIMP
@ -736,14 +522,14 @@ nsSimplePageSequenceFrame::StartPrint(nsIPresContext* aPresContext,
GetView(aPresContext, &seqView); GetView(aPresContext, &seqView);
nsRect rect; nsRect rect;
GetRect(rect); GetRect(rect);
printf("Seq Frame: - %d,%d,%d,%d ", rect.x, rect.y, rect.width, rect.height); fprintf(mDebugFD, "Seq Frame: %p - [%5d,%5d,%5d,%5d] ", this, rect.x, rect.y, rect.width, rect.height);
printf("view: %p ", seqView); fprintf(mDebugFD, "view: %p ", seqView);
nsRect viewRect; nsRect viewRect;
if (seqView) { if (seqView) {
seqView->GetBounds(viewRect); 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); page->GetRect(rect);
nsRect viewRect; nsRect viewRect;
view->GetBounds(viewRect); view->GetBounds(viewRect);
printf("Page: %d - %d,%d,%d,%d ", pageNum, rect.x, rect.y, rect.width, rect.height); fprintf(mDebugFD, " Page: %p No: %d - [%5d,%5d,%5d,%5d] ", page, 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, " [%5d,%5d,%5d,%5d]\n", viewRect.x, viewRect.y, viewRect.width, viewRect.height);
pageNum++; 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 #endif
// Determine if we are rendering only the selection // Determine if we are rendering only the selection
@ -901,13 +687,13 @@ nsSimplePageSequenceFrame::PrintNextPage(nsIPresContext* aPresContext,
nsresult rv = NS_OK; nsresult rv = NS_OK;
// See whether we should print this page // 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 // If printing a range of pages check whether the page number is in the
// range of pages to print // range of pages to print
if (mDoingPageRange) { if (mDoingPageRange) {
if (mPageNum < mFromPageNum) { if (mPageNum < mFromPageNum) {
printThisPage = PR_FALSE; mPrintThisPage = PR_FALSE;
} else if (mPageNum > mToPageNum) { } else if (mPageNum > mToPageNum) {
mPageNum++; mPageNum++;
mCurrentPageFrame = nsnull; mCurrentPageFrame = nsnull;
@ -918,18 +704,21 @@ nsSimplePageSequenceFrame::PrintNextPage(nsIPresContext* aPresContext,
// Check for printing of odd and even pages // Check for printing of odd and even pages
if (mPageNum & 0x1) { if (mPageNum & 0x1) {
if (!printOddPages) { if (!printOddPages) {
printThisPage = PR_FALSE; // don't print odd numbered page mPrintThisPage = PR_FALSE; // don't print odd numbered page
} }
} else { } else {
if (!printEvenPages) { if (!printEvenPages) {
printThisPage = PR_FALSE; // don't print even numbered page mPrintThisPage = PR_FALSE; // don't print even numbered page
} }
} }
if (printThisPage) { if (mPrintThisPage) {
rv = dc->BeginPage(); if (!mSkipPageBegin) {
if (NS_FAILED(rv)) { PRINT_DEBUG_MSG1("\n***************** BeginPage *****************\n");
return rv; rv = dc->BeginPage();
if (NS_FAILED(rv)) {
return rv;
}
} }
// cast the frame to be a page frame // cast the frame to be a page frame
@ -944,12 +733,11 @@ nsSimplePageSequenceFrame::PrintNextPage(nsIPresContext* aPresContext,
mCurrentPageFrame->GetView(aPresContext, &view); mCurrentPageFrame->GetView(aPresContext, &view);
NS_ASSERTION(nsnull != view, "no page view"); NS_ASSERTION(nsnull != view, "no page view");
#if defined(DEBUG_rods) || defined(DEBUG_dcone)
{ PRINT_DEBUG_MSG4("SeqFr::Paint -> %p PageNo: %d View: %p", pf, mPageNum, view);
printf("SPSF::Paint(Async) -> PageNo: %d View: %p\n", mPageNum, view); PRINT_DEBUG_MSG3(" At: %d,%d\n", mMargin.left+mOffsetX, mMargin.top+mOffsetY);
}
#endif vm->Display(view, mMargin.left+mOffsetX, mMargin.top+mOffsetY);
vm->Display(view, mMargin.left, mMargin.top);
// this view was printed and since display set the origin // 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 // XXX Doesn't seem like we need to do this anymore
//view->SetVisibility(nsViewVisibility_kHide); //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)) { if (NS_FAILED(rv)) {
return rv; return rv;
} }
} }
if (nsIPrintOptions::kRangeSelection != mPrintRangeType || if (nsIPrintOptions::kRangeSelection != mPrintRangeType ||
(nsIPrintOptions::kRangeSelection == mPrintRangeType && printThisPage)) { (nsIPrintOptions::kRangeSelection == mPrintRangeType && mPrintThisPage)) {
mPrintedPageNum++; mPrintedPageNum++;
} }
mPageNum++; mPageNum++;
rv = mCurrentPageFrame->GetNextSibling(&mCurrentPageFrame); return mCurrentPageFrame->GetNextSibling(&mCurrentPageFrame);
return rv;
} }
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 GetNumPages(PRInt32* aNumPages);
NS_IMETHOD IsDoingPrintRange(PRBool* aDoing); NS_IMETHOD IsDoingPrintRange(PRBool* aDoing);
NS_IMETHOD GetPrintRange(PRInt32* aFromPage, PRInt32* aToPage); 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 // Debugging
NS_IMETHOD GetFrameName(nsString& aResult) const; NS_IMETHOD GetFrameName(nsString& aResult) const;
NS_IMETHOD SetDebugFD(FILE* aFD);
FILE * mDebugFD;
#endif #endif
protected: protected:
@ -94,6 +103,13 @@ protected:
PRInt32 mPrintRangeType; PRInt32 mPrintRangeType;
PRInt32 mFromPageNum; PRInt32 mFromPageNum;
PRInt32 mToPageNum; 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 // tstaic data members
PRUnichar * nsPageFrame::mPageNumFormat = nsnull; 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 nsresult
NS_NewPageFrame(nsIPresShell* aPresShell, nsIFrame** aNewFrame) NS_NewPageFrame(nsIPresShell* aPresShell, nsIFrame** aNewFrame)
{ {
@ -69,8 +87,14 @@ NS_NewPageFrame(nsIPresShell* aPresShell, nsIFrame** aNewFrame)
} }
nsPageFrame::nsPageFrame() : nsPageFrame::nsPageFrame() :
mHeadFootFont(nsnull) mHeadFootFont(nsnull),
mSupressHF(PR_FALSE),
mClipRect(-1, -1, -1, -1)
{ {
#ifdef NS_DEBUG
mDebugFD = stdout;
#endif
} }
nsPageFrame::~nsPageFrame() nsPageFrame::~nsPageFrame()
@ -174,11 +198,15 @@ NS_METHOD nsPageFrame::Reflow(nsIPresContext* aPresContext,
NS_ASSERTION(nsnull == childNextInFlow, "bad child flow list"); 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 // Return our desired size
aDesiredSize.width = aReflowState.availableWidth; aDesiredSize.width = aReflowState.availableWidth;
aDesiredSize.height = aReflowState.availableHeight; aDesiredSize.height = aReflowState.availableHeight;
} }
PRINT_DEBUG_MSG2("PageFrame::Reflow %p ", this);
PRINT_DEBUG_MSG3("[%d,%d]\n", aReflowState.availableWidth, aReflowState.availableHeight);
return NS_OK; return NS_OK;
} }
@ -254,6 +282,7 @@ nsPageFrame::DrawHeaderFooter(nsIRenderingContext& aRenderingContext,
nscoord aHeight, nscoord aHeight,
PRBool aUseHalfThePage) PRBool aUseHalfThePage)
{ {
// first make sure we have a vaild string and that the height of the // first make sure we have a vaild string and that the height of the
// text will fit in the margin // text will fit in the margin
if (aStr.Length() > 0 && if (aStr.Length() > 0 &&
@ -300,6 +329,25 @@ nsPageFrame::DrawHeaderFooter(nsIRenderingContext& aRenderingContext,
aRenderingContext.SetClipRect(rect, nsClipCombine_kReplace, clipEmpty); aRenderingContext.SetClipRect(rect, nsClipCombine_kReplace, clipEmpty);
aRenderingContext.DrawString(str, x, y); aRenderingContext.DrawString(str, x, y);
aRenderingContext.PopState(clipEmpty); 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, const nsRect& aDirtyRect,
nsFramePaintLayer aWhichLayer) 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); nsresult rv = nsContainerFrame::Paint(aPresContext, aRenderingContext, aDirtyRect, aWhichLayer);
#if defined(DEBUG_rods) || defined(DEBUG_dcone)
if (NS_FRAME_PAINT_LAYER_FOREGROUND == aWhichLayer) { 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 // get the current margin
mPrintOptions->GetMarginInTwips(mMargin); mPrintOptions->GetMarginInTwips(mMargin);
@ -325,9 +394,9 @@ nsPageFrame::Paint(nsIPresContext* aPresContext,
aPresContext->GetPixelsToTwips(&p2t); aPresContext->GetPixelsToTwips(&p2t);
rect.Deflate(NSToCoordRound(p2t), NSToCoordRound(p2t)); rect.Deflate(NSToCoordRound(p2t), NSToCoordRound(p2t));
aRenderingContext.SetColor(NS_RGB(0, 0, 0)); aRenderingContext.SetColor(NS_RGB(0, 0, 0));
//aRenderingContext.DrawRect(rect); aRenderingContext.DrawRect(rect);
rect.Inflate(NSToCoordRound(p2t), NSToCoordRound(p2t)); 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 #endif
// use the whole page // use the whole page
rect.width += mMargin.left + mMargin.right; rect.width += mMargin.left + mMargin.right;
@ -419,6 +488,7 @@ nsPageFrame::Paint(nsIPresContext* aPresContext,
} }
aRenderingContext.PopState(clipEmpty);
return rv; return rv;
} }
@ -441,7 +511,7 @@ void
nsPageFrame::SetPageNumInfo(PRInt32 aPageNumber, PRInt32 aTotalPages) nsPageFrame::SetPageNumInfo(PRInt32 aPageNumber, PRInt32 aTotalPages)
{ {
mPageNum = aPageNumber; mPageNum = aPageNumber;
mTotNumPages = aTotalPages; mTotNumPages = aTotalPages;
} }

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

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

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

@ -50,6 +50,24 @@
static NS_DEFINE_CID(kPrintOptionsCID, NS_PRINTOPTIONS_CID); 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 nsresult
NS_NewSimplePageSequenceFrame(nsIPresShell* aPresShell, nsIFrame** aNewFrame) NS_NewSimplePageSequenceFrame(nsIPresShell* aPresShell, nsIFrame** aNewFrame)
{ {
@ -83,7 +101,14 @@ nsSimplePageSequenceFrame::nsSimplePageSequenceFrame() :
printService->GetPrintRange(&printType); printService->GetPrintRange(&printType);
mIsPrintingSelection = nsIPrintOptions::kRangeSelection == 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() nsSimplePageSequenceFrame::~nsSimplePageSequenceFrame()
@ -247,9 +272,28 @@ nsSimplePageSequenceFrame::Reflow(nsIPresContext* aPresContext,
// Compute the size of each page and the x coordinate that each page will // Compute the size of each page and the x coordinate that each page will
// be placed at // be placed at
nsSize pageSize; nsRect pageSize;
aPresContext->GetPageWidth(&pageSize.width); nsRect adjSize;
aPresContext->GetPageHeight(&pageSize.height); 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 // XXX - Hack Alert
// OK, so ther eis a selection, we will print the entire selection // OK, so ther eis a selection, we will print the entire selection
@ -261,10 +305,15 @@ nsSimplePageSequenceFrame::Reflow(nsIPresContext* aPresContext,
pageSize.height = 0x0FFFFFFF; 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 x = mMargin.left;
nscoord y = mMargin.top; nscoord y = mMargin.top;// Running y-offset for each page
// See if it's an incremental reflow command // See if it's an incremental reflow command
if (eReflowReason_Incremental == aReflowState.reason) { if (eReflowReason_Incremental == aReflowState.reason) {
@ -279,11 +328,12 @@ nsSimplePageSequenceFrame::Reflow(nsIPresContext* aPresContext,
nsHTMLReflowMetrics kidSize(nsnull); nsHTMLReflowMetrics kidSize(nsnull);
for (nsIFrame* kidFrame = mFrames.FirstChild(); nsnull != kidFrame; ) { for (nsIFrame* kidFrame = mFrames.FirstChild(); nsnull != kidFrame; ) {
// Reflow the page // Reflow the page
nsSize availSize(pageSize.width, pageSize.height);
nsHTMLReflowState kidReflowState(aPresContext, aReflowState, kidFrame, nsHTMLReflowState kidReflowState(aPresContext, aReflowState, kidFrame,
pageSize, reflowReason); availSize, reflowReason);
nsReflowStatus status; nsReflowStatus status;
kidReflowState.availableWidth = pageSize.width - mMargin.left - mMargin.right; kidReflowState.availableWidth = pageSize.width - margin.left - margin.right;
kidReflowState.availableHeight = pageSize.height - mMargin.top - mMargin.bottom; kidReflowState.availableHeight = pageSize.height - margin.top - margin.bottom;
kidReflowState.mComputedWidth = kidReflowState.availableWidth; kidReflowState.mComputedWidth = kidReflowState.availableWidth;
//kidReflowState.mComputedHeight = kidReflowState.availableHeight; //kidReflowState.mComputedHeight = kidReflowState.availableHeight;
@ -371,272 +421,8 @@ nsSimplePageSequenceFrame::Print(nsIPresContext* aPresContext,
nsIPrintOptions* aPrintOptions, nsIPrintOptions* aPrintOptions,
nsIPrintStatusCallback* aStatusCallback) nsIPrintStatusCallback* aStatusCallback)
{ {
NS_ENSURE_ARG_POINTER(aPresContext); NS_ASSERTION(0, "No longer being used.");
NS_ENSURE_ARG_POINTER(aPrintOptions); return NS_ERROR_FAILURE;
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_IMETHODIMP NS_IMETHODIMP
@ -736,14 +522,14 @@ nsSimplePageSequenceFrame::StartPrint(nsIPresContext* aPresContext,
GetView(aPresContext, &seqView); GetView(aPresContext, &seqView);
nsRect rect; nsRect rect;
GetRect(rect); GetRect(rect);
printf("Seq Frame: - %d,%d,%d,%d ", rect.x, rect.y, rect.width, rect.height); fprintf(mDebugFD, "Seq Frame: %p - [%5d,%5d,%5d,%5d] ", this, rect.x, rect.y, rect.width, rect.height);
printf("view: %p ", seqView); fprintf(mDebugFD, "view: %p ", seqView);
nsRect viewRect; nsRect viewRect;
if (seqView) { if (seqView) {
seqView->GetBounds(viewRect); 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); page->GetRect(rect);
nsRect viewRect; nsRect viewRect;
view->GetBounds(viewRect); view->GetBounds(viewRect);
printf("Page: %d - %d,%d,%d,%d ", pageNum, rect.x, rect.y, rect.width, rect.height); fprintf(mDebugFD, " Page: %p No: %d - [%5d,%5d,%5d,%5d] ", page, 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, " [%5d,%5d,%5d,%5d]\n", viewRect.x, viewRect.y, viewRect.width, viewRect.height);
pageNum++; 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 #endif
// Determine if we are rendering only the selection // Determine if we are rendering only the selection
@ -901,13 +687,13 @@ nsSimplePageSequenceFrame::PrintNextPage(nsIPresContext* aPresContext,
nsresult rv = NS_OK; nsresult rv = NS_OK;
// See whether we should print this page // 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 // If printing a range of pages check whether the page number is in the
// range of pages to print // range of pages to print
if (mDoingPageRange) { if (mDoingPageRange) {
if (mPageNum < mFromPageNum) { if (mPageNum < mFromPageNum) {
printThisPage = PR_FALSE; mPrintThisPage = PR_FALSE;
} else if (mPageNum > mToPageNum) { } else if (mPageNum > mToPageNum) {
mPageNum++; mPageNum++;
mCurrentPageFrame = nsnull; mCurrentPageFrame = nsnull;
@ -918,18 +704,21 @@ nsSimplePageSequenceFrame::PrintNextPage(nsIPresContext* aPresContext,
// Check for printing of odd and even pages // Check for printing of odd and even pages
if (mPageNum & 0x1) { if (mPageNum & 0x1) {
if (!printOddPages) { if (!printOddPages) {
printThisPage = PR_FALSE; // don't print odd numbered page mPrintThisPage = PR_FALSE; // don't print odd numbered page
} }
} else { } else {
if (!printEvenPages) { if (!printEvenPages) {
printThisPage = PR_FALSE; // don't print even numbered page mPrintThisPage = PR_FALSE; // don't print even numbered page
} }
} }
if (printThisPage) { if (mPrintThisPage) {
rv = dc->BeginPage(); if (!mSkipPageBegin) {
if (NS_FAILED(rv)) { PRINT_DEBUG_MSG1("\n***************** BeginPage *****************\n");
return rv; rv = dc->BeginPage();
if (NS_FAILED(rv)) {
return rv;
}
} }
// cast the frame to be a page frame // cast the frame to be a page frame
@ -944,12 +733,11 @@ nsSimplePageSequenceFrame::PrintNextPage(nsIPresContext* aPresContext,
mCurrentPageFrame->GetView(aPresContext, &view); mCurrentPageFrame->GetView(aPresContext, &view);
NS_ASSERTION(nsnull != view, "no page view"); NS_ASSERTION(nsnull != view, "no page view");
#if defined(DEBUG_rods) || defined(DEBUG_dcone)
{ PRINT_DEBUG_MSG4("SeqFr::Paint -> %p PageNo: %d View: %p", pf, mPageNum, view);
printf("SPSF::Paint(Async) -> PageNo: %d View: %p\n", mPageNum, view); PRINT_DEBUG_MSG3(" At: %d,%d\n", mMargin.left+mOffsetX, mMargin.top+mOffsetY);
}
#endif vm->Display(view, mMargin.left+mOffsetX, mMargin.top+mOffsetY);
vm->Display(view, mMargin.left, mMargin.top);
// this view was printed and since display set the origin // 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 // XXX Doesn't seem like we need to do this anymore
//view->SetVisibility(nsViewVisibility_kHide); //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)) { if (NS_FAILED(rv)) {
return rv; return rv;
} }
} }
if (nsIPrintOptions::kRangeSelection != mPrintRangeType || if (nsIPrintOptions::kRangeSelection != mPrintRangeType ||
(nsIPrintOptions::kRangeSelection == mPrintRangeType && printThisPage)) { (nsIPrintOptions::kRangeSelection == mPrintRangeType && mPrintThisPage)) {
mPrintedPageNum++; mPrintedPageNum++;
} }
mPageNum++; mPageNum++;
rv = mCurrentPageFrame->GetNextSibling(&mCurrentPageFrame); return mCurrentPageFrame->GetNextSibling(&mCurrentPageFrame);
return rv;
} }
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 GetNumPages(PRInt32* aNumPages);
NS_IMETHOD IsDoingPrintRange(PRBool* aDoing); NS_IMETHOD IsDoingPrintRange(PRBool* aDoing);
NS_IMETHOD GetPrintRange(PRInt32* aFromPage, PRInt32* aToPage); 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 // Debugging
NS_IMETHOD GetFrameName(nsString& aResult) const; NS_IMETHOD GetFrameName(nsString& aResult) const;
NS_IMETHOD SetDebugFD(FILE* aFD);
FILE * mDebugFD;
#endif #endif
protected: protected:
@ -94,6 +103,13 @@ protected:
PRInt32 mPrintRangeType; PRInt32 mPrintRangeType;
PRInt32 mFromPageNum; PRInt32 mFromPageNum;
PRInt32 mToPageNum; 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 // 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 // the repeatability of header and footers on continued tables is handled when they are created
if (isPaginated && !mPrevInFlow && (NS_UNCONSTRAINEDSIZE == aReflowState.availSize.height)) { if (isPaginated && !mPrevInFlow && (NS_UNCONSTRAINEDSIZE == aReflowState.availSize.height)) {
nscoord pageHeight; nsRect actualRect;
aPresContext->GetPageHeight(&pageHeight); nsRect adjRect;
aPresContext->GetPageDim(&actualRect, &adjRect);
// don't repeat the thead or tfoot unless it is < 25% of the page height // don't repeat the thead or tfoot unless it is < 25% of the page height
if (thead) { if (thead) {
thead->SetRepeatable(IsRepeatable(*thead, pageHeight)); thead->SetRepeatable(IsRepeatable(*thead, actualRect.height));
} }
if (tfoot) { if (tfoot) {
tfoot->SetRepeatable(IsRepeatable(*tfoot, pageHeight)); tfoot->SetRepeatable(IsRepeatable(*tfoot, actualRect.height));
} }
} }

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

@ -823,8 +823,10 @@ nsTableRowGroupFrame::SplitRowGroup(nsIPresContext* aPresContext,
nsRect bounds; nsRect bounds;
rowFrame->GetRect(bounds); rowFrame->GetRect(bounds);
if (bounds.YMost() > availHeight) { if (bounds.YMost() > availHeight) {
nscoord pageHeight; nsRect actualRect;
aPresContext->GetPageHeight(&pageHeight); 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 // 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 // row or there is at least 20% of the current page available
if (!prevRowFrame || (availHeight - heightTaken > pageHeight / 5)) { 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 // 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 // the repeatability of header and footers on continued tables is handled when they are created
if (isPaginated && !mPrevInFlow && (NS_UNCONSTRAINEDSIZE == aReflowState.availSize.height)) { if (isPaginated && !mPrevInFlow && (NS_UNCONSTRAINEDSIZE == aReflowState.availSize.height)) {
nscoord pageHeight; nsRect actualRect;
aPresContext->GetPageHeight(&pageHeight); nsRect adjRect;
aPresContext->GetPageDim(&actualRect, &adjRect);
// don't repeat the thead or tfoot unless it is < 25% of the page height // don't repeat the thead or tfoot unless it is < 25% of the page height
if (thead) { if (thead) {
thead->SetRepeatable(IsRepeatable(*thead, pageHeight)); thead->SetRepeatable(IsRepeatable(*thead, actualRect.height));
} }
if (tfoot) { if (tfoot) {
tfoot->SetRepeatable(IsRepeatable(*tfoot, pageHeight)); tfoot->SetRepeatable(IsRepeatable(*tfoot, actualRect.height));
} }
} }

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

@ -823,8 +823,10 @@ nsTableRowGroupFrame::SplitRowGroup(nsIPresContext* aPresContext,
nsRect bounds; nsRect bounds;
rowFrame->GetRect(bounds); rowFrame->GetRect(bounds);
if (bounds.YMost() > availHeight) { if (bounds.YMost() > availHeight) {
nscoord pageHeight; nsRect actualRect;
aPresContext->GetPageHeight(&pageHeight); 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 // 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 // row or there is at least 20% of the current page available
if (!prevRowFrame || (availHeight - heightTaken > pageHeight / 5)) { if (!prevRowFrame || (availHeight - heightTaken > pageHeight / 5)) {

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

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

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

@ -90,21 +90,21 @@ Contributor(s): Masaki Katakai <katakai@japan.sun.com>
<row> <row>
<text class="label" value="&printrangeGroup.label;" flex ="1"/> <text class="label" value="&printrangeGroup.label;" flex ="1"/>
<radiogroup id="printrangeGroup" orient="vertical"> <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"> <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;" /> <text class = "label" id = "frompageLabel" for = "frompageInput" value = "&frompageInput.label;" />
<textbox id = "frompageInput" style = "width:5em;" onkeyup="checkValid(this.id)"/> <textbox id = "frompageInput" style = "width:5em;" onkeyup="checkValid(this.id)"/>
<text class = "label" id = "topageLabel" for = "topageInput" value = "&topageInput.label;" /> <text class = "label" id = "topageLabel" for = "topageInput" value = "&topageInput.label;" />
<textbox id = "topageInput" style = "width:5em;" onkeyup="checkValid(this.id)"/> <textbox id = "topageInput" style = "width:5em;" onkeyup="checkValid(this.id)"/>
</box> </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> </radiogroup>
</row> </row>
<row> <row>
<text class="label" value="&printframeGroup.label;" id="printrangeGroupLabel" flex ="1"/> <text class="label" value="&printframeGroup.label;" id="printrangeGroupLabel" flex ="1"/>
<radiogroup id="printrangeGroup" orient="vertical"> <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 = "selectedframeRadio" label = "&selectedframeRadio.label;" />
<radio group = "printrangeGroup" id = "eachframesepRadio" label = "&eachframesepRadio.label;" /> <radio group = "printrangeGroup" id = "eachframesepRadio" label = "&eachframesepRadio.label;" />
</radiogroup> </radiogroup>
@ -143,6 +143,6 @@ Contributor(s): Masaki Katakai <katakai@japan.sun.com>
<!-- Places to overlay common dialog buttons and keyset --> <!-- Places to overlay common dialog buttons and keyset -->
<box id="okCancelButtons"/> <box id="okCancelButtons"/>
<keyset id="dialogKeys"/> <keyset id="keyset"/>
</window> </window>

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

@ -36,7 +36,7 @@
<!ENTITY selectionRadio.label "Selection"> <!ENTITY selectionRadio.label "Selection">
<!ENTITY printframeGroup.label "Print Frames:"> <!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 selectedframeRadio.label "The selected frame">
<!ENTITY eachframesepRadio.label "Each frame separately"> <!ENTITY eachframesepRadio.label "Each frame separately">