Fix else-after-returns throughout pdfium.
[pdfium.git] / fpdfsdk / src / pdfwindow / PWL_Signature.cpp
index 36297f3..76b2bd3 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_Signature.h"\r
-#include "../../include/pdfwindow/PWL_Label.h"\r
-#include "../../include/pdfwindow/PWL_Utils.h"\r
-\r
-/* --------------------------------- CPWL_Signature_Image --------------------------------- */\r
-\r
-CPWL_Signature_Image::CPWL_Signature_Image() : m_pImage(NULL)\r
-{\r
-}\r
-\r
-CPWL_Signature_Image::~CPWL_Signature_Image()\r
-{\r
-}\r
-\r
-void CPWL_Signature_Image::SetImage(CFX_DIBSource* pImage)\r
-{\r
-       m_pImage = pImage;\r
-}\r
-\r
-CFX_DIBSource* CPWL_Signature_Image::GetImage()\r
-{\r
-       return m_pImage;\r
-}\r
-\r
-void CPWL_Signature_Image::DrawThisAppearance(CFX_RenderDevice* pDevice, CPDF_Matrix* pUser2Device)\r
-{\r
-       CPWL_Wnd::DrawThisAppearance(pDevice, pUser2Device);\r
-\r
-       if (m_pImage)\r
-       {\r
-               CPDF_Rect rcClient = GetClientRect();\r
-\r
-               FX_FLOAT x, y;\r
-               pUser2Device->Transform(rcClient.left, rcClient.top, x, y);\r
-\r
-               pDevice->StretchDIBits(m_pImage, (FX_INT32)x, (FX_INT32)y, \r
-                       (FX_INT32)rcClient.Width(), (FX_INT32)rcClient.Height());\r
-       }\r
-}\r
-\r
-void CPWL_Signature_Image::GetThisAppearanceStream(CFX_ByteTextBuf & sAppStream)\r
-{\r
-       sAppStream << CPWL_Image::GetImageAppStream();\r
-}\r
-\r
-void CPWL_Signature_Image::GetScale(FX_FLOAT & fHScale,FX_FLOAT & fVScale)\r
-{\r
-       FX_FLOAT fImageW, fImageH;\r
-\r
-       GetImageSize(fImageW, fImageH);\r
-\r
-       CPDF_Rect rcClient = GetClientRect();\r
-\r
-       fHScale = rcClient.Width() / fImageW;\r
-       fVScale = rcClient.Height() / fImageH;  \r
-}\r
-\r
-/* --------------------------------- CPWL_Signature --------------------------------- */\r
-\r
-CPWL_Signature::CPWL_Signature() : \r
-       m_pText(NULL),\r
-       m_pDescription(NULL),\r
-       m_pImage(NULL),\r
-       m_bTextExist(TRUE),\r
-       m_bImageExist(FALSE),\r
-       m_bFlagExist(TRUE)\r
-{\r
-}\r
-\r
-CPWL_Signature::~CPWL_Signature()\r
-{\r
-}\r
-\r
-void CPWL_Signature::SetTextFlag(FX_BOOL bTextExist)\r
-{\r
-       m_bTextExist = bTextExist;\r
-\r
-       RePosChildWnd();\r
-}\r
-\r
-void CPWL_Signature::SetImageFlag(FX_BOOL bImageExist)\r
-{\r
-       m_bImageExist = bImageExist;\r
-\r
-       RePosChildWnd();\r
-}\r
-\r
-void CPWL_Signature::SetFoxitFlag(FX_BOOL bFlagExist)\r
-{\r
-       m_bFlagExist = bFlagExist;\r
-}\r
-\r
-void CPWL_Signature::SetText(FX_LPCWSTR sText)\r
-{\r
-       m_pText->SetText(sText);\r
-\r
-       RePosChildWnd();\r
-}\r
-\r
-void CPWL_Signature::SetDescription(FX_LPCWSTR string)\r
-{\r
-       m_pDescription->SetText(string);\r
-\r
-       RePosChildWnd();\r
-}\r
-\r
-void CPWL_Signature::SetImage(CFX_DIBSource* pImage)\r
-{\r
-       m_pImage->SetImage(pImage);\r
-\r
-       RePosChildWnd();\r
-}\r
-\r
-void CPWL_Signature::SetImageStream(CPDF_Stream * pStream, FX_LPCSTR sImageAlias)\r
-{\r
-       m_pImage->SetPDFStream(pStream);\r
-       m_pImage->SetImageAlias(sImageAlias);\r
-\r
-       RePosChildWnd();\r
-}\r
-\r
-void CPWL_Signature::RePosChildWnd()\r
-{\r
-       CPDF_Rect rcClient = GetClientRect();\r
-\r
-       CPDF_Rect rcText = rcClient;\r
-       CPDF_Rect rcDescription = rcClient;\r
-\r
-       FX_BOOL bTextVisible = m_bTextExist && m_pText->GetText().GetLength() > 0;\r
-       \r
-       if ((bTextVisible || m_bImageExist) &&\r
-               m_pDescription->GetText().GetLength() > 0)\r
-       {\r
-               if (rcClient.Width() >= rcClient.Height())\r
-               {\r
-                       rcText.right = rcText.left + rcClient.Width() / 2.0f;\r
-                       rcDescription.left = rcDescription.right - rcClient.Width() / 2.0f;\r
-               }\r
-               else\r
-               {\r
-                       rcText.bottom = rcText.top - rcClient.Height() / 2.0f;\r
-                       rcDescription.top = rcDescription.bottom + rcClient.Height() / 2.0f;\r
-               }\r
-       }\r
-\r
-       m_pText->SetVisible(bTextVisible);\r
-       m_pImage->SetVisible(m_bImageExist);\r
-\r
-       m_pText->Move(rcText, TRUE, FALSE);\r
-       m_pImage->Move(rcText, TRUE, FALSE);\r
-       m_pDescription->Move(rcDescription, TRUE, FALSE);\r
-}\r
-\r
-void CPWL_Signature::CreateChildWnd(const PWL_CREATEPARAM & cp)\r
-{\r
-       m_pImage = new CPWL_Signature_Image;\r
-       PWL_CREATEPARAM icp = cp;\r
-       icp.pParentWnd = this;\r
-       icp.dwFlags = PWS_CHILD | PWS_VISIBLE;\r
-       icp.sTextColor = CPWL_Color(COLORTYPE_GRAY, 0);\r
-       m_pImage->Create(icp);\r
-\r
-       m_pText = new CPWL_Label;\r
-       PWL_CREATEPARAM acp = cp;\r
-       acp.pParentWnd = this;\r
-       acp.dwFlags = PWS_CHILD | PWS_VISIBLE | PWS_AUTOFONTSIZE | PES_MULTILINE | PES_AUTORETURN | PES_MIDDLE | PES_CENTER;\r
-       acp.sTextColor = CPWL_Color(COLORTYPE_GRAY, 0);\r
-       m_pText->Create(acp);\r
-\r
-       m_pDescription = new CPWL_Label;\r
-       PWL_CREATEPARAM dcp = cp;\r
-       dcp.pParentWnd = this;\r
-       dcp.dwFlags = PWS_CHILD | PWS_VISIBLE | PWS_AUTOFONTSIZE | PES_MULTILINE | PES_AUTORETURN | PES_LEFT | PES_CENTER;\r
-       dcp.sTextColor = CPWL_Color(COLORTYPE_GRAY, 0);\r
-       m_pDescription->Create(dcp);\r
-}\r
-\r
-void CPWL_Signature::DrawThisAppearance(CFX_RenderDevice* pDevice, CPDF_Matrix* pUser2Device)\r
-{\r
-       CPWL_Wnd::DrawThisAppearance(pDevice, pUser2Device);\r
-\r
-       if (m_bFlagExist)\r
-               CPWL_Utils::DrawIconAppStream(pDevice, pUser2Device, PWL_ICONTYPE_FOXIT, CPWL_Utils::GetCenterSquare(GetClientRect()),\r
-                       CPWL_Color(COLORTYPE_RGB,0.91f,0.855f,0.92f), CPWL_Color(COLORTYPE_TRANSPARENT), 255);\r
-\r
-       /*\r
-       CPDF_Rect rcClient = GetClientRect();\r
-\r
-       CFX_PathData path;\r
-\r
-       path.SetPointCount(2);\r
-       path.SetPoint(0, rcClient.left, (rcClient.top + rcClient.bottom) * 0.5f, FXPT_MOVETO);\r
-       path.SetPoint(1, rcClient.right, (rcClient.top + rcClient.bottom) * 0.5f, FXPT_LINETO);\r
-\r
-       CFX_GraphStateData gsd;\r
-       gsd.SetDashCount(2);                            \r
-       gsd.m_DashArray[0] = 6.0f;\r
-       gsd.m_DashArray[1] = 6.0f;\r
-       gsd.m_DashPhase = 0;    \r
-       \r
-       gsd.m_LineWidth = 10.0f;\r
-       pDevice->DrawPath(&path, pUser2Device, &gsd, 0, ArgbEncode(255,255,0,0), FXFILL_ALTERNATE);\r
-       */\r
-}\r
-\r
-void CPWL_Signature::GetThisAppearanceStream(CFX_ByteTextBuf & sAppStream)\r
-{\r
-       CPWL_Wnd::GetThisAppearanceStream(sAppStream);\r
-}\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_Signature.h"
+#include "../../include/pdfwindow/PWL_Label.h"
+#include "../../include/pdfwindow/PWL_Utils.h"
+
+/* --------------------------------- CPWL_Signature_Image --------------------------------- */
+
+CPWL_Signature_Image::CPWL_Signature_Image() : m_pImage(NULL)
+{
+}
+
+CPWL_Signature_Image::~CPWL_Signature_Image()
+{
+}
+
+void CPWL_Signature_Image::SetImage(CFX_DIBSource* pImage)
+{
+       m_pImage = pImage;
+}
+
+CFX_DIBSource* CPWL_Signature_Image::GetImage()
+{
+       return m_pImage;
+}
+
+void CPWL_Signature_Image::DrawThisAppearance(CFX_RenderDevice* pDevice, CPDF_Matrix* pUser2Device)
+{
+       CPWL_Wnd::DrawThisAppearance(pDevice, pUser2Device);
+
+       if (m_pImage)
+       {
+               CPDF_Rect rcClient = GetClientRect();
+
+               FX_FLOAT x, y;
+               pUser2Device->Transform(rcClient.left, rcClient.top, x, y);
+
+               pDevice->StretchDIBits(m_pImage, (int32_t)x, (int32_t)y,
+                       (int32_t)rcClient.Width(), (int32_t)rcClient.Height());
+       }
+}
+
+void CPWL_Signature_Image::GetThisAppearanceStream(CFX_ByteTextBuf & sAppStream)
+{
+       sAppStream << CPWL_Image::GetImageAppStream();
+}
+
+void CPWL_Signature_Image::GetScale(FX_FLOAT & fHScale,FX_FLOAT & fVScale)
+{
+       FX_FLOAT fImageW, fImageH;
+
+       GetImageSize(fImageW, fImageH);
+
+       CPDF_Rect rcClient = GetClientRect();
+
+       fHScale = rcClient.Width() / fImageW;
+       fVScale = rcClient.Height() / fImageH;
+}
+
+/* --------------------------------- CPWL_Signature --------------------------------- */
+
+CPWL_Signature::CPWL_Signature() :
+       m_pText(NULL),
+       m_pDescription(NULL),
+       m_pImage(NULL),
+       m_bTextExist(TRUE),
+       m_bImageExist(FALSE),
+       m_bFlagExist(TRUE)
+{
+}
+
+CPWL_Signature::~CPWL_Signature()
+{
+}
+
+void CPWL_Signature::SetTextFlag(FX_BOOL bTextExist)
+{
+       m_bTextExist = bTextExist;
+
+       RePosChildWnd();
+}
+
+void CPWL_Signature::SetImageFlag(FX_BOOL bImageExist)
+{
+       m_bImageExist = bImageExist;
+
+       RePosChildWnd();
+}
+
+void CPWL_Signature::SetFoxitFlag(FX_BOOL bFlagExist)
+{
+       m_bFlagExist = bFlagExist;
+}
+
+void CPWL_Signature::SetText(const FX_WCHAR* sText)
+{
+       m_pText->SetText(sText);
+
+       RePosChildWnd();
+}
+
+void CPWL_Signature::SetDescription(const FX_WCHAR* string)
+{
+       m_pDescription->SetText(string);
+
+       RePosChildWnd();
+}
+
+void CPWL_Signature::SetImage(CFX_DIBSource* pImage)
+{
+       m_pImage->SetImage(pImage);
+
+       RePosChildWnd();
+}
+
+void CPWL_Signature::SetImageStream(CPDF_Stream * pStream, const FX_CHAR* sImageAlias)
+{
+       m_pImage->SetPDFStream(pStream);
+       m_pImage->SetImageAlias(sImageAlias);
+
+       RePosChildWnd();
+}
+
+void CPWL_Signature::RePosChildWnd()
+{
+       CPDF_Rect rcClient = GetClientRect();
+
+       CPDF_Rect rcText = rcClient;
+       CPDF_Rect rcDescription = rcClient;
+
+       FX_BOOL bTextVisible = m_bTextExist && m_pText->GetText().GetLength() > 0;
+
+       if ((bTextVisible || m_bImageExist) &&
+               m_pDescription->GetText().GetLength() > 0)
+       {
+               if (rcClient.Width() >= rcClient.Height())
+               {
+                       rcText.right = rcText.left + rcClient.Width() / 2.0f;
+                       rcDescription.left = rcDescription.right - rcClient.Width() / 2.0f;
+               }
+               else
+               {
+                       rcText.bottom = rcText.top - rcClient.Height() / 2.0f;
+                       rcDescription.top = rcDescription.bottom + rcClient.Height() / 2.0f;
+               }
+       }
+
+       m_pText->SetVisible(bTextVisible);
+       m_pImage->SetVisible(m_bImageExist);
+
+       m_pText->Move(rcText, TRUE, FALSE);
+       m_pImage->Move(rcText, TRUE, FALSE);
+       m_pDescription->Move(rcDescription, TRUE, FALSE);
+}
+
+void CPWL_Signature::CreateChildWnd(const PWL_CREATEPARAM & cp)
+{
+       m_pImage = new CPWL_Signature_Image;
+       PWL_CREATEPARAM icp = cp;
+       icp.pParentWnd = this;
+       icp.dwFlags = PWS_CHILD | PWS_VISIBLE;
+       icp.sTextColor = CPWL_Color(COLORTYPE_GRAY, 0);
+       m_pImage->Create(icp);
+
+       m_pText = new CPWL_Label;
+       PWL_CREATEPARAM acp = cp;
+       acp.pParentWnd = this;
+       acp.dwFlags = PWS_CHILD | PWS_VISIBLE | PWS_AUTOFONTSIZE | PES_MULTILINE | PES_AUTORETURN | PES_MIDDLE | PES_CENTER;
+       acp.sTextColor = CPWL_Color(COLORTYPE_GRAY, 0);
+       m_pText->Create(acp);
+
+       m_pDescription = new CPWL_Label;
+       PWL_CREATEPARAM dcp = cp;
+       dcp.pParentWnd = this;
+       dcp.dwFlags = PWS_CHILD | PWS_VISIBLE | PWS_AUTOFONTSIZE | PES_MULTILINE | PES_AUTORETURN | PES_LEFT | PES_CENTER;
+       dcp.sTextColor = CPWL_Color(COLORTYPE_GRAY, 0);
+       m_pDescription->Create(dcp);
+}
+
+void CPWL_Signature::DrawThisAppearance(CFX_RenderDevice* pDevice, CPDF_Matrix* pUser2Device)
+{
+       CPWL_Wnd::DrawThisAppearance(pDevice, pUser2Device);
+
+       if (m_bFlagExist)
+               CPWL_Utils::DrawIconAppStream(pDevice, pUser2Device, PWL_ICONTYPE_FOXIT, CPWL_Utils::GetCenterSquare(GetClientRect()),
+                       CPWL_Color(COLORTYPE_RGB,0.91f,0.855f,0.92f), CPWL_Color(COLORTYPE_TRANSPARENT), 255);
+
+       /*
+       CPDF_Rect rcClient = GetClientRect();
+
+       CFX_PathData path;
+
+       path.SetPointCount(2);
+       path.SetPoint(0, rcClient.left, (rcClient.top + rcClient.bottom) * 0.5f, FXPT_MOVETO);
+       path.SetPoint(1, rcClient.right, (rcClient.top + rcClient.bottom) * 0.5f, FXPT_LINETO);
+
+       CFX_GraphStateData gsd;
+       gsd.SetDashCount(2);
+       gsd.m_DashArray[0] = 6.0f;
+       gsd.m_DashArray[1] = 6.0f;
+       gsd.m_DashPhase = 0;
+
+       gsd.m_LineWidth = 10.0f;
+       pDevice->DrawPath(&path, pUser2Device, &gsd, 0, ArgbEncode(255,255,0,0), FXFILL_ALTERNATE);
+       */
+}
+
+void CPWL_Signature::GetThisAppearanceStream(CFX_ByteTextBuf & sAppStream)
+{
+       CPWL_Wnd::GetThisAppearanceStream(sAppStream);
+}
+
+