| OLD | NEW |
| 1 // Copyright 2016 PDFium Authors. All rights reserved. | 1 // Copyright 2016 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 "fpdfsdk/include/cpdfsdk_baannot.h" | 7 #include "fpdfsdk/include/cpdfsdk_baannot.h" |
| 8 | 8 |
| 9 #include "core/fpdfapi/fpdf_parser/include/cpdf_array.h" | 9 #include "core/fpdfapi/fpdf_parser/include/cpdf_array.h" |
| 10 #include "core/fpdfapi/fpdf_parser/include/cpdf_document.h" | 10 #include "core/fpdfapi/fpdf_parser/include/cpdf_document.h" |
| (...skipping 144 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
| 155 m_pAnnot->GetAnnotDict()->SetIntegerFor("StructParent", key); | 155 m_pAnnot->GetAnnotDict()->SetIntegerFor("StructParent", key); |
| 156 } | 156 } |
| 157 | 157 |
| 158 int CPDFSDK_BAAnnot::GetStructParent() const { | 158 int CPDFSDK_BAAnnot::GetStructParent() const { |
| 159 return m_pAnnot->GetAnnotDict()->GetIntegerFor("StructParent"); | 159 return m_pAnnot->GetAnnotDict()->GetIntegerFor("StructParent"); |
| 160 } | 160 } |
| 161 | 161 |
| 162 // border | 162 // border |
| 163 void CPDFSDK_BAAnnot::SetBorderWidth(int nWidth) { | 163 void CPDFSDK_BAAnnot::SetBorderWidth(int nWidth) { |
| 164 CPDF_Array* pBorder = m_pAnnot->GetAnnotDict()->GetArrayFor("Border"); | 164 CPDF_Array* pBorder = m_pAnnot->GetAnnotDict()->GetArrayFor("Border"); |
| 165 | |
| 166 if (pBorder) { | 165 if (pBorder) { |
| 167 pBorder->SetAt(2, new CPDF_Number(nWidth)); | 166 pBorder->SetAt(2, new CPDF_Number(nWidth)); |
| 168 } else { | 167 } else { |
| 169 CPDF_Dictionary* pBSDict = m_pAnnot->GetAnnotDict()->GetDictFor("BS"); | 168 CPDF_Dictionary* pBSDict = m_pAnnot->GetAnnotDict()->GetDictFor("BS"); |
| 170 | |
| 171 if (!pBSDict) { | 169 if (!pBSDict) { |
| 172 pBSDict = new CPDF_Dictionary; | 170 pBSDict = |
| 171 new CPDF_Dictionary(m_pAnnot->GetDocument()->GetByteStringPool()); |
| 173 m_pAnnot->GetAnnotDict()->SetFor("BS", pBSDict); | 172 m_pAnnot->GetAnnotDict()->SetFor("BS", pBSDict); |
| 174 } | 173 } |
| 175 | |
| 176 pBSDict->SetIntegerFor("W", nWidth); | 174 pBSDict->SetIntegerFor("W", nWidth); |
| 177 } | 175 } |
| 178 } | 176 } |
| 179 | 177 |
| 180 int CPDFSDK_BAAnnot::GetBorderWidth() const { | 178 int CPDFSDK_BAAnnot::GetBorderWidth() const { |
| 181 if (CPDF_Array* pBorder = m_pAnnot->GetAnnotDict()->GetArrayFor("Border")) { | 179 if (CPDF_Array* pBorder = m_pAnnot->GetAnnotDict()->GetArrayFor("Border")) |
| 182 return pBorder->GetIntegerAt(2); | 180 return pBorder->GetIntegerAt(2); |
| 183 } | 181 |
| 184 if (CPDF_Dictionary* pBSDict = m_pAnnot->GetAnnotDict()->GetDictFor("BS")) { | 182 if (CPDF_Dictionary* pBSDict = m_pAnnot->GetAnnotDict()->GetDictFor("BS")) |
| 185 return pBSDict->GetIntegerFor("W", 1); | 183 return pBSDict->GetIntegerFor("W", 1); |
| 186 } | 184 |
| 187 return 1; | 185 return 1; |
| 188 } | 186 } |
| 189 | 187 |
| 190 void CPDFSDK_BAAnnot::SetBorderStyle(BorderStyle nStyle) { | 188 void CPDFSDK_BAAnnot::SetBorderStyle(BorderStyle nStyle) { |
| 191 CPDF_Dictionary* pBSDict = m_pAnnot->GetAnnotDict()->GetDictFor("BS"); | 189 CPDF_Dictionary* pBSDict = m_pAnnot->GetAnnotDict()->GetDictFor("BS"); |
| 192 if (!pBSDict) { | 190 if (!pBSDict) { |
| 193 pBSDict = new CPDF_Dictionary; | 191 pBSDict = new CPDF_Dictionary(m_pAnnot->GetDocument()->GetByteStringPool()); |
| 194 m_pAnnot->GetAnnotDict()->SetFor("BS", pBSDict); | 192 m_pAnnot->GetAnnotDict()->SetFor("BS", pBSDict); |
| 195 } | 193 } |
| 196 | 194 |
| 197 switch (nStyle) { | 195 switch (nStyle) { |
| 198 case BorderStyle::SOLID: | 196 case BorderStyle::SOLID: |
| 199 pBSDict->SetNameFor("S", "S"); | 197 pBSDict->SetNameFor("S", "S"); |
| 200 break; | 198 break; |
| 201 case BorderStyle::DASH: | 199 case BorderStyle::DASH: |
| 202 pBSDict->SetNameFor("S", "D"); | 200 pBSDict->SetNameFor("S", "D"); |
| 203 break; | 201 break; |
| (...skipping 86 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
| 290 | 288 |
| 291 return FALSE; | 289 return FALSE; |
| 292 } | 290 } |
| 293 | 291 |
| 294 void CPDFSDK_BAAnnot::WriteAppearance(const CFX_ByteString& sAPType, | 292 void CPDFSDK_BAAnnot::WriteAppearance(const CFX_ByteString& sAPType, |
| 295 const CFX_FloatRect& rcBBox, | 293 const CFX_FloatRect& rcBBox, |
| 296 const CFX_Matrix& matrix, | 294 const CFX_Matrix& matrix, |
| 297 const CFX_ByteString& sContents, | 295 const CFX_ByteString& sContents, |
| 298 const CFX_ByteString& sAPState) { | 296 const CFX_ByteString& sAPState) { |
| 299 CPDF_Dictionary* pAPDict = m_pAnnot->GetAnnotDict()->GetDictFor("AP"); | 297 CPDF_Dictionary* pAPDict = m_pAnnot->GetAnnotDict()->GetDictFor("AP"); |
| 300 | |
| 301 if (!pAPDict) { | 298 if (!pAPDict) { |
| 302 pAPDict = new CPDF_Dictionary; | 299 pAPDict = new CPDF_Dictionary(m_pAnnot->GetDocument()->GetByteStringPool()); |
| 303 m_pAnnot->GetAnnotDict()->SetFor("AP", pAPDict); | 300 m_pAnnot->GetAnnotDict()->SetFor("AP", pAPDict); |
| 304 } | 301 } |
| 305 | 302 |
| 306 CPDF_Stream* pStream = nullptr; | 303 CPDF_Stream* pStream = nullptr; |
| 307 CPDF_Dictionary* pParentDict = nullptr; | 304 CPDF_Dictionary* pParentDict = nullptr; |
| 308 | |
| 309 if (sAPState.IsEmpty()) { | 305 if (sAPState.IsEmpty()) { |
| 310 pParentDict = pAPDict; | 306 pParentDict = pAPDict; |
| 311 pStream = pAPDict->GetStreamFor(sAPType); | 307 pStream = pAPDict->GetStreamFor(sAPType); |
| 312 } else { | 308 } else { |
| 313 CPDF_Dictionary* pAPTypeDict = pAPDict->GetDictFor(sAPType); | 309 CPDF_Dictionary* pAPTypeDict = pAPDict->GetDictFor(sAPType); |
| 314 if (!pAPTypeDict) { | 310 if (!pAPTypeDict) { |
| 315 pAPTypeDict = new CPDF_Dictionary; | 311 pAPTypeDict = |
| 312 new CPDF_Dictionary(m_pAnnot->GetDocument()->GetByteStringPool()); |
| 316 pAPDict->SetFor(sAPType, pAPTypeDict); | 313 pAPDict->SetFor(sAPType, pAPTypeDict); |
| 317 } | 314 } |
| 318 pParentDict = pAPTypeDict; | 315 pParentDict = pAPTypeDict; |
| 319 pStream = pAPTypeDict->GetStreamFor(sAPState); | 316 pStream = pAPTypeDict->GetStreamFor(sAPState); |
| 320 } | 317 } |
| 321 | 318 |
| 322 if (!pStream) { | 319 if (!pStream) { |
| 323 pStream = new CPDF_Stream; | 320 pStream = new CPDF_Stream; |
| 324 CPDF_Document* pDoc = m_pPageView->GetPDFDocument(); | 321 CPDF_Document* pDoc = m_pPageView->GetPDFDocument(); |
| 325 pParentDict->SetReferenceFor(sAPType, pDoc, | 322 pParentDict->SetReferenceFor(sAPType, pDoc, |
| 326 pDoc->AddIndirectObject(pStream)); | 323 pDoc->AddIndirectObject(pStream)); |
| 327 } | 324 } |
| 328 | 325 |
| 329 CPDF_Dictionary* pStreamDict = pStream->GetDict(); | 326 CPDF_Dictionary* pStreamDict = pStream->GetDict(); |
| 330 if (!pStreamDict) { | 327 if (!pStreamDict) { |
| 331 pStreamDict = new CPDF_Dictionary; | 328 pStreamDict = |
| 329 new CPDF_Dictionary(m_pAnnot->GetDocument()->GetByteStringPool()); |
| 332 pStreamDict->SetNameFor("Type", "XObject"); | 330 pStreamDict->SetNameFor("Type", "XObject"); |
| 333 pStreamDict->SetNameFor("Subtype", "Form"); | 331 pStreamDict->SetNameFor("Subtype", "Form"); |
| 334 pStreamDict->SetIntegerFor("FormType", 1); | 332 pStreamDict->SetIntegerFor("FormType", 1); |
| 335 pStream->InitStream(nullptr, 0, pStreamDict); | 333 pStream->InitStream(nullptr, 0, pStreamDict); |
| 336 } | 334 } |
| 337 | 335 |
| 338 if (pStreamDict) { | 336 if (pStreamDict) { |
| 339 pStreamDict->SetMatrixFor("Matrix", matrix); | 337 pStreamDict->SetMatrixFor("Matrix", matrix); |
| 340 pStreamDict->SetRectFor("BBox", rcBBox); | 338 pStreamDict->SetRectFor("BBox", rcBBox); |
| 341 } | 339 } |
| (...skipping 54 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
| 396 CPDF_RenderOptions* pOptions) { | 394 CPDF_RenderOptions* pOptions) { |
| 397 m_pAnnot->GetAPForm(m_pPageView->GetPDFPage(), CPDF_Annot::Normal); | 395 m_pAnnot->GetAPForm(m_pPageView->GetPDFPage(), CPDF_Annot::Normal); |
| 398 m_pAnnot->DrawAppearance(m_pPageView->GetPDFPage(), pDevice, pUser2Device, | 396 m_pAnnot->DrawAppearance(m_pPageView->GetPDFPage(), pDevice, pUser2Device, |
| 399 CPDF_Annot::Normal, nullptr); | 397 CPDF_Annot::Normal, nullptr); |
| 400 } | 398 } |
| 401 | 399 |
| 402 void CPDFSDK_BAAnnot::SetOpenState(bool bOpenState) { | 400 void CPDFSDK_BAAnnot::SetOpenState(bool bOpenState) { |
| 403 if (CPDF_Annot* pAnnot = m_pAnnot->GetPopupAnnot()) | 401 if (CPDF_Annot* pAnnot = m_pAnnot->GetPopupAnnot()) |
| 404 pAnnot->SetOpenState(bOpenState); | 402 pAnnot->SetOpenState(bOpenState); |
| 405 } | 403 } |
| OLD | NEW |