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
6#include "include/core/SkColor.h"
7#include "include/core/SkMatrix.h"
8#include "include/core/SkScalar.h"
9#include "src/core/SkClipStack.h"
10
11class 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.
15struct 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
41