| 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 "core/fpdfapi/fpdf_parser/include/cpdf_array.h" | 7 #include "core/fpdfapi/fpdf_parser/include/cpdf_array.h" |
| 8 #include "core/fpdfapi/fpdf_parser/include/cpdf_document.h" | 8 #include "core/fpdfapi/fpdf_parser/include/cpdf_document.h" |
| 9 #include "core/fpdfdoc/doc_utils.h" | 9 #include "core/fpdfdoc/doc_utils.h" |
| 10 #include "core/fpdfdoc/include/fpdf_doc.h" | 10 #include "core/fpdfdoc/include/fpdf_doc.h" |
| (...skipping 482 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
| 493 int nLabelNum = nPage - n + pLabel->GetIntegerBy("St", 1); | 493 int nLabelNum = nPage - n + pLabel->GetIntegerBy("St", 1); |
| 494 CFX_WideString wsNumPortion = | 494 CFX_WideString wsNumPortion = |
| 495 _GetLabelNumPortion(nLabelNum, bsNumberingStyle); | 495 _GetLabelNumPortion(nLabelNum, bsNumberingStyle); |
| 496 wsLabel += wsNumPortion; | 496 wsLabel += wsNumPortion; |
| 497 return wsLabel; | 497 return wsLabel; |
| 498 } | 498 } |
| 499 } | 499 } |
| 500 wsLabel.Format(L"%d", nPage + 1); | 500 wsLabel.Format(L"%d", nPage + 1); |
| 501 return wsLabel; | 501 return wsLabel; |
| 502 } | 502 } |
| 503 |
| 503 int32_t CPDF_PageLabel::GetPageByLabel(const CFX_ByteStringC& bsLabel) const { | 504 int32_t CPDF_PageLabel::GetPageByLabel(const CFX_ByteStringC& bsLabel) const { |
| 504 if (!m_pDocument) { | 505 if (!m_pDocument) |
| 505 return -1; | 506 return -1; |
| 507 |
| 508 CPDF_Dictionary* pPDFRoot = m_pDocument->GetRoot(); |
| 509 if (!pPDFRoot) |
| 510 return -1; |
| 511 |
| 512 int nPages = m_pDocument->GetPageCount(); |
| 513 for (int i = 0; i < nPages; i++) { |
| 514 if (PDF_EncodeText(GetLabel(i)).Compare(bsLabel)) |
| 515 return i; |
| 506 } | 516 } |
| 507 CPDF_Dictionary* pPDFRoot = m_pDocument->GetRoot(); | 517 |
| 508 if (!pPDFRoot) { | 518 int nPage = FXSYS_atoi(CFX_ByteString(bsLabel).c_str()); // NUL terminate. |
| 509 return -1; | 519 return nPage > 0 && nPage <= nPages ? nPage : -1; |
| 510 } | |
| 511 int nPages = m_pDocument->GetPageCount(); | |
| 512 CFX_ByteString bsLbl; | |
| 513 CFX_ByteString bsOrig = bsLabel; | |
| 514 for (int i = 0; i < nPages; i++) { | |
| 515 bsLbl = PDF_EncodeText(GetLabel(i)); | |
| 516 if (!bsLbl.Compare(bsOrig.AsStringC())) { | |
| 517 return i; | |
| 518 } | |
| 519 } | |
| 520 bsLbl = bsOrig; | |
| 521 int nPage = FXSYS_atoi(bsLbl.c_str()); | |
| 522 if (nPage > 0 && nPage <= nPages) { | |
| 523 return nPage; | |
| 524 } | |
| 525 return -1; | |
| 526 } | 520 } |
| 521 |
| 527 int32_t CPDF_PageLabel::GetPageByLabel(const CFX_WideStringC& wsLabel) const { | 522 int32_t CPDF_PageLabel::GetPageByLabel(const CFX_WideStringC& wsLabel) const { |
| 528 return GetPageByLabel(PDF_EncodeText(wsLabel.c_str()).AsStringC()); | 523 return GetPageByLabel(PDF_EncodeText(wsLabel.c_str()).AsStringC()); |
| 529 } | 524 } |
| OLD | NEW |