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 "layoutprovider_taggedpdf.h" | 7 #include "layoutprovider_taggedpdf.h" |
8 CPDF_LayoutElement::CPDF_LayoutElement() | 8 CPDF_LayoutElement::CPDF_LayoutElement() |
9 { | 9 { |
10 m_pTaggedElement = NULL; | 10 m_pTaggedElement = NULL; |
(...skipping 618 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
629 } | 629 } |
630 FX_BOOL CPDF_LayoutElement::AddObject(CPDF_PageObject* pObj) | 630 FX_BOOL CPDF_LayoutElement::AddObject(CPDF_PageObject* pObj) |
631 { | 631 { |
632 return m_ObjArray.Add(pObj); | 632 return m_ObjArray.Add(pObj); |
633 } | 633 } |
634 IPDF_LayoutProvider* IPDF_LayoutProvider::Create_LayoutProvider_TaggedPDF(CPDF_P
ageObjects* pPage) | 634 IPDF_LayoutProvider* IPDF_LayoutProvider::Create_LayoutProvider_TaggedPDF(CPDF_P
ageObjects* pPage) |
635 { | 635 { |
636 if(pPage == NULL) { | 636 if(pPage == NULL) { |
637 return NULL; | 637 return NULL; |
638 } | 638 } |
639 CPDF_LayoutProvider_TaggedPDF* pProvider = FX_NEW CPDF_LayoutProvider_Tagged
PDF; | 639 CPDF_LayoutProvider_TaggedPDF* pProvider = new CPDF_LayoutProvider_TaggedPDF
; |
640 if (!pProvider) { | |
641 return NULL; | |
642 } | |
643 pProvider->Init(pPage); | 640 pProvider->Init(pPage); |
644 return pProvider; | 641 return pProvider; |
645 } | 642 } |
646 CPDF_LayoutProvider_TaggedPDF::CPDF_LayoutProvider_TaggedPDF() | 643 CPDF_LayoutProvider_TaggedPDF::CPDF_LayoutProvider_TaggedPDF() |
647 { | 644 { |
648 m_pPause = NULL; | 645 m_pPause = NULL; |
649 m_pRoot = NULL; | 646 m_pRoot = NULL; |
650 m_pPageTree = NULL; | 647 m_pPageTree = NULL; |
651 m_pCurTaggedElement = NULL; | 648 m_pCurTaggedElement = NULL; |
652 } | 649 } |
(...skipping 12 matching lines...) Expand all Loading... |
665 } | 662 } |
666 void CPDF_LayoutProvider_TaggedPDF::ProcessElement(CPDF_LayoutElement*pParent, C
PDF_StructElement* pTaggedElement) | 663 void CPDF_LayoutProvider_TaggedPDF::ProcessElement(CPDF_LayoutElement*pParent, C
PDF_StructElement* pTaggedElement) |
667 { | 664 { |
668 if(!pTaggedElement) { | 665 if(!pTaggedElement) { |
669 return; | 666 return; |
670 } | 667 } |
671 if(!pParent) { | 668 if(!pParent) { |
672 m_Status = LayoutError; | 669 m_Status = LayoutError; |
673 return; | 670 return; |
674 } | 671 } |
675 CPDF_LayoutElement* pElement = FX_NEW CPDF_LayoutElement; | 672 CPDF_LayoutElement* pElement = new CPDF_LayoutElement; |
676 if (!pElement) { | |
677 m_Status = LayoutError; | |
678 return; | |
679 } | |
680 pElement->m_pParentElement = pParent; | 673 pElement->m_pParentElement = pParent; |
681 pElement->m_pTaggedElement = pTaggedElement; | 674 pElement->m_pTaggedElement = pTaggedElement; |
682 pParent->m_ChildArray.Add(pElement); | 675 pParent->m_ChildArray.Add(pElement); |
683 int count = pTaggedElement->CountKids(); | 676 int count = pTaggedElement->CountKids(); |
684 for(int i = 0; i < count; i++) { | 677 for(int i = 0; i < count; i++) { |
685 CPDF_StructKid Kid = pTaggedElement->GetKid(i); | 678 CPDF_StructKid Kid = pTaggedElement->GetKid(i); |
686 switch(Kid.m_Type) { | 679 switch(Kid.m_Type) { |
687 case CPDF_StructKid::Element: { | 680 case CPDF_StructKid::Element: { |
688 ProcessElement(pElement, Kid.m_Element.m_pElement); | 681 ProcessElement(pElement, Kid.m_Element.m_pElement); |
689 if(m_Status != LayoutReady) { | 682 if(m_Status != LayoutReady) { |
(...skipping 32 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
722 } | 715 } |
723 if(!m_pPageTree) { | 716 if(!m_pPageTree) { |
724 m_Status = LayoutError; | 717 m_Status = LayoutError; |
725 return LayoutError; | 718 return LayoutError; |
726 } | 719 } |
727 int count = m_pPageTree->CountTopElements(); | 720 int count = m_pPageTree->CountTopElements(); |
728 if(count == 0) { | 721 if(count == 0) { |
729 m_Status = LayoutError; | 722 m_Status = LayoutError; |
730 return LayoutError; | 723 return LayoutError; |
731 } | 724 } |
732 m_pRoot = FX_NEW CPDF_LayoutElement; | 725 m_pRoot = new CPDF_LayoutElement; |
733 if (!m_pRoot) { | |
734 m_Status = LayoutError; | |
735 return LayoutError; | |
736 } | |
737 for(int i = 0; i < count; i++) { | 726 for(int i = 0; i < count; i++) { |
738 CPDF_StructElement* pElement = m_pPageTree->GetTopElement(i); | 727 CPDF_StructElement* pElement = m_pPageTree->GetTopElement(i); |
739 if(pElement) { | 728 if(pElement) { |
740 ProcessElement(m_pRoot, pElement); | 729 ProcessElement(m_pRoot, pElement); |
741 if(m_Status != LayoutReady) { | 730 if(m_Status != LayoutReady) { |
742 return m_Status; | 731 return m_Status; |
743 } | 732 } |
744 } | 733 } |
745 } | 734 } |
746 m_pCurTaggedElement = NULL; | 735 m_pCurTaggedElement = NULL; |
(...skipping 24 matching lines...) Expand all Loading... |
771 return LayoutFinished; | 760 return LayoutFinished; |
772 } | 761 } |
773 int CPDF_LayoutProvider_TaggedPDF::GetPosition() | 762 int CPDF_LayoutProvider_TaggedPDF::GetPosition() |
774 { | 763 { |
775 if(m_TopElementIndex == 0) { | 764 if(m_TopElementIndex == 0) { |
776 return 0; | 765 return 0; |
777 } | 766 } |
778 int count = m_pPageTree->CountTopElements(); | 767 int count = m_pPageTree->CountTopElements(); |
779 return m_TopElementIndex / count * 100; | 768 return m_TopElementIndex / count * 100; |
780 } | 769 } |
OLD | NEW |