| OLD | NEW |
| 1 // Copyright 2015 PDFium Authors. All rights reserved. | 1 // Copyright 2015 PDFium Authors. All rights reserved. |
| 2 // Use of this source code is governed by a BSD-style license that can be | 2 // Use of this source code is governed by a BSD-style license that can be |
| 3 // found in the LICENSE file. | 3 // found in the LICENSE file. |
| 4 | 4 |
| 5 #include "testing/embedder_test.h" | 5 #include "testing/embedder_test.h" |
| 6 | 6 |
| 7 #include <limits.h> | 7 #include <limits.h> |
| 8 | 8 |
| 9 #include <list> | 9 #include <list> |
| 10 #include <string> | 10 #include <string> |
| (...skipping 224 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
| 235 | 235 |
| 236 int EmbedderTest::GetPageCount() { | 236 int EmbedderTest::GetPageCount() { |
| 237 int page_count = FPDF_GetPageCount(document_); | 237 int page_count = FPDF_GetPageCount(document_); |
| 238 for (int i = 0; i < page_count; ++i) { | 238 for (int i = 0; i < page_count; ++i) { |
| 239 (void)FPDFAvail_IsPageAvail(avail_, i, &hints_); | 239 (void)FPDFAvail_IsPageAvail(avail_, i, &hints_); |
| 240 } | 240 } |
| 241 return page_count; | 241 return page_count; |
| 242 } | 242 } |
| 243 | 243 |
| 244 FPDF_PAGE EmbedderTest::LoadPage(int page_number) { | 244 FPDF_PAGE EmbedderTest::LoadPage(int page_number) { |
| 245 // First check whether it is loaded already. |
| 246 auto it = page_map_.find(page_number); |
| 247 if (it != page_map_.end()) |
| 248 return it->second; |
| 249 |
| 245 FPDF_PAGE page = FPDF_LoadPage(document_, page_number); | 250 FPDF_PAGE page = FPDF_LoadPage(document_, page_number); |
| 246 if (!page) { | 251 if (!page) { |
| 247 return nullptr; | 252 return nullptr; |
| 248 } | 253 } |
| 249 FORM_OnAfterLoadPage(page, form_handle_); | 254 FORM_OnAfterLoadPage(page, form_handle_); |
| 250 FORM_DoPageAAction(page, form_handle_, FPDFPAGE_AACTION_OPEN); | 255 FORM_DoPageAAction(page, form_handle_, FPDFPAGE_AACTION_OPEN); |
| 256 // Cache the page. |
| 257 page_map_[page_number] = page; |
| 251 return page; | 258 return page; |
| 252 } | 259 } |
| 253 | 260 |
| 254 FPDF_PAGE EmbedderTest::LoadAndCachePage(int page_number) { | |
| 255 FPDF_PAGE page = delegate_->GetPage(form_handle_, document_, page_number); | |
| 256 if (!page) { | |
| 257 return nullptr; | |
| 258 } | |
| 259 FORM_DoPageAAction(page, form_handle_, FPDFPAGE_AACTION_OPEN); | |
| 260 return page; | |
| 261 } | |
| 262 | |
| 263 FPDF_BITMAP EmbedderTest::RenderPage(FPDF_PAGE page) { | 261 FPDF_BITMAP EmbedderTest::RenderPage(FPDF_PAGE page) { |
| 264 int width = static_cast<int>(FPDF_GetPageWidth(page)); | 262 int width = static_cast<int>(FPDF_GetPageWidth(page)); |
| 265 int height = static_cast<int>(FPDF_GetPageHeight(page)); | 263 int height = static_cast<int>(FPDF_GetPageHeight(page)); |
| 266 int alpha = FPDFPage_HasTransparency(page) ? 1 : 0; | 264 int alpha = FPDFPage_HasTransparency(page) ? 1 : 0; |
| 267 FPDF_BITMAP bitmap = FPDFBitmap_Create(width, height, alpha); | 265 FPDF_BITMAP bitmap = FPDFBitmap_Create(width, height, alpha); |
| 268 FPDF_DWORD fill_color = alpha ? 0x00000000 : 0xFFFFFFFF; | 266 FPDF_DWORD fill_color = alpha ? 0x00000000 : 0xFFFFFFFF; |
| 269 FPDFBitmap_FillRect(bitmap, 0, 0, width, height, fill_color); | 267 FPDFBitmap_FillRect(bitmap, 0, 0, width, height, fill_color); |
| 270 FPDF_RenderPageBitmap(bitmap, page, 0, 0, width, height, 0, 0); | 268 FPDF_RenderPageBitmap(bitmap, page, 0, 0, width, height, 0, 0); |
| 271 FPDF_FFLDraw(form_handle_, bitmap, page, 0, 0, width, height, 0, 0); | 269 FPDF_FFLDraw(form_handle_, bitmap, page, 0, 0, width, height, 0, 0); |
| 272 return bitmap; | 270 return bitmap; |
| 273 } | 271 } |
| 274 | 272 |
| 275 void EmbedderTest::UnloadPage(FPDF_PAGE page) { | 273 void EmbedderTest::UnloadPage(FPDF_PAGE page) { |
| 276 FORM_DoPageAAction(page, form_handle_, FPDFPAGE_AACTION_CLOSE); | 274 FORM_DoPageAAction(page, form_handle_, FPDFPAGE_AACTION_CLOSE); |
| 277 FORM_OnBeforeClosePage(page, form_handle_); | 275 FORM_OnBeforeClosePage(page, form_handle_); |
| 278 FPDF_ClosePage(page); | 276 FPDF_ClosePage(page); |
| 279 } | 277 } |
| 280 | 278 |
| 281 FPDF_PAGE EmbedderTest::Delegate::GetPage(FPDF_FORMHANDLE form_handle, | 279 FPDF_PAGE EmbedderTest::Delegate::GetPage(FPDF_FORMFILLINFO* info, |
| 282 FPDF_DOCUMENT document, | 280 FPDF_DOCUMENT document, |
| 283 int page_index) { | 281 int page_index) { |
| 284 auto it = m_pageMap.find(page_index); | 282 EmbedderTest* test = static_cast<EmbedderTest*>(info); |
| 285 if (it != m_pageMap.end()) { | 283 auto it = test->page_map_.find(page_index); |
| 286 return it->second; | 284 return it != test->page_map_.end() ? it->second : nullptr; |
| 287 } | |
| 288 FPDF_PAGE page = FPDF_LoadPage(document, page_index); | |
| 289 if (!page) { | |
| 290 return nullptr; | |
| 291 } | |
| 292 m_pageMap[page_index] = page; | |
| 293 FORM_OnAfterLoadPage(page, form_handle); | |
| 294 return page; | |
| 295 } | 285 } |
| 296 | 286 |
| 297 // static | 287 // static |
| 298 void EmbedderTest::UnsupportedHandlerTrampoline(UNSUPPORT_INFO* info, | 288 void EmbedderTest::UnsupportedHandlerTrampoline(UNSUPPORT_INFO* info, |
| 299 int type) { | 289 int type) { |
| 300 EmbedderTest* test = static_cast<EmbedderTest*>(info); | 290 EmbedderTest* test = static_cast<EmbedderTest*>(info); |
| 301 test->delegate_->UnsupportedHandler(type); | 291 test->delegate_->UnsupportedHandler(type); |
| 302 } | 292 } |
| 303 | 293 |
| 304 // static | 294 // static |
| (...skipping 17 matching lines...) Expand all Loading... |
| 322 // static | 312 // static |
| 323 void EmbedderTest::KillTimerTrampoline(FPDF_FORMFILLINFO* info, int id) { | 313 void EmbedderTest::KillTimerTrampoline(FPDF_FORMFILLINFO* info, int id) { |
| 324 EmbedderTest* test = static_cast<EmbedderTest*>(info); | 314 EmbedderTest* test = static_cast<EmbedderTest*>(info); |
| 325 return test->delegate_->KillTimer(id); | 315 return test->delegate_->KillTimer(id); |
| 326 } | 316 } |
| 327 | 317 |
| 328 // static | 318 // static |
| 329 FPDF_PAGE EmbedderTest::GetPageTrampoline(FPDF_FORMFILLINFO* info, | 319 FPDF_PAGE EmbedderTest::GetPageTrampoline(FPDF_FORMFILLINFO* info, |
| 330 FPDF_DOCUMENT document, | 320 FPDF_DOCUMENT document, |
| 331 int page_index) { | 321 int page_index) { |
| 332 EmbedderTest* test = static_cast<EmbedderTest*>(info); | 322 return static_cast<EmbedderTest*>(info)->delegate_->GetPage(info, document, |
| 333 return test->delegate_->GetPage(test->form_handle(), document, page_index); | 323 page_index); |
| 334 } | 324 } |
| 335 | 325 |
| 336 // Can't use gtest-provided main since we need to stash the path to the | 326 // Can't use gtest-provided main since we need to stash the path to the |
| 337 // executable in order to find the external V8 binary data files. | 327 // executable in order to find the external V8 binary data files. |
| 338 int main(int argc, char** argv) { | 328 int main(int argc, char** argv) { |
| 339 g_exe_path = argv[0]; | 329 g_exe_path = argv[0]; |
| 340 testing::InitGoogleTest(&argc, argv); | 330 testing::InitGoogleTest(&argc, argv); |
| 341 testing::InitGoogleMock(&argc, argv); | 331 testing::InitGoogleMock(&argc, argv); |
| 342 int ret_val = RUN_ALL_TESTS(); | 332 int ret_val = RUN_ALL_TESTS(); |
| 343 | 333 |
| 344 #ifdef PDF_ENABLE_V8 | 334 #ifdef PDF_ENABLE_V8 |
| 345 #ifdef V8_USE_EXTERNAL_STARTUP_DATA | 335 #ifdef V8_USE_EXTERNAL_STARTUP_DATA |
| 346 if (g_v8_natives) | 336 if (g_v8_natives) |
| 347 free(const_cast<char*>(g_v8_natives->data)); | 337 free(const_cast<char*>(g_v8_natives->data)); |
| 348 if (g_v8_snapshot) | 338 if (g_v8_snapshot) |
| 349 free(const_cast<char*>(g_v8_snapshot->data)); | 339 free(const_cast<char*>(g_v8_snapshot->data)); |
| 350 #endif // V8_USE_EXTERNAL_STARTUP_DATA | 340 #endif // V8_USE_EXTERNAL_STARTUP_DATA |
| 351 #endif // PDF_ENABLE_V8 | 341 #endif // PDF_ENABLE_V8 |
| 352 | 342 |
| 353 return ret_val; | 343 return ret_val; |
| 354 } | 344 } |
| OLD | NEW |