OLD | NEW |
1 // Copyright 2016 PDFium Authors. All rights reserved. | 1 // Copyright 2016 PDFium Authors. All rights reserved. |
2 // Use of this source code is governed by a BSD-style license that can be | 2 // Use of this source code is governed by a BSD-style license that can be |
3 // found in the LICENSE file. | 3 // found in the LICENSE file. |
4 | 4 |
5 // Original code copyright 2014 Foxit Software Inc. http://www.foxitsoftware.com | 5 // Original code copyright 2014 Foxit Software Inc. http://www.foxitsoftware.com |
6 | 6 |
7 #include "core/fpdfapi/fpdf_page/include/cpdf_generalstate.h" | 7 #include "core/fpdfapi/fpdf_page/include/cpdf_generalstate.h" |
8 | 8 |
9 namespace { | 9 namespace { |
10 | 10 |
11 int RI_StringToId(const CFX_ByteString& ri) { | 11 int RI_StringToId(const CFX_ByteString& ri) { |
12 uint32_t id = ri.GetID(); | 12 uint32_t id = ri.GetID(); |
13 if (id == FXBSTR_ID('A', 'b', 's', 'o')) | 13 if (id == FXBSTR_ID('A', 'b', 's', 'o')) |
14 return 1; | 14 return 1; |
15 | 15 |
16 if (id == FXBSTR_ID('S', 'a', 't', 'u')) | 16 if (id == FXBSTR_ID('S', 'a', 't', 'u')) |
17 return 2; | 17 return 2; |
18 | 18 |
19 if (id == FXBSTR_ID('P', 'e', 'r', 'c')) | 19 if (id == FXBSTR_ID('P', 'e', 'r', 'c')) |
20 return 3; | 20 return 3; |
21 | 21 |
22 return 0; | 22 return 0; |
23 } | 23 } |
24 | 24 |
25 } // namespace | 25 } // namespace |
26 | 26 |
| 27 CPDF_GeneralState::CPDF_GeneralState() {} |
| 28 |
| 29 CPDF_GeneralState::CPDF_GeneralState(const CPDF_GeneralState& that) |
| 30 : m_Ref(that.m_Ref) {} |
| 31 |
| 32 CPDF_GeneralState::~CPDF_GeneralState() {} |
| 33 |
27 void CPDF_GeneralState::SetRenderIntent(const CFX_ByteString& ri) { | 34 void CPDF_GeneralState::SetRenderIntent(const CFX_ByteString& ri) { |
28 GetPrivateCopy()->m_RenderIntent = RI_StringToId(ri); | 35 m_Ref.GetPrivateCopy()->m_RenderIntent = RI_StringToId(ri); |
29 } | 36 } |
| 37 |
| 38 int CPDF_GeneralState::GetBlendType() const { |
| 39 const CPDF_GeneralStateData* pData = m_Ref.GetObject(); |
| 40 return pData ? pData->m_BlendType : FXDIB_BLEND_NORMAL; |
| 41 } |
| 42 |
| 43 void CPDF_GeneralState::SetBlendType(int type) { |
| 44 m_Ref.GetPrivateCopy()->m_BlendType = type; |
| 45 } |
| 46 |
| 47 FX_FLOAT CPDF_GeneralState::GetFillAlpha() const { |
| 48 const CPDF_GeneralStateData* pData = m_Ref.GetObject(); |
| 49 return pData ? pData->m_FillAlpha : 1.0f; |
| 50 } |
| 51 |
| 52 void CPDF_GeneralState::SetFillAlpha(FX_FLOAT alpha) { |
| 53 m_Ref.GetPrivateCopy()->m_FillAlpha = alpha; |
| 54 } |
| 55 |
| 56 FX_FLOAT CPDF_GeneralState::GetStrokeAlpha() const { |
| 57 const CPDF_GeneralStateData* pData = m_Ref.GetObject(); |
| 58 return pData ? pData->m_StrokeAlpha : 1.0f; |
| 59 } |
| 60 |
| 61 void CPDF_GeneralState::SetStrokeAlpha(FX_FLOAT alpha) { |
| 62 m_Ref.GetPrivateCopy()->m_StrokeAlpha = alpha; |
| 63 } |
| 64 |
| 65 CPDF_Object* CPDF_GeneralState::GetSoftMask() const { |
| 66 const CPDF_GeneralStateData* pData = m_Ref.GetObject(); |
| 67 return pData ? pData->m_pSoftMask : nullptr; |
| 68 } |
| 69 |
| 70 void CPDF_GeneralState::SetSoftMask(CPDF_Object* pObject) { |
| 71 m_Ref.GetPrivateCopy()->m_pSoftMask = pObject; |
| 72 } |
| 73 |
| 74 CPDF_Object* CPDF_GeneralState::GetTR() const { |
| 75 const CPDF_GeneralStateData* pData = m_Ref.GetObject(); |
| 76 return pData ? pData->m_pTR : nullptr; |
| 77 } |
| 78 |
| 79 void CPDF_GeneralState::SetTR(CPDF_Object* pObject) { |
| 80 m_Ref.GetPrivateCopy()->m_pTR = pObject; |
| 81 } |
| 82 |
| 83 CPDF_TransferFunc* CPDF_GeneralState::GetTransferFunc() const { |
| 84 const CPDF_GeneralStateData* pData = m_Ref.GetObject(); |
| 85 return pData ? pData->m_pTransferFunc : nullptr; |
| 86 } |
| 87 |
| 88 void CPDF_GeneralState::SetTransferFunc(CPDF_TransferFunc* pFunc) { |
| 89 m_Ref.GetPrivateCopy()->m_pTransferFunc = pFunc; |
| 90 } |
| 91 |
| 92 void CPDF_GeneralState::SetBlendMode(const CFX_ByteStringC& mode) { |
| 93 m_Ref.GetPrivateCopy()->SetBlendMode(mode); |
| 94 } |
| 95 |
| 96 const FX_FLOAT* CPDF_GeneralState::GetSMaskMatrix() const { |
| 97 const CPDF_GeneralStateData* pData = m_Ref.GetObject(); |
| 98 return pData ? pData->m_SMaskMatrix : nullptr; |
| 99 } |
| 100 |
| 101 FX_FLOAT* CPDF_GeneralState::GetMutableSMaskMatrix() { |
| 102 return m_Ref.GetPrivateCopy()->m_SMaskMatrix; |
| 103 } |
| 104 |
| 105 bool CPDF_GeneralState::GetFillOP() const { |
| 106 const CPDF_GeneralStateData* pData = m_Ref.GetObject(); |
| 107 return pData && pData->m_FillOP; |
| 108 } |
| 109 |
| 110 void CPDF_GeneralState::SetFillOP(bool op) { |
| 111 m_Ref.GetPrivateCopy()->m_FillOP = op; |
| 112 } |
| 113 |
| 114 void CPDF_GeneralState::SetStrokeOP(bool op) { |
| 115 m_Ref.GetPrivateCopy()->m_StrokeOP = op; |
| 116 } |
| 117 |
| 118 bool CPDF_GeneralState::GetStrokeOP() const { |
| 119 const CPDF_GeneralStateData* pData = m_Ref.GetObject(); |
| 120 return pData && pData->m_StrokeOP; |
| 121 } |
| 122 |
| 123 int CPDF_GeneralState::GetOPMode() const { |
| 124 return m_Ref.GetObject()->m_OPMode; |
| 125 } |
| 126 |
| 127 void CPDF_GeneralState::SetOPMode(int mode) { |
| 128 m_Ref.GetPrivateCopy()->m_OPMode = mode; |
| 129 } |
| 130 |
| 131 void CPDF_GeneralState::SetBG(CPDF_Object* pObject) { |
| 132 m_Ref.GetPrivateCopy()->m_pBG = pObject; |
| 133 } |
| 134 |
| 135 void CPDF_GeneralState::SetUCR(CPDF_Object* pObject) { |
| 136 m_Ref.GetPrivateCopy()->m_pUCR = pObject; |
| 137 } |
| 138 |
| 139 void CPDF_GeneralState::SetHT(CPDF_Object* pObject) { |
| 140 m_Ref.GetPrivateCopy()->m_pHT = pObject; |
| 141 } |
| 142 |
| 143 void CPDF_GeneralState::SetFlatness(FX_FLOAT flatness) { |
| 144 m_Ref.GetPrivateCopy()->m_Flatness = flatness; |
| 145 } |
| 146 |
| 147 void CPDF_GeneralState::SetSmoothness(FX_FLOAT smoothness) { |
| 148 m_Ref.GetPrivateCopy()->m_Smoothness = smoothness; |
| 149 } |
| 150 |
| 151 bool CPDF_GeneralState::GetStrokeAdjust() const { |
| 152 const CPDF_GeneralStateData* pData = m_Ref.GetObject(); |
| 153 return pData && pData->m_StrokeAdjust; |
| 154 } |
| 155 |
| 156 void CPDF_GeneralState::SetStrokeAdjust(bool adjust) { |
| 157 m_Ref.GetPrivateCopy()->m_StrokeAdjust = adjust; |
| 158 } |
| 159 |
| 160 void CPDF_GeneralState::SetAlphaSource(bool source) { |
| 161 m_Ref.GetPrivateCopy()->m_AlphaSource = source; |
| 162 } |
| 163 |
| 164 void CPDF_GeneralState::SetTextKnockout(bool knockout) { |
| 165 m_Ref.GetPrivateCopy()->m_TextKnockout = knockout; |
| 166 } |
| 167 |
| 168 void CPDF_GeneralState::SetMatrix(const CFX_Matrix& matrix) { |
| 169 m_Ref.GetPrivateCopy()->m_Matrix = matrix; |
| 170 } |
| 171 |
| 172 CFX_Matrix* CPDF_GeneralState::GetMutableMatrix() { |
| 173 return &m_Ref.GetPrivateCopy()->m_Matrix; |
| 174 } |
OLD | NEW |