• Home
  • Line#
  • Scopes#
  • Navigate#
  • Raw
  • Download
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 "../../include/pdfwindow/PDFWindow.h"
8 #include "../../include/pdfwindow/PWL_Wnd.h"
9 #include "../../include/pdfwindow/PWL_Icon.h"
10 #include "../../include/pdfwindow/PWL_Signature.h"
11 #include "../../include/pdfwindow/PWL_Label.h"
12 #include "../../include/pdfwindow/PWL_Utils.h"
13 
14 /* --------------------------------- CPWL_Signature_Image --------------------------------- */
15 
CPWL_Signature_Image()16 CPWL_Signature_Image::CPWL_Signature_Image() : m_pImage(NULL)
17 {
18 }
19 
~CPWL_Signature_Image()20 CPWL_Signature_Image::~CPWL_Signature_Image()
21 {
22 }
23 
SetImage(CFX_DIBSource * pImage)24 void CPWL_Signature_Image::SetImage(CFX_DIBSource* pImage)
25 {
26 	m_pImage = pImage;
27 }
28 
GetImage()29 CFX_DIBSource* CPWL_Signature_Image::GetImage()
30 {
31 	return m_pImage;
32 }
33 
DrawThisAppearance(CFX_RenderDevice * pDevice,CPDF_Matrix * pUser2Device)34 void CPWL_Signature_Image::DrawThisAppearance(CFX_RenderDevice* pDevice, CPDF_Matrix* pUser2Device)
35 {
36 	CPWL_Wnd::DrawThisAppearance(pDevice, pUser2Device);
37 
38 	if (m_pImage)
39 	{
40 		CPDF_Rect rcClient = GetClientRect();
41 
42 		FX_FLOAT x, y;
43 		pUser2Device->Transform(rcClient.left, rcClient.top, x, y);
44 
45 		pDevice->StretchDIBits(m_pImage, (FX_INT32)x, (FX_INT32)y,
46 			(FX_INT32)rcClient.Width(), (FX_INT32)rcClient.Height());
47 	}
48 }
49 
GetThisAppearanceStream(CFX_ByteTextBuf & sAppStream)50 void CPWL_Signature_Image::GetThisAppearanceStream(CFX_ByteTextBuf & sAppStream)
51 {
52 	sAppStream << CPWL_Image::GetImageAppStream();
53 }
54 
GetScale(FX_FLOAT & fHScale,FX_FLOAT & fVScale)55 void CPWL_Signature_Image::GetScale(FX_FLOAT & fHScale,FX_FLOAT & fVScale)
56 {
57 	FX_FLOAT fImageW, fImageH;
58 
59 	GetImageSize(fImageW, fImageH);
60 
61 	CPDF_Rect rcClient = GetClientRect();
62 
63 	fHScale = rcClient.Width() / fImageW;
64 	fVScale = rcClient.Height() / fImageH;
65 }
66 
67 /* --------------------------------- CPWL_Signature --------------------------------- */
68 
CPWL_Signature()69 CPWL_Signature::CPWL_Signature() :
70 	m_pText(NULL),
71 	m_pDescription(NULL),
72 	m_pImage(NULL),
73 	m_bTextExist(TRUE),
74 	m_bImageExist(FALSE),
75 	m_bFlagExist(TRUE)
76 {
77 }
78 
~CPWL_Signature()79 CPWL_Signature::~CPWL_Signature()
80 {
81 }
82 
SetTextFlag(FX_BOOL bTextExist)83 void CPWL_Signature::SetTextFlag(FX_BOOL bTextExist)
84 {
85 	m_bTextExist = bTextExist;
86 
87 	RePosChildWnd();
88 }
89 
SetImageFlag(FX_BOOL bImageExist)90 void CPWL_Signature::SetImageFlag(FX_BOOL bImageExist)
91 {
92 	m_bImageExist = bImageExist;
93 
94 	RePosChildWnd();
95 }
96 
SetFoxitFlag(FX_BOOL bFlagExist)97 void CPWL_Signature::SetFoxitFlag(FX_BOOL bFlagExist)
98 {
99 	m_bFlagExist = bFlagExist;
100 }
101 
SetText(FX_LPCWSTR sText)102 void CPWL_Signature::SetText(FX_LPCWSTR sText)
103 {
104 	m_pText->SetText(sText);
105 
106 	RePosChildWnd();
107 }
108 
SetDescription(FX_LPCWSTR string)109 void CPWL_Signature::SetDescription(FX_LPCWSTR string)
110 {
111 	m_pDescription->SetText(string);
112 
113 	RePosChildWnd();
114 }
115 
SetImage(CFX_DIBSource * pImage)116 void CPWL_Signature::SetImage(CFX_DIBSource* pImage)
117 {
118 	m_pImage->SetImage(pImage);
119 
120 	RePosChildWnd();
121 }
122 
SetImageStream(CPDF_Stream * pStream,FX_LPCSTR sImageAlias)123 void CPWL_Signature::SetImageStream(CPDF_Stream * pStream, FX_LPCSTR sImageAlias)
124 {
125 	m_pImage->SetPDFStream(pStream);
126 	m_pImage->SetImageAlias(sImageAlias);
127 
128 	RePosChildWnd();
129 }
130 
RePosChildWnd()131 void CPWL_Signature::RePosChildWnd()
132 {
133 	CPDF_Rect rcClient = GetClientRect();
134 
135 	CPDF_Rect rcText = rcClient;
136 	CPDF_Rect rcDescription = rcClient;
137 
138 	FX_BOOL bTextVisible = m_bTextExist && m_pText->GetText().GetLength() > 0;
139 
140 	if ((bTextVisible || m_bImageExist) &&
141 		m_pDescription->GetText().GetLength() > 0)
142 	{
143 		if (rcClient.Width() >= rcClient.Height())
144 		{
145 			rcText.right = rcText.left + rcClient.Width() / 2.0f;
146 			rcDescription.left = rcDescription.right - rcClient.Width() / 2.0f;
147 		}
148 		else
149 		{
150 			rcText.bottom = rcText.top - rcClient.Height() / 2.0f;
151 			rcDescription.top = rcDescription.bottom + rcClient.Height() / 2.0f;
152 		}
153 	}
154 
155 	m_pText->SetVisible(bTextVisible);
156 	m_pImage->SetVisible(m_bImageExist);
157 
158 	m_pText->Move(rcText, TRUE, FALSE);
159 	m_pImage->Move(rcText, TRUE, FALSE);
160 	m_pDescription->Move(rcDescription, TRUE, FALSE);
161 }
162 
CreateChildWnd(const PWL_CREATEPARAM & cp)163 void CPWL_Signature::CreateChildWnd(const PWL_CREATEPARAM & cp)
164 {
165 	m_pImage = new CPWL_Signature_Image;
166 	PWL_CREATEPARAM icp = cp;
167 	icp.pParentWnd = this;
168 	icp.dwFlags = PWS_CHILD | PWS_VISIBLE;
169 	icp.sTextColor = CPWL_Color(COLORTYPE_GRAY, 0);
170 	m_pImage->Create(icp);
171 
172 	m_pText = new CPWL_Label;
173 	PWL_CREATEPARAM acp = cp;
174 	acp.pParentWnd = this;
175 	acp.dwFlags = PWS_CHILD | PWS_VISIBLE | PWS_AUTOFONTSIZE | PES_MULTILINE | PES_AUTORETURN | PES_MIDDLE | PES_CENTER;
176 	acp.sTextColor = CPWL_Color(COLORTYPE_GRAY, 0);
177 	m_pText->Create(acp);
178 
179 	m_pDescription = new CPWL_Label;
180 	PWL_CREATEPARAM dcp = cp;
181 	dcp.pParentWnd = this;
182 	dcp.dwFlags = PWS_CHILD | PWS_VISIBLE | PWS_AUTOFONTSIZE | PES_MULTILINE | PES_AUTORETURN | PES_LEFT | PES_CENTER;
183 	dcp.sTextColor = CPWL_Color(COLORTYPE_GRAY, 0);
184 	m_pDescription->Create(dcp);
185 }
186 
DrawThisAppearance(CFX_RenderDevice * pDevice,CPDF_Matrix * pUser2Device)187 void CPWL_Signature::DrawThisAppearance(CFX_RenderDevice* pDevice, CPDF_Matrix* pUser2Device)
188 {
189 	CPWL_Wnd::DrawThisAppearance(pDevice, pUser2Device);
190 
191 	if (m_bFlagExist)
192 		CPWL_Utils::DrawIconAppStream(pDevice, pUser2Device, PWL_ICONTYPE_FOXIT, CPWL_Utils::GetCenterSquare(GetClientRect()),
193 			CPWL_Color(COLORTYPE_RGB,0.91f,0.855f,0.92f), CPWL_Color(COLORTYPE_TRANSPARENT), 255);
194 
195 	/*
196 	CPDF_Rect rcClient = GetClientRect();
197 
198 	CFX_PathData path;
199 
200 	path.SetPointCount(2);
201 	path.SetPoint(0, rcClient.left, (rcClient.top + rcClient.bottom) * 0.5f, FXPT_MOVETO);
202 	path.SetPoint(1, rcClient.right, (rcClient.top + rcClient.bottom) * 0.5f, FXPT_LINETO);
203 
204 	CFX_GraphStateData gsd;
205 	gsd.SetDashCount(2);
206 	gsd.m_DashArray[0] = 6.0f;
207 	gsd.m_DashArray[1] = 6.0f;
208 	gsd.m_DashPhase = 0;
209 
210 	gsd.m_LineWidth = 10.0f;
211 	pDevice->DrawPath(&path, pUser2Device, &gsd, 0, ArgbEncode(255,255,0,0), FXFILL_ALTERNATE);
212 	*/
213 }
214 
GetThisAppearanceStream(CFX_ByteTextBuf & sAppStream)215 void CPWL_Signature::GetThisAppearanceStream(CFX_ByteTextBuf & sAppStream)
216 {
217 	CPWL_Wnd::GetThisAppearanceStream(sAppStream);
218 }
219 
220 
221