Qt
Internal/Contributor docs for the Qt SDK. Note: These are NOT official API docs; those are found at https://doc.qt.io/
Loading...
Searching...
No Matches
cpdf_allstates.cpp
Go to the documentation of this file.
1// Copyright 2016 The PDFium Authors
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/page/cpdf_allstates.h"
8
9#include <algorithm>
10#include <utility>
11#include <vector>
12
13#include "core/fpdfapi/font/cpdf_font.h"
14#include "core/fpdfapi/page/cpdf_pageobjectholder.h"
15#include "core/fpdfapi/page/cpdf_streamcontentparser.h"
16#include "core/fpdfapi/parser/cpdf_array.h"
17#include "core/fpdfapi/parser/cpdf_dictionary.h"
18#include "core/fpdfapi/parser/fpdf_parser_utility.h"
19#include "core/fxcrt/bytestring.h"
20#include "core/fxge/cfx_graphstatedata.h"
21
23
24CPDF_AllStates::CPDF_AllStates(const CPDF_AllStates& that) = default;
25
27
28CPDF_AllStates::~CPDF_AllStates() = default;
29
31 m_GraphicStates.SetDefaultStates();
32}
33
34void CPDF_AllStates::SetLineDash(const CPDF_Array* pArray,
35 float phase,
36 float scale) {
37 std::vector<float> dashes = ReadArrayElementsToVector(pArray, pArray->size());
38 mutable_graph_state().SetLineDash(std::move(dashes), phase, scale);
39}
40
41void CPDF_AllStates::ProcessExtGS(const CPDF_Dictionary* pGS,
42 CPDF_StreamContentParser* pParser) {
44 for (const auto& it : locker) {
45 RetainPtr<CPDF_Object> pObject = it.second->GetMutableDirect();
46 if (!pObject)
47 continue;
48
49 uint32_t key = it.first.GetID();
50 switch (key) {
51 case FXBSTR_ID('L', 'W', 0, 0):
52 mutable_graph_state().SetLineWidth(pObject->GetNumber());
53 break;
54 case FXBSTR_ID('L', 'C', 0, 0):
55 mutable_graph_state().SetLineCap(
56 static_cast<CFX_GraphStateData::LineCap>(pObject->GetInteger()));
57 break;
58 case FXBSTR_ID('L', 'J', 0, 0):
59 mutable_graph_state().SetLineJoin(
60 static_cast<CFX_GraphStateData::LineJoin>(pObject->GetInteger()));
61 break;
62 case FXBSTR_ID('M', 'L', 0, 0):
63 mutable_graph_state().SetMiterLimit(pObject->GetNumber());
64 break;
65 case FXBSTR_ID('D', 0, 0, 0): {
66 const CPDF_Array* pDash = pObject->AsArray();
67 if (!pDash)
68 break;
69
70 RetainPtr<const CPDF_Array> pArray = pDash->GetArrayAt(0);
71 if (!pArray)
72 break;
73
74 SetLineDash(pArray.Get(), pDash->GetFloatAt(1), 1.0f);
75 break;
76 }
77 case FXBSTR_ID('R', 'I', 0, 0):
78 mutable_general_state().SetRenderIntent(pObject->GetString());
79 break;
80 case FXBSTR_ID('F', 'o', 'n', 't'): {
81 const CPDF_Array* pFont = pObject->AsArray();
82 if (!pFont)
83 break;
84
85 mutable_text_state().SetFontSize(pFont->GetFloatAt(1));
86 mutable_text_state().SetFont(
87 pParser->FindFont(pFont->GetByteStringAt(0)));
88 break;
89 }
90 case FXBSTR_ID('T', 'R', 0, 0):
91 if (pGS->KeyExist("TR2")) {
92 continue;
93 }
94 [[fallthrough]];
95 case FXBSTR_ID('T', 'R', '2', 0):
96 mutable_general_state().SetTR(!pObject->IsName() ? std::move(pObject)
97 : nullptr);
98 break;
99 case FXBSTR_ID('B', 'M', 0, 0): {
100 const CPDF_Array* pArray = pObject->AsArray();
101 mutable_general_state().SetBlendMode(pArray ? pArray->GetByteStringAt(0)
102 : pObject->GetString());
103 if (general_state().GetBlendType() > BlendMode::kMultiply) {
104 pParser->GetPageObjectHolder()->SetBackgroundAlphaNeeded(true);
105 }
106 break;
107 }
108 case FXBSTR_ID('S', 'M', 'a', 's'): {
109 RetainPtr<CPDF_Dictionary> pMaskDict = ToDictionary(pObject);
110 mutable_general_state().SetSoftMask(pMaskDict);
111 if (pMaskDict)
112 mutable_general_state().SetSMaskMatrix(
113 pParser->GetCurStates()->m_CTM);
114 break;
115 }
116 case FXBSTR_ID('C', 'A', 0, 0):
117 mutable_general_state().SetStrokeAlpha(
118 std::clamp(pObject->GetNumber(), 0.0f, 1.0f));
119 break;
120 case FXBSTR_ID('c', 'a', 0, 0):
121 mutable_general_state().SetFillAlpha(
122 std::clamp(pObject->GetNumber(), 0.0f, 1.0f));
123 break;
124 case FXBSTR_ID('O', 'P', 0, 0):
125 mutable_general_state().SetStrokeOP(!!pObject->GetInteger());
126 if (!pGS->KeyExist("op"))
127 mutable_general_state().SetFillOP(!!pObject->GetInteger());
128 break;
129 case FXBSTR_ID('o', 'p', 0, 0):
130 mutable_general_state().SetFillOP(!!pObject->GetInteger());
131 break;
132 case FXBSTR_ID('O', 'P', 'M', 0):
133 mutable_general_state().SetOPMode(pObject->GetInteger());
134 break;
135 case FXBSTR_ID('B', 'G', 0, 0):
136 if (pGS->KeyExist("BG2")) {
137 continue;
138 }
139 [[fallthrough]];
140 case FXBSTR_ID('B', 'G', '2', 0):
141 mutable_general_state().SetBG(std::move(pObject));
142 break;
143 case FXBSTR_ID('U', 'C', 'R', 0):
144 if (pGS->KeyExist("UCR2")) {
145 continue;
146 }
147 [[fallthrough]];
148 case FXBSTR_ID('U', 'C', 'R', '2'):
149 mutable_general_state().SetUCR(std::move(pObject));
150 break;
151 case FXBSTR_ID('H', 'T', 0, 0):
152 mutable_general_state().SetHT(std::move(pObject));
153 break;
154 case FXBSTR_ID('F', 'L', 0, 0):
155 mutable_general_state().SetFlatness(pObject->GetNumber());
156 break;
157 case FXBSTR_ID('S', 'M', 0, 0):
158 mutable_general_state().SetSmoothness(pObject->GetNumber());
159 break;
160 case FXBSTR_ID('S', 'A', 0, 0):
161 mutable_general_state().SetStrokeAdjust(!!pObject->GetInteger());
162 break;
163 case FXBSTR_ID('A', 'I', 'S', 0):
164 mutable_general_state().SetAlphaSource(!!pObject->GetInteger());
165 break;
166 case FXBSTR_ID('T', 'K', 0, 0):
167 mutable_general_state().SetTextKnockout(!!pObject->GetInteger());
168 break;
169 }
170 }
172}
173
175 m_TextLinePos = CFX_PointF();
176 m_TextPos = CFX_PointF();
177}
178
180 return m_CTM.Transform(m_TextMatrix.Transform(
181 CFX_PointF(m_TextPos.x, m_TextPos.y + m_TextRise)));
182}
183
184void CPDF_AllStates::MoveTextPoint(const CFX_PointF& point) {
185 m_TextLinePos += point;
186 m_TextPos = m_TextLinePos;
187}
188
190 m_TextLinePos.y -= m_TextLeading;
191 m_TextPos = m_TextLinePos;
192}
193
195 m_TextPos.x += value;
196}
197
199 m_TextPos.y += value;
200}
void IncrementTextPositionX(float value)
CFX_GraphState & mutable_graph_state()
void MoveTextPoint(const CFX_PointF &point)
void IncrementTextPositionY(float value)
CFX_PointF GetTransformedTextPosition() const
CPDF_GeneralState & mutable_general_state()
CPDF_AllStates & operator=(const CPDF_AllStates &that)
void SetLineDash(const CPDF_Array *pArray, float phase, float scale)
void ProcessExtGS(const CPDF_Dictionary *pGS, CPDF_StreamContentParser *pParser)
CPDF_AllStates(const CPDF_AllStates &that)
CPDF_DictionaryLocker(const CPDF_Dictionary *pDictionary)
void SetMatrix(const CFX_Matrix &matrix)