From d60e9ad5194e13475ccb21575a7c57de1e2e22c4 Mon Sep 17 00:00:00 2001 From: Jane Liu Date: Mon, 26 Jun 2017 11:28:36 -0400 Subject: Changed the return type for annotation APIs Before: When returning FPDF_ANNOTATION, the APIs would take in a FPDF_ANNTOATION* and write the handle of the annotation to it, while returning a boolean as status. This CL: This CL changes the APIs to directly return FPDF_ANNOTATION, which would be null on failure. Also adds more null checks within the annotation APIs. Bug=pdfium:737 Change-Id: I4f77dd1b16d43eab3f16c303598b76591da0dcab Reviewed-on: https://pdfium-review.googlesource.com/6952 Reviewed-by: dsinclair Commit-Queue: Jane Liu --- fpdfsdk/fpdfannot.cpp | 126 +++++++++++++++++++++---------------- fpdfsdk/fpdfannot_embeddertest.cpp | 48 +++++++------- fpdfsdk/fpdfedit_embeddertest.cpp | 4 +- public/fpdf_annot.h | 30 +++------ samples/pdfium_test.cc | 26 +++----- 5 files changed, 116 insertions(+), 118 deletions(-) diff --git a/fpdfsdk/fpdfannot.cpp b/fpdfsdk/fpdfannot.cpp index 6d47b04be2..169c31c236 100644 --- a/fpdfsdk/fpdfannot.cpp +++ b/fpdfsdk/fpdfannot.cpp @@ -6,6 +6,7 @@ #include "public/fpdf_annot.h" +#include #include #include "core/fpdfapi/page/cpdf_form.h" @@ -131,10 +132,6 @@ class CPDF_AnnotContext { CFX_UnownedPtr m_pPage; }; -FPDF_ANNOTATION FPDFAnnotationFromCPDFAnnotContext(CPDF_AnnotContext* pAnnot) { - return static_cast(pAnnot); -} - CPDF_AnnotContext* CPDFAnnotContextFromFPDFAnnotation(FPDF_ANNOTATION annot) { return static_cast(annot); } @@ -150,13 +147,11 @@ FPDFAnnot_IsSupportedSubtype(FPDF_ANNOTATION_SUBTYPE subtype) { subtype == FPDF_ANNOT_UNDERLINE; } -DLLEXPORT FPDF_BOOL STDCALL -FPDFPage_CreateAnnot(FPDF_PAGE page, - FPDF_ANNOTATION_SUBTYPE subtype, - FPDF_ANNOTATION* annot) { +DLLEXPORT FPDF_ANNOTATION STDCALL +FPDFPage_CreateAnnot(FPDF_PAGE page, FPDF_ANNOTATION_SUBTYPE subtype) { CPDF_Page* pPage = CPDFPageFromFPDFPage(page); if (!pPage || !FPDFAnnot_IsSupportedSubtype(subtype)) - return false; + return nullptr; auto pDict = pdfium::MakeUnique( pPage->m_pDocument->GetByteStringPool()); @@ -164,18 +159,15 @@ FPDFPage_CreateAnnot(FPDF_PAGE page, pDict->SetNewFor("Subtype", CPDF_Annot::AnnotSubtypeToString( static_cast(subtype))); - if (annot) { - auto pNewAnnot = - pdfium::MakeUnique(pDict.get(), pPage, nullptr); - *annot = FPDFAnnotationFromCPDFAnnotContext(pNewAnnot.release()); - } + auto pNewAnnot = + pdfium::MakeUnique(pDict.get(), pPage, nullptr); CPDF_Array* pAnnotList = pPage->m_pFormDict->GetArrayFor("Annots"); if (!pAnnotList) pAnnotList = pPage->m_pFormDict->SetNewFor("Annots"); pAnnotList->Add(std::move(pDict)); - return true; + return pNewAnnot.release(); } DLLEXPORT int STDCALL FPDFPage_GetAnnotCount(FPDF_PAGE page) { @@ -187,21 +179,18 @@ DLLEXPORT int STDCALL FPDFPage_GetAnnotCount(FPDF_PAGE page) { return pAnnots ? pAnnots->GetCount() : 0; } -DLLEXPORT FPDF_BOOL STDCALL FPDFPage_GetAnnot(FPDF_PAGE page, - int index, - FPDF_ANNOTATION* annot) { +DLLEXPORT FPDF_ANNOTATION STDCALL FPDFPage_GetAnnot(FPDF_PAGE page, int index) { CPDF_Page* pPage = CPDFPageFromFPDFPage(page); - if (!pPage || !pPage->m_pFormDict || index < 0 || !annot) - return false; + if (!pPage || !pPage->m_pFormDict || index < 0) + return nullptr; CPDF_Array* pAnnots = pPage->m_pFormDict->GetArrayFor("Annots"); if (!pAnnots || static_cast(index) >= pAnnots->GetCount()) - return false; + return nullptr; CPDF_Dictionary* pDict = ToDictionary(pAnnots->GetDirectObjectAt(index)); auto pNewAnnot = pdfium::MakeUnique(pDict, pPage, nullptr); - *annot = FPDFAnnotationFromCPDFAnnotContext(pNewAnnot.release()); - return true; + return pNewAnnot.release(); } DLLEXPORT void STDCALL FPDFPage_CloseAnnot(FPDF_ANNOTATION annot) { @@ -210,6 +199,9 @@ DLLEXPORT void STDCALL FPDFPage_CloseAnnot(FPDF_ANNOTATION annot) { DLLEXPORT FPDF_ANNOTATION_SUBTYPE STDCALL FPDFAnnot_GetSubtype(FPDF_ANNOTATION annot) { + if (!annot) + return FPDF_ANNOT_UNKNOWN; + CPDF_Dictionary* pAnnotDict = CPDFAnnotContextFromFPDFAnnotation(annot)->GetAnnotDict(); if (!pAnnotDict) @@ -225,9 +217,12 @@ DLLEXPORT FPDF_BOOL STDCALL FPDFAnnot_SetColor(FPDF_ANNOTATION annot, unsigned int G, unsigned int B, unsigned int A) { + if (!annot || R > 255 || G > 255 || B > 255 || A > 255) + return false; + CPDF_Dictionary* pAnnotDict = CPDFAnnotContextFromFPDFAnnotation(annot)->GetAnnotDict(); - if (!pAnnotDict || R > 255 || G > 255 || B > 255 || A > 255) + if (!pAnnotDict) return false; // Set the opacity of the annotation. @@ -254,9 +249,12 @@ DLLEXPORT FPDF_BOOL STDCALL FPDFAnnot_GetColor(FPDF_ANNOTATION annot, unsigned int* G, unsigned int* B, unsigned int* A) { + if (!annot || !R || !G || !B || !A) + return false; + CPDF_Dictionary* pAnnotDict = CPDFAnnotContextFromFPDFAnnotation(annot)->GetAnnotDict(); - if (!pAnnotDict || !R || !G || !B || !A) + if (!pAnnotDict) return false; CPDF_Array* pColor = pAnnotDict->GetArrayFor( @@ -323,6 +321,9 @@ FPDFAnnot_SetAttachmentPoints(FPDF_ANNOTATION annot, CPDF_Dictionary* pAnnotDict = CPDFAnnotContextFromFPDFAnnotation(annot)->GetAnnotDict(); + if (!pAnnotDict) + return false; + CPDF_Array* pQuadPoints = pAnnotDict->GetArrayFor("QuadPoints"); if (pQuadPoints) pQuadPoints->Clear(); @@ -340,31 +341,37 @@ FPDFAnnot_SetAttachmentPoints(FPDF_ANNOTATION annot, return true; } -DLLEXPORT FPDF_BOOL STDCALL -FPDFAnnot_GetAttachmentPoints(FPDF_ANNOTATION annot, - FS_QUADPOINTSF* quadPoints) { - if (!annot || !quadPoints || !FPDFAnnot_HasAttachmentPoints(annot)) - return false; +DLLEXPORT FS_QUADPOINTSF STDCALL +FPDFAnnot_GetAttachmentPoints(FPDF_ANNOTATION annot) { + if (!annot || !FPDFAnnot_HasAttachmentPoints(annot)) + return FS_QUADPOINTSF(); - CPDF_Array* pArray = - CPDFAnnotContextFromFPDFAnnotation(annot)->GetAnnotDict()->GetArrayFor( - "QuadPoints"); - if (!pArray) - return false; + CPDF_Dictionary* pAnnotDict = + CPDFAnnotContextFromFPDFAnnotation(annot)->GetAnnotDict(); + if (!pAnnotDict) + return FS_QUADPOINTSF(); - quadPoints->x1 = pArray->GetNumberAt(0); - quadPoints->y1 = pArray->GetNumberAt(1); - quadPoints->x2 = pArray->GetNumberAt(2); - quadPoints->y2 = pArray->GetNumberAt(3); - quadPoints->x3 = pArray->GetNumberAt(4); - quadPoints->y3 = pArray->GetNumberAt(5); - quadPoints->x4 = pArray->GetNumberAt(6); - quadPoints->y4 = pArray->GetNumberAt(7); - return true; + CPDF_Array* pArray = pAnnotDict->GetArrayFor("QuadPoints"); + if (!pArray) + return FS_QUADPOINTSF(); + + FS_QUADPOINTSF quadPoints; + quadPoints.x1 = pArray->GetNumberAt(0); + quadPoints.y1 = pArray->GetNumberAt(1); + quadPoints.x2 = pArray->GetNumberAt(2); + quadPoints.y2 = pArray->GetNumberAt(3); + quadPoints.x3 = pArray->GetNumberAt(4); + quadPoints.y3 = pArray->GetNumberAt(5); + quadPoints.x4 = pArray->GetNumberAt(6); + quadPoints.y4 = pArray->GetNumberAt(7); + return quadPoints; } DLLEXPORT FPDF_BOOL STDCALL FPDFAnnot_SetRect(FPDF_ANNOTATION annot, FS_RECTF rect) { + if (!annot) + return false; + CPDF_Dictionary* pAnnotDict = CPDFAnnotContextFromFPDFAnnotation(annot)->GetAnnotDict(); if (!pAnnotDict) @@ -383,27 +390,33 @@ DLLEXPORT FPDF_BOOL STDCALL FPDFAnnot_SetRect(FPDF_ANNOTATION annot, return true; } -DLLEXPORT FPDF_BOOL STDCALL FPDFAnnot_GetRect(FPDF_ANNOTATION annot, - FS_RECTF* rect) { +DLLEXPORT FS_RECTF STDCALL FPDFAnnot_GetRect(FPDF_ANNOTATION annot) { + if (!annot) + return FS_RECTF(); + CPDF_Dictionary* pAnnotDict = CPDFAnnotContextFromFPDFAnnotation(annot)->GetAnnotDict(); - if (!rect || !pAnnotDict) - return false; + if (!pAnnotDict) + return FS_RECTF(); CFX_FloatRect rt = pAnnotDict->GetRectFor("Rect"); if (rt.IsEmpty()) - return false; - - rect->left = rt.left; - rect->bottom = rt.bottom; - rect->right = rt.right; - rect->top = rt.top; - return true; + return FS_RECTF(); + + FS_RECTF rect; + rect.left = rt.left; + rect.bottom = rt.bottom; + rect.right = rt.right; + rect.top = rt.top; + return rect; } DLLEXPORT FPDF_BOOL STDCALL FPDFAnnot_SetText(FPDF_ANNOTATION annot, FPDFANNOT_TEXTTYPE type, FPDF_WIDESTRING text) { + if (!annot) + return false; + CPDF_Dictionary* pAnnotDict = CPDFAnnotContextFromFPDFAnnotation(annot)->GetAnnotDict(); if (!pAnnotDict) @@ -420,6 +433,9 @@ DLLEXPORT unsigned long STDCALL FPDFAnnot_GetText(FPDF_ANNOTATION annot, FPDFANNOT_TEXTTYPE type, void* buffer, unsigned long buflen) { + if (!annot) + return 0; + CPDF_Dictionary* pAnnotDict = CPDFAnnotContextFromFPDFAnnotation(annot)->GetAnnotDict(); if (!pAnnotDict) diff --git a/fpdfsdk/fpdfannot_embeddertest.cpp b/fpdfsdk/fpdfannot_embeddertest.cpp index b7dee88b78..4d6ae1c6d8 100644 --- a/fpdfsdk/fpdfannot_embeddertest.cpp +++ b/fpdfsdk/fpdfannot_embeddertest.cpp @@ -40,8 +40,8 @@ TEST_F(FPDFAnnotEmbeddertest, ExtractHighlightLongContent) { EXPECT_EQ(1, FPDFPage_GetAnnotCount(page)); // Check that the annotation is of type "highlight". - FPDF_ANNOTATION annot; - ASSERT_TRUE(FPDFPage_GetAnnot(page, 0, &annot)); + FPDF_ANNOTATION annot = FPDFPage_GetAnnot(page, 0); + ASSERT_TRUE(annot); EXPECT_EQ(FPDF_ANNOT_HIGHLIGHT, FPDFAnnot_GetSubtype(annot)); // Check that the annotation color is yellow. @@ -98,8 +98,7 @@ TEST_F(FPDFAnnotEmbeddertest, ExtractHighlightLongContent) { .c_str()); // Check that the quadpoints are correct. - FS_QUADPOINTSF quadpoints; - ASSERT_TRUE(FPDFAnnot_GetAttachmentPoints(annot, &quadpoints)); + FS_QUADPOINTSF quadpoints = FPDFAnnot_GetAttachmentPoints(annot); EXPECT_EQ(115.802643f, quadpoints.x1); EXPECT_EQ(718.913940f, quadpoints.y1); EXPECT_EQ(157.211182f, quadpoints.x4); @@ -119,8 +118,8 @@ TEST_F(FPDFAnnotEmbeddertest, ExtractInkMultiple) { EXPECT_EQ(3, FPDFPage_GetAnnotCount(page)); // Check that the third annotation is of type "ink". - FPDF_ANNOTATION annot; - ASSERT_TRUE(FPDFPage_GetAnnot(page, 2, &annot)); + FPDF_ANNOTATION annot = FPDFPage_GetAnnot(page, 2); + ASSERT_TRUE(annot); EXPECT_EQ(FPDF_ANNOT_INK, FPDFAnnot_GetSubtype(annot)); // Check that the annotation color is blue with opacity. @@ -141,8 +140,7 @@ TEST_F(FPDFAnnotEmbeddertest, ExtractInkMultiple) { // Check that the rectange coordinates are correct. // Note that upon rendering, the rectangle coordinates will be adjusted. - FS_RECTF rect; - ASSERT_TRUE(FPDFAnnot_GetRect(annot, &rect)); + FS_RECTF rect = FPDFAnnot_GetRect(annot); EXPECT_EQ(351.820404f, rect.left); EXPECT_EQ(583.830688f, rect.bottom); EXPECT_EQ(475.336090f, rect.right); @@ -159,8 +157,7 @@ TEST_F(FPDFAnnotEmbeddertest, AddIllegalSubtypeAnnotation) { ASSERT_TRUE(page); // Add an annotation with an illegal subtype. - FPDF_ANNOTATION annot; - ASSERT_FALSE(FPDFPage_CreateAnnot(page, -1, &annot)); + ASSERT_FALSE(FPDFPage_CreateAnnot(page, -1)); UnloadPage(page); } @@ -173,8 +170,8 @@ TEST_F(FPDFAnnotEmbeddertest, AddFirstTextAnnotation) { EXPECT_EQ(0, FPDFPage_GetAnnotCount(page)); // Add a text annotation to the page. - FPDF_ANNOTATION annot; - ASSERT_TRUE(FPDFPage_CreateAnnot(page, FPDF_ANNOT_TEXT, &annot)); + FPDF_ANNOTATION annot = FPDFPage_CreateAnnot(page, FPDF_ANNOT_TEXT); + ASSERT_TRUE(annot); // Check that there is now 1 annotations on this page. EXPECT_EQ(1, FPDFPage_GetAnnotCount(page)); @@ -183,7 +180,8 @@ TEST_F(FPDFAnnotEmbeddertest, AddFirstTextAnnotation) { EXPECT_EQ(FPDF_ANNOT_TEXT, FPDFAnnot_GetSubtype(annot)); FPDFPage_CloseAnnot(annot); - ASSERT_TRUE(FPDFPage_GetAnnot(page, 0, &annot)); + annot = FPDFPage_GetAnnot(page, 0); + ASSERT_TRUE(annot); EXPECT_EQ(FPDF_ANNOT_TEXT, FPDFAnnot_GetSubtype(annot)); // Set the color of the annotation. @@ -213,15 +211,16 @@ TEST_F(FPDFAnnotEmbeddertest, AddFirstTextAnnotation) { EXPECT_EQ(51u, A); // Set the annotation rectangle. - FS_RECTF rect; - EXPECT_FALSE(FPDFAnnot_GetRect(annot, &rect)); + FS_RECTF rect = FPDFAnnot_GetRect(annot); + EXPECT_EQ(0.f, rect.left); + EXPECT_EQ(0.f, rect.right); rect.left = 35; rect.bottom = 150; rect.right = 53; rect.top = 165; ASSERT_TRUE(FPDFAnnot_SetRect(annot, rect)); // Check that the annotation rectangle has been set correctly. - ASSERT_TRUE(FPDFAnnot_GetRect(annot, &rect)); + rect = FPDFAnnot_GetRect(annot); EXPECT_EQ(35.f, rect.left); EXPECT_EQ(150.f, rect.bottom); EXPECT_EQ(53.f, rect.right); @@ -256,10 +255,9 @@ TEST_F(FPDFAnnotEmbeddertest, AddAndSaveUnderlineAnnotation) { // Check that there is a total of one annotation on its first page, and verify // its quadpoints. EXPECT_EQ(1, FPDFPage_GetAnnotCount(page)); - FPDF_ANNOTATION annot; - ASSERT_TRUE(FPDFPage_GetAnnot(page, 0, &annot)); - FS_QUADPOINTSF quadpoints; - ASSERT_TRUE(FPDFAnnot_GetAttachmentPoints(annot, &quadpoints)); + FPDF_ANNOTATION annot = FPDFPage_GetAnnot(page, 0); + ASSERT_TRUE(annot); + FS_QUADPOINTSF quadpoints = FPDFAnnot_GetAttachmentPoints(annot); EXPECT_EQ(115.802643f, quadpoints.x1); EXPECT_EQ(718.913940f, quadpoints.y1); EXPECT_EQ(157.211182f, quadpoints.x4); @@ -267,7 +265,8 @@ TEST_F(FPDFAnnotEmbeddertest, AddAndSaveUnderlineAnnotation) { FPDFPage_CloseAnnot(annot); // Add an underline annotation to the page and set its quadpoints. - ASSERT_TRUE(FPDFPage_CreateAnnot(page, FPDF_ANNOT_UNDERLINE, &annot)); + annot = FPDFPage_CreateAnnot(page, FPDF_ANNOT_UNDERLINE); + ASSERT_TRUE(annot); quadpoints.x1 = 140.802643f; quadpoints.x3 = 140.802643f; ASSERT_TRUE(FPDFAnnot_SetAttachmentPoints(annot, quadpoints)); @@ -294,11 +293,10 @@ TEST_F(FPDFAnnotEmbeddertest, AddAndSaveUnderlineAnnotation) { // Check that the second annotation is an underline annotation and verify // its quadpoints. - FPDF_ANNOTATION new_annot; - ASSERT_TRUE(FPDFPage_GetAnnot(new_page, 1, &new_annot)); + FPDF_ANNOTATION new_annot = FPDFPage_GetAnnot(new_page, 1); + ASSERT_TRUE(new_annot); EXPECT_EQ(FPDF_ANNOT_UNDERLINE, FPDFAnnot_GetSubtype(new_annot)); - FS_QUADPOINTSF new_quadpoints; - ASSERT_TRUE(FPDFAnnot_GetAttachmentPoints(new_annot, &new_quadpoints)); + FS_QUADPOINTSF new_quadpoints = FPDFAnnot_GetAttachmentPoints(new_annot); EXPECT_NEAR(quadpoints.x1, new_quadpoints.x1, 0.001f); EXPECT_NEAR(quadpoints.y1, new_quadpoints.y1, 0.001f); EXPECT_NEAR(quadpoints.x4, new_quadpoints.x4, 0.001f); diff --git a/fpdfsdk/fpdfedit_embeddertest.cpp b/fpdfsdk/fpdfedit_embeddertest.cpp index fcf7e3903b..ad3e0d15a8 100644 --- a/fpdfsdk/fpdfedit_embeddertest.cpp +++ b/fpdfsdk/fpdfedit_embeddertest.cpp @@ -900,12 +900,14 @@ TEST_F(FPDFEditEmbeddertest, TransformAnnot) { ASSERT_TRUE(page); // Add an underline annotation to the page without specifying its rectangle. - ASSERT_TRUE(FPDFPage_CreateAnnot(page, FPDF_ANNOT_UNDERLINE, nullptr)); + FPDF_ANNOTATION annot = FPDFPage_CreateAnnot(page, FPDF_ANNOT_UNDERLINE); + ASSERT_TRUE(annot); // FPDFPage_TransformAnnots() should run without errors when modifying // annotation rectangles. FPDFPage_TransformAnnots(page, 1, 2, 3, 4, 5, 6); + FPDFPage_CloseAnnot(annot); UnloadPage(page); } diff --git a/public/fpdf_annot.h b/public/fpdf_annot.h index bd18898695..0a1646fd5c 100644 --- a/public/fpdf_annot.h +++ b/public/fpdf_annot.h @@ -71,13 +71,10 @@ FPDFAnnot_IsSupportedSubtype(FPDF_ANNOTATION_SUBTYPE subtype); // // page - handle to a page. // subtype - the subtype of the new annotation. -// annot - receives the newly created annotation. // -// Returns true if successful, false otherwise. -DLLEXPORT FPDF_BOOL STDCALL -FPDFPage_CreateAnnot(FPDF_PAGE page, - FPDF_ANNOTATION_SUBTYPE subtype, - FPDF_ANNOTATION* annot); +// Returns a handle to the new annotation object, or NULL on failure. +DLLEXPORT FPDF_ANNOTATION STDCALL +FPDFPage_CreateAnnot(FPDF_PAGE page, FPDF_ANNOTATION_SUBTYPE subtype); // Get the number of annotations in |page|. // @@ -90,12 +87,9 @@ DLLEXPORT int STDCALL FPDFPage_GetAnnotCount(FPDF_PAGE page); // // page - handle to a page. // index - the index of the annotation. -// annot - receives the annotation. // -// Returns true if successful, false otherwise. -DLLEXPORT FPDF_BOOL STDCALL FPDFPage_GetAnnot(FPDF_PAGE page, - int index, - FPDF_ANNOTATION* annot); +// Returns a handle to the annotation object, or NULL on failure. +DLLEXPORT FPDF_ANNOTATION STDCALL FPDFPage_GetAnnot(FPDF_PAGE page, int index); // Close an annotation. Must be called when the annotation returned by // FPDFPage_CreateAnnot() or FPDFPage_GetAnnot() is no longer needed. This @@ -169,12 +163,10 @@ FPDFAnnot_SetAttachmentPoints(FPDF_ANNOTATION annot, FS_QUADPOINTSF quadPoints); // Get the attachment points (i.e. quadpoints) of an annotation. // // annot - handle to an annotation. -// quadPoints - receives the attachment points. // -// Returns true if successful, false otherwise. -DLLEXPORT FPDF_BOOL STDCALL -FPDFAnnot_GetAttachmentPoints(FPDF_ANNOTATION annot, - FS_QUADPOINTSF* quadPoints); +// Returns a quadpoints object, or an empty set of quadpoints on failure. +DLLEXPORT FS_QUADPOINTSF STDCALL +FPDFAnnot_GetAttachmentPoints(FPDF_ANNOTATION annot); // Set the annotation rectangle defining the location of the annotation. // @@ -188,11 +180,9 @@ DLLEXPORT FPDF_BOOL STDCALL FPDFAnnot_SetRect(FPDF_ANNOTATION annot, // Get the annotation rectangle defining the location of the annotation. // // annot - handle to an annotation. -// rect - receives the annotation rectangle. // -// Returns true if successful, false otherwise. -DLLEXPORT FPDF_BOOL STDCALL FPDFAnnot_GetRect(FPDF_ANNOTATION annot, - FS_RECTF* rect); +// Returns a rectangle object, or an empty rectangle on failure. +DLLEXPORT FS_RECTF STDCALL FPDFAnnot_GetRect(FPDF_ANNOTATION annot); // Set the contents of an annotation. // diff --git a/samples/pdfium_test.cc b/samples/pdfium_test.cc index ccd57a7e6a..5a3668f6ce 100644 --- a/samples/pdfium_test.cc +++ b/samples/pdfium_test.cc @@ -277,8 +277,8 @@ void WriteAnnot(FPDF_PAGE page, const char* pdf_name, int num) { for (int i = 0; i < annot_count; i++) { // Retrieve the annotation object and its subtype. fprintf(fp, "Annotation #%d:\n", i + 1); - FPDF_ANNOTATION annot; - if (!FPDFPage_GetAnnot(page, i, &annot)) { + FPDF_ANNOTATION annot = FPDFPage_GetAnnot(page, i); + if (!annot) { fprintf(fp, "Failed to retrieve annotation!\n\n"); continue; } @@ -319,25 +319,17 @@ void WriteAnnot(FPDF_PAGE page, const char* pdf_name, int num) { .c_str()); // Retrieve the annotation's quadpoints if it is a markup annotation. - FS_QUADPOINTSF quadpoints; if (FPDFAnnot_HasAttachmentPoints(annot)) { - if (!FPDFAnnot_GetAttachmentPoints(annot, &quadpoints)) { - fprintf(fp, "Failed to retrieve quadpoints.\n"); - } else { - fprintf(fp, "Quadpoints: (%f, %f), (%f, %f), (%f, %f), (%f, %f)\n", - quadpoints.x1, quadpoints.y1, quadpoints.x2, quadpoints.y2, - quadpoints.x3, quadpoints.y3, quadpoints.x4, quadpoints.y4); - } + FS_QUADPOINTSF quadpoints = FPDFAnnot_GetAttachmentPoints(annot); + fprintf(fp, "Quadpoints: (%f, %f), (%f, %f), (%f, %f), (%f, %f)\n", + quadpoints.x1, quadpoints.y1, quadpoints.x2, quadpoints.y2, + quadpoints.x3, quadpoints.y3, quadpoints.x4, quadpoints.y4); } // Retrieve the annotation's rectangle coordinates. - FS_RECTF rect; - if (!FPDFAnnot_GetRect(annot, &rect)) { - fprintf(fp, "Failed to retrieve rectangle.\n\n"); - } else { - fprintf(fp, "Rectangle: l - %f, b - %f, r - %f, t - %f\n\n", rect.left, - rect.bottom, rect.right, rect.top); - } + FS_RECTF rect = FPDFAnnot_GetRect(annot); + fprintf(fp, "Rectangle: l - %f, b - %f, r - %f, t - %f\n\n", rect.left, + rect.bottom, rect.right, rect.top); } (void)fclose(fp); -- cgit v1.2.3