enabling PDF surface on windows. bug 369930. r/sr=vlad

This commit is contained in:
pavlov%pavlov.net 2007-03-01 00:02:27 +00:00
Родитель e98fed2963
Коммит 5033ec7891
16 изменённых файлов: 254 добавлений и 125 удалений

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

@ -7249,6 +7249,7 @@ if test "$MOZ_SVG" -o "$MOZ_ENABLE_CANVAS" -o "$MOZ_ENABLE_CAIRO_GFX" ; then
if test "$MOZ_WIDGET_TOOLKIT" = "windows"; then
WIN32_SURFACE_FEATURE="#define CAIRO_HAS_WIN32_SURFACE 1"
WIN32_FONT_FEATURE="#define CAIRO_HAS_WIN32_FONT 1"
PDF_SURFACE_FEATURE="#define CAIRO_HAS_PDF_SURFACE 1"
fi
if test "$MOZ_WIDGET_TOOLKIT" = "os2"; then
OS2_SURFACE_FEATURE="#define CAIRO_HAS_OS2_SURFACE 1"

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

@ -113,6 +113,12 @@ ifeq ($(MOZ_WIDGET_TOOLKIT),windows)
CSRCS += cairo-win32-font.c \
cairo-win32-surface.c
EXPORTS += cairo-win32.h
CSRCS += cairo-base85-stream.c \
cairo-pdf-surface.c \
cairo-type1-fallback.c \
cairo-truetype-subset.c \
cairo-cff-subset.c
EXPORTS += cairo-pdf.h
endif
ifeq ($(MOZ_WIDGET_TOOLKIT),os2)

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

