| OLD | NEW |
| (Empty) |
| 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 "core/fpdfdoc/include/cpdf_bookmark.h" | |
| 8 | |
| 9 #include <memory> | |
| 10 #include <vector> | |
| 11 | |
| 12 #include "core/fpdfapi/fpdf_parser/include/cpdf_array.h" | |
| 13 #include "core/fpdfapi/fpdf_parser/include/cpdf_document.h" | |
| 14 #include "core/fpdfapi/fpdf_parser/include/cpdf_string.h" | |
| 15 #include "core/fpdfdoc/include/cpdf_bookmarktree.h" | |
| 16 #include "core/fpdfdoc/include/cpdf_nametree.h" | |
| 17 #include "core/fxge/include/fx_dib.h" | |
| 18 | |
| 19 CPDF_Bookmark CPDF_BookmarkTree::GetFirstChild( | |
| 20 const CPDF_Bookmark& parent) const { | |
| 21 CPDF_Dictionary* pParentDict = parent.GetDict(); | |
| 22 if (pParentDict) | |
| 23 return CPDF_Bookmark(pParentDict->GetDictBy("First")); | |
| 24 | |
| 25 CPDF_Dictionary* pRoot = m_pDocument->GetRoot(); | |
| 26 if (!pRoot) | |
| 27 return CPDF_Bookmark(); | |
| 28 | |
| 29 CPDF_Dictionary* pOutlines = pRoot->GetDictBy("Outlines"); | |
| 30 if (!pOutlines) | |
| 31 return CPDF_Bookmark(); | |
| 32 | |
| 33 return CPDF_Bookmark(pOutlines->GetDictBy("First")); | |
| 34 } | |
| 35 | |
| 36 CPDF_Bookmark CPDF_BookmarkTree::GetNextSibling( | |
| 37 const CPDF_Bookmark& bookmark) const { | |
| 38 CPDF_Dictionary* pDict = bookmark.GetDict(); | |
| 39 if (!pDict) | |
| 40 return CPDF_Bookmark(); | |
| 41 | |
| 42 CPDF_Dictionary* pNext = pDict->GetDictBy("Next"); | |
| 43 return pNext == pDict ? CPDF_Bookmark() : CPDF_Bookmark(pNext); | |
| 44 } | |
| 45 | |
| 46 uint32_t CPDF_Bookmark::GetColorRef() const { | |
| 47 if (!m_pDict) | |
| 48 return FXSYS_RGB(0, 0, 0); | |
| 49 | |
| 50 CPDF_Array* pColor = m_pDict->GetArrayBy("C"); | |
| 51 if (!pColor) | |
| 52 return FXSYS_RGB(0, 0, 0); | |
| 53 | |
| 54 int r = FXSYS_round(pColor->GetNumberAt(0) * 255); | |
| 55 int g = FXSYS_round(pColor->GetNumberAt(1) * 255); | |
| 56 int b = FXSYS_round(pColor->GetNumberAt(2) * 255); | |
| 57 return FXSYS_RGB(r, g, b); | |
| 58 } | |
| 59 | |
| 60 uint32_t CPDF_Bookmark::GetFontStyle() const { | |
| 61 return m_pDict ? m_pDict->GetIntegerBy("F") : 0; | |
| 62 } | |
| 63 | |
| 64 CFX_WideString CPDF_Bookmark::GetTitle() const { | |
| 65 if (!m_pDict) { | |
| 66 return CFX_WideString(); | |
| 67 } | |
| 68 CPDF_String* pString = ToString(m_pDict->GetDirectObjectBy("Title")); | |
| 69 if (!pString) | |
| 70 return CFX_WideString(); | |
| 71 | |
| 72 CFX_WideString title = pString->GetUnicodeText(); | |
| 73 int len = title.GetLength(); | |
| 74 if (!len) { | |
| 75 return CFX_WideString(); | |
| 76 } | |
| 77 std::unique_ptr<FX_WCHAR[]> buf(new FX_WCHAR[len]); | |
| 78 for (int i = 0; i < len; i++) { | |
| 79 FX_WCHAR w = title[i]; | |
| 80 buf[i] = w > 0x20 ? w : 0x20; | |
| 81 } | |
| 82 return CFX_WideString(buf.get(), len); | |
| 83 } | |
| 84 CPDF_Dest CPDF_Bookmark::GetDest(CPDF_Document* pDocument) const { | |
| 85 if (!m_pDict) | |
| 86 return CPDF_Dest(); | |
| 87 | |
| 88 CPDF_Object* pDest = m_pDict->GetDirectObjectBy("Dest"); | |
| 89 if (!pDest) | |
| 90 return CPDF_Dest(); | |
| 91 if (pDest->IsString() || pDest->IsName()) { | |
| 92 CPDF_NameTree name_tree(pDocument, "Dests"); | |
| 93 return CPDF_Dest(name_tree.LookupNamedDest(pDocument, pDest->GetString())); | |
| 94 } | |
| 95 if (CPDF_Array* pArray = pDest->AsArray()) | |
| 96 return CPDF_Dest(pArray); | |
| 97 return CPDF_Dest(); | |
| 98 } | |
| 99 CPDF_Action CPDF_Bookmark::GetAction() const { | |
| 100 if (!m_pDict) { | |
| 101 return CPDF_Action(); | |
| 102 } | |
| 103 return CPDF_Action(m_pDict->GetDictBy("A")); | |
| 104 } | |
| OLD | NEW |