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