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