OLD | NEW |
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 const int nMaxRecursion = 32; | 8 const int nMaxRecursion = 32; |
9 int CPDF_Dest::GetPageIndex(CPDF_Document* pDoc) | 9 int CPDF_Dest::GetPageIndex(CPDF_Document* pDoc) { |
10 { | 10 if (m_pObj == NULL || m_pObj->GetType() != PDFOBJ_ARRAY) { |
11 if (m_pObj == NULL || m_pObj->GetType() != PDFOBJ_ARRAY) { | 11 return 0; |
12 return 0; | 12 } |
13 } | 13 CPDF_Object* pPage = ((CPDF_Array*)m_pObj)->GetElementValue(0); |
14 CPDF_Object* pPage = ((CPDF_Array*)m_pObj)->GetElementValue(0); | 14 if (pPage == NULL) { |
15 if (pPage == NULL) { | 15 return 0; |
16 return 0; | 16 } |
17 } | 17 if (pPage->GetType() == PDFOBJ_NUMBER) { |
18 if (pPage->GetType() == PDFOBJ_NUMBER) { | 18 return pPage->GetInteger(); |
19 return pPage->GetInteger(); | 19 } |
20 } | 20 if (pPage->GetType() != PDFOBJ_DICTIONARY) { |
21 if (pPage->GetType() != PDFOBJ_DICTIONARY) { | 21 return 0; |
22 return 0; | 22 } |
23 } | 23 return pDoc->GetPageIndex(pPage->GetObjNum()); |
24 return pDoc->GetPageIndex(pPage->GetObjNum()); | 24 } |
25 } | 25 FX_DWORD CPDF_Dest::GetPageObjNum() { |
26 FX_DWORD CPDF_Dest::GetPageObjNum() | 26 if (m_pObj == NULL || m_pObj->GetType() != PDFOBJ_ARRAY) { |
27 { | 27 return 0; |
28 if (m_pObj == NULL || m_pObj->GetType() != PDFOBJ_ARRAY) { | 28 } |
29 return 0; | 29 CPDF_Object* pPage = ((CPDF_Array*)m_pObj)->GetElementValue(0); |
30 } | 30 if (pPage == NULL) { |
31 CPDF_Object* pPage = ((CPDF_Array*)m_pObj)->GetElementValue(0); | 31 return 0; |
32 if (pPage == NULL) { | 32 } |
33 return 0; | 33 if (pPage->GetType() == PDFOBJ_NUMBER) { |
34 } | 34 return pPage->GetInteger(); |
35 if (pPage->GetType() == PDFOBJ_NUMBER) { | 35 } |
36 return pPage->GetInteger(); | 36 if (pPage->GetType() == PDFOBJ_DICTIONARY) { |
37 } | 37 return pPage->GetObjNum(); |
38 if (pPage->GetType() == PDFOBJ_DICTIONARY) { | 38 } |
39 return pPage->GetObjNum(); | 39 return 0; |
40 } | 40 } |
41 return 0; | 41 const FX_CHAR* g_sZoomModes[] = {"XYZ", "Fit", "FitH", "FitV", "FitR", |
42 } | 42 "FitB", "FitBH", "FitBV", ""}; |
43 const FX_CHAR* g_sZoomModes[] = {"XYZ", "Fit", "FitH", "FitV", "FitR", "FitB", "
FitBH", "FitBV", ""}; | 43 int CPDF_Dest::GetZoomMode() { |
44 int CPDF_Dest::GetZoomMode() | 44 if (m_pObj == NULL || m_pObj->GetType() != PDFOBJ_ARRAY) { |
45 { | 45 return 0; |
46 if (m_pObj == NULL || m_pObj->GetType() != PDFOBJ_ARRAY) { | 46 } |
47 return 0; | 47 CFX_ByteString mode; |
48 } | 48 CPDF_Object* pObj = ((CPDF_Array*)m_pObj)->GetElementValue(1); |
49 CFX_ByteString mode; | 49 mode = pObj ? pObj->GetString() : CFX_ByteString(); |
50 CPDF_Object* pObj = ((CPDF_Array*)m_pObj)->GetElementValue(1); | 50 int i = 0; |
51 mode = pObj ? pObj->GetString() : CFX_ByteString(); | 51 while (g_sZoomModes[i][0] != '\0') { |
52 int i = 0; | 52 if (mode == g_sZoomModes[i]) { |
53 while (g_sZoomModes[i][0] != '\0') { | 53 return i + 1; |
54 if (mode == g_sZoomModes[i]) { | 54 } |
55 return i + 1; | 55 i++; |
| 56 } |
| 57 return 0; |
| 58 } |
| 59 FX_FLOAT CPDF_Dest::GetParam(int index) { |
| 60 if (m_pObj == NULL || m_pObj->GetType() != PDFOBJ_ARRAY) { |
| 61 return 0; |
| 62 } |
| 63 return ((CPDF_Array*)m_pObj)->GetNumber(2 + index); |
| 64 } |
| 65 CFX_ByteString CPDF_Dest::GetRemoteName() { |
| 66 if (m_pObj == NULL) { |
| 67 return CFX_ByteString(); |
| 68 } |
| 69 return m_pObj->GetString(); |
| 70 } |
| 71 CPDF_NameTree::CPDF_NameTree(CPDF_Document* pDoc, |
| 72 const CFX_ByteStringC& category) { |
| 73 if (pDoc->GetRoot() && pDoc->GetRoot()->GetDict(FX_BSTRC("Names"))) |
| 74 m_pRoot = pDoc->GetRoot()->GetDict(FX_BSTRC("Names"))->GetDict(category); |
| 75 else |
| 76 m_pRoot = NULL; |
| 77 } |
| 78 static CPDF_Object* SearchNameNode(CPDF_Dictionary* pNode, |
| 79 const CFX_ByteString& csName, |
| 80 int& nIndex, |
| 81 CPDF_Array** ppFind, |
| 82 int nLevel = 0) { |
| 83 if (nLevel > nMaxRecursion) { |
| 84 return NULL; |
| 85 } |
| 86 CPDF_Array* pLimits = pNode->GetArray(FX_BSTRC("Limits")); |
| 87 if (pLimits != NULL) { |
| 88 CFX_ByteString csLeft = pLimits->GetString(0); |
| 89 CFX_ByteString csRight = pLimits->GetString(1); |
| 90 if (csLeft.Compare(csRight) > 0) { |
| 91 CFX_ByteString csTmp = csRight; |
| 92 csRight = csLeft; |
| 93 csLeft = csTmp; |
| 94 } |
| 95 if (csName.Compare(csLeft) < 0 || csName.Compare(csRight) > 0) { |
| 96 return NULL; |
| 97 } |
| 98 } |
| 99 CPDF_Array* pNames = pNode->GetArray(FX_BSTRC("Names")); |
| 100 if (pNames) { |
| 101 FX_DWORD dwCount = pNames->GetCount() / 2; |
| 102 for (FX_DWORD i = 0; i < dwCount; i++) { |
| 103 CFX_ByteString csValue = pNames->GetString(i * 2); |
| 104 int32_t iCompare = csValue.Compare(csName); |
| 105 if (iCompare <= 0) { |
| 106 if (ppFind != NULL) { |
| 107 *ppFind = pNames; |
56 } | 108 } |
57 i ++; | 109 if (iCompare < 0) { |
58 } | 110 continue; |
59 return 0; | |
60 } | |
61 FX_FLOAT CPDF_Dest::GetParam(int index) | |
62 { | |
63 if (m_pObj == NULL || m_pObj->GetType() != PDFOBJ_ARRAY) { | |
64 return 0; | |
65 } | |
66 return ((CPDF_Array*)m_pObj)->GetNumber(2 + index); | |
67 } | |
68 CFX_ByteString CPDF_Dest::GetRemoteName() | |
69 { | |
70 if (m_pObj == NULL) { | |
71 return CFX_ByteString(); | |
72 } | |
73 return m_pObj->GetString(); | |
74 } | |
75 CPDF_NameTree::CPDF_NameTree(CPDF_Document* pDoc, const CFX_ByteStringC& categor
y) | |
76 { | |
77 if (pDoc->GetRoot() && pDoc->GetRoot()->GetDict(FX_BSTRC("Names"))) | |
78 m_pRoot = pDoc->GetRoot()->GetDict(FX_BSTRC("Names"))->GetDict(category)
; | |
79 else | |
80 m_pRoot = NULL; | |
81 } | |
82 static CPDF_Object* SearchNameNode(CPDF_Dictionary* pNode, const CFX_ByteString&
csName, | |
83 int& nIndex, CPDF_Array** ppFind, int nLevel
= 0) | |
84 { | |
85 if (nLevel > nMaxRecursion) { | |
86 return NULL; | |
87 } | |
88 CPDF_Array* pLimits = pNode->GetArray(FX_BSTRC("Limits")); | |
89 if (pLimits != NULL) { | |
90 CFX_ByteString csLeft = pLimits->GetString(0); | |
91 CFX_ByteString csRight = pLimits->GetString(1); | |
92 if (csLeft.Compare(csRight) > 0) { | |
93 CFX_ByteString csTmp = csRight; | |
94 csRight = csLeft; | |
95 csLeft = csTmp; | |
96 } | 111 } |
97 if (csName.Compare(csLeft) < 0 || csName.Compare(csRight) > 0) { | 112 } else { |
98 return NULL; | 113 break; |
99 } | 114 } |
100 } | 115 nIndex += i; |
101 CPDF_Array* pNames = pNode->GetArray(FX_BSTRC("Names")); | 116 return pNames->GetElementValue(i * 2 + 1); |
102 if (pNames) { | 117 } |
103 FX_DWORD dwCount = pNames->GetCount() / 2; | 118 nIndex += dwCount; |
104 for (FX_DWORD i = 0; i < dwCount; i ++) { | 119 return NULL; |
105 CFX_ByteString csValue = pNames->GetString(i * 2); | 120 } |
106 int32_t iCompare = csValue.Compare(csName); | 121 CPDF_Array* pKids = pNode->GetArray(FX_BSTRC("Kids")); |
107 if (iCompare <= 0) { | 122 if (pKids == NULL) { |
108 if (ppFind != NULL) { | 123 return NULL; |
109 *ppFind = pNames; | 124 } |
110 } | 125 for (FX_DWORD i = 0; i < pKids->GetCount(); i++) { |
111 if (iCompare < 0) { | 126 CPDF_Dictionary* pKid = pKids->GetDict(i); |
112 continue; | 127 if (pKid == NULL) { |
113 } | 128 continue; |
114 } else { | 129 } |
115 break; | 130 CPDF_Object* pFound = |
116 } | 131 SearchNameNode(pKid, csName, nIndex, ppFind, nLevel + 1); |
117 nIndex += i; | 132 if (pFound) { |
118 return pNames->GetElementValue(i * 2 + 1); | 133 return pFound; |
119 } | 134 } |
120 nIndex += dwCount; | 135 } |
121 return NULL; | 136 return NULL; |
122 } | 137 } |
123 CPDF_Array* pKids = pNode->GetArray(FX_BSTRC("Kids")); | 138 static CPDF_Object* SearchNameNode(CPDF_Dictionary* pNode, |
124 if (pKids == NULL) { | 139 int nIndex, |
125 return NULL; | 140 int& nCurIndex, |
126 } | 141 CFX_ByteString& csName, |
127 for (FX_DWORD i = 0; i < pKids->GetCount(); i ++) { | 142 CPDF_Array** ppFind, |
128 CPDF_Dictionary* pKid = pKids->GetDict(i); | 143 int nLevel = 0) { |
129 if (pKid == NULL) { | 144 if (nLevel > nMaxRecursion) { |
130 continue; | 145 return NULL; |
131 } | 146 } |
132 CPDF_Object* pFound = SearchNameNode(pKid, csName, nIndex, ppFind, nLeve
l + 1); | 147 CPDF_Array* pNames = pNode->GetArray(FX_BSTRC("Names")); |
133 if (pFound) { | 148 if (pNames) { |
134 return pFound; | 149 int nCount = pNames->GetCount() / 2; |
135 } | 150 if (nIndex >= nCurIndex + nCount) { |
136 } | 151 nCurIndex += nCount; |
137 return NULL; | 152 return NULL; |
138 } | 153 } |
139 static CPDF_Object* SearchNameNode(CPDF_Dictionary* pNode, int nIndex, int& nCur
Index, | 154 if (ppFind != NULL) { |
140 CFX_ByteString& csName, CPDF_Array** ppFind,
int nLevel = 0) | 155 *ppFind = pNames; |
141 { | 156 } |
142 if (nLevel > nMaxRecursion) { | 157 csName = pNames->GetString((nIndex - nCurIndex) * 2); |
143 return NULL; | 158 return pNames->GetElementValue((nIndex - nCurIndex) * 2 + 1); |
144 } | 159 } |
145 CPDF_Array* pNames = pNode->GetArray(FX_BSTRC("Names")); | 160 CPDF_Array* pKids = pNode->GetArray(FX_BSTRC("Kids")); |
146 if (pNames) { | 161 if (pKids == NULL) { |
147 int nCount = pNames->GetCount() / 2; | 162 return NULL; |
148 if (nIndex >= nCurIndex + nCount) { | 163 } |
149 nCurIndex += nCount; | 164 for (FX_DWORD i = 0; i < pKids->GetCount(); i++) { |
150 return NULL; | 165 CPDF_Dictionary* pKid = pKids->GetDict(i); |
151 } | 166 if (pKid == NULL) { |
152 if (ppFind != NULL) { | 167 continue; |
153 *ppFind = pNames; | 168 } |
154 } | 169 CPDF_Object* pFound = |
155 csName = pNames->GetString((nIndex - nCurIndex) * 2); | 170 SearchNameNode(pKid, nIndex, nCurIndex, csName, ppFind, nLevel + 1); |
156 return pNames->GetElementValue((nIndex - nCurIndex) * 2 + 1); | 171 if (pFound) { |
157 } | 172 return pFound; |
158 CPDF_Array* pKids = pNode->GetArray(FX_BSTRC("Kids")); | 173 } |
159 if (pKids == NULL) { | 174 } |
160 return NULL; | 175 return NULL; |
161 } | 176 } |
162 for (FX_DWORD i = 0; i < pKids->GetCount(); i ++) { | 177 static int CountNames(CPDF_Dictionary* pNode, int nLevel = 0) { |
163 CPDF_Dictionary* pKid = pKids->GetDict(i); | 178 if (nLevel > nMaxRecursion) { |
164 if (pKid == NULL) { | 179 return 0; |
165 continue; | 180 } |
166 } | 181 CPDF_Array* pNames = pNode->GetArray(FX_BSTRC("Names")); |
167 CPDF_Object* pFound = SearchNameNode(pKid, nIndex, nCurIndex, csName, pp
Find, nLevel + 1); | 182 if (pNames) { |
168 if (pFound) { | 183 return pNames->GetCount() / 2; |
169 return pFound; | 184 } |
170 } | 185 CPDF_Array* pKids = pNode->GetArray(FX_BSTRC("Kids")); |
171 } | 186 if (pKids == NULL) { |
172 return NULL; | 187 return 0; |
173 } | 188 } |
174 static int CountNames(CPDF_Dictionary* pNode, int nLevel = 0) | 189 int nCount = 0; |
175 { | 190 for (FX_DWORD i = 0; i < pKids->GetCount(); i++) { |
176 if (nLevel > nMaxRecursion) { | 191 CPDF_Dictionary* pKid = pKids->GetDict(i); |
177 return 0; | 192 if (pKid == NULL) { |
178 } | 193 continue; |
179 CPDF_Array* pNames = pNode->GetArray(FX_BSTRC("Names")); | 194 } |
180 if (pNames) { | 195 nCount += CountNames(pKid, nLevel + 1); |
181 return pNames->GetCount() / 2; | 196 } |
182 } | 197 return nCount; |
183 CPDF_Array* pKids = pNode->GetArray(FX_BSTRC("Kids")); | 198 } |
184 if (pKids == NULL) { | 199 int CPDF_NameTree::GetCount() const { |
185 return 0; | 200 if (m_pRoot == NULL) { |
186 } | 201 return 0; |
187 int nCount = 0; | 202 } |
188 for (FX_DWORD i = 0; i < pKids->GetCount(); i ++) { | 203 return ::CountNames(m_pRoot); |
189 CPDF_Dictionary* pKid = pKids->GetDict(i); | 204 } |
190 if (pKid == NULL) { | 205 int CPDF_NameTree::GetIndex(const CFX_ByteString& csName) const { |
191 continue; | 206 if (m_pRoot == NULL) { |
192 } | 207 return -1; |
193 nCount += CountNames(pKid, nLevel + 1); | 208 } |
194 } | 209 int nIndex = 0; |
195 return nCount; | 210 if (SearchNameNode(m_pRoot, csName, nIndex, NULL) == NULL) { |
196 } | 211 return -1; |
197 int CPDF_NameTree::GetCount() const | 212 } |
198 { | 213 return nIndex; |
199 if (m_pRoot == NULL) { | 214 } |
200 return 0; | 215 CPDF_Object* CPDF_NameTree::LookupValue(int nIndex, |
201 } | 216 CFX_ByteString& csName) const { |
202 return ::CountNames(m_pRoot); | 217 if (m_pRoot == NULL) { |
203 } | 218 return NULL; |
204 int CPDF_NameTree::GetIndex(const CFX_ByteString& csName) const | 219 } |
205 { | 220 int nCurIndex = 0; |
206 if (m_pRoot == NULL) { | 221 return SearchNameNode(m_pRoot, nIndex, nCurIndex, csName, NULL); |
207 return -1; | 222 } |
208 } | 223 CPDF_Object* CPDF_NameTree::LookupValue(const CFX_ByteString& csName) const { |
209 int nIndex = 0; | 224 if (m_pRoot == NULL) { |
210 if (SearchNameNode(m_pRoot, csName, nIndex, NULL) == NULL) { | 225 return NULL; |
211 return -1; | 226 } |
212 } | 227 int nIndex = 0; |
213 return nIndex; | 228 return SearchNameNode(m_pRoot, csName, nIndex, NULL); |
214 } | 229 } |
215 CPDF_Object* CPDF_NameTree::LookupValue(int nIndex, CFX_ByteString& csName) cons
t | 230 CPDF_Array* CPDF_NameTree::LookupNamedDest(CPDF_Document* pDoc, |
216 { | 231 const CFX_ByteStringC& sName) { |
217 if (m_pRoot == NULL) { | 232 CPDF_Object* pValue = LookupValue(sName); |
218 return NULL; | 233 if (pValue == NULL) { |
219 } | 234 CPDF_Dictionary* pDests = pDoc->GetRoot()->GetDict(FX_BSTRC("Dests")); |
220 int nCurIndex = 0; | 235 if (pDests == NULL) { |
221 return SearchNameNode(m_pRoot, nIndex, nCurIndex, csName, NULL); | 236 return NULL; |
222 } | 237 } |
223 CPDF_Object* CPDF_NameTree::LookupValue(const CFX_ByteString& csName) const | 238 pValue = pDests->GetElementValue(sName); |
224 { | 239 } |
225 if (m_pRoot == NULL) { | 240 if (pValue == NULL) { |
226 return NULL; | 241 return NULL; |
227 } | 242 } |
228 int nIndex = 0; | 243 if (pValue->GetType() == PDFOBJ_ARRAY) { |
229 return SearchNameNode(m_pRoot, csName, nIndex, NULL); | 244 return (CPDF_Array*)pValue; |
230 } | 245 } |
231 CPDF_Array* CPDF_NameTree::LookupNamedDest(CPDF_Document* pDoc, const CFX_By
teStringC& sName) | 246 if (pValue->GetType() == PDFOBJ_DICTIONARY) { |
232 { | 247 return ((CPDF_Dictionary*)pValue)->GetArray(FX_BSTRC("D")); |
233 CPDF_Object* pValue = LookupValue(sName); | 248 } |
234 if (pValue == NULL) { | 249 return NULL; |
235 CPDF_Dictionary* pDests = pDoc->GetRoot()->GetDict(FX_BSTRC("Dests")); | 250 } |
236 if (pDests == NULL) { | 251 #if _FXM_PLATFORM_ == _FXM_PLATFORM_APPLE_ || \ |
237 return NULL; | 252 _FXM_PLATFORM_ == _FXM_PLATFORM_WINDOWS_ |
238 } | 253 static CFX_WideString ChangeSlashToPlatform(const FX_WCHAR* str) { |
239 pValue = pDests->GetElementValue(sName); | 254 CFX_WideString result; |
240 } | 255 while (*str) { |
241 if (pValue == NULL) { | 256 if (*str == '/') { |
242 return NULL; | 257 #if _FXM_PLATFORM_ == _FXM_PLATFORM_APPLE_ |
243 } | 258 result += ':'; |
244 if (pValue->GetType() == PDFOBJ_ARRAY) { | 259 #else |
245 return (CPDF_Array*)pValue; | 260 result += '\\'; |
246 } | 261 #endif |
| 262 } else { |
| 263 result += *str; |
| 264 } |
| 265 str++; |
| 266 } |
| 267 return result; |
| 268 } |
| 269 static CFX_WideString ChangeSlashToPDF(const FX_WCHAR* str) { |
| 270 CFX_WideString result; |
| 271 while (*str) { |
| 272 if (*str == '\\' || *str == ':') { |
| 273 result += '/'; |
| 274 } else { |
| 275 result += *str; |
| 276 } |
| 277 str++; |
| 278 } |
| 279 return result; |
| 280 } |
| 281 #endif |
| 282 static CFX_WideString FILESPEC_DecodeFileName(const CFX_WideStringC& filepath) { |
| 283 if (filepath.GetLength() <= 1) { |
| 284 return CFX_WideString(); |
| 285 } |
| 286 #if _FXM_PLATFORM_ == _FXM_PLATFORM_APPLE_ |
| 287 if (filepath.Left(sizeof("/Mac") - 1) == CFX_WideStringC(L"/Mac")) { |
| 288 return ChangeSlashToPlatform(filepath.GetPtr() + 1); |
| 289 } |
| 290 return ChangeSlashToPlatform(filepath.GetPtr()); |
| 291 #elif _FXM_PLATFORM_ == _FXM_PLATFORM_WINDOWS_ |
| 292 if (filepath.GetAt(0) != '/') { |
| 293 return ChangeSlashToPlatform(filepath.GetPtr()); |
| 294 } |
| 295 if (filepath.GetAt(1) == '/') { |
| 296 return ChangeSlashToPlatform(filepath.GetPtr() + 1); |
| 297 } |
| 298 if (filepath.GetAt(2) == '/') { |
| 299 CFX_WideString result; |
| 300 result += filepath.GetAt(1); |
| 301 result += ':'; |
| 302 result += ChangeSlashToPlatform(filepath.GetPtr() + 2); |
| 303 return result; |
| 304 } |
| 305 CFX_WideString result; |
| 306 result += '\\'; |
| 307 result += ChangeSlashToPlatform(filepath.GetPtr()); |
| 308 return result; |
| 309 #else |
| 310 return filepath; |
| 311 #endif |
| 312 } |
| 313 FX_BOOL CPDF_FileSpec::GetFileName(CFX_WideString& csFileName) const { |
| 314 if (m_pObj == NULL) { |
| 315 return FALSE; |
| 316 } |
| 317 if (m_pObj->GetType() == PDFOBJ_DICTIONARY) { |
| 318 CPDF_Dictionary* pDict = (CPDF_Dictionary*)m_pObj; |
| 319 csFileName = pDict->GetUnicodeText(FX_BSTRC("UF")); |
| 320 if (csFileName.IsEmpty()) { |
| 321 csFileName = CFX_WideString::FromLocal(pDict->GetString(FX_BSTRC("F"))); |
| 322 } |
| 323 if (pDict->GetString(FX_BSTRC("FS")) == FX_BSTRC("URL")) { |
| 324 return TRUE; |
| 325 } |
| 326 if (csFileName.IsEmpty()) { |
| 327 if (pDict->KeyExist(FX_BSTRC("DOS"))) { |
| 328 csFileName = |
| 329 CFX_WideString::FromLocal(pDict->GetString(FX_BSTRC("DOS"))); |
| 330 } else if (pDict->KeyExist(FX_BSTRC("Mac"))) { |
| 331 csFileName = |
| 332 CFX_WideString::FromLocal(pDict->GetString(FX_BSTRC("Mac"))); |
| 333 } else if (pDict->KeyExist(FX_BSTRC("Unix"))) { |
| 334 csFileName = |
| 335 CFX_WideString::FromLocal(pDict->GetString(FX_BSTRC("Unix"))); |
| 336 } else { |
| 337 return FALSE; |
| 338 } |
| 339 } |
| 340 } else { |
| 341 csFileName = CFX_WideString::FromLocal(m_pObj->GetString()); |
| 342 } |
| 343 csFileName = FILESPEC_DecodeFileName(csFileName); |
| 344 return TRUE; |
| 345 } |
| 346 CPDF_FileSpec::CPDF_FileSpec() { |
| 347 m_pObj = CPDF_Dictionary::Create(); |
| 348 if (m_pObj != NULL) { |
| 349 ((CPDF_Dictionary*)m_pObj) |
| 350 ->SetAtName(FX_BSTRC("Type"), FX_BSTRC("Filespec")); |
| 351 } |
| 352 } |
| 353 FX_BOOL CPDF_FileSpec::IsURL() const { |
| 354 if (m_pObj == NULL) { |
| 355 return FALSE; |
| 356 } |
| 357 if (m_pObj->GetType() != PDFOBJ_DICTIONARY) { |
| 358 return FALSE; |
| 359 } |
| 360 return ((CPDF_Dictionary*)m_pObj)->GetString(FX_BSTRC("FS")) == |
| 361 FX_BSTRC("URL"); |
| 362 } |
| 363 CFX_WideString FILESPEC_EncodeFileName(const CFX_WideStringC& filepath) { |
| 364 if (filepath.GetLength() <= 1) { |
| 365 return CFX_WideString(); |
| 366 } |
| 367 #if _FXM_PLATFORM_ == _FXM_PLATFORM_WINDOWS_ |
| 368 if (filepath.GetAt(1) == ':') { |
| 369 CFX_WideString result; |
| 370 result = '/'; |
| 371 result += filepath.GetAt(0); |
| 372 if (filepath.GetAt(2) != '\\') { |
| 373 result += '/'; |
| 374 } |
| 375 result += ChangeSlashToPDF(filepath.GetPtr() + 2); |
| 376 return result; |
| 377 } |
| 378 if (filepath.GetAt(0) == '\\' && filepath.GetAt(1) == '\\') { |
| 379 return ChangeSlashToPDF(filepath.GetPtr() + 1); |
| 380 } |
| 381 if (filepath.GetAt(0) == '\\') { |
| 382 CFX_WideString result; |
| 383 result = '/'; |
| 384 result += ChangeSlashToPDF(filepath.GetPtr()); |
| 385 return result; |
| 386 } |
| 387 return ChangeSlashToPDF(filepath.GetPtr()); |
| 388 #elif _FXM_PLATFORM_ == _FXM_PLATFORM_APPLE_ |
| 389 if (filepath.Left(sizeof("Mac") - 1) == FX_WSTRC(L"Mac")) { |
| 390 CFX_WideString result; |
| 391 result = '/'; |
| 392 result += ChangeSlashToPDF(filepath.GetPtr()); |
| 393 return result; |
| 394 } |
| 395 return ChangeSlashToPDF(filepath.GetPtr()); |
| 396 #else |
| 397 return filepath; |
| 398 #endif |
| 399 } |
| 400 CPDF_Stream* CPDF_FileSpec::GetFileStream() const { |
| 401 if (m_pObj == NULL) { |
| 402 return NULL; |
| 403 } |
| 404 int32_t iType = m_pObj->GetType(); |
| 405 if (iType == PDFOBJ_STREAM) { |
| 406 return (CPDF_Stream*)m_pObj; |
| 407 } else if (iType == PDFOBJ_DICTIONARY) { |
| 408 CPDF_Dictionary* pEF = ((CPDF_Dictionary*)m_pObj)->GetDict(FX_BSTRC("EF")); |
| 409 if (pEF == NULL) { |
| 410 return NULL; |
| 411 } |
| 412 return pEF->GetStream(FX_BSTRC("F")); |
| 413 } |
| 414 return NULL; |
| 415 } |
| 416 static void FPDFDOC_FILESPEC_SetFileName(CPDF_Object* pObj, |
| 417 const CFX_WideStringC& wsFileName, |
| 418 FX_BOOL bURL) { |
| 419 ASSERT(pObj != NULL); |
| 420 CFX_WideString wsStr; |
| 421 if (bURL) { |
| 422 wsStr = wsFileName; |
| 423 } else { |
| 424 wsStr = FILESPEC_EncodeFileName(wsFileName); |
| 425 } |
| 426 int32_t iType = pObj->GetType(); |
| 427 if (iType == PDFOBJ_STRING) { |
| 428 pObj->SetString(CFX_ByteString::FromUnicode(wsStr)); |
| 429 } else if (iType == PDFOBJ_DICTIONARY) { |
| 430 CPDF_Dictionary* pDict = (CPDF_Dictionary*)pObj; |
| 431 pDict->SetAtString(FX_BSTRC("F"), CFX_ByteString::FromUnicode(wsStr)); |
| 432 pDict->SetAtString(FX_BSTRC("UF"), PDF_EncodeText(wsStr)); |
| 433 } |
| 434 } |
| 435 void CPDF_FileSpec::SetFileName(const CFX_WideStringC& wsFileName, |
| 436 FX_BOOL bURL) { |
| 437 ASSERT(m_pObj != NULL); |
| 438 if (m_pObj->GetType() == PDFOBJ_DICTIONARY && bURL) { |
| 439 ((CPDF_Dictionary*)m_pObj)->SetAtName(FX_BSTRC("FS"), "URL"); |
| 440 } |
| 441 FPDFDOC_FILESPEC_SetFileName(m_pObj, wsFileName, bURL); |
| 442 } |
| 443 static CFX_WideString _MakeRoman(int num) { |
| 444 const int arabic[] = {1000, 900, 500, 400, 100, 90, 50, 40, 10, 9, 5, 4, 1}; |
| 445 const CFX_WideString roman[] = {L"m", L"cm", L"d", L"cd", L"c", |
| 446 L"xc", L"l", L"xl", L"x", L"ix", |
| 447 L"v", L"iv", L"i"}; |
| 448 const int nMaxNum = 1000000; |
| 449 num %= nMaxNum; |
| 450 int i = 0; |
| 451 CFX_WideString wsRomanNumber; |
| 452 while (num > 0) { |
| 453 while (num >= arabic[i]) { |
| 454 num = num - arabic[i]; |
| 455 wsRomanNumber += roman[i]; |
| 456 } |
| 457 i = i + 1; |
| 458 } |
| 459 return wsRomanNumber; |
| 460 } |
| 461 static CFX_WideString _MakeLetters(int num) { |
| 462 if (num == 0) { |
| 463 return CFX_WideString(); |
| 464 } |
| 465 CFX_WideString wsLetters; |
| 466 const int nMaxCount = 1000; |
| 467 const int nLetterCount = 26; |
| 468 num -= 1; |
| 469 int count = num / nLetterCount + 1; |
| 470 count %= nMaxCount; |
| 471 FX_WCHAR ch = L'a' + num % nLetterCount; |
| 472 for (int i = 0; i < count; i++) { |
| 473 wsLetters += ch; |
| 474 } |
| 475 return wsLetters; |
| 476 } |
| 477 static CFX_WideString _GetLabelNumPortion(int num, |
| 478 const CFX_ByteString& bsStyle) { |
| 479 CFX_WideString wsNumPortion; |
| 480 if (bsStyle.IsEmpty()) { |
| 481 return wsNumPortion; |
| 482 } |
| 483 if (bsStyle == "D") { |
| 484 wsNumPortion.Format(L"%d", num); |
| 485 } else if (bsStyle == "R") { |
| 486 wsNumPortion = _MakeRoman(num); |
| 487 wsNumPortion.MakeUpper(); |
| 488 } else if (bsStyle == "r") { |
| 489 wsNumPortion = _MakeRoman(num); |
| 490 } else if (bsStyle == "A") { |
| 491 wsNumPortion = _MakeLetters(num); |
| 492 wsNumPortion.MakeUpper(); |
| 493 } else if (bsStyle == "a") { |
| 494 wsNumPortion = _MakeLetters(num); |
| 495 } |
| 496 return wsNumPortion; |
| 497 } |
| 498 CFX_WideString CPDF_PageLabel::GetLabel(int nPage) const { |
| 499 CFX_WideString wsLabel; |
| 500 if (m_pDocument == NULL) { |
| 501 return wsLabel; |
| 502 } |
| 503 CPDF_Dictionary* pPDFRoot = m_pDocument->GetRoot(); |
| 504 if (pPDFRoot == NULL) { |
| 505 return wsLabel; |
| 506 } |
| 507 CPDF_Dictionary* pLabels = pPDFRoot->GetDict(FX_BSTRC("PageLabels")); |
| 508 CPDF_NumberTree numberTree(pLabels); |
| 509 CPDF_Object* pValue = NULL; |
| 510 int n = nPage; |
| 511 while (n >= 0) { |
| 512 pValue = numberTree.LookupValue(n); |
| 513 if (pValue != NULL) { |
| 514 break; |
| 515 } |
| 516 n--; |
| 517 } |
| 518 if (pValue != NULL) { |
| 519 pValue = pValue->GetDirect(); |
247 if (pValue->GetType() == PDFOBJ_DICTIONARY) { | 520 if (pValue->GetType() == PDFOBJ_DICTIONARY) { |
248 return ((CPDF_Dictionary*)pValue)->GetArray(FX_BSTRC("D")); | 521 CPDF_Dictionary* pLabel = (CPDF_Dictionary*)pValue; |
249 } | 522 if (pLabel->KeyExist(FX_BSTRC("P"))) { |
250 return NULL; | 523 wsLabel += pLabel->GetUnicodeText(FX_BSTRC("P")); |
251 } | 524 } |
252 #if _FXM_PLATFORM_ == _FXM_PLATFORM_APPLE_ || _FXM_PLATFORM_ == _FXM_PLATFORM_
WINDOWS_ | 525 CFX_ByteString bsNumberingStyle = pLabel->GetString(FX_BSTRC("S"), NULL); |
253 static CFX_WideString ChangeSlashToPlatform(const FX_WCHAR* str) | 526 int nLabelNum = nPage - n + pLabel->GetInteger(FX_BSTRC("St"), 1); |
254 { | 527 CFX_WideString wsNumPortion = |
255 CFX_WideString result; | 528 _GetLabelNumPortion(nLabelNum, bsNumberingStyle); |
256 while (*str) { | 529 wsLabel += wsNumPortion; |
257 if (*str == '/') { | 530 return wsLabel; |
258 #if _FXM_PLATFORM_ == _FXM_PLATFORM_APPLE_ | 531 } |
259 result += ':'; | 532 } |
260 #else | 533 wsLabel.Format(L"%d", nPage + 1); |
261 result += '\\'; | 534 return wsLabel; |
262 #endif | 535 } |
263 } else { | 536 int32_t CPDF_PageLabel::GetPageByLabel(const CFX_ByteStringC& bsLabel) const { |
264 result += *str; | 537 if (m_pDocument == NULL) { |
265 } | |
266 str++; | |
267 } | |
268 return result; | |
269 } | |
270 static CFX_WideString ChangeSlashToPDF(const FX_WCHAR* str) | |
271 { | |
272 CFX_WideString result; | |
273 while (*str) { | |
274 if (*str == '\\' || *str == ':') { | |
275 result += '/'; | |
276 } else { | |
277 result += *str; | |
278 } | |
279 str++; | |
280 } | |
281 return result; | |
282 } | |
283 #endif | |
284 static CFX_WideString FILESPEC_DecodeFileName(const CFX_WideStringC& filepath) | |
285 { | |
286 if (filepath.GetLength() <= 1) { | |
287 return CFX_WideString(); | |
288 } | |
289 #if _FXM_PLATFORM_ == _FXM_PLATFORM_APPLE_ | |
290 if (filepath.Left(sizeof("/Mac") - 1) == CFX_WideStringC(L"/Mac")) { | |
291 return ChangeSlashToPlatform(filepath.GetPtr() + 1); | |
292 } | |
293 return ChangeSlashToPlatform(filepath.GetPtr()); | |
294 #elif _FXM_PLATFORM_ == _FXM_PLATFORM_WINDOWS_ | |
295 if (filepath.GetAt(0) != '/') { | |
296 return ChangeSlashToPlatform(filepath.GetPtr()); | |
297 } | |
298 if (filepath.GetAt(1) == '/') { | |
299 return ChangeSlashToPlatform(filepath.GetPtr() + 1); | |
300 } | |
301 if (filepath.GetAt(2) == '/') { | |
302 CFX_WideString result; | |
303 result += filepath.GetAt(1); | |
304 result += ':'; | |
305 result += ChangeSlashToPlatform(filepath.GetPtr() + 2); | |
306 return result; | |
307 } | |
308 CFX_WideString result; | |
309 result += '\\'; | |
310 result += ChangeSlashToPlatform(filepath.GetPtr()); | |
311 return result; | |
312 #else | |
313 return filepath; | |
314 #endif | |
315 } | |
316 FX_BOOL CPDF_FileSpec::GetFileName(CFX_WideString &csFileName) const | |
317 { | |
318 if (m_pObj == NULL) { | |
319 return FALSE; | |
320 } | |
321 if (m_pObj->GetType() == PDFOBJ_DICTIONARY) { | |
322 CPDF_Dictionary* pDict = (CPDF_Dictionary*)m_pObj; | |
323 csFileName = pDict->GetUnicodeText(FX_BSTRC("UF")); | |
324 if (csFileName.IsEmpty()) { | |
325 csFileName = CFX_WideString::FromLocal(pDict->GetString(FX_BSTRC("F"
))); | |
326 } | |
327 if (pDict->GetString(FX_BSTRC("FS")) == FX_BSTRC("URL")) { | |
328 return TRUE; | |
329 } | |
330 if (csFileName.IsEmpty()) { | |
331 if (pDict->KeyExist(FX_BSTRC("DOS"))) { | |
332 csFileName = CFX_WideString::FromLocal(pDict->GetString(FX_BSTRC
("DOS"))); | |
333 } else if (pDict->KeyExist(FX_BSTRC("Mac"))) { | |
334 csFileName = CFX_WideString::FromLocal(pDict->GetString(FX_BSTRC
("Mac"))); | |
335 } else if (pDict->KeyExist(FX_BSTRC("Unix"))) { | |
336 csFileName = CFX_WideString::FromLocal(pDict->GetString(FX_BSTRC
("Unix"))); | |
337 } else { | |
338 return FALSE; | |
339 } | |
340 } | |
341 } else { | |
342 csFileName = CFX_WideString::FromLocal(m_pObj->GetString()); | |
343 } | |
344 csFileName = FILESPEC_DecodeFileName(csFileName); | |
345 return TRUE; | |
346 } | |
347 CPDF_FileSpec::CPDF_FileSpec() | |
348 { | |
349 m_pObj = CPDF_Dictionary::Create(); | |
350 if (m_pObj != NULL) { | |
351 ((CPDF_Dictionary*)m_pObj)->SetAtName(FX_BSTRC("Type"), FX_BSTRC("Filesp
ec")); | |
352 } | |
353 } | |
354 FX_BOOL CPDF_FileSpec::IsURL() const | |
355 { | |
356 if (m_pObj == NULL) { | |
357 return FALSE; | |
358 } | |
359 if (m_pObj->GetType() != PDFOBJ_DICTIONARY) { | |
360 return FALSE; | |
361 } | |
362 return ((CPDF_Dictionary*)m_pObj)->GetString(FX_BSTRC("FS")) == FX_BSTRC("UR
L"); | |
363 } | |
364 CFX_WideString FILESPEC_EncodeFileName(const CFX_WideStringC& filepath) | |
365 { | |
366 if (filepath.GetLength() <= 1) { | |
367 return CFX_WideString(); | |
368 } | |
369 #if _FXM_PLATFORM_ == _FXM_PLATFORM_WINDOWS_ | |
370 if (filepath.GetAt(1) == ':') { | |
371 CFX_WideString result; | |
372 result = '/'; | |
373 result += filepath.GetAt(0); | |
374 if (filepath.GetAt(2) != '\\') { | |
375 result += '/'; | |
376 } | |
377 result += ChangeSlashToPDF(filepath.GetPtr() + 2); | |
378 return result; | |
379 } | |
380 if (filepath.GetAt(0) == '\\' && filepath.GetAt(1) == '\\') { | |
381 return ChangeSlashToPDF(filepath.GetPtr() + 1); | |
382 } | |
383 if (filepath.GetAt(0) == '\\') { | |
384 CFX_WideString result; | |
385 result = '/'; | |
386 result += ChangeSlashToPDF(filepath.GetPtr()); | |
387 return result; | |
388 } | |
389 return ChangeSlashToPDF(filepath.GetPtr()); | |
390 #elif _FXM_PLATFORM_ == _FXM_PLATFORM_APPLE_ | |
391 if (filepath.Left(sizeof("Mac") - 1) == FX_WSTRC(L"Mac")) { | |
392 CFX_WideString result; | |
393 result = '/'; | |
394 result += ChangeSlashToPDF(filepath.GetPtr()); | |
395 return result; | |
396 } | |
397 return ChangeSlashToPDF(filepath.GetPtr()); | |
398 #else | |
399 return filepath; | |
400 #endif | |
401 } | |
402 CPDF_Stream* CPDF_FileSpec::GetFileStream() const | |
403 { | |
404 if (m_pObj == NULL) { | |
405 return NULL; | |
406 } | |
407 int32_t iType = m_pObj->GetType(); | |
408 if (iType == PDFOBJ_STREAM) { | |
409 return (CPDF_Stream*)m_pObj; | |
410 } else if (iType == PDFOBJ_DICTIONARY) { | |
411 CPDF_Dictionary *pEF = ((CPDF_Dictionary*)m_pObj)->GetDict(FX_BSTRC("EF"
)); | |
412 if (pEF == NULL) { | |
413 return NULL; | |
414 } | |
415 return pEF->GetStream(FX_BSTRC("F")); | |
416 } | |
417 return NULL; | |
418 } | |
419 static void FPDFDOC_FILESPEC_SetFileName(CPDF_Object *pObj, const CFX_WideString
C& wsFileName, FX_BOOL bURL) | |
420 { | |
421 ASSERT(pObj != NULL); | |
422 CFX_WideString wsStr; | |
423 if (bURL) { | |
424 wsStr = wsFileName; | |
425 } else { | |
426 wsStr = FILESPEC_EncodeFileName(wsFileName); | |
427 } | |
428 int32_t iType = pObj->GetType(); | |
429 if (iType == PDFOBJ_STRING) { | |
430 pObj->SetString(CFX_ByteString::FromUnicode(wsStr)); | |
431 } else if (iType == PDFOBJ_DICTIONARY) { | |
432 CPDF_Dictionary* pDict = (CPDF_Dictionary*)pObj; | |
433 pDict->SetAtString(FX_BSTRC("F"), CFX_ByteString::FromUnicode(wsStr)); | |
434 pDict->SetAtString(FX_BSTRC("UF"), PDF_EncodeText(wsStr)); | |
435 } | |
436 } | |
437 void CPDF_FileSpec::SetFileName(const CFX_WideStringC& wsFileName, FX_BOOL bURL) | |
438 { | |
439 ASSERT(m_pObj != NULL); | |
440 if (m_pObj->GetType() == PDFOBJ_DICTIONARY && bURL) { | |
441 ((CPDF_Dictionary*)m_pObj)->SetAtName(FX_BSTRC("FS"), "URL"); | |
442 } | |
443 FPDFDOC_FILESPEC_SetFileName(m_pObj, wsFileName, bURL); | |
444 } | |
445 static CFX_WideString _MakeRoman(int num) | |
446 { | |
447 const int arabic[] = { | |
448 1000, 900, 500, 400, 100, 90, 50, 40, 10, 9, 5, 4, 1 | |
449 }; | |
450 const CFX_WideString roman[] = { | |
451 L"m", L"cm", L"d", L"cd", L"c", L"xc", L"l", L"xl", L"x", L"ix", L"v", L
"iv", L"i" | |
452 }; | |
453 const int nMaxNum = 1000000; | |
454 num %= nMaxNum; | |
455 int i = 0; | |
456 CFX_WideString wsRomanNumber; | |
457 while (num > 0) { | |
458 while (num >= arabic[i]) { | |
459 num = num - arabic[i]; | |
460 wsRomanNumber += roman[i]; | |
461 } | |
462 i = i + 1; | |
463 } | |
464 return wsRomanNumber; | |
465 } | |
466 static CFX_WideString _MakeLetters(int num) | |
467 { | |
468 if (num == 0) { | |
469 return CFX_WideString(); | |
470 } | |
471 CFX_WideString wsLetters; | |
472 const int nMaxCount = 1000; | |
473 const int nLetterCount = 26; | |
474 num -= 1; | |
475 int count = num / nLetterCount + 1; | |
476 count %= nMaxCount; | |
477 FX_WCHAR ch = L'a' + num % nLetterCount; | |
478 for (int i = 0; i < count; i++) { | |
479 wsLetters += ch; | |
480 } | |
481 return wsLetters; | |
482 } | |
483 static CFX_WideString _GetLabelNumPortion(int num, const CFX_ByteString& bsStyle
) | |
484 { | |
485 CFX_WideString wsNumPortion; | |
486 if (bsStyle.IsEmpty()) { | |
487 return wsNumPortion; | |
488 } | |
489 if (bsStyle == "D") { | |
490 wsNumPortion.Format(L"%d", num); | |
491 } else if (bsStyle == "R") { | |
492 wsNumPortion = _MakeRoman(num); | |
493 wsNumPortion.MakeUpper(); | |
494 } else if (bsStyle == "r") { | |
495 wsNumPortion = _MakeRoman(num); | |
496 } else if (bsStyle == "A") { | |
497 wsNumPortion = _MakeLetters(num); | |
498 wsNumPortion.MakeUpper(); | |
499 } else if (bsStyle == "a") { | |
500 wsNumPortion = _MakeLetters(num); | |
501 } | |
502 return wsNumPortion; | |
503 } | |
504 CFX_WideString CPDF_PageLabel::GetLabel(int nPage) const | |
505 { | |
506 CFX_WideString wsLabel; | |
507 if (m_pDocument == NULL) { | |
508 return wsLabel; | |
509 } | |
510 CPDF_Dictionary* pPDFRoot = m_pDocument->GetRoot(); | |
511 if (pPDFRoot == NULL) { | |
512 return wsLabel; | |
513 } | |
514 CPDF_Dictionary* pLabels = pPDFRoot->GetDict(FX_BSTRC("PageLabels")); | |
515 CPDF_NumberTree numberTree(pLabels); | |
516 CPDF_Object* pValue = NULL; | |
517 int n = nPage; | |
518 while (n >= 0) { | |
519 pValue = numberTree.LookupValue(n); | |
520 if (pValue != NULL) { | |
521 break; | |
522 } | |
523 n--; | |
524 } | |
525 if (pValue != NULL) { | |
526 pValue = pValue->GetDirect(); | |
527 if (pValue->GetType() == PDFOBJ_DICTIONARY) { | |
528 CPDF_Dictionary* pLabel = (CPDF_Dictionary*)pValue; | |
529 if (pLabel->KeyExist(FX_BSTRC("P"))) { | |
530 wsLabel += pLabel->GetUnicodeText(FX_BSTRC("P")); | |
531 } | |
532 CFX_ByteString bsNumberingStyle = pLabel->GetString(FX_BSTRC("S"), N
ULL); | |
533 int nLabelNum = nPage - n + pLabel->GetInteger(FX_BSTRC("St"), 1); | |
534 CFX_WideString wsNumPortion = _GetLabelNumPortion(nLabelNum, bsNumbe
ringStyle); | |
535 wsLabel += wsNumPortion; | |
536 return wsLabel; | |
537 } | |
538 } | |
539 wsLabel.Format(L"%d", nPage + 1); | |
540 return wsLabel; | |
541 } | |
542 int32_t CPDF_PageLabel::GetPageByLabel(const CFX_ByteStringC& bsLabel) const | |
543 { | |
544 if (m_pDocument == NULL) { | |
545 return -1; | |
546 } | |
547 CPDF_Dictionary* pPDFRoot = m_pDocument->GetRoot(); | |
548 if (pPDFRoot == NULL) { | |
549 return -1; | |
550 } | |
551 int nPages = m_pDocument->GetPageCount(); | |
552 CFX_ByteString bsLbl; | |
553 CFX_ByteString bsOrig = bsLabel; | |
554 for (int i = 0; i < nPages; i++) { | |
555 bsLbl = PDF_EncodeText(GetLabel(i)); | |
556 if (!bsLbl.Compare(bsOrig)) { | |
557 return i; | |
558 } | |
559 } | |
560 bsLbl = bsOrig; | |
561 int nPage = FXSYS_atoi(bsLbl); | |
562 if (nPage > 0 && nPage <= nPages) { | |
563 return nPage; | |
564 } | |
565 return -1; | 538 return -1; |
566 } | 539 } |
567 int32_t CPDF_PageLabel::GetPageByLabel(const CFX_WideStringC& wsLabel) const | 540 CPDF_Dictionary* pPDFRoot = m_pDocument->GetRoot(); |
568 { | 541 if (pPDFRoot == NULL) { |
569 CFX_ByteString bsLabel = PDF_EncodeText(wsLabel.GetPtr()); | 542 return -1; |
570 return GetPageByLabel(bsLabel); | 543 } |
571 } | 544 int nPages = m_pDocument->GetPageCount(); |
| 545 CFX_ByteString bsLbl; |
| 546 CFX_ByteString bsOrig = bsLabel; |
| 547 for (int i = 0; i < nPages; i++) { |
| 548 bsLbl = PDF_EncodeText(GetLabel(i)); |
| 549 if (!bsLbl.Compare(bsOrig)) { |
| 550 return i; |
| 551 } |
| 552 } |
| 553 bsLbl = bsOrig; |
| 554 int nPage = FXSYS_atoi(bsLbl); |
| 555 if (nPage > 0 && nPage <= nPages) { |
| 556 return nPage; |
| 557 } |
| 558 return -1; |
| 559 } |
| 560 int32_t CPDF_PageLabel::GetPageByLabel(const CFX_WideStringC& wsLabel) const { |
| 561 CFX_ByteString bsLabel = PDF_EncodeText(wsLabel.GetPtr()); |
| 562 return GetPageByLabel(bsLabel); |
| 563 } |
OLD | NEW |