Give names to the shading types
[pdfium.git] / core / src / fpdfapi / fpdf_page / fpdf_page_parser.cpp
index 3295b7f..3057948 100644 (file)
@@ -671,51 +671,28 @@ void CPDF_StreamContentParser::Handle_ExecuteXObject() {
   CFX_ByteString name = GetString(0);
   if (name == m_LastImageName && m_pLastImage && m_pLastImage->GetStream() &&
       m_pLastImage->GetStream()->GetObjNum()) {
-    AddImage(NULL, m_pLastImage, FALSE);
+    AddImage(nullptr, m_pLastImage, FALSE);
     return;
   }
+
   if (m_Options.m_bTextOnly) {
-    CPDF_Object* pRes = NULL;
-    if (m_pResources == NULL) {
+    if (!m_pResources)
       return;
-    }
-    if (m_pResources == m_pPageResources) {
-      CPDF_Dictionary* pList = m_pResources->GetDict(FX_BSTRC("XObject"));
-      if (pList == NULL) {
-        return;
-      }
-      pRes = pList->GetElement(name);
-      if (pRes == NULL || pRes->GetType() != PDFOBJ_REFERENCE) {
-        return;
-      }
-    } else {
-      CPDF_Dictionary* pList = m_pResources->GetDict(FX_BSTRC("XObject"));
-      if (pList == NULL) {
-        if (m_pPageResources == NULL) {
-          return;
-        }
-        CPDF_Dictionary* pList = m_pPageResources->GetDict(FX_BSTRC("XObject"));
-        if (pList == NULL) {
-          return;
-        }
-        pRes = pList->GetElement(name);
-        if (pRes == NULL || pRes->GetType() != PDFOBJ_REFERENCE) {
-          return;
-        }
-      } else {
-        pRes = pList->GetElement(name);
-        if (pRes == NULL || pRes->GetType() != PDFOBJ_REFERENCE) {
-          return;
-        }
-      }
-    }
+
+    CPDF_Dictionary* pList = m_pResources->GetDict(FX_BSTRC("XObject"));
+    if (!pList && m_pPageResources && m_pResources != m_pPageResources)
+      pList = m_pPageResources->GetDict(FX_BSTRC("XObject"));
+    if (!pList)
+      return;
+    CPDF_Reference* pRes = ToReference(pList->GetElement(name));
+    if (!pRes)
+      return;
+
     FX_BOOL bForm;
-    if (m_pDocument->IsFormStream(((CPDF_Reference*)pRes)->GetRefObjNum(),
-                                  bForm) &&
-        !bForm) {
+    if (m_pDocument->IsFormStream(pRes->GetRefObjNum(), bForm) && !bForm)
       return;
-    }
   }
+
   CPDF_Stream* pXObject = ToStream(FindResourceObj(FX_BSTRC("XObject"), name));
   if (!pXObject) {
     m_bResourceMissing = TRUE;
@@ -1115,12 +1092,13 @@ void CPDF_StreamContentParser::Handle_SetColorPS_Stroke() {
   }
   FX_Free(values);
 }
-CFX_FloatRect _GetShadingBBox(CPDF_Stream* pStream,
-                              int type,
-                              const CFX_AffineMatrix* pMatrix,
-                              CPDF_Function** pFuncs,
-                              int nFuncs,
-                              CPDF_ColorSpace* pCS);
+CFX_FloatRect GetShadingBBox(CPDF_Stream* pStream,
+                             ShadingType type,
+                             const CFX_AffineMatrix* pMatrix,
+                             CPDF_Function** pFuncs,
+                             int nFuncs,
+                             CPDF_ColorSpace* pCS);
+
 void CPDF_StreamContentParser::Handle_ShadeFill() {
   if (m_Options.m_bTextOnly) {
     return;
@@ -1150,11 +1128,11 @@ void CPDF_StreamContentParser::Handle_ShadeFill() {
   } else {
     bbox = m_BBox;
   }
-  if (pShading->m_ShadingType >= 4) {
-    bbox.Intersect(_GetShadingBBox(ToStream(pShading->m_pShadingObj),
-                                   pShading->m_ShadingType, &pObj->m_Matrix,
-                                   pShading->m_pFunctions, pShading->m_nFuncs,
-                                   pShading->m_pCS));
+  if (pShading->IsMeshShading()) {
+    bbox.Intersect(GetShadingBBox(ToStream(pShading->m_pShadingObj),
+                                  pShading->m_ShadingType, &pObj->m_Matrix,
+                                  pShading->m_pFunctions, pShading->m_nFuncs,
+                                  pShading->m_pCS));
   }
   pObj->m_Left = bbox.left;
   pObj->m_Right = bbox.right;