jaepark | 2736276 | 2016-08-11 13:10:39 -0700 | [diff] [blame] | 1 | // Copyright 2016 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 | |
dsinclair | 114e46a | 2016-09-29 17:18:21 -0700 | [diff] [blame] | 7 | #include "fpdfsdk/cpdfsdk_baannot.h" |
jaepark | 2736276 | 2016-08-11 13:10:39 -0700 | [diff] [blame] | 8 | |
tsepez | 0e606b5 | 2016-11-18 16:22:41 -0800 | [diff] [blame] | 9 | #include <algorithm> |
tsepez | 9e05ee1 | 2016-11-21 13:19:10 -0800 | [diff] [blame] | 10 | #include <utility> |
tsepez | 0e606b5 | 2016-11-18 16:22:41 -0800 | [diff] [blame] | 11 | |
dsinclair | 488b7ad | 2016-10-04 11:55:50 -0700 | [diff] [blame] | 12 | #include "core/fpdfapi/parser/cpdf_array.h" |
| 13 | #include "core/fpdfapi/parser/cpdf_document.h" |
tsepez | 0e606b5 | 2016-11-18 16:22:41 -0800 | [diff] [blame] | 14 | #include "core/fpdfapi/parser/cpdf_name.h" |
dsinclair | 488b7ad | 2016-10-04 11:55:50 -0700 | [diff] [blame] | 15 | #include "core/fpdfapi/parser/cpdf_number.h" |
tsepez | 0e606b5 | 2016-11-18 16:22:41 -0800 | [diff] [blame] | 16 | #include "core/fpdfapi/parser/cpdf_reference.h" |
dsinclair | 488b7ad | 2016-10-04 11:55:50 -0700 | [diff] [blame] | 17 | #include "core/fpdfapi/parser/cpdf_stream.h" |
tsepez | 0e606b5 | 2016-11-18 16:22:41 -0800 | [diff] [blame] | 18 | #include "core/fpdfapi/parser/cpdf_string.h" |
dsinclair | 488b7ad | 2016-10-04 11:55:50 -0700 | [diff] [blame] | 19 | #include "core/fpdfapi/parser/fpdf_parser_decode.h" |
dsinclair | 114e46a | 2016-09-29 17:18:21 -0700 | [diff] [blame] | 20 | #include "fpdfsdk/cpdfsdk_datetime.h" |
dsinclair | 114e46a | 2016-09-29 17:18:21 -0700 | [diff] [blame] | 21 | #include "fpdfsdk/cpdfsdk_pageview.h" |
jaepark | 2736276 | 2016-08-11 13:10:39 -0700 | [diff] [blame] | 22 | |
| 23 | CPDFSDK_BAAnnot::CPDFSDK_BAAnnot(CPDF_Annot* pAnnot, |
| 24 | CPDFSDK_PageView* pPageView) |
| 25 | : CPDFSDK_Annot(pPageView), m_pAnnot(pAnnot) {} |
| 26 | |
| 27 | CPDFSDK_BAAnnot::~CPDFSDK_BAAnnot() {} |
| 28 | |
| 29 | CPDF_Annot* CPDFSDK_BAAnnot::GetPDFAnnot() const { |
Tom Sepez | 797ca5c | 2017-05-25 12:03:18 -0700 | [diff] [blame] | 30 | return m_pAnnot.Get(); |
jaepark | 2736276 | 2016-08-11 13:10:39 -0700 | [diff] [blame] | 31 | } |
| 32 | |
jaepark | 35512aa | 2016-08-29 17:15:08 -0700 | [diff] [blame] | 33 | CPDF_Annot* CPDFSDK_BAAnnot::GetPDFPopupAnnot() const { |
| 34 | return m_pAnnot->GetPopupAnnot(); |
| 35 | } |
| 36 | |
jaepark | 2736276 | 2016-08-11 13:10:39 -0700 | [diff] [blame] | 37 | CPDF_Dictionary* CPDFSDK_BAAnnot::GetAnnotDict() const { |
| 38 | return m_pAnnot->GetAnnotDict(); |
| 39 | } |
| 40 | |
Dan Sinclair | cb2ea42 | 2017-07-19 15:24:49 -0400 | [diff] [blame] | 41 | CPDF_Dictionary* CPDFSDK_BAAnnot::GetAPDict() const { |
| 42 | CPDF_Dictionary* pAPDict = m_pAnnot->GetAnnotDict()->GetDictFor("AP"); |
| 43 | if (!pAPDict) |
| 44 | pAPDict = m_pAnnot->GetAnnotDict()->SetNewFor<CPDF_Dictionary>("AP"); |
| 45 | return pAPDict; |
| 46 | } |
| 47 | |
jaepark | 2736276 | 2016-08-11 13:10:39 -0700 | [diff] [blame] | 48 | void CPDFSDK_BAAnnot::SetRect(const CFX_FloatRect& rect) { |
| 49 | ASSERT(rect.right - rect.left >= GetMinWidth()); |
| 50 | ASSERT(rect.top - rect.bottom >= GetMinHeight()); |
| 51 | |
dsinclair | 38fd844 | 2016-09-15 10:15:32 -0700 | [diff] [blame] | 52 | m_pAnnot->GetAnnotDict()->SetRectFor("Rect", rect); |
jaepark | 2736276 | 2016-08-11 13:10:39 -0700 | [diff] [blame] | 53 | } |
| 54 | |
| 55 | CFX_FloatRect CPDFSDK_BAAnnot::GetRect() const { |
jaepark | a1d2111 | 2016-08-25 13:33:34 -0700 | [diff] [blame] | 56 | return m_pAnnot->GetRect(); |
jaepark | 2736276 | 2016-08-11 13:10:39 -0700 | [diff] [blame] | 57 | } |
| 58 | |
jaepark | 956553e | 2016-08-31 06:49:27 -0700 | [diff] [blame] | 59 | CPDF_Annot::Subtype CPDFSDK_BAAnnot::GetAnnotSubtype() const { |
jaepark | 9ed9137 | 2016-08-26 16:16:10 -0700 | [diff] [blame] | 60 | return m_pAnnot->GetSubtype(); |
jaepark | 2736276 | 2016-08-11 13:10:39 -0700 | [diff] [blame] | 61 | } |
| 62 | |
| 63 | void CPDFSDK_BAAnnot::DrawAppearance(CFX_RenderDevice* pDevice, |
Lei Zhang | 8a44940 | 2017-08-17 15:07:47 -0700 | [diff] [blame] | 64 | const CFX_Matrix& mtUser2Device, |
jaepark | 2736276 | 2016-08-11 13:10:39 -0700 | [diff] [blame] | 65 | CPDF_Annot::AppearanceMode mode, |
| 66 | const CPDF_RenderOptions* pOptions) { |
Lei Zhang | 8a44940 | 2017-08-17 15:07:47 -0700 | [diff] [blame] | 67 | m_pAnnot->DrawAppearance(m_pPageView->GetPDFPage(), pDevice, mtUser2Device, |
jaepark | 2736276 | 2016-08-11 13:10:39 -0700 | [diff] [blame] | 68 | mode, pOptions); |
| 69 | } |
| 70 | |
tsepez | 4cf5515 | 2016-11-02 14:37:54 -0700 | [diff] [blame] | 71 | bool CPDFSDK_BAAnnot::IsAppearanceValid() { |
dsinclair | 38fd844 | 2016-09-15 10:15:32 -0700 | [diff] [blame] | 72 | return !!m_pAnnot->GetAnnotDict()->GetDictFor("AP"); |
jaepark | 2736276 | 2016-08-11 13:10:39 -0700 | [diff] [blame] | 73 | } |
| 74 | |
tsepez | 4cf5515 | 2016-11-02 14:37:54 -0700 | [diff] [blame] | 75 | bool CPDFSDK_BAAnnot::IsAppearanceValid(CPDF_Annot::AppearanceMode mode) { |
dsinclair | 38fd844 | 2016-09-15 10:15:32 -0700 | [diff] [blame] | 76 | CPDF_Dictionary* pAP = m_pAnnot->GetAnnotDict()->GetDictFor("AP"); |
jaepark | 2736276 | 2016-08-11 13:10:39 -0700 | [diff] [blame] | 77 | if (!pAP) |
tsepez | 4cf5515 | 2016-11-02 14:37:54 -0700 | [diff] [blame] | 78 | return false; |
jaepark | 2736276 | 2016-08-11 13:10:39 -0700 | [diff] [blame] | 79 | |
| 80 | // Choose the right sub-ap |
Dan Sinclair | 812e96c | 2017-03-13 16:43:37 -0400 | [diff] [blame] | 81 | const char* ap_entry = "N"; |
jaepark | 2736276 | 2016-08-11 13:10:39 -0700 | [diff] [blame] | 82 | if (mode == CPDF_Annot::Down) |
| 83 | ap_entry = "D"; |
| 84 | else if (mode == CPDF_Annot::Rollover) |
| 85 | ap_entry = "R"; |
| 86 | if (!pAP->KeyExist(ap_entry)) |
| 87 | ap_entry = "N"; |
| 88 | |
| 89 | // Get the AP stream or subdirectory |
dsinclair | 38fd844 | 2016-09-15 10:15:32 -0700 | [diff] [blame] | 90 | CPDF_Object* psub = pAP->GetDirectObjectFor(ap_entry); |
jaepark | 2736276 | 2016-08-11 13:10:39 -0700 | [diff] [blame] | 91 | return !!psub; |
| 92 | } |
| 93 | |
| 94 | void CPDFSDK_BAAnnot::DrawBorder(CFX_RenderDevice* pDevice, |
| 95 | const CFX_Matrix* pUser2Device, |
| 96 | const CPDF_RenderOptions* pOptions) { |
| 97 | m_pAnnot->DrawBorder(pDevice, pUser2Device, pOptions); |
| 98 | } |
| 99 | |
| 100 | void CPDFSDK_BAAnnot::ClearCachedAP() { |
| 101 | m_pAnnot->ClearCachedAP(); |
| 102 | } |
| 103 | |
Ryan Harrison | 275e260 | 2017-09-18 14:23:18 -0400 | [diff] [blame] | 104 | void CPDFSDK_BAAnnot::SetContents(const WideString& sContents) { |
tsepez | 0e606b5 | 2016-11-18 16:22:41 -0800 | [diff] [blame] | 105 | if (sContents.IsEmpty()) { |
dsinclair | 38fd844 | 2016-09-15 10:15:32 -0700 | [diff] [blame] | 106 | m_pAnnot->GetAnnotDict()->RemoveFor("Contents"); |
tsepez | 0e606b5 | 2016-11-18 16:22:41 -0800 | [diff] [blame] | 107 | } else { |
| 108 | m_pAnnot->GetAnnotDict()->SetNewFor<CPDF_String>( |
| 109 | "Contents", PDF_EncodeText(sContents), false); |
| 110 | } |
jaepark | 2736276 | 2016-08-11 13:10:39 -0700 | [diff] [blame] | 111 | } |
| 112 | |
Ryan Harrison | 275e260 | 2017-09-18 14:23:18 -0400 | [diff] [blame] | 113 | WideString CPDFSDK_BAAnnot::GetContents() const { |
dsinclair | 38fd844 | 2016-09-15 10:15:32 -0700 | [diff] [blame] | 114 | return m_pAnnot->GetAnnotDict()->GetUnicodeTextFor("Contents"); |
jaepark | 2736276 | 2016-08-11 13:10:39 -0700 | [diff] [blame] | 115 | } |
| 116 | |
Ryan Harrison | 275e260 | 2017-09-18 14:23:18 -0400 | [diff] [blame] | 117 | void CPDFSDK_BAAnnot::SetAnnotName(const WideString& sName) { |
tsepez | 0e606b5 | 2016-11-18 16:22:41 -0800 | [diff] [blame] | 118 | if (sName.IsEmpty()) { |
dsinclair | 38fd844 | 2016-09-15 10:15:32 -0700 | [diff] [blame] | 119 | m_pAnnot->GetAnnotDict()->RemoveFor("NM"); |
tsepez | 0e606b5 | 2016-11-18 16:22:41 -0800 | [diff] [blame] | 120 | } else { |
| 121 | m_pAnnot->GetAnnotDict()->SetNewFor<CPDF_String>( |
| 122 | "NM", PDF_EncodeText(sName), false); |
| 123 | } |
jaepark | 2736276 | 2016-08-11 13:10:39 -0700 | [diff] [blame] | 124 | } |
| 125 | |
Ryan Harrison | 275e260 | 2017-09-18 14:23:18 -0400 | [diff] [blame] | 126 | WideString CPDFSDK_BAAnnot::GetAnnotName() const { |
dsinclair | 38fd844 | 2016-09-15 10:15:32 -0700 | [diff] [blame] | 127 | return m_pAnnot->GetAnnotDict()->GetUnicodeTextFor("NM"); |
jaepark | 2736276 | 2016-08-11 13:10:39 -0700 | [diff] [blame] | 128 | } |
| 129 | |
| 130 | void CPDFSDK_BAAnnot::SetModifiedDate(const FX_SYSTEMTIME& st) { |
| 131 | CPDFSDK_DateTime dt(st); |
Ryan Harrison | 275e260 | 2017-09-18 14:23:18 -0400 | [diff] [blame] | 132 | ByteString str = dt.ToPDFDateTimeString(); |
jaepark | 2736276 | 2016-08-11 13:10:39 -0700 | [diff] [blame] | 133 | if (str.IsEmpty()) |
dsinclair | 38fd844 | 2016-09-15 10:15:32 -0700 | [diff] [blame] | 134 | m_pAnnot->GetAnnotDict()->RemoveFor("M"); |
jaepark | 2736276 | 2016-08-11 13:10:39 -0700 | [diff] [blame] | 135 | else |
tsepez | 0e606b5 | 2016-11-18 16:22:41 -0800 | [diff] [blame] | 136 | m_pAnnot->GetAnnotDict()->SetNewFor<CPDF_String>("M", str, false); |
jaepark | 2736276 | 2016-08-11 13:10:39 -0700 | [diff] [blame] | 137 | } |
| 138 | |
| 139 | FX_SYSTEMTIME CPDFSDK_BAAnnot::GetModifiedDate() const { |
| 140 | FX_SYSTEMTIME systime; |
Ryan Harrison | 275e260 | 2017-09-18 14:23:18 -0400 | [diff] [blame] | 141 | ByteString str = m_pAnnot->GetAnnotDict()->GetStringFor("M"); |
jaepark | 2736276 | 2016-08-11 13:10:39 -0700 | [diff] [blame] | 142 | CPDFSDK_DateTime dt(str); |
| 143 | dt.ToSystemTime(systime); |
jaepark | 2736276 | 2016-08-11 13:10:39 -0700 | [diff] [blame] | 144 | return systime; |
| 145 | } |
| 146 | |
| 147 | void CPDFSDK_BAAnnot::SetFlags(uint32_t nFlags) { |
tsepez | 0e606b5 | 2016-11-18 16:22:41 -0800 | [diff] [blame] | 148 | m_pAnnot->GetAnnotDict()->SetNewFor<CPDF_Number>("F", |
| 149 | static_cast<int>(nFlags)); |
jaepark | 2736276 | 2016-08-11 13:10:39 -0700 | [diff] [blame] | 150 | } |
| 151 | |
| 152 | uint32_t CPDFSDK_BAAnnot::GetFlags() const { |
dsinclair | 38fd844 | 2016-09-15 10:15:32 -0700 | [diff] [blame] | 153 | return m_pAnnot->GetAnnotDict()->GetIntegerFor("F"); |
jaepark | 2736276 | 2016-08-11 13:10:39 -0700 | [diff] [blame] | 154 | } |
| 155 | |
Ryan Harrison | 275e260 | 2017-09-18 14:23:18 -0400 | [diff] [blame] | 156 | void CPDFSDK_BAAnnot::SetAppState(const ByteString& str) { |
jaepark | 2736276 | 2016-08-11 13:10:39 -0700 | [diff] [blame] | 157 | if (str.IsEmpty()) |
dsinclair | 38fd844 | 2016-09-15 10:15:32 -0700 | [diff] [blame] | 158 | m_pAnnot->GetAnnotDict()->RemoveFor("AS"); |
jaepark | 2736276 | 2016-08-11 13:10:39 -0700 | [diff] [blame] | 159 | else |
tsepez | 0e606b5 | 2016-11-18 16:22:41 -0800 | [diff] [blame] | 160 | m_pAnnot->GetAnnotDict()->SetNewFor<CPDF_String>("AS", str, false); |
jaepark | 2736276 | 2016-08-11 13:10:39 -0700 | [diff] [blame] | 161 | } |
| 162 | |
Ryan Harrison | 275e260 | 2017-09-18 14:23:18 -0400 | [diff] [blame] | 163 | ByteString CPDFSDK_BAAnnot::GetAppState() const { |
dsinclair | 38fd844 | 2016-09-15 10:15:32 -0700 | [diff] [blame] | 164 | return m_pAnnot->GetAnnotDict()->GetStringFor("AS"); |
jaepark | 2736276 | 2016-08-11 13:10:39 -0700 | [diff] [blame] | 165 | } |
| 166 | |
| 167 | void CPDFSDK_BAAnnot::SetStructParent(int key) { |
tsepez | 0e606b5 | 2016-11-18 16:22:41 -0800 | [diff] [blame] | 168 | m_pAnnot->GetAnnotDict()->SetNewFor<CPDF_Number>("StructParent", key); |
jaepark | 2736276 | 2016-08-11 13:10:39 -0700 | [diff] [blame] | 169 | } |
| 170 | |
| 171 | int CPDFSDK_BAAnnot::GetStructParent() const { |
dsinclair | 38fd844 | 2016-09-15 10:15:32 -0700 | [diff] [blame] | 172 | return m_pAnnot->GetAnnotDict()->GetIntegerFor("StructParent"); |
jaepark | 2736276 | 2016-08-11 13:10:39 -0700 | [diff] [blame] | 173 | } |
| 174 | |
| 175 | // border |
| 176 | void CPDFSDK_BAAnnot::SetBorderWidth(int nWidth) { |
dsinclair | 38fd844 | 2016-09-15 10:15:32 -0700 | [diff] [blame] | 177 | CPDF_Array* pBorder = m_pAnnot->GetAnnotDict()->GetArrayFor("Border"); |
jaepark | 2736276 | 2016-08-11 13:10:39 -0700 | [diff] [blame] | 178 | if (pBorder) { |
tsepez | 8a3aa45 | 2016-11-16 12:26:06 -0800 | [diff] [blame] | 179 | pBorder->SetNewAt<CPDF_Number>(2, nWidth); |
jaepark | 2736276 | 2016-08-11 13:10:39 -0700 | [diff] [blame] | 180 | } else { |
dsinclair | 38fd844 | 2016-09-15 10:15:32 -0700 | [diff] [blame] | 181 | CPDF_Dictionary* pBSDict = m_pAnnot->GetAnnotDict()->GetDictFor("BS"); |
tsepez | 0e606b5 | 2016-11-18 16:22:41 -0800 | [diff] [blame] | 182 | if (!pBSDict) |
| 183 | pBSDict = m_pAnnot->GetAnnotDict()->SetNewFor<CPDF_Dictionary>("BS"); |
| 184 | |
| 185 | pBSDict->SetNewFor<CPDF_Number>("W", nWidth); |
jaepark | 2736276 | 2016-08-11 13:10:39 -0700 | [diff] [blame] | 186 | } |
| 187 | } |
| 188 | |
| 189 | int CPDFSDK_BAAnnot::GetBorderWidth() const { |
tsepez | 698c571 | 2016-09-28 16:47:07 -0700 | [diff] [blame] | 190 | if (CPDF_Array* pBorder = m_pAnnot->GetAnnotDict()->GetArrayFor("Border")) |
jaepark | 2736276 | 2016-08-11 13:10:39 -0700 | [diff] [blame] | 191 | return pBorder->GetIntegerAt(2); |
tsepez | 698c571 | 2016-09-28 16:47:07 -0700 | [diff] [blame] | 192 | |
| 193 | if (CPDF_Dictionary* pBSDict = m_pAnnot->GetAnnotDict()->GetDictFor("BS")) |
dsinclair | 38fd844 | 2016-09-15 10:15:32 -0700 | [diff] [blame] | 194 | return pBSDict->GetIntegerFor("W", 1); |
tsepez | 698c571 | 2016-09-28 16:47:07 -0700 | [diff] [blame] | 195 | |
jaepark | 2736276 | 2016-08-11 13:10:39 -0700 | [diff] [blame] | 196 | return 1; |
| 197 | } |
| 198 | |
| 199 | void CPDFSDK_BAAnnot::SetBorderStyle(BorderStyle nStyle) { |
dsinclair | 38fd844 | 2016-09-15 10:15:32 -0700 | [diff] [blame] | 200 | CPDF_Dictionary* pBSDict = m_pAnnot->GetAnnotDict()->GetDictFor("BS"); |
tsepez | 0e606b5 | 2016-11-18 16:22:41 -0800 | [diff] [blame] | 201 | if (!pBSDict) |
| 202 | pBSDict = m_pAnnot->GetAnnotDict()->SetNewFor<CPDF_Dictionary>("BS"); |
jaepark | 2736276 | 2016-08-11 13:10:39 -0700 | [diff] [blame] | 203 | |
| 204 | switch (nStyle) { |
| 205 | case BorderStyle::SOLID: |
tsepez | 0e606b5 | 2016-11-18 16:22:41 -0800 | [diff] [blame] | 206 | pBSDict->SetNewFor<CPDF_Name>("S", "S"); |
jaepark | 2736276 | 2016-08-11 13:10:39 -0700 | [diff] [blame] | 207 | break; |
| 208 | case BorderStyle::DASH: |
tsepez | 0e606b5 | 2016-11-18 16:22:41 -0800 | [diff] [blame] | 209 | pBSDict->SetNewFor<CPDF_Name>("S", "D"); |
jaepark | 2736276 | 2016-08-11 13:10:39 -0700 | [diff] [blame] | 210 | break; |
| 211 | case BorderStyle::BEVELED: |
tsepez | 0e606b5 | 2016-11-18 16:22:41 -0800 | [diff] [blame] | 212 | pBSDict->SetNewFor<CPDF_Name>("S", "B"); |
jaepark | 2736276 | 2016-08-11 13:10:39 -0700 | [diff] [blame] | 213 | break; |
| 214 | case BorderStyle::INSET: |
tsepez | 0e606b5 | 2016-11-18 16:22:41 -0800 | [diff] [blame] | 215 | pBSDict->SetNewFor<CPDF_Name>("S", "I"); |
jaepark | 2736276 | 2016-08-11 13:10:39 -0700 | [diff] [blame] | 216 | break; |
| 217 | case BorderStyle::UNDERLINE: |
tsepez | 0e606b5 | 2016-11-18 16:22:41 -0800 | [diff] [blame] | 218 | pBSDict->SetNewFor<CPDF_Name>("S", "U"); |
jaepark | 2736276 | 2016-08-11 13:10:39 -0700 | [diff] [blame] | 219 | break; |
| 220 | default: |
| 221 | break; |
| 222 | } |
| 223 | } |
| 224 | |
| 225 | BorderStyle CPDFSDK_BAAnnot::GetBorderStyle() const { |
dsinclair | 38fd844 | 2016-09-15 10:15:32 -0700 | [diff] [blame] | 226 | CPDF_Dictionary* pBSDict = m_pAnnot->GetAnnotDict()->GetDictFor("BS"); |
jaepark | 2736276 | 2016-08-11 13:10:39 -0700 | [diff] [blame] | 227 | if (pBSDict) { |
Ryan Harrison | 275e260 | 2017-09-18 14:23:18 -0400 | [diff] [blame] | 228 | ByteString sBorderStyle = pBSDict->GetStringFor("S", "S"); |
jaepark | 2736276 | 2016-08-11 13:10:39 -0700 | [diff] [blame] | 229 | if (sBorderStyle == "S") |
| 230 | return BorderStyle::SOLID; |
| 231 | if (sBorderStyle == "D") |
| 232 | return BorderStyle::DASH; |
| 233 | if (sBorderStyle == "B") |
| 234 | return BorderStyle::BEVELED; |
| 235 | if (sBorderStyle == "I") |
| 236 | return BorderStyle::INSET; |
| 237 | if (sBorderStyle == "U") |
| 238 | return BorderStyle::UNDERLINE; |
| 239 | } |
| 240 | |
dsinclair | 38fd844 | 2016-09-15 10:15:32 -0700 | [diff] [blame] | 241 | CPDF_Array* pBorder = m_pAnnot->GetAnnotDict()->GetArrayFor("Border"); |
jaepark | 2736276 | 2016-08-11 13:10:39 -0700 | [diff] [blame] | 242 | if (pBorder) { |
| 243 | if (pBorder->GetCount() >= 4) { |
| 244 | CPDF_Array* pDP = pBorder->GetArrayAt(3); |
| 245 | if (pDP && pDP->GetCount() > 0) |
| 246 | return BorderStyle::DASH; |
| 247 | } |
| 248 | } |
| 249 | |
| 250 | return BorderStyle::SOLID; |
| 251 | } |
| 252 | |
| 253 | void CPDFSDK_BAAnnot::SetColor(FX_COLORREF color) { |
tsepez | 0e606b5 | 2016-11-18 16:22:41 -0800 | [diff] [blame] | 254 | CPDF_Array* pArray = m_pAnnot->GetAnnotDict()->SetNewFor<CPDF_Array>("C"); |
Dan Sinclair | 05df075 | 2017-03-14 14:43:42 -0400 | [diff] [blame] | 255 | pArray->AddNew<CPDF_Number>(static_cast<float>(FXSYS_GetRValue(color)) / |
tsepez | 8a3aa45 | 2016-11-16 12:26:06 -0800 | [diff] [blame] | 256 | 255.0f); |
Dan Sinclair | 05df075 | 2017-03-14 14:43:42 -0400 | [diff] [blame] | 257 | pArray->AddNew<CPDF_Number>(static_cast<float>(FXSYS_GetGValue(color)) / |
tsepez | 8a3aa45 | 2016-11-16 12:26:06 -0800 | [diff] [blame] | 258 | 255.0f); |
Dan Sinclair | 05df075 | 2017-03-14 14:43:42 -0400 | [diff] [blame] | 259 | pArray->AddNew<CPDF_Number>(static_cast<float>(FXSYS_GetBValue(color)) / |
tsepez | 8a3aa45 | 2016-11-16 12:26:06 -0800 | [diff] [blame] | 260 | 255.0f); |
jaepark | 2736276 | 2016-08-11 13:10:39 -0700 | [diff] [blame] | 261 | } |
| 262 | |
| 263 | void CPDFSDK_BAAnnot::RemoveColor() { |
dsinclair | 38fd844 | 2016-09-15 10:15:32 -0700 | [diff] [blame] | 264 | m_pAnnot->GetAnnotDict()->RemoveFor("C"); |
jaepark | 2736276 | 2016-08-11 13:10:39 -0700 | [diff] [blame] | 265 | } |
| 266 | |
tsepez | 4cf5515 | 2016-11-02 14:37:54 -0700 | [diff] [blame] | 267 | bool CPDFSDK_BAAnnot::GetColor(FX_COLORREF& color) const { |
dsinclair | 38fd844 | 2016-09-15 10:15:32 -0700 | [diff] [blame] | 268 | if (CPDF_Array* pEntry = m_pAnnot->GetAnnotDict()->GetArrayFor("C")) { |
jaepark | 2736276 | 2016-08-11 13:10:39 -0700 | [diff] [blame] | 269 | size_t nCount = pEntry->GetCount(); |
| 270 | if (nCount == 1) { |
Dan Sinclair | 05df075 | 2017-03-14 14:43:42 -0400 | [diff] [blame] | 271 | float g = pEntry->GetNumberAt(0) * 255; |
jaepark | 2736276 | 2016-08-11 13:10:39 -0700 | [diff] [blame] | 272 | |
| 273 | color = FXSYS_RGB((int)g, (int)g, (int)g); |
| 274 | |
tsepez | 4cf5515 | 2016-11-02 14:37:54 -0700 | [diff] [blame] | 275 | return true; |
jaepark | 2736276 | 2016-08-11 13:10:39 -0700 | [diff] [blame] | 276 | } else if (nCount == 3) { |
Dan Sinclair | 05df075 | 2017-03-14 14:43:42 -0400 | [diff] [blame] | 277 | float r = pEntry->GetNumberAt(0) * 255; |
| 278 | float g = pEntry->GetNumberAt(1) * 255; |
| 279 | float b = pEntry->GetNumberAt(2) * 255; |
jaepark | 2736276 | 2016-08-11 13:10:39 -0700 | [diff] [blame] | 280 | |
| 281 | color = FXSYS_RGB((int)r, (int)g, (int)b); |
| 282 | |
tsepez | 4cf5515 | 2016-11-02 14:37:54 -0700 | [diff] [blame] | 283 | return true; |
jaepark | 2736276 | 2016-08-11 13:10:39 -0700 | [diff] [blame] | 284 | } else if (nCount == 4) { |
Dan Sinclair | 05df075 | 2017-03-14 14:43:42 -0400 | [diff] [blame] | 285 | float c = pEntry->GetNumberAt(0); |
| 286 | float m = pEntry->GetNumberAt(1); |
| 287 | float y = pEntry->GetNumberAt(2); |
| 288 | float k = pEntry->GetNumberAt(3); |
jaepark | 2736276 | 2016-08-11 13:10:39 -0700 | [diff] [blame] | 289 | |
Dan Sinclair | 05df075 | 2017-03-14 14:43:42 -0400 | [diff] [blame] | 290 | float r = 1.0f - std::min(1.0f, c + k); |
| 291 | float g = 1.0f - std::min(1.0f, m + k); |
| 292 | float b = 1.0f - std::min(1.0f, y + k); |
jaepark | 2736276 | 2016-08-11 13:10:39 -0700 | [diff] [blame] | 293 | |
| 294 | color = FXSYS_RGB((int)(r * 255), (int)(g * 255), (int)(b * 255)); |
| 295 | |
tsepez | 4cf5515 | 2016-11-02 14:37:54 -0700 | [diff] [blame] | 296 | return true; |
jaepark | 2736276 | 2016-08-11 13:10:39 -0700 | [diff] [blame] | 297 | } |
| 298 | } |
| 299 | |
tsepez | 4cf5515 | 2016-11-02 14:37:54 -0700 | [diff] [blame] | 300 | return false; |
jaepark | 2736276 | 2016-08-11 13:10:39 -0700 | [diff] [blame] | 301 | } |
| 302 | |
tsepez | 4cf5515 | 2016-11-02 14:37:54 -0700 | [diff] [blame] | 303 | bool CPDFSDK_BAAnnot::IsVisible() const { |
jaepark | 2736276 | 2016-08-11 13:10:39 -0700 | [diff] [blame] | 304 | uint32_t nFlags = GetFlags(); |
| 305 | return !((nFlags & ANNOTFLAG_INVISIBLE) || (nFlags & ANNOTFLAG_HIDDEN) || |
| 306 | (nFlags & ANNOTFLAG_NOVIEW)); |
| 307 | } |
| 308 | |
| 309 | CPDF_Action CPDFSDK_BAAnnot::GetAction() const { |
dsinclair | 38fd844 | 2016-09-15 10:15:32 -0700 | [diff] [blame] | 310 | return CPDF_Action(m_pAnnot->GetAnnotDict()->GetDictFor("A")); |
jaepark | 2736276 | 2016-08-11 13:10:39 -0700 | [diff] [blame] | 311 | } |
| 312 | |
| 313 | void CPDFSDK_BAAnnot::SetAction(const CPDF_Action& action) { |
tsepez | bb577af | 2016-09-21 19:10:19 -0700 | [diff] [blame] | 314 | CPDF_Dictionary* pDict = action.GetDict(); |
| 315 | if (pDict != m_pAnnot->GetAnnotDict()->GetDictFor("A")) { |
jaepark | 2736276 | 2016-08-11 13:10:39 -0700 | [diff] [blame] | 316 | CPDF_Document* pDoc = m_pPageView->GetPDFDocument(); |
tsepez | 70c4afd | 2016-11-15 11:33:44 -0800 | [diff] [blame] | 317 | if (pDict->IsInline()) |
| 318 | pDict = pDoc->AddIndirectObject(pDict->Clone())->AsDictionary(); |
tsepez | 0e606b5 | 2016-11-18 16:22:41 -0800 | [diff] [blame] | 319 | m_pAnnot->GetAnnotDict()->SetNewFor<CPDF_Reference>("A", pDoc, |
| 320 | pDict->GetObjNum()); |
jaepark | 2736276 | 2016-08-11 13:10:39 -0700 | [diff] [blame] | 321 | } |
| 322 | } |
| 323 | |
| 324 | void CPDFSDK_BAAnnot::RemoveAction() { |
dsinclair | 38fd844 | 2016-09-15 10:15:32 -0700 | [diff] [blame] | 325 | m_pAnnot->GetAnnotDict()->RemoveFor("A"); |
jaepark | 2736276 | 2016-08-11 13:10:39 -0700 | [diff] [blame] | 326 | } |
| 327 | |
| 328 | CPDF_AAction CPDFSDK_BAAnnot::GetAAction() const { |
dsinclair | 38fd844 | 2016-09-15 10:15:32 -0700 | [diff] [blame] | 329 | return CPDF_AAction(m_pAnnot->GetAnnotDict()->GetDictFor("AA")); |
jaepark | 2736276 | 2016-08-11 13:10:39 -0700 | [diff] [blame] | 330 | } |
| 331 | |
| 332 | void CPDFSDK_BAAnnot::SetAAction(const CPDF_AAction& aa) { |
dsinclair | 38fd844 | 2016-09-15 10:15:32 -0700 | [diff] [blame] | 333 | if (aa.GetDict() != m_pAnnot->GetAnnotDict()->GetDictFor("AA")) |
tsepez | 0e606b5 | 2016-11-18 16:22:41 -0800 | [diff] [blame] | 334 | m_pAnnot->GetAnnotDict()->SetFor("AA", pdfium::WrapUnique(aa.GetDict())); |
jaepark | 2736276 | 2016-08-11 13:10:39 -0700 | [diff] [blame] | 335 | } |
| 336 | |
| 337 | void CPDFSDK_BAAnnot::RemoveAAction() { |
dsinclair | 38fd844 | 2016-09-15 10:15:32 -0700 | [diff] [blame] | 338 | m_pAnnot->GetAnnotDict()->RemoveFor("AA"); |
jaepark | 2736276 | 2016-08-11 13:10:39 -0700 | [diff] [blame] | 339 | } |
| 340 | |
| 341 | CPDF_Action CPDFSDK_BAAnnot::GetAAction(CPDF_AAction::AActionType eAAT) { |
| 342 | CPDF_AAction AAction = GetAAction(); |
jaepark | 2736276 | 2016-08-11 13:10:39 -0700 | [diff] [blame] | 343 | if (AAction.ActionExist(eAAT)) |
| 344 | return AAction.GetAction(eAAT); |
| 345 | |
| 346 | if (eAAT == CPDF_AAction::ButtonUp) |
| 347 | return GetAction(); |
| 348 | |
| 349 | return CPDF_Action(); |
| 350 | } |
| 351 | |
jaepark | 35512aa | 2016-08-29 17:15:08 -0700 | [diff] [blame] | 352 | void CPDFSDK_BAAnnot::SetOpenState(bool bOpenState) { |
| 353 | if (CPDF_Annot* pAnnot = m_pAnnot->GetPopupAnnot()) |
| 354 | pAnnot->SetOpenState(bOpenState); |
| 355 | } |
Henrique Nakashima | 89bf9ce | 2017-09-19 16:45:10 -0400 | [diff] [blame] | 356 | |
| 357 | int CPDFSDK_BAAnnot::GetLayoutOrder() const { |
| 358 | if (m_pAnnot->GetSubtype() == CPDF_Annot::Subtype::POPUP) |
| 359 | return 1; |
| 360 | |
| 361 | return CPDFSDK_Annot::GetLayoutOrder(); |
| 362 | } |