OLD | NEW |
1 // Copyright 2016 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 "core/fpdfapi/fpdf_parser/include/cpdf_array.h" | 9 #include "core/fpdfapi/fpdf_parser/include/cpdf_array.h" |
10 #include "core/fpdfapi/fpdf_parser/include/cpdf_string.h" | 10 #include "core/fpdfapi/fpdf_parser/include/cpdf_string.h" |
11 #include "core/fpdfdoc/include/cpdf_nametree.h" | 11 #include "core/fpdfdoc/include/cpdf_nametree.h" |
12 #include "core/fxge/include/fx_dib.h" | 12 #include "core/fxge/include/fx_dib.h" |
13 | 13 |
14 uint32_t CPDF_Bookmark::GetColorRef() const { | 14 uint32_t CPDF_Bookmark::GetColorRef() const { |
15 if (!m_pDict) | 15 if (!m_pDict) |
16 return FXSYS_RGB(0, 0, 0); | 16 return FXSYS_RGB(0, 0, 0); |
17 | 17 |
18 CPDF_Array* pColor = m_pDict->GetArrayBy("C"); | 18 CPDF_Array* pColor = m_pDict->GetArrayFor("C"); |
19 if (!pColor) | 19 if (!pColor) |
20 return FXSYS_RGB(0, 0, 0); | 20 return FXSYS_RGB(0, 0, 0); |
21 | 21 |
22 int r = FXSYS_round(pColor->GetNumberAt(0) * 255); | 22 int r = FXSYS_round(pColor->GetNumberAt(0) * 255); |
23 int g = FXSYS_round(pColor->GetNumberAt(1) * 255); | 23 int g = FXSYS_round(pColor->GetNumberAt(1) * 255); |
24 int b = FXSYS_round(pColor->GetNumberAt(2) * 255); | 24 int b = FXSYS_round(pColor->GetNumberAt(2) * 255); |
25 return FXSYS_RGB(r, g, b); | 25 return FXSYS_RGB(r, g, b); |
26 } | 26 } |
27 | 27 |
28 uint32_t CPDF_Bookmark::GetFontStyle() const { | 28 uint32_t CPDF_Bookmark::GetFontStyle() const { |
29 return m_pDict ? m_pDict->GetIntegerBy("F") : 0; | 29 return m_pDict ? m_pDict->GetIntegerFor("F") : 0; |
30 } | 30 } |
31 | 31 |
32 CFX_WideString CPDF_Bookmark::GetTitle() const { | 32 CFX_WideString CPDF_Bookmark::GetTitle() const { |
33 if (!m_pDict) | 33 if (!m_pDict) |
34 return CFX_WideString(); | 34 return CFX_WideString(); |
35 | 35 |
36 CPDF_String* pString = ToString(m_pDict->GetDirectObjectBy("Title")); | 36 CPDF_String* pString = ToString(m_pDict->GetDirectObjectFor("Title")); |
37 if (!pString) | 37 if (!pString) |
38 return CFX_WideString(); | 38 return CFX_WideString(); |
39 | 39 |
40 CFX_WideString title = pString->GetUnicodeText(); | 40 CFX_WideString title = pString->GetUnicodeText(); |
41 int len = title.GetLength(); | 41 int len = title.GetLength(); |
42 if (!len) | 42 if (!len) |
43 return CFX_WideString(); | 43 return CFX_WideString(); |
44 | 44 |
45 std::unique_ptr<FX_WCHAR[]> buf(new FX_WCHAR[len]); | 45 std::unique_ptr<FX_WCHAR[]> buf(new FX_WCHAR[len]); |
46 for (int i = 0; i < len; i++) { | 46 for (int i = 0; i < len; i++) { |
47 FX_WCHAR w = title[i]; | 47 FX_WCHAR w = title[i]; |
48 buf[i] = w > 0x20 ? w : 0x20; | 48 buf[i] = w > 0x20 ? w : 0x20; |
49 } | 49 } |
50 return CFX_WideString(buf.get(), len); | 50 return CFX_WideString(buf.get(), len); |
51 } | 51 } |
52 | 52 |
53 CPDF_Dest CPDF_Bookmark::GetDest(CPDF_Document* pDocument) const { | 53 CPDF_Dest CPDF_Bookmark::GetDest(CPDF_Document* pDocument) const { |
54 if (!m_pDict) | 54 if (!m_pDict) |
55 return CPDF_Dest(); | 55 return CPDF_Dest(); |
56 | 56 |
57 CPDF_Object* pDest = m_pDict->GetDirectObjectBy("Dest"); | 57 CPDF_Object* pDest = m_pDict->GetDirectObjectFor("Dest"); |
58 if (!pDest) | 58 if (!pDest) |
59 return CPDF_Dest(); | 59 return CPDF_Dest(); |
60 if (pDest->IsString() || pDest->IsName()) { | 60 if (pDest->IsString() || pDest->IsName()) { |
61 CPDF_NameTree name_tree(pDocument, "Dests"); | 61 CPDF_NameTree name_tree(pDocument, "Dests"); |
62 return CPDF_Dest(name_tree.LookupNamedDest(pDocument, pDest->GetString())); | 62 return CPDF_Dest(name_tree.LookupNamedDest(pDocument, pDest->GetString())); |
63 } | 63 } |
64 if (CPDF_Array* pArray = pDest->AsArray()) | 64 if (CPDF_Array* pArray = pDest->AsArray()) |
65 return CPDF_Dest(pArray); | 65 return CPDF_Dest(pArray); |
66 return CPDF_Dest(); | 66 return CPDF_Dest(); |
67 } | 67 } |
68 | 68 |
69 CPDF_Action CPDF_Bookmark::GetAction() const { | 69 CPDF_Action CPDF_Bookmark::GetAction() const { |
70 return m_pDict ? CPDF_Action(m_pDict->GetDictBy("A")) : CPDF_Action(); | 70 return m_pDict ? CPDF_Action(m_pDict->GetDictFor("A")) : CPDF_Action(); |
71 } | 71 } |
OLD | NEW |