adding Thebes printing APIs

git-svn-id: svn://10.0.0.236/trunk@188644 18797224-902f-48f8-a5cc-f745e15eee43
This commit is contained in:
pavlov%pavlov.net
2006-02-01 05:21:59 +00:00
parent be269c58dd
commit 776704eb2f
5 changed files with 118 additions and 6 deletions

View File

@@ -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;

View File

@@ -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;

View File

@@ -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;

View File

@@ -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);
}

View File

@@ -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;
}