• Home
  • Line#
  • Scopes#
  • Navigate#
  • Raw
  • Download
1 // Copyright 2016 The PDFium Authors
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_bookmark.h"
8 
9 #include <algorithm>
10 #include <utility>
11 
12 #include "core/fpdfapi/parser/cpdf_array.h"
13 #include "core/fpdfapi/parser/cpdf_dictionary.h"
14 #include "core/fpdfapi/parser/cpdf_string.h"
15 #include "core/fxge/dib/fx_dib.h"
16 
17 CPDF_Bookmark::CPDF_Bookmark() = default;
18 
19 CPDF_Bookmark::CPDF_Bookmark(const CPDF_Bookmark& that) = default;
20 
CPDF_Bookmark(RetainPtr<const CPDF_Dictionary> pDict)21 CPDF_Bookmark::CPDF_Bookmark(RetainPtr<const CPDF_Dictionary> pDict)
22     : m_pDict(std::move(pDict)) {}
23 
24 CPDF_Bookmark::~CPDF_Bookmark() = default;
25 
GetTitle() const26 WideString CPDF_Bookmark::GetTitle() const {
27   if (!m_pDict) {
28     return WideString();
29   }
30   RetainPtr<const CPDF_String> pString =
31       ToString(m_pDict->GetDirectObjectFor("Title"));
32   if (!pString) {
33     return WideString();
34   }
35   WideString title = pString->GetUnicodeText();
36   WideString result;
37   result.Reserve(title.GetLength());
38   for (const wchar_t wc : title) {
39     result += std::max(wc, static_cast<wchar_t>(0x20));
40   }
41   return result;
42 }
43 
GetDest(CPDF_Document * pDocument) const44 CPDF_Dest CPDF_Bookmark::GetDest(CPDF_Document* pDocument) const {
45   if (!m_pDict)
46     return CPDF_Dest(nullptr);
47   return CPDF_Dest::Create(pDocument, m_pDict->GetDirectObjectFor("Dest"));
48 }
49 
GetAction() const50 CPDF_Action CPDF_Bookmark::GetAction() const {
51   return CPDF_Action(m_pDict ? m_pDict->GetDictFor("A") : nullptr);
52 }
53 
GetCount() const54 int CPDF_Bookmark::GetCount() const {
55   return m_pDict->GetIntegerFor("Count");
56 }
57