Hal Canary | f5edf36 | 2019-04-10 11:00:01 -0400 | [diff] [blame] | 1 | // Copyright 2019 Google LLC. |
| 2 | // Use of this source code is governed by a BSD-style license that can be found in the LICENSE file. |
| 3 | #ifndef SkPDFGraphicStackState_DEFINED |
| 4 | #define SkPDFGraphicStackState_DEFINED |
| 5 | |
Mike Klein | c0bd9f9 | 2019-04-23 12:05:21 -0500 | [diff] [blame] | 6 | #include "include/core/SkColor.h" |
| 7 | #include "include/core/SkMatrix.h" |
| 8 | #include "include/core/SkScalar.h" |
| 9 | #include "src/core/SkClipStack.h" |
Hal Canary | f5edf36 | 2019-04-10 11:00:01 -0400 | [diff] [blame] | 10 | |
| 11 | class SkDynamicMemoryWStream; |
| 12 | |
| 13 | // It is important to not confuse SkPDFGraphicStackState with SkPDFGraphicState, the |
| 14 | // later being our representation of an object in the PDF file. |
| 15 | struct SkPDFGraphicStackState { |
| 16 | struct Entry { |
| 17 | SkMatrix fMatrix = SkMatrix::I(); |
| 18 | uint32_t fClipStackGenID = SkClipStack::kWideOpenGenID; |
| 19 | SkColor4f fColor = {0, 0, 0, 1}; |
| 20 | SkScalar fTextScaleX = 1; // Zero means we don't care what the value is. |
| 21 | int fShaderIndex = -1; |
| 22 | int fGraphicStateIndex = -1; |
| 23 | }; |
| 24 | // Must use stack for matrix, and for clip, plus one for no matrix or clip. |
| 25 | static constexpr int kMaxStackDepth = 2; |
| 26 | Entry fEntries[kMaxStackDepth + 1]; |
| 27 | int fStackDepth = 0; |
| 28 | SkDynamicMemoryWStream* fContentStream; |
| 29 | |
| 30 | SkPDFGraphicStackState(SkDynamicMemoryWStream* s = nullptr) : fContentStream(s) {} |
| 31 | void updateClip(const SkClipStack* clipStack, const SkIRect& bounds); |
| 32 | void updateMatrix(const SkMatrix& matrix); |
| 33 | void updateDrawingState(const Entry& state); |
| 34 | void push(); |
| 35 | void pop(); |
| 36 | void drainStack(); |
| 37 | Entry* currentEntry() { return &fEntries[fStackDepth]; } |
| 38 | }; |
| 39 | |
| 40 | #endif // SkPDFGraphicStackState_DEFINED |