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