1 // Copyright 2014 PDFium Authors. All rights reserved. 2 // Use of this source code is governed by a BSD-style license that can be 3 // found in the LICENSE file. 4 5 // Original code copyright 2014 Foxit Software Inc. http://www.foxitsoftware.com 6 7 #include "fpdfsdk/include/pdfwindow/PWL_Icon.h" 8 #include "fpdfsdk/include/pdfwindow/PWL_Label.h" 9 #include "fpdfsdk/include/pdfwindow/PWL_Signature.h" 10 #include "fpdfsdk/include/pdfwindow/PWL_Utils.h" 11 #include "fpdfsdk/include/pdfwindow/PWL_Wnd.h" 12 13 CPWL_Signature_Image::CPWL_Signature_Image() : m_pImage(NULL) {} 14 15 CPWL_Signature_Image::~CPWL_Signature_Image() {} 16 17 void CPWL_Signature_Image::SetImage(CFX_DIBSource* pImage) { 18 m_pImage = pImage; 19 } 20 21 CFX_DIBSource* CPWL_Signature_Image::GetImage() { 22 return m_pImage; 23 } 24 25 void CPWL_Signature_Image::DrawThisAppearance(CFX_RenderDevice* pDevice, 26 CFX_Matrix* pUser2Device) { 27 CPWL_Wnd::DrawThisAppearance(pDevice, pUser2Device); 28 29 if (m_pImage) { 30 CPDF_Rect rcClient = GetClientRect(); 31 32 FX_FLOAT x, y; 33 pUser2Device->Transform(rcClient.left, rcClient.top, x, y); 34 35 pDevice->StretchDIBits(m_pImage, (int32_t)x, (int32_t)y, 36 (int32_t)rcClient.Width(), 37 (int32_t)rcClient.Height()); 38 } 39 } 40 41 void CPWL_Signature_Image::GetThisAppearanceStream( 42 CFX_ByteTextBuf& sAppStream) { 43 sAppStream << CPWL_Image::GetImageAppStream(); 44 } 45 46 void CPWL_Signature_Image::GetScale(FX_FLOAT& fHScale, FX_FLOAT& fVScale) { 47 FX_FLOAT fImageW, fImageH; 48 49 GetImageSize(fImageW, fImageH); 50 51 CPDF_Rect rcClient = GetClientRect(); 52 53 fHScale = rcClient.Width() / fImageW; 54 fVScale = rcClient.Height() / fImageH; 55 } 56 57 CPWL_Signature::CPWL_Signature() 58 : m_pText(NULL), 59 m_pDescription(NULL), 60 m_pImage(NULL), 61 m_bTextExist(TRUE), 62 m_bImageExist(FALSE), 63 m_bFlagExist(TRUE) {} 64 65 CPWL_Signature::~CPWL_Signature() {} 66 67 void CPWL_Signature::SetTextFlag(FX_BOOL bTextExist) { 68 m_bTextExist = bTextExist; 69 70 RePosChildWnd(); 71 } 72 73 void CPWL_Signature::SetImageFlag(FX_BOOL bImageExist) { 74 m_bImageExist = bImageExist; 75 76 RePosChildWnd(); 77 } 78 79 void CPWL_Signature::SetFoxitFlag(FX_BOOL bFlagExist) { 80 m_bFlagExist = bFlagExist; 81 } 82 83 void CPWL_Signature::SetText(const FX_WCHAR* sText) { 84 m_pText->SetText(sText); 85 86 RePosChildWnd(); 87 } 88 89 void CPWL_Signature::SetDescription(const FX_WCHAR* string) { 90 m_pDescription->SetText(string); 91 92 RePosChildWnd(); 93 } 94 95 void CPWL_Signature::SetImage(CFX_DIBSource* pImage) { 96 m_pImage->SetImage(pImage); 97 98 RePosChildWnd(); 99 } 100 101 void CPWL_Signature::SetImageStream(CPDF_Stream* pStream, 102 const FX_CHAR* sImageAlias) { 103 m_pImage->SetPDFStream(pStream); 104 m_pImage->SetImageAlias(sImageAlias); 105 106 RePosChildWnd(); 107 } 108 109 void CPWL_Signature::RePosChildWnd() { 110 CPDF_Rect rcClient = GetClientRect(); 111 112 CPDF_Rect rcText = rcClient; 113 CPDF_Rect rcDescription = rcClient; 114 115 FX_BOOL bTextVisible = m_bTextExist && m_pText->GetText().GetLength() > 0; 116 117 if ((bTextVisible || m_bImageExist) && 118 m_pDescription->GetText().GetLength() > 0) { 119 if (rcClient.Width() >= rcClient.Height()) { 120 rcText.right = rcText.left + rcClient.Width() / 2.0f; 121 rcDescription.left = rcDescription.right - rcClient.Width() / 2.0f; 122 } else { 123 rcText.bottom = rcText.top - rcClient.Height() / 2.0f; 124 rcDescription.top = rcDescription.bottom + rcClient.Height() / 2.0f; 125 } 126 } 127 128 m_pText->SetVisible(bTextVisible); 129 m_pImage->SetVisible(m_bImageExist); 130 131 m_pText->Move(rcText, TRUE, FALSE); 132 m_pImage->Move(rcText, TRUE, FALSE); 133 m_pDescription->Move(rcDescription, TRUE, FALSE); 134 } 135 136 void CPWL_Signature::CreateChildWnd(const PWL_CREATEPARAM& cp) { 137 m_pImage = new CPWL_Signature_Image; 138 PWL_CREATEPARAM icp = cp; 139 icp.pParentWnd = this; 140 icp.dwFlags = PWS_CHILD | PWS_VISIBLE; 141 icp.sTextColor = CPWL_Color(COLORTYPE_GRAY, 0); 142 m_pImage->Create(icp); 143 144 m_pText = new CPWL_Label; 145 PWL_CREATEPARAM acp = cp; 146 acp.pParentWnd = this; 147 acp.dwFlags = PWS_CHILD | PWS_VISIBLE | PWS_AUTOFONTSIZE | PES_MULTILINE | 148 PES_AUTORETURN | PES_MIDDLE | PES_CENTER; 149 acp.sTextColor = CPWL_Color(COLORTYPE_GRAY, 0); 150 m_pText->Create(acp); 151 152 m_pDescription = new CPWL_Label; 153 PWL_CREATEPARAM dcp = cp; 154 dcp.pParentWnd = this; 155 dcp.dwFlags = PWS_CHILD | PWS_VISIBLE | PWS_AUTOFONTSIZE | PES_MULTILINE | 156 PES_AUTORETURN | PES_LEFT | PES_CENTER; 157 dcp.sTextColor = CPWL_Color(COLORTYPE_GRAY, 0); 158 m_pDescription->Create(dcp); 159 } 160 161 void CPWL_Signature::DrawThisAppearance(CFX_RenderDevice* pDevice, 162 CFX_Matrix* pUser2Device) { 163 CPWL_Wnd::DrawThisAppearance(pDevice, pUser2Device); 164 165 if (m_bFlagExist) { 166 CPWL_Utils::DrawIconAppStream( 167 pDevice, pUser2Device, PWL_ICONTYPE_FOXIT, 168 CPWL_Utils::GetCenterSquare(GetClientRect()), 169 CPWL_Color(COLORTYPE_RGB, 0.91f, 0.855f, 0.92f), 170 CPWL_Color(COLORTYPE_TRANSPARENT), 255); 171 } 172 } 173 174 void CPWL_Signature::GetThisAppearanceStream(CFX_ByteTextBuf& sAppStream) { 175 CPWL_Wnd::GetThisAppearanceStream(sAppStream); 176 } 177