tor-browser

The Tor Browser
git clone https://git.dasho.dev/tor-browser.git
Log | Files | Refs | README | LICENSE

PrintTargetSkPDF.h (2312B)


      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/. */
      5 
      6 #ifndef MOZILLA_GFX_PRINTTARGETSKPDF_H
      7 #define MOZILLA_GFX_PRINTTARGETSKPDF_H
      8 
      9 #include "mozilla/UniquePtr.h"
     10 #include "nsCOMPtr.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"
     15 
     16 namespace mozilla {
     17 namespace gfx {
     18 
     19 /**
     20 * Skia PDF printing target.
     21 */
     22 class PrintTargetSkPDF final : public PrintTarget {
     23 public:
     24  static already_AddRefed<PrintTargetSkPDF> CreateOrNull(
     25      UniquePtr<SkWStream> aStream, const IntSize& aSizeInPoints);
     26  static already_AddRefed<PrintTargetSkPDF> CreateOrNull(
     27      nsIOutputStream* aStream, const IntSize& aSizeInPoints);
     28 
     29  nsresult BeginPrinting(const nsAString& aTitle,
     30                         const nsAString& aPrintToFileName, int32_t aStartPage,
     31                         int32_t aEndPage) override;
     32  nsresult EndPrinting() override;
     33  void Finish() override;
     34 
     35  nsresult BeginPage(const IntSize& aSizeInPoints) override;
     36  nsresult EndPage() override;
     37 
     38  already_AddRefed<DrawTarget> MakeDrawTarget(
     39      const IntSize& aSize, DrawEventRecorder* aRecorder = nullptr) final;
     40 
     41  already_AddRefed<DrawTarget> GetReferenceDrawTarget() final;
     42 
     43 private:
     44  PrintTargetSkPDF(const IntSize& aSize, UniquePtr<SkWStream> aStream);
     45  virtual ~PrintTargetSkPDF();
     46 
     47  // Do not hand out references to this object.  It holds a non-owning
     48  // reference to mOStreame, so must not outlive mOStream.
     49  sk_sp<SkDocument> mPDFDoc;
     50 
     51  // The stream that the SkDocument outputs to.
     52  UniquePtr<SkWStream> mOStream;
     53 
     54  // The current page's SkCanvas and its wrapping DrawTarget:
     55  // Canvas is owned by mPDFDoc, which handles its deletion.
     56  SkCanvas* mPageCanvas;
     57  RefPtr<DrawTarget> mPageDT;
     58 
     59  // Members needed to provide a reference DrawTarget:
     60  sk_sp<SkDocument> mRefPDFDoc;
     61  // Canvas owned by mRefPDFDoc, which handles its deletion.
     62  SkCanvas* mRefCanvas;
     63  SkDynamicMemoryWStream mRefOStream;
     64 };
     65 
     66 }  // namespace gfx
     67 }  // namespace mozilla
     68 
     69 #endif /* MOZILLA_GFX_PRINTTARGETSKPDF_H */