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