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 | |
| 166 | if (pBorder) { |
| 167 | pBorder->SetAt(2, new CPDF_Number(nWidth)); |
| 168 | } else { |
dsinclair | 38fd844 | 2016-09-15 10:15:32 -0700 | [diff] [blame^] | 169 | CPDF_Dictionary* pBSDict = m_pAnnot->GetAnnotDict()->GetDictFor("BS"); |
jaepark | 2736276 | 2016-08-11 13:10:39 -0700 | [diff] [blame] | 170 | |
| 171 | if (!pBSDict) { |
| 172 | pBSDict = new CPDF_Dictionary; |
dsinclair | 38fd844 | 2016-09-15 10:15:32 -0700 | [diff] [blame^] | 173 | m_pAnnot->GetAnnotDict()->SetFor("BS", pBSDict); |
jaepark | 2736276 | 2016-08-11 13:10:39 -0700 | [diff] [blame] | 174 | } |
| 175 | |
dsinclair | 38fd844 | 2016-09-15 10:15:32 -0700 | [diff] [blame^] | 176 | pBSDict->SetIntegerFor("W", nWidth); |
jaepark | 2736276 | 2016-08-11 13:10:39 -0700 | [diff] [blame] | 177 | } |
| 178 | } |
| 179 | |
| 180 | int CPDFSDK_BAAnnot::GetBorderWidth() const { |
dsinclair | 38fd844 | 2016-09-15 10:15:32 -0700 | [diff] [blame^] | 181 | if (CPDF_Array* pBorder = m_pAnnot->GetAnnotDict()->GetArrayFor("Border")) { |
jaepark | 2736276 | 2016-08-11 13:10:39 -0700 | [diff] [blame] | 182 | return pBorder->GetIntegerAt(2); |
| 183 | } |
dsinclair | 38fd844 | 2016-09-15 10:15:32 -0700 | [diff] [blame^] | 184 | if (CPDF_Dictionary* pBSDict = m_pAnnot->GetAnnotDict()->GetDictFor("BS")) { |
| 185 | return pBSDict->GetIntegerFor("W", 1); |
jaepark | 2736276 | 2016-08-11 13:10:39 -0700 | [diff] [blame] | 186 | } |
| 187 | return 1; |
| 188 | } |
| 189 | |
| 190 | void CPDFSDK_BAAnnot::SetBorderStyle(BorderStyle nStyle) { |
dsinclair | 38fd844 | 2016-09-15 10:15:32 -0700 | [diff] [blame^] | 191 | CPDF_Dictionary* pBSDict = m_pAnnot->GetAnnotDict()->GetDictFor("BS"); |
jaepark | 2736276 | 2016-08-11 13:10:39 -0700 | [diff] [blame] | 192 | if (!pBSDict) { |
| 193 | pBSDict = new CPDF_Dictionary; |
dsinclair | 38fd844 | 2016-09-15 10:15:32 -0700 | [diff] [blame^] | 194 | m_pAnnot->GetAnnotDict()->SetFor("BS", pBSDict); |
jaepark | 2736276 | 2016-08-11 13:10:39 -0700 | [diff] [blame] | 195 | } |
| 196 | |
| 197 | switch (nStyle) { |
| 198 | case BorderStyle::SOLID: |
dsinclair | 38fd844 | 2016-09-15 10:15:32 -0700 | [diff] [blame^] | 199 | pBSDict->SetNameFor("S", "S"); |
jaepark | 2736276 | 2016-08-11 13:10:39 -0700 | [diff] [blame] | 200 | break; |
| 201 | case BorderStyle::DASH: |
dsinclair | 38fd844 | 2016-09-15 10:15:32 -0700 | [diff] [blame^] | 202 | pBSDict->SetNameFor("S", "D"); |
jaepark | 2736276 | 2016-08-11 13:10:39 -0700 | [diff] [blame] | 203 | break; |
| 204 | case BorderStyle::BEVELED: |
dsinclair | 38fd844 | 2016-09-15 10:15:32 -0700 | [diff] [blame^] | 205 | pBSDict->SetNameFor("S", "B"); |
jaepark | 2736276 | 2016-08-11 13:10:39 -0700 | [diff] [blame] | 206 | break; |
| 207 | case BorderStyle::INSET: |
dsinclair | 38fd844 | 2016-09-15 10:15:32 -0700 | [diff] [blame^] | 208 | pBSDict->SetNameFor("S", "I"); |
jaepark | 2736276 | 2016-08-11 13:10:39 -0700 | [diff] [blame] | 209 | break; |
| 210 | case BorderStyle::UNDERLINE: |
dsinclair | 38fd844 | 2016-09-15 10:15:32 -0700 | [diff] [blame^] | 211 | pBSDict->SetNameFor("S", "U"); |
jaepark | 2736276 | 2016-08-11 13:10:39 -0700 | [diff] [blame] | 212 | break; |
| 213 | default: |
| 214 | break; |
| 215 | } |
| 216 | } |
| 217 | |
| 218 | BorderStyle CPDFSDK_BAAnnot::GetBorderStyle() const { |
dsinclair | 38fd844 | 2016-09-15 10:15:32 -0700 | [diff] [blame^] | 219 | CPDF_Dictionary* pBSDict = m_pAnnot->GetAnnotDict()->GetDictFor("BS"); |
jaepark | 2736276 | 2016-08-11 13:10:39 -0700 | [diff] [blame] | 220 | if (pBSDict) { |
dsinclair | 38fd844 | 2016-09-15 10:15:32 -0700 | [diff] [blame^] | 221 | CFX_ByteString sBorderStyle = pBSDict->GetStringFor("S", "S"); |
jaepark | 2736276 | 2016-08-11 13:10:39 -0700 | [diff] [blame] | 222 | if (sBorderStyle == "S") |
| 223 | return BorderStyle::SOLID; |
| 224 | if (sBorderStyle == "D") |
| 225 | return BorderStyle::DASH; |
| 226 | if (sBorderStyle == "B") |
| 227 | return BorderStyle::BEVELED; |
| 228 | if (sBorderStyle == "I") |
| 229 | return BorderStyle::INSET; |
| 230 | if (sBorderStyle == "U") |
| 231 | return BorderStyle::UNDERLINE; |
| 232 | } |
| 233 | |
dsinclair | 38fd844 | 2016-09-15 10:15:32 -0700 | [diff] [blame^] | 234 | CPDF_Array* pBorder = m_pAnnot->GetAnnotDict()->GetArrayFor("Border"); |
jaepark | 2736276 | 2016-08-11 13:10:39 -0700 | [diff] [blame] | 235 | if (pBorder) { |
| 236 | if (pBorder->GetCount() >= 4) { |
| 237 | CPDF_Array* pDP = pBorder->GetArrayAt(3); |
| 238 | if (pDP && pDP->GetCount() > 0) |
| 239 | return BorderStyle::DASH; |
| 240 | } |
| 241 | } |
| 242 | |
| 243 | return BorderStyle::SOLID; |
| 244 | } |
| 245 | |
| 246 | void CPDFSDK_BAAnnot::SetColor(FX_COLORREF color) { |
| 247 | CPDF_Array* pArray = new CPDF_Array; |
| 248 | pArray->AddNumber((FX_FLOAT)FXSYS_GetRValue(color) / 255.0f); |
| 249 | pArray->AddNumber((FX_FLOAT)FXSYS_GetGValue(color) / 255.0f); |
| 250 | pArray->AddNumber((FX_FLOAT)FXSYS_GetBValue(color) / 255.0f); |
dsinclair | 38fd844 | 2016-09-15 10:15:32 -0700 | [diff] [blame^] | 251 | m_pAnnot->GetAnnotDict()->SetFor("C", pArray); |
jaepark | 2736276 | 2016-08-11 13:10:39 -0700 | [diff] [blame] | 252 | } |
| 253 | |
| 254 | void CPDFSDK_BAAnnot::RemoveColor() { |
dsinclair | 38fd844 | 2016-09-15 10:15:32 -0700 | [diff] [blame^] | 255 | m_pAnnot->GetAnnotDict()->RemoveFor("C"); |
jaepark | 2736276 | 2016-08-11 13:10:39 -0700 | [diff] [blame] | 256 | } |
| 257 | |
| 258 | FX_BOOL CPDFSDK_BAAnnot::GetColor(FX_COLORREF& color) const { |
dsinclair | 38fd844 | 2016-09-15 10:15:32 -0700 | [diff] [blame^] | 259 | if (CPDF_Array* pEntry = m_pAnnot->GetAnnotDict()->GetArrayFor("C")) { |
jaepark | 2736276 | 2016-08-11 13:10:39 -0700 | [diff] [blame] | 260 | size_t nCount = pEntry->GetCount(); |
| 261 | if (nCount == 1) { |
| 262 | FX_FLOAT g = pEntry->GetNumberAt(0) * 255; |
| 263 | |
| 264 | color = FXSYS_RGB((int)g, (int)g, (int)g); |
| 265 | |
| 266 | return TRUE; |
| 267 | } else if (nCount == 3) { |
| 268 | FX_FLOAT r = pEntry->GetNumberAt(0) * 255; |
| 269 | FX_FLOAT g = pEntry->GetNumberAt(1) * 255; |
| 270 | FX_FLOAT b = pEntry->GetNumberAt(2) * 255; |
| 271 | |
| 272 | color = FXSYS_RGB((int)r, (int)g, (int)b); |
| 273 | |
| 274 | return TRUE; |
| 275 | } else if (nCount == 4) { |
| 276 | FX_FLOAT c = pEntry->GetNumberAt(0); |
| 277 | FX_FLOAT m = pEntry->GetNumberAt(1); |
| 278 | FX_FLOAT y = pEntry->GetNumberAt(2); |
| 279 | FX_FLOAT k = pEntry->GetNumberAt(3); |
| 280 | |
| 281 | FX_FLOAT r = 1.0f - std::min(1.0f, c + k); |
| 282 | FX_FLOAT g = 1.0f - std::min(1.0f, m + k); |
| 283 | FX_FLOAT b = 1.0f - std::min(1.0f, y + k); |
| 284 | |
| 285 | color = FXSYS_RGB((int)(r * 255), (int)(g * 255), (int)(b * 255)); |
| 286 | |
| 287 | return TRUE; |
| 288 | } |
| 289 | } |
| 290 | |
| 291 | return FALSE; |
| 292 | } |
| 293 | |
| 294 | void CPDFSDK_BAAnnot::WriteAppearance(const CFX_ByteString& sAPType, |
| 295 | const CFX_FloatRect& rcBBox, |
| 296 | const CFX_Matrix& matrix, |
| 297 | const CFX_ByteString& sContents, |
| 298 | const CFX_ByteString& sAPState) { |
dsinclair | 38fd844 | 2016-09-15 10:15:32 -0700 | [diff] [blame^] | 299 | CPDF_Dictionary* pAPDict = m_pAnnot->GetAnnotDict()->GetDictFor("AP"); |
jaepark | 2736276 | 2016-08-11 13:10:39 -0700 | [diff] [blame] | 300 | |
| 301 | if (!pAPDict) { |
| 302 | pAPDict = new CPDF_Dictionary; |
dsinclair | 38fd844 | 2016-09-15 10:15:32 -0700 | [diff] [blame^] | 303 | m_pAnnot->GetAnnotDict()->SetFor("AP", pAPDict); |
jaepark | 2736276 | 2016-08-11 13:10:39 -0700 | [diff] [blame] | 304 | } |
| 305 | |
| 306 | CPDF_Stream* pStream = nullptr; |
| 307 | CPDF_Dictionary* pParentDict = nullptr; |
| 308 | |
| 309 | if (sAPState.IsEmpty()) { |
| 310 | pParentDict = pAPDict; |
dsinclair | 38fd844 | 2016-09-15 10:15:32 -0700 | [diff] [blame^] | 311 | pStream = pAPDict->GetStreamFor(sAPType); |
jaepark | 2736276 | 2016-08-11 13:10:39 -0700 | [diff] [blame] | 312 | } else { |
dsinclair | 38fd844 | 2016-09-15 10:15:32 -0700 | [diff] [blame^] | 313 | CPDF_Dictionary* pAPTypeDict = pAPDict->GetDictFor(sAPType); |
jaepark | 2736276 | 2016-08-11 13:10:39 -0700 | [diff] [blame] | 314 | if (!pAPTypeDict) { |
| 315 | pAPTypeDict = new CPDF_Dictionary; |
dsinclair | 38fd844 | 2016-09-15 10:15:32 -0700 | [diff] [blame^] | 316 | pAPDict->SetFor(sAPType, pAPTypeDict); |
jaepark | 2736276 | 2016-08-11 13:10:39 -0700 | [diff] [blame] | 317 | } |
| 318 | pParentDict = pAPTypeDict; |
dsinclair | 38fd844 | 2016-09-15 10:15:32 -0700 | [diff] [blame^] | 319 | pStream = pAPTypeDict->GetStreamFor(sAPState); |
jaepark | 2736276 | 2016-08-11 13:10:39 -0700 | [diff] [blame] | 320 | } |
| 321 | |
| 322 | if (!pStream) { |
| 323 | pStream = new CPDF_Stream(nullptr, 0, nullptr); |
| 324 | CPDF_Document* pDoc = m_pPageView->GetPDFDocument(); |
| 325 | int32_t objnum = pDoc->AddIndirectObject(pStream); |
dsinclair | 38fd844 | 2016-09-15 10:15:32 -0700 | [diff] [blame^] | 326 | pParentDict->SetReferenceFor(sAPType, pDoc, objnum); |
jaepark | 2736276 | 2016-08-11 13:10:39 -0700 | [diff] [blame] | 327 | } |
| 328 | |
| 329 | CPDF_Dictionary* pStreamDict = pStream->GetDict(); |
| 330 | if (!pStreamDict) { |
| 331 | pStreamDict = new CPDF_Dictionary; |
dsinclair | 38fd844 | 2016-09-15 10:15:32 -0700 | [diff] [blame^] | 332 | pStreamDict->SetNameFor("Type", "XObject"); |
| 333 | pStreamDict->SetNameFor("Subtype", "Form"); |
| 334 | pStreamDict->SetIntegerFor("FormType", 1); |
jaepark | 2736276 | 2016-08-11 13:10:39 -0700 | [diff] [blame] | 335 | pStream->InitStream(nullptr, 0, pStreamDict); |
| 336 | } |
| 337 | |
| 338 | if (pStreamDict) { |
dsinclair | 38fd844 | 2016-09-15 10:15:32 -0700 | [diff] [blame^] | 339 | pStreamDict->SetMatrixFor("Matrix", matrix); |
| 340 | pStreamDict->SetRectFor("BBox", rcBBox); |
jaepark | 2736276 | 2016-08-11 13:10:39 -0700 | [diff] [blame] | 341 | } |
| 342 | |
| 343 | pStream->SetData((uint8_t*)sContents.c_str(), sContents.GetLength(), FALSE, |
| 344 | FALSE); |
| 345 | } |
| 346 | |
| 347 | FX_BOOL CPDFSDK_BAAnnot::IsVisible() const { |
| 348 | uint32_t nFlags = GetFlags(); |
| 349 | return !((nFlags & ANNOTFLAG_INVISIBLE) || (nFlags & ANNOTFLAG_HIDDEN) || |
| 350 | (nFlags & ANNOTFLAG_NOVIEW)); |
| 351 | } |
| 352 | |
| 353 | CPDF_Action CPDFSDK_BAAnnot::GetAction() const { |
dsinclair | 38fd844 | 2016-09-15 10:15:32 -0700 | [diff] [blame^] | 354 | return CPDF_Action(m_pAnnot->GetAnnotDict()->GetDictFor("A")); |
jaepark | 2736276 | 2016-08-11 13:10:39 -0700 | [diff] [blame] | 355 | } |
| 356 | |
| 357 | void CPDFSDK_BAAnnot::SetAction(const CPDF_Action& action) { |
| 358 | ASSERT(action.GetDict()); |
dsinclair | 38fd844 | 2016-09-15 10:15:32 -0700 | [diff] [blame^] | 359 | if (action.GetDict() != m_pAnnot->GetAnnotDict()->GetDictFor("A")) { |
jaepark | 2736276 | 2016-08-11 13:10:39 -0700 | [diff] [blame] | 360 | CPDF_Document* pDoc = m_pPageView->GetPDFDocument(); |
| 361 | CPDF_Dictionary* pDict = action.GetDict(); |
| 362 | if (pDict && pDict->GetObjNum() == 0) { |
| 363 | pDoc->AddIndirectObject(pDict); |
| 364 | } |
dsinclair | 38fd844 | 2016-09-15 10:15:32 -0700 | [diff] [blame^] | 365 | m_pAnnot->GetAnnotDict()->SetReferenceFor("A", pDoc, pDict->GetObjNum()); |
jaepark | 2736276 | 2016-08-11 13:10:39 -0700 | [diff] [blame] | 366 | } |
| 367 | } |
| 368 | |
| 369 | void CPDFSDK_BAAnnot::RemoveAction() { |
dsinclair | 38fd844 | 2016-09-15 10:15:32 -0700 | [diff] [blame^] | 370 | m_pAnnot->GetAnnotDict()->RemoveFor("A"); |
jaepark | 2736276 | 2016-08-11 13:10:39 -0700 | [diff] [blame] | 371 | } |
| 372 | |
| 373 | CPDF_AAction CPDFSDK_BAAnnot::GetAAction() const { |
dsinclair | 38fd844 | 2016-09-15 10:15:32 -0700 | [diff] [blame^] | 374 | return CPDF_AAction(m_pAnnot->GetAnnotDict()->GetDictFor("AA")); |
jaepark | 2736276 | 2016-08-11 13:10:39 -0700 | [diff] [blame] | 375 | } |
| 376 | |
| 377 | void CPDFSDK_BAAnnot::SetAAction(const CPDF_AAction& aa) { |
dsinclair | 38fd844 | 2016-09-15 10:15:32 -0700 | [diff] [blame^] | 378 | if (aa.GetDict() != m_pAnnot->GetAnnotDict()->GetDictFor("AA")) |
| 379 | m_pAnnot->GetAnnotDict()->SetFor("AA", aa.GetDict()); |
jaepark | 2736276 | 2016-08-11 13:10:39 -0700 | [diff] [blame] | 380 | } |
| 381 | |
| 382 | void CPDFSDK_BAAnnot::RemoveAAction() { |
dsinclair | 38fd844 | 2016-09-15 10:15:32 -0700 | [diff] [blame^] | 383 | m_pAnnot->GetAnnotDict()->RemoveFor("AA"); |
jaepark | 2736276 | 2016-08-11 13:10:39 -0700 | [diff] [blame] | 384 | } |
| 385 | |
| 386 | CPDF_Action CPDFSDK_BAAnnot::GetAAction(CPDF_AAction::AActionType eAAT) { |
| 387 | CPDF_AAction AAction = GetAAction(); |
| 388 | |
| 389 | if (AAction.ActionExist(eAAT)) |
| 390 | return AAction.GetAction(eAAT); |
| 391 | |
| 392 | if (eAAT == CPDF_AAction::ButtonUp) |
| 393 | return GetAction(); |
| 394 | |
| 395 | return CPDF_Action(); |
| 396 | } |
| 397 | |
| 398 | void CPDFSDK_BAAnnot::Annot_OnDraw(CFX_RenderDevice* pDevice, |
| 399 | CFX_Matrix* pUser2Device, |
| 400 | CPDF_RenderOptions* pOptions) { |
| 401 | m_pAnnot->GetAPForm(m_pPageView->GetPDFPage(), CPDF_Annot::Normal); |
| 402 | m_pAnnot->DrawAppearance(m_pPageView->GetPDFPage(), pDevice, pUser2Device, |
| 403 | CPDF_Annot::Normal, nullptr); |
| 404 | } |
jaepark | 35512aa | 2016-08-29 17:15:08 -0700 | [diff] [blame] | 405 | |
| 406 | void CPDFSDK_BAAnnot::SetOpenState(bool bOpenState) { |
| 407 | if (CPDF_Annot* pAnnot = m_pAnnot->GetPopupAnnot()) |
| 408 | pAnnot->SetOpenState(bOpenState); |
| 409 | } |