From df064df7a08e008b3c8e4d56bb0b75da9f014147 Mon Sep 17 00:00:00 2001 From: Lei Zhang Date: Thu, 31 Aug 2017 02:33:27 -0700 Subject: Change APIs to use FPDF_BYTESTRING for keys. Change-Id: I865a9eeb197ea2c1f5480cae32d975909495676d Reviewed-on: https://pdfium-review.googlesource.com/12551 Reviewed-by: dsinclair Commit-Queue: Lei Zhang --- fpdfsdk/fpdfannot.cpp | 40 +++++++++++++++------------------------- 1 file changed, 15 insertions(+), 25 deletions(-) (limited to 'fpdfsdk/fpdfannot.cpp') diff --git a/fpdfsdk/fpdfannot.cpp b/fpdfsdk/fpdfannot.cpp index d6080fd35f..95f0f44af9 100644 --- a/fpdfsdk/fpdfannot.cpp +++ b/fpdfsdk/fpdfannot.cpp @@ -689,7 +689,7 @@ FPDF_EXPORT FPDF_BOOL FPDF_CALLCONV FPDFAnnot_GetRect(FPDF_ANNOTATION annot, } FPDF_EXPORT FPDF_BOOL FPDF_CALLCONV FPDFAnnot_HasKey(FPDF_ANNOTATION annot, - FPDF_WIDESTRING key) { + FPDF_BYTESTRING key) { if (!annot) return false; @@ -698,26 +698,22 @@ FPDF_EXPORT FPDF_BOOL FPDF_CALLCONV FPDFAnnot_HasKey(FPDF_ANNOTATION annot, if (!pAnnotDict) return false; - return pAnnotDict->KeyExist(CFXByteStringFromFPDFWideString(key)); + return pAnnotDict->KeyExist(key); } FPDF_EXPORT FPDF_OBJECT_TYPE FPDF_CALLCONV -FPDFAnnot_GetValueType(FPDF_ANNOTATION annot, FPDF_WIDESTRING key) { +FPDFAnnot_GetValueType(FPDF_ANNOTATION annot, FPDF_BYTESTRING key) { if (!FPDFAnnot_HasKey(annot, key)) return FPDF_OBJECT_UNKNOWN; - CPDF_Object* pObj = - CPDFAnnotContextFromFPDFAnnotation(annot)->GetAnnotDict()->GetObjectFor( - CFXByteStringFromFPDFWideString(key)); - if (!pObj) - return FPDF_OBJECT_UNKNOWN; - - return pObj->GetType(); + auto* pAnnot = CPDFAnnotContextFromFPDFAnnotation(annot); + CPDF_Object* pObj = pAnnot->GetAnnotDict()->GetObjectFor(key); + return pObj ? pObj->GetType() : FPDF_OBJECT_UNKNOWN; } FPDF_EXPORT FPDF_BOOL FPDF_CALLCONV FPDFAnnot_SetStringValue(FPDF_ANNOTATION annot, - FPDF_WIDESTRING key, + FPDF_BYTESTRING key, FPDF_WIDESTRING value) { if (!annot) return false; @@ -727,15 +723,14 @@ FPDFAnnot_SetStringValue(FPDF_ANNOTATION annot, if (!pAnnotDict) return false; - pAnnotDict->SetNewFor(CFXByteStringFromFPDFWideString(key), - CFXByteStringFromFPDFWideString(value), - false); + pAnnotDict->SetNewFor( + key, CFXByteStringFromFPDFWideString(value), false); return true; } FPDF_EXPORT unsigned long FPDF_CALLCONV FPDFAnnot_GetStringValue(FPDF_ANNOTATION annot, - FPDF_WIDESTRING key, + FPDF_BYTESTRING key, void* buffer, unsigned long buflen) { if (!annot) @@ -746,19 +741,17 @@ FPDFAnnot_GetStringValue(FPDF_ANNOTATION annot, if (!pAnnotDict) return 0; - return Utf16EncodeMaybeCopyAndReturnLength( - pAnnotDict->GetUnicodeTextFor(CFXByteStringFromFPDFWideString(key)), - buffer, buflen); + return Utf16EncodeMaybeCopyAndReturnLength(pAnnotDict->GetUnicodeTextFor(key), + buffer, buflen); } FPDF_EXPORT FPDF_ANNOTATION FPDF_CALLCONV -FPDFAnnot_GetLinkedAnnot(FPDF_ANNOTATION annot, FPDF_WIDESTRING key) { +FPDFAnnot_GetLinkedAnnot(FPDF_ANNOTATION annot, FPDF_BYTESTRING key) { CPDF_AnnotContext* pAnnot = CPDFAnnotContextFromFPDFAnnotation(annot); if (!pAnnot || !pAnnot->GetAnnotDict()) return nullptr; - CPDF_Dictionary* pLinkedDict = - pAnnot->GetAnnotDict()->GetDictFor(CFXByteStringFromFPDFWideString(key)); + CPDF_Dictionary* pLinkedDict = pAnnot->GetAnnotDict()->GetDictFor(key); if (!pLinkedDict || pLinkedDict->GetStringFor("Type") != "Annot") return nullptr; @@ -773,10 +766,7 @@ FPDF_EXPORT int FPDF_CALLCONV FPDFAnnot_GetFlags(FPDF_ANNOTATION annot) { CPDF_Dictionary* pAnnotDict = CPDFAnnotContextFromFPDFAnnotation(annot)->GetAnnotDict(); - if (!pAnnotDict) - return FPDF_ANNOT_FLAG_NONE; - - return pAnnotDict->GetIntegerFor("F"); + return pAnnotDict ? pAnnotDict->GetIntegerFor("F") : FPDF_ANNOT_FLAG_NONE; } FPDF_EXPORT FPDF_BOOL FPDF_CALLCONV FPDFAnnot_SetFlags(FPDF_ANNOTATION annot, -- cgit v1.2.3