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 #include "PrintTargetThebes.h"
8 #include "gfxASurface.h"
9 #include "gfxPlatform.h"
10 #include "mozilla/gfx/Logging.h"
12 namespace mozilla::gfx
{
15 already_AddRefed
<PrintTargetThebes
> PrintTargetThebes::CreateOrNull(
16 gfxASurface
* aSurface
) {
19 if (!aSurface
|| aSurface
->CairoStatus()) {
23 RefPtr
<PrintTargetThebes
> target
= new PrintTargetThebes(aSurface
);
25 return target
.forget();
28 PrintTargetThebes::PrintTargetThebes(gfxASurface
* aSurface
)
29 : PrintTarget(nullptr, aSurface
->GetSize()), mGfxSurface(aSurface
) {}
31 already_AddRefed
<DrawTarget
> PrintTargetThebes::MakeDrawTarget(
32 const IntSize
& aSize
, DrawEventRecorder
* aRecorder
) {
33 // This should not be called outside of BeginPage()/EndPage() calls since
34 // some backends can only provide a valid DrawTarget at that time.
35 MOZ_ASSERT(mHasActivePage
, "We can't guarantee a valid DrawTarget");
37 RefPtr
<gfx::DrawTarget
> dt
=
38 gfxPlatform::CreateDrawTargetForSurface(mGfxSurface
, aSize
);
39 if (!dt
|| !dt
->IsValid()) {
44 dt
= CreateRecordingDrawTarget(aRecorder
, dt
);
45 if (!dt
|| !dt
->IsValid()) {
53 already_AddRefed
<DrawTarget
> PrintTargetThebes::GetReferenceDrawTarget() {
55 RefPtr
<gfx::DrawTarget
> dt
=
56 gfxPlatform::CreateDrawTargetForSurface(mGfxSurface
, mSize
);
57 if (!dt
|| !dt
->IsValid()) {
60 mRefDT
= dt
->CreateSimilarDrawTarget(IntSize(1, 1), dt
->GetFormat());
63 return do_AddRef(mRefDT
);
66 nsresult
PrintTargetThebes::BeginPrinting(const nsAString
& aTitle
,
67 const nsAString
& aPrintToFileName
,
70 return mGfxSurface
->BeginPrinting(aTitle
, aPrintToFileName
);
73 nsresult
PrintTargetThebes::EndPrinting() { return mGfxSurface
->EndPrinting(); }
75 nsresult
PrintTargetThebes::AbortPrinting() {
77 mHasActivePage
= false;
79 return mGfxSurface
->AbortPrinting();
82 nsresult
PrintTargetThebes::BeginPage(const IntSize
& aSizeInPoints
) {
84 mHasActivePage
= true;
86 return mGfxSurface
->BeginPage();
89 nsresult
PrintTargetThebes::EndPage() {
91 mHasActivePage
= false;
93 return mGfxSurface
->EndPage();
96 void PrintTargetThebes::Finish() { return mGfxSurface
->Finish(); }
98 } // namespace mozilla::gfx