| OLD | NEW |
| 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 "core/include/fpdfdoc/fpdf_doc.h" | 7 #include "core/include/fpdfdoc/fpdf_doc.h" |
| 8 | 8 |
| 9 CPDF_FormControl::CPDF_FormControl(CPDF_FormField* pField, | 9 CPDF_FormControl::CPDF_FormControl(CPDF_FormField* pField, |
| 10 CPDF_Dictionary* pWidgetDict) { | 10 CPDF_Dictionary* pWidgetDict) { |
| 11 m_pField = pField; | 11 m_pField = pField; |
| 12 m_pWidgetDict = pWidgetDict; | 12 m_pWidgetDict = pWidgetDict; |
| 13 m_pForm = m_pField->m_pForm; | 13 m_pForm = m_pField->m_pForm; |
| 14 } | 14 } |
| 15 CFX_FloatRect CPDF_FormControl::GetRect() const { | 15 CFX_FloatRect CPDF_FormControl::GetRect() const { |
| 16 return m_pWidgetDict->GetRect("Rect"); | 16 return m_pWidgetDict->GetRect("Rect"); |
| 17 } | 17 } |
| 18 CFX_ByteString CPDF_FormControl::GetOnStateName() { | 18 CFX_ByteString CPDF_FormControl::GetOnStateName() { |
| 19 ASSERT(GetType() == CPDF_FormField::CheckBox || | 19 ASSERT(GetType() == CPDF_FormField::CheckBox || |
| 20 GetType() == CPDF_FormField::RadioButton); | 20 GetType() == CPDF_FormField::RadioButton); |
| 21 CFX_ByteString csOn; | 21 CFX_ByteString csOn; |
| 22 CPDF_Dictionary* pAP = m_pWidgetDict->GetDict("AP"); | 22 CPDF_Dictionary* pAP = m_pWidgetDict->GetDict("AP"); |
| 23 if (pAP == NULL) { | 23 if (!pAP) { |
| 24 return csOn; | 24 return csOn; |
| 25 } | 25 } |
| 26 CPDF_Dictionary* pN = pAP->GetDict("N"); | 26 CPDF_Dictionary* pN = pAP->GetDict("N"); |
| 27 if (pN == NULL) { | 27 if (!pN) { |
| 28 return csOn; | 28 return csOn; |
| 29 } | 29 } |
| 30 FX_POSITION pos = pN->GetStartPos(); | 30 FX_POSITION pos = pN->GetStartPos(); |
| 31 while (pos) { | 31 while (pos) { |
| 32 pN->GetNextElement(pos, csOn); | 32 pN->GetNextElement(pos, csOn); |
| 33 if (csOn != "Off") { | 33 if (csOn != "Off") { |
| 34 return csOn; | 34 return csOn; |
| 35 } | 35 } |
| 36 } | 36 } |
| 37 return CFX_ByteString(); | 37 return CFX_ByteString(); |
| 38 } | 38 } |
| 39 void CPDF_FormControl::SetOnStateName(const CFX_ByteString& csOn) { | 39 void CPDF_FormControl::SetOnStateName(const CFX_ByteString& csOn) { |
| 40 ASSERT(GetType() == CPDF_FormField::CheckBox || | 40 ASSERT(GetType() == CPDF_FormField::CheckBox || |
| 41 GetType() == CPDF_FormField::RadioButton); | 41 GetType() == CPDF_FormField::RadioButton); |
| 42 CFX_ByteString csValue = csOn; | 42 CFX_ByteString csValue = csOn; |
| 43 if (csValue.IsEmpty()) { | 43 if (csValue.IsEmpty()) { |
| 44 csValue = "Yes"; | 44 csValue = "Yes"; |
| 45 } | 45 } |
| 46 if (csValue == "Off") { | 46 if (csValue == "Off") { |
| 47 csValue = "Yes"; | 47 csValue = "Yes"; |
| 48 } | 48 } |
| 49 CFX_ByteString csAS = m_pWidgetDict->GetString("AS", "Off"); | 49 CFX_ByteString csAS = m_pWidgetDict->GetString("AS", "Off"); |
| 50 if (csAS != "Off") { | 50 if (csAS != "Off") { |
| 51 m_pWidgetDict->SetAtName("AS", csValue); | 51 m_pWidgetDict->SetAtName("AS", csValue); |
| 52 } | 52 } |
| 53 CPDF_Dictionary* pAP = m_pWidgetDict->GetDict("AP"); | 53 CPDF_Dictionary* pAP = m_pWidgetDict->GetDict("AP"); |
| 54 if (pAP == NULL) { | 54 if (!pAP) { |
| 55 return; | 55 return; |
| 56 } | 56 } |
| 57 FX_POSITION pos1 = pAP->GetStartPos(); | 57 FX_POSITION pos1 = pAP->GetStartPos(); |
| 58 while (pos1) { | 58 while (pos1) { |
| 59 CFX_ByteString csKey1; | 59 CFX_ByteString csKey1; |
| 60 CPDF_Object* pObj1 = pAP->GetNextElement(pos1, csKey1); | 60 CPDF_Object* pObj1 = pAP->GetNextElement(pos1, csKey1); |
| 61 if (pObj1 == NULL) { | 61 if (!pObj1) { |
| 62 continue; | 62 continue; |
| 63 } | 63 } |
| 64 CPDF_Object* pObjDirect1 = pObj1->GetDirect(); | 64 CPDF_Object* pObjDirect1 = pObj1->GetDirect(); |
| 65 CPDF_Dictionary* pSubDict = pObjDirect1->AsDictionary(); | 65 CPDF_Dictionary* pSubDict = pObjDirect1->AsDictionary(); |
| 66 if (!pSubDict) | 66 if (!pSubDict) |
| 67 continue; | 67 continue; |
| 68 | 68 |
| 69 FX_POSITION pos2 = pSubDict->GetStartPos(); | 69 FX_POSITION pos2 = pSubDict->GetStartPos(); |
| 70 while (pos2) { | 70 while (pos2) { |
| 71 CFX_ByteString csKey2; | 71 CFX_ByteString csKey2; |
| 72 CPDF_Object* pObj2 = pSubDict->GetNextElement(pos2, csKey2); | 72 CPDF_Object* pObj2 = pSubDict->GetNextElement(pos2, csKey2); |
| 73 if (pObj2 == NULL) { | 73 if (!pObj2) { |
| 74 continue; | 74 continue; |
| 75 } | 75 } |
| 76 if (csKey2 != "Off") { | 76 if (csKey2 != "Off") { |
| 77 pSubDict->ReplaceKey(csKey2, csValue); | 77 pSubDict->ReplaceKey(csKey2, csValue); |
| 78 break; | 78 break; |
| 79 } | 79 } |
| 80 } | 80 } |
| 81 } | 81 } |
| 82 } | 82 } |
| 83 CFX_ByteString CPDF_FormControl::GetCheckedAPState() { | 83 CFX_ByteString CPDF_FormControl::GetCheckedAPState() { |
| (...skipping 33 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
| 117 ASSERT(GetType() == CPDF_FormField::CheckBox || | 117 ASSERT(GetType() == CPDF_FormField::CheckBox || |
| 118 GetType() == CPDF_FormField::RadioButton); | 118 GetType() == CPDF_FormField::RadioButton); |
| 119 CFX_ByteString csOn = GetOnStateName(); | 119 CFX_ByteString csOn = GetOnStateName(); |
| 120 CFX_ByteString csAS = m_pWidgetDict->GetString("AS"); | 120 CFX_ByteString csAS = m_pWidgetDict->GetString("AS"); |
| 121 return csAS == csOn; | 121 return csAS == csOn; |
| 122 } | 122 } |
| 123 FX_BOOL CPDF_FormControl::IsDefaultChecked() { | 123 FX_BOOL CPDF_FormControl::IsDefaultChecked() { |
| 124 ASSERT(GetType() == CPDF_FormField::CheckBox || | 124 ASSERT(GetType() == CPDF_FormField::CheckBox || |
| 125 GetType() == CPDF_FormField::RadioButton); | 125 GetType() == CPDF_FormField::RadioButton); |
| 126 CPDF_Object* pDV = FPDF_GetFieldAttr(m_pField->m_pDict, "DV"); | 126 CPDF_Object* pDV = FPDF_GetFieldAttr(m_pField->m_pDict, "DV"); |
| 127 if (pDV == NULL) { | 127 if (!pDV) { |
| 128 return FALSE; | 128 return FALSE; |
| 129 } | 129 } |
| 130 CFX_ByteString csDV = pDV->GetString(); | 130 CFX_ByteString csDV = pDV->GetString(); |
| 131 CFX_ByteString csOn = GetOnStateName(); | 131 CFX_ByteString csOn = GetOnStateName(); |
| 132 return (csDV == csOn); | 132 return (csDV == csOn); |
| 133 } | 133 } |
| 134 void CPDF_FormControl::CheckControl(FX_BOOL bChecked) { | 134 void CPDF_FormControl::CheckControl(FX_BOOL bChecked) { |
| 135 ASSERT(GetType() == CPDF_FormField::CheckBox || | 135 ASSERT(GetType() == CPDF_FormField::CheckBox || |
| 136 GetType() == CPDF_FormField::RadioButton); | 136 GetType() == CPDF_FormField::RadioButton); |
| 137 CFX_ByteString csOn = GetOnStateName(); | 137 CFX_ByteString csOn = GetOnStateName(); |
| (...skipping 12 matching lines...) Expand all Loading... |
| 150 CPDF_Annot::AppearanceMode mode); | 150 CPDF_Annot::AppearanceMode mode); |
| 151 void CPDF_FormControl::DrawControl(CFX_RenderDevice* pDevice, | 151 void CPDF_FormControl::DrawControl(CFX_RenderDevice* pDevice, |
| 152 CFX_Matrix* pMatrix, | 152 CFX_Matrix* pMatrix, |
| 153 CPDF_Page* pPage, | 153 CPDF_Page* pPage, |
| 154 CPDF_Annot::AppearanceMode mode, | 154 CPDF_Annot::AppearanceMode mode, |
| 155 const CPDF_RenderOptions* pOptions) { | 155 const CPDF_RenderOptions* pOptions) { |
| 156 if (m_pWidgetDict->GetInteger("F") & ANNOTFLAG_HIDDEN) { | 156 if (m_pWidgetDict->GetInteger("F") & ANNOTFLAG_HIDDEN) { |
| 157 return; | 157 return; |
| 158 } | 158 } |
| 159 CPDF_Stream* pStream = FPDFDOC_GetAnnotAP(m_pWidgetDict, mode); | 159 CPDF_Stream* pStream = FPDFDOC_GetAnnotAP(m_pWidgetDict, mode); |
| 160 if (pStream == NULL) { | 160 if (!pStream) { |
| 161 return; | 161 return; |
| 162 } | 162 } |
| 163 CFX_FloatRect form_bbox = pStream->GetDict()->GetRect("BBox"); | 163 CFX_FloatRect form_bbox = pStream->GetDict()->GetRect("BBox"); |
| 164 CFX_Matrix form_matrix = pStream->GetDict()->GetMatrix("Matrix"); | 164 CFX_Matrix form_matrix = pStream->GetDict()->GetMatrix("Matrix"); |
| 165 form_matrix.TransformRect(form_bbox); | 165 form_matrix.TransformRect(form_bbox); |
| 166 CFX_FloatRect arect = m_pWidgetDict->GetRect("Rect"); | 166 CFX_FloatRect arect = m_pWidgetDict->GetRect("Rect"); |
| 167 CFX_Matrix matrix; | 167 CFX_Matrix matrix; |
| 168 matrix.MatchRect(arect, form_bbox); | 168 matrix.MatchRect(arect, form_bbox); |
| 169 matrix.Concat(*pMatrix); | 169 matrix.Concat(*pMatrix); |
| 170 CPDF_Form form(m_pField->m_pForm->m_pDocument, | 170 CPDF_Form form(m_pField->m_pForm->m_pDocument, |
| 171 m_pField->m_pForm->m_pFormDict->GetDict("DR"), pStream); | 171 m_pField->m_pForm->m_pFormDict->GetDict("DR"), pStream); |
| 172 form.ParseContent(NULL, NULL, NULL, NULL); | 172 form.ParseContent(NULL, NULL, NULL, NULL); |
| 173 CPDF_RenderContext context; | 173 CPDF_RenderContext context; |
| 174 context.Create(pPage); | 174 context.Create(pPage); |
| 175 context.DrawObjectList(pDevice, &form, &matrix, pOptions); | 175 context.DrawObjectList(pDevice, &form, &matrix, pOptions); |
| 176 } | 176 } |
| 177 const FX_CHAR* g_sHighlightingMode[] = {"N", "I", "O", "P", "T", ""}; | 177 const FX_CHAR* g_sHighlightingMode[] = {"N", "I", "O", "P", "T", ""}; |
| 178 CPDF_FormControl::HighlightingMode CPDF_FormControl::GetHighlightingMode() { | 178 CPDF_FormControl::HighlightingMode CPDF_FormControl::GetHighlightingMode() { |
| 179 if (m_pWidgetDict == NULL) { | 179 if (!m_pWidgetDict) { |
| 180 return Invert; | 180 return Invert; |
| 181 } | 181 } |
| 182 CFX_ByteString csH = m_pWidgetDict->GetString("H", "I"); | 182 CFX_ByteString csH = m_pWidgetDict->GetString("H", "I"); |
| 183 int i = 0; | 183 int i = 0; |
| 184 while (g_sHighlightingMode[i][0] != '\0') { | 184 while (g_sHighlightingMode[i][0] != '\0') { |
| 185 if (csH.Equal(g_sHighlightingMode[i])) { | 185 if (csH.Equal(g_sHighlightingMode[i])) { |
| 186 return (HighlightingMode)i; | 186 return (HighlightingMode)i; |
| 187 } | 187 } |
| 188 i++; | 188 i++; |
| 189 } | 189 } |
| (...skipping 120 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
| 310 } | 310 } |
| 311 | 311 |
| 312 int CPDF_FormControl::GetControlAlignment() { | 312 int CPDF_FormControl::GetControlAlignment() { |
| 313 if (!m_pWidgetDict) { | 313 if (!m_pWidgetDict) { |
| 314 return 0; | 314 return 0; |
| 315 } | 315 } |
| 316 if (m_pWidgetDict->KeyExist("Q")) { | 316 if (m_pWidgetDict->KeyExist("Q")) { |
| 317 return m_pWidgetDict->GetInteger("Q", 0); | 317 return m_pWidgetDict->GetInteger("Q", 0); |
| 318 } | 318 } |
| 319 CPDF_Object* pObj = FPDF_GetFieldAttr(m_pField->m_pDict, "Q"); | 319 CPDF_Object* pObj = FPDF_GetFieldAttr(m_pField->m_pDict, "Q"); |
| 320 if (pObj == NULL) { | 320 if (pObj) |
| 321 return m_pField->m_pForm->GetFormAlignment(); | 321 return pObj->GetInteger(); |
| 322 } | 322 return m_pField->m_pForm->GetFormAlignment(); |
| 323 return pObj->GetInteger(); | |
| 324 } | 323 } |
| 325 | 324 |
| 326 CPDF_ApSettings::CPDF_ApSettings(CPDF_Dictionary* pDict) : m_pDict(pDict) {} | 325 CPDF_ApSettings::CPDF_ApSettings(CPDF_Dictionary* pDict) : m_pDict(pDict) {} |
| 327 | 326 |
| 328 bool CPDF_ApSettings::HasMKEntry(const CFX_ByteStringC& csEntry) const { | 327 bool CPDF_ApSettings::HasMKEntry(const CFX_ByteStringC& csEntry) const { |
| 329 return m_pDict && m_pDict->KeyExist(csEntry); | 328 return m_pDict && m_pDict->KeyExist(csEntry); |
| 330 } | 329 } |
| 331 | 330 |
| 332 int CPDF_ApSettings::GetRotation() const { | 331 int CPDF_ApSettings::GetRotation() const { |
| 333 return m_pDict ? m_pDict->GetInteger("R") : 0; | 332 return m_pDict ? m_pDict->GetInteger("R") : 0; |
| (...skipping 45 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
| 379 return pEntry ? pEntry->GetNumber(index) : 0; | 378 return pEntry ? pEntry->GetNumber(index) : 0; |
| 380 } | 379 } |
| 381 | 380 |
| 382 void CPDF_ApSettings::GetOriginalColor(int& iColorType, | 381 void CPDF_ApSettings::GetOriginalColor(int& iColorType, |
| 383 FX_FLOAT fc[4], | 382 FX_FLOAT fc[4], |
| 384 const CFX_ByteStringC& csEntry) const { | 383 const CFX_ByteStringC& csEntry) const { |
| 385 iColorType = COLORTYPE_TRANSPARENT; | 384 iColorType = COLORTYPE_TRANSPARENT; |
| 386 for (int i = 0; i < 4; i++) { | 385 for (int i = 0; i < 4; i++) { |
| 387 fc[i] = 0; | 386 fc[i] = 0; |
| 388 } | 387 } |
| 389 if (m_pDict == NULL) { | 388 if (!m_pDict) { |
| 390 return; | 389 return; |
| 391 } | 390 } |
| 392 CPDF_Array* pEntry = m_pDict->GetArray(csEntry); | 391 CPDF_Array* pEntry = m_pDict->GetArray(csEntry); |
| 393 if (pEntry == NULL) { | 392 if (!pEntry) { |
| 394 return; | 393 return; |
| 395 } | 394 } |
| 396 FX_DWORD dwCount = pEntry->GetCount(); | 395 FX_DWORD dwCount = pEntry->GetCount(); |
| 397 if (dwCount == 1) { | 396 if (dwCount == 1) { |
| 398 iColorType = COLORTYPE_GRAY; | 397 iColorType = COLORTYPE_GRAY; |
| 399 fc[0] = pEntry->GetNumber(0); | 398 fc[0] = pEntry->GetNumber(0); |
| 400 } else if (dwCount == 3) { | 399 } else if (dwCount == 3) { |
| 401 iColorType = COLORTYPE_RGB; | 400 iColorType = COLORTYPE_RGB; |
| 402 fc[0] = pEntry->GetNumber(0); | 401 fc[0] = pEntry->GetNumber(0); |
| 403 fc[1] = pEntry->GetNumber(1); | 402 fc[1] = pEntry->GetNumber(1); |
| (...skipping 16 matching lines...) Expand all Loading... |
| 420 return m_pDict ? m_pDict->GetStream(csEntry) : nullptr; | 419 return m_pDict ? m_pDict->GetStream(csEntry) : nullptr; |
| 421 } | 420 } |
| 422 | 421 |
| 423 CPDF_IconFit CPDF_ApSettings::GetIconFit() const { | 422 CPDF_IconFit CPDF_ApSettings::GetIconFit() const { |
| 424 return m_pDict ? m_pDict->GetDict("IF") : nullptr; | 423 return m_pDict ? m_pDict->GetDict("IF") : nullptr; |
| 425 } | 424 } |
| 426 | 425 |
| 427 int CPDF_ApSettings::GetTextPosition() const { | 426 int CPDF_ApSettings::GetTextPosition() const { |
| 428 return m_pDict ? m_pDict->GetInteger("TP", TEXTPOS_CAPTION) : TEXTPOS_CAPTION; | 427 return m_pDict ? m_pDict->GetInteger("TP", TEXTPOS_CAPTION) : TEXTPOS_CAPTION; |
| 429 } | 428 } |
| OLD | NEW |