• Home
  • Line#
  • Scopes#
  • Navigate#
  • Raw
  • Download
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 <vector>
8 
9 #include "../../../third_party/base/nonstd_unique_ptr.h"
10 #include "../../include/fpdfdoc/fpdf_doc.h"
11 
GetFirstChild(const CPDF_Bookmark & parent) const12 CPDF_Bookmark CPDF_BookmarkTree::GetFirstChild(const CPDF_Bookmark& parent) const
13 {
14     if (!parent.m_pDict) {
15         CPDF_Dictionary* pRoot = m_pDocument->GetRoot()->GetDict("Outlines");
16         if (!pRoot) {
17             return CPDF_Bookmark();
18         }
19         return CPDF_Bookmark(pRoot->GetDict("First"));
20     }
21     return CPDF_Bookmark(parent.m_pDict->GetDict("First"));
22 }
GetNextSibling(const CPDF_Bookmark & bookmark) const23 CPDF_Bookmark CPDF_BookmarkTree::GetNextSibling(const CPDF_Bookmark& bookmark) const
24 {
25     if (!bookmark.m_pDict) {
26         return CPDF_Bookmark();
27     }
28     CPDF_Dictionary *pNext = bookmark.m_pDict->GetDict("Next");
29     return pNext == bookmark.m_pDict ? CPDF_Bookmark() : CPDF_Bookmark(pNext);
30 }
GetColorRef() const31 FX_DWORD CPDF_Bookmark::GetColorRef() const
32 {
33     if (!m_pDict) {
34         return 0;
35     }
36     CPDF_Array* pColor = m_pDict->GetArray("C");
37     if (!pColor) {
38         return FXSYS_RGB(0, 0, 0);
39     }
40     int r = FXSYS_round(pColor->GetNumber(0) * 255);
41     int g = FXSYS_round(pColor->GetNumber(1) * 255);
42     int b = FXSYS_round(pColor->GetNumber(2) * 255);
43     return FXSYS_RGB(r, g, b);
44 }
GetFontStyle() const45 FX_DWORD CPDF_Bookmark::GetFontStyle() const
46 {
47     if (!m_pDict) {
48         return 0;
49     }
50     return m_pDict->GetInteger("F");
51 }
GetTitle() const52 CFX_WideString CPDF_Bookmark::GetTitle() const
53 {
54     if (!m_pDict) {
55         return CFX_WideString();
56     }
57     CPDF_String* pString = (CPDF_String*)m_pDict->GetElementValue("Title");
58     if (!pString || pString->GetType() != PDFOBJ_STRING) {
59         return CFX_WideString();
60     }
61     CFX_WideString title = pString->GetUnicodeText();
62     int len = title.GetLength();
63     if (!len) {
64         return CFX_WideString();
65     }
66     nonstd::unique_ptr<FX_WCHAR[]> buf(new FX_WCHAR[len]);
67     for (int i = 0; i < len; i++) {
68         FX_WCHAR w = title[i];
69         buf[i] = w > 0x20 ? w : 0x20;
70     }
71     return CFX_WideString(buf.get(), len);
72 }
GetDest(CPDF_Document * pDocument) const73 CPDF_Dest CPDF_Bookmark::GetDest(CPDF_Document* pDocument) const
74 {
75     if (!m_pDict) {
76         return CPDF_Dest();
77     }
78     CPDF_Object* pDest = m_pDict->GetElementValue("Dest");
79     if (!pDest) {
80         return CPDF_Dest();
81     }
82     if (pDest->GetType() == PDFOBJ_STRING || pDest->GetType() == PDFOBJ_NAME) {
83         CPDF_NameTree name_tree(pDocument, FX_BSTRC("Dests"));
84         CFX_ByteStringC name = pDest->GetString();
85         return CPDF_Dest(name_tree.LookupNamedDest(pDocument, name));
86     }
87     if (pDest->GetType() == PDFOBJ_ARRAY) {
88         return CPDF_Dest((CPDF_Array*)pDest);
89     }
90     return CPDF_Dest();
91 }
GetAction() const92 CPDF_Action CPDF_Bookmark::GetAction() const
93 {
94     if (!m_pDict) {
95         return CPDF_Action();
96     }
97     return CPDF_Action(m_pDict->GetDict("A"));
98 }
99