| OLD | NEW |
| 1 // Copyright 2016 PDFium Authors. All rights reserved. | 1 // Copyright 2016 PDFium Authors. All rights reserved. |
| 2 // Use of this source code is governed by a BSD-style license that can be | 2 // Use of this source code is governed by a BSD-style license that can be |
| 3 // found in the LICENSE file. | 3 // found in the LICENSE file. |
| 4 | 4 |
| 5 // Original code copyright 2014 Foxit Software Inc. http://www.foxitsoftware.com | 5 // Original code copyright 2014 Foxit Software Inc. http://www.foxitsoftware.com |
| 6 | 6 |
| 7 #include "core/fpdfdoc/include/cpdf_annot.h" | 7 #include "core/fpdfdoc/include/cpdf_annot.h" |
| 8 | 8 |
| 9 #include "core/fpdfapi/fpdf_page/include/cpdf_form.h" | 9 #include "core/fpdfapi/fpdf_page/include/cpdf_form.h" |
| 10 #include "core/fpdfapi/fpdf_page/include/cpdf_page.h" | 10 #include "core/fpdfapi/fpdf_page/include/cpdf_page.h" |
| (...skipping 21 matching lines...) Expand all Loading... |
| 32 } // namespace | 32 } // namespace |
| 33 | 33 |
| 34 CPDF_Annot::CPDF_Annot(CPDF_Dictionary* pDict, | 34 CPDF_Annot::CPDF_Annot(CPDF_Dictionary* pDict, |
| 35 CPDF_Document* pDocument, | 35 CPDF_Document* pDocument, |
| 36 bool bToOwnDict) | 36 bool bToOwnDict) |
| 37 : m_bOwnedAnnotDict(bToOwnDict), | 37 : m_bOwnedAnnotDict(bToOwnDict), |
| 38 m_pAnnotDict(pDict), | 38 m_pAnnotDict(pDict), |
| 39 m_pDocument(pDocument), | 39 m_pDocument(pDocument), |
| 40 m_bOpenState(false), | 40 m_bOpenState(false), |
| 41 m_pPopupAnnot(nullptr) { | 41 m_pPopupAnnot(nullptr) { |
| 42 m_nSubtype = StringToAnnotSubtype(m_pAnnotDict->GetStringBy("Subtype")); | 42 m_nSubtype = StringToAnnotSubtype(m_pAnnotDict->GetStringFor("Subtype")); |
| 43 GenerateAPIfNeeded(); | 43 GenerateAPIfNeeded(); |
| 44 } | 44 } |
| 45 | 45 |
| 46 CPDF_Annot::~CPDF_Annot() { | 46 CPDF_Annot::~CPDF_Annot() { |
| 47 if (m_bOwnedAnnotDict) | 47 if (m_bOwnedAnnotDict) |
| 48 m_pAnnotDict->Release(); | 48 m_pAnnotDict->Release(); |
| 49 ClearCachedAP(); | 49 ClearCachedAP(); |
| 50 } | 50 } |
| 51 | 51 |
| 52 void CPDF_Annot::GenerateAPIfNeeded() { | 52 void CPDF_Annot::GenerateAPIfNeeded() { |
| (...skipping 35 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
| 88 } | 88 } |
| 89 | 89 |
| 90 CPDF_Annot::Subtype CPDF_Annot::GetSubtype() const { | 90 CPDF_Annot::Subtype CPDF_Annot::GetSubtype() const { |
| 91 return m_nSubtype; | 91 return m_nSubtype; |
| 92 } | 92 } |
| 93 | 93 |
| 94 CFX_FloatRect CPDF_Annot::GetRect() const { | 94 CFX_FloatRect CPDF_Annot::GetRect() const { |
| 95 if (!m_pAnnotDict) | 95 if (!m_pAnnotDict) |
| 96 return CFX_FloatRect(); | 96 return CFX_FloatRect(); |
| 97 | 97 |
| 98 CFX_FloatRect rect = m_pAnnotDict->GetRectBy("Rect"); | 98 CFX_FloatRect rect = m_pAnnotDict->GetRectFor("Rect"); |
| 99 rect.Normalize(); | 99 rect.Normalize(); |
| 100 return rect; | 100 return rect; |
| 101 } | 101 } |
| 102 | 102 |
| 103 uint32_t CPDF_Annot::GetFlags() const { | 103 uint32_t CPDF_Annot::GetFlags() const { |
| 104 return m_pAnnotDict->GetIntegerBy("F"); | 104 return m_pAnnotDict->GetIntegerFor("F"); |
| 105 } | 105 } |
| 106 | 106 |
| 107 CPDF_Stream* FPDFDOC_GetAnnotAP(CPDF_Dictionary* pAnnotDict, | 107 CPDF_Stream* FPDFDOC_GetAnnotAP(CPDF_Dictionary* pAnnotDict, |
| 108 CPDF_Annot::AppearanceMode mode) { | 108 CPDF_Annot::AppearanceMode mode) { |
| 109 CPDF_Dictionary* pAP = pAnnotDict->GetDictBy("AP"); | 109 CPDF_Dictionary* pAP = pAnnotDict->GetDictFor("AP"); |
| 110 if (!pAP) { | 110 if (!pAP) { |
| 111 return nullptr; | 111 return nullptr; |
| 112 } | 112 } |
| 113 const FX_CHAR* ap_entry = "N"; | 113 const FX_CHAR* ap_entry = "N"; |
| 114 if (mode == CPDF_Annot::Down) | 114 if (mode == CPDF_Annot::Down) |
| 115 ap_entry = "D"; | 115 ap_entry = "D"; |
| 116 else if (mode == CPDF_Annot::Rollover) | 116 else if (mode == CPDF_Annot::Rollover) |
| 117 ap_entry = "R"; | 117 ap_entry = "R"; |
| 118 if (!pAP->KeyExist(ap_entry)) | 118 if (!pAP->KeyExist(ap_entry)) |
| 119 ap_entry = "N"; | 119 ap_entry = "N"; |
| 120 | 120 |
| 121 CPDF_Object* psub = pAP->GetDirectObjectBy(ap_entry); | 121 CPDF_Object* psub = pAP->GetDirectObjectFor(ap_entry); |
| 122 if (!psub) | 122 if (!psub) |
| 123 return nullptr; | 123 return nullptr; |
| 124 if (CPDF_Stream* pStream = psub->AsStream()) | 124 if (CPDF_Stream* pStream = psub->AsStream()) |
| 125 return pStream; | 125 return pStream; |
| 126 | 126 |
| 127 if (CPDF_Dictionary* pDict = psub->AsDictionary()) { | 127 if (CPDF_Dictionary* pDict = psub->AsDictionary()) { |
| 128 CFX_ByteString as = pAnnotDict->GetStringBy("AS"); | 128 CFX_ByteString as = pAnnotDict->GetStringFor("AS"); |
| 129 if (as.IsEmpty()) { | 129 if (as.IsEmpty()) { |
| 130 CFX_ByteString value = pAnnotDict->GetStringBy("V"); | 130 CFX_ByteString value = pAnnotDict->GetStringFor("V"); |
| 131 if (value.IsEmpty()) { | 131 if (value.IsEmpty()) { |
| 132 CPDF_Dictionary* pParentDict = pAnnotDict->GetDictBy("Parent"); | 132 CPDF_Dictionary* pParentDict = pAnnotDict->GetDictFor("Parent"); |
| 133 value = pParentDict ? pParentDict->GetStringBy("V") : CFX_ByteString(); | 133 value = pParentDict ? pParentDict->GetStringFor("V") : CFX_ByteString(); |
| 134 } | 134 } |
| 135 if (value.IsEmpty() || !pDict->KeyExist(value)) | 135 if (value.IsEmpty() || !pDict->KeyExist(value)) |
| 136 as = "Off"; | 136 as = "Off"; |
| 137 else | 137 else |
| 138 as = value; | 138 as = value; |
| 139 } | 139 } |
| 140 return pDict->GetStreamBy(as); | 140 return pDict->GetStreamFor(as); |
| 141 } | 141 } |
| 142 return nullptr; | 142 return nullptr; |
| 143 } | 143 } |
| 144 | 144 |
| 145 CPDF_Form* CPDF_Annot::GetAPForm(const CPDF_Page* pPage, AppearanceMode mode) { | 145 CPDF_Form* CPDF_Annot::GetAPForm(const CPDF_Page* pPage, AppearanceMode mode) { |
| 146 CPDF_Stream* pStream = FPDFDOC_GetAnnotAP(m_pAnnotDict, mode); | 146 CPDF_Stream* pStream = FPDFDOC_GetAnnotAP(m_pAnnotDict, mode); |
| 147 if (!pStream) | 147 if (!pStream) |
| 148 return nullptr; | 148 return nullptr; |
| 149 | 149 |
| 150 auto it = m_APMap.find(pStream); | 150 auto it = m_APMap.find(pStream); |
| 151 if (it != m_APMap.end()) | 151 if (it != m_APMap.end()) |
| 152 return it->second.get(); | 152 return it->second.get(); |
| 153 | 153 |
| 154 CPDF_Form* pNewForm = | 154 CPDF_Form* pNewForm = |
| 155 new CPDF_Form(m_pDocument, pPage->m_pResources, pStream); | 155 new CPDF_Form(m_pDocument, pPage->m_pResources, pStream); |
| 156 pNewForm->ParseContent(nullptr, nullptr, nullptr); | 156 pNewForm->ParseContent(nullptr, nullptr, nullptr); |
| 157 m_APMap[pStream] = WrapUnique(pNewForm); | 157 m_APMap[pStream] = WrapUnique(pNewForm); |
| 158 return pNewForm; | 158 return pNewForm; |
| 159 } | 159 } |
| 160 | 160 |
| 161 static CPDF_Form* FPDFDOC_Annot_GetMatrix(const CPDF_Page* pPage, | 161 static CPDF_Form* FPDFDOC_Annot_GetMatrix(const CPDF_Page* pPage, |
| 162 CPDF_Annot* pAnnot, | 162 CPDF_Annot* pAnnot, |
| 163 CPDF_Annot::AppearanceMode mode, | 163 CPDF_Annot::AppearanceMode mode, |
| 164 const CFX_Matrix* pUser2Device, | 164 const CFX_Matrix* pUser2Device, |
| 165 CFX_Matrix& matrix) { | 165 CFX_Matrix& matrix) { |
| 166 CPDF_Form* pForm = pAnnot->GetAPForm(pPage, mode); | 166 CPDF_Form* pForm = pAnnot->GetAPForm(pPage, mode); |
| 167 if (!pForm) { | 167 if (!pForm) { |
| 168 return nullptr; | 168 return nullptr; |
| 169 } | 169 } |
| 170 CFX_FloatRect form_bbox = pForm->m_pFormDict->GetRectBy("BBox"); | 170 CFX_FloatRect form_bbox = pForm->m_pFormDict->GetRectFor("BBox"); |
| 171 CFX_Matrix form_matrix = pForm->m_pFormDict->GetMatrixBy("Matrix"); | 171 CFX_Matrix form_matrix = pForm->m_pFormDict->GetMatrixFor("Matrix"); |
| 172 form_matrix.TransformRect(form_bbox); | 172 form_matrix.TransformRect(form_bbox); |
| 173 matrix.MatchRect(pAnnot->GetRect(), form_bbox); | 173 matrix.MatchRect(pAnnot->GetRect(), form_bbox); |
| 174 matrix.Concat(*pUser2Device); | 174 matrix.Concat(*pUser2Device); |
| 175 return pForm; | 175 return pForm; |
| 176 } | 176 } |
| 177 | 177 |
| 178 // Static. | 178 // Static. |
| 179 bool CPDF_Annot::IsAnnotationHidden(CPDF_Dictionary* pAnnotDict) { | 179 bool CPDF_Annot::IsAnnotationHidden(CPDF_Dictionary* pAnnotDict) { |
| 180 return !!(pAnnotDict->GetIntegerBy("F") & ANNOTFLAG_HIDDEN); | 180 return !!(pAnnotDict->GetIntegerFor("F") & ANNOTFLAG_HIDDEN); |
| 181 } | 181 } |
| 182 | 182 |
| 183 // Static. | 183 // Static. |
| 184 CPDF_Annot::Subtype CPDF_Annot::StringToAnnotSubtype( | 184 CPDF_Annot::Subtype CPDF_Annot::StringToAnnotSubtype( |
| 185 const CFX_ByteString& sSubtype) { | 185 const CFX_ByteString& sSubtype) { |
| 186 if (sSubtype == "Text") | 186 if (sSubtype == "Text") |
| 187 return CPDF_Annot::Subtype::TEXT; | 187 return CPDF_Annot::Subtype::TEXT; |
| 188 if (sSubtype == "Link") | 188 if (sSubtype == "Link") |
| 189 return CPDF_Annot::Subtype::LINK; | 189 return CPDF_Annot::Subtype::LINK; |
| 190 if (sSubtype == "FreeText") | 190 if (sSubtype == "FreeText") |
| (...skipping 168 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
| 359 return; | 359 return; |
| 360 } | 360 } |
| 361 bool bPrinting = pDevice->GetDeviceClass() == FXDC_PRINTER || | 361 bool bPrinting = pDevice->GetDeviceClass() == FXDC_PRINTER || |
| 362 (pOptions && (pOptions->m_Flags & RENDER_PRINTPREVIEW)); | 362 (pOptions && (pOptions->m_Flags & RENDER_PRINTPREVIEW)); |
| 363 if (bPrinting && (annot_flags & ANNOTFLAG_PRINT) == 0) { | 363 if (bPrinting && (annot_flags & ANNOTFLAG_PRINT) == 0) { |
| 364 return; | 364 return; |
| 365 } | 365 } |
| 366 if (!bPrinting && (annot_flags & ANNOTFLAG_NOVIEW)) { | 366 if (!bPrinting && (annot_flags & ANNOTFLAG_NOVIEW)) { |
| 367 return; | 367 return; |
| 368 } | 368 } |
| 369 CPDF_Dictionary* pBS = m_pAnnotDict->GetDictBy("BS"); | 369 CPDF_Dictionary* pBS = m_pAnnotDict->GetDictFor("BS"); |
| 370 char style_char; | 370 char style_char; |
| 371 FX_FLOAT width; | 371 FX_FLOAT width; |
| 372 CPDF_Array* pDashArray = nullptr; | 372 CPDF_Array* pDashArray = nullptr; |
| 373 if (!pBS) { | 373 if (!pBS) { |
| 374 CPDF_Array* pBorderArray = m_pAnnotDict->GetArrayBy("Border"); | 374 CPDF_Array* pBorderArray = m_pAnnotDict->GetArrayFor("Border"); |
| 375 style_char = 'S'; | 375 style_char = 'S'; |
| 376 if (pBorderArray) { | 376 if (pBorderArray) { |
| 377 width = pBorderArray->GetNumberAt(2); | 377 width = pBorderArray->GetNumberAt(2); |
| 378 if (pBorderArray->GetCount() == 4) { | 378 if (pBorderArray->GetCount() == 4) { |
| 379 pDashArray = pBorderArray->GetArrayAt(3); | 379 pDashArray = pBorderArray->GetArrayAt(3); |
| 380 if (!pDashArray) { | 380 if (!pDashArray) { |
| 381 return; | 381 return; |
| 382 } | 382 } |
| 383 size_t nLen = pDashArray->GetCount(); | 383 size_t nLen = pDashArray->GetCount(); |
| 384 size_t i = 0; | 384 size_t i = 0; |
| 385 for (; i < nLen; ++i) { | 385 for (; i < nLen; ++i) { |
| 386 CPDF_Object* pObj = pDashArray->GetDirectObjectAt(i); | 386 CPDF_Object* pObj = pDashArray->GetDirectObjectAt(i); |
| 387 if (pObj && pObj->GetInteger()) { | 387 if (pObj && pObj->GetInteger()) { |
| 388 break; | 388 break; |
| 389 } | 389 } |
| 390 } | 390 } |
| 391 if (i == nLen) { | 391 if (i == nLen) { |
| 392 return; | 392 return; |
| 393 } | 393 } |
| 394 style_char = 'D'; | 394 style_char = 'D'; |
| 395 } | 395 } |
| 396 } else { | 396 } else { |
| 397 width = 1; | 397 width = 1; |
| 398 } | 398 } |
| 399 } else { | 399 } else { |
| 400 CFX_ByteString style = pBS->GetStringBy("S"); | 400 CFX_ByteString style = pBS->GetStringFor("S"); |
| 401 pDashArray = pBS->GetArrayBy("D"); | 401 pDashArray = pBS->GetArrayFor("D"); |
| 402 style_char = style[1]; | 402 style_char = style[1]; |
| 403 width = pBS->GetNumberBy("W"); | 403 width = pBS->GetNumberFor("W"); |
| 404 } | 404 } |
| 405 if (width <= 0) { | 405 if (width <= 0) { |
| 406 return; | 406 return; |
| 407 } | 407 } |
| 408 CPDF_Array* pColor = m_pAnnotDict->GetArrayBy("C"); | 408 CPDF_Array* pColor = m_pAnnotDict->GetArrayFor("C"); |
| 409 uint32_t argb = 0xff000000; | 409 uint32_t argb = 0xff000000; |
| 410 if (pColor) { | 410 if (pColor) { |
| 411 int R = (int32_t)(pColor->GetNumberAt(0) * 255); | 411 int R = (int32_t)(pColor->GetNumberAt(0) * 255); |
| 412 int G = (int32_t)(pColor->GetNumberAt(1) * 255); | 412 int G = (int32_t)(pColor->GetNumberAt(1) * 255); |
| 413 int B = (int32_t)(pColor->GetNumberAt(2) * 255); | 413 int B = (int32_t)(pColor->GetNumberAt(2) * 255); |
| 414 argb = ArgbEncode(0xff, R, G, B); | 414 argb = ArgbEncode(0xff, R, G, B); |
| 415 } | 415 } |
| 416 CFX_GraphStateData graph_state; | 416 CFX_GraphStateData graph_state; |
| 417 graph_state.m_LineWidth = width; | 417 graph_state.m_LineWidth = width; |
| 418 if (style_char == 'D') { | 418 if (style_char == 'D') { |
| (...skipping 21 matching lines...) Expand all Loading... |
| 440 CFX_PathData path; | 440 CFX_PathData path; |
| 441 width /= 2; | 441 width /= 2; |
| 442 path.AppendRect(rect.left + width, rect.bottom + width, rect.right - width, | 442 path.AppendRect(rect.left + width, rect.bottom + width, rect.right - width, |
| 443 rect.top - width); | 443 rect.top - width); |
| 444 int fill_type = 0; | 444 int fill_type = 0; |
| 445 if (pOptions && (pOptions->m_Flags & RENDER_NOPATHSMOOTH)) { | 445 if (pOptions && (pOptions->m_Flags & RENDER_NOPATHSMOOTH)) { |
| 446 fill_type |= FXFILL_NOPATHSMOOTH; | 446 fill_type |= FXFILL_NOPATHSMOOTH; |
| 447 } | 447 } |
| 448 pDevice->DrawPath(&path, pUser2Device, &graph_state, argb, argb, fill_type); | 448 pDevice->DrawPath(&path, pUser2Device, &graph_state, argb, argb, fill_type); |
| 449 } | 449 } |
| OLD | NEW |