blob: 7dcdc43a4cd2c0182a8e92093e07b57209e27046 [file] [log] [blame]
vandebo@chromium.org9b49dc02010-10-20 22:23:29 +00001/*
epoger@google.comec3ed6a2011-07-28 14:26:00 +00002 * Copyright 2010 The Android Open Source Project
vandebo@chromium.org9b49dc02010-10-20 22:23:29 +00003 *
epoger@google.comec3ed6a2011-07-28 14:26:00 +00004 * Use of this source code is governed by a BSD-style license that can be
5 * found in the LICENSE file.
vandebo@chromium.org9b49dc02010-10-20 22:23:29 +00006 */
7
epoger@google.comec3ed6a2011-07-28 14:26:00 +00008
vandebo@chromium.org9b49dc02010-10-20 22:23:29 +00009#ifndef SkPDFGraphicState_DEFINED
10#define SkPDFGraphicState_DEFINED
11
Hal Canary50dbc092018-06-12 14:50:37 -040012#include "SkMacros.h"
mtklein4e976072016-08-08 09:06:27 -070013#include "SkOpts.h"
Hal Canary50dbc092018-06-12 14:50:37 -040014#include "SkPDFTypes.h"
vandebo@chromium.org9b49dc02010-10-20 22:23:29 +000015
martina.kollarovab8d6af12016-06-29 05:12:31 -070016class SkPaint;
Hal Canary4ca9fa32018-12-21 16:15:01 -050017
vandebo@chromium.org6112c212011-05-13 03:50:38 +000018
vandebo@chromium.org9b49dc02010-10-20 22:23:29 +000019/** \class SkPDFGraphicState
20 SkPaint objects roughly correspond to graphic state dictionaries that can
vandebo@chromium.org6112c212011-05-13 03:50:38 +000021 be installed. So that a given dictionary is only output to the pdf file
halcanarybe27a112015-04-01 13:31:19 -070022 once, we want to canonicalize them.
vandebo@chromium.org9b49dc02010-10-20 22:23:29 +000023*/
Hal Canary80fa7ce2017-06-28 16:04:20 -040024namespace SkPDFGraphicState {
commit-bot@chromium.org93a2e212013-07-23 23:16:03 +000025 enum SkPDFSMaskMode {
26 kAlpha_SMaskMode,
27 kLuminosity_SMaskMode
28 };
29
Hal Canary5c1b3602017-04-17 16:30:06 -040030 /** Get the graphic state for the passed SkPaint.
vandebo@chromium.org9b49dc02010-10-20 22:23:29 +000031 */
Hal Canary9a3f5542018-12-10 19:59:07 -050032 SkPDFIndirectReference GetGraphicStateForPaint(SkPDFDocument*, const SkPaint&);
vandebo@chromium.org9b49dc02010-10-20 22:23:29 +000033
halcanary1437c1e2016-03-13 18:30:24 -070034 /** Make a graphic state that only sets the passed soft mask.
commit-bot@chromium.org93a2e212013-07-23 23:16:03 +000035 * @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.
halcanarybe27a112015-04-01 13:31:19 -070038 *
39 * These are not de-duped.
vandebo@chromium.org6112c212011-05-13 03:50:38 +000040 */
Hal Canary9a3f5542018-12-10 19:59:07 -050041 SkPDFIndirectReference GetSMaskGraphicState(SkPDFIndirectReference sMask,
42 bool invert,
43 SkPDFSMaskMode sMaskMode,
44 SkPDFDocument* doc);
Hal Canary80fa7ce2017-06-28 16:04:20 -040045}
vandebo@chromium.org6112c212011-05-13 03:50:38 +000046
Hal Canary80fa7ce2017-06-28 16:04:20 -040047SK_BEGIN_REQUIRE_DENSE
48struct SkPDFStrokeGraphicState {
49 SkScalar fStrokeWidth;
50 SkScalar fStrokeMiter;
Hal Canary29844292018-10-10 14:39:39 -040051 SkScalar fAlpha;
Hal Canary80fa7ce2017-06-28 16:04:20 -040052 uint8_t fStrokeCap; // SkPaint::Cap
53 uint8_t fStrokeJoin; // SkPaint::Join
Hal Canary29844292018-10-10 14:39:39 -040054 uint8_t fBlendMode; // SkBlendMode
55 uint8_t fPADDING = 0;
Hal Canary80fa7ce2017-06-28 16:04:20 -040056 bool operator==(const SkPDFStrokeGraphicState& o) const { return !memcmp(this, &o, sizeof(o)); }
57 bool operator!=(const SkPDFStrokeGraphicState& o) const { return !(*this == o); }
vandebo@chromium.org9b49dc02010-10-20 22:23:29 +000058};
Hal Canary80fa7ce2017-06-28 16:04:20 -040059SK_END_REQUIRE_DENSE
60
61SK_BEGIN_REQUIRE_DENSE
62struct SkPDFFillGraphicState {
Hal Canary29844292018-10-10 14:39:39 -040063 SkScalar fAlpha;
Hal Canary80fa7ce2017-06-28 16:04:20 -040064 uint8_t fBlendMode;
Hal Canary29844292018-10-10 14:39:39 -040065 uint8_t fPADDING[3] = {0, 0, 0};
Hal Canary80fa7ce2017-06-28 16:04:20 -040066 bool operator==(const SkPDFFillGraphicState& o) const { return !memcmp(this, &o, sizeof(o)); }
67 bool operator!=(const SkPDFFillGraphicState& o) const { return !(*this == o); }
68};
69SK_END_REQUIRE_DENSE
vandebo@chromium.org9b49dc02010-10-20 22:23:29 +000070
71#endif