| 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 "include/private/base/SkFloatingPoint.h" |
| 10 |
#include "src/core/SkClipStack.h" |
| 11 |
|
| 12 |
#include <cstdint> |
| 13 |
|
| 14 |
class SkDynamicMemoryWStream; |
| 15 |
struct SkIRect; |
| 16 |
|
| 17 |
// It is important to not confuse SkPDFGraphicStackState with SkPDFGraphicState, the |
| 18 |
// later being our representation of an object in the PDF file. |
| 19 |
struct SkPDFGraphicStackState { |
| 20 |
struct Entry { |
| 21 |
SkMatrix fMatrix = SkMatrix::I(); |
| 22 |
uint32_t fClipStackGenID = SkClipStack::kWideOpenGenID; |
| 23 |
SkColor4f fColor = {SK_FloatNaN, SK_FloatNaN, SK_FloatNaN, SK_FloatNaN}; |
| 24 |
SkScalar fTextScaleX = 1; // Zero means we don't care what the value is. |
| 25 |
int fShaderIndex = -1; |
| 26 |
int fGraphicStateIndex = -1; |
| 27 |
}; |
| 28 |
// Must use stack for matrix, and for clip, plus one for no matrix or clip. |
| 29 |
inline static constexpr int kMaxStackDepth = 2; |
| 30 |
Entry fEntries[kMaxStackDepth + 1]; |
| 31 |
int fStackDepth = 0; |
| 32 |
SkDynamicMemoryWStream* fContentStream; |
| 33 |
|
| 34 |
SkPDFGraphicStackState(SkDynamicMemoryWStream* s = nullptr) : fContentStream(s) {} |
| 35 |
void updateClip(const SkClipStack* clipStack, const SkIRect& bounds); |
| 36 |
void updateMatrix(const SkMatrix& matrix); |
| 37 |
void updateDrawingState(const Entry& state); |
| 38 |
void push(); |
| 39 |
void pop(); |
| 40 |
void drainStack(); |
| 41 |
Entry* currentEntry() { return &fEntries[fStackDepth]; } |
| 42 |
}; |
| 43 |
|
| 44 |
#endif // SkPDFGraphicStackState_DEFINED |