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