| OLD | NEW |
| 1 // Copyright (c) 2010 The Chromium Authors. All rights reserved. | 1 // Copyright (c) 2010 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_page.h" | 5 #include "pdf/pdfium/pdfium_page.h" |
| 6 | 6 |
| 7 #include <math.h> | 7 #include <math.h> |
| 8 #include <stddef.h> | 8 #include <stddef.h> |
| 9 | 9 |
| 10 #include <algorithm> | 10 #include <algorithm> |
| (...skipping 55 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
| 66 std::swap(top, bottom); | 66 std::swap(top, bottom); |
| 67 pp::FloatRect page_coords(left, top, right - left, bottom - top); | 67 pp::FloatRect page_coords(left, top, right - left, bottom - top); |
| 68 return FloatPageRectToPixelRect(page, page_coords); | 68 return FloatPageRectToPixelRect(page, page_coords); |
| 69 } | 69 } |
| 70 | 70 |
| 71 bool OverlapsOnYAxis(const pp::FloatRect &a, const pp::FloatRect& b) { | 71 bool OverlapsOnYAxis(const pp::FloatRect &a, const pp::FloatRect& b) { |
| 72 return !(a.IsEmpty() || b.IsEmpty() || | 72 return !(a.IsEmpty() || b.IsEmpty() || |
| 73 a.bottom() < b.y() || b.bottom() < a.y()); | 73 a.bottom() < b.y() || b.bottom() < a.y()); |
| 74 } | 74 } |
| 75 | 75 |
| 76 pp::Rect UnionLinkCharRects(const std::vector<pp::Rect>& rects) { |
| 77 pp::Rect result_rect; |
| 78 for (const auto& rect : rects) |
| 79 result_rect = result_rect.Union(rect); |
| 80 |
| 81 return result_rect; |
| 82 } |
| 83 |
| 76 } // namespace | 84 } // namespace |
| 77 | 85 |
| 78 namespace chrome_pdf { | 86 namespace chrome_pdf { |
| 79 | 87 |
| 80 PDFiumPage::PDFiumPage(PDFiumEngine* engine, | 88 PDFiumPage::PDFiumPage(PDFiumEngine* engine, |
| 81 int i, | 89 int i, |
| 82 const pp::Rect& r, | 90 const pp::Rect& r, |
| 83 bool available) | 91 bool available) |
| 84 : engine_(engine), | 92 : engine_(engine), |
| 85 page_(NULL), | 93 page_(NULL), |
| (...skipping 278 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
| 364 if (rect.Contains(origin)) { | 372 if (rect.Contains(origin)) { |
| 365 if (target) | 373 if (target) |
| 366 target->url = links_[i].url; | 374 target->url = links_[i].url; |
| 367 return i; | 375 return i; |
| 368 } | 376 } |
| 369 } | 377 } |
| 370 } | 378 } |
| 371 return -1; | 379 return -1; |
| 372 } | 380 } |
| 373 | 381 |
| 382 std::vector<pp::Rect> PDFiumPage::GetLinkRects() { |
| 383 std::vector<pp::Rect> link_rects; |
| 384 if (!available_) |
| 385 return link_rects; |
| 386 |
| 387 CalculateLinks(); |
| 388 |
| 389 for (const auto& link : links_) |
| 390 link_rects.push_back(UnionLinkCharRects(link.rects)); |
| 391 |
| 392 return link_rects; |
| 393 } |
| 394 |
| 374 std::vector<int> PDFiumPage::GetLinks(pp::Rect text_area, | 395 std::vector<int> PDFiumPage::GetLinks(pp::Rect text_area, |
| 375 std::vector<LinkTarget>* targets) { | 396 std::vector<LinkTarget>* targets) { |
| 376 std::vector<int> links; | 397 std::vector<int> links; |
| 377 if (!available_) | 398 if (!available_) |
| 378 return links; | 399 return links; |
| 379 | 400 |
| 380 CalculateLinks(); | 401 CalculateLinks(); |
| 381 | 402 |
| 382 for (size_t i = 0; i < links_.size(); ++i) { | 403 for (size_t i = 0; i < links_.size(); ++i) { |
| 383 for (const auto& rect : links_[i].rects) { | 404 for (const auto& rect : links_[i].rects) { |
| (...skipping 113 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
| 497 page_->loading_count_--; | 518 page_->loading_count_--; |
| 498 } | 519 } |
| 499 | 520 |
| 500 PDFiumPage::Link::Link() { | 521 PDFiumPage::Link::Link() { |
| 501 } | 522 } |
| 502 | 523 |
| 503 PDFiumPage::Link::~Link() { | 524 PDFiumPage::Link::~Link() { |
| 504 } | 525 } |
| 505 | 526 |
| 506 } // namespace chrome_pdf | 527 } // namespace chrome_pdf |
| OLD | NEW |