michael@0: /* -*- Mode: C++; tab-width: 20; indent-tabs-mode: nil; c-basic-offset: 4 -*- michael@0: * This Source Code Form is subject to the terms of the Mozilla Public michael@0: * License, v. 2.0. If a copy of the MPL was not distributed with this michael@0: * file, You can obtain one at http://mozilla.org/MPL/2.0/. */ michael@0: michael@0: #include "gfxPDFSurface.h" michael@0: michael@0: #include "cairo.h" michael@0: #include "cairo-pdf.h" michael@0: michael@0: static cairo_status_t michael@0: write_func(void *closure, const unsigned char *data, unsigned int length) michael@0: { michael@0: nsCOMPtr out = reinterpret_cast(closure); michael@0: do { michael@0: uint32_t wrote = 0; michael@0: if (NS_FAILED(out->Write((const char*)data, length, &wrote))) michael@0: break; michael@0: data += wrote; length -= wrote; michael@0: } while (length > 0); michael@0: NS_ASSERTION(length == 0, "not everything was written to the file"); michael@0: return CAIRO_STATUS_SUCCESS; michael@0: } michael@0: michael@0: gfxPDFSurface::gfxPDFSurface(nsIOutputStream *aStream, const gfxSize& aSizeInPoints) michael@0: : mStream(aStream), mXDPI(-1), mYDPI(-1), mSize(aSizeInPoints) michael@0: { michael@0: Init(cairo_pdf_surface_create_for_stream(write_func, (void*)mStream, mSize.width, mSize.height)); michael@0: } michael@0: michael@0: gfxPDFSurface::~gfxPDFSurface() michael@0: { michael@0: } michael@0: michael@0: nsresult michael@0: gfxPDFSurface::BeginPrinting(const nsAString& aTitle, const nsAString& aPrintToFileName) michael@0: { michael@0: return NS_OK; michael@0: } michael@0: michael@0: nsresult michael@0: gfxPDFSurface::EndPrinting() michael@0: { michael@0: return NS_OK; michael@0: } michael@0: michael@0: nsresult michael@0: gfxPDFSurface::AbortPrinting() michael@0: { michael@0: return NS_OK; michael@0: } michael@0: michael@0: nsresult michael@0: gfxPDFSurface::BeginPage() michael@0: { michael@0: return NS_OK; michael@0: } michael@0: michael@0: nsresult michael@0: gfxPDFSurface::EndPage() michael@0: { michael@0: cairo_surface_show_page(CairoSurface()); michael@0: return NS_OK; michael@0: } michael@0: michael@0: void michael@0: gfxPDFSurface::Finish() michael@0: { michael@0: gfxASurface::Finish(); michael@0: mStream->Close(); michael@0: } michael@0: michael@0: void michael@0: gfxPDFSurface::SetDPI(double xDPI, double yDPI) michael@0: { michael@0: mXDPI = xDPI; michael@0: mYDPI = yDPI; michael@0: cairo_surface_set_fallback_resolution(CairoSurface(), xDPI, yDPI); michael@0: } michael@0: michael@0: void michael@0: gfxPDFSurface::GetDPI(double *xDPI, double *yDPI) michael@0: { michael@0: *xDPI = mXDPI; michael@0: *yDPI = mYDPI; michael@0: }