diff options
23 files changed, 235 insertions, 272 deletions
@@ -167,6 +167,7 @@ jumbo_static_library("pdfium") { "fpdfsdk/ipdfsdk_pauseadapter.cpp", "fpdfsdk/ipdfsdk_pauseadapter.h", "public/cpp/fpdf_deleters.h", + "public/cpp/fpdf_scopers.h", "public/fpdf_annot.h", "public/fpdf_attachment.h", "public/fpdf_catalog.h", diff --git a/core/fpdfapi/edit/cpdf_creator_embeddertest.cpp b/core/fpdfapi/edit/cpdf_creator_embeddertest.cpp index 86cd67b121..1913c4ba19 100644 --- a/core/fpdfapi/edit/cpdf_creator_embeddertest.cpp +++ b/core/fpdfapi/edit/cpdf_creator_embeddertest.cpp @@ -7,6 +7,7 @@ #include <vector> #include "core/fxcrt/fx_system.h" +#include "public/cpp/fpdf_scopers.h" #include "public/fpdf_annot.h" #include "public/fpdf_edit.h" #include "public/fpdfview.h" @@ -27,8 +28,7 @@ TEST_F(CPDF_CreatorEmbedderTest, SavedDocsAreEqualAfterParse) { ASSERT_GE(1, FPDF_GetPageCount(document())); FPDF_PAGE page = LoadPage(0); ASSERT_TRUE(page); - std::unique_ptr<void, FPDFBitmapDeleter> bitmap = - RenderLoadedPageWithFlags(page, FPDF_ANNOT); + ScopedFPDFBitmap bitmap = RenderLoadedPageWithFlags(page, FPDF_ANNOT); EXPECT_EQ(595, FPDFBitmap_GetWidth(bitmap.get())); EXPECT_EQ(842, FPDFBitmap_GetHeight(bitmap.get())); UnloadPage(page); diff --git a/core/fpdfapi/page/cpdf_stitchfunc_embeddertest.cpp b/core/fpdfapi/page/cpdf_stitchfunc_embeddertest.cpp index ebc71926a0..9b3b18d425 100644 --- a/core/fpdfapi/page/cpdf_stitchfunc_embeddertest.cpp +++ b/core/fpdfapi/page/cpdf_stitchfunc_embeddertest.cpp @@ -4,6 +4,7 @@ #include <memory> +#include "public/cpp/fpdf_scopers.h" #include "testing/embedder_test.h" #include "testing/gtest/include/gtest/gtest.h" @@ -16,7 +17,7 @@ TEST_F(FPDFPageFuncEmbeddertest, Bug_551460) { EXPECT_TRUE(OpenDocument("bug_551460.pdf")); FPDF_PAGE page = LoadPage(0); ASSERT_TRUE(page); - std::unique_ptr<void, FPDFBitmapDeleter> bitmap = RenderLoadedPage(page); + ScopedFPDFBitmap bitmap = RenderLoadedPage(page); CompareBitmap(bitmap.get(), 612, 792, "1940568c9ba33bac5d0b1ee9558c76b3"); UnloadPage(page); } diff --git a/core/fpdfapi/parser/cpdf_security_handler_embeddertest.cpp b/core/fpdfapi/parser/cpdf_security_handler_embeddertest.cpp index 4937b3d8d1..95f1dd4977 100644 --- a/core/fpdfapi/parser/cpdf_security_handler_embeddertest.cpp +++ b/core/fpdfapi/parser/cpdf_security_handler_embeddertest.cpp @@ -6,6 +6,7 @@ #include <string> #include "core/fxcrt/fx_system.h" +#include "public/cpp/fpdf_scopers.h" #include "public/fpdf_edit.h" #include "public/fpdf_save.h" #include "public/fpdfview.h" @@ -61,7 +62,7 @@ TEST_F(CPDFSecurityHandlerEmbeddertest, PasswordAfterGenerateSave) { EXPECT_TRUE(FPDFPath_SetFillColor(red_rect, 255, 0, 0, 255)); EXPECT_TRUE(FPDFPath_SetDrawMode(red_rect, FPDF_FILLMODE_ALTERNATE, 0)); FPDFPage_InsertObject(page, red_rect); - std::unique_ptr<void, FPDFBitmapDeleter> bitmap = RenderLoadedPage(page); + ScopedFPDFBitmap bitmap = RenderLoadedPage(page); CompareBitmap(bitmap.get(), 612, 792, md5); EXPECT_TRUE(FPDFPage_GenerateContent(page)); SetWholeFileAvailable(); diff --git a/core/fpdfapi/parser/fpdf_parser_decode_embeddertest.cpp b/core/fpdfapi/parser/fpdf_parser_decode_embeddertest.cpp index 0a7dde9b05..7054db99d7 100644 --- a/core/fpdfapi/parser/fpdf_parser_decode_embeddertest.cpp +++ b/core/fpdfapi/parser/fpdf_parser_decode_embeddertest.cpp @@ -7,6 +7,7 @@ #include <string> #include "core/fpdfapi/parser/fpdf_parser_decode.h" +#include "public/cpp/fpdf_scopers.h" #include "testing/embedder_test.h" #include "testing/gtest/include/gtest/gtest.h" #include "testing/test_support.h" @@ -94,7 +95,7 @@ TEST_F(FPDFParserDecodeEmbeddertest, Bug_552046) { EXPECT_TRUE(OpenDocument("bug_552046.pdf")); FPDF_PAGE page = LoadPage(0); ASSERT_TRUE(page); - std::unique_ptr<void, FPDFBitmapDeleter> bitmap = RenderLoadedPage(page); + ScopedFPDFBitmap bitmap = RenderLoadedPage(page); CompareBitmap(bitmap.get(), 612, 792, "1940568c9ba33bac5d0b1ee9558c76b3"); UnloadPage(page); } @@ -105,7 +106,7 @@ TEST_F(FPDFParserDecodeEmbeddertest, Bug_555784) { EXPECT_TRUE(OpenDocument("bug_555784.pdf")); FPDF_PAGE page = LoadPage(0); ASSERT_TRUE(page); - std::unique_ptr<void, FPDFBitmapDeleter> bitmap = RenderLoadedPage(page); + ScopedFPDFBitmap bitmap = RenderLoadedPage(page); CompareBitmap(bitmap.get(), 612, 792, "1940568c9ba33bac5d0b1ee9558c76b3"); UnloadPage(page); } @@ -116,7 +117,7 @@ TEST_F(FPDFParserDecodeEmbeddertest, Bug_455199) { EXPECT_TRUE(OpenDocument("bug_455199.pdf")); FPDF_PAGE page = LoadPage(0); ASSERT_TRUE(page); - std::unique_ptr<void, FPDFBitmapDeleter> bitmap = RenderLoadedPage(page); + ScopedFPDFBitmap bitmap = RenderLoadedPage(page); #if _FX_PLATFORM_ == _FX_PLATFORM_APPLE_ const char kExpectedMd5sum[] = "b90475ca64d1348c3bf5e2b77ad9187a"; #elif _FX_PLATFORM_ == _FX_PLATFORM_WINDOWS_ diff --git a/core/fpdfapi/render/fpdf_render_loadimage_embeddertest.cpp b/core/fpdfapi/render/fpdf_render_loadimage_embeddertest.cpp index 588b974e29..48d7ea3399 100644 --- a/core/fpdfapi/render/fpdf_render_loadimage_embeddertest.cpp +++ b/core/fpdfapi/render/fpdf_render_loadimage_embeddertest.cpp @@ -4,6 +4,7 @@ #include <memory> +#include "public/cpp/fpdf_scopers.h" #include "testing/embedder_test.h" #include "testing/gtest/include/gtest/gtest.h" @@ -15,7 +16,7 @@ TEST_F(FPDFRenderLoadImageEmbeddertest, Bug_554151) { EXPECT_TRUE(OpenDocument("bug_554151.pdf")); FPDF_PAGE page = LoadPage(0); ASSERT_TRUE(page); - std::unique_ptr<void, FPDFBitmapDeleter> bitmap = RenderLoadedPage(page); + ScopedFPDFBitmap bitmap = RenderLoadedPage(page); CompareBitmap(bitmap.get(), 612, 792, "a14d7ee573c1b2456d7bf6b7762823cf"); UnloadPage(page); } @@ -25,7 +26,7 @@ TEST_F(FPDFRenderLoadImageEmbeddertest, Bug_557223) { EXPECT_TRUE(OpenDocument("bug_557223.pdf")); FPDF_PAGE page = LoadPage(0); ASSERT_TRUE(page); - std::unique_ptr<void, FPDFBitmapDeleter> bitmap = RenderLoadedPage(page); + ScopedFPDFBitmap bitmap = RenderLoadedPage(page); CompareBitmap(bitmap.get(), 24, 24, "dc0ea1b743c2edb22c597cadc8537f7b"); UnloadPage(page); } @@ -35,7 +36,7 @@ TEST_F(FPDFRenderLoadImageEmbeddertest, Bug_603518) { EXPECT_TRUE(OpenDocument("bug_603518.pdf")); FPDF_PAGE page = LoadPage(0); EXPECT_NE(nullptr, page); - std::unique_ptr<void, FPDFBitmapDeleter> bitmap = RenderLoadedPage(page); + ScopedFPDFBitmap bitmap = RenderLoadedPage(page); CompareBitmap(bitmap.get(), 749, 749, "b9e75190cdc5edf0069a408744ca07dc"); UnloadPage(page); } diff --git a/core/fpdfapi/render/fpdf_render_pattern_embeddertest.cpp b/core/fpdfapi/render/fpdf_render_pattern_embeddertest.cpp index 00b0933b71..31ce246365 100644 --- a/core/fpdfapi/render/fpdf_render_pattern_embeddertest.cpp +++ b/core/fpdfapi/render/fpdf_render_pattern_embeddertest.cpp @@ -4,6 +4,7 @@ #include <memory> +#include "public/cpp/fpdf_scopers.h" #include "testing/embedder_test.h" #include "testing/gtest/include/gtest/gtest.h" @@ -14,7 +15,7 @@ TEST_F(FPDFRenderPatternEmbeddertest, LoadError_547706) { EXPECT_TRUE(OpenDocument("bug_547706.pdf")); FPDF_PAGE page = LoadPage(0); ASSERT_TRUE(page); - std::unique_ptr<void, FPDFBitmapDeleter> bitmap = RenderLoadedPage(page); + ScopedFPDFBitmap bitmap = RenderLoadedPage(page); CompareBitmap(bitmap.get(), 612, 792, "1940568c9ba33bac5d0b1ee9558c76b3"); UnloadPage(page); } diff --git a/core/fxcodec/codec/fx_codec_embeddertest.cpp b/core/fxcodec/codec/fx_codec_embeddertest.cpp index 40a1662839..3773cb21bc 100644 --- a/core/fxcodec/codec/fx_codec_embeddertest.cpp +++ b/core/fxcodec/codec/fx_codec_embeddertest.cpp @@ -4,6 +4,7 @@ #include <memory> +#include "public/cpp/fpdf_scopers.h" #include "testing/embedder_test.h" #include "testing/gtest/include/gtest/gtest.h" @@ -15,7 +16,7 @@ TEST_F(FXCodecEmbeddertest, Bug_631912) { EXPECT_TRUE(OpenDocument("bug_631912.pdf")); FPDF_PAGE page = LoadPage(0); ASSERT_TRUE(page); - std::unique_ptr<void, FPDFBitmapDeleter> bitmap = RenderLoadedPage(page); + ScopedFPDFBitmap bitmap = RenderLoadedPage(page); CompareBitmap(bitmap.get(), 691, 432, "24d75af646f8772c5ee7ced260452ae4"); UnloadPage(page); } diff --git a/core/fxge/fx_ge_text_embeddertest.cpp b/core/fxge/fx_ge_text_embeddertest.cpp index 362ccf5dc1..e47ed5f7c6 100644 --- a/core/fxge/fx_ge_text_embeddertest.cpp +++ b/core/fxge/fx_ge_text_embeddertest.cpp @@ -4,6 +4,7 @@ #include <memory> +#include "public/cpp/fpdf_scopers.h" #include "testing/embedder_test.h" #include "testing/gtest/include/gtest/gtest.h" @@ -14,7 +15,7 @@ TEST_F(FXGETextEmbedderTest, BadItalic) { EXPECT_TRUE(OpenDocument("bug_601362.pdf")); FPDF_PAGE page = LoadPage(0); ASSERT_TRUE(page); - std::unique_ptr<void, FPDFBitmapDeleter> bitmap = RenderLoadedPage(page); + ScopedFPDFBitmap bitmap = RenderLoadedPage(page); EXPECT_EQ(612, FPDFBitmap_GetWidth(bitmap.get())); EXPECT_EQ(792, FPDFBitmap_GetHeight(bitmap.get())); UnloadPage(page); diff --git a/fpdfsdk/fpdf_annot_embeddertest.cpp b/fpdfsdk/fpdf_annot_embeddertest.cpp index 9d5c5548b6..13dc117929 100644 --- a/fpdfsdk/fpdf_annot_embeddertest.cpp +++ b/fpdfsdk/fpdf_annot_embeddertest.cpp @@ -8,7 +8,7 @@ #include <vector> #include "core/fxcrt/fx_system.h" -#include "public/cpp/fpdf_deleters.h" +#include "public/cpp/fpdf_scopers.h" #include "public/fpdf_annot.h" #include "public/fpdf_edit.h" #include "public/fpdfview.h" @@ -38,8 +38,7 @@ TEST_F(FPDFAnnotEmbeddertest, RenderAnnotWithOnlyRolloverAP) { // normal appearance defined, only its rollover appearance. In this case, its // normal appearance should be generated, allowing the highlight annotation to // still display. - std::unique_ptr<void, FPDFBitmapDeleter> bitmap = - RenderLoadedPageWithFlags(page, FPDF_ANNOT); + ScopedFPDFBitmap bitmap = RenderLoadedPageWithFlags(page, FPDF_ANNOT); CompareBitmap(bitmap.get(), 612, 792, "dc98f06da047bd8aabfa99562d2cbd1e"); UnloadPage(page); @@ -52,8 +51,7 @@ TEST_F(FPDFAnnotEmbeddertest, RenderMultilineMarkupAnnotWithoutAP) { FPDF_PAGE page = LoadPage(0); ASSERT_TRUE(page); - std::unique_ptr<void, FPDFBitmapDeleter> bitmap = - RenderLoadedPageWithFlags(page, FPDF_ANNOT); + ScopedFPDFBitmap bitmap = RenderLoadedPageWithFlags(page, FPDF_ANNOT); CompareBitmap(bitmap.get(), 595, 842, md5_hash); UnloadPage(page); @@ -73,8 +71,7 @@ TEST_F(FPDFAnnotEmbeddertest, ExtractHighlightLongContent) { // Check that the annotation is of type "highlight". { - std::unique_ptr<void, FPDFAnnotationDeleter> annot( - FPDFPage_GetAnnot(page, 0)); + ScopedFPDFAnnotation annot(FPDFPage_GetAnnot(page, 0)); ASSERT_TRUE(annot); EXPECT_EQ(FPDF_ANNOT_HIGHLIGHT, FPDFAnnot_GetSubtype(annot.get())); @@ -157,8 +154,7 @@ TEST_F(FPDFAnnotEmbeddertest, ExtractInkMultiple) { { // Check that the third annotation is of type "ink". - std::unique_ptr<void, FPDFAnnotationDeleter> annot( - FPDFPage_GetAnnot(page, 2)); + ScopedFPDFAnnotation annot(FPDFPage_GetAnnot(page, 2)); ASSERT_TRUE(annot); EXPECT_EQ(FPDF_ANNOT_INK, FPDFAnnot_GetSubtype(annot.get())); @@ -211,8 +207,7 @@ TEST_F(FPDFAnnotEmbeddertest, AddFirstTextAnnotation) { { // Add a text annotation to the page. - std::unique_ptr<void, FPDFAnnotationDeleter> annot( - FPDFPage_CreateAnnot(page, FPDF_ANNOT_TEXT)); + ScopedFPDFAnnotation annot(FPDFPage_CreateAnnot(page, FPDF_ANNOT_TEXT)); ASSERT_TRUE(annot); // Check that there is now 1 annotations on this page. @@ -223,8 +218,7 @@ TEST_F(FPDFAnnotEmbeddertest, AddFirstTextAnnotation) { } { - std::unique_ptr<void, FPDFAnnotationDeleter> annot( - FPDFPage_GetAnnot(page, 0)); + ScopedFPDFAnnotation annot(FPDFPage_GetAnnot(page, 0)); ASSERT_TRUE(annot); EXPECT_EQ(FPDF_ANNOT_TEXT, FPDFAnnot_GetSubtype(annot.get())); @@ -300,8 +294,7 @@ TEST_F(FPDFAnnotEmbeddertest, AddAndSaveUnderlineAnnotation) { EXPECT_EQ(1, FPDFPage_GetAnnotCount(page)); FS_QUADPOINTSF quadpoints; { - std::unique_ptr<void, FPDFAnnotationDeleter> annot( - FPDFPage_GetAnnot(page, 0)); + ScopedFPDFAnnotation annot(FPDFPage_GetAnnot(page, 0)); ASSERT_TRUE(annot); ASSERT_TRUE(FPDFAnnot_GetAttachmentPoints(annot.get(), 0, &quadpoints)); EXPECT_EQ(115.802643f, quadpoints.x1); @@ -312,7 +305,7 @@ TEST_F(FPDFAnnotEmbeddertest, AddAndSaveUnderlineAnnotation) { // Add an underline annotation to the page and set its quadpoints. { - std::unique_ptr<void, FPDFAnnotationDeleter> annot( + ScopedFPDFAnnotation annot( FPDFPage_CreateAnnot(page, FPDF_ANNOT_UNDERLINE)); ASSERT_TRUE(annot); quadpoints.x1 = 140.802643f; @@ -337,8 +330,7 @@ TEST_F(FPDFAnnotEmbeddertest, AddAndSaveUnderlineAnnotation) { { // Check that the second annotation is an underline annotation and verify // its quadpoints. - std::unique_ptr<void, FPDFAnnotationDeleter> new_annot( - FPDFPage_GetAnnot(page, 1)); + ScopedFPDFAnnotation new_annot(FPDFPage_GetAnnot(page, 1)); ASSERT_TRUE(new_annot); EXPECT_EQ(FPDF_ANNOT_UNDERLINE, FPDFAnnot_GetSubtype(new_annot.get())); FS_QUADPOINTSF new_quadpoints; @@ -462,8 +454,7 @@ TEST_F(FPDFAnnotEmbeddertest, ModifyRectQuadpointsWithAP) { // Check that the original file renders correctly. { - std::unique_ptr<void, FPDFBitmapDeleter> bitmap = - RenderLoadedPageWithFlags(page, FPDF_ANNOT); + ScopedFPDFBitmap bitmap = RenderLoadedPageWithFlags(page, FPDF_ANNOT); CompareBitmap(bitmap.get(), 612, 792, md5_original); } @@ -472,8 +463,7 @@ TEST_F(FPDFAnnotEmbeddertest, ModifyRectQuadpointsWithAP) { // Retrieve the highlight annotation which has its AP stream already defined. { - std::unique_ptr<void, FPDFAnnotationDeleter> annot( - FPDFPage_GetAnnot(page, 0)); + ScopedFPDFAnnotation annot(FPDFPage_GetAnnot(page, 0)); ASSERT_TRUE(annot); EXPECT_EQ(FPDF_ANNOT_HIGHLIGHT, FPDFAnnot_GetSubtype(annot.get())); @@ -504,8 +494,7 @@ TEST_F(FPDFAnnotEmbeddertest, ModifyRectQuadpointsWithAP) { // Check that updating quadpoints does not change the annotation's position. { - std::unique_ptr<void, FPDFBitmapDeleter> bitmap = - RenderLoadedPageWithFlags(page, FPDF_ANNOT); + ScopedFPDFBitmap bitmap = RenderLoadedPageWithFlags(page, FPDF_ANNOT); CompareBitmap(bitmap.get(), 612, 792, md5_original); } @@ -526,15 +515,13 @@ TEST_F(FPDFAnnotEmbeddertest, ModifyRectQuadpointsWithAP) { // Check that updating the rectangle changes the annotation's position. { - std::unique_ptr<void, FPDFBitmapDeleter> bitmap = - RenderLoadedPageWithFlags(page, FPDF_ANNOT); + ScopedFPDFBitmap bitmap = RenderLoadedPageWithFlags(page, FPDF_ANNOT); CompareBitmap(bitmap.get(), 612, 792, md5_modified_highlight); } { // Retrieve the square annotation which has its AP stream already defined. - std::unique_ptr<void, FPDFAnnotationDeleter> annot( - FPDFPage_GetAnnot(page, 2)); + ScopedFPDFAnnotation annot(FPDFPage_GetAnnot(page, 2)); ASSERT_TRUE(annot); EXPECT_EQ(FPDF_ANNOT_SQUARE, FPDFAnnot_GetSubtype(annot.get())); @@ -548,8 +535,7 @@ TEST_F(FPDFAnnotEmbeddertest, ModifyRectQuadpointsWithAP) { // Check that updating the rectangle changes the square annotation's // position. - std::unique_ptr<void, FPDFBitmapDeleter> bitmap = - RenderLoadedPageWithFlags(page, FPDF_ANNOT); + ScopedFPDFBitmap bitmap = RenderLoadedPageWithFlags(page, FPDF_ANNOT); CompareBitmap(bitmap.get(), 612, 792, md5_modified_square); } @@ -562,8 +548,7 @@ TEST_F(FPDFAnnotEmbeddertest, CountAttachmentPoints) { FPDF_PAGE page = LoadPage(0); ASSERT_TRUE(page); { - std::unique_ptr<void, FPDFAnnotationDeleter> annot( - FPDFPage_GetAnnot(page, 0)); + ScopedFPDFAnnotation annot(FPDFPage_GetAnnot(page, 0)); ASSERT_TRUE(annot); // This is a three line annotation. @@ -589,22 +574,19 @@ TEST_F(FPDFAnnotEmbeddertest, RemoveAnnotation) { // Check that the annotations have the expected rectangle coordinates. { - std::unique_ptr<void, FPDFAnnotationDeleter> annot( - FPDFPage_GetAnnot(page, 0)); + ScopedFPDFAnnotation annot(FPDFPage_GetAnnot(page, 0)); ASSERT_TRUE(FPDFAnnot_GetRect(annot.get(), &rect)); EXPECT_NEAR(86.1971f, rect.left, 0.001f); } { - std::unique_ptr<void, FPDFAnnotationDeleter> annot( - FPDFPage_GetAnnot(page, 1)); + ScopedFPDFAnnotation annot(FPDFPage_GetAnnot(page, 1)); ASSERT_TRUE(FPDFAnnot_GetRect(annot.get(), &rect)); EXPECT_NEAR(149.8127f, rect.left, 0.001f); } { - std::unique_ptr<void, FPDFAnnotationDeleter> annot( - FPDFPage_GetAnnot(page, 2)); + ScopedFPDFAnnotation annot(FPDFPage_GetAnnot(page, 2)); ASSERT_TRUE(FPDFAnnot_GetRect(annot.get(), &rect)); EXPECT_NEAR(351.8204f, rect.left, 0.001f); } @@ -643,15 +625,13 @@ TEST_F(FPDFAnnotEmbeddertest, RemoveAnnotation) { // Check that the remaining 2 annotations are the original 1st and 3rd ones // by verifying their rectangle coordinates. { - std::unique_ptr<void, FPDFAnnotationDeleter> annot( - FPDFPage_GetAnnot(new_page, 0)); + ScopedFPDFAnnotation annot(FPDFPage_GetAnnot(new_page, 0)); ASSERT_TRUE(FPDFAnnot_GetRect(annot.get(), &rect)); EXPECT_NEAR(86.1971f, rect.left, 0.001f); } { - std::unique_ptr<void, FPDFAnnotationDeleter> annot( - FPDFPage_GetAnnot(new_page, 1)); + ScopedFPDFAnnotation annot(FPDFPage_GetAnnot(new_page, 1)); ASSERT_TRUE(FPDFAnnot_GetRect(annot.get(), &rect)); EXPECT_NEAR(351.8204f, rect.left, 0.001f); } @@ -680,15 +660,13 @@ TEST_F(FPDFAnnotEmbeddertest, AddAndModifyPath) { // Check that the page renders correctly. { - std::unique_ptr<void, FPDFBitmapDeleter> bitmap = - RenderLoadedPageWithFlags(page, FPDF_ANNOT); + ScopedFPDFBitmap bitmap = RenderLoadedPageWithFlags(page, FPDF_ANNOT); CompareBitmap(bitmap.get(), 595, 842, md5_original); } { // Retrieve the stamp annotation which has its AP stream already defined. - std::unique_ptr<void, FPDFAnnotationDeleter> annot( - FPDFPage_GetAnnot(page, 0)); + ScopedFPDFAnnotation annot(FPDFPage_GetAnnot(page, 0)); ASSERT_TRUE(annot); // Check that this annotation has one path object and retrieve it. @@ -706,8 +684,7 @@ TEST_F(FPDFAnnotEmbeddertest, AddAndModifyPath) { // Check that the page with the modified annotation renders correctly. { - std::unique_ptr<void, FPDFBitmapDeleter> bitmap = - RenderLoadedPageWithFlags(page, FPDF_ANNOT); + ScopedFPDFBitmap bitmap = RenderLoadedPageWithFlags(page, FPDF_ANNOT); CompareBitmap(bitmap.get(), 595, 842, md5_modified_path); } @@ -726,8 +703,7 @@ TEST_F(FPDFAnnotEmbeddertest, AddAndModifyPath) { // Check that the page with an annotation with two paths renders correctly. { - std::unique_ptr<void, FPDFBitmapDeleter> bitmap = - RenderLoadedPageWithFlags(page, FPDF_ANNOT); + ScopedFPDFBitmap bitmap = RenderLoadedPageWithFlags(page, FPDF_ANNOT); CompareBitmap(bitmap.get(), 595, 842, md5_two_paths); } @@ -739,8 +715,7 @@ TEST_F(FPDFAnnotEmbeddertest, AddAndModifyPath) { // Check that the page renders the same as before. { - std::unique_ptr<void, FPDFBitmapDeleter> bitmap = - RenderLoadedPageWithFlags(page, FPDF_ANNOT); + ScopedFPDFBitmap bitmap = RenderLoadedPageWithFlags(page, FPDF_ANNOT); CompareBitmap(bitmap.get(), 595, 842, md5_modified_path); } @@ -748,8 +723,7 @@ TEST_F(FPDFAnnotEmbeddertest, AddAndModifyPath) { { // Create another stamp annotation and set its annotation rectangle. - std::unique_ptr<void, FPDFAnnotationDeleter> annot( - FPDFPage_CreateAnnot(page, FPDF_ANNOT_STAMP)); + ScopedFPDFAnnotation annot(FPDFPage_CreateAnnot(page, FPDF_ANNOT_STAMP)); ASSERT_TRUE(annot); rect.left = 200.f; rect.bottom = 400.f; @@ -791,8 +765,7 @@ TEST_F(FPDFAnnotEmbeddertest, AddAndModifyPath) { EXPECT_EQ(3, FPDFPage_GetAnnotCount(page)); { - std::unique_ptr<void, FPDFAnnotationDeleter> annot( - FPDFPage_GetAnnot(page, 2)); + ScopedFPDFAnnotation annot(FPDFPage_GetAnnot(page, 2)); ASSERT_TRUE(annot); EXPECT_EQ(1, FPDFAnnot_GetObjectCount(annot.get())); @@ -817,15 +790,13 @@ TEST_F(FPDFAnnotEmbeddertest, ModifyAnnotationFlags) { // Check that the page renders correctly. { - std::unique_ptr<void, FPDFBitmapDeleter> bitmap = - RenderLoadedPageWithFlags(page, FPDF_ANNOT); + ScopedFPDFBitmap bitmap = RenderLoadedPageWithFlags(page, FPDF_ANNOT); CompareBitmap(bitmap.get(), 612, 792, "dc98f06da047bd8aabfa99562d2cbd1e"); } { // Retrieve the annotation. - std::unique_ptr<void, FPDFAnnotationDeleter> annot( - FPDFPage_GetAnnot(page, 0)); + ScopedFPDFAnnotation annot(FPDFPage_GetAnnot(page, 0)); ASSERT_TRUE(annot); // Check that the original flag values are as expected. @@ -842,8 +813,7 @@ TEST_F(FPDFAnnotEmbeddertest, ModifyAnnotationFlags) { // Check that the page renders correctly without rendering the annotation. { - std::unique_ptr<void, FPDFBitmapDeleter> bitmap = - RenderLoadedPageWithFlags(page, FPDF_ANNOT); + ScopedFPDFBitmap bitmap = RenderLoadedPageWithFlags(page, FPDF_ANNOT); CompareBitmap(bitmap.get(), 612, 792, "1940568c9ba33bac5d0b1ee9558c76b3"); } @@ -858,8 +828,7 @@ TEST_F(FPDFAnnotEmbeddertest, ModifyAnnotationFlags) { // Check that the page renders correctly as before. { - std::unique_ptr<void, FPDFBitmapDeleter> bitmap = - RenderLoadedPageWithFlags(page, FPDF_ANNOT); + ScopedFPDFBitmap bitmap = RenderLoadedPageWithFlags(page, FPDF_ANNOT); CompareBitmap(bitmap.get(), 612, 792, "dc98f06da047bd8aabfa99562d2cbd1e"); } } @@ -886,8 +855,7 @@ TEST_F(FPDFAnnotEmbeddertest, AddAndModifyImage) { // Check that the page renders correctly. { - std::unique_ptr<void, FPDFBitmapDeleter> bitmap = - RenderLoadedPageWithFlags(page, FPDF_ANNOT); + ScopedFPDFBitmap bitmap = RenderLoadedPageWithFlags(page, FPDF_ANNOT); CompareBitmap(bitmap.get(), 595, 842, md5_original); } @@ -896,8 +864,7 @@ TEST_F(FPDFAnnotEmbeddertest, AddAndModifyImage) { { // Create a stamp annotation and set its annotation rectangle. - std::unique_ptr<void, FPDFAnnotationDeleter> annot( - FPDFPage_CreateAnnot(page, FPDF_ANNOT_STAMP)); + ScopedFPDFAnnotation annot(FPDFPage_CreateAnnot(page, FPDF_ANNOT_STAMP)); ASSERT_TRUE(annot); FS_RECTF rect; rect.left = 200.f; @@ -922,15 +889,13 @@ TEST_F(FPDFAnnotEmbeddertest, AddAndModifyImage) { // Check that the page renders correctly with the new image object. { - std::unique_ptr<void, FPDFBitmapDeleter> bitmap = - RenderLoadedPageWithFlags(page, FPDF_ANNOT); + ScopedFPDFBitmap bitmap = RenderLoadedPageWithFlags(page, FPDF_ANNOT); CompareBitmap(bitmap.get(), 595, 842, md5_new_image); } { // Retrieve the newly added stamp annotation and its image object. - std::unique_ptr<void, FPDFAnnotationDeleter> annot( - FPDFPage_GetAnnot(page, 2)); + ScopedFPDFAnnotation annot(FPDFPage_GetAnnot(page, 2)); ASSERT_TRUE(annot); EXPECT_EQ(1, FPDFAnnot_GetObjectCount(annot.get())); FPDF_PAGEOBJECT image_object = FPDFAnnot_GetObject(annot.get(), 0); @@ -971,15 +936,13 @@ TEST_F(FPDFAnnotEmbeddertest, AddAndModifyText) { // Check that the page renders correctly. { - std::unique_ptr<void, FPDFBitmapDeleter> bitmap = - RenderLoadedPageWithFlags(page, FPDF_ANNOT); + ScopedFPDFBitmap bitmap = RenderLoadedPageWithFlags(page, FPDF_ANNOT); CompareBitmap(bitmap.get(), 595, 842, md5_original); } { // Create a stamp annotation and set its annotation rectangle. - std::unique_ptr<void, FPDFAnnotationDeleter> annot( - FPDFPage_CreateAnnot(page, FPDF_ANNOT_STAMP)); + ScopedFPDFAnnotation annot(FPDFPage_CreateAnnot(page, FPDF_ANNOT_STAMP)); ASSERT_TRUE(annot); FS_RECTF rect; rect.left = 200.f; @@ -1002,15 +965,13 @@ TEST_F(FPDFAnnotEmbeddertest, AddAndModifyText) { // Check that the page renders correctly with the new text object. { - std::unique_ptr<void, FPDFBitmapDeleter> bitmap = - RenderLoadedPageWithFlags(page, FPDF_ANNOT); + ScopedFPDFBitmap bitmap = RenderLoadedPageWithFlags(page, FPDF_ANNOT); CompareBitmap(bitmap.get(), 595, 842, md5_new_text); } { // Retrieve the newly added stamp annotation and its text object. - std::unique_ptr<void, FPDFAnnotationDeleter> annot( - FPDFPage_GetAnnot(page, 2)); + ScopedFPDFAnnotation annot(FPDFPage_GetAnnot(page, 2)); ASSERT_TRUE(annot); EXPECT_EQ(1, FPDFAnnot_GetObjectCount(annot.get())); FPDF_PAGEOBJECT text_object = FPDFAnnot_GetObject(annot.get(), 0); @@ -1025,16 +986,14 @@ TEST_F(FPDFAnnotEmbeddertest, AddAndModifyText) { // Check that the page renders correctly with the modified text object. { - std::unique_ptr<void, FPDFBitmapDeleter> bitmap = - RenderLoadedPageWithFlags(page, FPDF_ANNOT); + ScopedFPDFBitmap bitmap = RenderLoadedPageWithFlags(page, FPDF_ANNOT); CompareBitmap(bitmap.get(), 595, 842, md5_modified_text); } // Remove the new annotation, and check that the page renders as before. EXPECT_TRUE(FPDFPage_RemoveAnnot(page, 2)); { - std::unique_ptr<void, FPDFBitmapDeleter> bitmap = - RenderLoadedPageWithFlags(page, FPDF_ANNOT); + ScopedFPDFBitmap bitmap = RenderLoadedPageWithFlags(page, FPDF_ANNOT); CompareBitmap(bitmap.get(), 595, 842, md5_original); } @@ -1052,8 +1011,7 @@ TEST_F(FPDFAnnotEmbeddertest, GetSetStringValue) { { // Retrieve the first annotation. - std::unique_ptr<void, FPDFAnnotationDeleter> annot( - FPDFPage_GetAnnot(page, 0)); + ScopedFPDFAnnotation annot(FPDFPage_GetAnnot(page, 0)); ASSERT_TRUE(annot); // Check that a non-existent key does not exist. @@ -1107,8 +1065,7 @@ TEST_F(FPDFAnnotEmbeddertest, GetSetStringValue) { page = LoadSavedPage(0); VerifySavedRendering(page, 595, 842, md5); { - std::unique_ptr<void, FPDFAnnotationDeleter> new_annot( - FPDFPage_GetAnnot(page, 0)); + ScopedFPDFAnnotation new_annot(FPDFPage_GetAnnot(page, 0)); // Check that the string value of the modified date is the newly-set value. EXPECT_EQ(FPDF_OBJECT_STRING, @@ -1133,8 +1090,7 @@ TEST_F(FPDFAnnotEmbeddertest, GetSetAP) { { // Retrieve the first annotation. - std::unique_ptr<void, FPDFAnnotationDeleter> annot( - FPDFPage_GetAnnot(page, 0)); + ScopedFPDFAnnotation annot(FPDFPage_GetAnnot(page, 0)); ASSERT_TRUE(annot); // Check that the string value of an AP returns the expected length. @@ -1230,8 +1186,7 @@ TEST_F(FPDFAnnotEmbeddertest, GetSetAP) { OpenSavedDocument(); page = LoadSavedPage(0); { - std::unique_ptr<void, FPDFAnnotationDeleter> new_annot( - FPDFPage_GetAnnot(page, 0)); + ScopedFPDFAnnotation new_annot(FPDFPage_GetAnnot(page, 0)); // Check that the new annotation value is equal to the value we set before // saving. @@ -1258,8 +1213,7 @@ TEST_F(FPDFAnnotEmbeddertest, RemoveOptionalAP) { { // Retrieve the first annotation. - std::unique_ptr<void, FPDFAnnotationDeleter> annot( - FPDFPage_GetAnnot(page, 0)); + ScopedFPDFAnnotation annot(FPDFPage_GetAnnot(page, 0)); ASSERT_TRUE(annot); // Set Down AP. Normal AP is already set. @@ -1295,8 +1249,7 @@ TEST_F(FPDFAnnotEmbeddertest, RemoveRequiredAP) { { // Retrieve the first annotation. - std::unique_ptr<void, FPDFAnnotationDeleter> annot( - FPDFPage_GetAnnot(page, 0)); + ScopedFPDFAnnotation annot(FPDFPage_GetAnnot(page, 0)); ASSERT_TRUE(annot); // Set Down AP. Normal AP is already set. @@ -1331,8 +1284,7 @@ TEST_F(FPDFAnnotEmbeddertest, ExtractLinkedAnnotations) { { // Retrieve the highlight annotation which has its popup defined. - std::unique_ptr<void, FPDFAnnotationDeleter> annot( - FPDFPage_GetAnnot(page, 0)); + ScopedFPDFAnnotation annot(FPDFPage_GetAnnot(page, 0)); ASSERT_TRUE(annot); EXPECT_EQ(FPDF_ANNOT_HIGHLIGHT, FPDFAnnot_GetSubtype(annot.get())); EXPECT_EQ(0, FPDFPage_GetAnnotIndex(page, annot.get())); @@ -1342,7 +1294,7 @@ TEST_F(FPDFAnnotEmbeddertest, ExtractLinkedAnnotations) { FPDFAnnot_GetValueType(annot.get(), kPopupKey)); // Retrieve and verify the popup of the highlight annotation. - std::unique_ptr<void, FPDFAnnotationDeleter> popup( + ScopedFPDFAnnotation popup( FPDFAnnot_GetLinkedAnnot(annot.get(), kPopupKey)); ASSERT_TRUE(popup); EXPECT_EQ(FPDF_ANNOT_POPUP, FPDFAnnot_GetSubtype(popup.get())); @@ -1378,8 +1330,7 @@ TEST_F(FPDFAnnotEmbeddertest, GetFormFieldFlagsTextField) { { // Retrieve the first annotation: user-editable text field. - std::unique_ptr<void, FPDFAnnotationDeleter> annot( - FPDFPage_GetAnnot(page, 0)); + ScopedFPDFAnnotation annot(FPDFPage_GetAnnot(page, 0)); ASSERT_TRUE(annot); // Check that the flag values are as expected. @@ -1389,8 +1340,7 @@ TEST_F(FPDFAnnotEmbeddertest, GetFormFieldFlagsTextField) { { // Retrieve the second annotation: read-only text field. - std::unique_ptr<void, FPDFAnnotationDeleter> annot( - FPDFPage_GetAnnot(page, 1)); + ScopedFPDFAnnotation annot(FPDFPage_GetAnnot(page, 1)); ASSERT_TRUE(annot); // Check that the flag values are as expected. @@ -1409,8 +1359,7 @@ TEST_F(FPDFAnnotEmbeddertest, GetFormFieldFlagsComboBox) { { // Retrieve the first annotation: user-editable combobox. - std::unique_ptr<void, FPDFAnnotationDeleter> annot( - FPDFPage_GetAnnot(page, 0)); + ScopedFPDFAnnotation annot(FPDFPage_GetAnnot(page, 0)); ASSERT_TRUE(annot); // Check that the flag values are as expected. @@ -1422,8 +1371,7 @@ TEST_F(FPDFAnnotEmbeddertest, GetFormFieldFlagsComboBox) { { // Retrieve the second annotation: regular combobox. - std::unique_ptr<void, FPDFAnnotationDeleter> annot( - FPDFPage_GetAnnot(page, 1)); + ScopedFPDFAnnotation annot(FPDFPage_GetAnnot(page, 1)); ASSERT_TRUE(annot); // Check that the flag values are as expected. @@ -1435,8 +1383,7 @@ TEST_F(FPDFAnnotEmbeddertest, GetFormFieldFlagsComboBox) { { // Retrieve the third annotation: read-only combobox. - std::unique_ptr<void, FPDFAnnotationDeleter> annot( - FPDFPage_GetAnnot(page, 2)); + ScopedFPDFAnnotation annot(FPDFPage_GetAnnot(page, 2)); ASSERT_TRUE(annot); // Check that the flag values are as expected. @@ -1471,7 +1418,7 @@ TEST_F(FPDFAnnotEmbeddertest, GetFormAnnotAndCheckFlagsTextField) { { // Retrieve user-editable text field annotation. - std::unique_ptr<void, FPDFAnnotationDeleter> annot( + ScopedFPDFAnnotation annot( FPDFAnnot_GetFormFieldAtPoint(form_handle(), page, 105, 118)); ASSERT_TRUE(annot); @@ -1482,7 +1429,7 @@ TEST_F(FPDFAnnotEmbeddertest, GetFormAnnotAndCheckFlagsTextField) { { // Retrieve read-only text field annotation. - std::unique_ptr<void, FPDFAnnotationDeleter> annot( + ScopedFPDFAnnotation annot( FPDFAnnot_GetFormFieldAtPoint(form_handle(), page, 105, 202)); ASSERT_TRUE(annot); @@ -1502,7 +1449,7 @@ TEST_F(FPDFAnnotEmbeddertest, GetFormAnnotAndCheckFlagsComboBox) { { // Retrieve user-editable combobox annotation. - std::unique_ptr<void, FPDFAnnotationDeleter> annot( + ScopedFPDFAnnotation annot( FPDFAnnot_GetFormFieldAtPoint(form_handle(), page, 102, 363)); ASSERT_TRUE(annot); @@ -1515,7 +1462,7 @@ TEST_F(FPDFAnnotEmbeddertest, GetFormAnnotAndCheckFlagsComboBox) { { // Retrieve regular combobox annotation. - std::unique_ptr<void, FPDFAnnotationDeleter> annot( + ScopedFPDFAnnotation annot( FPDFAnnot_GetFormFieldAtPoint(form_handle(), page, 102, 413)); ASSERT_TRUE(annot); @@ -1528,7 +1475,7 @@ TEST_F(FPDFAnnotEmbeddertest, GetFormAnnotAndCheckFlagsComboBox) { { // Retrieve read-only combobox annotation. - std::unique_ptr<void, FPDFAnnotationDeleter> annot( + ScopedFPDFAnnotation annot( FPDFAnnot_GetFormFieldAtPoint(form_handle(), page, 102, 513)); ASSERT_TRUE(annot); diff --git a/fpdfsdk/fpdf_edit_embeddertest.cpp b/fpdfsdk/fpdf_edit_embeddertest.cpp index 3da57ab737..0604cdbe71 100644 --- a/fpdfsdk/fpdf_edit_embeddertest.cpp +++ b/fpdfsdk/fpdf_edit_embeddertest.cpp @@ -15,7 +15,7 @@ #include "core/fpdfapi/parser/cpdf_stream.h" #include "core/fxcrt/fx_system.h" #include "fpdfsdk/cpdfsdk_helpers.h" -#include "public/cpp/fpdf_deleters.h" +#include "public/cpp/fpdf_scopers.h" #include "public/fpdf_annot.h" #include "public/fpdf_edit.h" #include "public/fpdfview.h" @@ -192,7 +192,7 @@ TEST_F(FPDFEditEmbeddertest, RasterizePDF) { const char kAllBlackMd5sum[] = "5708fc5c4a8bd0abde99c8e8f0390615"; // Get the bitmap for the original document/ - std::unique_ptr<void, FPDFBitmapDeleter> orig_bitmap; + ScopedFPDFBitmap orig_bitmap; { EXPECT_TRUE(OpenDocument("black.pdf")); FPDF_PAGE orig_page = LoadPage(0); @@ -243,8 +243,7 @@ TEST_F(FPDFEditEmbeddertest, AddPaths) { EXPECT_TRUE(FPDFPath_SetDrawMode(red_rect, FPDF_FILLMODE_ALTERNATE, 0)); FPDFPage_InsertObject(page, red_rect); { - std::unique_ptr<void, FPDFBitmapDeleter> page_bitmap = - RenderPageWithFlags(page, nullptr, 0); + ScopedFPDFBitmap page_bitmap = RenderPageWithFlags(page, nullptr, 0); CompareBitmap(page_bitmap.get(), 612, 792, "66d02eaa6181e2c069ce2ea99beda497"); } @@ -307,8 +306,7 @@ TEST_F(FPDFEditEmbeddertest, AddPaths) { EXPECT_TRUE(FPDFPath_SetDrawMode(green_rect, FPDF_FILLMODE_WINDING, 0)); FPDFPage_InsertObject(page, green_rect); { - std::unique_ptr<void, FPDFBitmapDeleter> page_bitmap = - RenderPageWithFlags(page, nullptr, 0); + ScopedFPDFBitmap page_bitmap = RenderPageWithFlags(page, nullptr, 0); CompareBitmap(page_bitmap.get(), 612, 792, "7b0b87604594e773add528fae567a558"); } @@ -348,8 +346,7 @@ TEST_F(FPDFEditEmbeddertest, AddPaths) { FPDFPage_InsertObject(page, black_path); { - std::unique_ptr<void, FPDFBitmapDeleter> page_bitmap = - RenderPageWithFlags(page, nullptr, 0); + ScopedFPDFBitmap page_bitmap = RenderPageWithFlags(page, nullptr, 0); CompareBitmap(page_bitmap.get(), 612, 792, "eadc8020a14dfcf091da2688733d8806"); } @@ -367,8 +364,7 @@ TEST_F(FPDFEditEmbeddertest, AddPaths) { FPDFPage_InsertObject(page, blue_path); const char kLastMD5[] = "9823e1a21bd9b72b6a442ba4f12af946"; { - std::unique_ptr<void, FPDFBitmapDeleter> page_bitmap = - RenderPageWithFlags(page, nullptr, 0); + ScopedFPDFBitmap page_bitmap = RenderPageWithFlags(page, nullptr, 0); CompareBitmap(page_bitmap.get(), 612, 792, kLastMD5); } @@ -396,8 +392,7 @@ TEST_F(FPDFEditEmbeddertest, RemovePageObject) { #else const char kOriginalMD5[] = "2baa4c0e1758deba1b9c908e1fbd04ed"; #endif - std::unique_ptr<void, FPDFBitmapDeleter> page_bitmap = - RenderPageWithFlags(page, nullptr, 0); + ScopedFPDFBitmap page_bitmap = RenderPageWithFlags(page, nullptr, 0); CompareBitmap(page_bitmap.get(), 200, 200, kOriginalMD5); } @@ -416,8 +411,7 @@ TEST_F(FPDFEditEmbeddertest, RemovePageObject) { #else const char kRemovedMD5[] = "b76df015fe88009c3c342395df96abf1"; #endif - std::unique_ptr<void, FPDFBitmapDeleter> page_bitmap = - RenderPageWithFlags(page, nullptr, 0); + ScopedFPDFBitmap page_bitmap = RenderPageWithFlags(page, nullptr, 0); CompareBitmap(page_bitmap.get(), 200, 200, kRemovedMD5); } ASSERT_EQ(1, FPDFPage_CountObjects(page)); @@ -441,8 +435,7 @@ TEST_F(FPDFEditEmbeddertest, RemoveMarkedObjectsPrime) { #else const char kOriginalMD5[] = "2edc6e70d54889aa0c0b7bdf3e168f86"; #endif - std::unique_ptr<void, FPDFBitmapDeleter> page_bitmap = - RenderPageWithFlags(page, nullptr, 0); + ScopedFPDFBitmap page_bitmap = RenderPageWithFlags(page, nullptr, 0); CompareBitmap(page_bitmap.get(), 200, 200, kOriginalMD5); } @@ -526,8 +519,7 @@ TEST_F(FPDFEditEmbeddertest, RemoveMarkedObjectsPrime) { #else const char kNonPrimesMD5[] = "33d9c45bec41ead92a295e252f6b7922"; #endif - std::unique_ptr<void, FPDFBitmapDeleter> page_bitmap = - RenderPageWithFlags(page, nullptr, 0); + ScopedFPDFBitmap page_bitmap = RenderPageWithFlags(page, nullptr, 0); CompareBitmap(page_bitmap.get(), 200, 200, kNonPrimesMD5); } @@ -601,8 +593,7 @@ TEST_F(FPDFEditEmbeddertest, AddAndRemovePaths) { // Render the blank page and verify it's a blank bitmap. const char kBlankMD5[] = "1940568c9ba33bac5d0b1ee9558c76b3"; { - std::unique_ptr<void, FPDFBitmapDeleter> page_bitmap = - RenderPageWithFlags(page, nullptr, 0); + ScopedFPDFBitmap page_bitmap = RenderPageWithFlags(page, nullptr, 0); CompareBitmap(page_bitmap.get(), 612, 792, kBlankMD5); } ASSERT_EQ(0, FPDFPage_CountObjects(page)); @@ -615,8 +606,7 @@ TEST_F(FPDFEditEmbeddertest, AddAndRemovePaths) { FPDFPage_InsertObject(page, red_rect); const char kRedRectangleMD5[] = "66d02eaa6181e2c069ce2ea99beda497"; { - std::unique_ptr<void, FPDFBitmapDeleter> page_bitmap = - RenderPageWithFlags(page, nullptr, 0); + ScopedFPDFBitmap page_bitmap = RenderPageWithFlags(page, nullptr, 0); CompareBitmap(page_bitmap.get(), 612, 792, kRedRectangleMD5); } EXPECT_EQ(1, FPDFPage_CountObjects(page)); @@ -625,8 +615,7 @@ TEST_F(FPDFEditEmbeddertest, AddAndRemovePaths) { // back to a blank one. EXPECT_TRUE(FPDFPage_RemoveObject(page, red_rect)); { - std::unique_ptr<void, FPDFBitmapDeleter> page_bitmap = - RenderPageWithFlags(page, nullptr, 0); + ScopedFPDFBitmap page_bitmap = RenderPageWithFlags(page, nullptr, 0); CompareBitmap(page_bitmap.get(), 612, 792, kBlankMD5); } EXPECT_EQ(0, FPDFPage_CountObjects(page)); @@ -687,7 +676,7 @@ TEST_F(FPDFEditEmbeddertest, PathOnTopOfText) { FPDFPage_InsertObject(page, black_path); // Render and check the result. Text is slightly different on Mac. - std::unique_ptr<void, FPDFBitmapDeleter> bitmap = RenderLoadedPage(page); + ScopedFPDFBitmap bitmap = RenderLoadedPage(page); #if _FX_PLATFORM_ == _FX_PLATFORM_APPLE_ const char md5[] = "f9e6fa74230f234286bfcada9f7606d8"; #else @@ -715,7 +704,7 @@ TEST_F(FPDFEditEmbeddertest, EditOverExistingContent) { EXPECT_TRUE(FPDFPath_SetDrawMode(red_rect, FPDF_FILLMODE_ALTERNATE, 0)); FPDFPage_InsertObject(page, red_rect); - std::unique_ptr<void, FPDFBitmapDeleter> bitmap = RenderLoadedPage(page); + ScopedFPDFBitmap bitmap = RenderLoadedPage(page); CompareBitmap(bitmap.get(), 612, 792, "ad04e5bd0f471a9a564fb034bd0fb073"); EXPECT_TRUE(FPDFPage_GenerateContent(page)); @@ -742,8 +731,7 @@ TEST_F(FPDFEditEmbeddertest, EditOverExistingContent) { FPDFPage_InsertObject(saved_page, green_rect2); const char kLastMD5[] = "4b5b00f824620f8c9b8801ebb98e1cdd"; { - std::unique_ptr<void, FPDFBitmapDeleter> new_bitmap = - RenderSavedPage(saved_page); + ScopedFPDFBitmap new_bitmap = RenderSavedPage(saved_page); CompareBitmap(new_bitmap.get(), 612, 792, kLastMD5); } EXPECT_TRUE(FPDFPage_GenerateContent(saved_page)); @@ -770,8 +758,7 @@ TEST_F(FPDFEditEmbeddertest, AddStrokedPaths) { EXPECT_TRUE(FPDFPath_SetDrawMode(rect, 0, 1)); FPDFPage_InsertObject(page, rect); { - std::unique_ptr<void, FPDFBitmapDeleter> page_bitmap = - RenderPageWithFlags(page, nullptr, 0); + ScopedFPDFBitmap page_bitmap = RenderPageWithFlags(page, nullptr, 0); CompareBitmap(page_bitmap.get(), 612, 792, "64bd31f862a89e0a9e505a5af6efd506"); } @@ -787,8 +774,7 @@ TEST_F(FPDFEditEmbeddertest, AddStrokedPaths) { EXPECT_TRUE(FPDFPath_SetDrawMode(check, 0, 1)); FPDFPage_InsertObject(page, check); { - std::unique_ptr<void, FPDFBitmapDeleter> page_bitmap = - RenderPageWithFlags(page, nullptr, 0); + ScopedFPDFBitmap page_bitmap = RenderPageWithFlags(page, nullptr, 0); CompareBitmap(page_bitmap.get(), 612, 792, "4b6f3b9d25c4e194821217d5016c3724"); } @@ -805,8 +791,7 @@ TEST_F(FPDFEditEmbeddertest, AddStrokedPaths) { EXPECT_TRUE(FPDFPath_SetDrawMode(path, FPDF_FILLMODE_ALTERNATE, 1)); FPDFPage_InsertObject(page, path); { - std::unique_ptr<void, FPDFBitmapDeleter> page_bitmap = - RenderPageWithFlags(page, nullptr, 0); + ScopedFPDFBitmap page_bitmap = RenderPageWithFlags(page, nullptr, 0); CompareBitmap(page_bitmap.get(), 612, 792, "ff3e6a22326754944cc6e56609acd73b"); } @@ -827,8 +812,7 @@ TEST_F(FPDFEditEmbeddertest, AddStandardFontText) { FPDFPageObj_Transform(text_object1, 1, 0, 0, 1, 20, 20); FPDFPage_InsertObject(page, text_object1); { - std::unique_ptr<void, FPDFBitmapDeleter> page_bitmap = - RenderPageWithFlags(page, nullptr, 0); + ScopedFPDFBitmap page_bitmap = RenderPageWithFlags(page, nullptr, 0); #if _FX_PLATFORM_ == _FX_PLATFORM_APPLE_ const char md5[] = "a4dddc1a3930fa694bbff9789dab4161"; #else @@ -847,8 +831,7 @@ TEST_F(FPDFEditEmbeddertest, AddStandardFontText) { FPDFPageObj_Transform(text_object2, 1, 0, 0, 1, 100, 600); FPDFPage_InsertObject(page, text_object2); { - std::unique_ptr<void, FPDFBitmapDeleter> page_bitmap = - RenderPageWithFlags(page, nullptr, 0); + ScopedFPDFBitmap page_bitmap = RenderPageWithFlags(page, nullptr, 0); #if _FX_PLATFORM_ == _FX_PLATFORM_APPLE_ const char md5_2[] = "a5c4ace4c6f27644094813fe1441a21c"; #elif _FX_PLATFORM_ == _FX_PLATFORM_WINDOWS_ @@ -869,8 +852,7 @@ TEST_F(FPDFEditEmbeddertest, AddStandardFontText) { FPDFPageObj_Transform(text_object3, 1, 1.5, 2, 0.5, 200, 200); FPDFPage_InsertObject(page, text_object3); { - std::unique_ptr<void, FPDFBitmapDeleter> page_bitmap = - RenderPageWithFlags(page, nullptr, 0); + ScopedFPDFBitmap page_bitmap = RenderPageWithFlags(page, nullptr, 0); #if _FX_PLATFORM_ == _FX_PLATFORM_APPLE_ const char md5_3[] = "40b3ef04f915ff4c4208948001763544"; #elif _FX_PLATFORM_ == _FX_PLATFORM_WINDOWS_ @@ -888,8 +870,7 @@ TEST_F(FPDFEditEmbeddertest, AddStandardFontText) { TEST_F(FPDFEditEmbeddertest, GraphicsData) { // New page - std::unique_ptr<void, FPDFPageDeleter> page( - FPDFPage_New(CreateNewDocument(), 0, 612, 792)); + ScopedFPDFPage page(FPDFPage_New(CreateNewDocument(), 0, 612, 792)); // Create a rect with nontrivial graphics FPDF_PAGEOBJECT rect1 = FPDFPageObj_CreateNewRect(10, 10, 100, 100); @@ -958,8 +939,7 @@ TEST_F(FPDFEditEmbeddertest, DoubleGenerating) { // Check the bitmap { - std::unique_ptr<void, FPDFBitmapDeleter> page_bitmap = - RenderPageWithFlags(page, nullptr, 0); + ScopedFPDFBitmap page_bitmap = RenderPageWithFlags(page, nullptr, 0); CompareBitmap(page_bitmap.get(), 612, 792, "5384da3406d62360ffb5cac4476fff1c"); } @@ -971,8 +951,7 @@ TEST_F(FPDFEditEmbeddertest, DoubleGenerating) { // Check that bitmap displays changed content { - std::unique_ptr<void, FPDFBitmapDeleter> page_bitmap = - RenderPageWithFlags(page, nullptr, 0); + ScopedFPDFBitmap page_bitmap = RenderPageWithFlags(page, nullptr, 0); CompareBitmap(page_bitmap.get(), 612, 792, "2e51656f5073b0bee611d9cd086aa09c"); } @@ -981,8 +960,7 @@ TEST_F(FPDFEditEmbeddertest, DoubleGenerating) { EXPECT_TRUE(FPDFPage_GenerateContent(page)); EXPECT_EQ(3, static_cast<int>(graphics_dict->GetCount())); { - std::unique_ptr<void, FPDFBitmapDeleter> page_bitmap = - RenderPageWithFlags(page, nullptr, 0); + ScopedFPDFBitmap page_bitmap = RenderPageWithFlags(page, nullptr, 0); CompareBitmap(page_bitmap.get(), 612, 792, "2e51656f5073b0bee611d9cd086aa09c"); } @@ -1014,7 +992,7 @@ TEST_F(FPDFEditEmbeddertest, LoadSimpleType1Font) { CPDF_Font::GetStockFont(cpdf_doc(), "Times-Bold"); const uint8_t* data = stock_font->GetFont()->GetFontData(); const uint32_t size = stock_font->GetFont()->GetSize(); - std::unique_ptr<void, FPDFFontDeleter> font( + ScopedFPDFFont font( FPDFText_LoadFont(document(), data, size, FPDF_FONT_TYPE1, false)); ASSERT_TRUE(font.get()); CPDF_Font* typed_font = static_cast<CPDF_Font*>(font.get()); @@ -1043,7 +1021,7 @@ TEST_F(FPDFEditEmbeddertest, LoadSimpleTrueTypeFont) { const CPDF_Font* stock_font = CPDF_Font::GetStockFont(cpdf_doc(), "Courier"); const uint8_t* data = stock_font->GetFont()->GetFontData(); const uint32_t size = stock_font->GetFont()->GetSize(); - std::unique_ptr<void, FPDFFontDeleter> font( + ScopedFPDFFont font( FPDFText_LoadFont(document(), data, size, FPDF_FONT_TRUETYPE, false)); ASSERT_TRUE(font.get()); CPDF_Font* typed_font = static_cast<CPDF_Font*>(font.get()); @@ -1073,7 +1051,7 @@ TEST_F(FPDFEditEmbeddertest, LoadCIDType0Font) { CPDF_Font::GetStockFont(cpdf_doc(), "Times-Roman"); const uint8_t* data = stock_font->GetFont()->GetFontData(); const uint32_t size = stock_font->GetFont()->GetSize(); - std::unique_ptr<void, FPDFFontDeleter> font( + ScopedFPDFFont font( FPDFText_LoadFont(document(), data, size, FPDF_FONT_TYPE1, 1)); ASSERT_TRUE(font.get()); CPDF_Font* typed_font = static_cast<CPDF_Font*>(font.get()); @@ -1115,7 +1093,7 @@ TEST_F(FPDFEditEmbeddertest, LoadCIDType2Font) { const uint8_t* data = stock_font->GetFont()->GetFontData(); const uint32_t size = stock_font->GetFont()->GetSize(); - std::unique_ptr<void, FPDFFontDeleter> font( + ScopedFPDFFont font( FPDFText_LoadFont(document(), data, size, FPDF_FONT_TRUETYPE, 1)); ASSERT_TRUE(font.get()); CPDF_Font* typed_font = static_cast<CPDF_Font*>(font.get()); @@ -1167,7 +1145,7 @@ TEST_F(FPDFEditEmbeddertest, AddTrueTypeFontText) { const CPDF_Font* stock_font = CPDF_Font::GetStockFont(cpdf_doc(), "Arial"); const uint8_t* data = stock_font->GetFont()->GetFontData(); const uint32_t size = stock_font->GetFont()->GetSize(); - std::unique_ptr<void, FPDFFontDeleter> font( + ScopedFPDFFont font( FPDFText_LoadFont(document(), data, size, FPDF_FONT_TRUETYPE, 0)); ASSERT_TRUE(font.get()); @@ -1180,8 +1158,7 @@ TEST_F(FPDFEditEmbeddertest, AddTrueTypeFontText) { EXPECT_TRUE(FPDFText_SetText(text_object, text.get())); FPDFPageObj_Transform(text_object, 1, 0, 0, 1, 400, 400); FPDFPage_InsertObject(page, text_object); - std::unique_ptr<void, FPDFBitmapDeleter> page_bitmap = - RenderPageWithFlags(page, nullptr, 0); + ScopedFPDFBitmap page_bitmap = RenderPageWithFlags(page, nullptr, 0); #if _FX_PLATFORM_ == _FX_PLATFORM_APPLE_ const char md5[] = "17d2b6cd574cf66170b09c8927529a94"; #else @@ -1198,8 +1175,7 @@ TEST_F(FPDFEditEmbeddertest, AddTrueTypeFontText) { FPDFPageObj_Transform(text_object2, 1, 0, 0, 1, 200, 200); FPDFPage_InsertObject(page, text_object2); } - std::unique_ptr<void, FPDFBitmapDeleter> page_bitmap2 = - RenderPageWithFlags(page, nullptr, 0); + ScopedFPDFBitmap page_bitmap2 = RenderPageWithFlags(page, nullptr, 0); #if _FX_PLATFORM_ == _FX_PLATFORM_APPLE_ const char md5_2[] = "8eded4193ff1f0f77b8b600a825e97ea"; #else @@ -1222,7 +1198,7 @@ TEST_F(FPDFEditEmbeddertest, TransformAnnot) { { // Add an underline annotation to the page without specifying its rectangle. - std::unique_ptr<void, FPDFAnnotationDeleter> annot( + ScopedFPDFAnnotation annot( FPDFPage_CreateAnnot(page, FPDF_ANNOT_UNDERLINE)); ASSERT_TRUE(annot); @@ -1247,7 +1223,7 @@ TEST_F(FPDFEditEmbeddertest, AddCIDFontText) { const uint32_t size = CIDfont.GetSize(); // Load the data into a FPDF_Font. - std::unique_ptr<void, FPDFFontDeleter> font( + ScopedFPDFFont font( FPDFText_LoadFont(document(), data, size, FPDF_FONT_TRUETYPE, 1)); ASSERT_TRUE(font.get()); @@ -1279,8 +1255,7 @@ TEST_F(FPDFEditEmbeddertest, AddCIDFontText) { // Check that the text renders properly. const char md5[] = "c68cd79aa72bf83a7b25271370d46b21"; { - std::unique_ptr<void, FPDFBitmapDeleter> page_bitmap = - RenderPageWithFlags(page, nullptr, 0); + ScopedFPDFBitmap page_bitmap = RenderPageWithFlags(page, nullptr, 0); CompareBitmap(page_bitmap.get(), 612, 792, md5); } @@ -1312,8 +1287,7 @@ TEST_F(FPDFEditEmbeddertest, SaveAndRender) { EXPECT_TRUE(FPDFPath_BezierTo(green_path, 38, 33, 39, 36, 40, 40)); EXPECT_TRUE(FPDFPath_Close(green_path)); FPDFPage_InsertObject(page, green_path); - std::unique_ptr<void, FPDFBitmapDeleter> page_bitmap = - RenderLoadedPage(page); + ScopedFPDFBitmap page_bitmap = RenderLoadedPage(page); CompareBitmap(page_bitmap.get(), 612, 792, md5); // Now save the result, closing the page and document @@ -1388,8 +1362,7 @@ TEST_F(FPDFEditEmbeddertest, ExtractJBigImageBitmap) { FPDF_PAGEOBJECT obj = FPDFPage_GetObject(page, 0); ASSERT_EQ(FPDF_PAGEOBJ_IMAGE, FPDFPageObj_GetType(obj)); { - std::unique_ptr<void, FPDFBitmapDeleter> bitmap( - FPDFImageObj_GetBitmap(obj)); + ScopedFPDFBitmap bitmap(FPDFImageObj_GetBitmap(obj)); ASSERT_TRUE(bitmap); EXPECT_EQ(FPDFBitmap_Gray, FPDFBitmap_GetFormat(bitmap.get())); CompareBitmap(bitmap.get(), 1152, 720, "3f6a48e2b3e91b799bf34567f55cb4de"); diff --git a/fpdfsdk/fpdf_formfill_embeddertest.cpp b/fpdfsdk/fpdf_formfill_embeddertest.cpp index cedb96c0ca..94c16f3290 100644 --- a/fpdfsdk/fpdf_formfill_embeddertest.cpp +++ b/fpdfsdk/fpdf_formfill_embeddertest.cpp @@ -9,7 +9,7 @@ #include "core/fxcrt/fx_coordinates.h" #include "core/fxcrt/fx_string.h" #include "core/fxcrt/fx_system.h" -#include "public/cpp/fpdf_deleters.h" +#include "public/cpp/fpdf_scopers.h" #include "public/fpdf_formfill.h" #include "public/fpdf_fwlevent.h" #include "testing/embedder_test.h" @@ -586,7 +586,7 @@ TEST_F(FPDFFormFillEmbeddertest, FormText) { EXPECT_TRUE(OpenDocument("text_form.pdf")); FPDF_PAGE page = LoadPage(0); ASSERT_TRUE(page); - std::unique_ptr<void, FPDFBitmapDeleter> bitmap1 = RenderLoadedPage(page); + ScopedFPDFBitmap bitmap1 = RenderLoadedPage(page); CompareBitmap(bitmap1.get(), 300, 300, md5_1); // Click on the textfield @@ -600,14 +600,14 @@ TEST_F(FPDFFormFillEmbeddertest, FormText) { FORM_OnChar(form_handle(), page, 65, 0); FORM_OnChar(form_handle(), page, 66, 0); FORM_OnChar(form_handle(), page, 67, 0); - std::unique_ptr<void, FPDFBitmapDeleter> bitmap2 = RenderLoadedPage(page); + ScopedFPDFBitmap bitmap2 = RenderLoadedPage(page); CompareBitmap(bitmap2.get(), 300, 300, md5_2); // Take out focus by clicking out of the textfield FORM_OnMouseMove(form_handle(), page, 0, 15.0, 15.0); FORM_OnLButtonDown(form_handle(), page, 0, 15.0, 15.0); FORM_OnLButtonUp(form_handle(), page, 0, 15.0, 15.0); - std::unique_ptr<void, FPDFBitmapDeleter> bitmap3 = RenderLoadedPage(page); + ScopedFPDFBitmap bitmap3 = RenderLoadedPage(page); CompareBitmap(bitmap3.get(), 300, 300, md5_3); EXPECT_TRUE(FPDF_SaveAsCopy(document(), this, 0)); diff --git a/fpdfsdk/fpdf_ppo.cpp b/fpdfsdk/fpdf_ppo.cpp index 6daaf13704..0847113f86 100644 --- a/fpdfsdk/fpdf_ppo.cpp +++ b/fpdfsdk/fpdf_ppo.cpp @@ -26,7 +26,7 @@ #include "core/fxcrt/retain_ptr.h" #include "core/fxcrt/unowned_ptr.h" #include "fpdfsdk/cpdfsdk_helpers.h" -#include "public/cpp/fpdf_deleters.h" +#include "public/cpp/fpdf_scopers.h" #include "third_party/base/ptr_util.h" #include "third_party/base/stl_util.h" @@ -778,8 +778,7 @@ FPDF_ImportNPagesToOne(FPDF_DOCUMENT src_doc, return nullptr; } - std::unique_ptr<void, FPDFDocumentDeleter> output_doc( - FPDF_CreateNewDocument()); + ScopedFPDFDocument output_doc(FPDF_CreateNewDocument()); if (!output_doc) return nullptr; diff --git a/fpdfsdk/fpdf_ppo_embeddertest.cpp b/fpdfsdk/fpdf_ppo_embeddertest.cpp index 614573b24f..8412771aaf 100644 --- a/fpdfsdk/fpdf_ppo_embeddertest.cpp +++ b/fpdfsdk/fpdf_ppo_embeddertest.cpp @@ -6,7 +6,7 @@ #include <string> #include "fpdfsdk/cpdfsdk_helpers.h" -#include "public/cpp/fpdf_deleters.h" +#include "public/cpp/fpdf_scopers.h" #include "public/fpdf_edit.h" #include "public/fpdf_ppo.h" #include "public/fpdf_save.h" @@ -64,19 +64,19 @@ TEST_F(FPDFPPOEmbeddertest, ImportPages) { TEST_F(FPDFPPOEmbeddertest, ImportNPages) { ASSERT_TRUE(OpenDocument("rectangles_multi_pages.pdf")); - std::unique_ptr<void, FPDFDocumentDeleter> output_doc_2up( + ScopedFPDFDocument output_doc_2up( FPDF_ImportNPagesToOne(document(), 612, 792, 2, 1)); ASSERT_TRUE(output_doc_2up); EXPECT_EQ(3, FPDF_GetPageCount(output_doc_2up.get())); - std::unique_ptr<void, FPDFDocumentDeleter> output_doc_5up( + ScopedFPDFDocument output_doc_5up( FPDF_ImportNPagesToOne(document(), 612, 792, 5, 1)); ASSERT_TRUE(output_doc_5up); EXPECT_EQ(1, FPDF_GetPageCount(output_doc_5up.get())); - std::unique_ptr<void, FPDFDocumentDeleter> output_doc_8up( + ScopedFPDFDocument output_doc_8up( FPDF_ImportNPagesToOne(document(), 792, 612, 8, 1)); ASSERT_TRUE(output_doc_8up); EXPECT_EQ(1, FPDF_GetPageCount(output_doc_8up.get())); - std::unique_ptr<void, FPDFDocumentDeleter> output_doc_128up( + ScopedFPDFDocument output_doc_128up( FPDF_ImportNPagesToOne(document(), 792, 612, 128, 1)); ASSERT_TRUE(output_doc_128up); EXPECT_EQ(1, FPDF_GetPageCount(output_doc_128up.get())); @@ -106,16 +106,14 @@ TEST_F(FPDFPPOEmbeddertest, NupRenderImage) { const int kPageCount = 2; constexpr const char* kExpectedMD5s[kPageCount] = { "4d225b961da0f1bced7c83273e64c9b6", "fb18142190d770cfbc329d2b071aee4d"}; - std::unique_ptr<void, FPDFDocumentDeleter> output_doc_3up( + ScopedFPDFDocument output_doc_3up( FPDF_ImportNPagesToOne(document(), 792, 612, 3, 1)); ASSERT_TRUE(output_doc_3up); ASSERT_EQ(kPageCount, FPDF_GetPageCount(output_doc_3up.get())); for (int i = 0; i < kPageCount; ++i) { - std::unique_ptr<void, FPDFPageDeleter> page( - FPDF_LoadPage(output_doc_3up.get(), i)); + ScopedFPDFPage page(FPDF_LoadPage(output_doc_3up.get(), i)); ASSERT_TRUE(page); - std::unique_ptr<void, FPDFBitmapDeleter> bitmap( - RenderPageWithFlags(page.get(), nullptr, 0)); + ScopedFPDFBitmap bitmap(RenderPageWithFlags(page.get(), nullptr, 0)); EXPECT_EQ(792, FPDFBitmap_GetWidth(bitmap.get())); EXPECT_EQ(612, FPDFBitmap_GetHeight(bitmap.get())); EXPECT_EQ(kExpectedMD5s[i], HashBitmap(bitmap.get())); @@ -218,7 +216,7 @@ TEST_F(FPDFPPOEmbeddertest, BUG_750568) { FPDF_PAGE page = LoadPage(i); ASSERT_TRUE(page); - std::unique_ptr<void, FPDFBitmapDeleter> bitmap = RenderLoadedPage(page); + ScopedFPDFBitmap bitmap = RenderLoadedPage(page); ASSERT_EQ(200, FPDFBitmap_GetWidth(bitmap.get())); ASSERT_EQ(200, FPDFBitmap_GetHeight(bitmap.get())); ASSERT_EQ(800, FPDFBitmap_GetStride(bitmap.get())); @@ -235,8 +233,7 @@ TEST_F(FPDFPPOEmbeddertest, BUG_750568) { FPDF_PAGE page = FPDF_LoadPage(output_doc, i); ASSERT_TRUE(page); - std::unique_ptr<void, FPDFBitmapDeleter> bitmap = - RenderPageWithFlags(page, nullptr, 0); + ScopedFPDFBitmap bitmap = RenderPageWithFlags(page, nullptr, 0); ASSERT_EQ(200, FPDFBitmap_GetWidth(bitmap.get())); ASSERT_EQ(200, FPDFBitmap_GetHeight(bitmap.get())); ASSERT_EQ(800, FPDFBitmap_GetStride(bitmap.get())); @@ -252,7 +249,7 @@ TEST_F(FPDFPPOEmbeddertest, ImportWithZeroLengthStream) { FPDF_PAGE page = LoadPage(0); ASSERT_TRUE(page); - std::unique_ptr<void, FPDFBitmapDeleter> bitmap = RenderLoadedPage(page); + ScopedFPDFBitmap bitmap = RenderLoadedPage(page); ASSERT_EQ(200, FPDFBitmap_GetWidth(bitmap.get())); ASSERT_EQ(200, FPDFBitmap_GetHeight(bitmap.get())); ASSERT_EQ(800, FPDFBitmap_GetStride(bitmap.get())); @@ -267,8 +264,7 @@ TEST_F(FPDFPPOEmbeddertest, ImportWithZeroLengthStream) { EXPECT_EQ(1, FPDF_GetPageCount(new_doc)); FPDF_PAGE new_page = FPDF_LoadPage(new_doc, 0); ASSERT_NE(nullptr, new_page); - std::unique_ptr<void, FPDFBitmapDeleter> new_bitmap = - RenderPageWithFlags(new_page, nullptr, 0); + ScopedFPDFBitmap new_bitmap = RenderPageWithFlags(new_page, nullptr, 0); ASSERT_EQ(200, FPDFBitmap_GetWidth(new_bitmap.get())); ASSERT_EQ(200, FPDFBitmap_GetHeight(new_bitmap.get())); ASSERT_EQ(800, FPDFBitmap_GetStride(new_bitmap.get())); diff --git a/fpdfsdk/fpdf_save_embeddertest.cpp b/fpdfsdk/fpdf_save_embeddertest.cpp index e753ba0356..64a305fa86 100644 --- a/fpdfsdk/fpdf_save_embeddertest.cpp +++ b/fpdfsdk/fpdf_save_embeddertest.cpp @@ -6,6 +6,7 @@ #include <string> #include "core/fxcrt/fx_string.h" +#include "public/cpp/fpdf_scopers.h" #include "public/fpdf_edit.h" #include "public/fpdf_ppo.h" #include "public/fpdf_save.h" @@ -67,7 +68,7 @@ TEST_F(FPDFSaveEmbedderTest, SaveLinearizedDoc) { for (int i = 0; i < kPageCount; ++i) { FPDF_PAGE page = LoadPage(i); ASSERT_TRUE(page); - std::unique_ptr<void, FPDFBitmapDeleter> bitmap = RenderLoadedPage(page); + ScopedFPDFBitmap bitmap = RenderLoadedPage(page); EXPECT_EQ(612, FPDFBitmap_GetWidth(bitmap.get())); EXPECT_EQ(792, FPDFBitmap_GetHeight(bitmap.get())); original_md5[i] = HashBitmap(bitmap.get()); @@ -85,7 +86,7 @@ TEST_F(FPDFSaveEmbedderTest, SaveLinearizedDoc) { for (int i = 0; i < kPageCount; ++i) { FPDF_PAGE page = LoadSavedPage(i); ASSERT_TRUE(page); - std::unique_ptr<void, FPDFBitmapDeleter> bitmap = RenderSavedPage(page); + ScopedFPDFBitmap bitmap = RenderSavedPage(page); EXPECT_EQ(original_md5[i], HashBitmap(bitmap.get())); CloseSavedPage(page); } diff --git a/fpdfsdk/fpdf_view_embeddertest.cpp b/fpdfsdk/fpdf_view_embeddertest.cpp index 8d2cd3af1b..40e1c9df5d 100644 --- a/fpdfsdk/fpdf_view_embeddertest.cpp +++ b/fpdfsdk/fpdf_view_embeddertest.cpp @@ -8,6 +8,7 @@ #include <string> #include "fpdfsdk/fpdf_view_c_api_test.h" +#include "public/cpp/fpdf_scopers.h" #include "public/fpdfview.h" #include "testing/embedder_test.h" #include "testing/gtest/include/gtest/gtest.h" @@ -439,7 +440,7 @@ TEST_F(FPDFViewEmbeddertest, FPDF_RenderPageBitmapWithMatrix) { EXPECT_EQ(200, page_width); EXPECT_EQ(300, page_height); - std::unique_ptr<void, FPDFBitmapDeleter> bitmap = RenderLoadedPage(page); + ScopedFPDFBitmap bitmap = RenderLoadedPage(page); CompareBitmap(bitmap.get(), page_width, page_height, kOriginalMD5); FS_RECTF page_rect{0, 0, page_width, page_height}; diff --git a/public/cpp/fpdf_scopers.h b/public/cpp/fpdf_scopers.h new file mode 100644 index 0000000000..1898ac887d --- /dev/null +++ b/public/cpp/fpdf_scopers.h @@ -0,0 +1,54 @@ +// Copyright 2018 PDFium Authors. All rights reserved. +// Use of this source code is governed by a BSD-style license that can be +// found in the LICENSE file. + +#ifndef PUBLIC_CPP_FPDF_SCOPERS_H_ +#define PUBLIC_CPP_FPDF_SCOPERS_H_ + +#include <memory> +#include <type_traits> + +#include "public/cpp/fpdf_deleters.h" +#include "public/fpdf_annot.h" +#include "public/fpdf_dataavail.h" +#include "public/fpdf_edit.h" +#include "public/fpdf_formfill.h" +#include "public/fpdf_structtree.h" +#include "public/fpdf_text.h" +#include "public/fpdfview.h" + +// Versions of FPDF types that clean up the object at scope exit. + +using ScopedFPDFAnnotation = + std::unique_ptr<std::remove_pointer<FPDF_ANNOTATION>::type, + FPDFAnnotationDeleter>; + +using ScopedFPDFAvail = + std::unique_ptr<std::remove_pointer<FPDF_AVAIL>::type, FPDFAvailDeleter>; + +using ScopedFPDFBitmap = + std::unique_ptr<std::remove_pointer<FPDF_BITMAP>::type, FPDFBitmapDeleter>; + +using ScopedFPDFDocument = + std::unique_ptr<std::remove_pointer<FPDF_DOCUMENT>::type, + FPDFDocumentDeleter>; + +using ScopedFPDFFormHandle = + std::unique_ptr<std::remove_pointer<FPDF_FORMHANDLE>::type, + FPDFFormHandleDeleter>; + +using ScopedFPDFTextPage = + std::unique_ptr<std::remove_pointer<FPDF_TEXTPAGE>::type, + FPDFTextPageDeleter>; + +using ScopedFPDFPage = + std::unique_ptr<std::remove_pointer<FPDF_PAGE>::type, FPDFPageDeleter>; + +using ScopedFPDFStructTree = + std::unique_ptr<std::remove_pointer<FPDF_STRUCTTREE>::type, + FPDFStructTreeDeleter>; + +using ScopedFPDFFont = + std::unique_ptr<std::remove_pointer<FPDF_FONT>::type, FPDFFontDeleter>; + +#endif // PUBLIC_CPP_FPDF_SCOPERS_H_ diff --git a/samples/pdfium_test.cc b/samples/pdfium_test.cc index 292673f1de..c2c217ddae 100644 --- a/samples/pdfium_test.cc +++ b/samples/pdfium_test.cc @@ -18,7 +18,7 @@ #define _SKIA_SUPPORT_ #endif -#include "public/cpp/fpdf_deleters.h" +#include "public/cpp/fpdf_scopers.h" #include "public/fpdf_annot.h" #include "public/fpdf_attachment.h" #include "public/fpdf_dataavail.h" @@ -136,7 +136,7 @@ Optional<std::string> ExpandDirectoryPath(const std::string& path) { struct FPDF_FORMFILLINFO_PDFiumTest : public FPDF_FORMFILLINFO { // Hold a map of the currently loaded pages in order to avoid them // to get loaded twice. - std::map<int, std::unique_ptr<void, FPDFPageDeleter>> loaded_pages; + std::map<int, ScopedFPDFPage> loaded_pages; // Hold a pointer of FPDF_FORMHANDLE so that PDFium app hooks can // make use of it. @@ -473,7 +473,7 @@ FPDF_PAGE GetPageForIndex(FPDF_FORMFILLINFO* param, if (iter != loaded_pages.end()) return iter->second.get(); - std::unique_ptr<void, FPDFPageDeleter> page(FPDF_LoadPage(doc, index)); + ScopedFPDFPage page(FPDF_LoadPage(doc, index)); if (!page) return nullptr; @@ -513,8 +513,7 @@ bool RenderPage(const std::string& name, return true; } - std::unique_ptr<void, FPDFTextPageDeleter> text_page(FPDFText_LoadPage(page)); - + ScopedFPDFTextPage text_page(FPDFText_LoadPage(page)); double scale = 1.0; if (!options.scale_factor_as_string.empty()) std::stringstream(options.scale_factor_as_string) >> scale; @@ -522,8 +521,7 @@ bool RenderPage(const std::string& name, auto width = static_cast<int>(FPDF_GetPageWidth(page) * scale); auto height = static_cast<int>(FPDF_GetPageHeight(page) * scale); int alpha = FPDFPage_HasTransparency(page) ? 1 : 0; - std::unique_ptr<void, FPDFBitmapDeleter> bitmap( - FPDFBitmap_Create(width, height, alpha)); + ScopedFPDFBitmap bitmap(FPDFBitmap_Create(width, height, alpha)); if (bitmap) { FPDF_DWORD fill_color = alpha ? 0x00000000 : 0xFFFFFFFF; @@ -637,11 +635,10 @@ void RenderPdf(const std::string& name, hints.AddSegment = Add_Segment; // The pdf_avail must outlive doc. - std::unique_ptr<void, FPDFAvailDeleter> pdf_avail( - FPDFAvail_Create(&file_avail, &file_access)); + ScopedFPDFAvail pdf_avail(FPDFAvail_Create(&file_avail, &file_access)); // The document must outlive |form_callbacks.loaded_pages|. - std::unique_ptr<void, FPDFDocumentDeleter> doc; + ScopedFPDFDocument doc; int nRet = PDF_DATA_NOTAVAIL; bool bIsLinearized = false; @@ -701,7 +698,7 @@ void RenderPdf(const std::string& name, form_callbacks.m_pJsPlatform = &platform_callbacks; #endif // PDF_ENABLE_V8 - std::unique_ptr<void, FPDFFormHandleDeleter> form( + ScopedFPDFFormHandle form( FPDFDOC_InitFormFillEnvironment(doc.get(), &form_callbacks)); form_callbacks.form_handle = form.get(); diff --git a/samples/pdfium_test_dump_helper.cc b/samples/pdfium_test_dump_helper.cc index 729a4cd152..2b422a93fb 100644 --- a/samples/pdfium_test_dump_helper.cc +++ b/samples/pdfium_test_dump_helper.cc @@ -11,7 +11,7 @@ #include <string> #include <utility> -#include "public/cpp/fpdf_deleters.h" +#include "public/cpp/fpdf_scopers.h" #include "testing/test_support.h" namespace { @@ -55,8 +55,7 @@ void DumpChildStructure(FPDF_STRUCTELEMENT child, int indent) { } void DumpPageStructure(FPDF_PAGE page, const int page_idx) { - std::unique_ptr<void, FPDFStructTreeDeleter> tree( - FPDF_StructTree_GetForPage(page)); + ScopedFPDFStructTree tree(FPDF_StructTree_GetForPage(page)); if (!tree) { fprintf(stderr, "Failed to load struct tree for page %d\n", page_idx); return; diff --git a/samples/pdfium_test_write_helper.cc b/samples/pdfium_test_write_helper.cc index d061252e07..c436c97fbe 100644 --- a/samples/pdfium_test_write_helper.cc +++ b/samples/pdfium_test_write_helper.cc @@ -9,7 +9,7 @@ #include <memory> #include <vector> -#include "public/cpp/fpdf_deleters.h" +#include "public/cpp/fpdf_scopers.h" #include "public/fpdf_annot.h" #include "public/fpdf_attachment.h" #include "public/fpdf_edit.h" @@ -215,7 +215,7 @@ void WriteText(FPDF_PAGE page, const char* pdf_name, int num) { return; } - std::unique_ptr<void, FPDFTextPageDeleter> textpage(FPDFText_LoadPage(page)); + ScopedFPDFTextPage textpage(FPDFText_LoadPage(page)); for (int i = 0; i < FPDFText_CountChars(textpage.get()); i++) { uint32_t c = FPDFText_GetUnicode(textpage.get(), i); if (fwrite(&c, sizeof(c), 1, fp) != 1) { @@ -250,8 +250,7 @@ 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); - std::unique_ptr<void, FPDFAnnotationDeleter> annot( - FPDFPage_GetAnnot(page, i)); + ScopedFPDFAnnotation annot(FPDFPage_GetAnnot(page, i)); if (!annot) { fprintf(fp, "Failed to retrieve annotation!\n\n"); continue; @@ -579,8 +578,7 @@ void WriteImages(FPDF_PAGE page, const char* pdf_name, int page_num) { if (FPDFPageObj_GetType(obj) != FPDF_PAGEOBJ_IMAGE) continue; - std::unique_ptr<void, FPDFBitmapDeleter> bitmap( - FPDFImageObj_GetBitmap(obj)); + ScopedFPDFBitmap bitmap(FPDFImageObj_GetBitmap(obj)); if (!bitmap) { fprintf(stderr, "Image object #%d on page #%d has an empty bitmap.\n", i + 1, page_num + 1); diff --git a/testing/embedder_test.cpp b/testing/embedder_test.cpp index fd53b52fdc..03eebe3abc 100644 --- a/testing/embedder_test.cpp +++ b/testing/embedder_test.cpp @@ -15,6 +15,7 @@ #include <vector> #include "core/fdrm/crypto/fx_crypt.h" +#include "public/cpp/fpdf_scopers.h" #include "public/fpdf_dataavail.h" #include "public/fpdf_edit.h" #include "public/fpdf_text.h" @@ -305,13 +306,12 @@ void EmbedderTest::UnloadPage(FPDF_PAGE page) { page_map_.erase(page_number); } -std::unique_ptr<void, FPDFBitmapDeleter> EmbedderTest::RenderLoadedPage( - FPDF_PAGE page) { +ScopedFPDFBitmap EmbedderTest::RenderLoadedPage(FPDF_PAGE page) { return RenderLoadedPageWithFlags(page, 0); } -std::unique_ptr<void, FPDFBitmapDeleter> -EmbedderTest::RenderLoadedPageWithFlags(FPDF_PAGE page, int flags) { +ScopedFPDFBitmap EmbedderTest::RenderLoadedPageWithFlags(FPDF_PAGE page, + int flags) { if (GetPageNumberForLoadedPage(page) < 0) { NOTREACHED(); return nullptr; @@ -319,14 +319,12 @@ EmbedderTest::RenderLoadedPageWithFlags(FPDF_PAGE page, int flags) { return RenderPageWithFlags(page, form_handle_, flags); } -std::unique_ptr<void, FPDFBitmapDeleter> EmbedderTest::RenderSavedPage( - FPDF_PAGE page) { +ScopedFPDFBitmap EmbedderTest::RenderSavedPage(FPDF_PAGE page) { return RenderSavedPageWithFlags(page, 0); } -std::unique_ptr<void, FPDFBitmapDeleter> EmbedderTest::RenderSavedPageWithFlags( - FPDF_PAGE page, - int flags) { +ScopedFPDFBitmap EmbedderTest::RenderSavedPageWithFlags(FPDF_PAGE page, + int flags) { if (GetPageNumberForSavedPage(page) < 0) { NOTREACHED(); return nullptr; @@ -335,15 +333,13 @@ std::unique_ptr<void, FPDFBitmapDeleter> EmbedderTest::RenderSavedPageWithFlags( } // static -std::unique_ptr<void, FPDFBitmapDeleter> EmbedderTest::RenderPageWithFlags( - FPDF_PAGE page, - FPDF_FORMHANDLE handle, - int flags) { +ScopedFPDFBitmap EmbedderTest::RenderPageWithFlags(FPDF_PAGE page, + FPDF_FORMHANDLE handle, + int flags) { int width = static_cast<int>(FPDF_GetPageWidth(page)); int height = static_cast<int>(FPDF_GetPageHeight(page)); int alpha = FPDFPage_HasTransparency(page) ? 1 : 0; - std::unique_ptr<void, FPDFBitmapDeleter> bitmap( - FPDFBitmap_Create(width, height, alpha)); + ScopedFPDFBitmap bitmap(FPDFBitmap_Create(width, height, alpha)); FPDF_DWORD fill_color = alpha ? 0x00000000 : 0xFFFFFFFF; FPDFBitmap_FillRect(bitmap.get(), 0, 0, width, height, fill_color); FPDF_RenderPageBitmap(bitmap.get(), page, 0, 0, width, height, 0, flags); @@ -417,8 +413,7 @@ void EmbedderTest::VerifySavedRendering(FPDF_PAGE page, ASSERT(saved_document_); ASSERT(page); - std::unique_ptr<void, FPDFBitmapDeleter> bitmap = - RenderSavedPageWithFlags(page, FPDF_ANNOT); + ScopedFPDFBitmap bitmap = RenderSavedPageWithFlags(page, FPDF_ANNOT); CompareBitmap(bitmap.get(), width, height, md5); } diff --git a/testing/embedder_test.h b/testing/embedder_test.h index 4923180c4a..8156dd2353 100644 --- a/testing/embedder_test.h +++ b/testing/embedder_test.h @@ -9,7 +9,7 @@ #include <memory> #include <string> -#include "public/cpp/fpdf_deleters.h" +#include "public/cpp/fpdf_scopers.h" #include "public/fpdf_dataavail.h" #include "public/fpdf_ext.h" #include "public/fpdf_formfill.h" @@ -126,26 +126,22 @@ class EmbedderTest : public ::testing::Test, void UnloadPage(FPDF_PAGE page); // RenderLoadedPageWithFlags() with no flags. - std::unique_ptr<void, FPDFBitmapDeleter> RenderLoadedPage(FPDF_PAGE page); + ScopedFPDFBitmap RenderLoadedPage(FPDF_PAGE page); // Convert |page| loaded via LoadPage() into a bitmap with the specified page // rendering |flags|. // // See public/fpdfview.h for a list of page rendering flags. - std::unique_ptr<void, FPDFBitmapDeleter> RenderLoadedPageWithFlags( - FPDF_PAGE page, - int flags); + ScopedFPDFBitmap RenderLoadedPageWithFlags(FPDF_PAGE page, int flags); // RenderSavedPageWithFlags() with no flags. - std::unique_ptr<void, FPDFBitmapDeleter> RenderSavedPage(FPDF_PAGE page); + ScopedFPDFBitmap RenderSavedPage(FPDF_PAGE page); // Convert |page| loaded via LoadSavedPage() into a bitmap with the specified // page rendering |flags|. // // See public/fpdfview.h for a list of page rendering flags. - std::unique_ptr<void, FPDFBitmapDeleter> RenderSavedPageWithFlags( - FPDF_PAGE page, - int flags); + ScopedFPDFBitmap RenderSavedPageWithFlags(FPDF_PAGE page, int flags); // Convert |page| into a bitmap with the specified page rendering |flags|. // The form handle associated with |page| should be passed in via |handle|. @@ -153,8 +149,9 @@ class EmbedderTest : public ::testing::Test, // // See public/fpdfview.h for a list of page rendering flags. // If none of the above Render methods are appropriate, then use this one. - static std::unique_ptr<void, FPDFBitmapDeleter> - RenderPageWithFlags(FPDF_PAGE page, FPDF_FORMHANDLE handle, int flags); + static ScopedFPDFBitmap RenderPageWithFlags(FPDF_PAGE page, + FPDF_FORMHANDLE handle, + int flags); protected: using PageNumberToHandleMap = std::map<int, FPDF_PAGE>; diff --git a/testing/libfuzzer/pdf_font_fuzzer.cc b/testing/libfuzzer/pdf_font_fuzzer.cc index aed66613fa..7c596307f0 100644 --- a/testing/libfuzzer/pdf_font_fuzzer.cc +++ b/testing/libfuzzer/pdf_font_fuzzer.cc @@ -5,7 +5,7 @@ #include <cstring> #include <memory> -#include "public/cpp/fpdf_deleters.h" +#include "public/cpp/fpdf_scopers.h" #include "public/fpdf_edit.h" #include "public/fpdfview.h" @@ -13,15 +13,13 @@ extern "C" int LLVMFuzzerTestOneInput(const uint8_t* data, size_t size) { if (size < 2) return 0; - std::unique_ptr<void, FPDFDocumentDeleter> doc(FPDF_CreateNewDocument()); - std::unique_ptr<void, FPDFPageDeleter> page( - FPDFPage_New(doc.get(), 0, 612, 792)); + ScopedFPDFDocument doc(FPDF_CreateNewDocument()); + ScopedFPDFPage page(FPDFPage_New(doc.get(), 0, 612, 792)); int font_type = data[0]; FPDF_BOOL cid = data[1]; data += 2; size -= 2; - std::unique_ptr<void, FPDFFontDeleter> font( - FPDFText_LoadFont(doc.get(), data, size, font_type, cid)); + ScopedFPDFFont font(FPDFText_LoadFont(doc.get(), data, size, font_type, cid)); if (!font) return 0; |