Home | History | Annotate | Download | only in fpdfdoc
      1 // Copyright 2014 PDFium Authors. All rights reserved.
      2 // Use of this source code is governed by a BSD-style license that can be
      3 // found in the LICENSE file.
      4 
      5 // Original code copyright 2014 Foxit Software Inc. http://www.foxitsoftware.com
      6 
      7 #include "../../include/fpdfdoc/fpdf_doc.h"
      8 CPDF_LinkList::~CPDF_LinkList()
      9 {
     10     FX_POSITION pos = m_PageMap.GetStartPosition();
     11     while (pos) {
     12         FX_LPVOID key, value;
     13         m_PageMap.GetNextAssoc(pos, key, value);
     14         delete (CFX_PtrArray*)value;
     15     }
     16 }
     17 CFX_PtrArray* CPDF_LinkList::GetPageLinks(CPDF_Page* pPage)
     18 {
     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((FX_LPVOID)(FX_UINTPTR)objnum, (FX_LPVOID&)pPageLinkList)) {
     25         pPageLinkList = FX_NEW CFX_PtrArray;
     26         if (pPageLinkList == NULL) {
     27             return NULL;
     28         }
     29         m_PageMap.SetAt((FX_LPVOID)(FX_UINTPTR)objnum, pPageLinkList);
     30         LoadPageLinks(pPage, pPageLinkList);
     31     }
     32     return pPageLinkList;
     33 }
     34 int CPDF_LinkList::CountLinks(CPDF_Page* pPage)
     35 {
     36     CFX_PtrArray* pPageLinkList = GetPageLinks(pPage);
     37     if (pPageLinkList == NULL) {
     38         return 0;
     39     }
     40     return pPageLinkList->GetSize();
     41 }
     42 CPDF_Link CPDF_LinkList::GetLink(CPDF_Page* pPage, int index)
     43 {
     44     CFX_PtrArray* pPageLinkList = GetPageLinks(pPage);
     45     if (pPageLinkList == NULL) {
     46         return NULL;
     47     }
     48     return (CPDF_Dictionary*)pPageLinkList->GetAt(index);
     49 }
     50 CPDF_Link CPDF_LinkList::GetLinkAtPoint(CPDF_Page* pPage, FX_FLOAT pdf_x, FX_FLOAT pdf_y)
     51 {
     52     CFX_PtrArray* pPageLinkList = GetPageLinks(pPage);
     53     if (pPageLinkList == NULL) {
     54         return NULL;
     55     }
     56     int size = pPageLinkList->GetSize();
     57     for (int i = 0; i < size; i ++) {
     58         CPDF_Link Link = (CPDF_Dictionary*)pPageLinkList->GetAt(i);
     59         CPDF_Rect rect = Link.GetRect();
     60         if (rect.Contains(pdf_x, pdf_y)) {
     61             return Link;
     62         }
     63     }
     64     return NULL;
     65 }
     66 void CPDF_LinkList::LoadPageLinks(CPDF_Page* pPage, CFX_PtrArray* pList)
     67 {
     68     CPDF_Array* pAnnotList = pPage->m_pFormDict->GetArray("Annots");
     69     if (pAnnotList == NULL) {
     70         return;
     71     }
     72     for (FX_DWORD i = 0; i < pAnnotList->GetCount(); i ++) {
     73         CPDF_Dictionary* pAnnot = pAnnotList->GetDict(i);
     74         if (pAnnot == NULL) {
     75             continue;
     76         }
     77         if (pAnnot->GetString("Subtype") != "Link") {
     78             continue;
     79         }
     80         pList->Add(pAnnot);
     81     }
     82 }
     83 CPDF_Rect CPDF_Link::GetRect()
     84 {
     85     return m_pDict->GetRect("Rect");
     86 }
     87 CPDF_Dest CPDF_Link::GetDest(CPDF_Document* pDoc)
     88 {
     89     CPDF_Object* pDest = m_pDict->GetElementValue("Dest");
     90     if (pDest == NULL) {
     91         return NULL;
     92     }
     93     if (pDest->GetType() == PDFOBJ_STRING || pDest->GetType() == PDFOBJ_NAME) {
     94         CPDF_NameTree name_tree(pDoc, FX_BSTRC("Dests"));
     95         CFX_ByteStringC name = pDest->GetString();
     96         return name_tree.LookupNamedDest(pDoc, name);
     97     } else if (pDest->GetType() == PDFOBJ_ARRAY) {
     98         return (CPDF_Array*)pDest;
     99     }
    100     return NULL;
    101 }
    102 CPDF_Action CPDF_Link::GetAction()
    103 {
    104     return m_pDict->GetDict("A");
    105 }
    106