@ -73,6 +73,7 @@ static nsSystemFontsGTK2 *gSystemFonts = nsnull;
#include <cairo-win32.h>
#include "nsSystemFontsWin.h"
#include "gfxWindowsSurface.h"
#include "gfxPDFSurface.h"
static nsSystemFontsWin *gSystemFonts = nsnull;
#include <usp10.h>
#elif defined(XP_OS2)
@ -118,7 +119,6 @@ nsThebesDeviceContext::nsThebesDeviceContext()
mWidth = 0;
mHeight = 0;
mPrinter = PR_FALSE;
mDeviceContextSpec = nsnull;
mWidgetSurfaceCache.Init();
@ -136,72 +136,88 @@ nsThebesDeviceContext::~nsThebesDeviceContext()
nsresult
nsThebesDeviceContext::SetDPI()
{
PRInt32 dpi = 96;
PRInt32 dpi = -1;
PRBool dotsArePixels = PR_TRUE;
// Get prefVal the value of the preference
// "layout.css.dpi"
// or -1 if we can't get it.
// If it's negative, use the default DPI setting
// If it's 0, force the use of the OS's set resolution. Set this if your
// X server has the correct DPI and it's less than 96dpi.
// If it's positive, we use it as the logical resolution
nsresult rv;
PRInt32 prefDPI;
nsCOMPtr<nsIPref> prefs(do_GetService(NS_PREF_CONTRACTID, &rv));
if (NS_SUCCEEDED(rv) && prefs) {
rv = prefs->GetIntPref("layout.css.dpi", &prefDPI);
if (NS_FAILED(rv)) {
prefDPI = -1;
// PostScript, PDF and Mac (when printing) all use 72 dpi
if (mPrintingSurface &&
(mPrintingSurface->GetType() == gfxASurface::SurfaceTypePDF ||
mPrintingSurface->GetType() == gfxASurface::SurfaceTypePS ||
mPrintingSurface->GetType() == gfxASurface::SurfaceTypeQuartz2)) {
dpi = 72;
dotsArePixels = PR_FALSE;
} else {
// Get prefVal the value of the preference
// "layout.css.dpi"
// or -1 if we can't get it.
// If it's negative, use the default DPI setting
// If it's 0, force the use of the OS's set resolution. Set this if your
// X server has the correct DPI and it's less than 96dpi.
// If it's positive, we use it as the logical resolution
nsresult rv;
PRInt32 prefDPI;
nsCOMPtr<nsIPref> prefs(do_GetService(NS_PREF_CONTRACTID, &rv));
if (NS_SUCCEEDED(rv) && prefs) {
rv = prefs->GetIntPref("layout.css.dpi", &prefDPI);
if (NS_FAILED(rv)) {
prefDPI = -1;
}
}
}
#if defined(MOZ_ENABLE_GTK2)
float screenWidthIn = float(::gdk_screen_width_mm()) / 25.4f;
PRInt32 OSVal = NSToCoordRound(float(::gdk_screen_width()) / screenWidthIn);
float screenWidthIn = float(::gdk_screen_width_mm()) / 25.4f;
PRInt32 OSVal = NSToCoordRound(float(::gdk_screen_width()) / screenWidthIn);
if (prefDPI == 0) // Force the use of the OS dpi
dpi = OSVal;
else // Otherwise, the minimum dpi is 96dpi
dpi = PR_MAX(OSVal, 96);
if (mPrinter) {
// cairo printing doesn't really have the
// notion of DPI so we have to use 72...
// XXX is this an issue? we force everything else to be 96+
dpi = 72;
}
if (prefDPI == 0) // Force the use of the OS dpi
dpi = OSVal;
else // Otherwise, the minimum dpi is 96dpi
dpi = PR_MAX(OSVal, 96);
#elif defined(XP_WIN)
// XXX we should really look at the widget for printing and such, but this widget is currently always null...
HDC dc = GetHDC() ? GetHDC() : GetDC((HWND)nsnull);
// XXX we should really look at the widget if !dc but it is currently always null
HDC dc = GetPrintHDC();
if (!dc)
dc = GetDC((HWND)nsnull);
PRInt32 OSVal = GetDeviceCaps(dc, LOGPIXELSY);
PRInt32 OSVal = GetDeviceCaps(dc, LOGPIXELSY);
if (dc != GetHDC())
ReleaseDC((HWND)nsnull, dc);
if (dc != GetPrintHDC())
ReleaseDC((HWND)nsnull, dc);
if (OSVal != 0)
dpi = OSVal;
if (OSVal != 0)
dpi = OSVal;
#elif defined(XP_MACOSX)
// XXX Need to get the screen DPI instead of defaulting to 96dpi
if (mPrinter) {
dpi = 72;
}
// we probably want to actually get a real DPI here?
dpi = 96;
#else
#error undefined platform dpi
#endif
if (prefDPI > 0 && !mPrinter)
dpi = prefDPI;
if (prefDPI > 0 && !mPrintingSurface)
dpi = prefDPI;
}
NS_ASSERTION(dpi != -1, "no dpi set");
if (dotsArePixels) {
// First figure out the closest multiple of 96, which is the number of
// dev pixels per CSS pixel. Then, divide that into AppUnitsPerCSSPixel()
// to get the number of app units per dev pixel. The PR_MAXes are to
// make sure we don't end up dividing by zero.
mAppUnitsPerDevPixel = PR_MAX(1, AppUnitsPerCSSPixel() /
PR_MAX(1, (dpi + 48) / 96));
} else {
/* set mAppUnitsPerDevPixel so we're using exactly 72 dpi, even
* though that means we have a non-integer number of device "pixels"
* per CSS pixel
*/
mAppUnitsPerDevPixel = (AppUnitsPerCSSPixel() * 96) / dpi;
}
// First figure out the closest multiple of 96, which is the number of
// dev pixels per CSS pixel. Then, divide that into AppUnitsPerCSSPixel()
// to get the number of app units per dev pixel. The PR_MAXes are to
// make sure we don't end up dividing by zero.
mAppUnitsPerDevPixel = PR_MAX(1, AppUnitsPerCSSPixel() /
PR_MAX(1, (dpi + 48) / 96));
mAppUnitsPerInch = NSIntPixelsToAppUnits(dpi, mAppUnitsPerDevPixel);
return NS_OK;
@ -412,7 +428,7 @@ nsThebesDeviceContext::ConvertPixel(nscolor aColor, PRUint32 & aPixel)
NS_IMETHODIMP
nsThebesDeviceContext::GetDeviceSurfaceDimensions(nscoord &aWidth, nscoord &aHeight)
{
if (mPrinter) {
if (mPrintingSurface) {
// we have a printer device
aWidth = mWidth;
aHeight = mHeight;
@ -429,7 +445,7 @@ nsThebesDeviceContext::GetDeviceSurfaceDimensions(nscoord &aWidth, nscoord &aHei
NS_IMETHODIMP
nsThebesDeviceContext::GetRect(nsRect &aRect)
{
if (mPrinter) {
if (mPrintingSurface) {
// we have a printer device
aRect.x = 0;
aRect.y = 0;
@ -444,7 +460,7 @@ nsThebesDeviceContext::GetRect(nsRect &aRect)
NS_IMETHODIMP
nsThebesDeviceContext::GetClientRect(nsRect &aRect)
{
if (mPrinter) {
if (mPrintingSurface) {
// we have a printer device
aRect.x = 0;
aRect.y = 0;
@ -475,9 +491,9 @@ nsThebesDeviceContext::InitForPrinting(nsIDeviceContextSpec *aDevice)
NS_ADDREF(mDeviceContextSpec = aDevice);
mPrinter = PR_TRUE;
aDevice->GetSurfaceForPrinter(getter_AddRefs(mPrintingSurface));
nsresult rv = aDevice->GetSurfaceForPrinter(getter_AddRefs(mPrintingSurface));
if (NS_FAILED(rv))
return NS_ERROR_FAILURE;
Init(nsnull);
@ -628,7 +644,7 @@ nsThebesDeviceContext::FindScreen(nsIScreen** outScreen)
void
nsThebesDeviceContext::CalcPrintingSize()
{
if (!mPrinter)
if (!mPrintingSurface)
return;
PRBool inPoints = PR_TRUE;
@ -640,11 +656,14 @@ nsThebesDeviceContext::CalcPrintingSize()
size = reinterpret_cast<gfxImageSurface*>(mPrintingSurface.get())->GetSize();
break;
#ifdef MOZ_ENABLE_GTK2
#if defined(MOZ_ENABLE_GTK2) || defined(XP_WIN)
case gfxASurface::SurfaceTypePDF:
inPoints = PR_TRUE;
size = reinterpret_cast<gfxPDFSurface*>(mPrintingSurface.get())->GetSize();
break;
#endif
#ifdef MOZ_ENABLE_GTK2
case gfxASurface::SurfaceTypePS:
inPoints = PR_TRUE;
size = reinterpret_cast<gfxPSSurface*>(mPrintingSurface.get())->GetSize();
@ -662,11 +681,13 @@ nsThebesDeviceContext::CalcPrintingSize()
case gfxASurface::SurfaceTypeWin32:
{
inPoints = PR_FALSE;
HDC dc = GetHDC() ? GetHDC() : GetDC((HWND)mWidget);
HDC dc = GetPrintHDC();
if (!dc)
dc = GetDC((HWND)mWidget);
size.width = NSIntPixelsToAppUnits(::GetDeviceCaps(dc, HORZRES), AppUnitsPerDevPixel());
size.height = NSIntPixelsToAppUnits(::GetDeviceCaps(dc, VERTRES), AppUnitsPerDevPixel());
mDepth = (PRUint32)::GetDeviceCaps(dc, BITSPIXEL);
if (dc != (HDC)GetHDC())
if (dc != (HDC)GetPrintHDC())
ReleaseDC((HWND)mWidget, dc);
break;
}

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

@ -68,7 +68,7 @@ public:
NS_DECL_ISUPPORTS_INHERITED
NS_IMETHOD Init(nsNativeWidget aWidget);
NS_IMETHOD InitForPrinting(nsIDeviceContextSpec* aDevSpec);
NS_IMETHOD InitForPrinting(nsIDeviceContextSpec *aDevSpec);
NS_IMETHOD CreateRenderingContext(nsIView *aView, nsIRenderingContext *&aContext);
NS_IMETHOD CreateRenderingContext(nsIDrawingSurface *aSurface, nsIRenderingContext *&aContext);
@ -76,8 +76,8 @@ public:
NS_IMETHOD CreateRenderingContext(nsIRenderingContext *&aContext);
NS_IMETHOD CreateRenderingContextInstance(nsIRenderingContext *&aContext);
NS_IMETHOD SupportsNativeWidgets(PRBool &aSupportsWidgets);
NS_IMETHOD PrepareNativeWidget(nsIWidget* aWidget, void** aOut);
NS_IMETHOD SupportsNativeWidgets(PRBool& aSupportsWidgets);
NS_IMETHOD PrepareNativeWidget(nsIWidget *aWidget, void **aOut);
NS_IMETHOD GetSystemFont(nsSystemFontID aID, nsFont *aFont) const;
@ -87,18 +87,18 @@ public:
NS_IMETHOD GetPaletteInfo(nsPaletteInfo& aPaletteInfo);
NS_IMETHOD ConvertPixel(nscolor aColor, PRUint32 & aPixel);
NS_IMETHOD ConvertPixel(nscolor aColor, PRUint32& aPixel);
NS_IMETHOD GetDeviceSurfaceDimensions(PRInt32 &aWidth, PRInt32 &aHeight);
NS_IMETHOD GetRect(nsRect &aRect);
NS_IMETHOD GetClientRect(nsRect &aRect);
NS_IMETHOD GetDeviceSurfaceDimensions(PRInt32& aWidth, PRInt32& aHeight);
NS_IMETHOD GetRect(nsRect& aRect);
NS_IMETHOD GetClientRect(nsRect& aRect);
/* printing goop */
NS_IMETHOD PrepareDocument(PRUnichar * aTitle,
PRUnichar* aPrintToFileName);
NS_IMETHOD PrepareDocument(PRUnichar *aTitle,
PRUnichar *aPrintToFileName);
NS_IMETHOD BeginDocument(PRUnichar* aTitle,
PRUnichar* aPrintToFileName,
NS_IMETHOD BeginDocument(PRUnichar *aTitle,
PRUnichar *aPrintToFileName,
PRInt32 aStartPage,
PRInt32 aEndPage);
@ -114,7 +114,7 @@ public:
nsNativeWidget GetWidget() { return mWidget; }
#ifdef XP_WIN
HDC GetHDC() {
HDC GetPrintHDC() {
if (mPrintingSurface) {
NS_ASSERTION(mPrintingSurface->GetType() == gfxASurface::SurfaceTypeWin32, "invalid surface type");
return reinterpret_cast<gfxWindowsSurface*>(mPrintingSurface.get())->GetDC();
@ -125,9 +125,9 @@ public:
protected:
nsresult SetDPI();
void ComputeClientRectUsingScreen(nsRect* outRect);
void ComputeFullAreaUsingScreen(nsRect* outRect);
void FindScreen(nsIScreen** outScreen);
void ComputeClientRectUsingScreen(nsRect *outRect);
void ComputeFullAreaUsingScreen(nsRect *outRect);
void FindScreen(nsIScreen **outScreen);
void CalcPrintingSize();
PRUint32 mDepth;
@ -137,12 +137,11 @@ private:
nscoord mWidth;
nscoord mHeight;
PRBool mPrinter;
nsRefPtrHashtable<nsISupportsHashKey, gfxASurface> mWidgetSurfaceCache;
nsRefPtr<gfxASurface> mPrintingSurface;
nsIDeviceContextSpec * mDeviceContextSpec;
nsIDeviceContextSpec *mDeviceContextSpec;
};
#endif /* _NS_CAIRODEVICECONTEXT_H_ */

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

@ -36,6 +36,7 @@ ifeq ($(MOZ_WIDGET_TOOLKIT),windows)
EXPORTS += gfxWindowsFonts.h \
gfxWindowsPlatform.h \
gfxWindowsSurface.h
EXPORTS += gfxPDFSurface.h
ifdef MOZ_ENABLE_GLITZ
REQUIRES += glitzwgl

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

@ -120,7 +120,7 @@ public:
thebes_destroy_func_t destroy);
void *GetData(const cairo_user_data_key_t *key);
void Finish();
virtual void Finish();
protected:
static gfxASurface* GetSurfaceWrapper(cairo_surface_t *csurf);

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

@ -40,17 +40,21 @@
#include "gfxASurface.h"
/* for the output stream */
#include "nsCOMPtr.h"
#include "nsIOutputStream.h"
class THEBES_API gfxPDFSurface : public gfxASurface {
public:
/* size is in points */
gfxPDFSurface(const char *filename, const gfxSize& aSizeInPonits);
gfxPDFSurface(nsIOutputStream *aStream, const gfxSize& aSizeInPonits);
virtual ~gfxPDFSurface();
nsresult BeginPrinting(const nsAString& aTitle, const nsAString& aPrintToFileName);
nsresult EndPrinting();
nsresult AbortPrinting();
nsresult BeginPage();
nsresult EndPage();
virtual nsresult BeginPrinting(const nsAString& aTitle, const nsAString& aPrintToFileName);
virtual nsresult EndPrinting();
virtual nsresult AbortPrinting();
virtual nsresult BeginPage();
virtual nsresult EndPage();
virtual void Finish();
void SetDPI(double x, double y);
void GetDPI(double *xDPI, double *yDPI);
@ -59,6 +63,7 @@ public:
const gfxSize& GetSize() const { return mSize; }
private:
nsCOMPtr<nsIOutputStream> mStream;
double mXDPI;
double mYDPI;
gfxSize mSize;

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

@ -38,22 +38,23 @@
#ifndef GFX_PSSURFACE_H
#define GFX_PSSURFACE_H
#include <stdio.h>
#include "gfxASurface.h"
/* for the output stream */
#include "nsCOMPtr.h"
#include "nsIOutputStream.h"
class THEBES_API gfxPSSurface : public gfxASurface {
public:
#ifdef UNTESTED_CODE
gfxPSSurface(FILE *file, gfxSize aSizeInPonits); /* does not close the file */
#endif
gfxPSSurface(const char *filename, const gfxSize& aSizeInPonits);
gfxPSSurface(nsIOutputStream *aStream, const gfxSize& aSizeInPonits);
virtual ~gfxPSSurface();
nsresult BeginPrinting(const nsAString& aTitle, const nsAString& aPrintToFileName);
nsresult EndPrinting();
nsresult AbortPrinting();
nsresult BeginPage();
nsresult EndPage();
virtual nsresult BeginPrinting(const nsAString& aTitle, const nsAString& aPrintToFileName);
virtual nsresult EndPrinting();
virtual nsresult AbortPrinting();
virtual nsresult BeginPage();
virtual nsresult EndPage();
virtual void Finish();
void SetDPI(double x, double y);
void GetDPI(double *xDPI, double *yDPI);
@ -62,6 +63,7 @@ public:
const gfxSize& GetSize() const { return mSize; }
private:
nsCOMPtr<nsIOutputStream> mStream;
double mXDPI;
double mYDPI;
gfxSize mSize;

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

@ -18,7 +18,6 @@ REQUIRES = \
pref \
xpcom \
unicharutil \
gfx \
$(NULL)
CPPSRCS = \
@ -58,6 +57,7 @@ CPPSRCS += gfxWindowsFonts.cpp \
gfxWindowsSurface.cpp \
nsUnicodeRange.cpp \
$(NULL)
CPPSRCS += gfxPDFSurface.cpp
_OS_LIBS = usp10
ifdef GNU_CXX

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

@ -40,10 +40,24 @@
#include "cairo.h"
#include "cairo-pdf.h"
gfxPDFSurface::gfxPDFSurface(const char *filename, const gfxSize& aSizeInPoints)
: mXDPI(-1), mYDPI(-1), mSize(aSizeInPoints)
static cairo_status_t
write_func(void *closure, const unsigned char *data, unsigned int length)
{
Init(cairo_pdf_surface_create(filename, mSize.width, mSize.height));
nsCOMPtr<nsIOutputStream> out = reinterpret_cast<nsIOutputStream*>(closure);
do {
PRUint32 wrote = 0;
if (NS_FAILED(out->Write((const char*)data, length, &wrote)))
break;
data += wrote; length -= wrote;
} while (length > 0);
NS_ASSERTION(length == 0, "not everything was written to the file");
return CAIRO_STATUS_SUCCESS;
}
gfxPDFSurface::gfxPDFSurface(nsIOutputStream *aStream, const gfxSize& aSizeInPoints)
: mStream(aStream), mXDPI(-1), mYDPI(-1), mSize(aSizeInPoints)
{
Init(cairo_pdf_surface_create_for_stream(write_func, (void*)mStream, mSize.width, mSize.height));
}
gfxPDFSurface::~gfxPDFSurface()
@ -83,6 +97,13 @@ gfxPDFSurface::EndPage()
return NS_OK;
}
void
gfxPDFSurface::Finish()
{
gfxASurface::Finish();
mStream->Close();
}
void
gfxPDFSurface::SetDPI(double xDPI, double yDPI)
{

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

@ -37,31 +37,28 @@
#include "gfxPSSurface.h"
#include <cairo-ps.h>
#include "cairo.h"
#include "cairo-ps.h"
#ifdef UNTESTED_CODE
static cairo_status_t
write_func(void *closure,
const unsigned char *data,
unsigned int length)
write_func(void *closure, const unsigned char *data, unsigned int length)
{
fwrite(data, 1, length, (FILE*)closure);
}
#endif
gfxPSSurface::gfxPSSurface(const char *filename, const gfxSize& aSizeInPoints)
: mXDPI(-1), mYDPI(-1), mSize(aSizeInPoints)
{
Init(cairo_ps_surface_create(filename, mSize.width, mSize.height));
nsCOMPtr<nsIOutputStream> out = reinterpret_cast<nsIOutputStream*>(closure);
do {
PRUint32 wrote = 0;
if (NS_FAILED(out->Write((const char*)data, length, &wrote)))
break;
data += wrote; length -= wrote;
} while (length > 0);
NS_ASSERTION(length == 0, "not everything was written to the file");
return CAIRO_STATUS_SUCCESS;
}
#ifdef UNTESTED_CODE
gfxPSSurface::gfxPSSurface(FILE *file, gfxSize aSizeInPoints)
: mXDPI(-1), mYDPI(-1), mSize(aSizeInPoints)
gfxPSSurface::gfxPSSurface(nsIOutputStream *aStream, const gfxSize& aSizeInPoints)
: mStream(aStream), mXDPI(-1), mYDPI(-1), mSize(aSizeInPoints)
{
Init(cairo_ps_surface_create_for_stream(write_func, file, mSize.width, mSize.height));
Init(cairo_ps_surface_create_for_stream(write_func, (void*)mStream, mSize.width, mSize.height));
}
#endif
gfxPSSurface::~gfxPSSurface()
{
@ -100,6 +97,13 @@ gfxPSSurface::EndPage()
return NS_OK;
}
void
gfxPSSurface::Finish()
{
gfxASurface::Finish();
mStream->Close();
}
void
gfxPSSurface::SetDPI(double xDPI, double yDPI)
{

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

@ -155,6 +155,13 @@ interface nsIPrintSettings : nsISupports
const short kFrameEnableAll = 1;
const short kFrameEnableAsIsAndEach = 2;
/**
* Output file format
*/
const short kOutputFormatNative = 0;
const short kOutputFormatPS = 1;
const short kOutputFormatPDF = 2;
/**
* Set PrintOptions
*/
@ -251,6 +258,7 @@ interface nsIPrintSettings : nsISupports
attribute boolean printToFile;
attribute wstring toFileName;
attribute short outputFormat;
attribute long printPageDelay; /* in milliseconds */

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

@ -71,6 +71,9 @@
#include "nsPrintJobFactoryGTK.h"
#include "nsIFileStreams.h"
#include "nsILocalFile.h"
/* Ensure that the result is always equal to either PR_TRUE or PR_FALSE */
#define MAKE_PR_BOOL(val) ((val)?(PR_TRUE):(PR_FALSE))
@ -438,11 +441,21 @@ NS_IMETHODIMP nsDeviceContextSpecGTK::GetSurfaceForPrinter(gfxASurface **aSurfac
printf("\"%s\", %d, %d\n", path, width, height);
nsCOMPtr<nsILocalFile> file = do_CreateInstance("@mozilla.org/file/local;1");
nsresult rv = file->InitWithPath(NS_ConvertUTF8toUTF16(filename));
if (NS_FAILED(rv))
return rv;
nsCOMPtr<nsIFileOutputStream> stream = do_CreateInstance("@mozilla.org/network/file-output-stream;1");
rv = stream->Init(file, -1, -1, 0);
if (NS_FAILED(rv))
return rv;
nsPrintJobFactoryGTK::CreatePrintJob((this), mPrintJob);
#ifdef USE_PDF
gfxPDFSurface *surface = new gfxPDFSurface(path, gfxSize(w, h));
gfxPDFSurface *surface = new gfxPDFSurface(stream, gfxSize(w, h));
#else
gfxPSSurface *surface = new gfxPSSurface(path, gfxSize(w, h));
gfxPSSurface *surface = new gfxPSSurface(stream, gfxSize(w, h));
#endif
// surface->SetDPI(600, 600);

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

@ -51,9 +51,11 @@
#include "nsIServiceManager.h"
#include "nsReadableUtils.h"
#ifdef MOZ_CAIRO_GFX
#include "gfxPDFSurface.h"
#include "gfxWindowsSurface.h"
#endif
#include "nsIFileStreams.h"
#include "nsUnitConversion.h"
#include "nsIWindowWatcher.h"
#include "nsIDOMWindow.h"
@ -517,19 +519,49 @@ NS_IMETHODIMP nsDeviceContextSpecWin::GetSurfaceForPrinter(gfxASurface **surface
{
NS_ASSERTION(mDevMode, "DevMode can't be NULL here");
if (mDevMode) {
HDC dc = ::CreateDC(mDriverName, mDeviceName, NULL, mDevMode);
nsRefPtr<gfxASurface> newSurface;
// have this surface take over ownership of this DC
nsRefPtr<gfxASurface> newSurface = new gfxWindowsSurface(dc, PR_TRUE);
PRInt16 outputFormat;
mPrintSettings->GetOutputFormat(&outputFormat);
if (outputFormat == nsIPrintSettings::kOutputFormatPDF) {
nsXPIDLString filename;
mPrintSettings->GetToFileName(getter_Copies(filename));
PRInt32 width, height;
mPrintSettings->GetPageSizeInTwips(&width, &height);
double w, h;
// convert twips to points
w = width/20;
h = height/20;
nsCOMPtr<nsILocalFile> file = do_CreateInstance("@mozilla.org/file/local;1");
nsresult rv = file->InitWithPath(filename);
if (NS_FAILED(rv))
return rv;
nsCOMPtr<nsIFileOutputStream> stream = do_CreateInstance("@mozilla.org/network/file-output-stream;1");
rv = stream->Init(file, -1, -1, 0);
if (NS_FAILED(rv))
return rv;
newSurface = new gfxPDFSurface(stream, gfxSize(w, h));
} else {
if (mDevMode) {
HDC dc = ::CreateDC(mDriverName, mDeviceName, NULL, mDevMode);
// have this surface take over ownership of this DC
newSurface = new gfxWindowsSurface(dc, PR_TRUE);
}
}
if (newSurface) {
*surface = newSurface;
NS_ADDREF(*surface);
return NS_OK;
}
*surface = nsnull;
return NS_ERROR_FAILURE;
}

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

@ -74,6 +74,7 @@ nsPrintSettings::nsPrintSettings() :
mOrientation(kPortraitOrientation),
mNumCopies(1),
mPrintToFile(PR_FALSE),
mOutputFormat(kOutputFormatNative),
mIsInitedFromPrinter(PR_FALSE),
mIsInitedFromPrefs(PR_FALSE)
{
@ -353,6 +354,19 @@ NS_IMETHODIMP nsPrintSettings::SetToFileName(const PRUnichar * aToFileName)
return NS_OK;
}
/* attribute short outputFormat; */
NS_IMETHODIMP nsPrintSettings::GetOutputFormat(PRInt16 *aOutputFormat)
{
NS_ENSURE_ARG_POINTER(aOutputFormat);
*aOutputFormat = mOutputFormat;
return NS_OK;
}
NS_IMETHODIMP nsPrintSettings::SetOutputFormat(PRInt16 aOutputFormat)
{
mOutputFormat = aOutputFormat;
return NS_OK;
}
/* attribute long printPageDelay; */
NS_IMETHODIMP nsPrintSettings::GetPrintPageDelay(PRInt32 *aPrintPageDelay)
{
@ -992,6 +1006,7 @@ nsPrintSettings& nsPrintSettings::operator=(const nsPrintSettings& rhs)
mPrinter = rhs.mPrinter;
mPrintToFile = rhs.mPrintToFile;
mToFileName = rhs.mToFileName;
mOutputFormat = rhs.mOutputFormat;
mPrintPageDelay = rhs.mPrintPageDelay;
for (PRInt32 i=0;i<NUM_HEAD_FOOT;i++) {

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

@ -128,6 +128,7 @@ protected:
nsXPIDLString mPrinter;
PRBool mPrintToFile;
nsString mToFileName;
PRInt16 mOutputFormat;
PRPackedBool mIsInitedFromPrinter;
PRPackedBool mIsInitedFromPrefs;