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