Fix else-after-returns throughout pdfium.
[pdfium.git] / fpdfsdk / src / pdfwindow / PWL_Icon.cpp
index a859a52..71174df 100644 (file)
-// Copyright 2014 PDFium Authors. All rights reserved.\r
-// Use of this source code is governed by a BSD-style license that can be\r
-// found in the LICENSE file.\r
\r
-// Original code copyright 2014 Foxit Software Inc. http://www.foxitsoftware.com\r
-\r
-#include "../../include/pdfwindow/PDFWindow.h"\r
-#include "../../include/pdfwindow/PWL_Wnd.h"\r
-#include "../../include/pdfwindow/PWL_Icon.h"\r
-#include "../../include/pdfwindow/PWL_Utils.h"\r
-\r
-/* ------------------------------- CPWL_Image ---------------------------------- */\r
-\r
-CPWL_Image::CPWL_Image() : m_pPDFStream(NULL)\r
-{\r
-}\r
-\r
-CPWL_Image::~CPWL_Image()\r
-{\r
-}\r
-\r
-CFX_ByteString CPWL_Image::GetImageAppStream()\r
-{\r
-       CFX_ByteTextBuf sAppStream;\r
-\r
-       CFX_ByteString sAlias = this->GetImageAlias();\r
-       CPDF_Rect rcPlate = GetClientRect();\r
-       CPDF_Matrix mt;\r
-       mt.SetReverse(GetImageMatrix());\r
-\r
-       FX_FLOAT fHScale = 1.0f;\r
-       FX_FLOAT fVScale = 1.0f;\r
-       GetScale(fHScale,fVScale);\r
-\r
-       FX_FLOAT fx = 0.0f;\r
-       FX_FLOAT fy = 0.0f;\r
-       GetImageOffset(fx,fy);\r
-\r
-       if (m_pPDFStream && sAlias.GetLength()>0)\r
-       {\r
-               sAppStream << "q\n";\r
-               sAppStream << rcPlate.left << " " << rcPlate.bottom << " "\r
-                       << rcPlate.right - rcPlate.left << " " << rcPlate.top - rcPlate.bottom << " re W n\n";\r
-\r
-               sAppStream << fHScale << " 0 0 " << fVScale << " " << rcPlate.left + fx << " " << rcPlate.bottom + fy << " cm\n";\r
-               sAppStream << mt.GetA() << " " << mt.GetB() << " " << mt.GetC() << " " << mt.GetD() << " " << mt.GetE() << " " << mt.GetF() << " cm\n";\r
-\r
-               sAppStream << "0 g 0 G 1 w /" << sAlias << " Do\n" << "Q\n";\r
-       }\r
-\r
-       return sAppStream.GetByteString();\r
-}\r
-\r
-void CPWL_Image::SetPDFStream(CPDF_Stream * pStream)\r
-{\r
-       m_pPDFStream = pStream;\r
-}\r
-\r
-CPDF_Stream * CPWL_Image::GetPDFStream()\r
-{\r
-       return this->m_pPDFStream;\r
-}\r
-\r
-void CPWL_Image::GetImageSize(FX_FLOAT & fWidth,FX_FLOAT & fHeight)\r
-{\r
-       fWidth = 0.0f;\r
-       fHeight = 0.0f;\r
-\r
-       if (m_pPDFStream)\r
-       {\r
-               if (CPDF_Dictionary * pDict = m_pPDFStream->GetDict())\r
-               {\r
-                       CPDF_Rect rect = pDict->GetRect("BBox");\r
-\r
-                       fWidth = rect.right - rect.left;\r
-                       fHeight = rect.top - rect.bottom;\r
-               }\r
-       }\r
-}\r
-\r
-CPDF_Matrix    CPWL_Image::GetImageMatrix()\r
-{\r
-       if (m_pPDFStream)\r
-       {\r
-               if (CPDF_Dictionary * pDict = m_pPDFStream->GetDict())\r
-               {\r
-                       return pDict->GetMatrix("Matrix");\r
-               }\r
-       }\r
-\r
-       return CPDF_Matrix();\r
-}\r
-\r
-CFX_ByteString CPWL_Image::GetImageAlias()\r
-{\r
-       if (m_sImageAlias.IsEmpty())\r
-       {\r
-               if (m_pPDFStream)\r
-               {\r
-                       if (CPDF_Dictionary * pDict = m_pPDFStream->GetDict())          \r
-                       {\r
-                               return pDict->GetString("Name");\r
-                       }\r
-               }\r
-       }\r
-       else\r
-               return m_sImageAlias;\r
-\r
-       return CFX_ByteString();\r
-}\r
-\r
-void CPWL_Image::SetImageAlias(FX_LPCSTR sImageAlias)\r
-{\r
-       m_sImageAlias = sImageAlias;\r
-}\r
-\r
-void CPWL_Image::GetScale(FX_FLOAT & fHScale,FX_FLOAT & fVScale)\r
-{\r
-       fHScale = 1.0f;\r
-       fVScale = 1.0f;\r
-}\r
-\r
-\r
-void CPWL_Image::GetImageOffset(FX_FLOAT & x,FX_FLOAT & y)\r
-{\r
-       x = 0.0f;\r
-       y = 0.0f;\r
-}\r
-\r
-/* ------------------------------- CPWL_Icon ---------------------------------- */\r
-\r
-CPWL_Icon::CPWL_Icon() : m_pIconFit(NULL)\r
-{\r
-}\r
-\r
-CPWL_Icon::~CPWL_Icon()\r
-{\r
-}\r
-\r
-FX_INT32 CPWL_Icon::GetScaleMethod()\r
-{\r
-       if (m_pIconFit)\r
-               return m_pIconFit->GetScaleMethod();\r
-\r
-       return 0;\r
-}\r
-\r
-FX_BOOL        CPWL_Icon::IsProportionalScale()\r
-{\r
-       if (m_pIconFit)\r
-               return m_pIconFit->IsProportionalScale();\r
-\r
-       return FALSE;\r
-}\r
-\r
-void CPWL_Icon::GetIconPosition(FX_FLOAT & fLeft, FX_FLOAT & fBottom)\r
-{\r
-       if (m_pIconFit)\r
-       {\r
-               //m_pIconFit->GetIconPosition(fLeft,fBottom);\r
-               fLeft = 0.0f;\r
-               fBottom = 0.0f;\r
-               CPDF_Array* pA = m_pIconFit->m_pDict->GetArray("A");\r
-               if (pA != NULL)\r
-               {\r
-                       FX_DWORD dwCount = pA->GetCount();\r
-                       if (dwCount > 0) fLeft = pA->GetNumber(0);\r
-                       if (dwCount > 1) fBottom = pA->GetNumber(1);\r
-               }\r
-       }\r
-       else\r
-       {\r
-               fLeft = 0.0f;\r
-               fBottom = 0.0f;\r
-       }\r
-}\r
-\r
-FX_BOOL CPWL_Icon::GetFittingBounds()\r
-{\r
-       if (m_pIconFit)\r
-               return m_pIconFit->GetFittingBounds();\r
-\r
-       return FALSE;\r
-}\r
-\r
-void CPWL_Icon::GetScale(FX_FLOAT & fHScale,FX_FLOAT & fVScale)\r
-{\r
-       fHScale = 1.0f;\r
-       fVScale = 1.0f;\r
-       \r
-       if (m_pPDFStream)\r
-       {\r
-               FX_FLOAT fImageWidth,fImageHeight;\r
-               FX_FLOAT fPlateWidth,fPlateHeight;\r
-\r
-               CPDF_Rect rcPlate = this->GetClientRect();      \r
-               fPlateWidth = rcPlate.right - rcPlate.left;\r
-               fPlateHeight = rcPlate.top - rcPlate.bottom;\r
-\r
-               GetImageSize(fImageWidth,fImageHeight);\r
-\r
-               FX_INT32 nScaleMethod = this->GetScaleMethod();\r
-\r
-               /*\r
-               enum ScaleMethod\r
-               {\r
-                       Always = 0,     //A, Always scale\r
-                       Bigger,         //B, Scale only when the icon is bigger than the annotation rectangle\r
-                       Smaller,        //S, Scale only when the icon is smaller then the annotation rectangle\r
-                       Never           //N, Never scale\r
-               };\r
-               */\r
-\r
-               switch (nScaleMethod)\r
-               {\r
-               default:\r
-               case 0:\r
-                       fHScale = fPlateWidth / PWL_MAX(fImageWidth,1.0f);\r
-                       fVScale = fPlateHeight / PWL_MAX(fImageHeight,1.0f);\r
-                       break;\r
-               case 1:\r
-                       if (fPlateWidth < fImageWidth)\r
-                               fHScale = fPlateWidth / PWL_MAX(fImageWidth,1.0f);\r
-                       if (fPlateHeight < fImageHeight)\r
-                               fVScale = fPlateHeight / PWL_MAX(fImageHeight,1.0f);\r
-                       break;\r
-               case 2:\r
-                       if (fPlateWidth > fImageWidth)\r
-                               fHScale = fPlateWidth / PWL_MAX(fImageWidth,1.0f);\r
-                       if (fPlateHeight > fImageHeight)\r
-                               fVScale = fPlateHeight / PWL_MAX(fImageHeight,1.0f);\r
-                       break;\r
-               case 3:\r
-                       break;\r
-               }\r
-\r
-               FX_FLOAT fMinScale;\r
-               if (IsProportionalScale())\r
-               {\r
-                       fMinScale = PWL_MIN(fHScale,fVScale);\r
-                       fHScale = fMinScale;\r
-                       fVScale = fMinScale;\r
-               }\r
-       }\r
-}\r
-\r
-void CPWL_Icon::GetImageOffset(FX_FLOAT & x,FX_FLOAT & y)\r
-{\r
-       FX_FLOAT fLeft,fBottom;\r
-\r
-       this->GetIconPosition(fLeft,fBottom);\r
-       x = 0.0f;\r
-       y = 0.0f;\r
-\r
-       FX_FLOAT fImageWidth,fImageHeight;\r
-       GetImageSize(fImageWidth,fImageHeight);\r
-\r
-       FX_FLOAT fHScale,fVScale;\r
-       GetScale(fHScale,fVScale);\r
-\r
-       FX_FLOAT fImageFactWidth = fImageWidth * fHScale;\r
-       FX_FLOAT fImageFactHeight = fImageHeight * fVScale;\r
-\r
-       FX_FLOAT fPlateWidth,fPlateHeight;\r
-       CPDF_Rect rcPlate = this->GetClientRect();      \r
-       fPlateWidth = rcPlate.right - rcPlate.left;\r
-       fPlateHeight = rcPlate.top - rcPlate.bottom;\r
-\r
-       x = (fPlateWidth - fImageFactWidth) * fLeft;\r
-       y = (fPlateHeight - fImageFactHeight)  * fBottom;\r
-}\r
-\r
+// 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/pdfwindow/PDFWindow.h"
+#include "../../include/pdfwindow/PWL_Wnd.h"
+#include "../../include/pdfwindow/PWL_Icon.h"
+#include "../../include/pdfwindow/PWL_Utils.h"
+
+/* ------------------------------- CPWL_Image ---------------------------------- */
+
+CPWL_Image::CPWL_Image() : m_pPDFStream(NULL)
+{
+}
+
+CPWL_Image::~CPWL_Image()
+{
+}
+
+CFX_ByteString CPWL_Image::GetImageAppStream()
+{
+       CFX_ByteTextBuf sAppStream;
+
+       CFX_ByteString sAlias = GetImageAlias();
+       CPDF_Rect rcPlate = GetClientRect();
+       CPDF_Matrix mt;
+       mt.SetReverse(GetImageMatrix());
+
+       FX_FLOAT fHScale = 1.0f;
+       FX_FLOAT fVScale = 1.0f;
+       GetScale(fHScale,fVScale);
+
+       FX_FLOAT fx = 0.0f;
+       FX_FLOAT fy = 0.0f;
+       GetImageOffset(fx,fy);
+
+       if (m_pPDFStream && sAlias.GetLength()>0)
+       {
+               sAppStream << "q\n";
+               sAppStream << rcPlate.left << " " << rcPlate.bottom << " "
+                       << rcPlate.right - rcPlate.left << " " << rcPlate.top - rcPlate.bottom << " re W n\n";
+
+               sAppStream << fHScale << " 0 0 " << fVScale << " " << rcPlate.left + fx << " " << rcPlate.bottom + fy << " cm\n";
+               sAppStream << mt.GetA() << " " << mt.GetB() << " " << mt.GetC() << " " << mt.GetD() << " " << mt.GetE() << " " << mt.GetF() << " cm\n";
+
+               sAppStream << "0 g 0 G 1 w /" << sAlias << " Do\n" << "Q\n";
+       }
+
+       return sAppStream.GetByteString();
+}
+
+void CPWL_Image::SetPDFStream(CPDF_Stream * pStream)
+{
+       m_pPDFStream = pStream;
+}
+
+CPDF_Stream * CPWL_Image::GetPDFStream()
+{
+       return m_pPDFStream;
+}
+
+void CPWL_Image::GetImageSize(FX_FLOAT & fWidth,FX_FLOAT & fHeight)
+{
+       fWidth = 0.0f;
+       fHeight = 0.0f;
+
+       if (m_pPDFStream)
+       {
+               if (CPDF_Dictionary * pDict = m_pPDFStream->GetDict())
+               {
+                       CPDF_Rect rect = pDict->GetRect("BBox");
+
+                       fWidth = rect.right - rect.left;
+                       fHeight = rect.top - rect.bottom;
+               }
+       }
+}
+
+CPDF_Matrix    CPWL_Image::GetImageMatrix()
+{
+       if (m_pPDFStream)
+       {
+               if (CPDF_Dictionary * pDict = m_pPDFStream->GetDict())
+               {
+                       return pDict->GetMatrix("Matrix");
+               }
+       }
+
+       return CPDF_Matrix();
+}
+
+CFX_ByteString CPWL_Image::GetImageAlias()
+{
+       if (m_sImageAlias.IsEmpty())
+       {
+               if (m_pPDFStream)
+               {
+                       if (CPDF_Dictionary * pDict = m_pPDFStream->GetDict())
+                       {
+                               return pDict->GetString("Name");
+                       }
+               }
+       }
+       else
+               return m_sImageAlias;
+
+       return CFX_ByteString();
+}
+
+void CPWL_Image::SetImageAlias(const FX_CHAR* sImageAlias)
+{
+       m_sImageAlias = sImageAlias;
+}
+
+void CPWL_Image::GetScale(FX_FLOAT & fHScale,FX_FLOAT & fVScale)
+{
+       fHScale = 1.0f;
+       fVScale = 1.0f;
+}
+
+
+void CPWL_Image::GetImageOffset(FX_FLOAT & x,FX_FLOAT & y)
+{
+       x = 0.0f;
+       y = 0.0f;
+}
+
+/* ------------------------------- CPWL_Icon ---------------------------------- */
+
+CPWL_Icon::CPWL_Icon() : m_pIconFit(NULL)
+{
+}
+
+CPWL_Icon::~CPWL_Icon()
+{
+}
+
+int32_t CPWL_Icon::GetScaleMethod()
+{
+       if (m_pIconFit)
+               return m_pIconFit->GetScaleMethod();
+
+       return 0;
+}
+
+FX_BOOL        CPWL_Icon::IsProportionalScale()
+{
+       if (m_pIconFit)
+               return m_pIconFit->IsProportionalScale();
+
+       return FALSE;
+}
+
+void CPWL_Icon::GetIconPosition(FX_FLOAT & fLeft, FX_FLOAT & fBottom)
+{
+       if (m_pIconFit)
+       {
+               //m_pIconFit->GetIconPosition(fLeft,fBottom);
+               fLeft = 0.0f;
+               fBottom = 0.0f;
+               CPDF_Array* pA = m_pIconFit->m_pDict ? m_pIconFit->m_pDict->GetArray("A") : NULL;
+               if (pA != NULL)
+               {
+                       FX_DWORD dwCount = pA->GetCount();
+                       if (dwCount > 0) fLeft = pA->GetNumber(0);
+                       if (dwCount > 1) fBottom = pA->GetNumber(1);
+               }
+       }
+       else
+       {
+               fLeft = 0.0f;
+               fBottom = 0.0f;
+       }
+}
+
+FX_BOOL CPWL_Icon::GetFittingBounds()
+{
+       if (m_pIconFit)
+               return m_pIconFit->GetFittingBounds();
+
+       return FALSE;
+}
+
+void CPWL_Icon::GetScale(FX_FLOAT & fHScale,FX_FLOAT & fVScale)
+{
+       fHScale = 1.0f;
+       fVScale = 1.0f;
+
+       if (m_pPDFStream)
+       {
+               FX_FLOAT fImageWidth,fImageHeight;
+               FX_FLOAT fPlateWidth,fPlateHeight;
+
+               CPDF_Rect rcPlate = GetClientRect();
+               fPlateWidth = rcPlate.right - rcPlate.left;
+               fPlateHeight = rcPlate.top - rcPlate.bottom;
+
+               GetImageSize(fImageWidth,fImageHeight);
+
+               int32_t nScaleMethod = GetScaleMethod();
+
+               switch (nScaleMethod)
+               {
+               default:
+               case 0:
+                       fHScale = fPlateWidth / PWL_MAX(fImageWidth,1.0f);
+                       fVScale = fPlateHeight / PWL_MAX(fImageHeight,1.0f);
+                       break;
+               case 1:
+                       if (fPlateWidth < fImageWidth)
+                               fHScale = fPlateWidth / PWL_MAX(fImageWidth,1.0f);
+                       if (fPlateHeight < fImageHeight)
+                               fVScale = fPlateHeight / PWL_MAX(fImageHeight,1.0f);
+                       break;
+               case 2:
+                       if (fPlateWidth > fImageWidth)
+                               fHScale = fPlateWidth / PWL_MAX(fImageWidth,1.0f);
+                       if (fPlateHeight > fImageHeight)
+                               fVScale = fPlateHeight / PWL_MAX(fImageHeight,1.0f);
+                       break;
+               case 3:
+                       break;
+               }
+
+               FX_FLOAT fMinScale;
+               if (IsProportionalScale())
+               {
+                       fMinScale = PWL_MIN(fHScale,fVScale);
+                       fHScale = fMinScale;
+                       fVScale = fMinScale;
+               }
+       }
+}
+
+void CPWL_Icon::GetImageOffset(FX_FLOAT & x,FX_FLOAT & y)
+{
+       FX_FLOAT fLeft,fBottom;
+
+       GetIconPosition(fLeft, fBottom);
+       x = 0.0f;
+       y = 0.0f;
+
+       FX_FLOAT fImageWidth,fImageHeight;
+       GetImageSize(fImageWidth,fImageHeight);
+
+       FX_FLOAT fHScale,fVScale;
+       GetScale(fHScale,fVScale);
+
+       FX_FLOAT fImageFactWidth = fImageWidth * fHScale;
+       FX_FLOAT fImageFactHeight = fImageHeight * fVScale;
+
+       FX_FLOAT fPlateWidth,fPlateHeight;
+       CPDF_Rect rcPlate = GetClientRect();
+       fPlateWidth = rcPlate.right - rcPlate.left;
+       fPlateHeight = rcPlate.top - rcPlate.bottom;
+
+       x = (fPlateWidth - fImageFactWidth) * fLeft;
+       y = (fPlateHeight - fImageFactHeight)  * fBottom;
+}
+