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 "../../include/fpdfdoc/fpdf_doc.h" | 7 #include "../../include/fpdfdoc/fpdf_doc.h" |
8 | 8 |
9 CPDF_LinkList::~CPDF_LinkList() | 9 CPDF_LinkList::~CPDF_LinkList() { |
10 { | 10 FX_POSITION pos = m_PageMap.GetStartPosition(); |
11 FX_POSITION pos = m_PageMap.GetStartPosition(); | 11 while (pos) { |
12 while (pos) { | 12 void* key; |
13 void* key; | 13 void* value; |
14 void* value; | 14 m_PageMap.GetNextAssoc(pos, key, value); |
15 m_PageMap.GetNextAssoc(pos, key, value); | 15 delete (CFX_PtrArray*)value; |
16 delete (CFX_PtrArray*)value; | 16 } |
| 17 } |
| 18 CFX_PtrArray* CPDF_LinkList::GetPageLinks(CPDF_Page* pPage) { |
| 19 FX_DWORD objnum = pPage->m_pFormDict->GetObjNum(); |
| 20 if (objnum == 0) { |
| 21 return NULL; |
| 22 } |
| 23 CFX_PtrArray* pPageLinkList = NULL; |
| 24 if (!m_PageMap.Lookup((void*)(uintptr_t)objnum, (void*&)pPageLinkList)) { |
| 25 pPageLinkList = new CFX_PtrArray; |
| 26 m_PageMap.SetAt((void*)(uintptr_t)objnum, pPageLinkList); |
| 27 LoadPageLinks(pPage, pPageLinkList); |
| 28 } |
| 29 return pPageLinkList; |
| 30 } |
| 31 int CPDF_LinkList::CountLinks(CPDF_Page* pPage) { |
| 32 CFX_PtrArray* pPageLinkList = GetPageLinks(pPage); |
| 33 if (pPageLinkList == NULL) { |
| 34 return 0; |
| 35 } |
| 36 return pPageLinkList->GetSize(); |
| 37 } |
| 38 CPDF_Link CPDF_LinkList::GetLink(CPDF_Page* pPage, int index) { |
| 39 CFX_PtrArray* pPageLinkList = GetPageLinks(pPage); |
| 40 if (!pPageLinkList) { |
| 41 return CPDF_Link(); |
| 42 } |
| 43 return CPDF_Link((CPDF_Dictionary*)pPageLinkList->GetAt(index)); |
| 44 } |
| 45 CPDF_Link CPDF_LinkList::GetLinkAtPoint(CPDF_Page* pPage, |
| 46 FX_FLOAT pdf_x, |
| 47 FX_FLOAT pdf_y) { |
| 48 CFX_PtrArray* pPageLinkList = GetPageLinks(pPage); |
| 49 if (!pPageLinkList) { |
| 50 return CPDF_Link(); |
| 51 } |
| 52 int size = pPageLinkList->GetSize(); |
| 53 for (int i = size - 1; i >= 0; --i) { |
| 54 CPDF_Link link((CPDF_Dictionary*)pPageLinkList->GetAt(i)); |
| 55 CPDF_Rect rect = link.GetRect(); |
| 56 if (rect.Contains(pdf_x, pdf_y)) { |
| 57 return link; |
17 } | 58 } |
| 59 } |
| 60 return CPDF_Link(); |
18 } | 61 } |
19 CFX_PtrArray* CPDF_LinkList::GetPageLinks(CPDF_Page* pPage) | 62 void CPDF_LinkList::LoadPageLinks(CPDF_Page* pPage, CFX_PtrArray* pList) { |
20 { | 63 CPDF_Array* pAnnotList = pPage->m_pFormDict->GetArray("Annots"); |
21 FX_DWORD objnum = pPage->m_pFormDict->GetObjNum(); | 64 if (pAnnotList == NULL) { |
22 if (objnum == 0) { | 65 return; |
23 return NULL; | 66 } |
| 67 for (FX_DWORD i = 0; i < pAnnotList->GetCount(); i++) { |
| 68 CPDF_Dictionary* pAnnot = pAnnotList->GetDict(i); |
| 69 if (pAnnot == NULL) { |
| 70 continue; |
24 } | 71 } |
25 CFX_PtrArray* pPageLinkList = NULL; | 72 if (pAnnot->GetString("Subtype") != "Link") { |
26 if (!m_PageMap.Lookup((void*)(uintptr_t)objnum, (void*&)pPageLinkList)) { | 73 continue; |
27 pPageLinkList = new CFX_PtrArray; | |
28 m_PageMap.SetAt((void*)(uintptr_t)objnum, pPageLinkList); | |
29 LoadPageLinks(pPage, pPageLinkList); | |
30 } | 74 } |
31 return pPageLinkList; | 75 pList->Add(pAnnot); |
| 76 } |
32 } | 77 } |
33 int CPDF_LinkList::CountLinks(CPDF_Page* pPage) | 78 CPDF_Rect CPDF_Link::GetRect() { |
34 { | 79 return m_pDict->GetRect("Rect"); |
35 CFX_PtrArray* pPageLinkList = GetPageLinks(pPage); | |
36 if (pPageLinkList == NULL) { | |
37 return 0; | |
38 } | |
39 return pPageLinkList->GetSize(); | |
40 } | 80 } |
41 CPDF_Link CPDF_LinkList::GetLink(CPDF_Page* pPage, int index) | 81 CPDF_Dest CPDF_Link::GetDest(CPDF_Document* pDoc) { |
42 { | 82 CPDF_Object* pDest = m_pDict->GetElementValue("Dest"); |
43 CFX_PtrArray* pPageLinkList = GetPageLinks(pPage); | 83 if (pDest == NULL) { |
44 if (!pPageLinkList) { | 84 return CPDF_Dest(); |
45 return CPDF_Link(); | 85 } |
46 } | 86 if (pDest->GetType() == PDFOBJ_STRING || pDest->GetType() == PDFOBJ_NAME) { |
47 return CPDF_Link((CPDF_Dictionary*)pPageLinkList->GetAt(index)); | 87 CPDF_NameTree name_tree(pDoc, FX_BSTRC("Dests")); |
| 88 CFX_ByteStringC name = pDest->GetString(); |
| 89 return CPDF_Dest(name_tree.LookupNamedDest(pDoc, name)); |
| 90 } |
| 91 if (pDest->GetType() == PDFOBJ_ARRAY) { |
| 92 return CPDF_Dest((CPDF_Array*)pDest); |
| 93 } |
| 94 return CPDF_Dest(); |
48 } | 95 } |
49 CPDF_Link CPDF_LinkList::GetLinkAtPoint(CPDF_Page* pPage, FX_FLOAT pdf_x, FX_FLO
AT pdf_y) | 96 CPDF_Action CPDF_Link::GetAction() { |
50 { | 97 return CPDF_Action(m_pDict->GetDict("A")); |
51 CFX_PtrArray* pPageLinkList = GetPageLinks(pPage); | |
52 if (!pPageLinkList) { | |
53 return CPDF_Link(); | |
54 } | |
55 int size = pPageLinkList->GetSize(); | |
56 for (int i = size - 1; i >= 0; --i) { | |
57 CPDF_Link link((CPDF_Dictionary*)pPageLinkList->GetAt(i)); | |
58 CPDF_Rect rect = link.GetRect(); | |
59 if (rect.Contains(pdf_x, pdf_y)) { | |
60 return link; | |
61 } | |
62 } | |
63 return CPDF_Link(); | |
64 } | 98 } |
65 void CPDF_LinkList::LoadPageLinks(CPDF_Page* pPage, CFX_PtrArray* pList) | |
66 { | |
67 CPDF_Array* pAnnotList = pPage->m_pFormDict->GetArray("Annots"); | |
68 if (pAnnotList == NULL) { | |
69 return; | |
70 } | |
71 for (FX_DWORD i = 0; i < pAnnotList->GetCount(); i ++) { | |
72 CPDF_Dictionary* pAnnot = pAnnotList->GetDict(i); | |
73 if (pAnnot == NULL) { | |
74 continue; | |
75 } | |
76 if (pAnnot->GetString("Subtype") != "Link") { | |
77 continue; | |
78 } | |
79 pList->Add(pAnnot); | |
80 } | |
81 } | |
82 CPDF_Rect CPDF_Link::GetRect() | |
83 { | |
84 return m_pDict->GetRect("Rect"); | |
85 } | |
86 CPDF_Dest CPDF_Link::GetDest(CPDF_Document* pDoc) | |
87 { | |
88 CPDF_Object* pDest = m_pDict->GetElementValue("Dest"); | |
89 if (pDest == NULL) { | |
90 return CPDF_Dest(); | |
91 } | |
92 if (pDest->GetType() == PDFOBJ_STRING || pDest->GetType() == PDFOBJ_NAME) { | |
93 CPDF_NameTree name_tree(pDoc, FX_BSTRC("Dests")); | |
94 CFX_ByteStringC name = pDest->GetString(); | |
95 return CPDF_Dest(name_tree.LookupNamedDest(pDoc, name)); | |
96 } | |
97 if (pDest->GetType() == PDFOBJ_ARRAY) { | |
98 return CPDF_Dest((CPDF_Array*)pDest); | |
99 } | |
100 return CPDF_Dest(); | |
101 } | |
102 CPDF_Action CPDF_Link::GetAction() | |
103 { | |
104 return CPDF_Action(m_pDict->GetDict("A")); | |
105 } | |
OLD | NEW |