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 | |
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')
-rw-r--r-- | testing/embedder_test.cpp | 79 | ||||
-rw-r--r-- | testing/embedder_test.h | 52 |
2 files changed, 96 insertions, 35 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) { diff --git a/testing/embedder_test.h b/testing/embedder_test.h index b36ac06a89..18b16b7066 100644 --- a/testing/embedder_test.h +++ b/testing/embedder_test.h @@ -9,6 +9,7 @@ #include <memory> #include <string> +#include "public/cpp/fpdf_deleters.h" #include "public/fpdf_dataavail.h" #include "public/fpdf_ext.h" #include "public/fpdf_formfill.h" @@ -108,18 +109,52 @@ class EmbedderTest : public ::testing::Test, // Load a specific page of the open document. FPDF_PAGE LoadPage(int page_number); + // Release the resources obtained from LoadPage(). Further use of |page| + // is prohibited after this call is made. + void UnloadPage(FPDF_PAGE page); + // Convert a loaded page into a bitmap. - FPDF_BITMAP RenderPage(FPDF_PAGE page); + // DEPRECATED. Use some one of the methods below instead. + FPDF_BITMAP RenderPageDeprecated(FPDF_PAGE page); - // Convert a loaded page into a bitmap with page rendering flags specified. + // RenderLoadedPageWithFlags() with no flags. + std::unique_ptr<void, FPDFBitmapDeleter> RenderLoadedPage(FPDF_PAGE page); + + // Convert |page| loaded via LoadPage() into a bitmap with the specified page + // rendering |flags|. + // // See public/fpdfview.h for a list of page rendering flags. - FPDF_BITMAP RenderPageWithFlags(FPDF_PAGE page, - FPDF_FORMHANDLE handle, - int flags); + std::unique_ptr<void, FPDFBitmapDeleter> RenderLoadedPageWithFlags( + FPDF_PAGE page, + int flags); - // Relese the resources obtained from LoadPage(). Further use of |page| - // is prohibited after this call is made. - void UnloadPage(FPDF_PAGE page); + // RenderSavedPageWithFlags() with no flags. + std::unique_ptr<void, FPDFBitmapDeleter> RenderSavedPage(FPDF_PAGE page); + + // Convert |page| loaded via LoadSavedPage() into a bitmap with the specified + // page rendering |flags|. + // + // See public/fpdfview.h for a list of page rendering flags. + std::unique_ptr<void, FPDFBitmapDeleter> RenderSavedPageWithFlags( + FPDF_PAGE page, + int flags); + + // DEPRECATED. Use RenderPageWithFlags() instead. + // Caller takes ownership of the returned bitmap. + // + // See public/fpdfview.h for a list of page rendering flags. + static FPDF_BITMAP RenderPageWithFlagsDeprecated(FPDF_PAGE page, + FPDF_FORMHANDLE handle, + int flags); + + // Convert |page| into a bitmap with the specified page rendering |flags|. + // The form handle associated with |page| should be passed in via |handle|. + // If |handle| is nullptr, then forms on the page will not be rendered. + // + // See public/fpdfview.h for a list of page rendering flags. + // If none of the above Render methods are appropriate, then use this one. + static std::unique_ptr<void, FPDFBitmapDeleter> + RenderPageWithFlags(FPDF_PAGE page, FPDF_FORMHANDLE handle, int flags); protected: bool OpenDocumentHelper(const char* password, @@ -157,7 +192,6 @@ class EmbedderTest : public ::testing::Test, FPDF_DOCUMENT OpenSavedDocument(const char* password = nullptr); void CloseSavedDocument(); FPDF_PAGE LoadSavedPage(int page_number); - FPDF_BITMAP RenderSavedPage(FPDF_PAGE page); void CloseSavedPage(FPDF_PAGE page); void VerifySavedRendering(FPDF_PAGE page, int width, |