Chromium Code Reviews
chromiumcodereview-hr@appspot.gserviceaccount.com (chromiumcodereview-hr) | Please choose your nickname with Settings | Help | Chromium Project | Gerrit Changes | Sign out
(219)

Side by Side Diff: core/fpdfdoc/cpdf_bookmark.cpp

Issue 2192823002: Splitting fpdfdoc/doc_* part I (Closed) Base URL: https://pdfium.googlesource.com/pdfium.git@fpdf_doc_II
Patch Set: Stddef not stdint Created 4 years, 4 months ago
Use n/p to move between diff chunks; N/P to move between comments. Draft comments are only viewable by you.
Jump to:
View unified diff | Download patch
« no previous file with comments | « core/fpdfdoc/cpdf_actionfields.cpp ('k') | core/fpdfdoc/cpdf_bookmarktree.cpp » ('j') | no next file with comments »
Toggle Intra-line Diffs ('i') | Expand Comments ('e') | Collapse Comments ('c') | Show Comments Hide Comments ('s')
OLDNEW
1 // Copyright 2014 PDFium Authors. All rights reserved. 1 // Copyright 2016 PDFium Authors. All rights reserved.
2 // Use of this source code is governed by a BSD-style license that can be 2 // Use of this source code is governed by a BSD-style license that can be
3 // found in the LICENSE file. 3 // found in the LICENSE file.
4 4
5 // Original code copyright 2014 Foxit Software Inc. http://www.foxitsoftware.com 5 // Original code copyright 2014 Foxit Software Inc. http://www.foxitsoftware.com
6 6
7 #include "core/fpdfdoc/include/cpdf_bookmark.h" 7 #include "core/fpdfdoc/include/cpdf_bookmark.h"
8 8
9 #include <memory>
10 #include <vector>
11
12 #include "core/fpdfapi/fpdf_parser/include/cpdf_array.h" 9 #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" 10 #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" 11 #include "core/fpdfdoc/include/cpdf_nametree.h"
17 #include "core/fxge/include/fx_dib.h" 12 #include "core/fxge/include/fx_dib.h"
18 13
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 { 14 uint32_t CPDF_Bookmark::GetColorRef() const {
47 if (!m_pDict) 15 if (!m_pDict)
48 return FXSYS_RGB(0, 0, 0); 16 return FXSYS_RGB(0, 0, 0);
49 17
50 CPDF_Array* pColor = m_pDict->GetArrayBy("C"); 18 CPDF_Array* pColor = m_pDict->GetArrayBy("C");
51 if (!pColor) 19 if (!pColor)
52 return FXSYS_RGB(0, 0, 0); 20 return FXSYS_RGB(0, 0, 0);
53 21
54 int r = FXSYS_round(pColor->GetNumberAt(0) * 255); 22 int r = FXSYS_round(pColor->GetNumberAt(0) * 255);
55 int g = FXSYS_round(pColor->GetNumberAt(1) * 255); 23 int g = FXSYS_round(pColor->GetNumberAt(1) * 255);
56 int b = FXSYS_round(pColor->GetNumberAt(2) * 255); 24 int b = FXSYS_round(pColor->GetNumberAt(2) * 255);
57 return FXSYS_RGB(r, g, b); 25 return FXSYS_RGB(r, g, b);
58 } 26 }
59 27
60 uint32_t CPDF_Bookmark::GetFontStyle() const { 28 uint32_t CPDF_Bookmark::GetFontStyle() const {
61 return m_pDict ? m_pDict->GetIntegerBy("F") : 0; 29 return m_pDict ? m_pDict->GetIntegerBy("F") : 0;
62 } 30 }
63 31
64 CFX_WideString CPDF_Bookmark::GetTitle() const { 32 CFX_WideString CPDF_Bookmark::GetTitle() const {
65 if (!m_pDict) { 33 if (!m_pDict)
66 return CFX_WideString(); 34 return CFX_WideString();
67 } 35
68 CPDF_String* pString = ToString(m_pDict->GetDirectObjectBy("Title")); 36 CPDF_String* pString = ToString(m_pDict->GetDirectObjectBy("Title"));
69 if (!pString) 37 if (!pString)
70 return CFX_WideString(); 38 return CFX_WideString();
71 39
72 CFX_WideString title = pString->GetUnicodeText(); 40 CFX_WideString title = pString->GetUnicodeText();
73 int len = title.GetLength(); 41 int len = title.GetLength();
74 if (!len) { 42 if (!len)
75 return CFX_WideString(); 43 return CFX_WideString();
76 } 44
77 std::unique_ptr<FX_WCHAR[]> buf(new FX_WCHAR[len]); 45 std::unique_ptr<FX_WCHAR[]> buf(new FX_WCHAR[len]);
78 for (int i = 0; i < len; i++) { 46 for (int i = 0; i < len; i++) {
79 FX_WCHAR w = title[i]; 47 FX_WCHAR w = title[i];
80 buf[i] = w > 0x20 ? w : 0x20; 48 buf[i] = w > 0x20 ? w : 0x20;
81 } 49 }
82 return CFX_WideString(buf.get(), len); 50 return CFX_WideString(buf.get(), len);
83 } 51 }
52
84 CPDF_Dest CPDF_Bookmark::GetDest(CPDF_Document* pDocument) const { 53 CPDF_Dest CPDF_Bookmark::GetDest(CPDF_Document* pDocument) const {
85 if (!m_pDict) 54 if (!m_pDict)
86 return CPDF_Dest(); 55 return CPDF_Dest();
87 56
88 CPDF_Object* pDest = m_pDict->GetDirectObjectBy("Dest"); 57 CPDF_Object* pDest = m_pDict->GetDirectObjectBy("Dest");
89 if (!pDest) 58 if (!pDest)
90 return CPDF_Dest(); 59 return CPDF_Dest();
91 if (pDest->IsString() || pDest->IsName()) { 60 if (pDest->IsString() || pDest->IsName()) {
92 CPDF_NameTree name_tree(pDocument, "Dests"); 61 CPDF_NameTree name_tree(pDocument, "Dests");
93 return CPDF_Dest(name_tree.LookupNamedDest(pDocument, pDest->GetString())); 62 return CPDF_Dest(name_tree.LookupNamedDest(pDocument, pDest->GetString()));
94 } 63 }
95 if (CPDF_Array* pArray = pDest->AsArray()) 64 if (CPDF_Array* pArray = pDest->AsArray())
96 return CPDF_Dest(pArray); 65 return CPDF_Dest(pArray);
97 return CPDF_Dest(); 66 return CPDF_Dest();
98 } 67 }
68
99 CPDF_Action CPDF_Bookmark::GetAction() const { 69 CPDF_Action CPDF_Bookmark::GetAction() const {
100 if (!m_pDict) { 70 return m_pDict ? CPDF_Action(m_pDict->GetDictBy("A")) : CPDF_Action();
101 return CPDF_Action();
102 }
103 return CPDF_Action(m_pDict->GetDictBy("A"));
104 } 71 }
OLDNEW
« no previous file with comments | « core/fpdfdoc/cpdf_actionfields.cpp ('k') | core/fpdfdoc/cpdf_bookmarktree.cpp » ('j') | no next file with comments »

Powered by Google App Engine
This is Rietveld 408576698