Merge to XFA: Create top-level public/ header directory.
[pdfium.git] / fpdfsdk / src / fpdftext.cpp
index 869ec48..951cde0 100644 (file)
@@ -4,8 +4,10 @@
  
 // Original code copyright 2014 Foxit Software Inc. http://www.foxitsoftware.com
 
+#include "../../public/fpdf_text.h"
 #include "../include/fsdk_define.h"
-#include "../include/fpdftext.h"
+#include "../include/fpdfxfa/fpdfxfa_doc.h"
+#include "../include/fpdfxfa/fpdfxfa_page.h"
 
 #ifdef _WIN32
 #include <tchar.h>
@@ -18,18 +20,13 @@ DLLEXPORT FPDF_TEXTPAGE STDCALL FPDFText_LoadPage(FPDF_PAGE page)
 {
        if (!page) return NULL;
        IPDF_TextPage* textpage=NULL;
-       try
-       {
-               CPDF_ViewerPreferences viewRef(((CPDF_Page*)page)->m_pDocument);
-               textpage=IPDF_TextPage::CreateTextPage((CPDF_Page*)page,viewRef.IsDirectionR2L());
-               textpage->ParseTextPage();
-       }
-       catch (...)
-       {
-               if (textpage)
-                       delete textpage;
-               return NULL;
-       }
+       CPDFXFA_Page* pPage = (CPDFXFA_Page*)page;
+       if (!pPage->GetPDFPage()) return NULL;
+       CPDFXFA_Document* pDoc = pPage->GetDocument();
+       CPDF_ViewerPreferences viewRef(pDoc->GetPDFDoc());
+       textpage=IPDF_TextPage::CreateTextPage((CPDF_Page*)pPage->GetPDFPage(),viewRef.IsDirectionR2L());
+       textpage->ParseTextPage();
+
        return textpage;
 }
 DLLEXPORT void STDCALL FPDFText_ClosePage(FPDF_TEXTPAGE text_page)
@@ -159,18 +156,9 @@ DLLEXPORT FPDF_SCHHANDLE STDCALL FPDFText_FindStart(FPDF_TEXTPAGE text_page,FPDF
 {
        if (!text_page) return NULL;
        IPDF_TextPageFind* textpageFind=NULL;
-       try
-       {
-               textpageFind=IPDF_TextPageFind::CreatePageFind((IPDF_TextPage*)text_page);
-               FX_STRSIZE len = CFX_WideString::WStringLength(findwhat);
-               textpageFind->FindFirst(CFX_WideString::FromUTF16LE(findwhat, len),flags,start_index);
-       }
-       catch (...)
-       {
-               if (textpageFind)
-                       delete textpageFind;
-               return NULL;            
-       }
+       textpageFind=IPDF_TextPageFind::CreatePageFind((IPDF_TextPage*)text_page);
+       FX_STRSIZE len = CFX_WideString::WStringLength(findwhat);
+       textpageFind->FindFirst(CFX_WideString::FromUTF16LE(findwhat, len),flags,start_index);
        return textpageFind;
 }
 DLLEXPORT FPDF_BOOL    STDCALL FPDFText_FindNext(FPDF_SCHHANDLE handle)
@@ -210,17 +198,8 @@ DLLEXPORT FPDF_PAGELINK STDCALL FPDFLink_LoadWebLinks(FPDF_TEXTPAGE text_page)
 {
        if (!text_page) return NULL;
        IPDF_LinkExtract* pageLink=NULL;
-       try
-       {
-               pageLink=IPDF_LinkExtract::CreateLinkExtract();
-               pageLink->ExtractLinks((IPDF_TextPage*)text_page);
-       }
-       catch (...)
-       {
-               if (pageLink)
-                       delete pageLink;
-               return NULL;
-       }
+       pageLink=IPDF_LinkExtract::CreateLinkExtract();
+       pageLink->ExtractLinks((IPDF_TextPage*)text_page);
        return pageLink;
 }
 DLLEXPORT int STDCALL FPDFLink_CountWebLinks(FPDF_PAGELINK link_page)
@@ -262,12 +241,13 @@ DLLEXPORT void STDCALL FPDFLink_GetRect(FPDF_PAGELINK link_page,int link_index,
        IPDF_LinkExtract* pageLink=(IPDF_LinkExtract*)link_page;
        CFX_RectArray rectArray;
        pageLink->GetRects(link_index,rectArray);
-       CFX_FloatRect rect;
-       rect=rectArray.GetAt(rect_index);
-       *left=rect.left;
-       *right=rect.right;
-       *top=rect.top;
-       *bottom=rect.bottom;
+       if (rect_index >= 0 && rect_index < rectArray.GetSize()) {
+               CFX_FloatRect rect=rectArray.GetAt(rect_index);
+               *left=rect.left;
+               *right=rect.right;
+               *top=rect.top;
+               *bottom=rect.bottom;
+       }
 }
 DLLEXPORT void STDCALL FPDFLink_CloseWebLinks(FPDF_PAGELINK link_page)
 {