1 /* -*- Mode: C++; tab-width: 20; indent-tabs-mode: nil; c-basic-offset: 2 -*-
2 * This Source Code Form is subject to the terms of the Mozilla Public
3 * License, v. 2.0. If a copy of the MPL was not distributed with this
4 * file, You can obtain one at http://mozilla.org/MPL/2.0/. */
6 #ifndef MOZILLA_GFX_PRINTTARGETSKPDF_H
7 #define MOZILLA_GFX_PRINTTARGETSKPDF_H
9 #include "mozilla/UniquePtr.h"
11 #include "PrintTarget.h"
12 #include "skia/include/core/SkCanvas.h"
13 #include "skia/include/docs/SkPDFDocument.h"
14 #include "skia/include/core/SkStream.h"
20 * Skia PDF printing target.
22 class PrintTargetSkPDF final
: public PrintTarget
{
24 // The returned PrintTargetSkPDF keeps a raw pointer to the passed SkWStream
25 // but does not own it. Callers are responsible for ensuring that passed
26 // stream outlives the returned PrintTarget.
27 static already_AddRefed
<PrintTargetSkPDF
> CreateOrNull(
28 UniquePtr
<SkWStream
> aStream
, const IntSize
& aSizeInPoints
);
30 nsresult
BeginPrinting(const nsAString
& aTitle
,
31 const nsAString
& aPrintToFileName
, int32_t aStartPage
,
32 int32_t aEndPage
) override
;
33 nsresult
EndPrinting() override
;
34 void Finish() override
;
36 nsresult
BeginPage() override
;
37 nsresult
EndPage() override
;
39 already_AddRefed
<DrawTarget
> MakeDrawTarget(
40 const IntSize
& aSize
, DrawEventRecorder
* aRecorder
= nullptr) final
;
42 already_AddRefed
<DrawTarget
> GetReferenceDrawTarget() final
;
45 PrintTargetSkPDF(const IntSize
& aSize
, UniquePtr
<SkWStream
> aStream
);
46 virtual ~PrintTargetSkPDF();
48 // Do not hand out references to this object. It holds a non-owning
49 // reference to mOStreame, so must not outlive mOStream.
50 sk_sp
<SkDocument
> mPDFDoc
;
52 // The stream that the SkDocument outputs to.
53 UniquePtr
<SkWStream
> mOStream
;
55 // The current page's SkCanvas and its wrapping DrawTarget:
56 // Canvas is owned by mPDFDoc, which handles its deletion.
57 SkCanvas
* mPageCanvas
;
58 RefPtr
<DrawTarget
> mPageDT
;
60 // Members needed to provide a reference DrawTarget:
61 sk_sp
<SkDocument
> mRefPDFDoc
;
62 // Canvas owned by mRefPDFDoc, which handles its deletion.
64 SkDynamicMemoryWStream mRefOStream
;
68 } // namespace mozilla
70 #endif /* MOZILLA_GFX_PRINTTARGETSKPDF_H */