Add missing operators for CFX_ByteStringC.
[pdfium.git] / core / src / fpdfdoc / doc_annot.cpp
index 227578a..4ccce21 100644 (file)
@@ -4,8 +4,10 @@
  
 // Original code copyright 2014 Foxit Software Inc. http://www.foxitsoftware.com
 
+#include "../../../third_party/base/nonstd_unique_ptr.h"
 #include "../../include/fpdfdoc/fpdf_doc.h"
 #include "../../include/fpdfapi/fpdf_pageobj.h"
+
 CPDF_AnnotList::CPDF_AnnotList(CPDF_Page* pPage)
 {
     ASSERT(pPage != NULL);
@@ -37,10 +39,7 @@ CPDF_AnnotList::CPDF_AnnotList(CPDF_Page* pPage)
             pAnnots->RemoveAt(i + 1);
             pDict = pAnnots->GetDict(i);
         }
-        CPDF_Annot* pAnnot = FX_NEW CPDF_Annot(pDict);
-        if (pAnnot == NULL) {
-            break;
-        }
+        CPDF_Annot* pAnnot = new CPDF_Annot(pDict);
         pAnnot->m_pList = this;
         m_AnnotList.Add(pAnnot);
         if (bRegenerateAP && pDict->GetConstString(FX_BSTRC("Subtype")) == FX_BSTRC("Widget"))
@@ -165,7 +164,7 @@ void CPDF_Annot::ClearCachedAP()
 }
 CFX_ByteString CPDF_Annot::GetSubType() const
 {
-    return m_pAnnotDict->GetConstString(FX_BSTRC("Subtype"));
+    return m_pAnnotDict ? m_pAnnotDict->GetConstString(FX_BSTRC("Subtype")) : CFX_ByteStringC();
 }
 void CPDF_Annot::GetRect(CPDF_Rect& rect) const
 {
@@ -202,7 +201,8 @@ CPDF_Stream* FPDFDOC_GetAnnotAP(CPDF_Dictionary* pAnnotDict, CPDF_Annot::Appeara
         if (as.IsEmpty()) {
             CFX_ByteString value = pAnnotDict->GetString(FX_BSTRC("V"));
             if (value.IsEmpty()) {
-                value = pAnnotDict->GetDict(FX_BSTRC("Parent"))->GetString(FX_BSTRC("V"));
+                CPDF_Dictionary* pDict = pAnnotDict->GetDict(FX_BSTRC("Parent"));
+                value = pDict ? pDict->GetString(FX_BSTRC("V")) : CFX_ByteString();
             }
             if (value.IsEmpty() || !((CPDF_Dictionary*)psub)->KeyExist(value)) {
                 as = FX_BSTRC("Off");
@@ -224,10 +224,7 @@ CPDF_Form* CPDF_Annot::GetAPForm(const CPDF_Page* pPage, AppearanceMode mode)
     if (m_APMap.Lookup(pStream, (void*&)pForm)) {
         return pForm;
     }
-    pForm = FX_NEW CPDF_Form(m_pList->m_pDocument, pPage->m_pResources, pStream);
-    if (pForm == NULL) {
-        return NULL;
-    }
+    pForm = new CPDF_Form(m_pList->m_pDocument, pPage->m_pResources, pStream);
     pForm->ParseContent(NULL, NULL, NULL, NULL);
     m_APMap.SetAt(pStream, pForm);
     return pForm;
@@ -322,19 +319,14 @@ CPDF_PageObject* CPDF_Annot::GetBorder(FX_BOOL bPrint, const CPDF_RenderOptions*
         int B = (FX_INT32)(pColor->GetNumber(2) * 255);
         argb = ArgbEncode(0xff, R, G, B);
     }
-    CPDF_PathObject *pPathObject = FX_NEW CPDF_PathObject();
-    if (!pPathObject) {
-        return NULL;
-    }
+    nonstd::unique_ptr<CPDF_PathObject> pPathObject(new CPDF_PathObject());
     CPDF_GraphStateData *pGraphState = pPathObject->m_GraphState.GetModify();
     if (!pGraphState) {
-        pPathObject->Release();
         return NULL;
     }
     pGraphState->m_LineWidth = width;
     CPDF_ColorStateData *pColorData = pPathObject->m_ColorState.GetModify();
     if (!pColorData) {
-        pPathObject->Release();
         return NULL;
     }
     pColorData->m_StrokeRGB = argb;
@@ -348,7 +340,6 @@ CPDF_PageObject* CPDF_Annot::GetBorder(FX_BOOL bPrint, const CPDF_RenderOptions*
             }
             pGraphState->m_DashArray = FX_Alloc(FX_FLOAT, dash_count);
             if (pGraphState->m_DashArray == NULL) {
-                pPathObject->Release();
                 return NULL;
             }
             pGraphState->m_DashCount = dash_count;
@@ -362,7 +353,6 @@ CPDF_PageObject* CPDF_Annot::GetBorder(FX_BOOL bPrint, const CPDF_RenderOptions*
         } else {
             pGraphState->m_DashArray = FX_Alloc(FX_FLOAT, 2);
             if (pGraphState->m_DashArray == NULL) {
-                pPathObject->Release();
                 return NULL;
             }
             pGraphState->m_DashCount = 2;
@@ -377,7 +367,7 @@ CPDF_PageObject* CPDF_Annot::GetBorder(FX_BOOL bPrint, const CPDF_RenderOptions*
         pPathData->AppendRect(rect.left + width, rect.bottom + width, rect.right - width, rect.top - width);
     }
     pPathObject->CalcBoundingBox();
-    return pPathObject;
+    return pPathObject.release();
 }
 void CPDF_Annot::DrawBorder(CFX_RenderDevice* pDevice, const CFX_AffineMatrix* pUser2Device, const CPDF_RenderOptions* pOptions)
 {