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 "core/fpdfdoc/cpdf_annotlist.h" | 7 #include "core/fpdfdoc/cpdf_annotlist.h" |
8 | 8 |
9 #include <memory> | 9 #include <memory> |
10 #include <utility> | 10 #include <utility> |
11 | 11 |
12 #include "core/fpdfapi/page/cpdf_page.h" | 12 #include "core/fpdfapi/page/cpdf_page.h" |
13 #include "core/fpdfapi/parser/cpdf_document.h" | 13 #include "core/fpdfapi/parser/cpdf_document.h" |
| 14 #include "core/fpdfapi/parser/cpdf_name.h" |
| 15 #include "core/fpdfapi/parser/cpdf_number.h" |
14 #include "core/fpdfapi/parser/cpdf_reference.h" | 16 #include "core/fpdfapi/parser/cpdf_reference.h" |
| 17 #include "core/fpdfapi/parser/cpdf_string.h" |
15 #include "core/fpdfapi/render/cpdf_renderoptions.h" | 18 #include "core/fpdfapi/render/cpdf_renderoptions.h" |
16 #include "core/fpdfdoc/cpdf_annot.h" | 19 #include "core/fpdfdoc/cpdf_annot.h" |
17 #include "core/fpdfdoc/cpdf_interform.h" | 20 #include "core/fpdfdoc/cpdf_interform.h" |
18 #include "core/fpdfdoc/cpdf_occontext.h" | 21 #include "core/fpdfdoc/cpdf_occontext.h" |
19 #include "core/fpdfdoc/cpvt_generateap.h" | 22 #include "core/fpdfdoc/cpvt_generateap.h" |
20 #include "core/fxge/cfx_renderdevice.h" | 23 #include "core/fxge/cfx_renderdevice.h" |
21 #include "third_party/base/ptr_util.h" | 24 #include "third_party/base/ptr_util.h" |
22 | 25 |
23 namespace { | 26 namespace { |
24 | 27 |
25 std::unique_ptr<CPDF_Annot> CreatePopupAnnot(CPDF_Annot* pAnnot, | 28 std::unique_ptr<CPDF_Annot> CreatePopupAnnot(CPDF_Annot* pAnnot, |
26 CPDF_Document* pDocument) { | 29 CPDF_Document* pDocument) { |
27 CPDF_Dictionary* pParentDict = pAnnot->GetAnnotDict(); | 30 CPDF_Dictionary* pParentDict = pAnnot->GetAnnotDict(); |
28 if (!pParentDict) | 31 if (!pParentDict) |
29 return nullptr; | 32 return nullptr; |
30 | 33 |
31 // TODO(jaepark): We shouldn't strip BOM for some strings and not for others. | 34 // TODO(jaepark): We shouldn't strip BOM for some strings and not for others. |
32 // See pdfium:593. | 35 // See pdfium:593. |
33 CFX_WideString sContents = pParentDict->GetUnicodeTextFor("Contents"); | 36 CFX_WideString sContents = pParentDict->GetUnicodeTextFor("Contents"); |
34 if (sContents.IsEmpty()) | 37 if (sContents.IsEmpty()) |
35 return nullptr; | 38 return nullptr; |
36 | 39 |
37 auto pAnnotDict = | 40 auto pAnnotDict = |
38 pdfium::MakeUnique<CPDF_Dictionary>(pDocument->GetByteStringPool()); | 41 pdfium::MakeUnique<CPDF_Dictionary>(pDocument->GetByteStringPool()); |
39 pAnnotDict->SetNameFor("Type", "Annot"); | 42 pAnnotDict->SetNewFor<CPDF_Name>("Type", "Annot"); |
40 pAnnotDict->SetNameFor("Subtype", "Popup"); | 43 pAnnotDict->SetNewFor<CPDF_Name>("Subtype", "Popup"); |
41 pAnnotDict->SetStringFor("T", pParentDict->GetStringFor("T")); | 44 pAnnotDict->SetNewFor<CPDF_String>("T", pParentDict->GetStringFor("T"), |
42 pAnnotDict->SetStringFor("Contents", sContents.UTF8Encode()); | 45 false); |
| 46 pAnnotDict->SetNewFor<CPDF_String>("Contents", sContents.UTF8Encode(), false); |
43 | 47 |
44 CFX_FloatRect rect = pParentDict->GetRectFor("Rect"); | 48 CFX_FloatRect rect = pParentDict->GetRectFor("Rect"); |
45 rect.Normalize(); | 49 rect.Normalize(); |
46 CFX_FloatRect popupRect(0, 0, 200, 200); | 50 CFX_FloatRect popupRect(0, 0, 200, 200); |
47 popupRect.Translate(rect.left, rect.bottom - popupRect.Height()); | 51 popupRect.Translate(rect.left, rect.bottom - popupRect.Height()); |
48 | 52 |
49 pAnnotDict->SetRectFor("Rect", popupRect); | 53 pAnnotDict->SetRectFor("Rect", popupRect); |
50 pAnnotDict->SetIntegerFor("F", 0); | 54 pAnnotDict->SetNewFor<CPDF_Number>("F", 0); |
51 | 55 |
52 auto pPopupAnnot = | 56 auto pPopupAnnot = |
53 pdfium::MakeUnique<CPDF_Annot>(std::move(pAnnotDict), pDocument); | 57 pdfium::MakeUnique<CPDF_Annot>(std::move(pAnnotDict), pDocument); |
54 pAnnot->SetPopupAnnot(pPopupAnnot.get()); | 58 pAnnot->SetPopupAnnot(pPopupAnnot.get()); |
55 return pPopupAnnot; | 59 return pPopupAnnot; |
56 } | 60 } |
57 | 61 |
58 } // namespace | 62 } // namespace |
59 | 63 |
60 CPDF_AnnotList::CPDF_AnnotList(CPDF_Page* pPage) | 64 CPDF_AnnotList::CPDF_AnnotList(CPDF_Page* pPage) |
(...skipping 109 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
170 CPDF_RenderContext* pContext, | 174 CPDF_RenderContext* pContext, |
171 bool bPrinting, | 175 bool bPrinting, |
172 CFX_Matrix* pMatrix, | 176 CFX_Matrix* pMatrix, |
173 bool bShowWidget, | 177 bool bShowWidget, |
174 CPDF_RenderOptions* pOptions) { | 178 CPDF_RenderOptions* pOptions) { |
175 uint32_t dwAnnotFlags = bShowWidget ? ANNOTFLAG_INVISIBLE | ANNOTFLAG_HIDDEN | 179 uint32_t dwAnnotFlags = bShowWidget ? ANNOTFLAG_INVISIBLE | ANNOTFLAG_HIDDEN |
176 : ANNOTFLAG_INVISIBLE; | 180 : ANNOTFLAG_INVISIBLE; |
177 DisplayAnnots(pPage, nullptr, pContext, bPrinting, pMatrix, dwAnnotFlags, | 181 DisplayAnnots(pPage, nullptr, pContext, bPrinting, pMatrix, dwAnnotFlags, |
178 pOptions, nullptr); | 182 pOptions, nullptr); |
179 } | 183 } |
OLD | NEW |