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