/src/mozilla-central/layout/printing/PrintTranslator.cpp
Line | Count | Source (jump to first uncovered line) |
1 | | /* -*- Mode: C++; tab-width: 8; indent-tabs-mode: nil; c-basic-offset: 2 -*- */ |
2 | | /* vim: set ts=8 sts=2 et sw=2 tw=80: */ |
3 | | /* This Source Code Form is subject to the terms of the Mozilla Public |
4 | | * License, v. 2.0. If a copy of the MPL was not distributed with this |
5 | | * file, You can obtain one at http://mozilla.org/MPL/2.0/. */ |
6 | | |
7 | | #include "PrintTranslator.h" |
8 | | |
9 | | #include "gfxContext.h" |
10 | | #include "nsDeviceContext.h" |
11 | | #include "mozilla/gfx/RecordedEvent.h" |
12 | | #include "mozilla/gfx/RecordingTypes.h" |
13 | | #include "mozilla/UniquePtr.h" |
14 | | |
15 | | using namespace mozilla::gfx; |
16 | | |
17 | | namespace mozilla { |
18 | | namespace layout { |
19 | | |
20 | | PrintTranslator::PrintTranslator(nsDeviceContext* aDeviceContext) |
21 | | : mDeviceContext(aDeviceContext) |
22 | 0 | { |
23 | 0 | RefPtr<gfxContext> context = mDeviceContext->CreateReferenceRenderingContext(); |
24 | 0 | mBaseDT = context->GetDrawTarget(); |
25 | 0 | } |
26 | | |
27 | | bool |
28 | | PrintTranslator::TranslateRecording(PRFileDescStream& aRecording) |
29 | 0 | { |
30 | 0 | uint32_t magicInt; |
31 | 0 | ReadElement(aRecording, magicInt); |
32 | 0 | if (magicInt != mozilla::gfx::kMagicInt) { |
33 | 0 | return false; |
34 | 0 | } |
35 | 0 | |
36 | 0 | uint16_t majorRevision; |
37 | 0 | ReadElement(aRecording, majorRevision); |
38 | 0 | if (majorRevision != kMajorRevision) { |
39 | 0 | return false; |
40 | 0 | } |
41 | 0 | |
42 | 0 | uint16_t minorRevision; |
43 | 0 | ReadElement(aRecording, minorRevision); |
44 | 0 | if (minorRevision > kMinorRevision) { |
45 | 0 | return false; |
46 | 0 | } |
47 | 0 | |
48 | 0 | int32_t eventType; |
49 | 0 | ReadElement(aRecording, eventType); |
50 | 0 | while (aRecording.good()) { |
51 | 0 | UniquePtr<RecordedEvent> recordedEvent( |
52 | 0 | RecordedEvent::LoadEventFromStream(aRecording, |
53 | 0 | static_cast<RecordedEvent::EventType>(eventType))); |
54 | 0 |
|
55 | 0 | // Make sure that the whole event was read from the stream successfully. |
56 | 0 | if (!aRecording.good() || !recordedEvent) { |
57 | 0 | return false; |
58 | 0 | } |
59 | 0 | |
60 | 0 | if (!recordedEvent->PlayEvent(this)) { |
61 | 0 | return false; |
62 | 0 | } |
63 | 0 | |
64 | 0 | ReadElement(aRecording, eventType); |
65 | 0 | } |
66 | 0 |
|
67 | 0 | return true; |
68 | 0 | } |
69 | | |
70 | | already_AddRefed<DrawTarget> |
71 | | PrintTranslator::CreateDrawTarget(ReferencePtr aRefPtr, |
72 | | const gfx::IntSize &aSize, |
73 | | gfx::SurfaceFormat aFormat) |
74 | 0 | { |
75 | 0 | RefPtr<gfxContext> context = mDeviceContext->CreateRenderingContext(); |
76 | 0 | if (!context) { |
77 | 0 | NS_WARNING("Failed to create rendering context for print."); |
78 | 0 | return nullptr; |
79 | 0 | } |
80 | 0 |
|
81 | 0 | RefPtr<DrawTarget> drawTarget = context->GetDrawTarget(); |
82 | 0 | AddDrawTarget(aRefPtr, drawTarget); |
83 | 0 | return drawTarget.forget(); |
84 | 0 | } |
85 | | |
86 | | } // namespace layout |
87 | | } // namespace mozilla |