OLD | NEW |
| (Empty) |
1 // Copyright 2016 PDFium Authors. All rights reserved. | |
2 // Use of this source code is governed by a BSD-style license that can be | |
3 // found in the LICENSE file. | |
4 | |
5 // Original code copyright 2014 Foxit Software Inc. http://www.foxitsoftware.com | |
6 | |
7 #include "core/fpdfapi/fpdf_page/cpdf_allstates.h" | |
8 | |
9 #include "core/fpdfapi/fpdf_page/pageint.h" | |
10 #include "core/fpdfapi/fpdf_parser/cpdf_array.h" | |
11 #include "core/fpdfapi/fpdf_parser/cpdf_dictionary.h" | |
12 #include "core/fxge/cfx_graphstatedata.h" | |
13 | |
14 namespace { | |
15 | |
16 FX_FLOAT ClipFloat(FX_FLOAT f) { | |
17 return std::max(0.0f, std::min(1.0f, f)); | |
18 } | |
19 | |
20 } // namespace | |
21 | |
22 CPDF_AllStates::CPDF_AllStates() { | |
23 m_TextX = m_TextY = m_TextLineX = m_TextLineY = 0; | |
24 m_TextLeading = 0; | |
25 m_TextRise = 0; | |
26 m_TextHorzScale = 1.0f; | |
27 } | |
28 | |
29 CPDF_AllStates::~CPDF_AllStates() {} | |
30 | |
31 void CPDF_AllStates::Copy(const CPDF_AllStates& src) { | |
32 CopyStates(src); | |
33 m_TextMatrix = src.m_TextMatrix; | |
34 m_ParentMatrix = src.m_ParentMatrix; | |
35 m_CTM = src.m_CTM; | |
36 m_TextX = src.m_TextX; | |
37 m_TextY = src.m_TextY; | |
38 m_TextLineX = src.m_TextLineX; | |
39 m_TextLineY = src.m_TextLineY; | |
40 m_TextLeading = src.m_TextLeading; | |
41 m_TextRise = src.m_TextRise; | |
42 m_TextHorzScale = src.m_TextHorzScale; | |
43 } | |
44 | |
45 void CPDF_AllStates::SetLineDash(CPDF_Array* pArray, | |
46 FX_FLOAT phase, | |
47 FX_FLOAT scale) { | |
48 m_GraphState.SetLineDash(pArray, phase, scale); | |
49 } | |
50 | |
51 void CPDF_AllStates::ProcessExtGS(CPDF_Dictionary* pGS, | |
52 CPDF_StreamContentParser* pParser) { | |
53 for (const auto& it : *pGS) { | |
54 const CFX_ByteString& key_str = it.first; | |
55 CPDF_Object* pElement = it.second; | |
56 CPDF_Object* pObject = pElement ? pElement->GetDirect() : nullptr; | |
57 if (!pObject) | |
58 continue; | |
59 | |
60 uint32_t key = key_str.GetID(); | |
61 switch (key) { | |
62 case FXBSTR_ID('L', 'W', 0, 0): | |
63 m_GraphState.SetLineWidth(pObject->GetNumber()); | |
64 break; | |
65 case FXBSTR_ID('L', 'C', 0, 0): | |
66 m_GraphState.SetLineCap( | |
67 static_cast<CFX_GraphStateData::LineCap>(pObject->GetInteger())); | |
68 break; | |
69 case FXBSTR_ID('L', 'J', 0, 0): | |
70 m_GraphState.SetLineJoin( | |
71 static_cast<CFX_GraphStateData::LineJoin>(pObject->GetInteger())); | |
72 break; | |
73 case FXBSTR_ID('M', 'L', 0, 0): | |
74 m_GraphState.SetMiterLimit(pObject->GetNumber()); | |
75 break; | |
76 case FXBSTR_ID('D', 0, 0, 0): { | |
77 CPDF_Array* pDash = pObject->AsArray(); | |
78 if (!pDash) | |
79 break; | |
80 | |
81 CPDF_Array* pArray = pDash->GetArrayAt(0); | |
82 if (!pArray) | |
83 break; | |
84 | |
85 SetLineDash(pArray, pDash->GetNumberAt(1), 1.0f); | |
86 break; | |
87 } | |
88 case FXBSTR_ID('R', 'I', 0, 0): | |
89 m_GeneralState.SetRenderIntent(pObject->GetString()); | |
90 break; | |
91 case FXBSTR_ID('F', 'o', 'n', 't'): { | |
92 CPDF_Array* pFont = pObject->AsArray(); | |
93 if (!pFont) | |
94 break; | |
95 | |
96 m_TextState.SetFontSize(pFont->GetNumberAt(1)); | |
97 m_TextState.SetFont(pParser->FindFont(pFont->GetStringAt(0))); | |
98 break; | |
99 } | |
100 case FXBSTR_ID('T', 'R', 0, 0): | |
101 if (pGS->KeyExist("TR2")) { | |
102 continue; | |
103 } | |
104 case FXBSTR_ID('T', 'R', '2', 0): | |
105 m_GeneralState.SetTR(pObject && !pObject->IsName() ? pObject : nullptr); | |
106 break; | |
107 case FXBSTR_ID('B', 'M', 0, 0): { | |
108 CPDF_Array* pArray = pObject->AsArray(); | |
109 m_GeneralState.SetBlendMode(pArray ? pArray->GetStringAt(0) | |
110 : pObject->GetString()); | |
111 if (m_GeneralState.GetBlendType() > FXDIB_BLEND_MULTIPLY) | |
112 pParser->GetPageObjectHolder()->SetBackgroundAlphaNeeded(TRUE); | |
113 break; | |
114 } | |
115 case FXBSTR_ID('S', 'M', 'a', 's'): | |
116 if (ToDictionary(pObject)) { | |
117 m_GeneralState.SetSoftMask(pObject); | |
118 m_GeneralState.SetSMaskMatrix(pParser->GetCurStates()->m_CTM); | |
119 } else { | |
120 m_GeneralState.SetSoftMask(nullptr); | |
121 } | |
122 break; | |
123 case FXBSTR_ID('C', 'A', 0, 0): | |
124 m_GeneralState.SetStrokeAlpha(ClipFloat(pObject->GetNumber())); | |
125 break; | |
126 case FXBSTR_ID('c', 'a', 0, 0): | |
127 m_GeneralState.SetFillAlpha(ClipFloat(pObject->GetNumber())); | |
128 break; | |
129 case FXBSTR_ID('O', 'P', 0, 0): | |
130 m_GeneralState.SetStrokeOP(!!pObject->GetInteger()); | |
131 if (!pGS->KeyExist("op")) | |
132 m_GeneralState.SetFillOP(!!pObject->GetInteger()); | |
133 break; | |
134 case FXBSTR_ID('o', 'p', 0, 0): | |
135 m_GeneralState.SetFillOP(!!pObject->GetInteger()); | |
136 break; | |
137 case FXBSTR_ID('O', 'P', 'M', 0): | |
138 m_GeneralState.SetOPMode(pObject->GetInteger()); | |
139 break; | |
140 case FXBSTR_ID('B', 'G', 0, 0): | |
141 if (pGS->KeyExist("BG2")) { | |
142 continue; | |
143 } | |
144 case FXBSTR_ID('B', 'G', '2', 0): | |
145 m_GeneralState.SetBG(pObject); | |
146 break; | |
147 case FXBSTR_ID('U', 'C', 'R', 0): | |
148 if (pGS->KeyExist("UCR2")) { | |
149 continue; | |
150 } | |
151 case FXBSTR_ID('U', 'C', 'R', '2'): | |
152 m_GeneralState.SetUCR(pObject); | |
153 break; | |
154 case FXBSTR_ID('H', 'T', 0, 0): | |
155 m_GeneralState.SetHT(pObject); | |
156 break; | |
157 case FXBSTR_ID('F', 'L', 0, 0): | |
158 m_GeneralState.SetFlatness(pObject->GetNumber()); | |
159 break; | |
160 case FXBSTR_ID('S', 'M', 0, 0): | |
161 m_GeneralState.SetSmoothness(pObject->GetNumber()); | |
162 break; | |
163 case FXBSTR_ID('S', 'A', 0, 0): | |
164 m_GeneralState.SetStrokeAdjust(!!pObject->GetInteger()); | |
165 break; | |
166 case FXBSTR_ID('A', 'I', 'S', 0): | |
167 m_GeneralState.SetAlphaSource(!!pObject->GetInteger()); | |
168 break; | |
169 case FXBSTR_ID('T', 'K', 0, 0): | |
170 m_GeneralState.SetTextKnockout(!!pObject->GetInteger()); | |
171 break; | |
172 } | |
173 } | |
174 m_GeneralState.SetMatrix(m_CTM); | |
175 } | |
OLD | NEW |