summaryrefslogtreecommitdiff
path: root/fpdfsdk
diff options
context:
space:
mode:
authorTom Sepez <tsepez@chromium.org>2018-04-25 18:49:32 +0000
committerChromium commit bot <commit-bot@chromium.org>2018-04-25 18:49:32 +0000
commite08d2b1fee0db40bac9538ca8b7be0a951675bd6 (patch)
tree81ded468a54adb247f46d7824632f6c4a537619c /fpdfsdk
parenteb3ec8f29846a5df67269a53ca94d1d740c84513 (diff)
downloadpdfium-e08d2b1fee0db40bac9538ca8b7be0a951675bd6.tar.xz
Introduce ScopedFPDF types in public/cpp/fpdf_scopers.h
Applies std::remove_ptr to the public API types so that we can deduce a correct unique ptr type no matter how that API might change away from void* usage. Creates shorter names for std::unique_ptr<std::remove_pointer<>, ...> Change-Id: I04a0ff43cb7d5a4d3867939a53a54c9cef00db86 Reviewed-on: https://pdfium-review.googlesource.com/31292 Reviewed-by: Lei Zhang <thestig@chromium.org> Reviewed-by: dsinclair <dsinclair@chromium.org> Commit-Queue: Tom Sepez <tsepez@chromium.org>
Diffstat (limited to 'fpdfsdk')
-rw-r--r--fpdfsdk/fpdf_annot_embeddertest.cpp175
-rw-r--r--fpdfsdk/fpdf_edit_embeddertest.cpp103
-rw-r--r--fpdfsdk/fpdf_formfill_embeddertest.cpp8
-rw-r--r--fpdfsdk/fpdf_ppo.cpp5
-rw-r--r--fpdfsdk/fpdf_ppo_embeddertest.cpp28
-rw-r--r--fpdfsdk/fpdf_save_embeddertest.cpp5
-rw-r--r--fpdfsdk/fpdf_view_embeddertest.cpp3
7 files changed, 122 insertions, 205 deletions
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};