OLD | NEW |
1 // Copyright 2014 PDFium Authors. All rights reserved. | 1 // Copyright 2014 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 // Original code copyright 2014 Foxit Software Inc. http://www.foxitsoftware.com | 5 // Original code copyright 2014 Foxit Software Inc. http://www.foxitsoftware.com |
6 | 6 |
7 #include "../../third_party/base/nonstd_unique_ptr.h" | 7 #include "../../third_party/base/nonstd_unique_ptr.h" |
8 #include "../include/fsdk_define.h" | 8 #include "../include/fsdk_define.h" |
9 #include "../include/fsdk_mgr.h" | 9 #include "../include/fsdk_mgr.h" |
10 #include "../include/fsdk_baseannot.h" | 10 #include "../include/fsdk_baseannot.h" |
(...skipping 2409 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
2420 CPDF_Rect rcAnnot2 = GetAnnotRect(p2); | 2420 CPDF_Rect rcAnnot2 = GetAnnotRect(p2); |
2421 | 2421 |
2422 if (rcAnnot1.top < rcAnnot2.top) | 2422 if (rcAnnot1.top < rcAnnot2.top) |
2423 return -1; | 2423 return -1; |
2424 if (rcAnnot1.top > rcAnnot2.top) | 2424 if (rcAnnot1.top > rcAnnot2.top) |
2425 return 1; | 2425 return 1; |
2426 return 0; | 2426 return 0; |
2427 } | 2427 } |
2428 | 2428 |
2429 void CBA_AnnotIterator::GenerateResults() { | 2429 void CBA_AnnotIterator::GenerateResults() { |
2430 ASSERT(m_pPageView != NULL); | |
2431 | |
2432 switch (m_nTabs) { | 2430 switch (m_nTabs) { |
2433 case BAI_STRUCTURE: { | 2431 case BAI_STRUCTURE: { |
2434 for (size_t i = 0; i < m_pPageView->CountAnnots(); ++i) { | 2432 for (size_t i = 0; i < m_pPageView->CountAnnots(); ++i) { |
2435 CPDFSDK_Annot* pAnnot = m_pPageView->GetAnnot(i); | 2433 CPDFSDK_Annot* pAnnot = m_pPageView->GetAnnot(i); |
2436 ASSERT(pAnnot != NULL); | |
2437 | |
2438 if (pAnnot->GetType() == m_sType && pAnnot->GetSubType() == m_sSubType) | 2434 if (pAnnot->GetType() == m_sType && pAnnot->GetSubType() == m_sSubType) |
2439 m_Annots.Add(pAnnot); | 2435 m_Annots.Add(pAnnot); |
2440 } | 2436 } |
2441 } break; | 2437 break; |
| 2438 } |
2442 case BAI_ROW: { | 2439 case BAI_ROW: { |
2443 CPDFSDK_SortAnnots sa; | 2440 CPDFSDK_SortAnnots sa; |
2444 | 2441 for (size_t i = 0; i < m_pPageView->CountAnnots(); ++i) { |
2445 { | 2442 CPDFSDK_Annot* pAnnot = m_pPageView->GetAnnot(i); |
2446 for (size_t i = 0; i < m_pPageView->CountAnnots(); ++i) { | 2443 if (pAnnot->GetType() == m_sType && pAnnot->GetSubType() == m_sSubType) |
2447 CPDFSDK_Annot* pAnnot = m_pPageView->GetAnnot(i); | 2444 sa.Add(pAnnot); |
2448 ASSERT(pAnnot != NULL); | |
2449 | |
2450 if (pAnnot->GetType() == m_sType && | |
2451 pAnnot->GetSubType() == m_sSubType) | |
2452 sa.Add(pAnnot); | |
2453 } | |
2454 } | 2445 } |
2455 | 2446 |
2456 if (sa.GetSize() > 0) { | 2447 if (sa.GetSize() > 0) |
2457 sa.Sort(CBA_AnnotIterator::CompareByLeft); | 2448 sa.Sort(CBA_AnnotIterator::CompareByLeft); |
2458 } | |
2459 | 2449 |
2460 while (sa.GetSize() > 0) { | 2450 while (sa.GetSize() > 0) { |
2461 int nLeftTopIndex = -1; | 2451 int nLeftTopIndex = -1; |
| 2452 FX_FLOAT fTop = 0.0f; |
2462 | 2453 |
2463 { | 2454 for (int i = sa.GetSize() - 1; i >= 0; i--) { |
2464 FX_FLOAT fTop = 0.0f; | 2455 CPDFSDK_Annot* pAnnot = sa.GetAt(i); |
| 2456 ASSERT(pAnnot); |
2465 | 2457 |
2466 for (int i = sa.GetSize() - 1; i >= 0; i--) { | 2458 CPDF_Rect rcAnnot = GetAnnotRect(pAnnot); |
2467 CPDFSDK_Annot* pAnnot = sa.GetAt(i); | |
2468 ASSERT(pAnnot != NULL); | |
2469 | 2459 |
2470 CPDF_Rect rcAnnot = GetAnnotRect(pAnnot); | 2460 if (rcAnnot.top > fTop) { |
2471 | 2461 nLeftTopIndex = i; |
2472 if (rcAnnot.top > fTop) { | 2462 fTop = rcAnnot.top; |
2473 nLeftTopIndex = i; | |
2474 fTop = rcAnnot.top; | |
2475 } | |
2476 } | 2463 } |
2477 } | 2464 } |
2478 | 2465 |
2479 if (nLeftTopIndex >= 0) { | 2466 if (nLeftTopIndex >= 0) { |
2480 CPDFSDK_Annot* pLeftTopAnnot = sa.GetAt(nLeftTopIndex); | 2467 CPDFSDK_Annot* pLeftTopAnnot = sa.GetAt(nLeftTopIndex); |
2481 ASSERT(pLeftTopAnnot != NULL); | 2468 ASSERT(pLeftTopAnnot); |
2482 | 2469 |
2483 CPDF_Rect rcLeftTop = GetAnnotRect(pLeftTopAnnot); | 2470 CPDF_Rect rcLeftTop = GetAnnotRect(pLeftTopAnnot); |
2484 | 2471 |
2485 m_Annots.Add(pLeftTopAnnot); | 2472 m_Annots.Add(pLeftTopAnnot); |
2486 sa.RemoveAt(nLeftTopIndex); | 2473 sa.RemoveAt(nLeftTopIndex); |
2487 | 2474 |
2488 CFX_ArrayTemplate<int> aSelect; | 2475 CFX_ArrayTemplate<int> aSelect; |
2489 | 2476 |
2490 { | 2477 for (int i = 0, sz = sa.GetSize(); i < sz; ++i) { |
2491 for (int i = 0, sz = sa.GetSize(); i < sz; i++) { | 2478 CPDFSDK_Annot* pAnnot = sa.GetAt(i); |
2492 CPDFSDK_Annot* pAnnot = sa.GetAt(i); | 2479 ASSERT(pAnnot); |
2493 ASSERT(pAnnot != NULL); | |
2494 | 2480 |
2495 CPDF_Rect rcAnnot = GetAnnotRect(pAnnot); | 2481 CPDF_Rect rcAnnot = GetAnnotRect(pAnnot); |
2496 | 2482 FX_FLOAT fCenterY = (rcAnnot.top + rcAnnot.bottom) / 2.0f; |
2497 FX_FLOAT fCenterY = (rcAnnot.top + rcAnnot.bottom) / 2.0f; | 2483 if (fCenterY > rcLeftTop.bottom && fCenterY < rcLeftTop.top) |
2498 | 2484 aSelect.Add(i); |
2499 if (fCenterY > rcLeftTop.bottom && fCenterY < rcLeftTop.top) | |
2500 aSelect.Add(i); | |
2501 } | |
2502 } | 2485 } |
2503 | 2486 |
2504 { | 2487 for (int i = 0, sz = aSelect.GetSize(); i < sz; ++i) |
2505 for (int i = 0, sz = aSelect.GetSize(); i < sz; i++) { | 2488 m_Annots.Add(sa[aSelect[i]]); |
2506 m_Annots.Add(sa[aSelect[i]]); | |
2507 } | |
2508 } | |
2509 | 2489 |
2510 { | 2490 for (int i = aSelect.GetSize() - 1; i >= 0; --i) |
2511 for (int i = aSelect.GetSize() - 1; i >= 0; i--) { | |
2512 sa.RemoveAt(aSelect[i]); | 2491 sa.RemoveAt(aSelect[i]); |
2513 } | |
2514 } | |
2515 | 2492 |
2516 aSelect.RemoveAll(); | 2493 aSelect.RemoveAll(); |
2517 } | 2494 } |
2518 } | 2495 } |
2519 sa.RemoveAll(); | 2496 sa.RemoveAll(); |
2520 } break; | 2497 break; |
| 2498 } |
2521 case BAI_COLUMN: { | 2499 case BAI_COLUMN: { |
2522 CPDFSDK_SortAnnots sa; | 2500 CPDFSDK_SortAnnots sa; |
2523 | 2501 for (size_t i = 0; i < m_pPageView->CountAnnots(); ++i) { |
2524 { | 2502 CPDFSDK_Annot* pAnnot = m_pPageView->GetAnnot(i); |
2525 for (size_t i = 0; i < m_pPageView->CountAnnots(); ++i) { | 2503 if (pAnnot->GetType() == m_sType && pAnnot->GetSubType() == m_sSubType) |
2526 CPDFSDK_Annot* pAnnot = m_pPageView->GetAnnot(i); | 2504 sa.Add(pAnnot); |
2527 ASSERT(pAnnot != NULL); | |
2528 | |
2529 if (pAnnot->GetType() == m_sType && | |
2530 pAnnot->GetSubType() == m_sSubType) | |
2531 sa.Add(pAnnot); | |
2532 } | |
2533 } | 2505 } |
2534 | 2506 |
2535 if (sa.GetSize() > 0) { | 2507 if (sa.GetSize() > 0) |
2536 sa.Sort(CBA_AnnotIterator::CompareByTop, FALSE); | 2508 sa.Sort(CBA_AnnotIterator::CompareByTop, FALSE); |
2537 } | |
2538 | 2509 |
2539 while (sa.GetSize() > 0) { | 2510 while (sa.GetSize() > 0) { |
2540 int nLeftTopIndex = -1; | 2511 int nLeftTopIndex = -1; |
| 2512 FX_FLOAT fLeft = -1.0f; |
2541 | 2513 |
2542 { | 2514 for (int i = sa.GetSize() - 1; i >= 0; --i) { |
2543 FX_FLOAT fLeft = -1.0f; | 2515 CPDFSDK_Annot* pAnnot = sa.GetAt(i); |
| 2516 ASSERT(pAnnot); |
2544 | 2517 |
2545 for (int i = sa.GetSize() - 1; i >= 0; i--) { | 2518 CPDF_Rect rcAnnot = GetAnnotRect(pAnnot); |
2546 CPDFSDK_Annot* pAnnot = sa.GetAt(i); | |
2547 ASSERT(pAnnot != NULL); | |
2548 | 2519 |
2549 CPDF_Rect rcAnnot = GetAnnotRect(pAnnot); | 2520 if (fLeft < 0) { |
2550 | 2521 nLeftTopIndex = 0; |
2551 if (fLeft < 0) { | 2522 fLeft = rcAnnot.left; |
2552 nLeftTopIndex = 0; | 2523 } else if (rcAnnot.left < fLeft) { |
2553 fLeft = rcAnnot.left; | 2524 nLeftTopIndex = i; |
2554 } else if (rcAnnot.left < fLeft) { | 2525 fLeft = rcAnnot.left; |
2555 nLeftTopIndex = i; | |
2556 fLeft = rcAnnot.left; | |
2557 } | |
2558 } | 2526 } |
2559 } | 2527 } |
2560 | 2528 |
2561 if (nLeftTopIndex >= 0) { | 2529 if (nLeftTopIndex >= 0) { |
2562 CPDFSDK_Annot* pLeftTopAnnot = sa.GetAt(nLeftTopIndex); | 2530 CPDFSDK_Annot* pLeftTopAnnot = sa.GetAt(nLeftTopIndex); |
2563 ASSERT(pLeftTopAnnot != NULL); | 2531 ASSERT(pLeftTopAnnot); |
2564 | 2532 |
2565 CPDF_Rect rcLeftTop = GetAnnotRect(pLeftTopAnnot); | 2533 CPDF_Rect rcLeftTop = GetAnnotRect(pLeftTopAnnot); |
2566 | 2534 |
2567 m_Annots.Add(pLeftTopAnnot); | 2535 m_Annots.Add(pLeftTopAnnot); |
2568 sa.RemoveAt(nLeftTopIndex); | 2536 sa.RemoveAt(nLeftTopIndex); |
2569 | 2537 |
2570 CFX_ArrayTemplate<int> aSelect; | 2538 CFX_ArrayTemplate<int> aSelect; |
| 2539 for (int i = 0, sz = sa.GetSize(); i < sz; ++i) { |
| 2540 CPDFSDK_Annot* pAnnot = sa.GetAt(i); |
| 2541 ASSERT(pAnnot); |
2571 | 2542 |
2572 { | 2543 CPDF_Rect rcAnnot = GetAnnotRect(pAnnot); |
2573 for (int i = 0, sz = sa.GetSize(); i < sz; i++) { | 2544 FX_FLOAT fCenterX = (rcAnnot.left + rcAnnot.right) / 2.0f; |
2574 CPDFSDK_Annot* pAnnot = sa.GetAt(i); | 2545 if (fCenterX > rcLeftTop.left && fCenterX < rcLeftTop.right) |
2575 ASSERT(pAnnot != NULL); | 2546 aSelect.Add(i); |
2576 | |
2577 CPDF_Rect rcAnnot = GetAnnotRect(pAnnot); | |
2578 | |
2579 FX_FLOAT fCenterX = (rcAnnot.left + rcAnnot.right) / 2.0f; | |
2580 | |
2581 if (fCenterX > rcLeftTop.left && fCenterX < rcLeftTop.right) | |
2582 aSelect.Add(i); | |
2583 } | |
2584 } | 2547 } |
2585 | 2548 |
2586 { | 2549 for (int i = 0, sz = aSelect.GetSize(); i < sz; ++i) |
2587 for (int i = 0, sz = aSelect.GetSize(); i < sz; i++) { | 2550 m_Annots.Add(sa[aSelect[i]]); |
2588 m_Annots.Add(sa[aSelect[i]]); | |
2589 } | |
2590 } | |
2591 | 2551 |
2592 { | 2552 for (int i = aSelect.GetSize() - 1; i >= 0; --i) |
2593 for (int i = aSelect.GetSize() - 1; i >= 0; i--) { | 2553 sa.RemoveAt(aSelect[i]); |
2594 sa.RemoveAt(aSelect[i]); | |
2595 } | |
2596 } | |
2597 | 2554 |
2598 aSelect.RemoveAll(); | 2555 aSelect.RemoveAll(); |
2599 } | 2556 } |
2600 } | 2557 } |
2601 sa.RemoveAll(); | 2558 sa.RemoveAll(); |
2602 } break; | 2559 break; |
| 2560 } |
2603 } | 2561 } |
2604 } | 2562 } |
2605 | 2563 |
2606 CPDF_Rect CBA_AnnotIterator::GetAnnotRect(CPDFSDK_Annot* pAnnot) { | 2564 CPDF_Rect CBA_AnnotIterator::GetAnnotRect(CPDFSDK_Annot* pAnnot) { |
2607 ASSERT(pAnnot != NULL); | |
2608 | |
2609 CPDF_Annot* pPDFAnnot = pAnnot->GetPDFAnnot(); | |
2610 ASSERT(pPDFAnnot != NULL); | |
2611 | |
2612 CPDF_Rect rcAnnot; | 2565 CPDF_Rect rcAnnot; |
2613 pPDFAnnot->GetRect(rcAnnot); | 2566 pAnnot->GetPDFAnnot()->GetRect(rcAnnot); |
2614 | |
2615 return rcAnnot; | 2567 return rcAnnot; |
2616 } | 2568 } |
OLD | NEW |