From e08d2b1fee0db40bac9538ca8b7be0a951675bd6 Mon Sep 17 00:00:00 2001 From: Tom Sepez Date: Wed, 25 Apr 2018 18:49:32 +0000 Subject: 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, ...> Change-Id: I04a0ff43cb7d5a4d3867939a53a54c9cef00db86 Reviewed-on: https://pdfium-review.googlesource.com/31292 Reviewed-by: Lei Zhang Reviewed-by: dsinclair Commit-Queue: Tom Sepez --- samples/pdfium_test.cc | 19 ++++++++----------- samples/pdfium_test_dump_helper.cc | 5 ++--- samples/pdfium_test_write_helper.cc | 10 ++++------ 3 files changed, 14 insertions(+), 20 deletions(-) (limited to 'samples') 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 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> loaded_pages; + std::map 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 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 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(FPDF_GetPageWidth(page) * scale); auto height = static_cast(FPDF_GetPageHeight(page) * scale); int alpha = FPDFPage_HasTransparency(page) ? 1 : 0; - std::unique_ptr 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 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 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 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 #include -#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 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 #include -#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 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 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 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); -- cgit v1.2.3