1.1 --- /dev/null Thu Jan 01 00:00:00 1970 +0000 1.2 +++ b/gfx/thebes/gfxPDFSurface.cpp Wed Dec 31 06:09:35 2014 +0100 1.3 @@ -0,0 +1,86 @@ 1.4 +/* -*- Mode: C++; tab-width: 20; indent-tabs-mode: nil; c-basic-offset: 4 -*- 1.5 + * This Source Code Form is subject to the terms of the Mozilla Public 1.6 + * License, v. 2.0. If a copy of the MPL was not distributed with this 1.7 + * file, You can obtain one at http://mozilla.org/MPL/2.0/. */ 1.8 + 1.9 +#include "gfxPDFSurface.h" 1.10 + 1.11 +#include "cairo.h" 1.12 +#include "cairo-pdf.h" 1.13 + 1.14 +static cairo_status_t 1.15 +write_func(void *closure, const unsigned char *data, unsigned int length) 1.16 +{ 1.17 + nsCOMPtr<nsIOutputStream> out = reinterpret_cast<nsIOutputStream*>(closure); 1.18 + do { 1.19 + uint32_t wrote = 0; 1.20 + if (NS_FAILED(out->Write((const char*)data, length, &wrote))) 1.21 + break; 1.22 + data += wrote; length -= wrote; 1.23 + } while (length > 0); 1.24 + NS_ASSERTION(length == 0, "not everything was written to the file"); 1.25 + return CAIRO_STATUS_SUCCESS; 1.26 +} 1.27 + 1.28 +gfxPDFSurface::gfxPDFSurface(nsIOutputStream *aStream, const gfxSize& aSizeInPoints) 1.29 + : mStream(aStream), mXDPI(-1), mYDPI(-1), mSize(aSizeInPoints) 1.30 +{ 1.31 + Init(cairo_pdf_surface_create_for_stream(write_func, (void*)mStream, mSize.width, mSize.height)); 1.32 +} 1.33 + 1.34 +gfxPDFSurface::~gfxPDFSurface() 1.35 +{ 1.36 +} 1.37 + 1.38 +nsresult 1.39 +gfxPDFSurface::BeginPrinting(const nsAString& aTitle, const nsAString& aPrintToFileName) 1.40 +{ 1.41 + return NS_OK; 1.42 +} 1.43 + 1.44 +nsresult 1.45 +gfxPDFSurface::EndPrinting() 1.46 +{ 1.47 + return NS_OK; 1.48 +} 1.49 + 1.50 +nsresult 1.51 +gfxPDFSurface::AbortPrinting() 1.52 +{ 1.53 + return NS_OK; 1.54 +} 1.55 + 1.56 +nsresult 1.57 +gfxPDFSurface::BeginPage() 1.58 +{ 1.59 + return NS_OK; 1.60 +} 1.61 + 1.62 +nsresult 1.63 +gfxPDFSurface::EndPage() 1.64 +{ 1.65 + cairo_surface_show_page(CairoSurface()); 1.66 + return NS_OK; 1.67 +} 1.68 + 1.69 +void 1.70 +gfxPDFSurface::Finish() 1.71 +{ 1.72 + gfxASurface::Finish(); 1.73 + mStream->Close(); 1.74 +} 1.75 + 1.76 +void 1.77 +gfxPDFSurface::SetDPI(double xDPI, double yDPI) 1.78 +{ 1.79 + mXDPI = xDPI; 1.80 + mYDPI = yDPI; 1.81 + cairo_surface_set_fallback_resolution(CairoSurface(), xDPI, yDPI); 1.82 +} 1.83 + 1.84 +void 1.85 +gfxPDFSurface::GetDPI(double *xDPI, double *yDPI) 1.86 +{ 1.87 + *xDPI = mXDPI; 1.88 + *yDPI = mYDPI; 1.89 +}