diff options
author | Lei Zhang <thestig@chromium.org> | 2018-02-05 18:28:38 +0000 |
---|---|---|
committer | Chromium commit bot <commit-bot@chromium.org> | 2018-02-05 18:28:38 +0000 |
commit | a21d593e202cbef9a0641d0123917ac3b8d73ee6 (patch) | |
tree | d72c9134cdbac10de2fca436b056c596b3aa3adf /samples | |
parent | 2896cfaff519136d7d770ca048b448e6b3ad9324 (diff) | |
download | pdfium-a21d593e202cbef9a0641d0123917ac3b8d73ee6.tar.xz |
Add FPDFAnnotationDeleter for use with std::unique_ptr.
Use it in existing code where appropriate.
BUG=chromium:808269
Change-Id: I55b67db05267f4f05a98c9bf8bbd43f6524cbc65
Reviewed-on: https://pdfium-review.googlesource.com/25210
Reviewed-by: dsinclair <dsinclair@chromium.org>
Commit-Queue: Lei Zhang <thestig@chromium.org>
Diffstat (limited to 'samples')
-rw-r--r-- | samples/pdfium_test.cc | 42 |
1 files changed, 21 insertions, 21 deletions
diff --git a/samples/pdfium_test.cc b/samples/pdfium_test.cc index 1549bd7ed4..d7648f6bde 100644 --- a/samples/pdfium_test.cc +++ b/samples/pdfium_test.cc @@ -352,26 +352,27 @@ 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 = FPDFPage_GetAnnot(page, i); + std::unique_ptr<void, FPDFAnnotationDeleter> annot( + FPDFPage_GetAnnot(page, i)); if (!annot) { fprintf(fp, "Failed to retrieve annotation!\n\n"); continue; } - FPDF_ANNOTATION_SUBTYPE subtype = FPDFAnnot_GetSubtype(annot); + FPDF_ANNOTATION_SUBTYPE subtype = FPDFAnnot_GetSubtype(annot.get()); fprintf(fp, "Subtype: %s\n", AnnotSubtypeToCString(subtype)); // Retrieve the annotation flags. fprintf(fp, "Flags set: %s\n", - AnnotFlagsToString(FPDFAnnot_GetFlags(annot)).c_str()); + AnnotFlagsToString(FPDFAnnot_GetFlags(annot.get())).c_str()); // Retrieve the annotation's object count and object types. - const int obj_count = FPDFAnnot_GetObjectCount(annot); + const int obj_count = FPDFAnnot_GetObjectCount(annot.get()); fprintf(fp, "Number of objects: %d\n", obj_count); if (obj_count > 0) { fprintf(fp, "Object types: "); for (int j = 0; j < obj_count; ++j) { const char* type = PageObjectTypeToCString( - FPDFPageObj_GetType(FPDFAnnot_GetObject(annot, j))); + FPDFPageObj_GetType(FPDFAnnot_GetObject(annot.get(), j))); fprintf(fp, "%s ", type); } fprintf(fp, "\n"); @@ -382,40 +383,41 @@ void WriteAnnot(FPDF_PAGE page, const char* pdf_name, int num) { unsigned int G; unsigned int B; unsigned int A; - if (!FPDFAnnot_GetColor(annot, FPDFANNOT_COLORTYPE_Color, &R, &G, &B, &A)) { - fprintf(fp, "Failed to retrieve color.\n"); - } else { + if (FPDFAnnot_GetColor(annot.get(), FPDFANNOT_COLORTYPE_Color, &R, &G, &B, + &A)) { fprintf(fp, "Color in RGBA: %d %d %d %d\n", R, G, B, A); - } - if (!FPDFAnnot_GetColor(annot, FPDFANNOT_COLORTYPE_InteriorColor, &R, &G, - &B, &A)) { - fprintf(fp, "Failed to retrieve interior color.\n"); } else { + fprintf(fp, "Failed to retrieve color.\n"); + } + if (FPDFAnnot_GetColor(annot.get(), FPDFANNOT_COLORTYPE_InteriorColor, &R, + &G, &B, &A)) { fprintf(fp, "Interior color in RGBA: %d %d %d %d\n", R, G, B, A); + } else { + fprintf(fp, "Failed to retrieve interior color.\n"); } // Retrieve the annotation's contents and author. static constexpr char kContentsKey[] = "Contents"; static constexpr char kAuthorKey[] = "T"; unsigned long len = - FPDFAnnot_GetStringValue(annot, kContentsKey, nullptr, 0); + FPDFAnnot_GetStringValue(annot.get(), kContentsKey, nullptr, 0); std::vector<char> buf(len); - FPDFAnnot_GetStringValue(annot, kContentsKey, buf.data(), len); + FPDFAnnot_GetStringValue(annot.get(), kContentsKey, buf.data(), len); fprintf(fp, "Content: %ls\n", GetPlatformWString(reinterpret_cast<unsigned short*>(buf.data())) .c_str()); - len = FPDFAnnot_GetStringValue(annot, kAuthorKey, nullptr, 0); + len = FPDFAnnot_GetStringValue(annot.get(), kAuthorKey, nullptr, 0); buf.clear(); buf.resize(len); - FPDFAnnot_GetStringValue(annot, kAuthorKey, buf.data(), len); + FPDFAnnot_GetStringValue(annot.get(), kAuthorKey, buf.data(), len); fprintf(fp, "Author: %ls\n", GetPlatformWString(reinterpret_cast<unsigned short*>(buf.data())) .c_str()); // Retrieve the annotation's quadpoints if it is a markup annotation. - if (FPDFAnnot_HasAttachmentPoints(annot)) { + if (FPDFAnnot_HasAttachmentPoints(annot.get())) { FS_QUADPOINTSF quadpoints; - if (FPDFAnnot_GetAttachmentPoints(annot, &quadpoints)) { + if (FPDFAnnot_GetAttachmentPoints(annot.get(), &quadpoints)) { fprintf(fp, "Quadpoints: (%.3f, %.3f), (%.3f, %.3f), (%.3f, %.3f), (%.3f, " "%.3f)\n", @@ -428,14 +430,12 @@ void WriteAnnot(FPDF_PAGE page, const char* pdf_name, int num) { // Retrieve the annotation's rectangle coordinates. FS_RECTF rect; - if (FPDFAnnot_GetRect(annot, &rect)) { + if (FPDFAnnot_GetRect(annot.get(), &rect)) { fprintf(fp, "Rectangle: l - %.3f, b - %.3f, r - %.3f, t - %.3f\n\n", rect.left, rect.bottom, rect.right, rect.top); } else { fprintf(fp, "Failed to retrieve annotation rectangle.\n"); } - - FPDFPage_CloseAnnot(annot); } (void)fclose(fp); |