DXR is a code search and navigation tool aimed at making sense of large projects. It supports full-text and regex searches as well as structural queries.

Implementation

Mercurial (e67641c2e4cc)

VCS Links

Line Code
1 2 3 4 5 6 7 8 9 10 11 12 13 14 15 16 17 18 19 20 21 22 23 24 25 26 27 28 29 30 31 32 33 34 35 36 37 38 39 40 41 42 43 44 45 46 47 48 49 50 51 52 53 54 55 56 57 58 59 60 61 62 63 64 65 66 67 68 69 70 71 72 73
/* -*- Mode: C++; tab-width: 20; indent-tabs-mode: nil; c-basic-offset: 4 -*-
 * This Source Code Form is subject to the terms of the Mozilla Public
 * License, v. 2.0. If a copy of the MPL was not distributed with this
 * file, You can obtain one at http://mozilla.org/MPL/2.0/. */

#ifndef MOZILLA_GFX_PRINTTARGETEMF_H
#define MOZILLA_GFX_PRINTTARGETEMF_H

#include "PrintTargetSkPDF.h"
#include "mozilla/ipc/Shmem.h"

/* include windows.h for the HDC definitions that we need. */
#include <windows.h>

namespace mozilla {
namespace widget {
class PDFiumProcessParent;
}
}  // namespace mozilla

namespace mozilla {
namespace gfx {

/**
 * A new subclass of PrintTarget.
 * 1. It uses PrintTargetSkPDF to generate one PDF file for one page.
 * 2. It then passes the FileDescriptor of that generated PDF file to the
 *    PDFium process for EMF conversion.
 * 3. After getting the converted EMF contents from the PDFium process, it then
 *    draws it onto the printer DC to finish one page printing task.
 */
class PrintTargetEMF final : public mozilla::gfx::PrintTarget {
 public:
  typedef gfx::IntSize IntSize;
  typedef mozilla::widget::PDFiumProcessParent PDFiumProcessParent;

  static already_AddRefed<PrintTargetEMF> CreateOrNull(
      HDC aDC, const IntSize& aSizeInPoints);

  nsresult BeginPrinting(const nsAString& aTitle,
                         const nsAString& aPrintToFileName, int32_t aStartPage,
                         int32_t aEndPage) final;
  nsresult EndPrinting() final;
  nsresult AbortPrinting() final;
  nsresult BeginPage() final;
  nsresult EndPage() final;

  already_AddRefed<DrawTarget> MakeDrawTarget(
      const IntSize& aSize, DrawEventRecorder* aRecorder = nullptr) final;

  already_AddRefed<DrawTarget> GetReferenceDrawTarget() final;

  void ConvertToEMFDone(const nsresult& aResult, mozilla::ipc::Shmem&& aEMF);
  bool IsSyncPagePrinting() const final { return false; }
  void ChannelIsBroken() { mChannelBroken = true; }

 private:
  PrintTargetEMF(HDC aDC, const IntSize& aSize);
  ~PrintTargetEMF() override;

  nsString mTitle;
  RefPtr<PrintTargetSkPDF> mTargetForCurrentPage;
  nsCOMPtr<nsIFile> mPDFFileForOnePage;
  RefPtr<PrintTargetSkPDF> mRefTarget;
  PDFiumProcessParent* mPDFiumProcess;
  HDC mPrinterDC;
  bool mChannelBroken;
};

}  // namespace gfx
}  // namespace mozilla

#endif /* MOZILLA_GFX_PRINTTARGETEMF_H */