OLD | NEW |
1 // Copyright (c) 2012 The Chromium Authors. All rights reserved. | 1 // Copyright (c) 2012 The Chromium 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 "pdf/pdfium/pdfium_engine.h" | 5 #include "pdf/pdfium/pdfium_engine.h" |
6 | 6 |
7 #include <math.h> | 7 #include <math.h> |
8 | 8 |
9 #include "base/json/json_writer.h" | 9 #include "base/json/json_writer.h" |
10 #include "base/logging.h" | 10 #include "base/logging.h" |
(...skipping 581 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
592 last_page_to_search_(-1), | 592 last_page_to_search_(-1), |
593 last_character_index_to_search_(-1), | 593 last_character_index_to_search_(-1), |
594 permissions_(0), | 594 permissions_(0), |
595 fpdf_availability_(NULL), | 595 fpdf_availability_(NULL), |
596 next_timer_id_(0), | 596 next_timer_id_(0), |
597 last_page_mouse_down_(-1), | 597 last_page_mouse_down_(-1), |
598 first_visible_page_(-1), | 598 first_visible_page_(-1), |
599 most_visible_page_(-1), | 599 most_visible_page_(-1), |
600 called_do_document_action_(false), | 600 called_do_document_action_(false), |
601 render_grayscale_(false), | 601 render_grayscale_(false), |
| 602 background_color_(0), |
602 progressive_paint_timeout_(0), | 603 progressive_paint_timeout_(0), |
603 getting_password_(false) { | 604 getting_password_(false) { |
604 find_factory_.Initialize(this); | 605 find_factory_.Initialize(this); |
605 password_factory_.Initialize(this); | 606 password_factory_.Initialize(this); |
606 | 607 |
607 file_access_.m_FileLen = 0; | 608 file_access_.m_FileLen = 0; |
608 file_access_.m_GetBlock = &GetBlock; | 609 file_access_.m_GetBlock = &GetBlock; |
609 file_access_.m_Param = &doc_loader_; | 610 file_access_.m_Param = &doc_loader_; |
610 | 611 |
611 file_availability_.version = 1; | 612 file_availability_.version = 1; |
(...skipping 1747 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
2359 if (pages_[i]->available()) { | 2360 if (pages_[i]->available()) { |
2360 selection_.push_back(PDFiumRange(pages_[i], 0, | 2361 selection_.push_back(PDFiumRange(pages_[i], 0, |
2361 pages_[i]->GetCharCount())); | 2362 pages_[i]->GetCharCount())); |
2362 } | 2363 } |
2363 } | 2364 } |
2364 | 2365 |
2365 int PDFiumEngine::GetNumberOfPages() { | 2366 int PDFiumEngine::GetNumberOfPages() { |
2366 return pages_.size(); | 2367 return pages_.size(); |
2367 } | 2368 } |
2368 | 2369 |
| 2370 uint32 PDFiumEngine::GetBackgroundColor() { |
| 2371 return background_color_; |
| 2372 } |
| 2373 |
| 2374 void PDFiumEngine::SetBackgroundColor(uint32 background_color) { |
| 2375 background_color_ = background_color; |
| 2376 } |
| 2377 |
2369 pp::VarArray PDFiumEngine::GetBookmarks() { | 2378 pp::VarArray PDFiumEngine::GetBookmarks() { |
2370 pp::VarDictionary dict = TraverseBookmarks(doc_, NULL); | 2379 pp::VarDictionary dict = TraverseBookmarks(doc_, NULL); |
2371 // The root bookmark contains no useful information. | 2380 // The root bookmark contains no useful information. |
2372 return pp::VarArray(dict.Get(pp::Var("children"))); | 2381 return pp::VarArray(dict.Get(pp::Var("children"))); |
2373 } | 2382 } |
2374 | 2383 |
2375 int PDFiumEngine::GetNamedDestinationPage(const std::string& destination) { | 2384 int PDFiumEngine::GetNamedDestinationPage(const std::string& destination) { |
2376 // Look for the destination. | 2385 // Look for the destination. |
2377 FPDF_DEST dest = FPDF_GetNamedDestByName(doc_, destination.c_str()); | 2386 FPDF_DEST dest = FPDF_GetNamedDestByName(doc_, destination.c_str()); |
2378 if (!dest) { | 2387 if (!dest) { |
(...skipping 551 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
2930 if (page_rect.x() > 0) { | 2939 if (page_rect.x() > 0) { |
2931 pp::Rect left(0, | 2940 pp::Rect left(0, |
2932 page_rect.y() - kPageShadowTop, | 2941 page_rect.y() - kPageShadowTop, |
2933 page_rect.x() - kPageShadowLeft, | 2942 page_rect.x() - kPageShadowLeft, |
2934 page_rect.height() + kPageShadowTop + | 2943 page_rect.height() + kPageShadowTop + |
2935 kPageShadowBottom + kPageSeparatorThickness); | 2944 kPageShadowBottom + kPageSeparatorThickness); |
2936 left = GetScreenRect(left).Intersect(dirty_in_screen); | 2945 left = GetScreenRect(left).Intersect(dirty_in_screen); |
2937 | 2946 |
2938 FPDFBitmap_FillRect(bitmap, left.x() - dirty_in_screen.x(), | 2947 FPDFBitmap_FillRect(bitmap, left.x() - dirty_in_screen.x(), |
2939 left.y() - dirty_in_screen.y(), left.width(), | 2948 left.y() - dirty_in_screen.y(), left.width(), |
2940 left.height(), kBackgroundColor); | 2949 left.height(), background_color_); |
2941 } | 2950 } |
2942 | 2951 |
2943 if (page_rect.right() < document_size_.width()) { | 2952 if (page_rect.right() < document_size_.width()) { |
2944 pp::Rect right(page_rect.right() + kPageShadowRight, | 2953 pp::Rect right(page_rect.right() + kPageShadowRight, |
2945 page_rect.y() - kPageShadowTop, | 2954 page_rect.y() - kPageShadowTop, |
2946 document_size_.width() - page_rect.right() - | 2955 document_size_.width() - page_rect.right() - |
2947 kPageShadowRight, | 2956 kPageShadowRight, |
2948 page_rect.height() + kPageShadowTop + | 2957 page_rect.height() + kPageShadowTop + |
2949 kPageShadowBottom + kPageSeparatorThickness); | 2958 kPageShadowBottom + kPageSeparatorThickness); |
2950 right = GetScreenRect(right).Intersect(dirty_in_screen); | 2959 right = GetScreenRect(right).Intersect(dirty_in_screen); |
2951 | 2960 |
2952 FPDFBitmap_FillRect(bitmap, right.x() - dirty_in_screen.x(), | 2961 FPDFBitmap_FillRect(bitmap, right.x() - dirty_in_screen.x(), |
2953 right.y() - dirty_in_screen.y(), right.width(), | 2962 right.y() - dirty_in_screen.y(), right.width(), |
2954 right.height(), kBackgroundColor); | 2963 right.height(), background_color_); |
2955 } | 2964 } |
2956 | 2965 |
2957 // Paint separator. | 2966 // Paint separator. |
2958 pp::Rect bottom(page_rect.x() - kPageShadowLeft, | 2967 pp::Rect bottom(page_rect.x() - kPageShadowLeft, |
2959 page_rect.bottom() + kPageShadowBottom, | 2968 page_rect.bottom() + kPageShadowBottom, |
2960 page_rect.width() + kPageShadowLeft + kPageShadowRight, | 2969 page_rect.width() + kPageShadowLeft + kPageShadowRight, |
2961 kPageSeparatorThickness); | 2970 kPageSeparatorThickness); |
2962 bottom = GetScreenRect(bottom).Intersect(dirty_in_screen); | 2971 bottom = GetScreenRect(bottom).Intersect(dirty_in_screen); |
2963 | 2972 |
2964 FPDFBitmap_FillRect(bitmap, bottom.x() - dirty_in_screen.x(), | 2973 FPDFBitmap_FillRect(bitmap, bottom.x() - dirty_in_screen.x(), |
2965 bottom.y() - dirty_in_screen.y(), bottom.width(), | 2974 bottom.y() - dirty_in_screen.y(), bottom.width(), |
2966 bottom.height(), kBackgroundColor); | 2975 bottom.height(), background_color_); |
2967 } | 2976 } |
2968 | 2977 |
2969 void PDFiumEngine::PaintPageShadow(int progressive_index, | 2978 void PDFiumEngine::PaintPageShadow(int progressive_index, |
2970 pp::ImageData* image_data) { | 2979 pp::ImageData* image_data) { |
2971 DCHECK_GE(progressive_index, 0); | 2980 DCHECK_GE(progressive_index, 0); |
2972 DCHECK_LT(static_cast<size_t>(progressive_index), progressive_paints_.size()); | 2981 DCHECK_LT(static_cast<size_t>(progressive_index), progressive_paints_.size()); |
2973 DCHECK(image_data); | 2982 DCHECK(image_data); |
2974 | 2983 |
2975 int page_index = progressive_paints_[progressive_index].page_index; | 2984 int page_index = progressive_paints_[progressive_index].page_index; |
2976 pp::Rect dirty_in_screen = progressive_paints_[progressive_index].rect; | 2985 pp::Rect dirty_in_screen = progressive_paints_[progressive_index].rect; |
(...skipping 431 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
3408 const double factor = 0.5; | 3417 const double factor = 0.5; |
3409 uint32 depth = std::max( | 3418 uint32 depth = std::max( |
3410 std::max(page_rect.x() - shadow_rect.x(), | 3419 std::max(page_rect.x() - shadow_rect.x(), |
3411 page_rect.y() - shadow_rect.y()), | 3420 page_rect.y() - shadow_rect.y()), |
3412 std::max(shadow_rect.right() - page_rect.right(), | 3421 std::max(shadow_rect.right() - page_rect.right(), |
3413 shadow_rect.bottom() - page_rect.bottom())); | 3422 shadow_rect.bottom() - page_rect.bottom())); |
3414 depth = static_cast<uint32>(depth * 1.5) + 1; | 3423 depth = static_cast<uint32>(depth * 1.5) + 1; |
3415 | 3424 |
3416 // We need to check depth only to verify our copy of shadow matrix is correct. | 3425 // We need to check depth only to verify our copy of shadow matrix is correct. |
3417 if (!page_shadow_.get() || page_shadow_->depth() != depth) | 3426 if (!page_shadow_.get() || page_shadow_->depth() != depth) |
3418 page_shadow_.reset(new ShadowMatrix(depth, factor, kBackgroundColor)); | 3427 page_shadow_.reset(new ShadowMatrix(depth, factor, background_color_)); |
3419 | 3428 |
3420 DCHECK(!image_data->is_null()); | 3429 DCHECK(!image_data->is_null()); |
3421 DrawShadow(image_data, shadow_rect, page_rect, clip_rect, *page_shadow_); | 3430 DrawShadow(image_data, shadow_rect, page_rect, clip_rect, *page_shadow_); |
3422 } | 3431 } |
3423 | 3432 |
3424 void PDFiumEngine::GetRegion(const pp::Point& location, | 3433 void PDFiumEngine::GetRegion(const pp::Point& location, |
3425 pp::ImageData* image_data, | 3434 pp::ImageData* image_data, |
3426 void** region, | 3435 void** region, |
3427 int* stride) const { | 3436 int* stride) const { |
3428 if (image_data->is_null()) { | 3437 if (image_data->is_null()) { |
(...skipping 589 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
4018 double* height) { | 4027 double* height) { |
4019 FPDF_DOCUMENT doc = FPDF_LoadMemDocument(pdf_buffer, pdf_buffer_size, NULL); | 4028 FPDF_DOCUMENT doc = FPDF_LoadMemDocument(pdf_buffer, pdf_buffer_size, NULL); |
4020 if (!doc) | 4029 if (!doc) |
4021 return false; | 4030 return false; |
4022 bool success = FPDF_GetPageSizeByIndex(doc, page_number, width, height) != 0; | 4031 bool success = FPDF_GetPageSizeByIndex(doc, page_number, width, height) != 0; |
4023 FPDF_CloseDocument(doc); | 4032 FPDF_CloseDocument(doc); |
4024 return success; | 4033 return success; |
4025 } | 4034 } |
4026 | 4035 |
4027 } // namespace chrome_pdf | 4036 } // namespace chrome_pdf |
OLD | NEW |