summaryrefslogtreecommitdiff
path: root/core/fpdfdoc/cpdf_pagelabel.cpp
diff options
context:
space:
mode:
authorthestig <thestig@chromium.org>2016-11-23 05:52:39 -0800
committerCommit bot <commit-bot@chromium.org>2016-11-23 05:52:39 -0800
commit733e068e077bb59597180bc9b8ff934dd125ffdc (patch)
treea174a02225f1c42933605d516324dc8d0bdd42b8 /core/fpdfdoc/cpdf_pagelabel.cpp
parent1a7534a1a477323f7b8497e359f6af6e9bd54cd5 (diff)
downloadpdfium-733e068e077bb59597180bc9b8ff934dd125ffdc.tar.xz
Add API for getting page labels.
BUG=pdfium:479 Review-Url: https://codereview.chromium.org/2521843003
Diffstat (limited to 'core/fpdfdoc/cpdf_pagelabel.cpp')
-rw-r--r--core/fpdfdoc/cpdf_pagelabel.cpp28
1 files changed, 18 insertions, 10 deletions
diff --git a/core/fpdfdoc/cpdf_pagelabel.cpp b/core/fpdfdoc/cpdf_pagelabel.cpp
index 64075ef55a..2a79d77ca7 100644
--- a/core/fpdfdoc/cpdf_pagelabel.cpp
+++ b/core/fpdfdoc/cpdf_pagelabel.cpp
@@ -75,16 +75,21 @@ CFX_WideString GetLabelNumPortion(int num, const CFX_ByteString& bsStyle) {
CPDF_PageLabel::CPDF_PageLabel(CPDF_Document* pDocument)
: m_pDocument(pDocument) {}
-CFX_WideString CPDF_PageLabel::GetLabel(int nPage) const {
- CFX_WideString wsLabel;
+bool CPDF_PageLabel::GetLabel(int nPage, CFX_WideString* wsLabel) const {
if (!m_pDocument)
- return wsLabel;
+ return false;
+
+ if (nPage < 0 || nPage >= m_pDocument->GetPageCount())
+ return false;
CPDF_Dictionary* pPDFRoot = m_pDocument->GetRoot();
if (!pPDFRoot)
- return wsLabel;
+ return false;
CPDF_Dictionary* pLabels = pPDFRoot->GetDictFor("PageLabels");
+ if (!pLabels)
+ return false;
+
CPDF_NumberTree numberTree(pLabels);
CPDF_Object* pValue = nullptr;
int n = nPage;
@@ -99,18 +104,18 @@ CFX_WideString CPDF_PageLabel::GetLabel(int nPage) const {
pValue = pValue->GetDirect();
if (CPDF_Dictionary* pLabel = pValue->AsDictionary()) {
if (pLabel->KeyExist("P"))
- wsLabel += pLabel->GetUnicodeTextFor("P");
+ *wsLabel += pLabel->GetUnicodeTextFor("P");
CFX_ByteString bsNumberingStyle = pLabel->GetStringFor("S", "");
int nLabelNum = nPage - n + pLabel->GetIntegerFor("St", 1);
CFX_WideString wsNumPortion =
GetLabelNumPortion(nLabelNum, bsNumberingStyle);
- wsLabel += wsNumPortion;
- return wsLabel;
+ *wsLabel += wsNumPortion;
+ return true;
}
}
- wsLabel.Format(L"%d", nPage + 1);
- return wsLabel;
+ wsLabel->Format(L"%d", nPage + 1);
+ return true;
}
int32_t CPDF_PageLabel::GetPageByLabel(const CFX_ByteStringC& bsLabel) const {
@@ -123,7 +128,10 @@ int32_t CPDF_PageLabel::GetPageByLabel(const CFX_ByteStringC& bsLabel) const {
int nPages = m_pDocument->GetPageCount();
for (int i = 0; i < nPages; i++) {
- if (PDF_EncodeText(GetLabel(i)).Compare(bsLabel))
+ CFX_WideString str;
+ if (!GetLabel(i, &str))
+ continue;
+ if (PDF_EncodeText(str).Compare(bsLabel))
return i;
}