Cleanup: Remove more checks for new returning NULL.
[pdfium.git] / fpdfsdk / src / fpdftext.cpp
index 869ec48..aba24f4 100644 (file)
@@ -1,11 +1,12 @@
 // Copyright 2014 PDFium Authors. All rights reserved.
 // Use of this source code is governed by a BSD-style license that can be
 // found in the LICENSE file.
+
 // Original code copyright 2014 Foxit Software Inc. http://www.foxitsoftware.com
 
-#include "../include/fsdk_define.h"
-#include "../include/fpdftext.h"
+#include "../../core/include/fpdfdoc/fpdf_doc.h"
+#include "../../core/include/fpdftext/fpdf_text.h"
+#include "../../public/fpdf_text.h"
 
 #ifdef _WIN32
 #include <tchar.h>
@@ -18,18 +19,9 @@ 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;
-       }
+       CPDF_ViewerPreferences viewRef(((CPDF_Page*)page)->m_pDocument);
+       textpage=IPDF_TextPage::CreateTextPage((CPDF_Page*)page,viewRef.IsDirectionR2L());
+       textpage->ParseTextPage();
        return textpage;
 }
 DLLEXPORT void STDCALL FPDFText_ClosePage(FPDF_TEXTPAGE text_page)
@@ -74,7 +66,7 @@ DLLEXPORT void STDCALL FPDFText_GetCharBox(FPDF_TEXTPAGE text_page, int index,do
 {
        if (!text_page) return;
        IPDF_TextPage* textpage=(IPDF_TextPage*)text_page;
-       
+
        if (index<0 || index>=textpage->CountChars()) return ;
        FPDF_CHAR_INFO  charinfo;
        textpage->GetCharInfo(index,charinfo);
@@ -96,7 +88,7 @@ DLLEXPORT int STDCALL FPDFText_GetText(FPDF_TEXTPAGE text_page,int start,int cou
 {
        if (!text_page) return 0;
        IPDF_TextPage* textpage=(IPDF_TextPage*)text_page;
-       
+
        if (start>=textpage->CountChars()) return 0;
 
        CFX_WideString str=textpage->GetPageText(start,count);
@@ -130,7 +122,7 @@ DLLEXPORT void STDCALL FPDFText_GetRect(FPDF_TEXTPAGE text_page,int rect_index,
        *bottom=rect.bottom;
 }
 
-DLLEXPORT int STDCALL FPDFText_GetBoundedText(FPDF_TEXTPAGE text_page,double left, double top, 
+DLLEXPORT int STDCALL FPDFText_GetBoundedText(FPDF_TEXTPAGE text_page,double left, double top,
                                                                                          double right, double bottom,unsigned short* buffer,int buflen)
 {
        if (!text_page) return 0;
@@ -150,7 +142,7 @@ DLLEXPORT int STDCALL FPDFText_GetBoundedText(FPDF_TEXTPAGE text_page,double lef
        cbUTF16Str.ReleaseBuffer(size*sizeof(unsigned short));
 
        return size;
-               
+
 }
 
 //Search
@@ -159,18 +151,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 +193,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 +236,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)
 {