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

Side by Side Diff: core/src/fpdfdoc/doc_bookmark.cpp

Issue 828203002: Clean up bookmark related codes. (Closed) Base URL: https://pdfium.googlesource.com/pdfium.git@master
Patch Set: Constructor Created 5 years, 11 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/include/fpdfdoc/fpdf_doc.h ('k') | fpdfsdk/src/fpdfdoc.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 2014 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 "../../include/fpdfdoc/fpdf_doc.h" 7 #include "../../include/fpdfdoc/fpdf_doc.h"
8 CPDF_Bookmark CPDF_BookmarkTree::GetFirstChild(CPDF_Bookmark Parent) 8 CPDF_Bookmark CPDF_BookmarkTree::GetFirstChild(const CPDF_Bookmark& parent) cons t
9 { 9 {
10 if (Parent.m_pDict == NULL) { 10 if (!parent.m_pDict) {
11 CPDF_Dictionary* pRoot = m_pDocument->GetRoot()->GetDict("Outlines"); 11 CPDF_Dictionary* pRoot = m_pDocument->GetRoot()->GetDict("Outlines");
12 if (pRoot == NULL) { 12 if (!pRoot) {
13 return NULL; 13 return CPDF_Bookmark();
14 } 14 }
15 return pRoot->GetDict("First"); 15 return CPDF_Bookmark(pRoot->GetDict("First"));
16 } 16 }
17 return Parent.m_pDict->GetDict("First"); 17 return CPDF_Bookmark(parent.m_pDict->GetDict("First"));
18 } 18 }
19 CPDF_Bookmark CPDF_BookmarkTree::GetNextSibling(CPDF_Bookmark This) 19 CPDF_Bookmark CPDF_BookmarkTree::GetNextSibling(const CPDF_Bookmark& bookmark) c onst
20 { 20 {
21 if (This.m_pDict == NULL) { 21 if (!bookmark.m_pDict) {
22 return NULL; 22 return CPDF_Bookmark();
23 } 23 }
24 CPDF_Dictionary *pNext = This.m_pDict->GetDict("Next"); 24 CPDF_Dictionary *pNext = bookmark.m_pDict->GetDict("Next");
25 return pNext == This.m_pDict ? NULL : pNext; 25 return pNext == bookmark.m_pDict ? CPDF_Bookmark() : CPDF_Bookmark(pNext);
26 } 26 }
27 FX_DWORD CPDF_Bookmark::GetColorRef() 27 FX_DWORD CPDF_Bookmark::GetColorRef() const
28 { 28 {
29 if (!m_pDict) { 29 if (!m_pDict) {
30 return 0; 30 return 0;
31 } 31 }
32 CPDF_Array* pColor = m_pDict->GetArray("C"); 32 CPDF_Array* pColor = m_pDict->GetArray("C");
33 if (pColor == NULL) { 33 if (!pColor) {
34 return FXSYS_RGB(0, 0, 0); 34 return FXSYS_RGB(0, 0, 0);
35 } 35 }
36 int r = FXSYS_round(pColor->GetNumber(0) * 255); 36 int r = FXSYS_round(pColor->GetNumber(0) * 255);
37 int g = FXSYS_round(pColor->GetNumber(1) * 255); 37 int g = FXSYS_round(pColor->GetNumber(1) * 255);
38 int b = FXSYS_round(pColor->GetNumber(2) * 255); 38 int b = FXSYS_round(pColor->GetNumber(2) * 255);
39 return FXSYS_RGB(r, g, b); 39 return FXSYS_RGB(r, g, b);
40 } 40 }
41 FX_DWORD CPDF_Bookmark::GetFontStyle() 41 FX_DWORD CPDF_Bookmark::GetFontStyle() const
42 { 42 {
43 if (!m_pDict) { 43 if (!m_pDict) {
44 return 0; 44 return 0;
45 } 45 }
46 return m_pDict->GetInteger("F"); 46 return m_pDict->GetInteger("F");
47 } 47 }
48 CFX_WideString CPDF_Bookmark::GetTitle() 48 CFX_WideString CPDF_Bookmark::GetTitle() const
49 { 49 {
50 if (!m_pDict) { 50 if (!m_pDict) {
51 return CFX_WideString(); 51 return CFX_WideString();
52 } 52 }
53 CPDF_String* pString = (CPDF_String*)m_pDict->GetElementValue("Title"); 53 CPDF_String* pString = (CPDF_String*)m_pDict->GetElementValue("Title");
54 if (pString == NULL || pString->GetType() != PDFOBJ_STRING) { 54 if (!pString || pString->GetType() != PDFOBJ_STRING) {
55 return CFX_WideString(); 55 return CFX_WideString();
56 } 56 }
57 CFX_WideString title = pString->GetUnicodeText(); 57 CFX_WideString title = pString->GetUnicodeText();
58 FX_LPWSTR buf = title.LockBuffer(); 58 FX_LPWSTR buf = title.LockBuffer();
59 int len = title.GetLength(), i; 59 int len = title.GetLength();
60 for (i = 0; i < len; i ++) 60 for (int i = 0; i < len; i++) {
61 if (buf[i] < 0x20) { 61 if (buf[i] < 0x20) {
62 buf[i] = 0x20; 62 buf[i] = 0x20;
63 } 63 }
64 }
64 title.ReleaseBuffer(len); 65 title.ReleaseBuffer(len);
65 return title; 66 return title;
66 } 67 }
67 CPDF_Dest CPDF_Bookmark::GetDest(CPDF_Document* pDocument) 68 CPDF_Dest CPDF_Bookmark::GetDest(CPDF_Document* pDocument) const
68 { 69 {
69 if (!m_pDict) { 70 if (!m_pDict) {
70 return NULL; 71 return NULL;
71 } 72 }
72 CPDF_Object* pDest = m_pDict->GetElementValue("Dest"); 73 CPDF_Object* pDest = m_pDict->GetElementValue("Dest");
73 if (pDest == NULL) { 74 if (!pDest) {
74 return NULL; 75 return NULL;
75 } 76 }
76 if (pDest->GetType() == PDFOBJ_STRING || pDest->GetType() == PDFOBJ_NAME) { 77 if (pDest->GetType() == PDFOBJ_STRING || pDest->GetType() == PDFOBJ_NAME) {
77 CPDF_NameTree name_tree(pDocument, FX_BSTRC("Dests")); 78 CPDF_NameTree name_tree(pDocument, FX_BSTRC("Dests"));
78 CFX_ByteStringC name = pDest->GetString(); 79 CFX_ByteStringC name = pDest->GetString();
79 return name_tree.LookupNamedDest(pDocument, name); 80 return name_tree.LookupNamedDest(pDocument, name);
80 } else if (pDest->GetType() == PDFOBJ_ARRAY) { 81 } else if (pDest->GetType() == PDFOBJ_ARRAY) {
81 return (CPDF_Array*)pDest; 82 return (CPDF_Array*)pDest;
82 } 83 }
83 return NULL; 84 return NULL;
84 } 85 }
85 CPDF_Action CPDF_Bookmark::GetAction() 86 CPDF_Action CPDF_Bookmark::GetAction() const
86 { 87 {
87 if (!m_pDict) { 88 if (!m_pDict) {
88 return NULL; 89 return NULL;
89 } 90 }
90 return m_pDict->GetDict("A"); 91 return m_pDict->GetDict("A");
91 } 92 }
OLDNEW
« no previous file with comments | « core/include/fpdfdoc/fpdf_doc.h ('k') | fpdfsdk/src/fpdfdoc.cpp » ('j') | no next file with comments »

Powered by Google App Engine
This is Rietveld 408576698