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 ++++++++----------- 1 file changed, 8 insertions(+), 11 deletions(-) (limited to 'samples/pdfium_test.cc') 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(); -- cgit v1.2.3