gfx/thebes/gfxPDFSurface.cpp

Thu, 22 Jan 2015 13:21:57 +0100

author
Michael Schloh von Bennewitz <michael@schloh.com>
date
Thu, 22 Jan 2015 13:21:57 +0100
branch
TOR_BUG_9701
changeset 15
b8a032363ba2
permissions
-rw-r--r--

Incorporate requested changes from Mozilla in review:
https://bugzilla.mozilla.org/show_bug.cgi?id=1123480#c6

michael@0 1 /* -*- Mode: C++; tab-width: 20; indent-tabs-mode: nil; c-basic-offset: 4 -*-
michael@0 2 * This Source Code Form is subject to the terms of the Mozilla Public
michael@0 3 * License, v. 2.0. If a copy of the MPL was not distributed with this
michael@0 4 * file, You can obtain one at http://mozilla.org/MPL/2.0/. */
michael@0 5
michael@0 6 #include "gfxPDFSurface.h"
michael@0 7
michael@0 8 #include "cairo.h"
michael@0 9 #include "cairo-pdf.h"
michael@0 10
michael@0 11 static cairo_status_t
michael@0 12 write_func(void *closure, const unsigned char *data, unsigned int length)
michael@0 13 {
michael@0 14 nsCOMPtr<nsIOutputStream> out = reinterpret_cast<nsIOutputStream*>(closure);
michael@0 15 do {
michael@0 16 uint32_t wrote = 0;
michael@0 17 if (NS_FAILED(out->Write((const char*)data, length, &wrote)))
michael@0 18 break;
michael@0 19 data += wrote; length -= wrote;
michael@0 20 } while (length > 0);
michael@0 21 NS_ASSERTION(length == 0, "not everything was written to the file");
michael@0 22 return CAIRO_STATUS_SUCCESS;
michael@0 23 }
michael@0 24
michael@0 25 gfxPDFSurface::gfxPDFSurface(nsIOutputStream *aStream, const gfxSize& aSizeInPoints)
michael@0 26 : mStream(aStream), mXDPI(-1), mYDPI(-1), mSize(aSizeInPoints)
michael@0 27 {
michael@0 28 Init(cairo_pdf_surface_create_for_stream(write_func, (void*)mStream, mSize.width, mSize.height));
michael@0 29 }
michael@0 30
michael@0 31 gfxPDFSurface::~gfxPDFSurface()
michael@0 32 {
michael@0 33 }
michael@0 34
michael@0 35 nsresult
michael@0 36 gfxPDFSurface::BeginPrinting(const nsAString& aTitle, const nsAString& aPrintToFileName)
michael@0 37 {
michael@0 38 return NS_OK;
michael@0 39 }
michael@0 40
michael@0 41 nsresult
michael@0 42 gfxPDFSurface::EndPrinting()
michael@0 43 {
michael@0 44 return NS_OK;
michael@0 45 }
michael@0 46
michael@0 47 nsresult
michael@0 48 gfxPDFSurface::AbortPrinting()
michael@0 49 {
michael@0 50 return NS_OK;
michael@0 51 }
michael@0 52
michael@0 53 nsresult
michael@0 54 gfxPDFSurface::BeginPage()
michael@0 55 {
michael@0 56 return NS_OK;
michael@0 57 }
michael@0 58
michael@0 59 nsresult
michael@0 60 gfxPDFSurface::EndPage()
michael@0 61 {
michael@0 62 cairo_surface_show_page(CairoSurface());
michael@0 63 return NS_OK;
michael@0 64 }
michael@0 65
michael@0 66 void
michael@0 67 gfxPDFSurface::Finish()
michael@0 68 {
michael@0 69 gfxASurface::Finish();
michael@0 70 mStream->Close();
michael@0 71 }
michael@0 72
michael@0 73 void
michael@0 74 gfxPDFSurface::SetDPI(double xDPI, double yDPI)
michael@0 75 {
michael@0 76 mXDPI = xDPI;
michael@0 77 mYDPI = yDPI;
michael@0 78 cairo_surface_set_fallback_resolution(CairoSurface(), xDPI, yDPI);
michael@0 79 }
michael@0 80
michael@0 81 void
michael@0 82 gfxPDFSurface::GetDPI(double *xDPI, double *yDPI)
michael@0 83 {
michael@0 84 *xDPI = mXDPI;
michael@0 85 *yDPI = mYDPI;
michael@0 86 }

mercurial