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