| OLD | NEW |
| 1 // Copyright 2014 PDFium Authors. All rights reserved. | 1 // Copyright 2014 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/fpdfapi/fpdf_page/include/cpdf_form.h" | 7 #include "core/fpdfapi/fpdf_page/include/cpdf_form.h" |
| 8 #include "core/fpdfapi/fpdf_page/include/cpdf_page.h" | 8 #include "core/fpdfapi/fpdf_page/include/cpdf_page.h" |
| 9 #include "core/fpdfapi/fpdf_parser/include/cpdf_array.h" | 9 #include "core/fpdfapi/fpdf_parser/include/cpdf_array.h" |
| 10 #include "core/fpdfapi/fpdf_parser/include/cpdf_document.h" | 10 #include "core/fpdfapi/fpdf_parser/include/cpdf_document.h" |
| (...skipping 10 matching lines...) Expand all Loading... |
| 21 return; | 21 return; |
| 22 | 22 |
| 23 CPDF_Array* pAnnots = pPage->m_pFormDict->GetArrayBy("Annots"); | 23 CPDF_Array* pAnnots = pPage->m_pFormDict->GetArrayBy("Annots"); |
| 24 if (!pAnnots) | 24 if (!pAnnots) |
| 25 return; | 25 return; |
| 26 | 26 |
| 27 CPDF_Dictionary* pRoot = m_pDocument->GetRoot(); | 27 CPDF_Dictionary* pRoot = m_pDocument->GetRoot(); |
| 28 CPDF_Dictionary* pAcroForm = pRoot->GetDictBy("AcroForm"); | 28 CPDF_Dictionary* pAcroForm = pRoot->GetDictBy("AcroForm"); |
| 29 FX_BOOL bRegenerateAP = | 29 FX_BOOL bRegenerateAP = |
| 30 pAcroForm && pAcroForm->GetBooleanBy("NeedAppearances"); | 30 pAcroForm && pAcroForm->GetBooleanBy("NeedAppearances"); |
| 31 for (FX_DWORD i = 0; i < pAnnots->GetCount(); ++i) { | 31 for (uint32_t i = 0; i < pAnnots->GetCount(); ++i) { |
| 32 CPDF_Dictionary* pDict = ToDictionary(pAnnots->GetElementValue(i)); | 32 CPDF_Dictionary* pDict = ToDictionary(pAnnots->GetElementValue(i)); |
| 33 if (!pDict) | 33 if (!pDict) |
| 34 continue; | 34 continue; |
| 35 | 35 |
| 36 FX_DWORD dwObjNum = pDict->GetObjNum(); | 36 uint32_t dwObjNum = pDict->GetObjNum(); |
| 37 if (dwObjNum == 0) { | 37 if (dwObjNum == 0) { |
| 38 dwObjNum = m_pDocument->AddIndirectObject(pDict); | 38 dwObjNum = m_pDocument->AddIndirectObject(pDict); |
| 39 CPDF_Reference* pAction = new CPDF_Reference(m_pDocument, dwObjNum); | 39 CPDF_Reference* pAction = new CPDF_Reference(m_pDocument, dwObjNum); |
| 40 pAnnots->InsertAt(i, pAction); | 40 pAnnots->InsertAt(i, pAction); |
| 41 pAnnots->RemoveAt(i + 1); | 41 pAnnots->RemoveAt(i + 1); |
| 42 pDict = pAnnots->GetDictAt(i); | 42 pDict = pAnnots->GetDictAt(i); |
| 43 } | 43 } |
| 44 m_AnnotList.push_back(new CPDF_Annot(pDict, this)); | 44 m_AnnotList.push_back(new CPDF_Annot(pDict, this)); |
| 45 if (bRegenerateAP && pDict->GetConstStringBy("Subtype") == "Widget" && | 45 if (bRegenerateAP && pDict->GetConstStringBy("Subtype") == "Widget" && |
| 46 CPDF_InterForm::UpdatingAPEnabled()) { | 46 CPDF_InterForm::UpdatingAPEnabled()) { |
| (...skipping 13 matching lines...) Expand all Loading... |
| 60 FX_BOOL bPrinting, | 60 FX_BOOL bPrinting, |
| 61 CFX_Matrix* pMatrix, | 61 CFX_Matrix* pMatrix, |
| 62 FX_BOOL bWidgetPass, | 62 FX_BOOL bWidgetPass, |
| 63 CPDF_RenderOptions* pOptions, | 63 CPDF_RenderOptions* pOptions, |
| 64 FX_RECT* clip_rect) { | 64 FX_RECT* clip_rect) { |
| 65 for (CPDF_Annot* pAnnot : m_AnnotList) { | 65 for (CPDF_Annot* pAnnot : m_AnnotList) { |
| 66 bool bWidget = pAnnot->GetSubType() == "Widget"; | 66 bool bWidget = pAnnot->GetSubType() == "Widget"; |
| 67 if ((bWidgetPass && !bWidget) || (!bWidgetPass && bWidget)) | 67 if ((bWidgetPass && !bWidget) || (!bWidgetPass && bWidget)) |
| 68 continue; | 68 continue; |
| 69 | 69 |
| 70 FX_DWORD annot_flags = pAnnot->GetFlags(); | 70 uint32_t annot_flags = pAnnot->GetFlags(); |
| 71 if (annot_flags & ANNOTFLAG_HIDDEN) | 71 if (annot_flags & ANNOTFLAG_HIDDEN) |
| 72 continue; | 72 continue; |
| 73 | 73 |
| 74 if (bPrinting && (annot_flags & ANNOTFLAG_PRINT) == 0) | 74 if (bPrinting && (annot_flags & ANNOTFLAG_PRINT) == 0) |
| 75 continue; | 75 continue; |
| 76 | 76 |
| 77 if (!bPrinting && (annot_flags & ANNOTFLAG_NOVIEW)) | 77 if (!bPrinting && (annot_flags & ANNOTFLAG_NOVIEW)) |
| 78 continue; | 78 continue; |
| 79 | 79 |
| 80 if (pOptions) { | 80 if (pOptions) { |
| (...skipping 22 matching lines...) Expand all Loading... |
| 103 pAnnot->DrawBorder(pDevice, &matrix, pOptions); | 103 pAnnot->DrawBorder(pDevice, &matrix, pOptions); |
| 104 } | 104 } |
| 105 } | 105 } |
| 106 } | 106 } |
| 107 | 107 |
| 108 void CPDF_AnnotList::DisplayAnnots(CPDF_Page* pPage, | 108 void CPDF_AnnotList::DisplayAnnots(CPDF_Page* pPage, |
| 109 CFX_RenderDevice* pDevice, | 109 CFX_RenderDevice* pDevice, |
| 110 CPDF_RenderContext* pContext, | 110 CPDF_RenderContext* pContext, |
| 111 FX_BOOL bPrinting, | 111 FX_BOOL bPrinting, |
| 112 CFX_Matrix* pUser2Device, | 112 CFX_Matrix* pUser2Device, |
| 113 FX_DWORD dwAnnotFlags, | 113 uint32_t dwAnnotFlags, |
| 114 CPDF_RenderOptions* pOptions, | 114 CPDF_RenderOptions* pOptions, |
| 115 FX_RECT* pClipRect) { | 115 FX_RECT* pClipRect) { |
| 116 if (dwAnnotFlags & 0x01) { | 116 if (dwAnnotFlags & 0x01) { |
| 117 DisplayPass(pPage, pDevice, pContext, bPrinting, pUser2Device, FALSE, | 117 DisplayPass(pPage, pDevice, pContext, bPrinting, pUser2Device, FALSE, |
| 118 pOptions, pClipRect); | 118 pOptions, pClipRect); |
| 119 } | 119 } |
| 120 if (dwAnnotFlags & 0x02) { | 120 if (dwAnnotFlags & 0x02) { |
| 121 DisplayPass(pPage, pDevice, pContext, bPrinting, pUser2Device, TRUE, | 121 DisplayPass(pPage, pDevice, pContext, bPrinting, pUser2Device, TRUE, |
| 122 pOptions, pClipRect); | 122 pOptions, pClipRect); |
| 123 } | 123 } |
| (...skipping 17 matching lines...) Expand all Loading... |
| 141 } | 141 } |
| 142 | 142 |
| 143 void CPDF_Annot::GetRect(CFX_FloatRect& rect) const { | 143 void CPDF_Annot::GetRect(CFX_FloatRect& rect) const { |
| 144 if (!m_pAnnotDict) { | 144 if (!m_pAnnotDict) { |
| 145 return; | 145 return; |
| 146 } | 146 } |
| 147 rect = m_pAnnotDict->GetRectBy("Rect"); | 147 rect = m_pAnnotDict->GetRectBy("Rect"); |
| 148 rect.Normalize(); | 148 rect.Normalize(); |
| 149 } | 149 } |
| 150 | 150 |
| 151 FX_DWORD CPDF_Annot::GetFlags() const { | 151 uint32_t CPDF_Annot::GetFlags() const { |
| 152 return m_pAnnotDict->GetIntegerBy("F"); | 152 return m_pAnnotDict->GetIntegerBy("F"); |
| 153 } | 153 } |
| 154 | 154 |
| 155 CPDF_Stream* FPDFDOC_GetAnnotAP(CPDF_Dictionary* pAnnotDict, | 155 CPDF_Stream* FPDFDOC_GetAnnotAP(CPDF_Dictionary* pAnnotDict, |
| 156 CPDF_Annot::AppearanceMode mode) { | 156 CPDF_Annot::AppearanceMode mode) { |
| 157 CPDF_Dictionary* pAP = pAnnotDict->GetDictBy("AP"); | 157 CPDF_Dictionary* pAP = pAnnotDict->GetDictBy("AP"); |
| 158 if (!pAP) { | 158 if (!pAP) { |
| 159 return NULL; | 159 return NULL; |
| 160 } | 160 } |
| 161 const FX_CHAR* ap_entry = "N"; | 161 const FX_CHAR* ap_entry = "N"; |
| (...skipping 90 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
| 252 } | 252 } |
| 253 pContext->AppendLayer(pForm, &matrix); | 253 pContext->AppendLayer(pForm, &matrix); |
| 254 return TRUE; | 254 return TRUE; |
| 255 } | 255 } |
| 256 void CPDF_Annot::DrawBorder(CFX_RenderDevice* pDevice, | 256 void CPDF_Annot::DrawBorder(CFX_RenderDevice* pDevice, |
| 257 const CFX_Matrix* pUser2Device, | 257 const CFX_Matrix* pUser2Device, |
| 258 const CPDF_RenderOptions* pOptions) { | 258 const CPDF_RenderOptions* pOptions) { |
| 259 if (GetSubType() == "Popup") { | 259 if (GetSubType() == "Popup") { |
| 260 return; | 260 return; |
| 261 } | 261 } |
| 262 FX_DWORD annot_flags = GetFlags(); | 262 uint32_t annot_flags = GetFlags(); |
| 263 if (annot_flags & ANNOTFLAG_HIDDEN) { | 263 if (annot_flags & ANNOTFLAG_HIDDEN) { |
| 264 return; | 264 return; |
| 265 } | 265 } |
| 266 bool bPrinting = pDevice->GetDeviceClass() == FXDC_PRINTER || | 266 bool bPrinting = pDevice->GetDeviceClass() == FXDC_PRINTER || |
| 267 (pOptions && (pOptions->m_Flags & RENDER_PRINTPREVIEW)); | 267 (pOptions && (pOptions->m_Flags & RENDER_PRINTPREVIEW)); |
| 268 if (bPrinting && (annot_flags & ANNOTFLAG_PRINT) == 0) { | 268 if (bPrinting && (annot_flags & ANNOTFLAG_PRINT) == 0) { |
| 269 return; | 269 return; |
| 270 } | 270 } |
| 271 if (!bPrinting && (annot_flags & ANNOTFLAG_NOVIEW)) { | 271 if (!bPrinting && (annot_flags & ANNOTFLAG_NOVIEW)) { |
| 272 return; | 272 return; |
| (...skipping 31 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
| 304 } else { | 304 } else { |
| 305 CFX_ByteString style = pBS->GetStringBy("S"); | 305 CFX_ByteString style = pBS->GetStringBy("S"); |
| 306 pDashArray = pBS->GetArrayBy("D"); | 306 pDashArray = pBS->GetArrayBy("D"); |
| 307 style_char = style[1]; | 307 style_char = style[1]; |
| 308 width = pBS->GetNumberBy("W"); | 308 width = pBS->GetNumberBy("W"); |
| 309 } | 309 } |
| 310 if (width <= 0) { | 310 if (width <= 0) { |
| 311 return; | 311 return; |
| 312 } | 312 } |
| 313 CPDF_Array* pColor = m_pAnnotDict->GetArrayBy("C"); | 313 CPDF_Array* pColor = m_pAnnotDict->GetArrayBy("C"); |
| 314 FX_DWORD argb = 0xff000000; | 314 uint32_t argb = 0xff000000; |
| 315 if (pColor) { | 315 if (pColor) { |
| 316 int R = (int32_t)(pColor->GetNumberAt(0) * 255); | 316 int R = (int32_t)(pColor->GetNumberAt(0) * 255); |
| 317 int G = (int32_t)(pColor->GetNumberAt(1) * 255); | 317 int G = (int32_t)(pColor->GetNumberAt(1) * 255); |
| 318 int B = (int32_t)(pColor->GetNumberAt(2) * 255); | 318 int B = (int32_t)(pColor->GetNumberAt(2) * 255); |
| 319 argb = ArgbEncode(0xff, R, G, B); | 319 argb = ArgbEncode(0xff, R, G, B); |
| 320 } | 320 } |
| 321 CFX_GraphStateData graph_state; | 321 CFX_GraphStateData graph_state; |
| 322 graph_state.m_LineWidth = width; | 322 graph_state.m_LineWidth = width; |
| 323 if (style_char == 'D') { | 323 if (style_char == 'D') { |
| 324 if (pDashArray) { | 324 if (pDashArray) { |
| 325 FX_DWORD dash_count = pDashArray->GetCount(); | 325 uint32_t dash_count = pDashArray->GetCount(); |
| 326 if (dash_count % 2) { | 326 if (dash_count % 2) { |
| 327 dash_count++; | 327 dash_count++; |
| 328 } | 328 } |
| 329 graph_state.m_DashArray = FX_Alloc(FX_FLOAT, dash_count); | 329 graph_state.m_DashArray = FX_Alloc(FX_FLOAT, dash_count); |
| 330 graph_state.m_DashCount = dash_count; | 330 graph_state.m_DashCount = dash_count; |
| 331 FX_DWORD i; | 331 uint32_t i; |
| 332 for (i = 0; i < pDashArray->GetCount(); ++i) { | 332 for (i = 0; i < pDashArray->GetCount(); ++i) { |
| 333 graph_state.m_DashArray[i] = pDashArray->GetNumberAt(i); | 333 graph_state.m_DashArray[i] = pDashArray->GetNumberAt(i); |
| 334 } | 334 } |
| 335 if (i < dash_count) { | 335 if (i < dash_count) { |
| 336 graph_state.m_DashArray[i] = graph_state.m_DashArray[i - 1]; | 336 graph_state.m_DashArray[i] = graph_state.m_DashArray[i - 1]; |
| 337 } | 337 } |
| 338 } else { | 338 } else { |
| 339 graph_state.m_DashArray = FX_Alloc(FX_FLOAT, 2); | 339 graph_state.m_DashArray = FX_Alloc(FX_FLOAT, 2); |
| 340 graph_state.m_DashCount = 2; | 340 graph_state.m_DashCount = 2; |
| 341 graph_state.m_DashArray[0] = graph_state.m_DashArray[1] = 3 * 1.0f; | 341 graph_state.m_DashArray[0] = graph_state.m_DashArray[1] = 3 * 1.0f; |
| 342 } | 342 } |
| 343 } | 343 } |
| 344 CFX_FloatRect rect; | 344 CFX_FloatRect rect; |
| 345 GetRect(rect); | 345 GetRect(rect); |
| 346 CFX_PathData path; | 346 CFX_PathData path; |
| 347 width /= 2; | 347 width /= 2; |
| 348 path.AppendRect(rect.left + width, rect.bottom + width, rect.right - width, | 348 path.AppendRect(rect.left + width, rect.bottom + width, rect.right - width, |
| 349 rect.top - width); | 349 rect.top - width); |
| 350 int fill_type = 0; | 350 int fill_type = 0; |
| 351 if (pOptions && (pOptions->m_Flags & RENDER_NOPATHSMOOTH)) { | 351 if (pOptions && (pOptions->m_Flags & RENDER_NOPATHSMOOTH)) { |
| 352 fill_type |= FXFILL_NOPATHSMOOTH; | 352 fill_type |= FXFILL_NOPATHSMOOTH; |
| 353 } | 353 } |
| 354 pDevice->DrawPath(&path, pUser2Device, &graph_state, argb, argb, fill_type); | 354 pDevice->DrawPath(&path, pUser2Device, &graph_state, argb, argb, fill_type); |
| 355 } | 355 } |
| OLD | NEW |