Commit 597c1a27 authored by Jonathan Watt's avatar Jonathan Watt
Browse files

Bug 1833244 p2. Create infrastructure to pass page dimensions to PrintTarget::BeginPage. r=dholbert

OS print drivers/devices know nothing about page dimensions unless we tell
them. Previously, the physical page dimensions (including orientation) have
always been the same, so communicating their dimensions once at the start of
a print has been enough. In preparation for supporting different "physical"
page dimensions (in the immediate future only different page orientations) when
we save to PDF, we need to have the infrastructure to pass dimensions through
on a page-by-page basis. This patch adds that.

None of the PrintTarget subclasses do anything with this extra information yet,
but in a follow-up patch PrintTargetPDF will use this information to create
PDFs with mixed page orientations.

Differential Revision: https://phabricator.services.mozilla.com/D179423
parent ae4a3b7b
Loading
Loading
Loading
Loading
+3 −3
Original line number Diff line number Diff line
@@ -327,14 +327,14 @@ nsresult nsDeviceContext::AbortDocument() {
  return rv;
}

nsresult nsDeviceContext::BeginPage() {
nsresult nsDeviceContext::BeginPage(const IntSize& aSizeInPoints) {
  MOZ_DIAGNOSTIC_ASSERT(!mIsCurrentlyPrintingDoc || mPrintTarget,
                        "What nulled out our print target while printing?");
  if (mDeviceContextSpec) {
    MOZ_TRY(mDeviceContextSpec->BeginPage());
    MOZ_TRY(mDeviceContextSpec->BeginPage(aSizeInPoints));
  }
  if (mPrintTarget) {
    MOZ_TRY(mPrintTarget->BeginPage());
    MOZ_TRY(mPrintTarget->BeginPage(aSizeInPoints));
  }
  return NS_OK;
}
+12 −2
Original line number Diff line number Diff line
@@ -20,6 +20,7 @@
#include "nscore.h"                   // for char16_t, nsAString
#include "mozilla/AppUnits.h"         // for AppUnits
#include "nsFontMetrics.h"            // for nsFontMetrics::Params
#include "mozilla/gfx/Point.h"        // for IntSize
#include "mozilla/gfx/PrintTarget.h"  // for PrintTarget::PageDoneCallback
#include "mozilla/gfx/PrintPromise.h"

@@ -48,7 +49,8 @@ class Screen;

class nsDeviceContext final {
 public:
  typedef mozilla::gfx::PrintTarget PrintTarget;
  using IntSize = mozilla::gfx::IntSize;
  using PrintTarget = mozilla::gfx::PrintTarget;

  nsDeviceContext();

@@ -223,9 +225,17 @@ class nsDeviceContext final {
   * Inform the output device that output of a page is beginning
   * Used for print related device contexts. Must be matched 1:1 with
   * EndPage() and within a BeginDocument()/EndDocument() pair.
   *
   * @param aSizeInPoints - The physical dimensions of the page in points.
   *                        Currently only supported (used) by print-to-PDF
   *                        print targets, and then only to switch the
   *                        orientation for a specific page (arbitrary page
   *                        sizes are not supported by the Core Graphics print-
   *                        to-PDF APIs, for example).
   *
   * @return error status
   */
  nsresult BeginPage();
  nsresult BeginPage(const IntSize& aSizeInPoints);

  /**
   * Inform the output device that output of a page is ending
+5 −1
Original line number Diff line number Diff line
@@ -43,7 +43,11 @@ class PrintTarget {
#endif
    return NS_OK;
  }
  virtual nsresult BeginPage() {
  /**
   * Note: not all print devices implement mixed page sizing. Most PrintTarget
   * subclasses will ignore `aSizeInPoints`.
   */
  virtual nsresult BeginPage(const IntSize& aSizeInPoints) {
#ifdef DEBUG
    MOZ_ASSERT(!mHasActivePage, "Missing EndPage() call");
    mHasActivePage = true;
+1 −1
Original line number Diff line number Diff line
@@ -28,7 +28,7 @@ class PrintTargetCG final : public PrintTarget {
                         int32_t aEndPage) final;
  nsresult EndPrinting() final;
  nsresult AbortPrinting() final;
  nsresult BeginPage() final;
  nsresult BeginPage(const IntSize& aSizeInPoints) final;
  nsresult EndPage() final;

  already_AddRefed<DrawTarget> GetReferenceDrawTarget() final;
+2 −2
Original line number Diff line number Diff line
@@ -210,7 +210,7 @@ nsresult PrintTargetCG::AbortPrinting() {
  return EndPrinting();
}

nsresult PrintTargetCG::BeginPage() {
nsresult PrintTargetCG::BeginPage(const IntSize& aSizeInPoints) {
  NS_OBJC_BEGIN_TRY_BLOCK_RETURN;

  CGContextRef context;
@@ -249,7 +249,7 @@ nsresult PrintTargetCG::BeginPage() {

  mCairoSurface = surface;

  return PrintTarget::BeginPage();
  return PrintTarget::BeginPage(aSizeInPoints);

  NS_OBJC_END_TRY_BLOCK_RETURN(NS_ERROR_FAILURE);
}
Loading