| OLD | NEW |
| 1 // Copyright 2016 PDFium Authors. All rights reserved. | 1 // Copyright 2016 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 "fpdfsdk/cpdfsdk_baannot.h" | 7 #include "fpdfsdk/cpdfsdk_baannot.h" |
| 8 | 8 |
| 9 #include "core/fpdfapi/parser/cpdf_array.h" | 9 #include "core/fpdfapi/parser/cpdf_array.h" |
| 10 #include "core/fpdfapi/parser/cpdf_document.h" | 10 #include "core/fpdfapi/parser/cpdf_document.h" |
| (...skipping 37 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
| 48 } | 48 } |
| 49 | 49 |
| 50 void CPDFSDK_BAAnnot::DrawAppearance(CFX_RenderDevice* pDevice, | 50 void CPDFSDK_BAAnnot::DrawAppearance(CFX_RenderDevice* pDevice, |
| 51 const CFX_Matrix* pUser2Device, | 51 const CFX_Matrix* pUser2Device, |
| 52 CPDF_Annot::AppearanceMode mode, | 52 CPDF_Annot::AppearanceMode mode, |
| 53 const CPDF_RenderOptions* pOptions) { | 53 const CPDF_RenderOptions* pOptions) { |
| 54 m_pAnnot->DrawAppearance(m_pPageView->GetPDFPage(), pDevice, pUser2Device, | 54 m_pAnnot->DrawAppearance(m_pPageView->GetPDFPage(), pDevice, pUser2Device, |
| 55 mode, pOptions); | 55 mode, pOptions); |
| 56 } | 56 } |
| 57 | 57 |
| 58 FX_BOOL CPDFSDK_BAAnnot::IsAppearanceValid() { | 58 bool CPDFSDK_BAAnnot::IsAppearanceValid() { |
| 59 return !!m_pAnnot->GetAnnotDict()->GetDictFor("AP"); | 59 return !!m_pAnnot->GetAnnotDict()->GetDictFor("AP"); |
| 60 } | 60 } |
| 61 | 61 |
| 62 FX_BOOL CPDFSDK_BAAnnot::IsAppearanceValid(CPDF_Annot::AppearanceMode mode) { | 62 bool CPDFSDK_BAAnnot::IsAppearanceValid(CPDF_Annot::AppearanceMode mode) { |
| 63 CPDF_Dictionary* pAP = m_pAnnot->GetAnnotDict()->GetDictFor("AP"); | 63 CPDF_Dictionary* pAP = m_pAnnot->GetAnnotDict()->GetDictFor("AP"); |
| 64 if (!pAP) | 64 if (!pAP) |
| 65 return FALSE; | 65 return false; |
| 66 | 66 |
| 67 // Choose the right sub-ap | 67 // Choose the right sub-ap |
| 68 const FX_CHAR* ap_entry = "N"; | 68 const FX_CHAR* ap_entry = "N"; |
| 69 if (mode == CPDF_Annot::Down) | 69 if (mode == CPDF_Annot::Down) |
| 70 ap_entry = "D"; | 70 ap_entry = "D"; |
| 71 else if (mode == CPDF_Annot::Rollover) | 71 else if (mode == CPDF_Annot::Rollover) |
| 72 ap_entry = "R"; | 72 ap_entry = "R"; |
| 73 if (!pAP->KeyExist(ap_entry)) | 73 if (!pAP->KeyExist(ap_entry)) |
| 74 ap_entry = "N"; | 74 ap_entry = "N"; |
| 75 | 75 |
| (...skipping 169 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
| 245 pArray->AddNumber((FX_FLOAT)FXSYS_GetRValue(color) / 255.0f); | 245 pArray->AddNumber((FX_FLOAT)FXSYS_GetRValue(color) / 255.0f); |
| 246 pArray->AddNumber((FX_FLOAT)FXSYS_GetGValue(color) / 255.0f); | 246 pArray->AddNumber((FX_FLOAT)FXSYS_GetGValue(color) / 255.0f); |
| 247 pArray->AddNumber((FX_FLOAT)FXSYS_GetBValue(color) / 255.0f); | 247 pArray->AddNumber((FX_FLOAT)FXSYS_GetBValue(color) / 255.0f); |
| 248 m_pAnnot->GetAnnotDict()->SetFor("C", pArray); | 248 m_pAnnot->GetAnnotDict()->SetFor("C", pArray); |
| 249 } | 249 } |
| 250 | 250 |
| 251 void CPDFSDK_BAAnnot::RemoveColor() { | 251 void CPDFSDK_BAAnnot::RemoveColor() { |
| 252 m_pAnnot->GetAnnotDict()->RemoveFor("C"); | 252 m_pAnnot->GetAnnotDict()->RemoveFor("C"); |
| 253 } | 253 } |
| 254 | 254 |
| 255 FX_BOOL CPDFSDK_BAAnnot::GetColor(FX_COLORREF& color) const { | 255 bool CPDFSDK_BAAnnot::GetColor(FX_COLORREF& color) const { |
| 256 if (CPDF_Array* pEntry = m_pAnnot->GetAnnotDict()->GetArrayFor("C")) { | 256 if (CPDF_Array* pEntry = m_pAnnot->GetAnnotDict()->GetArrayFor("C")) { |
| 257 size_t nCount = pEntry->GetCount(); | 257 size_t nCount = pEntry->GetCount(); |
| 258 if (nCount == 1) { | 258 if (nCount == 1) { |
| 259 FX_FLOAT g = pEntry->GetNumberAt(0) * 255; | 259 FX_FLOAT g = pEntry->GetNumberAt(0) * 255; |
| 260 | 260 |
| 261 color = FXSYS_RGB((int)g, (int)g, (int)g); | 261 color = FXSYS_RGB((int)g, (int)g, (int)g); |
| 262 | 262 |
| 263 return TRUE; | 263 return true; |
| 264 } else if (nCount == 3) { | 264 } else if (nCount == 3) { |
| 265 FX_FLOAT r = pEntry->GetNumberAt(0) * 255; | 265 FX_FLOAT r = pEntry->GetNumberAt(0) * 255; |
| 266 FX_FLOAT g = pEntry->GetNumberAt(1) * 255; | 266 FX_FLOAT g = pEntry->GetNumberAt(1) * 255; |
| 267 FX_FLOAT b = pEntry->GetNumberAt(2) * 255; | 267 FX_FLOAT b = pEntry->GetNumberAt(2) * 255; |
| 268 | 268 |
| 269 color = FXSYS_RGB((int)r, (int)g, (int)b); | 269 color = FXSYS_RGB((int)r, (int)g, (int)b); |
| 270 | 270 |
| 271 return TRUE; | 271 return true; |
| 272 } else if (nCount == 4) { | 272 } else if (nCount == 4) { |
| 273 FX_FLOAT c = pEntry->GetNumberAt(0); | 273 FX_FLOAT c = pEntry->GetNumberAt(0); |
| 274 FX_FLOAT m = pEntry->GetNumberAt(1); | 274 FX_FLOAT m = pEntry->GetNumberAt(1); |
| 275 FX_FLOAT y = pEntry->GetNumberAt(2); | 275 FX_FLOAT y = pEntry->GetNumberAt(2); |
| 276 FX_FLOAT k = pEntry->GetNumberAt(3); | 276 FX_FLOAT k = pEntry->GetNumberAt(3); |
| 277 | 277 |
| 278 FX_FLOAT r = 1.0f - std::min(1.0f, c + k); | 278 FX_FLOAT r = 1.0f - std::min(1.0f, c + k); |
| 279 FX_FLOAT g = 1.0f - std::min(1.0f, m + k); | 279 FX_FLOAT g = 1.0f - std::min(1.0f, m + k); |
| 280 FX_FLOAT b = 1.0f - std::min(1.0f, y + k); | 280 FX_FLOAT b = 1.0f - std::min(1.0f, y + k); |
| 281 | 281 |
| 282 color = FXSYS_RGB((int)(r * 255), (int)(g * 255), (int)(b * 255)); | 282 color = FXSYS_RGB((int)(r * 255), (int)(g * 255), (int)(b * 255)); |
| 283 | 283 |
| 284 return TRUE; | 284 return true; |
| 285 } | 285 } |
| 286 } | 286 } |
| 287 | 287 |
| 288 return FALSE; | 288 return false; |
| 289 } | 289 } |
| 290 | 290 |
| 291 void CPDFSDK_BAAnnot::WriteAppearance(const CFX_ByteString& sAPType, | 291 void CPDFSDK_BAAnnot::WriteAppearance(const CFX_ByteString& sAPType, |
| 292 const CFX_FloatRect& rcBBox, | 292 const CFX_FloatRect& rcBBox, |
| 293 const CFX_Matrix& matrix, | 293 const CFX_Matrix& matrix, |
| 294 const CFX_ByteString& sContents, | 294 const CFX_ByteString& sContents, |
| 295 const CFX_ByteString& sAPState) { | 295 const CFX_ByteString& sAPState) { |
| 296 CPDF_Dictionary* pAPDict = m_pAnnot->GetAnnotDict()->GetDictFor("AP"); | 296 CPDF_Dictionary* pAPDict = m_pAnnot->GetAnnotDict()->GetDictFor("AP"); |
| 297 if (!pAPDict) { | 297 if (!pAPDict) { |
| 298 pAPDict = new CPDF_Dictionary(m_pAnnot->GetDocument()->GetByteStringPool()); | 298 pAPDict = new CPDF_Dictionary(m_pAnnot->GetDocument()->GetByteStringPool()); |
| (...skipping 34 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
| 333 } | 333 } |
| 334 | 334 |
| 335 if (pStreamDict) { | 335 if (pStreamDict) { |
| 336 pStreamDict->SetMatrixFor("Matrix", matrix); | 336 pStreamDict->SetMatrixFor("Matrix", matrix); |
| 337 pStreamDict->SetRectFor("BBox", rcBBox); | 337 pStreamDict->SetRectFor("BBox", rcBBox); |
| 338 } | 338 } |
| 339 | 339 |
| 340 pStream->SetData((uint8_t*)sContents.c_str(), sContents.GetLength()); | 340 pStream->SetData((uint8_t*)sContents.c_str(), sContents.GetLength()); |
| 341 } | 341 } |
| 342 | 342 |
| 343 FX_BOOL CPDFSDK_BAAnnot::IsVisible() const { | 343 bool CPDFSDK_BAAnnot::IsVisible() const { |
| 344 uint32_t nFlags = GetFlags(); | 344 uint32_t nFlags = GetFlags(); |
| 345 return !((nFlags & ANNOTFLAG_INVISIBLE) || (nFlags & ANNOTFLAG_HIDDEN) || | 345 return !((nFlags & ANNOTFLAG_INVISIBLE) || (nFlags & ANNOTFLAG_HIDDEN) || |
| 346 (nFlags & ANNOTFLAG_NOVIEW)); | 346 (nFlags & ANNOTFLAG_NOVIEW)); |
| 347 } | 347 } |
| 348 | 348 |
| 349 CPDF_Action CPDFSDK_BAAnnot::GetAction() const { | 349 CPDF_Action CPDFSDK_BAAnnot::GetAction() const { |
| 350 return CPDF_Action(m_pAnnot->GetAnnotDict()->GetDictFor("A")); | 350 return CPDF_Action(m_pAnnot->GetAnnotDict()->GetDictFor("A")); |
| 351 } | 351 } |
| 352 | 352 |
| 353 void CPDFSDK_BAAnnot::SetAction(const CPDF_Action& action) { | 353 void CPDFSDK_BAAnnot::SetAction(const CPDF_Action& action) { |
| (...skipping 39 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
| 393 CPDF_RenderOptions* pOptions) { | 393 CPDF_RenderOptions* pOptions) { |
| 394 m_pAnnot->GetAPForm(m_pPageView->GetPDFPage(), CPDF_Annot::Normal); | 394 m_pAnnot->GetAPForm(m_pPageView->GetPDFPage(), CPDF_Annot::Normal); |
| 395 m_pAnnot->DrawAppearance(m_pPageView->GetPDFPage(), pDevice, pUser2Device, | 395 m_pAnnot->DrawAppearance(m_pPageView->GetPDFPage(), pDevice, pUser2Device, |
| 396 CPDF_Annot::Normal, nullptr); | 396 CPDF_Annot::Normal, nullptr); |
| 397 } | 397 } |
| 398 | 398 |
| 399 void CPDFSDK_BAAnnot::SetOpenState(bool bOpenState) { | 399 void CPDFSDK_BAAnnot::SetOpenState(bool bOpenState) { |
| 400 if (CPDF_Annot* pAnnot = m_pAnnot->GetPopupAnnot()) | 400 if (CPDF_Annot* pAnnot = m_pAnnot->GetPopupAnnot()) |
| 401 pAnnot->SetOpenState(bOpenState); | 401 pAnnot->SetOpenState(bOpenState); |
| 402 } | 402 } |
| OLD | NEW |