diff options
author | Tom Sepez <tsepez@chromium.org> | 2018-04-25 18:49:32 +0000 |
---|---|---|
committer | Chromium commit bot <commit-bot@chromium.org> | 2018-04-25 18:49:32 +0000 |
commit | e08d2b1fee0db40bac9538ca8b7be0a951675bd6 (patch) | |
tree | 81ded468a54adb247f46d7824632f6c4a537619c /samples/pdfium_test.cc | |
parent | eb3ec8f29846a5df67269a53ca94d1d740c84513 (diff) | |
download | pdfium-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 'samples/pdfium_test.cc')
-rw-r--r-- | samples/pdfium_test.cc | 19 |
1 files changed, 8 insertions, 11 deletions
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(); |