1 // Copyright 2016 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 "core/fpdfdoc/cpdf_link.h"
8 
9 #include "core/fpdfapi/parser/cpdf_array.h"
10 #include "core/fpdfdoc/cpdf_nametree.h"
11 
CPDF_Link()12 CPDF_Link::CPDF_Link() {}
13 
CPDF_Link(CPDF_Dictionary * pDict)14 CPDF_Link::CPDF_Link(CPDF_Dictionary* pDict) : m_pDict(pDict) {}
15 
16 CPDF_Link::CPDF_Link(const CPDF_Link& that) = default;
17 
~CPDF_Link()18 CPDF_Link::~CPDF_Link() {}
19 
GetRect()20 CFX_FloatRect CPDF_Link::GetRect() {
21   return m_pDict->GetRectFor("Rect");
22 }
23 
GetDest(CPDF_Document * pDoc)24 CPDF_Dest CPDF_Link::GetDest(CPDF_Document* pDoc) {
25   CPDF_Object* pDest = m_pDict->GetDirectObjectFor("Dest");
26   if (!pDest)
27     return CPDF_Dest();
28 
29   if (pDest->IsString() || pDest->IsName()) {
30     CPDF_NameTree name_tree(pDoc, "Dests");
31     return CPDF_Dest(name_tree.LookupNamedDest(pDoc, pDest->GetUnicodeText()));
32   }
33   if (CPDF_Array* pArray = pDest->AsArray())
34     return CPDF_Dest(pArray);
35   return CPDF_Dest();
36 }
37 
GetAction()38 CPDF_Action CPDF_Link::GetAction() {
39   return CPDF_Action(m_pDict->GetDictFor("A"));
40 }
41