1/* 2 * Copyright 2010 The Android Open Source Project 3 * 4 * Use of this source code is governed by a BSD-style license that can be 5 * found in the LICENSE file. 6 */ 7 8 9#ifndef SkPDFGraphicState_DEFINED 10#define SkPDFGraphicState_DEFINED 11 12#include "SkPDFTypes.h" 13#include "SkOpts.h" 14 15class SkPaint; 16class SkPDFCanon; 17 18/** \class SkPDFGraphicState 19 SkPaint objects roughly correspond to graphic state dictionaries that can 20 be installed. So that a given dictionary is only output to the pdf file 21 once, we want to canonicalize them. 22*/ 23namespace SkPDFGraphicState { 24 enum SkPDFSMaskMode { 25 kAlpha_SMaskMode, 26 kLuminosity_SMaskMode 27 }; 28 29 /** Get the graphic state for the passed SkPaint. 30 */ 31 sk_sp<SkPDFDict> GetGraphicStateForPaint(SkPDFCanon*, const SkPaint&); 32 33 /** Make a graphic state that only sets the passed soft mask. 34 * @param sMask The form xobject to use as a soft mask. 35 * @param invert Indicates if the alpha of the sMask should be inverted. 36 * @param sMaskMode Whether to use alpha or luminosity for the sMask. 37 * 38 * These are not de-duped. 39 */ 40 sk_sp<SkPDFDict> GetSMaskGraphicState(sk_sp<SkPDFObject> sMask, 41 bool invert, 42 SkPDFSMaskMode sMaskMode, 43 SkPDFCanon* canon); 44 45 sk_sp<SkPDFStream> MakeInvertFunction(); 46} 47 48SK_BEGIN_REQUIRE_DENSE 49struct SkPDFStrokeGraphicState { 50 SkScalar fStrokeWidth; 51 SkScalar fStrokeMiter; 52 uint8_t fStrokeCap; // SkPaint::Cap 53 uint8_t fStrokeJoin; // SkPaint::Join 54 uint8_t fAlpha; 55 uint8_t fBlendMode; 56 bool operator==(const SkPDFStrokeGraphicState& o) const { return !memcmp(this, &o, sizeof(o)); } 57 bool operator!=(const SkPDFStrokeGraphicState& o) const { return !(*this == o); } 58}; 59SK_END_REQUIRE_DENSE 60 61SK_BEGIN_REQUIRE_DENSE 62struct SkPDFFillGraphicState { 63 uint8_t fAlpha; 64 uint8_t fBlendMode; 65 bool operator==(const SkPDFFillGraphicState& o) const { return !memcmp(this, &o, sizeof(o)); } 66 bool operator!=(const SkPDFFillGraphicState& o) const { return !(*this == o); } 67}; 68SK_END_REQUIRE_DENSE 69 70#endif 71