Chromium Code Reviews
chromiumcodereview-hr@appspot.gserviceaccount.com (chromiumcodereview-hr) | Please choose your nickname with Settings | Help | Chromium Project | Gerrit Changes | Sign out
(434)

Side by Side Diff: core/src/fpdfdoc/doc_formcontrol.cpp

Issue 1265503005: clang-format all pdfium code. (Closed) Base URL: https://pdfium.googlesource.com/pdfium.git@master
Patch Set: sigh Created 5 years, 4 months ago
Use n/p to move between diff chunks; N/P to move between comments. Draft comments are only viewable by you.
Jump to:
View unified diff | Download patch
OLDNEW
1 // Copyright 2014 PDFium Authors. All rights reserved. 1 // Copyright 2014 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 "../../include/fpdfdoc/fpdf_doc.h" 7 #include "../../include/fpdfdoc/fpdf_doc.h"
8 CPDF_FormControl::CPDF_FormControl(CPDF_FormField* pField, CPDF_Dictionary* pWid getDict) 8 CPDF_FormControl::CPDF_FormControl(CPDF_FormField* pField,
9 { 9 CPDF_Dictionary* pWidgetDict) {
10 m_pField = pField; 10 m_pField = pField;
11 m_pWidgetDict = pWidgetDict; 11 m_pWidgetDict = pWidgetDict;
12 m_pForm = m_pField->m_pForm; 12 m_pForm = m_pField->m_pForm;
13 } 13 }
14 CFX_FloatRect CPDF_FormControl::GetRect() 14 CFX_FloatRect CPDF_FormControl::GetRect() {
15 { 15 return m_pWidgetDict->GetRect("Rect");
16 return m_pWidgetDict->GetRect("Rect"); 16 }
17 } 17 CFX_ByteString CPDF_FormControl::GetOnStateName() {
18 CFX_ByteString CPDF_FormControl::GetOnStateName() 18 ASSERT(GetType() == CPDF_FormField::CheckBox ||
19 { 19 GetType() == CPDF_FormField::RadioButton);
20 ASSERT(GetType() == CPDF_FormField::CheckBox || GetType() == CPDF_FormField: :RadioButton); 20 CFX_ByteString csOn;
21 CFX_ByteString csOn; 21 CPDF_Dictionary* pAP = m_pWidgetDict->GetDict("AP");
22 CPDF_Dictionary* pAP = m_pWidgetDict->GetDict("AP"); 22 if (pAP == NULL) {
23 if (pAP == NULL) { 23 return csOn;
24 return csOn; 24 }
25 } 25 CPDF_Dictionary* pN = pAP->GetDict("N");
26 CPDF_Dictionary* pN = pAP->GetDict("N"); 26 if (pN == NULL) {
27 if (pN == NULL) { 27 return csOn;
28 return csOn; 28 }
29 } 29 FX_POSITION pos = pN->GetStartPos();
30 FX_POSITION pos = pN->GetStartPos(); 30 while (pos) {
31 while (pos) { 31 pN->GetNextElement(pos, csOn);
32 pN->GetNextElement(pos, csOn); 32 if (csOn != "Off") {
33 if (csOn != "Off") { 33 return csOn;
34 return csOn; 34 }
35 }
36 return CFX_ByteString();
37 }
38 void CPDF_FormControl::SetOnStateName(const CFX_ByteString& csOn) {
39 ASSERT(GetType() == CPDF_FormField::CheckBox ||
40 GetType() == CPDF_FormField::RadioButton);
41 CFX_ByteString csValue = csOn;
42 if (csValue.IsEmpty()) {
43 csValue = "Yes";
44 }
45 if (csValue == "Off") {
46 csValue = "Yes";
47 }
48 CFX_ByteString csAS = m_pWidgetDict->GetString("AS", "Off");
49 if (csAS != "Off") {
50 m_pWidgetDict->SetAtName("AS", csValue);
51 }
52 CPDF_Dictionary* pAP = m_pWidgetDict->GetDict("AP");
53 if (pAP == NULL) {
54 return;
55 }
56 FX_POSITION pos1 = pAP->GetStartPos();
57 while (pos1) {
58 CFX_ByteString csKey1;
59 CPDF_Object* pObj1 = pAP->GetNextElement(pos1, csKey1);
60 if (pObj1 == NULL) {
61 continue;
62 }
63 CPDF_Object* pObjDirect1 = pObj1->GetDirect();
64 if (pObjDirect1->GetType() != PDFOBJ_DICTIONARY) {
65 continue;
66 }
67 CPDF_Dictionary* pSubDict = (CPDF_Dictionary*)pObjDirect1;
68 FX_POSITION pos2 = pSubDict->GetStartPos();
69 while (pos2) {
70 CFX_ByteString csKey2;
71 CPDF_Object* pObj2 = pSubDict->GetNextElement(pos2, csKey2);
72 if (pObj2 == NULL) {
73 continue;
74 }
75 if (csKey2 != "Off") {
76 pSubDict->ReplaceKey(csKey2, csValue);
77 break;
78 }
79 }
80 }
81 }
82 CFX_ByteString CPDF_FormControl::GetCheckedAPState() {
83 ASSERT(GetType() == CPDF_FormField::CheckBox ||
84 GetType() == CPDF_FormField::RadioButton);
85 CFX_ByteString csOn = GetOnStateName();
86 if (GetType() == CPDF_FormField::RadioButton ||
87 GetType() == CPDF_FormField::CheckBox) {
88 CPDF_Object* pOpt = FPDF_GetFieldAttr(m_pField->m_pDict, "Opt");
89 if (pOpt != NULL && pOpt->GetType() == PDFOBJ_ARRAY) {
90 int iIndex = m_pField->GetControlIndex(this);
91 csOn.Format("%d", iIndex);
92 }
93 }
94 if (csOn.IsEmpty()) {
95 csOn = "Yes";
96 }
97 return csOn;
98 }
99 CFX_WideString CPDF_FormControl::GetExportValue() {
100 ASSERT(GetType() == CPDF_FormField::CheckBox ||
101 GetType() == CPDF_FormField::RadioButton);
102 CFX_ByteString csOn = GetOnStateName();
103 if (GetType() == CPDF_FormField::RadioButton ||
104 GetType() == CPDF_FormField::CheckBox) {
105 CPDF_Object* pOpt = FPDF_GetFieldAttr(m_pField->m_pDict, "Opt");
106 if (pOpt != NULL && pOpt->GetType() == PDFOBJ_ARRAY) {
107 int iIndex = m_pField->GetControlIndex(this);
108 csOn = ((CPDF_Array*)pOpt)->GetString(iIndex);
109 }
110 }
111 if (csOn.IsEmpty()) {
112 csOn = "Yes";
113 }
114 CFX_WideString csWOn = PDF_DecodeText(csOn);
115 return csWOn;
116 }
117 FX_BOOL CPDF_FormControl::IsChecked() {
118 ASSERT(GetType() == CPDF_FormField::CheckBox ||
119 GetType() == CPDF_FormField::RadioButton);
120 CFX_ByteString csOn = GetOnStateName();
121 CFX_ByteString csAS = m_pWidgetDict->GetString("AS");
122 return csAS == csOn;
123 }
124 FX_BOOL CPDF_FormControl::IsDefaultChecked() {
125 ASSERT(GetType() == CPDF_FormField::CheckBox ||
126 GetType() == CPDF_FormField::RadioButton);
127 CPDF_Object* pDV = FPDF_GetFieldAttr(m_pField->m_pDict, "DV");
128 if (pDV == NULL) {
129 return FALSE;
130 }
131 CFX_ByteString csDV = pDV->GetString();
132 CFX_ByteString csOn = GetOnStateName();
133 return (csDV == csOn);
134 }
135 void CPDF_FormControl::CheckControl(FX_BOOL bChecked) {
136 ASSERT(GetType() == CPDF_FormField::CheckBox ||
137 GetType() == CPDF_FormField::RadioButton);
138 CFX_ByteString csOn = GetOnStateName();
139 CFX_ByteString csOldAS = m_pWidgetDict->GetString("AS", "Off");
140 CFX_ByteString csAS = "Off";
141 if (bChecked) {
142 csAS = csOn;
143 }
144 if (csOldAS == csAS) {
145 return;
146 }
147 m_pWidgetDict->SetAtName("AS", csAS);
148 m_pForm->m_bUpdated = TRUE;
149 }
150 CPDF_Stream* FPDFDOC_GetAnnotAP(CPDF_Dictionary* pAnnotDict,
151 CPDF_Annot::AppearanceMode mode);
152 void CPDF_FormControl::DrawControl(CFX_RenderDevice* pDevice,
153 CFX_AffineMatrix* pMatrix,
154 CPDF_Page* pPage,
155 CPDF_Annot::AppearanceMode mode,
156 const CPDF_RenderOptions* pOptions) {
157 if (m_pWidgetDict->GetInteger("F") & ANNOTFLAG_HIDDEN) {
158 return;
159 }
160 CPDF_Stream* pStream = FPDFDOC_GetAnnotAP(m_pWidgetDict, mode);
161 if (pStream == NULL) {
162 return;
163 }
164 CFX_FloatRect form_bbox = pStream->GetDict()->GetRect("BBox");
165 CFX_AffineMatrix form_matrix = pStream->GetDict()->GetMatrix("Matrix");
166 form_matrix.TransformRect(form_bbox);
167 CFX_FloatRect arect = m_pWidgetDict->GetRect("Rect");
168 CFX_AffineMatrix matrix;
169 matrix.MatchRect(arect, form_bbox);
170 matrix.Concat(*pMatrix);
171 CPDF_Form form(m_pField->m_pForm->m_pDocument,
172 m_pField->m_pForm->m_pFormDict->GetDict("DR"), pStream);
173 form.ParseContent(NULL, NULL, NULL, NULL);
174 CPDF_RenderContext context;
175 context.Create(pPage);
176 context.DrawObjectList(pDevice, &form, &matrix, pOptions);
177 }
178 const FX_CHAR* g_sHighlightingMode[] = {"N", "I", "O", "P", "T", ""};
179 CPDF_FormControl::HighlightingMode CPDF_FormControl::GetHighlightingMode() {
180 if (m_pWidgetDict == NULL) {
181 return Invert;
182 }
183 CFX_ByteString csH = m_pWidgetDict->GetString("H", "I");
184 int i = 0;
185 while (g_sHighlightingMode[i][0] != '\0') {
186 if (csH.Equal(g_sHighlightingMode[i])) {
187 return (HighlightingMode)i;
188 }
189 i++;
190 }
191 return Invert;
192 }
193 CPDF_ApSettings CPDF_FormControl::GetMK(FX_BOOL bCreate) {
194 if (!m_pWidgetDict) {
195 return NULL;
196 }
197 CPDF_ApSettings mk = m_pWidgetDict->GetDict(FX_BSTRC("MK"));
198 if (!mk && bCreate) {
199 mk = CPDF_Dictionary::Create();
200 if (mk == NULL) {
201 return NULL;
202 }
203 m_pWidgetDict->SetAt(FX_BSTRC("MK"), mk);
204 }
205 return mk;
206 }
207 FX_BOOL CPDF_FormControl::HasMKEntry(CFX_ByteString csEntry) {
208 CPDF_ApSettings mk = GetMK(FALSE);
209 return mk.HasMKEntry(csEntry);
210 }
211 int CPDF_FormControl::GetRotation() {
212 CPDF_ApSettings mk = GetMK(FALSE);
213 return mk.GetRotation();
214 }
215 FX_ARGB CPDF_FormControl::GetColor(int& iColorType, CFX_ByteString csEntry) {
216 CPDF_ApSettings mk = GetMK(FALSE);
217 return mk.GetColor(iColorType, csEntry);
218 }
219 FX_FLOAT CPDF_FormControl::GetOriginalColor(int index, CFX_ByteString csEntry) {
220 CPDF_ApSettings mk = GetMK(FALSE);
221 return mk.GetOriginalColor(index, csEntry);
222 }
223 void CPDF_FormControl::GetOriginalColor(int& iColorType,
224 FX_FLOAT fc[4],
225 CFX_ByteString csEntry) {
226 CPDF_ApSettings mk = GetMK(FALSE);
227 mk.GetOriginalColor(iColorType, fc, csEntry);
228 }
229 CFX_WideString CPDF_FormControl::GetCaption(CFX_ByteString csEntry) {
230 CPDF_ApSettings mk = GetMK(FALSE);
231 return mk.GetCaption(csEntry);
232 }
233 CPDF_Stream* CPDF_FormControl::GetIcon(CFX_ByteString csEntry) {
234 CPDF_ApSettings mk = GetMK(FALSE);
235 return mk.GetIcon(csEntry);
236 }
237 CPDF_IconFit CPDF_FormControl::GetIconFit() {
238 CPDF_ApSettings mk = GetMK(FALSE);
239 return mk.GetIconFit();
240 }
241 int CPDF_FormControl::GetTextPosition() {
242 CPDF_ApSettings mk = GetMK(FALSE);
243 return mk.GetTextPosition();
244 }
245 CPDF_Action CPDF_FormControl::GetAction() {
246 if (!m_pWidgetDict) {
247 return CPDF_Action();
248 }
249 if (m_pWidgetDict->KeyExist("A")) {
250 return CPDF_Action(m_pWidgetDict->GetDict("A"));
251 }
252 CPDF_Object* pObj = FPDF_GetFieldAttr(m_pField->m_pDict, "A");
253 if (!pObj) {
254 return CPDF_Action();
255 }
256 return CPDF_Action(pObj->GetDict());
257 }
258 CPDF_AAction CPDF_FormControl::GetAdditionalAction() {
259 if (!m_pWidgetDict) {
260 return nullptr;
261 }
262 if (m_pWidgetDict->KeyExist("AA")) {
263 return m_pWidgetDict->GetDict("AA");
264 }
265 return m_pField->GetAdditionalAction();
266 }
267 CPDF_DefaultAppearance CPDF_FormControl::GetDefaultAppearance() {
268 if (!m_pWidgetDict) {
269 return CFX_ByteString();
270 }
271 if (m_pWidgetDict->KeyExist("DA")) {
272 return m_pWidgetDict->GetString("DA");
273 }
274 CPDF_Object* pObj = FPDF_GetFieldAttr(m_pField->m_pDict, "DA");
275 if (!pObj) {
276 return m_pField->m_pForm->GetDefaultAppearance();
277 }
278 return pObj->GetString();
279 }
280
281 CPDF_Font* CPDF_FormControl::GetDefaultControlFont() {
282 CPDF_DefaultAppearance cDA = GetDefaultAppearance();
283 CFX_ByteString csFontNameTag;
284 FX_FLOAT fFontSize;
285 cDA.GetFont(csFontNameTag, fFontSize);
286 if (csFontNameTag.IsEmpty())
287 return nullptr;
288
289 CPDF_Object* pObj = FPDF_GetFieldAttr(m_pWidgetDict, "DR");
290 if (pObj && pObj->GetType() == PDFOBJ_DICTIONARY) {
291 CPDF_Dictionary* pFonts = ((CPDF_Dictionary*)pObj)->GetDict("Font");
292 if (pFonts) {
293 CPDF_Dictionary* pElement = pFonts->GetDict(csFontNameTag);
294 if (pElement) {
295 CPDF_Font* pFont = m_pField->m_pForm->m_pDocument->LoadFont(pElement);
296 if (pFont) {
297 return pFont;
35 } 298 }
36 } 299 }
37 return CFX_ByteString(); 300 }
38 } 301 }
39 void CPDF_FormControl::SetOnStateName(const CFX_ByteString& csOn) 302 if (CPDF_Font* pFormFont = m_pField->m_pForm->GetFormFont(csFontNameTag))
40 { 303 return pFormFont;
41 ASSERT(GetType() == CPDF_FormField::CheckBox || GetType() == CPDF_FormField: :RadioButton); 304
42 CFX_ByteString csValue = csOn; 305 CPDF_Dictionary* pPageDict = m_pWidgetDict->GetDict("P");
43 if (csValue.IsEmpty()) { 306 pObj = FPDF_GetFieldAttr(pPageDict, "Resources");
44 csValue = "Yes"; 307 if (pObj && pObj->GetType() == PDFOBJ_DICTIONARY) {
45 } 308 CPDF_Dictionary* pFonts = ((CPDF_Dictionary*)pObj)->GetDict("Font");
46 if (csValue == "Off") { 309 if (pFonts) {
47 csValue = "Yes"; 310 CPDF_Dictionary* pElement = pFonts->GetDict(csFontNameTag);
48 } 311 if (pElement) {
49 CFX_ByteString csAS = m_pWidgetDict->GetString("AS", "Off"); 312 CPDF_Font* pFont = m_pField->m_pForm->m_pDocument->LoadFont(pElement);
50 if (csAS != "Off") { 313 if (pFont) {
51 m_pWidgetDict->SetAtName("AS", csValue); 314 return pFont;
52 }
53 CPDF_Dictionary* pAP = m_pWidgetDict->GetDict("AP");
54 if (pAP == NULL) {
55 return;
56 }
57 FX_POSITION pos1 = pAP->GetStartPos();
58 while (pos1) {
59 CFX_ByteString csKey1;
60 CPDF_Object* pObj1 = pAP->GetNextElement(pos1, csKey1);
61 if (pObj1 == NULL) {
62 continue;
63 } 315 }
64 CPDF_Object* pObjDirect1 = pObj1->GetDirect(); 316 }
65 if (pObjDirect1->GetType() != PDFOBJ_DICTIONARY) { 317 }
66 continue; 318 }
67 } 319 return nullptr;
68 CPDF_Dictionary* pSubDict = (CPDF_Dictionary*)pObjDirect1;
69 FX_POSITION pos2 = pSubDict->GetStartPos();
70 while (pos2) {
71 CFX_ByteString csKey2;
72 CPDF_Object* pObj2 = pSubDict->GetNextElement(pos2, csKey2);
73 if (pObj2 == NULL) {
74 continue;
75 }
76 if (csKey2 != "Off") {
77 pSubDict->ReplaceKey(csKey2, csValue);
78 break;
79 }
80 }
81 }
82 }
83 CFX_ByteString CPDF_FormControl::GetCheckedAPState()
84 {
85 ASSERT(GetType() == CPDF_FormField::CheckBox || GetType() == CPDF_FormField: :RadioButton);
86 CFX_ByteString csOn = GetOnStateName();
87 if (GetType() == CPDF_FormField::RadioButton || GetType() == CPDF_FormField: :CheckBox) {
88 CPDF_Object* pOpt = FPDF_GetFieldAttr(m_pField->m_pDict, "Opt");
89 if (pOpt != NULL && pOpt->GetType() == PDFOBJ_ARRAY) {
90 int iIndex = m_pField->GetControlIndex(this);
91 csOn.Format("%d", iIndex);
92 }
93 }
94 if (csOn.IsEmpty()) {
95 csOn = "Yes";
96 }
97 return csOn;
98 }
99 CFX_WideString CPDF_FormControl::GetExportValue()
100 {
101 ASSERT(GetType() == CPDF_FormField::CheckBox || GetType() == CPDF_FormField: :RadioButton);
102 CFX_ByteString csOn = GetOnStateName();
103 if (GetType() == CPDF_FormField::RadioButton || GetType() == CPDF_FormField: :CheckBox) {
104 CPDF_Object* pOpt = FPDF_GetFieldAttr(m_pField->m_pDict, "Opt");
105 if (pOpt != NULL && pOpt->GetType() == PDFOBJ_ARRAY) {
106 int iIndex = m_pField->GetControlIndex(this);
107 csOn = ((CPDF_Array*)pOpt)->GetString(iIndex);
108 }
109 }
110 if (csOn.IsEmpty()) {
111 csOn = "Yes";
112 }
113 CFX_WideString csWOn = PDF_DecodeText(csOn);
114 return csWOn;
115 }
116 FX_BOOL CPDF_FormControl::IsChecked()
117 {
118 ASSERT(GetType() == CPDF_FormField::CheckBox || GetType() == CPDF_FormField: :RadioButton);
119 CFX_ByteString csOn = GetOnStateName();
120 CFX_ByteString csAS = m_pWidgetDict->GetString("AS");
121 return csAS == csOn;
122 }
123 FX_BOOL CPDF_FormControl::IsDefaultChecked()
124 {
125 ASSERT(GetType() == CPDF_FormField::CheckBox || GetType() == CPDF_FormField: :RadioButton);
126 CPDF_Object* pDV = FPDF_GetFieldAttr(m_pField->m_pDict, "DV");
127 if (pDV == NULL) {
128 return FALSE;
129 }
130 CFX_ByteString csDV = pDV->GetString();
131 CFX_ByteString csOn = GetOnStateName();
132 return (csDV == csOn);
133 }
134 void CPDF_FormControl::CheckControl(FX_BOOL bChecked)
135 {
136 ASSERT(GetType() == CPDF_FormField::CheckBox || GetType() == CPDF_FormField: :RadioButton);
137 CFX_ByteString csOn = GetOnStateName();
138 CFX_ByteString csOldAS = m_pWidgetDict->GetString("AS", "Off");
139 CFX_ByteString csAS = "Off";
140 if (bChecked) {
141 csAS = csOn;
142 }
143 if (csOldAS == csAS) {
144 return;
145 }
146 m_pWidgetDict->SetAtName("AS", csAS);
147 m_pForm->m_bUpdated = TRUE;
148 }
149 CPDF_Stream* FPDFDOC_GetAnnotAP(CPDF_Dictionary* pAnnotDict, CPDF_Annot::Appeara nceMode mode);
150 void CPDF_FormControl::DrawControl(CFX_RenderDevice* pDevice, CFX_AffineMatrix* pMatrix, CPDF_Page* pPage,
151 CPDF_Annot::AppearanceMode mode, const CPDF_R enderOptions* pOptions)
152 {
153 if (m_pWidgetDict->GetInteger("F") & ANNOTFLAG_HIDDEN) {
154 return;
155 }
156 CPDF_Stream* pStream = FPDFDOC_GetAnnotAP(m_pWidgetDict, mode);
157 if (pStream == NULL) {
158 return;
159 }
160 CFX_FloatRect form_bbox = pStream->GetDict()->GetRect("BBox");
161 CFX_AffineMatrix form_matrix = pStream->GetDict()->GetMatrix("Matrix");
162 form_matrix.TransformRect(form_bbox);
163 CFX_FloatRect arect = m_pWidgetDict->GetRect("Rect");
164 CFX_AffineMatrix matrix;
165 matrix.MatchRect(arect, form_bbox);
166 matrix.Concat(*pMatrix);
167 CPDF_Form form(m_pField->m_pForm->m_pDocument, m_pField->m_pForm->m_pFormDic t->GetDict("DR"), pStream);
168 form.ParseContent(NULL, NULL, NULL, NULL);
169 CPDF_RenderContext context;
170 context.Create(pPage);
171 context.DrawObjectList(pDevice, &form, &matrix, pOptions);
172 }
173 const FX_CHAR* g_sHighlightingMode[] = {"N", "I", "O", "P", "T", ""};
174 CPDF_FormControl::HighlightingMode CPDF_FormControl::GetHighlightingMode()
175 {
176 if (m_pWidgetDict == NULL) {
177 return Invert;
178 }
179 CFX_ByteString csH = m_pWidgetDict->GetString("H", "I");
180 int i = 0;
181 while (g_sHighlightingMode[i][0] != '\0') {
182 if (csH.Equal(g_sHighlightingMode[i])) {
183 return (HighlightingMode)i;
184 }
185 i ++;
186 }
187 return Invert;
188 }
189 CPDF_ApSettings CPDF_FormControl::GetMK(FX_BOOL bCreate)
190 {
191 if (!m_pWidgetDict) {
192 return NULL;
193 }
194 CPDF_ApSettings mk = m_pWidgetDict->GetDict(FX_BSTRC("MK"));
195 if (!mk && bCreate) {
196 mk = CPDF_Dictionary::Create();
197 if (mk == NULL) {
198 return NULL;
199 }
200 m_pWidgetDict->SetAt(FX_BSTRC("MK"), mk);
201 }
202 return mk;
203 }
204 FX_BOOL CPDF_FormControl::HasMKEntry(CFX_ByteString csEntry)
205 {
206 CPDF_ApSettings mk = GetMK(FALSE);
207 return mk.HasMKEntry(csEntry);
208 }
209 int CPDF_FormControl::GetRotation()
210 {
211 CPDF_ApSettings mk = GetMK(FALSE);
212 return mk.GetRotation();
213 }
214 FX_ARGB CPDF_FormControl::GetColor(int& iColorType, CFX_ByteString csEntry)
215 {
216 CPDF_ApSettings mk = GetMK(FALSE);
217 return mk.GetColor(iColorType, csEntry);
218 }
219 FX_FLOAT CPDF_FormControl::GetOriginalColor(int index, CFX_ByteString csEntry)
220 {
221 CPDF_ApSettings mk = GetMK(FALSE);
222 return mk.GetOriginalColor(index, csEntry);
223 }
224 void CPDF_FormControl::GetOriginalColor(int& iColorType, FX_FLOAT fc[4], CFX_Byt eString csEntry)
225 {
226 CPDF_ApSettings mk = GetMK(FALSE);
227 mk.GetOriginalColor(iColorType, fc, csEntry);
228 }
229 CFX_WideString CPDF_FormControl::GetCaption(CFX_ByteString csEntry)
230 {
231 CPDF_ApSettings mk = GetMK(FALSE);
232 return mk.GetCaption(csEntry);
233 }
234 CPDF_Stream* CPDF_FormControl::GetIcon(CFX_ByteString csEntry)
235 {
236 CPDF_ApSettings mk = GetMK(FALSE);
237 return mk.GetIcon(csEntry);
238 }
239 CPDF_IconFit CPDF_FormControl::GetIconFit()
240 {
241 CPDF_ApSettings mk = GetMK(FALSE);
242 return mk.GetIconFit();
243 }
244 int CPDF_FormControl::GetTextPosition()
245 {
246 CPDF_ApSettings mk = GetMK(FALSE);
247 return mk.GetTextPosition();
248 }
249 CPDF_Action CPDF_FormControl::GetAction()
250 {
251 if (!m_pWidgetDict) {
252 return CPDF_Action();
253 }
254 if (m_pWidgetDict->KeyExist("A")) {
255 return CPDF_Action(m_pWidgetDict->GetDict("A"));
256 }
257 CPDF_Object* pObj = FPDF_GetFieldAttr(m_pField->m_pDict, "A");
258 if (!pObj) {
259 return CPDF_Action();
260 }
261 return CPDF_Action(pObj->GetDict());
262 }
263 CPDF_AAction CPDF_FormControl::GetAdditionalAction()
264 {
265 if (!m_pWidgetDict) {
266 return nullptr;
267 }
268 if (m_pWidgetDict->KeyExist("AA")) {
269 return m_pWidgetDict->GetDict("AA");
270 }
271 return m_pField->GetAdditionalAction();
272 }
273 CPDF_DefaultAppearance CPDF_FormControl::GetDefaultAppearance()
274 {
275 if (!m_pWidgetDict) {
276 return CFX_ByteString();
277 }
278 if (m_pWidgetDict->KeyExist("DA")) {
279 return m_pWidgetDict->GetString("DA");
280 }
281 CPDF_Object* pObj = FPDF_GetFieldAttr(m_pField->m_pDict, "DA");
282 if (!pObj) {
283 return m_pField->m_pForm->GetDefaultAppearance();
284 }
285 return pObj->GetString();
286 } 320 }
287 321
288 CPDF_Font* CPDF_FormControl::GetDefaultControlFont() 322 int CPDF_FormControl::GetControlAlignment() {
289 { 323 if (!m_pWidgetDict) {
290 CPDF_DefaultAppearance cDA = GetDefaultAppearance(); 324 return 0;
291 CFX_ByteString csFontNameTag; 325 }
292 FX_FLOAT fFontSize; 326 if (m_pWidgetDict->KeyExist("Q")) {
293 cDA.GetFont(csFontNameTag, fFontSize); 327 return m_pWidgetDict->GetInteger("Q", 0);
294 if (csFontNameTag.IsEmpty()) 328 }
295 return nullptr; 329 CPDF_Object* pObj = FPDF_GetFieldAttr(m_pField->m_pDict, "Q");
296 330 if (pObj == NULL) {
297 CPDF_Object* pObj = FPDF_GetFieldAttr(m_pWidgetDict, "DR"); 331 return m_pField->m_pForm->GetFormAlignment();
298 if (pObj && pObj->GetType() == PDFOBJ_DICTIONARY) { 332 }
299 CPDF_Dictionary* pFonts = ((CPDF_Dictionary*)pObj)->GetDict("Font"); 333 return pObj->GetInteger();
300 if (pFonts) { 334 }
301 CPDF_Dictionary* pElement = pFonts->GetDict(csFontNameTag); 335 FX_BOOL CPDF_ApSettings::HasMKEntry(const CFX_ByteStringC& csEntry) {
302 if (pElement) { 336 if (m_pDict == NULL) {
303 CPDF_Font* pFont = 337 return FALSE;
304 m_pField->m_pForm->m_pDocument->LoadFont(pElement); 338 }
305 if (pFont) { 339 return m_pDict->KeyExist(csEntry);
306 return pFont; 340 }
307 } 341 int CPDF_ApSettings::GetRotation() {
308 } 342 if (m_pDict == NULL) {
309 } 343 return 0;
310 } 344 }
311 if (CPDF_Font* pFormFont = m_pField->m_pForm->GetFormFont(csFontNameTag)) 345 return m_pDict->GetInteger(FX_BSTRC("R"));
312 return pFormFont; 346 }
313 347 FX_ARGB CPDF_ApSettings::GetColor(int& iColorType,
314 CPDF_Dictionary *pPageDict = m_pWidgetDict->GetDict("P"); 348 const CFX_ByteStringC& csEntry) {
315 pObj = FPDF_GetFieldAttr(pPageDict, "Resources"); 349 iColorType = COLORTYPE_TRANSPARENT;
316 if (pObj && pObj->GetType() == PDFOBJ_DICTIONARY) { 350 if (m_pDict == NULL) {
317 CPDF_Dictionary* pFonts = ((CPDF_Dictionary*)pObj)->GetDict("Font"); 351 return 0;
318 if (pFonts) { 352 }
319 CPDF_Dictionary* pElement = pFonts->GetDict(csFontNameTag); 353 FX_ARGB color = 0;
320 if (pElement) { 354 CPDF_Array* pEntry = m_pDict->GetArray(csEntry);
321 CPDF_Font* pFont = 355 if (pEntry == NULL) {
322 m_pField->m_pForm->m_pDocument->LoadFont(pElement);
323 if (pFont) {
324 return pFont;
325 }
326 }
327 }
328 }
329 return nullptr;
330 }
331
332 int CPDF_FormControl::GetControlAlignment()
333 {
334 if (!m_pWidgetDict) {
335 return 0;
336 }
337 if (m_pWidgetDict->KeyExist("Q")) {
338 return m_pWidgetDict->GetInteger("Q", 0);
339 }
340 CPDF_Object* pObj = FPDF_GetFieldAttr(m_pField->m_pDict, "Q");
341 if (pObj == NULL) {
342 return m_pField->m_pForm->GetFormAlignment();
343 }
344 return pObj->GetInteger();
345 }
346 FX_BOOL CPDF_ApSettings::HasMKEntry(const CFX_ByteStringC& csEntry)
347 {
348 if (m_pDict == NULL) {
349 return FALSE;
350 }
351 return m_pDict->KeyExist(csEntry);
352 }
353 int CPDF_ApSettings::GetRotation()
354 {
355 if (m_pDict == NULL) {
356 return 0;
357 }
358 return m_pDict->GetInteger(FX_BSTRC("R"));
359 }
360 FX_ARGB CPDF_ApSettings::GetColor(int& iColorType, const CFX_ByteStringC& csEntr y)
361 {
362 iColorType = COLORTYPE_TRANSPARENT;
363 if (m_pDict == NULL) {
364 return 0;
365 }
366 FX_ARGB color = 0;
367 CPDF_Array* pEntry = m_pDict->GetArray(csEntry);
368 if (pEntry == NULL) {
369 return color;
370 }
371 FX_DWORD dwCount = pEntry->GetCount();
372 if (dwCount == 1) {
373 iColorType = COLORTYPE_GRAY;
374 FX_FLOAT g = pEntry->GetNumber(0) * 255;
375 color = ArgbEncode(255, (int)g, (int)g, (int)g);
376 } else if (dwCount == 3) {
377 iColorType = COLORTYPE_RGB;
378 FX_FLOAT r = pEntry->GetNumber(0) * 255;
379 FX_FLOAT g = pEntry->GetNumber(1) * 255;
380 FX_FLOAT b = pEntry->GetNumber(2) * 255;
381 color = ArgbEncode(255, (int)r, (int)g, (int)b);
382 } else if (dwCount == 4) {
383 iColorType = COLORTYPE_CMYK;
384 FX_FLOAT c = pEntry->GetNumber(0);
385 FX_FLOAT m = pEntry->GetNumber(1);
386 FX_FLOAT y = pEntry->GetNumber(2);
387 FX_FLOAT k = pEntry->GetNumber(3);
388 FX_FLOAT r = 1.0f - FX_MIN(1.0f, c + k);
389 FX_FLOAT g = 1.0f - FX_MIN(1.0f, m + k);
390 FX_FLOAT b = 1.0f - FX_MIN(1.0f, y + k);
391 color = ArgbEncode(255, (int)(r * 255), (int)(g * 255), (int)(b * 255));
392 }
393 return color; 356 return color;
394 } 357 }
395 FX_FLOAT CPDF_ApSettings::GetOriginalColor(int index, const CFX_ByteStringC& csE ntry) 358 FX_DWORD dwCount = pEntry->GetCount();
396 { 359 if (dwCount == 1) {
397 if (m_pDict == NULL) { 360 iColorType = COLORTYPE_GRAY;
398 return 0; 361 FX_FLOAT g = pEntry->GetNumber(0) * 255;
399 } 362 color = ArgbEncode(255, (int)g, (int)g, (int)g);
400 CPDF_Array* pEntry = m_pDict->GetArray(csEntry); 363 } else if (dwCount == 3) {
401 if (pEntry != NULL) { 364 iColorType = COLORTYPE_RGB;
402 return pEntry->GetNumber(index); 365 FX_FLOAT r = pEntry->GetNumber(0) * 255;
403 } 366 FX_FLOAT g = pEntry->GetNumber(1) * 255;
367 FX_FLOAT b = pEntry->GetNumber(2) * 255;
368 color = ArgbEncode(255, (int)r, (int)g, (int)b);
369 } else if (dwCount == 4) {
370 iColorType = COLORTYPE_CMYK;
371 FX_FLOAT c = pEntry->GetNumber(0);
372 FX_FLOAT m = pEntry->GetNumber(1);
373 FX_FLOAT y = pEntry->GetNumber(2);
374 FX_FLOAT k = pEntry->GetNumber(3);
375 FX_FLOAT r = 1.0f - FX_MIN(1.0f, c + k);
376 FX_FLOAT g = 1.0f - FX_MIN(1.0f, m + k);
377 FX_FLOAT b = 1.0f - FX_MIN(1.0f, y + k);
378 color = ArgbEncode(255, (int)(r * 255), (int)(g * 255), (int)(b * 255));
379 }
380 return color;
381 }
382 FX_FLOAT CPDF_ApSettings::GetOriginalColor(int index,
383 const CFX_ByteStringC& csEntry) {
384 if (m_pDict == NULL) {
404 return 0; 385 return 0;
405 } 386 }
406 void CPDF_ApSettings::GetOriginalColor(int& iColorType, FX_FLOAT fc[4], const CF X_ByteStringC& csEntry) 387 CPDF_Array* pEntry = m_pDict->GetArray(csEntry);
407 { 388 if (pEntry != NULL) {
408 iColorType = COLORTYPE_TRANSPARENT; 389 return pEntry->GetNumber(index);
409 for (int i = 0; i < 4; i ++) { 390 }
410 fc[i] = 0; 391 return 0;
411 } 392 }
412 if (m_pDict == NULL) { 393 void CPDF_ApSettings::GetOriginalColor(int& iColorType,
413 return; 394 FX_FLOAT fc[4],
414 } 395 const CFX_ByteStringC& csEntry) {
415 CPDF_Array* pEntry = m_pDict->GetArray(csEntry); 396 iColorType = COLORTYPE_TRANSPARENT;
416 if (pEntry == NULL) { 397 for (int i = 0; i < 4; i++) {
417 return; 398 fc[i] = 0;
418 } 399 }
419 FX_DWORD dwCount = pEntry->GetCount(); 400 if (m_pDict == NULL) {
420 if (dwCount == 1) { 401 return;
421 iColorType = COLORTYPE_GRAY; 402 }
422 fc[0] = pEntry->GetNumber(0); 403 CPDF_Array* pEntry = m_pDict->GetArray(csEntry);
423 } else if (dwCount == 3) { 404 if (pEntry == NULL) {
424 iColorType = COLORTYPE_RGB; 405 return;
425 fc[0] = pEntry->GetNumber(0); 406 }
426 fc[1] = pEntry->GetNumber(1); 407 FX_DWORD dwCount = pEntry->GetCount();
427 fc[2] = pEntry->GetNumber(2); 408 if (dwCount == 1) {
428 } else if (dwCount == 4) { 409 iColorType = COLORTYPE_GRAY;
429 iColorType = COLORTYPE_CMYK; 410 fc[0] = pEntry->GetNumber(0);
430 fc[0] = pEntry->GetNumber(0); 411 } else if (dwCount == 3) {
431 fc[1] = pEntry->GetNumber(1); 412 iColorType = COLORTYPE_RGB;
432 fc[2] = pEntry->GetNumber(2); 413 fc[0] = pEntry->GetNumber(0);
433 fc[3] = pEntry->GetNumber(3); 414 fc[1] = pEntry->GetNumber(1);
434 } 415 fc[2] = pEntry->GetNumber(2);
435 } 416 } else if (dwCount == 4) {
436 CFX_WideString CPDF_ApSettings::GetCaption(const CFX_ByteStringC& csEntry) 417 iColorType = COLORTYPE_CMYK;
437 { 418 fc[0] = pEntry->GetNumber(0);
438 CFX_WideString csCaption; 419 fc[1] = pEntry->GetNumber(1);
439 if (m_pDict == NULL) { 420 fc[2] = pEntry->GetNumber(2);
440 return csCaption; 421 fc[3] = pEntry->GetNumber(3);
441 } 422 }
442 return m_pDict->GetUnicodeText(csEntry); 423 }
443 } 424 CFX_WideString CPDF_ApSettings::GetCaption(const CFX_ByteStringC& csEntry) {
444 CPDF_Stream* CPDF_ApSettings::GetIcon(const CFX_ByteStringC& csEntry) 425 CFX_WideString csCaption;
445 { 426 if (m_pDict == NULL) {
446 if (m_pDict == NULL) { 427 return csCaption;
447 return NULL; 428 }
448 } 429 return m_pDict->GetUnicodeText(csEntry);
449 return m_pDict->GetStream(csEntry); 430 }
450 } 431 CPDF_Stream* CPDF_ApSettings::GetIcon(const CFX_ByteStringC& csEntry) {
451 CPDF_IconFit CPDF_ApSettings::GetIconFit() 432 if (m_pDict == NULL) {
452 { 433 return NULL;
453 if (m_pDict == NULL) { 434 }
454 return NULL; 435 return m_pDict->GetStream(csEntry);
455 } 436 }
456 return m_pDict->GetDict(FX_BSTRC("IF")); 437 CPDF_IconFit CPDF_ApSettings::GetIconFit() {
457 } 438 if (m_pDict == NULL) {
458 int CPDF_ApSettings::GetTextPosition() 439 return NULL;
459 { 440 }
460 if (m_pDict == NULL) { 441 return m_pDict->GetDict(FX_BSTRC("IF"));
461 return TEXTPOS_CAPTION; 442 }
462 } 443 int CPDF_ApSettings::GetTextPosition() {
463 return m_pDict->GetInteger(FX_BSTRC("TP"), TEXTPOS_CAPTION); 444 if (m_pDict == NULL) {
464 } 445 return TEXTPOS_CAPTION;
446 }
447 return m_pDict->GetInteger(FX_BSTRC("TP"), TEXTPOS_CAPTION);
448 }
OLDNEW

Powered by Google App Engine
This is Rietveld 408576698