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

Unified Diff: fpdfsdk/fpdfdoc.cpp

Issue 2521843003: Add API for getting page labels. (Closed)
Patch Set: Created 4 years, 1 month 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 side-by-side diff with in-line comments
Download patch
« no previous file with comments | « no previous file | fpdfsdk/fpdfview_c_api_test.c » ('j') | public/fpdf_doc.h » ('J')
Expand Comments ('e') | Collapse Comments ('c') | Show Comments Hide Comments ('s')
Index: fpdfsdk/fpdfdoc.cpp
diff --git a/fpdfsdk/fpdfdoc.cpp b/fpdfsdk/fpdfdoc.cpp
index 01d91242f44da662af6ca90c98d8895d8fd8d3da..faed707200b89c94262fb33f87b9e59033dc9c09 100644
--- a/fpdfsdk/fpdfdoc.cpp
+++ b/fpdfsdk/fpdfdoc.cpp
@@ -15,6 +15,7 @@
#include "core/fpdfdoc/cpdf_bookmark.h"
#include "core/fpdfdoc/cpdf_bookmarktree.h"
#include "core/fpdfdoc/cpdf_dest.h"
+#include "core/fpdfdoc/cpdf_pagelabel.h"
#include "fpdfsdk/fsdk_define.h"
#include "third_party/base/stl_util.h"
@@ -58,6 +59,16 @@ CPDF_LinkList* GetLinkList(CPDF_Page* page) {
return pHolder->get();
}
+unsigned long Utf16EncodeMaybeCopyAndReturnLength(const CFX_WideString& text,
+ void* buffer,
+ unsigned long buflen) {
+ CFX_ByteString encodedText = text.UTF16LE_Encode();
+ unsigned long len = encodedText.GetLength();
+ if (buffer && buflen >= len)
+ FXSYS_memcpy(buffer, encodedText.c_str(), len);
dsinclair 2016/11/22 14:14:58 Doesn't this need to copy len+1 to get the \0?
Lei Zhang 2016/11/23 00:20:43 This is lifted out of FPDFBookmark_GetTitle(), and
Lei Zhang 2016/11/23 01:53:42 UTF16LE_Encode() already added a double NUL.
+ return len;
+}
+
} // namespace
DLLEXPORT FPDF_BOOKMARK STDCALL
@@ -91,12 +102,7 @@ DLLEXPORT unsigned long STDCALL FPDFBookmark_GetTitle(FPDF_BOOKMARK pDict,
return 0;
CPDF_Bookmark bookmark(ToDictionary(static_cast<CPDF_Object*>(pDict)));
CFX_WideString title = bookmark.GetTitle();
- CFX_ByteString encodedTitle = title.UTF16LE_Encode();
- unsigned long len = encodedTitle.GetLength();
- if (buffer && buflen >= len) {
- FXSYS_memcpy(buffer, encodedTitle.c_str(), len);
- }
- return len;
+ return Utf16EncodeMaybeCopyAndReturnLength(title, buffer, buflen);
}
DLLEXPORT FPDF_BOOKMARK STDCALL FPDFBookmark_Find(FPDF_DOCUMENT document,
@@ -372,24 +378,31 @@ DLLEXPORT FPDF_BOOL STDCALL FPDFLink_GetQuadPoints(FPDF_LINK linkAnnot,
return false;
}
-DLLEXPORT unsigned long STDCALL FPDF_GetMetaText(FPDF_DOCUMENT doc,
+DLLEXPORT unsigned long STDCALL FPDF_GetMetaText(FPDF_DOCUMENT document,
FPDF_BYTESTRING tag,
void* buffer,
unsigned long buflen) {
if (!tag)
return 0;
- CPDF_Document* pDoc = CPDFDocumentFromFPDFDocument(doc);
+ CPDF_Document* pDoc = CPDFDocumentFromFPDFDocument(document);
if (!pDoc)
return 0;
CPDF_Dictionary* pInfo = pDoc->GetInfo();
if (!pInfo)
return 0;
CFX_WideString text = pInfo->GetUnicodeTextFor(tag);
- // Use UTF-16LE encoding
- CFX_ByteString encodedText = text.UTF16LE_Encode();
- unsigned long len = encodedText.GetLength();
- if (buffer && buflen >= len) {
- FXSYS_memcpy(buffer, encodedText.c_str(), len);
- }
- return len;
+ return Utf16EncodeMaybeCopyAndReturnLength(text, buffer, buflen);
+}
+
+DLLEXPORT unsigned long STDCALL FPDF_GetPagelLabel(FPDF_DOCUMENT document,
+ int page_index,
+ void* buffer,
+ unsigned long buflen) {
+ if (page_index < 0)
+ return 0;
+
+ // CPDF_PageLabel can deal with NULL |document|.
+ CPDF_PageLabel label(CPDFDocumentFromFPDFDocument(document));
+ CFX_WideString text = label.GetLabel(page_index);
dsinclair 2016/11/22 14:14:58 Don't need to store text as it's only used once.
Lei Zhang 2016/11/23 01:53:42 Done.
+ return Utf16EncodeMaybeCopyAndReturnLength(text, buffer, buflen);
}
« no previous file with comments | « no previous file | fpdfsdk/fpdfview_c_api_test.c » ('j') | public/fpdf_doc.h » ('J')

Powered by Google App Engine
This is Rietveld 408576698