diff --git a/mozilla/gfx/thebes/public/gfxASurface.h b/mozilla/gfx/thebes/public/gfxASurface.h index 3876b963eea..d297a4c717e 100644 --- a/mozilla/gfx/thebes/public/gfxASurface.h +++ b/mozilla/gfx/thebes/public/gfxASurface.h @@ -42,6 +42,7 @@ #include "gfxTypes.h" #include "gfxRect.h" +#include "nsStringFwd.h" /** * A surface is something you can draw on. Instantiate a subclass of this @@ -78,6 +79,13 @@ public: (int) r.size.width, (int) r.size.height); } + /* Printing backend functions */ + virtual nsresult BeginPrinting(const nsAString& aTitle, const nsAString& aPrintToFileName) { return NS_ERROR_NOT_IMPLEMENTED; } + virtual nsresult EndPrinting() { return NS_ERROR_NOT_IMPLEMENTED; } + virtual nsresult AbortPrinting() { return NS_ERROR_NOT_IMPLEMENTED; } + virtual nsresult BeginPage() { return NS_ERROR_NOT_IMPLEMENTED; } + virtual nsresult EndPage() { return NS_ERROR_NOT_IMPLEMENTED; } + protected: void Init(cairo_surface_t* surface) { mDestroyed = PR_FALSE; diff --git a/mozilla/gfx/thebes/public/gfxContext.h b/mozilla/gfx/thebes/public/gfxContext.h index bca243cee4a..6bed3941ad3 100644 --- a/mozilla/gfx/thebes/public/gfxContext.h +++ b/mozilla/gfx/thebes/public/gfxContext.h @@ -504,12 +504,15 @@ public: */ void PopFilter(); - /** - * ... - * + * Printing functions */ - void ShowPage(); + // XXX look and see if the arguments here should be a seperate object + void BeginPrinting(const nsAString& aTitle, const nsAString& aPrintToFileName); + void EndPrinting(); + void AbortPrinting(); + void BeginPage(); + void EndPage(); private: cairo_t *mCairo; diff --git a/mozilla/gfx/thebes/public/gfxWindowsSurface.h b/mozilla/gfx/thebes/public/gfxWindowsSurface.h index 48e657afd72..977a89b189a 100644 --- a/mozilla/gfx/thebes/public/gfxWindowsSurface.h +++ b/mozilla/gfx/thebes/public/gfxWindowsSurface.h @@ -52,6 +52,13 @@ public: virtual ~gfxWindowsSurface(); HDC GetDC() { return mDC; } + + nsresult BeginPrinting(const nsAString& aTitle, const nsAString& aPrintToFileName); + nsresult EndPrinting(); + nsresult AbortPrinting(); + nsresult BeginPage(); + nsresult EndPage(); + private: PRBool mOwnsDC; HDC mDC; diff --git a/mozilla/gfx/thebes/src/gfxContext.cpp b/mozilla/gfx/thebes/src/gfxContext.cpp index 7ee46a1ec8f..88169437d7a 100644 --- a/mozilla/gfx/thebes/src/gfxContext.cpp +++ b/mozilla/gfx/thebes/src/gfxContext.cpp @@ -526,7 +526,26 @@ void gfxContext::PopFilter() } -void gfxContext::ShowPage() +void gfxContext::BeginPrinting(const nsAString& aTitle, const nsAString& aPrintToFileName) { - cairo_show_page(mCairo); + mSurface->BeginPrinting(aTitle, aPrintToFileName); +} + +void gfxContext::EndPrinting() +{ + mSurface->EndPrinting(); +} +void gfxContext::AbortPrinting() +{ + mSurface->AbortPrinting(); +} +void gfxContext::BeginPage() +{ + mSurface->BeginPage(); +} + +void gfxContext::EndPage() +{ + if (NS_FAILED(mSurface->EndPage())) + cairo_show_page(mCairo); } diff --git a/mozilla/gfx/thebes/src/gfxWindowsSurface.cpp b/mozilla/gfx/thebes/src/gfxWindowsSurface.cpp index 9f44e6cb32e..89ce1cf2c40 100644 --- a/mozilla/gfx/thebes/src/gfxWindowsSurface.cpp +++ b/mozilla/gfx/thebes/src/gfxWindowsSurface.cpp @@ -36,6 +36,7 @@ * ***** END LICENSE BLOCK ***** */ #include "gfxWindowsSurface.h" +#include "nsString.h" THEBES_IMPL_REFCOUNTING(gfxWindowsSurface) @@ -116,3 +117,77 @@ gfxWindowsSurface::~gfxWindowsSurface() ::DeleteDC(mDC); } } + + +static char* +GetACPString(const nsAString& aStr) +{ + int acplen = aStr.Length() * 2 + 1; + char * acp = new char[acplen]; + if(acp) { + int outlen = ::WideCharToMultiByte(CP_ACP, 0, + PromiseFlatString(aStr).get(), + aStr.Length(), + acp, acplen, NULL, NULL); + if (outlen > 0) + acp[outlen] = '\0'; // null terminate + } + return acp; +} + +nsresult gfxWindowsSurface::BeginPrinting(const nsAString& aTitle, + const nsAString& aPrintToFileName) +{ +#define DOC_TITLE_LENGTH 30 + DOCINFO docinfo; + + nsString titleStr; + titleStr = aTitle; + if (titleStr.Length() > DOC_TITLE_LENGTH) { + titleStr.SetLength(DOC_TITLE_LENGTH-3); + titleStr.AppendLiteral("..."); + } + char *title = GetACPString(titleStr); + + char *docName = nsnull; + if (!aPrintToFileName.IsEmpty()) { + docName = ToNewCString(aPrintToFileName); + } + + docinfo.cbSize = sizeof(docinfo); + docinfo.lpszDocName = title ? title : "Mozilla Document"; + docinfo.lpszOutput = docName; + docinfo.lpszDatatype = NULL; + docinfo.fwType = 0; + + ::StartDoc(mDC, &docinfo); + + delete [] title; + if (docName != nsnull) nsMemory::Free(docName); + + return NS_OK; +} + +nsresult gfxWindowsSurface::EndPrinting() +{ + ::EndDoc(mDC); + return NS_OK; +} + +nsresult gfxWindowsSurface::AbortPrinting() +{ + ::AbortDoc(mDC); + return NS_OK; +} + +nsresult gfxWindowsSurface::BeginPage() +{ + ::StartPage(mDC); + return NS_OK; +} + +nsresult gfxWindowsSurface::EndPage() +{ + ::EndPage(mDC); + return NS_OK; +}