• Home
  • Line#
  • Scopes#
  • Navigate#
  • Raw
  • Download
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 "include/private/SkMacros.h"
13 #include "src/core/SkOpts.h"
14 #include "src/pdf/SkPDFTypes.h"
15 
16 class SkPaint;
17 
18 
19 /** \class SkPDFGraphicState
20     SkPaint objects roughly correspond to graphic state dictionaries that can
21     be installed. So that a given dictionary is only output to the pdf file
22     once, we want to canonicalize them.
23 */
24 namespace SkPDFGraphicState {
25     enum SkPDFSMaskMode {
26         kAlpha_SMaskMode,
27         kLuminosity_SMaskMode
28     };
29 
30     /** Get the graphic state for the passed SkPaint.
31      */
32     SkPDFIndirectReference GetGraphicStateForPaint(SkPDFDocument*, const SkPaint&);
33 
34     /** Make a graphic state that only sets the passed soft mask.
35      *  @param sMask     The form xobject to use as a soft mask.
36      *  @param invert    Indicates if the alpha of the sMask should be inverted.
37      *  @param sMaskMode Whether to use alpha or luminosity for the sMask.
38      *
39      *  These are not de-duped.
40      */
41     SkPDFIndirectReference GetSMaskGraphicState(SkPDFIndirectReference sMask,
42                                                 bool invert,
43                                                 SkPDFSMaskMode sMaskMode,
44                                                 SkPDFDocument* doc);
45 }  // namespace SkPDFGraphicState
46 
47 SK_BEGIN_REQUIRE_DENSE
48 struct SkPDFStrokeGraphicState {
49     SkScalar fStrokeWidth;
50     SkScalar fStrokeMiter;
51     SkScalar fAlpha;
52     uint8_t fStrokeCap;   // SkPaint::Cap
53     uint8_t fStrokeJoin;  // SkPaint::Join
54     uint8_t fBlendMode;   // SkBlendMode
55     uint8_t fPADDING = 0;
56     bool operator==(const SkPDFStrokeGraphicState& o) const { return !memcmp(this, &o, sizeof(o)); }
57     bool operator!=(const SkPDFStrokeGraphicState& o) const { return !(*this == o); }
58 };
59 SK_END_REQUIRE_DENSE
60 
61 SK_BEGIN_REQUIRE_DENSE
62 struct SkPDFFillGraphicState {
63     SkScalar fAlpha;
64     uint8_t fBlendMode;
65     uint8_t fPADDING[3] = {0, 0, 0};
66     bool operator==(const SkPDFFillGraphicState& o) const { return !memcmp(this, &o, sizeof(o)); }
67     bool operator!=(const SkPDFFillGraphicState& o) const { return !(*this == o); }
68 };
69 SK_END_REQUIRE_DENSE
70 
71 #endif
72