1 /* -*- Mode: C++; tab-width: 4; 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 #include "nsPrintSettingsImpl.h"
11 #include "nsReadableUtils.h"
12 #include "nsIPrintSession.h"
13 #include "mozilla/DebugOnly.h"
14 #include "mozilla/RefPtr.h"
16 #define DEFAULT_MARGIN_WIDTH 0.5
18 NS_IMPL_ISUPPORTS(nsPrintSettings
, nsIPrintSettings
)
20 nsPrintSettings::nsPrintSettings()
22 mPrintBGColors(false),
23 mPrintBGImages(false),
28 mShowPrintProgress(true),
29 mShowMarginGuides(false),
30 mHonorPageRuleMargins(true),
31 mIsPrintSelectionRBEnabled(false),
32 mPrintSelectionOnly(false),
36 mPaperSizeUnit(kPaperSizeInches
),
37 mPrintReversed(false),
39 mOrientation(kPortraitOrientation
),
45 mOutputFormat(kOutputFormatNative
),
46 mIsInitedFromPrinter(false),
47 mIsInitedFromPrefs(false) {
48 /* member initializers and constructor code */
49 int32_t marginWidth
= NS_INCHES_TO_INT_TWIPS(DEFAULT_MARGIN_WIDTH
);
50 mMargin
.SizeTo(marginWidth
, marginWidth
, marginWidth
, marginWidth
);
51 mEdge
.SizeTo(0, 0, 0, 0);
52 mUnwriteableMargin
.SizeTo(0, 0, 0, 0);
54 mHeaderStrs
[0].AssignLiteral("&T");
55 mHeaderStrs
[2].AssignLiteral("&U");
57 mFooterStrs
[0].AssignLiteral(
58 "&PT"); // Use &P (Page Num Only) or &PT (Page Num of Page Total)
59 mFooterStrs
[2].AssignLiteral("&D");
62 void nsPrintSettings::InitWithInitializer(
63 const PrintSettingsInitializer
& aSettings
) {
64 const double kInchesPerPoint
= 1.0 / 72.0;
66 SetPrinterName(aSettings
.mPrinter
);
67 SetPrintInColor(aSettings
.mPrintInColor
);
68 SetResolution(aSettings
.mResolution
);
69 // The paper ID used by nsPrintSettings is the non-localizable identifier
70 // exposed as "id" by the paper, not the potentially localized human-friendly
71 // "name", which could change, e.g. if the user changes their system locale.
72 SetPaperId(aSettings
.mPaperInfo
.mId
);
73 SetPaperWidth(aSettings
.mPaperInfo
.mSize
.Width() * kInchesPerPoint
);
74 SetPaperHeight(aSettings
.mPaperInfo
.mSize
.Height() * kInchesPerPoint
);
75 SetPaperSizeUnit(nsIPrintSettings::kPaperSizeInches
);
77 if (aSettings
.mPaperInfo
.mUnwriteableMargin
) {
78 const auto& margin
= aSettings
.mPaperInfo
.mUnwriteableMargin
.value();
79 // Margins are stored internally in TWIPS, but the setters expect inches.
80 SetUnwriteableMarginTop(margin
.top
* kInchesPerPoint
);
81 SetUnwriteableMarginRight(margin
.right
* kInchesPerPoint
);
82 SetUnwriteableMarginBottom(margin
.bottom
* kInchesPerPoint
);
83 SetUnwriteableMarginLeft(margin
.left
* kInchesPerPoint
);
86 // Set this last because other setters may overwrite its value.
87 SetIsInitializedFromPrinter(true);
90 nsPrintSettings::nsPrintSettings(const nsPrintSettings
& aPS
) { *this = aPS
; }
92 nsPrintSettings::~nsPrintSettings() = default;
94 NS_IMETHODIMP
nsPrintSettings::GetPrintSession(
95 nsIPrintSession
** aPrintSession
) {
96 NS_ENSURE_ARG_POINTER(aPrintSession
);
97 *aPrintSession
= nullptr;
99 nsCOMPtr
<nsIPrintSession
> session
= do_QueryReferent(mSession
);
100 if (!session
) return NS_ERROR_NOT_INITIALIZED
;
101 *aPrintSession
= session
;
102 NS_ADDREF(*aPrintSession
);
106 NS_IMETHODIMP
nsPrintSettings::SetPrintSession(nsIPrintSession
* aPrintSession
) {
107 // Clearing it by passing nullptr is not allowed. That's why we
108 // use a weak ref so that it doesn't have to be cleared.
109 NS_ENSURE_ARG(aPrintSession
);
111 mSession
= do_GetWeakReference(aPrintSession
);
113 // This may happen if the implementation of this object does
114 // not support weak references - programmer error.
115 NS_ERROR("Could not get a weak reference from aPrintSession");
116 return NS_ERROR_FAILURE
;
121 NS_IMETHODIMP
nsPrintSettings::GetPrintReversed(bool* aPrintReversed
) {
122 *aPrintReversed
= mPrintReversed
;
125 NS_IMETHODIMP
nsPrintSettings::SetPrintReversed(bool aPrintReversed
) {
126 mPrintReversed
= aPrintReversed
;
130 NS_IMETHODIMP
nsPrintSettings::GetPrintInColor(bool* aPrintInColor
) {
131 *aPrintInColor
= mPrintInColor
;
134 NS_IMETHODIMP
nsPrintSettings::SetPrintInColor(bool aPrintInColor
) {
135 mPrintInColor
= aPrintInColor
;
139 NS_IMETHODIMP
nsPrintSettings::GetOrientation(int32_t* aOrientation
) {
140 *aOrientation
= mOrientation
;
143 NS_IMETHODIMP
nsPrintSettings::SetOrientation(int32_t aOrientation
) {
144 mOrientation
= aOrientation
;
148 NS_IMETHODIMP
nsPrintSettings::GetResolution(int32_t* aResolution
) {
149 NS_ENSURE_ARG_POINTER(aResolution
);
150 *aResolution
= mResolution
;
153 NS_IMETHODIMP
nsPrintSettings::SetResolution(const int32_t aResolution
) {
154 mResolution
= aResolution
;
158 NS_IMETHODIMP
nsPrintSettings::GetDuplex(int32_t* aDuplex
) {
159 NS_ENSURE_ARG_POINTER(aDuplex
);
163 NS_IMETHODIMP
nsPrintSettings::SetDuplex(const int32_t aDuplex
) {
168 NS_IMETHODIMP
nsPrintSettings::GetPrinterName(nsAString
& aPrinter
) {
173 NS_IMETHODIMP
nsPrintSettings::SetPrinterName(const nsAString
& aPrinter
) {
174 if (!mPrinter
.Equals(aPrinter
)) {
175 mIsInitedFromPrinter
= false;
176 mIsInitedFromPrefs
= false;
179 mPrinter
.Assign(aPrinter
);
183 NS_IMETHODIMP
nsPrintSettings::GetNumCopies(int32_t* aNumCopies
) {
184 NS_ENSURE_ARG_POINTER(aNumCopies
);
185 *aNumCopies
= mNumCopies
;
188 NS_IMETHODIMP
nsPrintSettings::SetNumCopies(int32_t aNumCopies
) {
189 mNumCopies
= aNumCopies
;
193 NS_IMETHODIMP
nsPrintSettings::GetNumPagesPerSheet(int32_t* aNumPagesPerSheet
) {
194 NS_ENSURE_ARG_POINTER(aNumPagesPerSheet
);
195 *aNumPagesPerSheet
= mNumPagesPerSheet
;
198 NS_IMETHODIMP
nsPrintSettings::SetNumPagesPerSheet(int32_t aNumPagesPerSheet
) {
199 mNumPagesPerSheet
= aNumPagesPerSheet
;
203 NS_IMETHODIMP
nsPrintSettings::GetPrintToFile(bool* aPrintToFile
) {
204 NS_ENSURE_ARG_POINTER(aPrintToFile
);
205 *aPrintToFile
= mPrintToFile
;
208 NS_IMETHODIMP
nsPrintSettings::SetPrintToFile(bool aPrintToFile
) {
209 mPrintToFile
= aPrintToFile
;
213 NS_IMETHODIMP
nsPrintSettings::GetToFileName(nsAString
& aToFileName
) {
214 aToFileName
= mToFileName
;
217 NS_IMETHODIMP
nsPrintSettings::SetToFileName(const nsAString
& aToFileName
) {
218 mToFileName
= aToFileName
;
222 NS_IMETHODIMP
nsPrintSettings::GetOutputFormat(int16_t* aOutputFormat
) {
223 NS_ENSURE_ARG_POINTER(aOutputFormat
);
224 *aOutputFormat
= mOutputFormat
;
227 NS_IMETHODIMP
nsPrintSettings::SetOutputFormat(int16_t aOutputFormat
) {
228 mOutputFormat
= aOutputFormat
;
232 NS_IMETHODIMP
nsPrintSettings::GetPrintPageDelay(int32_t* aPrintPageDelay
) {
233 *aPrintPageDelay
= mPrintPageDelay
;
236 NS_IMETHODIMP
nsPrintSettings::SetPrintPageDelay(int32_t aPrintPageDelay
) {
237 mPrintPageDelay
= aPrintPageDelay
;
241 NS_IMETHODIMP
nsPrintSettings::GetIsInitializedFromPrinter(
242 bool* aIsInitializedFromPrinter
) {
243 NS_ENSURE_ARG_POINTER(aIsInitializedFromPrinter
);
244 *aIsInitializedFromPrinter
= mIsInitedFromPrinter
;
247 NS_IMETHODIMP
nsPrintSettings::SetIsInitializedFromPrinter(
248 bool aIsInitializedFromPrinter
) {
249 mIsInitedFromPrinter
= aIsInitializedFromPrinter
;
253 NS_IMETHODIMP
nsPrintSettings::GetIsInitializedFromPrefs(
254 bool* aInitializedFromPrefs
) {
255 NS_ENSURE_ARG_POINTER(aInitializedFromPrefs
);
256 *aInitializedFromPrefs
= mIsInitedFromPrefs
;
259 NS_IMETHODIMP
nsPrintSettings::SetIsInitializedFromPrefs(
260 bool aInitializedFromPrefs
) {
261 mIsInitedFromPrefs
= aInitializedFromPrefs
;
265 NS_IMETHODIMP
nsPrintSettings::GetMarginTop(double* aMarginTop
) {
266 NS_ENSURE_ARG_POINTER(aMarginTop
);
267 *aMarginTop
= NS_TWIPS_TO_INCHES(mMargin
.top
);
270 NS_IMETHODIMP
nsPrintSettings::SetMarginTop(double aMarginTop
) {
271 mMargin
.top
= NS_INCHES_TO_INT_TWIPS(float(aMarginTop
));
275 NS_IMETHODIMP
nsPrintSettings::GetMarginLeft(double* aMarginLeft
) {
276 NS_ENSURE_ARG_POINTER(aMarginLeft
);
277 *aMarginLeft
= NS_TWIPS_TO_INCHES(mMargin
.left
);
280 NS_IMETHODIMP
nsPrintSettings::SetMarginLeft(double aMarginLeft
) {
281 mMargin
.left
= NS_INCHES_TO_INT_TWIPS(float(aMarginLeft
));
285 NS_IMETHODIMP
nsPrintSettings::GetMarginBottom(double* aMarginBottom
) {
286 NS_ENSURE_ARG_POINTER(aMarginBottom
);
287 *aMarginBottom
= NS_TWIPS_TO_INCHES(mMargin
.bottom
);
290 NS_IMETHODIMP
nsPrintSettings::SetMarginBottom(double aMarginBottom
) {
291 mMargin
.bottom
= NS_INCHES_TO_INT_TWIPS(float(aMarginBottom
));
295 NS_IMETHODIMP
nsPrintSettings::GetMarginRight(double* aMarginRight
) {
296 NS_ENSURE_ARG_POINTER(aMarginRight
);
297 *aMarginRight
= NS_TWIPS_TO_INCHES(mMargin
.right
);
300 NS_IMETHODIMP
nsPrintSettings::SetMarginRight(double aMarginRight
) {
301 mMargin
.right
= NS_INCHES_TO_INT_TWIPS(float(aMarginRight
));
305 NS_IMETHODIMP
nsPrintSettings::GetEdgeTop(double* aEdgeTop
) {
306 NS_ENSURE_ARG_POINTER(aEdgeTop
);
307 *aEdgeTop
= NS_TWIPS_TO_INCHES(mEdge
.top
);
310 NS_IMETHODIMP
nsPrintSettings::SetEdgeTop(double aEdgeTop
) {
311 mEdge
.top
= NS_INCHES_TO_INT_TWIPS(float(aEdgeTop
));
315 NS_IMETHODIMP
nsPrintSettings::GetEdgeLeft(double* aEdgeLeft
) {
316 NS_ENSURE_ARG_POINTER(aEdgeLeft
);
317 *aEdgeLeft
= NS_TWIPS_TO_INCHES(mEdge
.left
);
320 NS_IMETHODIMP
nsPrintSettings::SetEdgeLeft(double aEdgeLeft
) {
321 mEdge
.left
= NS_INCHES_TO_INT_TWIPS(float(aEdgeLeft
));
325 NS_IMETHODIMP
nsPrintSettings::GetEdgeBottom(double* aEdgeBottom
) {
326 NS_ENSURE_ARG_POINTER(aEdgeBottom
);
327 *aEdgeBottom
= NS_TWIPS_TO_INCHES(mEdge
.bottom
);
330 NS_IMETHODIMP
nsPrintSettings::SetEdgeBottom(double aEdgeBottom
) {
331 mEdge
.bottom
= NS_INCHES_TO_INT_TWIPS(float(aEdgeBottom
));
335 NS_IMETHODIMP
nsPrintSettings::GetEdgeRight(double* aEdgeRight
) {
336 NS_ENSURE_ARG_POINTER(aEdgeRight
);
337 *aEdgeRight
= NS_TWIPS_TO_INCHES(mEdge
.right
);
340 NS_IMETHODIMP
nsPrintSettings::SetEdgeRight(double aEdgeRight
) {
341 mEdge
.right
= NS_INCHES_TO_INT_TWIPS(float(aEdgeRight
));
345 NS_IMETHODIMP
nsPrintSettings::GetUnwriteableMarginTop(
346 double* aUnwriteableMarginTop
) {
347 NS_ENSURE_ARG_POINTER(aUnwriteableMarginTop
);
348 *aUnwriteableMarginTop
= NS_TWIPS_TO_INCHES(mUnwriteableMargin
.top
);
351 NS_IMETHODIMP
nsPrintSettings::SetUnwriteableMarginTop(
352 double aUnwriteableMarginTop
) {
353 if (aUnwriteableMarginTop
>= 0.0) {
354 mUnwriteableMargin
.top
= NS_INCHES_TO_INT_TWIPS(aUnwriteableMarginTop
);
359 NS_IMETHODIMP
nsPrintSettings::GetUnwriteableMarginLeft(
360 double* aUnwriteableMarginLeft
) {
361 NS_ENSURE_ARG_POINTER(aUnwriteableMarginLeft
);
362 *aUnwriteableMarginLeft
= NS_TWIPS_TO_INCHES(mUnwriteableMargin
.left
);
365 NS_IMETHODIMP
nsPrintSettings::SetUnwriteableMarginLeft(
366 double aUnwriteableMarginLeft
) {
367 if (aUnwriteableMarginLeft
>= 0.0) {
368 mUnwriteableMargin
.left
= NS_INCHES_TO_INT_TWIPS(aUnwriteableMarginLeft
);
373 NS_IMETHODIMP
nsPrintSettings::GetUnwriteableMarginBottom(
374 double* aUnwriteableMarginBottom
) {
375 NS_ENSURE_ARG_POINTER(aUnwriteableMarginBottom
);
376 *aUnwriteableMarginBottom
= NS_TWIPS_TO_INCHES(mUnwriteableMargin
.bottom
);
379 NS_IMETHODIMP
nsPrintSettings::SetUnwriteableMarginBottom(
380 double aUnwriteableMarginBottom
) {
381 if (aUnwriteableMarginBottom
>= 0.0) {
382 mUnwriteableMargin
.bottom
=
383 NS_INCHES_TO_INT_TWIPS(aUnwriteableMarginBottom
);
388 NS_IMETHODIMP
nsPrintSettings::GetUnwriteableMarginRight(
389 double* aUnwriteableMarginRight
) {
390 NS_ENSURE_ARG_POINTER(aUnwriteableMarginRight
);
391 *aUnwriteableMarginRight
= NS_TWIPS_TO_INCHES(mUnwriteableMargin
.right
);
394 NS_IMETHODIMP
nsPrintSettings::SetUnwriteableMarginRight(
395 double aUnwriteableMarginRight
) {
396 if (aUnwriteableMarginRight
>= 0.0) {
397 mUnwriteableMargin
.right
= NS_INCHES_TO_INT_TWIPS(aUnwriteableMarginRight
);
402 NS_IMETHODIMP
nsPrintSettings::GetScaling(double* aScaling
) {
403 NS_ENSURE_ARG_POINTER(aScaling
);
404 *aScaling
= mScaling
;
408 NS_IMETHODIMP
nsPrintSettings::SetScaling(double aScaling
) {
413 NS_IMETHODIMP
nsPrintSettings::GetPrintBGColors(bool* aPrintBGColors
) {
414 NS_ENSURE_ARG_POINTER(aPrintBGColors
);
415 *aPrintBGColors
= mPrintBGColors
;
418 NS_IMETHODIMP
nsPrintSettings::SetPrintBGColors(bool aPrintBGColors
) {
419 mPrintBGColors
= aPrintBGColors
;
423 NS_IMETHODIMP
nsPrintSettings::GetPrintBGImages(bool* aPrintBGImages
) {
424 NS_ENSURE_ARG_POINTER(aPrintBGImages
);
425 *aPrintBGImages
= mPrintBGImages
;
428 NS_IMETHODIMP
nsPrintSettings::SetPrintBGImages(bool aPrintBGImages
) {
429 mPrintBGImages
= aPrintBGImages
;
433 NS_IMETHODIMP
nsPrintSettings::GetTitle(nsAString
& aTitle
) {
437 NS_IMETHODIMP
nsPrintSettings::SetTitle(const nsAString
& aTitle
) {
442 NS_IMETHODIMP
nsPrintSettings::GetDocURL(nsAString
& aDocURL
) {
446 NS_IMETHODIMP
nsPrintSettings::SetDocURL(const nsAString
& aDocURL
) {
451 NS_IMETHODIMP
nsPrintSettings::GetHeaderStrLeft(nsAString
& aTitle
) {
452 aTitle
= mHeaderStrs
[0];
455 NS_IMETHODIMP
nsPrintSettings::SetHeaderStrLeft(const nsAString
& aTitle
) {
456 mHeaderStrs
[0] = aTitle
;
460 NS_IMETHODIMP
nsPrintSettings::GetHeaderStrCenter(nsAString
& aTitle
) {
461 aTitle
= mHeaderStrs
[1];
464 NS_IMETHODIMP
nsPrintSettings::SetHeaderStrCenter(const nsAString
& aTitle
) {
465 mHeaderStrs
[1] = aTitle
;
469 NS_IMETHODIMP
nsPrintSettings::GetHeaderStrRight(nsAString
& aTitle
) {
470 aTitle
= mHeaderStrs
[2];
473 NS_IMETHODIMP
nsPrintSettings::SetHeaderStrRight(const nsAString
& aTitle
) {
474 mHeaderStrs
[2] = aTitle
;
478 NS_IMETHODIMP
nsPrintSettings::GetFooterStrLeft(nsAString
& aTitle
) {
479 aTitle
= mFooterStrs
[0];
482 NS_IMETHODIMP
nsPrintSettings::SetFooterStrLeft(const nsAString
& aTitle
) {
483 mFooterStrs
[0] = aTitle
;
487 NS_IMETHODIMP
nsPrintSettings::GetFooterStrCenter(nsAString
& aTitle
) {
488 aTitle
= mFooterStrs
[1];
491 NS_IMETHODIMP
nsPrintSettings::SetFooterStrCenter(const nsAString
& aTitle
) {
492 mFooterStrs
[1] = aTitle
;
496 NS_IMETHODIMP
nsPrintSettings::GetFooterStrRight(nsAString
& aTitle
) {
497 aTitle
= mFooterStrs
[2];
500 NS_IMETHODIMP
nsPrintSettings::SetFooterStrRight(const nsAString
& aTitle
) {
501 mFooterStrs
[2] = aTitle
;
505 NS_IMETHODIMP
nsPrintSettings::GetPrintSilent(bool* aPrintSilent
) {
506 NS_ENSURE_ARG_POINTER(aPrintSilent
);
507 *aPrintSilent
= mPrintSilent
;
510 NS_IMETHODIMP
nsPrintSettings::SetPrintSilent(bool aPrintSilent
) {
511 mPrintSilent
= aPrintSilent
;
515 NS_IMETHODIMP
nsPrintSettings::GetShrinkToFit(bool* aShrinkToFit
) {
516 NS_ENSURE_ARG_POINTER(aShrinkToFit
);
517 *aShrinkToFit
= mShrinkToFit
;
520 NS_IMETHODIMP
nsPrintSettings::SetShrinkToFit(bool aShrinkToFit
) {
521 mShrinkToFit
= aShrinkToFit
;
525 NS_IMETHODIMP
nsPrintSettings::GetShowPrintProgress(bool* aShowPrintProgress
) {
526 NS_ENSURE_ARG_POINTER(aShowPrintProgress
);
527 *aShowPrintProgress
= mShowPrintProgress
;
530 NS_IMETHODIMP
nsPrintSettings::SetShowPrintProgress(bool aShowPrintProgress
) {
531 mShowPrintProgress
= aShowPrintProgress
;
535 NS_IMETHODIMP
nsPrintSettings::GetShowMarginGuides(bool* aShowMarginGuides
) {
536 *aShowMarginGuides
= mShowMarginGuides
;
540 NS_IMETHODIMP
nsPrintSettings::SetShowMarginGuides(bool aShowMarginGuides
) {
541 mShowMarginGuides
= aShowMarginGuides
;
545 NS_IMETHODIMP
nsPrintSettings::GetHonorPageRuleMargins(bool* aResult
) {
546 *aResult
= mHonorPageRuleMargins
;
550 NS_IMETHODIMP
nsPrintSettings::SetHonorPageRuleMargins(bool aHonor
) {
551 mHonorPageRuleMargins
= aHonor
;
555 NS_IMETHODIMP
nsPrintSettings::GetIsPrintSelectionRBEnabled(
556 bool* aIsPrintSelectionRBEnabled
) {
557 *aIsPrintSelectionRBEnabled
= mIsPrintSelectionRBEnabled
;
560 NS_IMETHODIMP
nsPrintSettings::SetIsPrintSelectionRBEnabled(
561 bool aIsPrintSelectionRBEnabled
) {
562 mIsPrintSelectionRBEnabled
= aIsPrintSelectionRBEnabled
;
566 NS_IMETHODIMP
nsPrintSettings::GetPrintSelectionOnly(bool* aResult
) {
567 *aResult
= mPrintSelectionOnly
;
571 NS_IMETHODIMP
nsPrintSettings::SetPrintSelectionOnly(bool aSelectionOnly
) {
572 mPrintSelectionOnly
= aSelectionOnly
;
576 NS_IMETHODIMP
nsPrintSettings::GetPaperId(nsAString
& aPaperId
) {
580 NS_IMETHODIMP
nsPrintSettings::SetPaperId(const nsAString
& aPaperId
) {
585 NS_IMETHODIMP
nsPrintSettings::GetIsCancelled(bool* aIsCancelled
) {
586 NS_ENSURE_ARG_POINTER(aIsCancelled
);
587 *aIsCancelled
= mIsCancelled
;
590 NS_IMETHODIMP
nsPrintSettings::SetIsCancelled(bool aIsCancelled
) {
591 mIsCancelled
= aIsCancelled
;
595 NS_IMETHODIMP
nsPrintSettings::GetSaveOnCancel(bool* aSaveOnCancel
) {
596 *aSaveOnCancel
= mSaveOnCancel
;
600 NS_IMETHODIMP
nsPrintSettings::GetPaperWidth(double* aPaperWidth
) {
601 NS_ENSURE_ARG_POINTER(aPaperWidth
);
602 *aPaperWidth
= mPaperWidth
;
605 NS_IMETHODIMP
nsPrintSettings::SetPaperWidth(double aPaperWidth
) {
606 mPaperWidth
= aPaperWidth
;
610 NS_IMETHODIMP
nsPrintSettings::GetPaperHeight(double* aPaperHeight
) {
611 NS_ENSURE_ARG_POINTER(aPaperHeight
);
612 *aPaperHeight
= mPaperHeight
;
615 NS_IMETHODIMP
nsPrintSettings::SetPaperHeight(double aPaperHeight
) {
616 mPaperHeight
= aPaperHeight
;
620 NS_IMETHODIMP
nsPrintSettings::GetPaperSizeUnit(int16_t* aPaperSizeUnit
) {
621 NS_ENSURE_ARG_POINTER(aPaperSizeUnit
);
622 *aPaperSizeUnit
= mPaperSizeUnit
;
625 NS_IMETHODIMP
nsPrintSettings::SetPaperSizeUnit(int16_t aPaperSizeUnit
) {
626 mPaperSizeUnit
= aPaperSizeUnit
;
630 /** ---------------------------------------------------
631 * See documentation in nsPrintSettingsService.h
632 * @update 6/21/00 dwc
633 * @update 1/12/01 rods
636 nsPrintSettings::SetMarginInTwips(nsIntMargin
& aMargin
) {
642 nsPrintSettings::SetEdgeInTwips(nsIntMargin
& aEdge
) {
647 // NOTE: Any subclass implementation of this function should make sure
648 // to check for negative margin values in aUnwriteableMargin (which
649 // would indicate that we should use the system default unwriteable margin.)
651 nsPrintSettings::SetUnwriteableMarginInTwips(nsIntMargin
& aUnwriteableMargin
) {
652 if (aUnwriteableMargin
.top
>= 0) {
653 mUnwriteableMargin
.top
= aUnwriteableMargin
.top
;
655 if (aUnwriteableMargin
.left
>= 0) {
656 mUnwriteableMargin
.left
= aUnwriteableMargin
.left
;
658 if (aUnwriteableMargin
.bottom
>= 0) {
659 mUnwriteableMargin
.bottom
= aUnwriteableMargin
.bottom
;
661 if (aUnwriteableMargin
.right
>= 0) {
662 mUnwriteableMargin
.right
= aUnwriteableMargin
.right
;
667 nsIntMargin
nsPrintSettings::GetMarginInTwips() { return mMargin
; }
669 nsIntMargin
nsPrintSettings::GetEdgeInTwips() { return mEdge
; }
671 nsIntMargin
nsPrintSettings::GetUnwriteableMarginInTwips() {
672 return mUnwriteableMargin
;
675 /** ---------------------------------------------------
676 * Stub - platform-specific implementations can use this function.
679 nsPrintSettings::SetupSilentPrinting() { return NS_OK
; }
681 /** ---------------------------------------------------
682 * See documentation in nsPrintSettingsService.h
685 nsPrintSettings::GetEffectivePageSize(double* aWidth
, double* aHeight
) {
686 if (mPaperSizeUnit
== kPaperSizeInches
) {
687 *aWidth
= NS_INCHES_TO_TWIPS(float(mPaperWidth
));
688 *aHeight
= NS_INCHES_TO_TWIPS(float(mPaperHeight
));
690 MOZ_ASSERT(mPaperSizeUnit
== kPaperSizeMillimeters
,
691 "unexpected paper size unit");
692 *aWidth
= NS_MILLIMETERS_TO_TWIPS(float(mPaperWidth
));
693 *aHeight
= NS_MILLIMETERS_TO_TWIPS(float(mPaperHeight
));
695 if (kLandscapeOrientation
== mOrientation
) {
696 double temp
= *aWidth
;
703 bool nsPrintSettings::HasOrthogonalSheetsAndPages() {
704 return mNumPagesPerSheet
== 2 || mNumPagesPerSheet
== 6;
707 void nsPrintSettings::GetEffectiveSheetSize(double* aWidth
, double* aHeight
) {
708 mozilla::DebugOnly
<nsresult
> rv
= GetEffectivePageSize(aWidth
, aHeight
);
710 // Our GetEffectivePageSize impls only return NS_OK, so this should hold:
711 MOZ_ASSERT(NS_SUCCEEDED(rv
), "Uh oh, GetEffectivePageSize failed");
713 if (HasOrthogonalSheetsAndPages()) {
714 std::swap(*aWidth
, *aHeight
);
718 int32_t nsPrintSettings::GetSheetOrientation() {
719 if (HasOrthogonalSheetsAndPages()) {
720 // Sheet orientation is rotated with respect to the page orientation.
721 return kLandscapeOrientation
== mOrientation
? kPortraitOrientation
722 : kLandscapeOrientation
;
725 // Sheet orientation is the same as the page orientation.
730 nsPrintSettings::SetPageRanges(const nsTArray
<int32_t>& aPages
) {
731 // Needs to be a set of (start, end) pairs.
732 if (aPages
.Length() % 2 != 0) {
733 return NS_ERROR_FAILURE
;
735 mPageRanges
= aPages
.Clone();
740 nsPrintSettings::GetPageRanges(nsTArray
<int32_t>& aPages
) {
741 aPages
= mPageRanges
.Clone();
745 bool nsIPrintSettings::IsPageSkipped(int32_t aPageNum
,
746 const nsTArray
<int32_t>& aRanges
) {
747 MOZ_RELEASE_ASSERT(aRanges
.Length() % 2 == 0);
748 if (aRanges
.IsEmpty()) {
751 for (size_t i
= 0; i
< aRanges
.Length(); i
+= 2) {
752 if (aRanges
[i
] <= aPageNum
&& aPageNum
<= aRanges
[i
+ 1]) {
753 // The page is included in this piece of the custom range,
754 // so it's not skipped.
761 nsresult
nsPrintSettings::_Clone(nsIPrintSettings
** _retval
) {
762 RefPtr
<nsPrintSettings
> printSettings
= new nsPrintSettings(*this);
763 printSettings
.forget(_retval
);
768 nsPrintSettings::Clone(nsIPrintSettings
** _retval
) {
769 NS_ENSURE_ARG_POINTER(_retval
);
770 return _Clone(_retval
);
773 nsresult
nsPrintSettings::_Assign(nsIPrintSettings
* aPS
) {
774 nsPrintSettings
* ps
= static_cast<nsPrintSettings
*>(aPS
);
780 nsPrintSettings::Assign(nsIPrintSettings
* aPS
) {
785 //-------------------------------------------
786 nsPrintSettings
& nsPrintSettings::operator=(const nsPrintSettings
& rhs
) {
791 mPageRanges
= rhs
.mPageRanges
.Clone();
792 mMargin
= rhs
.mMargin
;
794 mUnwriteableMargin
= rhs
.mUnwriteableMargin
;
795 mScaling
= rhs
.mScaling
;
796 mPrintBGColors
= rhs
.mPrintBGColors
;
797 mPrintBGImages
= rhs
.mPrintBGImages
;
800 mIsCancelled
= rhs
.mIsCancelled
;
801 mSaveOnCancel
= rhs
.mSaveOnCancel
;
802 mPrintSilent
= rhs
.mPrintSilent
;
803 mShrinkToFit
= rhs
.mShrinkToFit
;
804 mShowPrintProgress
= rhs
.mShowPrintProgress
;
805 mShowMarginGuides
= rhs
.mShowMarginGuides
;
806 mHonorPageRuleMargins
= rhs
.mHonorPageRuleMargins
;
807 mIsPrintSelectionRBEnabled
= rhs
.mIsPrintSelectionRBEnabled
;
808 mPrintSelectionOnly
= rhs
.mPrintSelectionOnly
;
809 mPaperId
= rhs
.mPaperId
;
810 mPaperWidth
= rhs
.mPaperWidth
;
811 mPaperHeight
= rhs
.mPaperHeight
;
812 mPaperSizeUnit
= rhs
.mPaperSizeUnit
;
813 mPrintReversed
= rhs
.mPrintReversed
;
814 mPrintInColor
= rhs
.mPrintInColor
;
815 mOrientation
= rhs
.mOrientation
;
816 mResolution
= rhs
.mResolution
;
817 mDuplex
= rhs
.mDuplex
;
818 mNumCopies
= rhs
.mNumCopies
;
819 mNumPagesPerSheet
= rhs
.mNumPagesPerSheet
;
820 mPrinter
= rhs
.mPrinter
;
821 mPrintToFile
= rhs
.mPrintToFile
;
822 mToFileName
= rhs
.mToFileName
;
823 mOutputFormat
= rhs
.mOutputFormat
;
824 mIsInitedFromPrinter
= rhs
.mIsInitedFromPrinter
;
825 mIsInitedFromPrefs
= rhs
.mIsInitedFromPrefs
;
826 mPrintPageDelay
= rhs
.mPrintPageDelay
;
828 for (int32_t i
= 0; i
< NUM_HEAD_FOOT
; i
++) {
829 mHeaderStrs
[i
] = rhs
.mHeaderStrs
[i
];
830 mFooterStrs
[i
] = rhs
.mFooterStrs
[i
];
836 void nsPrintSettings::SetDefaultFileName() {
837 nsAutoString filename
;
838 nsresult rv
= GetToFileName(filename
);
839 if (NS_FAILED(rv
) || filename
.IsEmpty()) {
840 const char* path
= PR_GetEnv("PWD");
842 path
= PR_GetEnv("HOME");
846 CopyUTF8toUTF16(mozilla::MakeStringSpan(path
), filename
);
847 filename
.AppendLiteral("/mozilla.pdf");
849 filename
.AssignLiteral("mozilla.pdf");
852 SetToFileName(filename
);