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/cpdfsdk_baannot.h" | 7 #include "fpdfsdk/cpdfsdk_baannot.h" |
8 | 8 |
9 #include <algorithm> | 9 #include <algorithm> |
| 10 #include <utility> |
10 | 11 |
11 #include "core/fpdfapi/parser/cpdf_array.h" | 12 #include "core/fpdfapi/parser/cpdf_array.h" |
12 #include "core/fpdfapi/parser/cpdf_document.h" | 13 #include "core/fpdfapi/parser/cpdf_document.h" |
13 #include "core/fpdfapi/parser/cpdf_name.h" | 14 #include "core/fpdfapi/parser/cpdf_name.h" |
14 #include "core/fpdfapi/parser/cpdf_number.h" | 15 #include "core/fpdfapi/parser/cpdf_number.h" |
15 #include "core/fpdfapi/parser/cpdf_reference.h" | 16 #include "core/fpdfapi/parser/cpdf_reference.h" |
16 #include "core/fpdfapi/parser/cpdf_stream.h" | 17 #include "core/fpdfapi/parser/cpdf_stream.h" |
17 #include "core/fpdfapi/parser/cpdf_string.h" | 18 #include "core/fpdfapi/parser/cpdf_string.h" |
18 #include "core/fpdfapi/parser/fpdf_parser_decode.h" | 19 #include "core/fpdfapi/parser/fpdf_parser_decode.h" |
19 #include "fpdfsdk/cpdfsdk_datetime.h" | 20 #include "fpdfsdk/cpdfsdk_datetime.h" |
(...skipping 296 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
316 } | 317 } |
317 | 318 |
318 if (!pStream) { | 319 if (!pStream) { |
319 CPDF_Document* pDoc = m_pPageView->GetPDFDocument(); | 320 CPDF_Document* pDoc = m_pPageView->GetPDFDocument(); |
320 pStream = pDoc->NewIndirect<CPDF_Stream>(); | 321 pStream = pDoc->NewIndirect<CPDF_Stream>(); |
321 pParentDict->SetNewFor<CPDF_Reference>(sAPType, pDoc, pStream->GetObjNum()); | 322 pParentDict->SetNewFor<CPDF_Reference>(sAPType, pDoc, pStream->GetObjNum()); |
322 } | 323 } |
323 | 324 |
324 CPDF_Dictionary* pStreamDict = pStream->GetDict(); | 325 CPDF_Dictionary* pStreamDict = pStream->GetDict(); |
325 if (!pStreamDict) { | 326 if (!pStreamDict) { |
326 pStreamDict = | 327 auto pNewDict = pdfium::MakeUnique<CPDF_Dictionary>( |
327 new CPDF_Dictionary(m_pAnnot->GetDocument()->GetByteStringPool()); | 328 m_pAnnot->GetDocument()->GetByteStringPool()); |
| 329 pStreamDict = pNewDict.get(); |
328 pStreamDict->SetNewFor<CPDF_Name>("Type", "XObject"); | 330 pStreamDict->SetNewFor<CPDF_Name>("Type", "XObject"); |
329 pStreamDict->SetNewFor<CPDF_Name>("Subtype", "Form"); | 331 pStreamDict->SetNewFor<CPDF_Name>("Subtype", "Form"); |
330 pStreamDict->SetNewFor<CPDF_Number>("FormType", 1); | 332 pStreamDict->SetNewFor<CPDF_Number>("FormType", 1); |
331 pStream->InitStream(nullptr, 0, pStreamDict); | 333 pStream->InitStream(nullptr, 0, std::move(pNewDict)); |
332 } | 334 } |
333 | 335 pStreamDict->SetMatrixFor("Matrix", matrix); |
334 if (pStreamDict) { | 336 pStreamDict->SetRectFor("BBox", rcBBox); |
335 pStreamDict->SetMatrixFor("Matrix", matrix); | |
336 pStreamDict->SetRectFor("BBox", rcBBox); | |
337 } | |
338 | |
339 pStream->SetData((uint8_t*)sContents.c_str(), sContents.GetLength()); | 337 pStream->SetData((uint8_t*)sContents.c_str(), sContents.GetLength()); |
340 } | 338 } |
341 | 339 |
342 bool CPDFSDK_BAAnnot::IsVisible() const { | 340 bool CPDFSDK_BAAnnot::IsVisible() const { |
343 uint32_t nFlags = GetFlags(); | 341 uint32_t nFlags = GetFlags(); |
344 return !((nFlags & ANNOTFLAG_INVISIBLE) || (nFlags & ANNOTFLAG_HIDDEN) || | 342 return !((nFlags & ANNOTFLAG_INVISIBLE) || (nFlags & ANNOTFLAG_HIDDEN) || |
345 (nFlags & ANNOTFLAG_NOVIEW)); | 343 (nFlags & ANNOTFLAG_NOVIEW)); |
346 } | 344 } |
347 | 345 |
348 CPDF_Action CPDFSDK_BAAnnot::GetAction() const { | 346 CPDF_Action CPDFSDK_BAAnnot::GetAction() const { |
(...skipping 44 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
393 CPDF_RenderOptions* pOptions) { | 391 CPDF_RenderOptions* pOptions) { |
394 m_pAnnot->GetAPForm(m_pPageView->GetPDFPage(), CPDF_Annot::Normal); | 392 m_pAnnot->GetAPForm(m_pPageView->GetPDFPage(), CPDF_Annot::Normal); |
395 m_pAnnot->DrawAppearance(m_pPageView->GetPDFPage(), pDevice, pUser2Device, | 393 m_pAnnot->DrawAppearance(m_pPageView->GetPDFPage(), pDevice, pUser2Device, |
396 CPDF_Annot::Normal, nullptr); | 394 CPDF_Annot::Normal, nullptr); |
397 } | 395 } |
398 | 396 |
399 void CPDFSDK_BAAnnot::SetOpenState(bool bOpenState) { | 397 void CPDFSDK_BAAnnot::SetOpenState(bool bOpenState) { |
400 if (CPDF_Annot* pAnnot = m_pAnnot->GetPopupAnnot()) | 398 if (CPDF_Annot* pAnnot = m_pAnnot->GetPopupAnnot()) |
401 pAnnot->SetOpenState(bOpenState); | 399 pAnnot->SetOpenState(bOpenState); |
402 } | 400 } |
OLD | NEW |