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 353 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... | |
364 if (rect.Contains(origin)) { | 364 if (rect.Contains(origin)) { |
365 if (target) | 365 if (target) |
366 target->url = links_[i].url; | 366 target->url = links_[i].url; |
367 return i; | 367 return i; |
368 } | 368 } |
369 } | 369 } |
370 } | 370 } |
371 return -1; | 371 return -1; |
372 } | 372 } |
373 | 373 |
374 std::vector<pp::Rect> PDFiumPage::GetLinkRects() { | |
375 if (!available_) | |
376 return std::vector<pp::Rect>(); | |
377 | |
378 CalculateLinks(); | |
379 | |
380 std::vector<pp::Rect> link_rects; | |
381 for (size_t i = 0; i < links_.size(); ++i) { | |
Lei Zhang
2016/07/08 18:02:36
nit: You can also do a range-based for loop here.
jaepark
2016/07/08 20:58:16
Done.
| |
382 pp::Rect rect = UnionLinkCharRects(links_[i].rects); | |
Lei Zhang
2016/07/08 18:02:36
nit: No need for |rect| ?
jaepark
2016/07/08 20:58:16
Done.
| |
383 link_rects.push_back(rect); | |
384 } | |
385 | |
386 return link_rects; | |
387 } | |
388 | |
389 pp::Rect PDFiumPage::UnionLinkCharRects(const std::vector<pp::Rect> rects) { | |
390 if (rects.empty()) | |
Lei Zhang
2016/07/08 18:02:36
Can't you skip this check and get the same result?
jaepark
2016/07/08 20:58:16
Done.
| |
391 return pp::Rect(); | |
392 | |
393 pp::Rect result_rect; | |
394 for (const auto& rect : rects) | |
395 result_rect = result_rect.Union(rect); | |
396 | |
397 return result_rect; | |
398 } | |
399 | |
374 std::vector<int> PDFiumPage::GetLinks(pp::Rect text_area, | 400 std::vector<int> PDFiumPage::GetLinks(pp::Rect text_area, |
375 std::vector<LinkTarget>* targets) { | 401 std::vector<LinkTarget>* targets) { |
376 std::vector<int> links; | 402 std::vector<int> links; |
377 if (!available_) | 403 if (!available_) |
378 return links; | 404 return links; |
379 | 405 |
380 CalculateLinks(); | 406 CalculateLinks(); |
381 | 407 |
382 for (size_t i = 0; i < links_.size(); ++i) { | 408 for (size_t i = 0; i < links_.size(); ++i) { |
383 for (const auto& rect : links_[i].rects) { | 409 for (const auto& rect : links_[i].rects) { |
(...skipping 113 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... | |
497 page_->loading_count_--; | 523 page_->loading_count_--; |
498 } | 524 } |
499 | 525 |
500 PDFiumPage::Link::Link() { | 526 PDFiumPage::Link::Link() { |
501 } | 527 } |
502 | 528 |
503 PDFiumPage::Link::~Link() { | 529 PDFiumPage::Link::~Link() { |
504 } | 530 } |
505 | 531 |
506 } // namespace chrome_pdf | 532 } // namespace chrome_pdf |
OLD | NEW |