diff options
author | Lei Zhang <thestig@chromium.org> | 2018-02-07 20:28:35 +0000 |
---|---|---|
committer | Chromium commit bot <commit-bot@chromium.org> | 2018-02-07 20:28:35 +0000 |
commit | a98e36657d0e5a78e216f828b3e712e85250c1a7 (patch) | |
tree | 4621be8a3be00efafe28eea4639b87675db80d2b /testing/embedder_test.cpp | |
parent | 2496f8e3f3cb1cbfffd664c9b5d7983dc192887b (diff) | |
download | pdfium-a98e36657d0e5a78e216f828b3e712e85250c1a7.tar.xz |
Clean up RenderPage methods in EmbedderTest.
Add replacement methods that make themselves clear as to what they are
rendering, and return unique_ptrs to help prevent leakage. Mark existing
methods deprecated.
Change-Id: I9055407e614dfbe765428fb32a7da64df3418d1d
Reviewed-on: https://pdfium-review.googlesource.com/25470
Reviewed-by: dsinclair <dsinclair@chromium.org>
Commit-Queue: Lei Zhang <thestig@chromium.org>
Diffstat (limited to 'testing/embedder_test.cpp')
-rw-r--r-- | testing/embedder_test.cpp | 79 |
1 files changed, 53 insertions, 26 deletions
diff --git a/testing/embedder_test.cpp b/testing/embedder_test.cpp index d7f4376b24..bd52c26286 100644 --- a/testing/embedder_test.cpp +++ b/testing/embedder_test.cpp @@ -8,6 +8,7 @@ #include <fstream> #include <list> +#include <memory> #include <string> #include <utility> #include <vector> @@ -261,24 +262,6 @@ FPDF_PAGE EmbedderTest::LoadPage(int page_number) { return page; } -FPDF_BITMAP EmbedderTest::RenderPage(FPDF_PAGE page) { - return RenderPageWithFlags(page, form_handle_, 0); -} - -FPDF_BITMAP 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; - FPDF_BITMAP bitmap = FPDFBitmap_Create(width, height, alpha); - FPDF_DWORD fill_color = alpha ? 0x00000000 : 0xFFFFFFFF; - FPDFBitmap_FillRect(bitmap, 0, 0, width, height, fill_color); - FPDF_RenderPageBitmap(bitmap, page, 0, 0, width, height, 0, flags); - FPDF_FFLDraw(handle, bitmap, page, 0, 0, width, height, 0, flags); - return bitmap; -} - void EmbedderTest::UnloadPage(FPDF_PAGE page) { ASSERT(form_handle_); FORM_DoPageAAction(page, form_handle_, FPDFPAGE_AACTION_CLOSE); @@ -293,6 +276,55 @@ void EmbedderTest::UnloadPage(FPDF_PAGE page) { page_reverse_map_.erase(it); } +FPDF_BITMAP EmbedderTest::RenderPageDeprecated(FPDF_PAGE page) { + return RenderPageWithFlagsDeprecated(page, form_handle_, 0); +} + +std::unique_ptr<void, FPDFBitmapDeleter> EmbedderTest::RenderLoadedPage( + FPDF_PAGE page) { + return RenderLoadedPageWithFlags(page, 0); +} + +std::unique_ptr<void, FPDFBitmapDeleter> +EmbedderTest::RenderLoadedPageWithFlags(FPDF_PAGE page, int flags) { + return RenderPageWithFlags(page, form_handle_, flags); +} + +std::unique_ptr<void, FPDFBitmapDeleter> EmbedderTest::RenderSavedPage( + FPDF_PAGE page) { + return RenderSavedPageWithFlags(page, 0); +} + +std::unique_ptr<void, FPDFBitmapDeleter> EmbedderTest::RenderSavedPageWithFlags( + FPDF_PAGE page, + int flags) { + return RenderPageWithFlags(page, saved_form_handle_, flags); +} + +// static +FPDF_BITMAP EmbedderTest::RenderPageWithFlagsDeprecated(FPDF_PAGE page, + FPDF_FORMHANDLE handle, + int flags) { + return RenderPageWithFlags(page, handle, flags).release(); +} + +// static +std::unique_ptr<void, FPDFBitmapDeleter> 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)); + 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); + FPDF_FFLDraw(handle, bitmap.get(), page, 0, 0, width, height, 0, flags); + return bitmap; +} + FPDF_DOCUMENT EmbedderTest::OpenSavedDocument(const char* password) { memset(&saved_file_access_, 0, sizeof(saved_file_access_)); saved_file_access_.m_FileLen = data_string_.size(); @@ -330,10 +362,6 @@ FPDF_PAGE EmbedderTest::LoadSavedPage(int page_number) { return page; } -FPDF_BITMAP EmbedderTest::RenderSavedPage(FPDF_PAGE page) { - return RenderPageWithFlags(page, saved_form_handle_, 0); -} - void EmbedderTest::CloseSavedPage(FPDF_PAGE page) { ASSERT(page); FPDF_ClosePage(page); @@ -346,10 +374,9 @@ void EmbedderTest::VerifySavedRendering(FPDF_PAGE page, ASSERT(saved_document_); ASSERT(page); - FPDF_BITMAP new_bitmap = - RenderPageWithFlags(page, saved_form_handle_, FPDF_ANNOT); - CompareBitmap(new_bitmap, width, height, md5); - FPDFBitmap_Destroy(new_bitmap); + std::unique_ptr<void, FPDFBitmapDeleter> bitmap = + RenderSavedPageWithFlags(page, FPDF_ANNOT); + CompareBitmap(bitmap.get(), width, height, md5); } void EmbedderTest::VerifySavedDocument(int width, int height, const char* md5) { |