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