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

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

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

Powered by Google App Engine
This is Rietveld 408576698