John Abd-El-Malek | 3f3b45c | 2014-05-23 17:28:10 -0700 | [diff] [blame] | 1 | // Copyright 2014 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. |
Lei Zhang | a6d9f0e | 2015-06-13 00:48:38 -0700 | [diff] [blame] | 4 | |
John Abd-El-Malek | 3f3b45c | 2014-05-23 17:28:10 -0700 | [diff] [blame] | 5 | // Original code copyright 2014 Foxit Software Inc. http://www.foxitsoftware.com |
| 6 | |
Lei Zhang | b4e7f30 | 2015-11-06 15:52:32 -0800 | [diff] [blame] | 7 | #include "public/fpdfview.h" |
| 8 | |
Tom Sepez | 2d11d72 | 2018-05-31 23:38:32 +0000 | [diff] [blame] | 9 | #include <memory> |
thestig | d4c34f2 | 2016-09-28 17:04:51 -0700 | [diff] [blame] | 10 | #include <utility> |
rbpotter | cec0180 | 2017-04-17 09:10:21 -0700 | [diff] [blame] | 11 | #include <vector> |
Lei Zhang | aa8bf7e | 2015-12-24 19:13:32 -0800 | [diff] [blame] | 12 | |
dsinclair | 39c62fd | 2016-09-29 12:49:17 -0700 | [diff] [blame] | 13 | #include "core/fpdfapi/cpdf_modulemgr.h" |
| 14 | #include "core/fpdfapi/cpdf_pagerendercontext.h" |
dsinclair | 41872fa | 2016-10-04 11:29:35 -0700 | [diff] [blame] | 15 | #include "core/fpdfapi/page/cpdf_page.h" |
dsinclair | 488b7ad | 2016-10-04 11:55:50 -0700 | [diff] [blame] | 16 | #include "core/fpdfapi/parser/cpdf_array.h" |
Jane Liu | 4fd9a47 | 2017-06-01 18:56:09 -0400 | [diff] [blame] | 17 | #include "core/fpdfapi/parser/cpdf_dictionary.h" |
dsinclair | 488b7ad | 2016-10-04 11:55:50 -0700 | [diff] [blame] | 18 | #include "core/fpdfapi/parser/cpdf_document.h" |
Dan Sinclair | 7aba472 | 2018-03-28 17:04:16 +0000 | [diff] [blame] | 19 | #include "core/fpdfapi/parser/cpdf_name.h" |
| 20 | #include "core/fpdfapi/parser/cpdf_parser.h" |
dsinclair | 488b7ad | 2016-10-04 11:55:50 -0700 | [diff] [blame] | 21 | #include "core/fpdfapi/parser/fpdf_parser_decode.h" |
dsinclair | 69d9c68 | 2016-10-04 12:18:35 -0700 | [diff] [blame] | 22 | #include "core/fpdfapi/render/cpdf_progressiverenderer.h" |
Dan Sinclair | 7aba472 | 2018-03-28 17:04:16 +0000 | [diff] [blame] | 23 | #include "core/fpdfapi/render/cpdf_rendercontext.h" |
dsinclair | 69d9c68 | 2016-10-04 12:18:35 -0700 | [diff] [blame] | 24 | #include "core/fpdfapi/render/cpdf_renderoptions.h" |
dsinclair | 1727aee | 2016-09-29 13:12:56 -0700 | [diff] [blame] | 25 | #include "core/fpdfdoc/cpdf_annotlist.h" |
| 26 | #include "core/fpdfdoc/cpdf_nametree.h" |
| 27 | #include "core/fpdfdoc/cpdf_occontext.h" |
| 28 | #include "core/fpdfdoc/cpdf_viewerpreferences.h" |
Dan Sinclair | bcd1e70 | 2017-08-31 13:19:18 -0400 | [diff] [blame] | 29 | #include "core/fxcrt/fx_stream.h" |
Dan Sinclair | 7aba472 | 2018-03-28 17:04:16 +0000 | [diff] [blame] | 30 | #include "core/fxcrt/fx_system.h" |
Tom Sepez | e7f4d33 | 2018-05-03 20:27:05 +0000 | [diff] [blame] | 31 | #include "core/fxcrt/unowned_ptr.h" |
Dan Sinclair | a5085d4 | 2017-05-11 16:26:50 -0400 | [diff] [blame] | 32 | #include "core/fxge/cfx_defaultrenderdevice.h" |
dsinclair | 74a34fc | 2016-09-29 16:41:42 -0700 | [diff] [blame] | 33 | #include "core/fxge/cfx_gemodule.h" |
Dan Sinclair | 7aba472 | 2018-03-28 17:04:16 +0000 | [diff] [blame] | 34 | #include "core/fxge/cfx_renderdevice.h" |
| 35 | #include "fpdfsdk/cpdfsdk_customaccess.h" |
dsinclair | b402b17 | 2016-10-11 09:26:32 -0700 | [diff] [blame] | 36 | #include "fpdfsdk/cpdfsdk_formfillenvironment.h" |
Dan Sinclair | 00d47a6 | 2018-03-28 18:39:04 +0000 | [diff] [blame] | 37 | #include "fpdfsdk/cpdfsdk_helpers.h" |
Dan Sinclair | 7aba472 | 2018-03-28 17:04:16 +0000 | [diff] [blame] | 38 | #include "fpdfsdk/cpdfsdk_memoryaccess.h" |
dsinclair | 114e46a | 2016-09-29 17:18:21 -0700 | [diff] [blame] | 39 | #include "fpdfsdk/cpdfsdk_pageview.h" |
Dan Sinclair | 7d12532 | 2018-03-28 18:49:34 +0000 | [diff] [blame] | 40 | #include "fpdfsdk/ipdfsdk_pauseadapter.h" |
Dan Sinclair | e0345a4 | 2017-10-30 20:20:42 +0000 | [diff] [blame] | 41 | #include "fxjs/ijs_runtime.h" |
Ryan Harrison | a74a627 | 2017-10-16 10:57:48 -0400 | [diff] [blame] | 42 | #include "public/fpdf_formfill.h" |
tsepez | 36eb4bd | 2016-10-03 15:24:27 -0700 | [diff] [blame] | 43 | #include "third_party/base/ptr_util.h" |
Bo Xu | fdc00a7 | 2014-10-28 23:03:33 -0700 | [diff] [blame] | 44 | |
Tom Sepez | 40e9ff3 | 2015-11-30 12:39:54 -0800 | [diff] [blame] | 45 | #ifdef PDF_ENABLE_XFA |
dsinclair | 521b750 | 2016-11-02 13:02:28 -0700 | [diff] [blame] | 46 | #include "fpdfsdk/fpdfxfa/cpdfxfa_context.h" |
dsinclair | 4d29e78 | 2016-10-04 14:02:47 -0700 | [diff] [blame] | 47 | #include "fpdfsdk/fpdfxfa/cpdfxfa_page.h" |
Dan Sinclair | e778668 | 2017-03-29 15:18:41 -0400 | [diff] [blame] | 48 | #include "fxbarcode/BC_Library.h" |
Tom Sepez | 40e9ff3 | 2015-11-30 12:39:54 -0800 | [diff] [blame] | 49 | #endif // PDF_ENABLE_XFA |
| 50 | |
Dan Sinclair | 698aed7 | 2017-09-26 16:24:49 -0400 | [diff] [blame] | 51 | #if _FX_PLATFORM_ == _FX_PLATFORM_WINDOWS_ |
Dan Sinclair | a5085d4 | 2017-05-11 16:26:50 -0400 | [diff] [blame] | 52 | #include "core/fxge/cfx_windowsrenderdevice.h" |
Dan Sinclair | 7aba472 | 2018-03-28 17:04:16 +0000 | [diff] [blame] | 53 | #include "public/fpdf_edit.h" |
rbpotter | e8468c4 | 2017-07-11 10:04:29 -0700 | [diff] [blame] | 54 | |
| 55 | // These checks are here because core/ and public/ cannot depend on each other. |
| 56 | static_assert(WindowsPrintMode::kModeEmf == FPDF_PRINTMODE_EMF, |
| 57 | "WindowsPrintMode::kModeEmf value mismatch"); |
| 58 | static_assert(WindowsPrintMode::kModeTextOnly == FPDF_PRINTMODE_TEXTONLY, |
| 59 | "WindowsPrintMode::kModeTextOnly value mismatch"); |
| 60 | static_assert(WindowsPrintMode::kModePostScript2 == FPDF_PRINTMODE_POSTSCRIPT2, |
| 61 | "WindowsPrintMode::kModePostScript2 value mismatch"); |
| 62 | static_assert(WindowsPrintMode::kModePostScript3 == FPDF_PRINTMODE_POSTSCRIPT3, |
| 63 | "WindowsPrintMode::kModePostScript3 value mismatch"); |
Lei Zhang | 9ed6bd7 | 2018-04-25 21:10:05 +0000 | [diff] [blame] | 64 | static_assert(WindowsPrintMode::kModePostScript2PassThrough == |
| 65 | FPDF_PRINTMODE_POSTSCRIPT2_PASSTHROUGH, |
| 66 | "WindowsPrintMode::kModePostScript2PassThrough value mismatch"); |
| 67 | static_assert(WindowsPrintMode::kModePostScript3PassThrough == |
| 68 | FPDF_PRINTMODE_POSTSCRIPT3_PASSTHROUGH, |
| 69 | "WindowsPrintMode::kModePostScript3PassThrough value mismatch"); |
thestig | 25fa42f | 2016-05-25 21:39:46 -0700 | [diff] [blame] | 70 | #endif |
| 71 | |
thestig | a78ba60 | 2016-11-23 15:25:48 -0800 | [diff] [blame] | 72 | namespace { |
| 73 | |
Dan Sinclair | 830897a | 2017-05-11 14:36:10 -0400 | [diff] [blame] | 74 | bool g_bLibraryInitialized = false; |
tsepez | 0275910 | 2016-12-01 08:29:25 -0800 | [diff] [blame] | 75 | |
thestig | a78ba60 | 2016-11-23 15:25:48 -0800 | [diff] [blame] | 76 | void RenderPageImpl(CPDF_PageRenderContext* pContext, |
| 77 | CPDF_Page* pPage, |
| 78 | const CFX_Matrix& matrix, |
| 79 | const FX_RECT& clipping_rect, |
| 80 | int flags, |
| 81 | bool bNeedToRestore, |
Dan Sinclair | 7d12532 | 2018-03-28 18:49:34 +0000 | [diff] [blame] | 82 | IPDFSDK_PauseAdapter* pause) { |
thestig | a78ba60 | 2016-11-23 15:25:48 -0800 | [diff] [blame] | 83 | if (!pContext->m_pOptions) |
| 84 | pContext->m_pOptions = pdfium::MakeUnique<CPDF_RenderOptions>(); |
| 85 | |
Dan Sinclair | 921fe6b | 2017-10-05 11:14:12 -0400 | [diff] [blame] | 86 | uint32_t option_flags = pContext->m_pOptions->GetFlags(); |
thestig | a78ba60 | 2016-11-23 15:25:48 -0800 | [diff] [blame] | 87 | if (flags & FPDF_LCD_TEXT) |
Dan Sinclair | 921fe6b | 2017-10-05 11:14:12 -0400 | [diff] [blame] | 88 | option_flags |= RENDER_CLEARTYPE; |
thestig | a78ba60 | 2016-11-23 15:25:48 -0800 | [diff] [blame] | 89 | else |
Dan Sinclair | 921fe6b | 2017-10-05 11:14:12 -0400 | [diff] [blame] | 90 | option_flags &= ~RENDER_CLEARTYPE; |
thestig | a78ba60 | 2016-11-23 15:25:48 -0800 | [diff] [blame] | 91 | |
| 92 | if (flags & FPDF_NO_NATIVETEXT) |
Dan Sinclair | 921fe6b | 2017-10-05 11:14:12 -0400 | [diff] [blame] | 93 | option_flags |= RENDER_NO_NATIVETEXT; |
thestig | a78ba60 | 2016-11-23 15:25:48 -0800 | [diff] [blame] | 94 | if (flags & FPDF_RENDER_LIMITEDIMAGECACHE) |
Dan Sinclair | 921fe6b | 2017-10-05 11:14:12 -0400 | [diff] [blame] | 95 | option_flags |= RENDER_LIMITEDIMAGECACHE; |
thestig | a78ba60 | 2016-11-23 15:25:48 -0800 | [diff] [blame] | 96 | if (flags & FPDF_RENDER_FORCEHALFTONE) |
Dan Sinclair | 921fe6b | 2017-10-05 11:14:12 -0400 | [diff] [blame] | 97 | option_flags |= RENDER_FORCE_HALFTONE; |
thestig | a78ba60 | 2016-11-23 15:25:48 -0800 | [diff] [blame] | 98 | if (flags & FPDF_RENDER_NO_SMOOTHTEXT) |
Dan Sinclair | 921fe6b | 2017-10-05 11:14:12 -0400 | [diff] [blame] | 99 | option_flags |= RENDER_NOTEXTSMOOTH; |
thestig | a78ba60 | 2016-11-23 15:25:48 -0800 | [diff] [blame] | 100 | if (flags & FPDF_RENDER_NO_SMOOTHIMAGE) |
Dan Sinclair | 921fe6b | 2017-10-05 11:14:12 -0400 | [diff] [blame] | 101 | option_flags |= RENDER_NOIMAGESMOOTH; |
thestig | a78ba60 | 2016-11-23 15:25:48 -0800 | [diff] [blame] | 102 | if (flags & FPDF_RENDER_NO_SMOOTHPATH) |
Dan Sinclair | 921fe6b | 2017-10-05 11:14:12 -0400 | [diff] [blame] | 103 | option_flags |= RENDER_NOPATHSMOOTH; |
Tom Sepez | ca027339 | 2018-05-25 23:37:50 +0000 | [diff] [blame] | 104 | |
Dan Sinclair | 921fe6b | 2017-10-05 11:14:12 -0400 | [diff] [blame] | 105 | pContext->m_pOptions->SetFlags(option_flags); |
thestig | a78ba60 | 2016-11-23 15:25:48 -0800 | [diff] [blame] | 106 | |
| 107 | // Grayscale output |
Dan Sinclair | f55e72e | 2017-07-13 14:53:28 -0400 | [diff] [blame] | 108 | if (flags & FPDF_GRAYSCALE) |
Dan Sinclair | 921fe6b | 2017-10-05 11:14:12 -0400 | [diff] [blame] | 109 | pContext->m_pOptions->SetColorMode(CPDF_RenderOptions::kGray); |
thestig | a78ba60 | 2016-11-23 15:25:48 -0800 | [diff] [blame] | 110 | |
| 111 | const CPDF_OCContext::UsageType usage = |
| 112 | (flags & FPDF_PRINTING) ? CPDF_OCContext::Print : CPDF_OCContext::View; |
Dan Sinclair | 921fe6b | 2017-10-05 11:14:12 -0400 | [diff] [blame] | 113 | pContext->m_pOptions->SetOCContext( |
Lei Zhang | 8f63763 | 2018-05-07 23:36:26 +0000 | [diff] [blame] | 114 | pdfium::MakeRetain<CPDF_OCContext>(pPage->GetDocument(), usage)); |
thestig | a78ba60 | 2016-11-23 15:25:48 -0800 | [diff] [blame] | 115 | |
| 116 | pContext->m_pDevice->SaveState(); |
| 117 | pContext->m_pDevice->SetClip_Rect(clipping_rect); |
thestig | a78ba60 | 2016-11-23 15:25:48 -0800 | [diff] [blame] | 118 | pContext->m_pContext = pdfium::MakeUnique<CPDF_RenderContext>(pPage); |
| 119 | pContext->m_pContext->AppendLayer(pPage, &matrix); |
| 120 | |
| 121 | if (flags & FPDF_ANNOT) { |
| 122 | pContext->m_pAnnots = pdfium::MakeUnique<CPDF_AnnotList>(pPage); |
| 123 | bool bPrinting = pContext->m_pDevice->GetDeviceClass() != FXDC_DISPLAY; |
| 124 | pContext->m_pAnnots->DisplayAnnots(pPage, pContext->m_pContext.get(), |
| 125 | bPrinting, &matrix, false, nullptr); |
| 126 | } |
| 127 | |
| 128 | pContext->m_pRenderer = pdfium::MakeUnique<CPDF_ProgressiveRenderer>( |
| 129 | pContext->m_pContext.get(), pContext->m_pDevice.get(), |
| 130 | pContext->m_pOptions.get()); |
| 131 | pContext->m_pRenderer->Start(pause); |
| 132 | if (bNeedToRestore) |
| 133 | pContext->m_pDevice->RestoreState(false); |
| 134 | } |
| 135 | |
Artem Strygin | 3f7ff05 | 2017-07-27 22:16:13 +0300 | [diff] [blame] | 136 | FPDF_DOCUMENT LoadDocumentImpl( |
Dan Sinclair | 0b95042 | 2017-09-21 15:49:49 -0400 | [diff] [blame] | 137 | const RetainPtr<IFX_SeekableReadStream>& pFileAccess, |
Artem Strygin | 3f7ff05 | 2017-07-27 22:16:13 +0300 | [diff] [blame] | 138 | FPDF_BYTESTRING password) { |
Jane Liu | 8a1081f | 2017-08-22 16:28:05 -0400 | [diff] [blame] | 139 | if (!pFileAccess) { |
| 140 | ProcessParseError(CPDF_Parser::FILE_ERROR); |
Artem Strygin | 3f7ff05 | 2017-07-27 22:16:13 +0300 | [diff] [blame] | 141 | return nullptr; |
Jane Liu | 8a1081f | 2017-08-22 16:28:05 -0400 | [diff] [blame] | 142 | } |
Artem Strygin | 3f7ff05 | 2017-07-27 22:16:13 +0300 | [diff] [blame] | 143 | |
| 144 | auto pParser = pdfium::MakeUnique<CPDF_Parser>(); |
| 145 | pParser->SetPassword(password); |
| 146 | |
| 147 | auto pDocument = pdfium::MakeUnique<CPDF_Document>(std::move(pParser)); |
| 148 | CPDF_Parser::Error error = |
| 149 | pDocument->GetParser()->StartParse(pFileAccess, pDocument.get()); |
| 150 | if (error != CPDF_Parser::SUCCESS) { |
| 151 | ProcessParseError(error); |
| 152 | return nullptr; |
| 153 | } |
| 154 | CheckUnSupportError(pDocument.get(), error); |
Tom Sepez | b80edf3 | 2018-06-01 17:42:33 +0000 | [diff] [blame] | 155 | |
| 156 | #ifdef PDF_ENABLE_XFA |
| 157 | pDocument->SetExtension(pdfium::MakeUnique<CPDFXFA_Context>(pDocument.get())); |
| 158 | #endif // PDF_ENABLE_XFA |
| 159 | |
Artem Strygin | 3f7ff05 | 2017-07-27 22:16:13 +0300 | [diff] [blame] | 160 | return FPDFDocumentFromCPDFDocument(pDocument.release()); |
| 161 | } |
| 162 | |
tsepez | fa89a20 | 2016-12-02 09:48:30 -0800 | [diff] [blame] | 163 | } // namespace |
| 164 | |
Dan Sinclair | 00d2ad1 | 2017-08-10 14:13:02 -0400 | [diff] [blame] | 165 | FPDF_EXPORT void FPDF_CALLCONV FPDF_InitLibrary() { |
Lei Zhang | 6f62d53 | 2015-09-23 15:31:44 -0700 | [diff] [blame] | 166 | FPDF_InitLibraryWithConfig(nullptr); |
| 167 | } |
| 168 | |
Dan Sinclair | 00d2ad1 | 2017-08-10 14:13:02 -0400 | [diff] [blame] | 169 | FPDF_EXPORT void FPDF_CALLCONV |
Dan Sinclair | f766ad2 | 2016-03-14 13:51:24 -0400 | [diff] [blame] | 170 | FPDF_InitLibraryWithConfig(const FPDF_LIBRARY_CONFIG* cfg) { |
Dan Sinclair | 830897a | 2017-05-11 14:36:10 -0400 | [diff] [blame] | 171 | if (g_bLibraryInitialized) |
tsepez | 0275910 | 2016-12-01 08:29:25 -0800 | [diff] [blame] | 172 | return; |
| 173 | |
Dan Sinclair | dbc3d3e | 2017-05-11 13:41:38 -0400 | [diff] [blame] | 174 | FXMEM_InitializePartitionAlloc(); |
John Abd-El-Malek | 3f3b45c | 2014-05-23 17:28:10 -0700 | [diff] [blame] | 175 | |
weili | 47228ac | 2016-07-20 10:35:31 -0700 | [diff] [blame] | 176 | CFX_GEModule* pModule = CFX_GEModule::Get(); |
Dan Sinclair | 830897a | 2017-05-11 14:36:10 -0400 | [diff] [blame] | 177 | pModule->Init(cfg ? cfg->m_pUserFontPaths : nullptr); |
tsepez | 0275910 | 2016-12-01 08:29:25 -0800 | [diff] [blame] | 178 | |
Tom Sepez | 1b24628 | 2015-11-25 15:15:31 -0800 | [diff] [blame] | 179 | CPDF_ModuleMgr* pModuleMgr = CPDF_ModuleMgr::Get(); |
Lei Zhang | 76020fc | 2017-05-18 15:51:20 -0700 | [diff] [blame] | 180 | pModuleMgr->Init(); |
Tom Sepez | b4a2618 | 2017-03-01 12:15:00 -0800 | [diff] [blame] | 181 | |
Tom Sepez | 40e9ff3 | 2015-11-30 12:39:54 -0800 | [diff] [blame] | 182 | #ifdef PDF_ENABLE_XFA |
dsinclair | 8837c91 | 2016-11-01 11:22:37 -0700 | [diff] [blame] | 183 | BC_Library_Init(); |
Tom Sepez | 40e9ff3 | 2015-11-30 12:39:54 -0800 | [diff] [blame] | 184 | #endif // PDF_ENABLE_XFA |
Tom Sepez | 452b4f3 | 2015-10-13 09:27:27 -0700 | [diff] [blame] | 185 | if (cfg && cfg->version >= 2) |
| 186 | IJS_Runtime::Initialize(cfg->m_v8EmbedderSlot, cfg->m_pIsolate); |
Dan Sinclair | 830897a | 2017-05-11 14:36:10 -0400 | [diff] [blame] | 187 | |
| 188 | g_bLibraryInitialized = true; |
John Abd-El-Malek | 3f3b45c | 2014-05-23 17:28:10 -0700 | [diff] [blame] | 189 | } |
| 190 | |
Dan Sinclair | 00d2ad1 | 2017-08-10 14:13:02 -0400 | [diff] [blame] | 191 | FPDF_EXPORT void FPDF_CALLCONV FPDF_DestroyLibrary() { |
Dan Sinclair | 830897a | 2017-05-11 14:36:10 -0400 | [diff] [blame] | 192 | if (!g_bLibraryInitialized) |
tsepez | 0275910 | 2016-12-01 08:29:25 -0800 | [diff] [blame] | 193 | return; |
| 194 | |
Tom Sepez | 51da093 | 2015-11-25 16:05:49 -0800 | [diff] [blame] | 195 | #ifdef PDF_ENABLE_XFA |
Tom Sepez | 5628fd7 | 2017-04-27 14:58:53 -0700 | [diff] [blame] | 196 | BC_Library_Destroy(); |
Tom Sepez | 40e9ff3 | 2015-11-30 12:39:54 -0800 | [diff] [blame] | 197 | #endif // PDF_ENABLE_XFA |
dsinclair | 8837c91 | 2016-11-01 11:22:37 -0700 | [diff] [blame] | 198 | |
Nico Weber | 9d8ec5a | 2015-08-04 13:00:21 -0700 | [diff] [blame] | 199 | CPDF_ModuleMgr::Destroy(); |
| 200 | CFX_GEModule::Destroy(); |
Tom Sepez | 2c28619 | 2015-06-18 12:47:11 -0700 | [diff] [blame] | 201 | |
thestig | 2d6dda1 | 2016-06-28 07:39:09 -0700 | [diff] [blame] | 202 | IJS_Runtime::Destroy(); |
Dan Sinclair | 830897a | 2017-05-11 14:36:10 -0400 | [diff] [blame] | 203 | |
| 204 | g_bLibraryInitialized = false; |
John Abd-El-Malek | 3f3b45c | 2014-05-23 17:28:10 -0700 | [diff] [blame] | 205 | } |
| 206 | |
Dan Sinclair | 00d2ad1 | 2017-08-10 14:13:02 -0400 | [diff] [blame] | 207 | FPDF_EXPORT void FPDF_CALLCONV FPDF_SetSandBoxPolicy(FPDF_DWORD policy, |
| 208 | FPDF_BOOL enable) { |
Nico Weber | 9d8ec5a | 2015-08-04 13:00:21 -0700 | [diff] [blame] | 209 | return FSDK_SetSandBoxPolicy(policy, enable); |
John Abd-El-Malek | 3f3b45c | 2014-05-23 17:28:10 -0700 | [diff] [blame] | 210 | } |
| 211 | |
rbpotter | db76470 | 2017-01-12 10:31:43 -0800 | [diff] [blame] | 212 | #if defined(_WIN32) |
| 213 | #if defined(PDFIUM_PRINT_TEXT_WITH_GDI) |
Dan Sinclair | 00d2ad1 | 2017-08-10 14:13:02 -0400 | [diff] [blame] | 214 | FPDF_EXPORT void FPDF_CALLCONV |
thestig | fdb35ff | 2016-07-18 13:45:44 -0700 | [diff] [blame] | 215 | FPDF_SetTypefaceAccessibleFunc(PDFiumEnsureTypefaceCharactersAccessible func) { |
| 216 | g_pdfium_typeface_accessible_func = func; |
| 217 | } |
| 218 | |
Dan Sinclair | 00d2ad1 | 2017-08-10 14:13:02 -0400 | [diff] [blame] | 219 | FPDF_EXPORT void FPDF_CALLCONV FPDF_SetPrintTextWithGDI(FPDF_BOOL use_gdi) { |
thestig | fdb35ff | 2016-07-18 13:45:44 -0700 | [diff] [blame] | 220 | g_pdfium_print_text_with_gdi = !!use_gdi; |
| 221 | } |
rbpotter | db76470 | 2017-01-12 10:31:43 -0800 | [diff] [blame] | 222 | #endif // PDFIUM_PRINT_TEXT_WITH_GDI |
| 223 | |
Dan Sinclair | 00d2ad1 | 2017-08-10 14:13:02 -0400 | [diff] [blame] | 224 | FPDF_EXPORT FPDF_BOOL FPDF_CALLCONV FPDF_SetPrintMode(int mode) { |
Lei Zhang | 9ed6bd7 | 2018-04-25 21:10:05 +0000 | [diff] [blame] | 225 | if (mode < FPDF_PRINTMODE_EMF || |
| 226 | mode > FPDF_PRINTMODE_POSTSCRIPT3_PASSTHROUGH) { |
rbpotter | db76470 | 2017-01-12 10:31:43 -0800 | [diff] [blame] | 227 | return FALSE; |
Lei Zhang | 9ed6bd7 | 2018-04-25 21:10:05 +0000 | [diff] [blame] | 228 | } |
Lei Zhang | 537f4c7 | 2018-04-25 18:01:52 +0000 | [diff] [blame] | 229 | g_pdfium_print_mode = static_cast<WindowsPrintMode>(mode); |
rbpotter | db76470 | 2017-01-12 10:31:43 -0800 | [diff] [blame] | 230 | return TRUE; |
| 231 | } |
| 232 | #endif // defined(_WIN32) |
thestig | fdb35ff | 2016-07-18 13:45:44 -0700 | [diff] [blame] | 233 | |
Dan Sinclair | 00d2ad1 | 2017-08-10 14:13:02 -0400 | [diff] [blame] | 234 | FPDF_EXPORT FPDF_DOCUMENT FPDF_CALLCONV |
| 235 | FPDF_LoadDocument(FPDF_STRING file_path, FPDF_BYTESTRING password) { |
Tom Sepez | e3166a8 | 2015-08-05 10:50:32 -0700 | [diff] [blame] | 236 | // NOTE: the creation of the file needs to be by the embedder on the |
| 237 | // other side of this API. |
Lei Zhang | a6adac8 | 2017-11-02 19:27:08 +0000 | [diff] [blame] | 238 | return LoadDocumentImpl(IFX_SeekableReadStream::CreateFromFilename(file_path), |
| 239 | password); |
John Abd-El-Malek | 3f3b45c | 2014-05-23 17:28:10 -0700 | [diff] [blame] | 240 | } |
Jun Fang | e118ce9 | 2015-02-17 06:50:08 -0800 | [diff] [blame] | 241 | |
Ryan Harrison | 854d71c | 2017-10-18 12:28:14 -0400 | [diff] [blame] | 242 | FPDF_EXPORT int FPDF_CALLCONV FPDF_GetFormType(FPDF_DOCUMENT document) { |
Ryan Harrison | a74a627 | 2017-10-16 10:57:48 -0400 | [diff] [blame] | 243 | const CPDF_Document* pDoc = CPDFDocumentFromFPDFDocument(document); |
Lei Zhang | 0158106 | 2017-08-30 14:19:26 -0700 | [diff] [blame] | 244 | if (!pDoc) |
Ryan Harrison | 854d71c | 2017-10-18 12:28:14 -0400 | [diff] [blame] | 245 | return FORMTYPE_NONE; |
JUN FANG | 827a172 | 2015-03-05 13:39:21 -0800 | [diff] [blame] | 246 | |
Lei Zhang | 0158106 | 2017-08-30 14:19:26 -0700 | [diff] [blame] | 247 | const CPDF_Dictionary* pRoot = pDoc->GetRoot(); |
Nico Weber | 9d8ec5a | 2015-08-04 13:00:21 -0700 | [diff] [blame] | 248 | if (!pRoot) |
Ryan Harrison | 854d71c | 2017-10-18 12:28:14 -0400 | [diff] [blame] | 249 | return FORMTYPE_NONE; |
JUN FANG | 827a172 | 2015-03-05 13:39:21 -0800 | [diff] [blame] | 250 | |
Lei Zhang | 55bbb0a | 2018-05-08 19:26:37 +0000 | [diff] [blame] | 251 | const CPDF_Dictionary* pAcroForm = pRoot->GetDictFor("AcroForm"); |
Nico Weber | 9d8ec5a | 2015-08-04 13:00:21 -0700 | [diff] [blame] | 252 | if (!pAcroForm) |
Ryan Harrison | 854d71c | 2017-10-18 12:28:14 -0400 | [diff] [blame] | 253 | return FORMTYPE_NONE; |
JUN FANG | 827a172 | 2015-03-05 13:39:21 -0800 | [diff] [blame] | 254 | |
Lei Zhang | 55bbb0a | 2018-05-08 19:26:37 +0000 | [diff] [blame] | 255 | const CPDF_Object* pXFA = pAcroForm->GetObjectFor("XFA"); |
Nico Weber | 9d8ec5a | 2015-08-04 13:00:21 -0700 | [diff] [blame] | 256 | if (!pXFA) |
Ryan Harrison | 854d71c | 2017-10-18 12:28:14 -0400 | [diff] [blame] | 257 | return FORMTYPE_ACRO_FORM; |
JUN FANG | 827a172 | 2015-03-05 13:39:21 -0800 | [diff] [blame] | 258 | |
Lei Zhang | d6e92bd | 2018-01-29 19:01:26 +0000 | [diff] [blame] | 259 | bool bNeedsRendering = pRoot->GetBooleanFor("NeedsRendering", false); |
| 260 | return bNeedsRendering ? FORMTYPE_XFA_FULL : FORMTYPE_XFA_FOREGROUND; |
Jun Fang | e118ce9 | 2015-02-17 06:50:08 -0800 | [diff] [blame] | 261 | } |
| 262 | |
Ryan Harrison | a74a627 | 2017-10-16 10:57:48 -0400 | [diff] [blame] | 263 | #ifdef PDF_ENABLE_XFA |
Dan Sinclair | 00d2ad1 | 2017-08-10 14:13:02 -0400 | [diff] [blame] | 264 | FPDF_EXPORT FPDF_BOOL FPDF_CALLCONV FPDF_LoadXFA(FPDF_DOCUMENT document) { |
Tom Sepez | fe06d51 | 2018-05-01 17:25:25 +0000 | [diff] [blame] | 265 | auto* pDoc = CPDFDocumentFromFPDFDocument(document); |
Tom Sepez | 3f3c39d | 2018-05-01 17:46:34 +0000 | [diff] [blame] | 266 | if (!pDoc) |
| 267 | return false; |
| 268 | |
| 269 | auto* pContext = static_cast<CPDFXFA_Context*>(pDoc->GetExtension()); |
| 270 | return pContext && pContext->LoadXFADoc(); |
Bo Xu | fdc00a7 | 2014-10-28 23:03:33 -0700 | [diff] [blame] | 271 | } |
Tom Sepez | 40e9ff3 | 2015-11-30 12:39:54 -0800 | [diff] [blame] | 272 | #endif // PDF_ENABLE_XFA |
Bo Xu | fdc00a7 | 2014-10-28 23:03:33 -0700 | [diff] [blame] | 273 | |
Dan Sinclair | 00d2ad1 | 2017-08-10 14:13:02 -0400 | [diff] [blame] | 274 | FPDF_EXPORT FPDF_DOCUMENT FPDF_CALLCONV |
| 275 | FPDF_LoadMemDocument(const void* data_buf, int size, FPDF_BYTESTRING password) { |
Dan Sinclair | 7aba472 | 2018-03-28 17:04:16 +0000 | [diff] [blame] | 276 | return LoadDocumentImpl(pdfium::MakeRetain<CPDFSDK_MemoryAccess>( |
| 277 | static_cast<const uint8_t*>(data_buf), size), |
| 278 | password); |
John Abd-El-Malek | 3f3b45c | 2014-05-23 17:28:10 -0700 | [diff] [blame] | 279 | } |
| 280 | |
Dan Sinclair | 00d2ad1 | 2017-08-10 14:13:02 -0400 | [diff] [blame] | 281 | FPDF_EXPORT FPDF_DOCUMENT FPDF_CALLCONV |
Nico Weber | 9d8ec5a | 2015-08-04 13:00:21 -0700 | [diff] [blame] | 282 | FPDF_LoadCustomDocument(FPDF_FILEACCESS* pFileAccess, |
| 283 | FPDF_BYTESTRING password) { |
Dan Sinclair | 7aba472 | 2018-03-28 17:04:16 +0000 | [diff] [blame] | 284 | return LoadDocumentImpl(pdfium::MakeRetain<CPDFSDK_CustomAccess>(pFileAccess), |
Artem Strygin | 3f7ff05 | 2017-07-27 22:16:13 +0300 | [diff] [blame] | 285 | password); |
John Abd-El-Malek | 3f3b45c | 2014-05-23 17:28:10 -0700 | [diff] [blame] | 286 | } |
| 287 | |
Dan Sinclair | 00d2ad1 | 2017-08-10 14:13:02 -0400 | [diff] [blame] | 288 | FPDF_EXPORT FPDF_BOOL FPDF_CALLCONV FPDF_GetFileVersion(FPDF_DOCUMENT doc, |
| 289 | int* fileVersion) { |
Tom Sepez | 471a103 | 2015-10-15 16:17:18 -0700 | [diff] [blame] | 290 | if (!fileVersion) |
tsepez | 4cf5515 | 2016-11-02 14:37:54 -0700 | [diff] [blame] | 291 | return false; |
Bo Xu | fdc00a7 | 2014-10-28 23:03:33 -0700 | [diff] [blame] | 292 | |
Tom Sepez | 471a103 | 2015-10-15 16:17:18 -0700 | [diff] [blame] | 293 | *fileVersion = 0; |
| 294 | CPDF_Document* pDoc = CPDFDocumentFromFPDFDocument(doc); |
| 295 | if (!pDoc) |
tsepez | 4cf5515 | 2016-11-02 14:37:54 -0700 | [diff] [blame] | 296 | return false; |
Tom Sepez | 471a103 | 2015-10-15 16:17:18 -0700 | [diff] [blame] | 297 | |
Lei Zhang | 0158106 | 2017-08-30 14:19:26 -0700 | [diff] [blame] | 298 | const CPDF_Parser* pParser = pDoc->GetParser(); |
Nico Weber | 9d8ec5a | 2015-08-04 13:00:21 -0700 | [diff] [blame] | 299 | if (!pParser) |
tsepez | 4cf5515 | 2016-11-02 14:37:54 -0700 | [diff] [blame] | 300 | return false; |
Tom Sepez | 471a103 | 2015-10-15 16:17:18 -0700 | [diff] [blame] | 301 | |
Nico Weber | 9d8ec5a | 2015-08-04 13:00:21 -0700 | [diff] [blame] | 302 | *fileVersion = pParser->GetFileVersion(); |
tsepez | 4cf5515 | 2016-11-02 14:37:54 -0700 | [diff] [blame] | 303 | return true; |
John Abd-El-Malek | 3f3b45c | 2014-05-23 17:28:10 -0700 | [diff] [blame] | 304 | } |
| 305 | |
tsepez | c3255f5 | 2016-03-25 14:52:27 -0700 | [diff] [blame] | 306 | // jabdelmalek: changed return type from uint32_t to build on Linux (and match |
Nico Weber | 9d8ec5a | 2015-08-04 13:00:21 -0700 | [diff] [blame] | 307 | // header). |
Dan Sinclair | 00d2ad1 | 2017-08-10 14:13:02 -0400 | [diff] [blame] | 308 | FPDF_EXPORT unsigned long FPDF_CALLCONV |
| 309 | FPDF_GetDocPermissions(FPDF_DOCUMENT document) { |
Tom Sepez | 471a103 | 2015-10-15 16:17:18 -0700 | [diff] [blame] | 310 | CPDF_Document* pDoc = CPDFDocumentFromFPDFDocument(document); |
Tom Sepez | 28d30b4 | 2018-06-04 17:12:27 +0000 | [diff] [blame] | 311 | // https://bugs.chromium.org/p/pdfium/issues/detail?id=499 |
| 312 | if (!pDoc) { |
| 313 | #ifndef PDF_ENABLE_XFA |
| 314 | return 0; |
| 315 | #else // PDF_ENABLE_XFA |
| 316 | return 0xFFFFFFFF; |
| 317 | #endif // PDF_ENABLE_XFA |
| 318 | } |
| 319 | |
| 320 | return pDoc->GetUserPermissions(); |
John Abd-El-Malek | 3f3b45c | 2014-05-23 17:28:10 -0700 | [diff] [blame] | 321 | } |
| 322 | |
Dan Sinclair | 00d2ad1 | 2017-08-10 14:13:02 -0400 | [diff] [blame] | 323 | FPDF_EXPORT int FPDF_CALLCONV |
| 324 | FPDF_GetSecurityHandlerRevision(FPDF_DOCUMENT document) { |
Tom Sepez | 471a103 | 2015-10-15 16:17:18 -0700 | [diff] [blame] | 325 | CPDF_Document* pDoc = CPDFDocumentFromFPDFDocument(document); |
thestig | b8db511 | 2016-04-06 12:12:52 -0700 | [diff] [blame] | 326 | if (!pDoc || !pDoc->GetParser()) |
Nico Weber | 9d8ec5a | 2015-08-04 13:00:21 -0700 | [diff] [blame] | 327 | return -1; |
Bo Xu | c5cab02 | 2014-09-19 19:16:31 -0700 | [diff] [blame] | 328 | |
Tom Sepez | 471a103 | 2015-10-15 16:17:18 -0700 | [diff] [blame] | 329 | CPDF_Dictionary* pDict = pDoc->GetParser()->GetEncryptDict(); |
dsinclair | 38fd844 | 2016-09-15 10:15:32 -0700 | [diff] [blame] | 330 | return pDict ? pDict->GetIntegerFor("R") : -1; |
Bo Xu | c5cab02 | 2014-09-19 19:16:31 -0700 | [diff] [blame] | 331 | } |
| 332 | |
Dan Sinclair | 00d2ad1 | 2017-08-10 14:13:02 -0400 | [diff] [blame] | 333 | FPDF_EXPORT int FPDF_CALLCONV FPDF_GetPageCount(FPDF_DOCUMENT document) { |
Tom Sepez | fe06d51 | 2018-05-01 17:25:25 +0000 | [diff] [blame] | 334 | auto* pDoc = CPDFDocumentFromFPDFDocument(document); |
| 335 | if (!pDoc) |
| 336 | return 0; |
Tom Sepez | 3f3c39d | 2018-05-01 17:46:34 +0000 | [diff] [blame] | 337 | |
Tom Sepez | 5f3e4f1 | 2018-05-02 13:33:50 +0000 | [diff] [blame] | 338 | auto* pExtension = pDoc->GetExtension(); |
| 339 | return pExtension ? pExtension->GetPageCount() : pDoc->GetPageCount(); |
John Abd-El-Malek | 3f3b45c | 2014-05-23 17:28:10 -0700 | [diff] [blame] | 340 | } |
| 341 | |
Dan Sinclair | 00d2ad1 | 2017-08-10 14:13:02 -0400 | [diff] [blame] | 342 | FPDF_EXPORT FPDF_PAGE FPDF_CALLCONV FPDF_LoadPage(FPDF_DOCUMENT document, |
| 343 | int page_index) { |
Tom Sepez | fe06d51 | 2018-05-01 17:25:25 +0000 | [diff] [blame] | 344 | auto* pDoc = CPDFDocumentFromFPDFDocument(document); |
Tom Sepez | 50d12ad | 2015-11-24 09:50:51 -0800 | [diff] [blame] | 345 | if (!pDoc) |
Tom Sepez | 471a103 | 2015-10-15 16:17:18 -0700 | [diff] [blame] | 346 | return nullptr; |
Tom Sepez | 1b24628 | 2015-11-25 15:15:31 -0800 | [diff] [blame] | 347 | |
Tom Sepez | fe06d51 | 2018-05-01 17:25:25 +0000 | [diff] [blame] | 348 | if (page_index < 0 || page_index >= FPDF_GetPageCount(document)) |
Tom Sepez | 471a103 | 2015-10-15 16:17:18 -0700 | [diff] [blame] | 349 | return nullptr; |
| 350 | |
Tom Sepez | 40e9ff3 | 2015-11-30 12:39:54 -0800 | [diff] [blame] | 351 | #ifdef PDF_ENABLE_XFA |
Tom Sepez | 3f3c39d | 2018-05-01 17:46:34 +0000 | [diff] [blame] | 352 | auto* pContext = static_cast<CPDFXFA_Context*>(pDoc->GetExtension()); |
| 353 | if (pContext) |
Tom Sepez | 101535f | 2018-06-12 13:36:05 +0000 | [diff] [blame^] | 354 | return FPDFPageFromIPDFPage(pContext->GetXFAPage(page_index).Leak()); |
Tom Sepez | 3f3c39d | 2018-05-01 17:46:34 +0000 | [diff] [blame] | 355 | |
Tom Sepez | 037d938 | 2018-06-04 16:52:57 +0000 | [diff] [blame] | 356 | // Eventually, fallthrough into non-xfa case once page type made consistent. |
| 357 | return nullptr; |
| 358 | #else // PDF_ENABLE_XFA |
Tom Sepez | 967aa07 | 2018-05-08 13:40:20 +0000 | [diff] [blame] | 359 | CPDF_Dictionary* pDict = pDoc->GetPageDictionary(page_index); |
Lei Zhang | 412e908 | 2015-12-14 18:34:00 -0800 | [diff] [blame] | 360 | if (!pDict) |
thestig | 5cc2465 | 2016-04-26 11:46:02 -0700 | [diff] [blame] | 361 | return nullptr; |
| 362 | |
Tom Sepez | f06ed6d | 2018-06-04 18:26:07 +0000 | [diff] [blame] | 363 | auto pPage = pdfium::MakeRetain<CPDF_Page>(pDoc, pDict, true); |
| 364 | pPage->ParseContent(); |
Tom Sepez | 101535f | 2018-06-12 13:36:05 +0000 | [diff] [blame^] | 365 | return FPDFPageFromIPDFPage(pPage.Leak()); |
Tom Sepez | 037d938 | 2018-06-04 16:52:57 +0000 | [diff] [blame] | 366 | #endif // PDF_ENABLE_XFA |
John Abd-El-Malek | 3f3b45c | 2014-05-23 17:28:10 -0700 | [diff] [blame] | 367 | } |
| 368 | |
Dan Sinclair | 00d2ad1 | 2017-08-10 14:13:02 -0400 | [diff] [blame] | 369 | FPDF_EXPORT double FPDF_CALLCONV FPDF_GetPageWidth(FPDF_PAGE page) { |
Tom Sepez | 101535f | 2018-06-12 13:36:05 +0000 | [diff] [blame^] | 370 | IPDF_Page* pPage = IPDFPageFromFPDFPage(page); |
Tom Sepez | bf59a07 | 2015-10-21 14:07:23 -0700 | [diff] [blame] | 371 | return pPage ? pPage->GetPageWidth() : 0.0; |
John Abd-El-Malek | 3f3b45c | 2014-05-23 17:28:10 -0700 | [diff] [blame] | 372 | } |
| 373 | |
Dan Sinclair | 00d2ad1 | 2017-08-10 14:13:02 -0400 | [diff] [blame] | 374 | FPDF_EXPORT double FPDF_CALLCONV FPDF_GetPageHeight(FPDF_PAGE page) { |
Tom Sepez | 101535f | 2018-06-12 13:36:05 +0000 | [diff] [blame^] | 375 | IPDF_Page* pPage = IPDFPageFromFPDFPage(page); |
Tom Sepez | bf59a07 | 2015-10-21 14:07:23 -0700 | [diff] [blame] | 376 | return pPage ? pPage->GetPageHeight() : 0.0; |
John Abd-El-Malek | 3f3b45c | 2014-05-23 17:28:10 -0700 | [diff] [blame] | 377 | } |
| 378 | |
Henrique Nakashima | 2615590 | 2018-01-16 16:39:05 +0000 | [diff] [blame] | 379 | FPDF_EXPORT FPDF_BOOL FPDF_CALLCONV FPDF_GetPageBoundingBox(FPDF_PAGE page, |
| 380 | FS_RECTF* rect) { |
| 381 | if (!rect) |
| 382 | return false; |
| 383 | |
| 384 | CPDF_Page* pPage = CPDFPageFromFPDFPage(page); |
| 385 | if (!pPage) |
| 386 | return false; |
| 387 | |
Tom Sepez | 778e59e | 2018-06-05 19:24:42 +0000 | [diff] [blame] | 388 | FSRECTFFromCFXFloatRect(pPage->GetBBox(), rect); |
Henrique Nakashima | 2615590 | 2018-01-16 16:39:05 +0000 | [diff] [blame] | 389 | return true; |
| 390 | } |
| 391 | |
John Abd-El-Malek | 3f3b45c | 2014-05-23 17:28:10 -0700 | [diff] [blame] | 392 | #if defined(_WIN32) |
rbpotter | cec0180 | 2017-04-17 09:10:21 -0700 | [diff] [blame] | 393 | namespace { |
| 394 | |
| 395 | const double kEpsilonSize = 0.01f; |
| 396 | |
| 397 | void GetScaling(CPDF_Page* pPage, |
| 398 | int size_x, |
| 399 | int size_y, |
| 400 | int rotate, |
| 401 | double* scale_x, |
| 402 | double* scale_y) { |
| 403 | ASSERT(pPage); |
| 404 | ASSERT(scale_x); |
| 405 | ASSERT(scale_y); |
| 406 | double page_width = pPage->GetPageWidth(); |
| 407 | double page_height = pPage->GetPageHeight(); |
| 408 | if (page_width < kEpsilonSize || page_height < kEpsilonSize) |
| 409 | return; |
| 410 | |
| 411 | if (rotate % 2 == 0) { |
| 412 | *scale_x = size_x / page_width; |
| 413 | *scale_y = size_y / page_height; |
| 414 | } else { |
| 415 | *scale_x = size_y / page_width; |
| 416 | *scale_y = size_x / page_height; |
| 417 | } |
| 418 | } |
| 419 | |
| 420 | FX_RECT GetMaskDimensionsAndOffsets(CPDF_Page* pPage, |
| 421 | int start_x, |
| 422 | int start_y, |
| 423 | int size_x, |
| 424 | int size_y, |
| 425 | int rotate, |
| 426 | const CFX_FloatRect& mask_box) { |
| 427 | double scale_x = 0.0f; |
| 428 | double scale_y = 0.0f; |
| 429 | GetScaling(pPage, size_x, size_y, rotate, &scale_x, &scale_y); |
| 430 | if (scale_x < kEpsilonSize || scale_y < kEpsilonSize) |
| 431 | return FX_RECT(); |
| 432 | |
| 433 | // Compute sizes in page points. Round down to catch the entire bitmap. |
| 434 | int start_x_bm = static_cast<int>(mask_box.left * scale_x); |
| 435 | int start_y_bm = static_cast<int>(mask_box.bottom * scale_y); |
| 436 | int size_x_bm = static_cast<int>(mask_box.right * scale_x + 1.0f) - |
| 437 | static_cast<int>(mask_box.left * scale_x); |
| 438 | int size_y_bm = static_cast<int>(mask_box.top * scale_y + 1.0f) - |
| 439 | static_cast<int>(mask_box.bottom * scale_y); |
| 440 | |
| 441 | // Get page rotation |
rbpotter | ce8e51e | 2017-04-28 12:42:47 -0700 | [diff] [blame] | 442 | int page_rotation = pPage->GetPageRotation(); |
rbpotter | cec0180 | 2017-04-17 09:10:21 -0700 | [diff] [blame] | 443 | |
| 444 | // Compute offsets |
| 445 | int offset_x = 0; |
| 446 | int offset_y = 0; |
rbpotter | 8d7672e | 2017-08-16 16:45:44 -0700 | [diff] [blame] | 447 | if (size_x > size_y) |
| 448 | std::swap(size_x_bm, size_y_bm); |
| 449 | |
rbpotter | cec0180 | 2017-04-17 09:10:21 -0700 | [diff] [blame] | 450 | switch ((rotate + page_rotation) % 4) { |
| 451 | case 0: |
| 452 | offset_x = start_x_bm + start_x; |
| 453 | offset_y = start_y + size_y - size_y_bm - start_y_bm; |
| 454 | break; |
| 455 | case 1: |
| 456 | offset_x = start_y_bm + start_x; |
| 457 | offset_y = start_x_bm + start_y; |
| 458 | break; |
| 459 | case 2: |
| 460 | offset_x = start_x + size_x - size_x_bm - start_x_bm; |
| 461 | offset_y = start_y_bm + start_y; |
| 462 | break; |
| 463 | case 3: |
| 464 | offset_x = start_x + size_x - size_x_bm - start_y_bm; |
| 465 | offset_y = start_y + size_y - size_y_bm - start_x_bm; |
| 466 | break; |
| 467 | } |
| 468 | return FX_RECT(offset_x, offset_y, offset_x + size_x_bm, |
| 469 | offset_y + size_y_bm); |
| 470 | } |
| 471 | |
| 472 | // Get a bitmap of just the mask section defined by |mask_box| from a full page |
| 473 | // bitmap |pBitmap|. |
Dan Sinclair | 0b95042 | 2017-09-21 15:49:49 -0400 | [diff] [blame] | 474 | RetainPtr<CFX_DIBitmap> GetMaskBitmap(CPDF_Page* pPage, |
| 475 | int start_x, |
| 476 | int start_y, |
| 477 | int size_x, |
| 478 | int size_y, |
| 479 | int rotate, |
Lei Zhang | 8a884a4 | 2017-11-02 18:30:30 +0000 | [diff] [blame] | 480 | const RetainPtr<CFX_DIBitmap>& pSrc, |
Dan Sinclair | 0b95042 | 2017-09-21 15:49:49 -0400 | [diff] [blame] | 481 | const CFX_FloatRect& mask_box, |
| 482 | FX_RECT* bitmap_area) { |
rbpotter | cec0180 | 2017-04-17 09:10:21 -0700 | [diff] [blame] | 483 | ASSERT(bitmap_area); |
| 484 | *bitmap_area = GetMaskDimensionsAndOffsets(pPage, start_x, start_y, size_x, |
| 485 | size_y, rotate, mask_box); |
| 486 | if (bitmap_area->IsEmpty()) |
| 487 | return nullptr; |
| 488 | |
| 489 | // Create a new bitmap to transfer part of the page bitmap to. |
Dan Sinclair | 0b95042 | 2017-09-21 15:49:49 -0400 | [diff] [blame] | 490 | RetainPtr<CFX_DIBitmap> pDst = pdfium::MakeRetain<CFX_DIBitmap>(); |
Nicolas Pena | d08667c | 2018-04-16 17:41:47 +0000 | [diff] [blame] | 491 | if (!pDst->Create(bitmap_area->Width(), bitmap_area->Height(), FXDIB_Argb)) |
| 492 | return nullptr; |
| 493 | |
rbpotter | cec0180 | 2017-04-17 09:10:21 -0700 | [diff] [blame] | 494 | pDst->Clear(0x00ffffff); |
| 495 | pDst->TransferBitmap(0, 0, bitmap_area->Width(), bitmap_area->Height(), pSrc, |
| 496 | bitmap_area->left, bitmap_area->top); |
| 497 | return pDst; |
| 498 | } |
| 499 | |
| 500 | void RenderBitmap(CFX_RenderDevice* device, |
Dan Sinclair | 0b95042 | 2017-09-21 15:49:49 -0400 | [diff] [blame] | 501 | const RetainPtr<CFX_DIBitmap>& pSrc, |
rbpotter | cec0180 | 2017-04-17 09:10:21 -0700 | [diff] [blame] | 502 | const FX_RECT& mask_area) { |
| 503 | int size_x_bm = mask_area.Width(); |
| 504 | int size_y_bm = mask_area.Height(); |
| 505 | if (size_x_bm == 0 || size_y_bm == 0) |
| 506 | return; |
| 507 | |
| 508 | // Create a new bitmap from the old one |
Dan Sinclair | 0b95042 | 2017-09-21 15:49:49 -0400 | [diff] [blame] | 509 | RetainPtr<CFX_DIBitmap> pDst = pdfium::MakeRetain<CFX_DIBitmap>(); |
Nicolas Pena | d08667c | 2018-04-16 17:41:47 +0000 | [diff] [blame] | 510 | if (!pDst->Create(size_x_bm, size_y_bm, FXDIB_Rgb32)) |
| 511 | return; |
| 512 | |
rbpotter | cec0180 | 2017-04-17 09:10:21 -0700 | [diff] [blame] | 513 | pDst->Clear(0xffffffff); |
| 514 | pDst->CompositeBitmap(0, 0, size_x_bm, size_y_bm, pSrc, 0, 0, |
| 515 | FXDIB_BLEND_NORMAL, nullptr, false); |
| 516 | |
| 517 | if (device->GetDeviceCaps(FXDC_DEVICE_CLASS) == FXDC_PRINTER) { |
rbpotter | 8d7672e | 2017-08-16 16:45:44 -0700 | [diff] [blame] | 518 | device->StretchDIBits(pDst, mask_area.left, mask_area.top, size_x_bm, |
| 519 | size_y_bm); |
rbpotter | cec0180 | 2017-04-17 09:10:21 -0700 | [diff] [blame] | 520 | } else { |
| 521 | device->SetDIBits(pDst, mask_area.left, mask_area.top); |
| 522 | } |
| 523 | } |
| 524 | |
| 525 | } // namespace |
| 526 | |
Dan Sinclair | 00d2ad1 | 2017-08-10 14:13:02 -0400 | [diff] [blame] | 527 | FPDF_EXPORT void FPDF_CALLCONV FPDF_RenderPage(HDC dc, |
| 528 | FPDF_PAGE page, |
| 529 | int start_x, |
| 530 | int start_y, |
| 531 | int size_x, |
| 532 | int size_y, |
| 533 | int rotate, |
| 534 | int flags) { |
Tom Sepez | db0be96 | 2015-10-16 14:00:21 -0700 | [diff] [blame] | 535 | CPDF_Page* pPage = CPDFPageFromFPDFPage(page); |
Nico Weber | 9d8ec5a | 2015-08-04 13:00:21 -0700 | [diff] [blame] | 536 | if (!pPage) |
| 537 | return; |
rbpotter | cec0180 | 2017-04-17 09:10:21 -0700 | [diff] [blame] | 538 | pPage->SetRenderContext(pdfium::MakeUnique<CPDF_PageRenderContext>()); |
| 539 | CPDF_PageRenderContext* pContext = pPage->GetRenderContext(); |
John Abd-El-Malek | 3f3b45c | 2014-05-23 17:28:10 -0700 | [diff] [blame] | 540 | |
Dan Sinclair | 0b95042 | 2017-09-21 15:49:49 -0400 | [diff] [blame] | 541 | RetainPtr<CFX_DIBitmap> pBitmap; |
rbpotter | cec0180 | 2017-04-17 09:10:21 -0700 | [diff] [blame] | 542 | // Don't render the full page to bitmap for a mask unless there are a lot |
| 543 | // of masks. Full page bitmaps result in large spool sizes, so they should |
| 544 | // only be used when necessary. For large numbers of masks, rendering each |
| 545 | // individually is inefficient and unlikely to significantly improve spool |
rbpotter | 78b334a | 2017-10-25 11:58:41 -0700 | [diff] [blame] | 546 | // size. TODO (rbpotter): Find out why this still breaks printing for some |
| 547 | // PDFs (see crbug.com/777837). |
| 548 | const bool bEnableImageMasks = false; |
| 549 | const bool bNewBitmap = pPage->BackgroundAlphaNeeded() || |
| 550 | (pPage->HasImageMask() && !bEnableImageMasks) || |
| 551 | pPage->GetMaskBoundingBoxes().size() > 100; |
rbpotter | cec0180 | 2017-04-17 09:10:21 -0700 | [diff] [blame] | 552 | const bool bHasMask = pPage->HasImageMask() && !bNewBitmap; |
| 553 | if (bNewBitmap || bHasMask) { |
Tom Sepez | f0799fe | 2017-03-28 09:31:32 -0700 | [diff] [blame] | 554 | pBitmap = pdfium::MakeRetain<CFX_DIBitmap>(); |
Nicolas Pena | d08667c | 2018-04-16 17:41:47 +0000 | [diff] [blame] | 555 | // Create will probably work fine even if it fails here: we will just attach |
| 556 | // a zero-sized bitmap to |pDevice|. |
Nico Weber | 9d8ec5a | 2015-08-04 13:00:21 -0700 | [diff] [blame] | 557 | pBitmap->Create(size_x, size_y, FXDIB_Argb); |
| 558 | pBitmap->Clear(0x00ffffff); |
Dan Sinclair | a5085d4 | 2017-05-11 16:26:50 -0400 | [diff] [blame] | 559 | CFX_DefaultRenderDevice* pDevice = new CFX_DefaultRenderDevice; |
tsepez | 36eb4bd | 2016-10-03 15:24:27 -0700 | [diff] [blame] | 560 | pContext->m_pDevice = pdfium::WrapUnique(pDevice); |
Tom Sepez | f0799fe | 2017-03-28 09:31:32 -0700 | [diff] [blame] | 561 | pDevice->Attach(pBitmap, false, nullptr, false); |
rbpotter | cec0180 | 2017-04-17 09:10:21 -0700 | [diff] [blame] | 562 | if (bHasMask) { |
| 563 | pContext->m_pOptions = pdfium::MakeUnique<CPDF_RenderOptions>(); |
Dan Sinclair | 921fe6b | 2017-10-05 11:14:12 -0400 | [diff] [blame] | 564 | uint32_t option_flags = pContext->m_pOptions->GetFlags(); |
| 565 | option_flags |= RENDER_BREAKFORMASKS; |
| 566 | pContext->m_pOptions->SetFlags(option_flags); |
rbpotter | cec0180 | 2017-04-17 09:10:21 -0700 | [diff] [blame] | 567 | } |
Jun Fang | 1aeeceb | 2015-12-29 10:27:44 +0800 | [diff] [blame] | 568 | } else { |
Dan Sinclair | a5085d4 | 2017-05-11 16:26:50 -0400 | [diff] [blame] | 569 | pContext->m_pDevice = pdfium::MakeUnique<CFX_WindowsRenderDevice>(dc); |
Jun Fang | 1aeeceb | 2015-12-29 10:27:44 +0800 | [diff] [blame] | 570 | } |
rbpotter | cec0180 | 2017-04-17 09:10:21 -0700 | [diff] [blame] | 571 | |
Nico Weber | 9d8ec5a | 2015-08-04 13:00:21 -0700 | [diff] [blame] | 572 | FPDF_RenderPage_Retail(pContext, page, start_x, start_y, size_x, size_y, |
tsepez | 4cf5515 | 2016-11-02 14:37:54 -0700 | [diff] [blame] | 573 | rotate, flags, true, nullptr); |
Bo Xu | d4e406e | 2014-08-13 11:03:19 -0700 | [diff] [blame] | 574 | |
rbpotter | cec0180 | 2017-04-17 09:10:21 -0700 | [diff] [blame] | 575 | if (bHasMask) { |
| 576 | // Finish rendering the page to bitmap and copy the correct segments |
| 577 | // of the page to individual image mask bitmaps. |
| 578 | const std::vector<CFX_FloatRect>& mask_boxes = |
| 579 | pPage->GetMaskBoundingBoxes(); |
| 580 | std::vector<FX_RECT> bitmap_areas(mask_boxes.size()); |
Dan Sinclair | 0b95042 | 2017-09-21 15:49:49 -0400 | [diff] [blame] | 581 | std::vector<RetainPtr<CFX_DIBitmap>> bitmaps(mask_boxes.size()); |
rbpotter | cec0180 | 2017-04-17 09:10:21 -0700 | [diff] [blame] | 582 | for (size_t i = 0; i < mask_boxes.size(); i++) { |
| 583 | bitmaps[i] = |
| 584 | GetMaskBitmap(pPage, start_x, start_y, size_x, size_y, rotate, |
| 585 | pBitmap, mask_boxes[i], &bitmap_areas[i]); |
| 586 | pContext->m_pRenderer->Continue(nullptr); |
| 587 | } |
| 588 | |
| 589 | // Reset rendering context |
| 590 | pPage->SetRenderContext(nullptr); |
| 591 | |
| 592 | // Begin rendering to the printer. Add flag to indicate the renderer should |
| 593 | // pause after each image mask. |
| 594 | pPage->SetRenderContext(pdfium::MakeUnique<CPDF_PageRenderContext>()); |
| 595 | pContext = pPage->GetRenderContext(); |
Dan Sinclair | a5085d4 | 2017-05-11 16:26:50 -0400 | [diff] [blame] | 596 | pContext->m_pDevice = pdfium::MakeUnique<CFX_WindowsRenderDevice>(dc); |
rbpotter | cec0180 | 2017-04-17 09:10:21 -0700 | [diff] [blame] | 597 | pContext->m_pOptions = pdfium::MakeUnique<CPDF_RenderOptions>(); |
Dan Sinclair | 921fe6b | 2017-10-05 11:14:12 -0400 | [diff] [blame] | 598 | |
| 599 | uint32_t option_flags = pContext->m_pOptions->GetFlags(); |
| 600 | option_flags |= RENDER_BREAKFORMASKS; |
| 601 | pContext->m_pOptions->SetFlags(option_flags); |
| 602 | |
rbpotter | cec0180 | 2017-04-17 09:10:21 -0700 | [diff] [blame] | 603 | FPDF_RenderPage_Retail(pContext, page, start_x, start_y, size_x, size_y, |
| 604 | rotate, flags, true, nullptr); |
| 605 | |
| 606 | // Render masks |
| 607 | for (size_t i = 0; i < mask_boxes.size(); i++) { |
| 608 | // Render the bitmap for the mask and free the bitmap. |
| 609 | if (bitmaps[i]) { // will be null if mask has zero area |
| 610 | RenderBitmap(pContext->m_pDevice.get(), bitmaps[i], bitmap_areas[i]); |
| 611 | } |
| 612 | // Render the next portion of page. |
| 613 | pContext->m_pRenderer->Continue(nullptr); |
| 614 | } |
| 615 | } else if (bNewBitmap) { |
Dan Sinclair | a5085d4 | 2017-05-11 16:26:50 -0400 | [diff] [blame] | 616 | CFX_WindowsRenderDevice WinDC(dc); |
Nicolas Pena | d08667c | 2018-04-16 17:41:47 +0000 | [diff] [blame] | 617 | bool bitsStretched = false; |
thestig | 84144e8 | 2016-09-27 15:06:01 -0700 | [diff] [blame] | 618 | if (WinDC.GetDeviceCaps(FXDC_DEVICE_CLASS) == FXDC_PRINTER) { |
Tom Sepez | f0799fe | 2017-03-28 09:31:32 -0700 | [diff] [blame] | 619 | auto pDst = pdfium::MakeRetain<CFX_DIBitmap>(); |
Nicolas Pena | d08667c | 2018-04-16 17:41:47 +0000 | [diff] [blame] | 620 | if (pDst->Create(size_x, size_y, FXDIB_Rgb32)) { |
| 621 | memset(pDst->GetBuffer(), -1, pBitmap->GetPitch() * size_y); |
| 622 | pDst->CompositeBitmap(0, 0, size_x, size_y, pBitmap, 0, 0, |
| 623 | FXDIB_BLEND_NORMAL, nullptr, false); |
| 624 | WinDC.StretchDIBits(pDst, 0, 0, size_x, size_y); |
| 625 | bitsStretched = true; |
| 626 | } |
Lei Zhang | 6d8b1c2 | 2015-06-19 17:26:17 -0700 | [diff] [blame] | 627 | } |
Nicolas Pena | d08667c | 2018-04-16 17:41:47 +0000 | [diff] [blame] | 628 | if (!bitsStretched) |
| 629 | WinDC.SetDIBits(pBitmap, 0, 0); |
Nico Weber | 9d8ec5a | 2015-08-04 13:00:21 -0700 | [diff] [blame] | 630 | } |
rbpotter | cec0180 | 2017-04-17 09:10:21 -0700 | [diff] [blame] | 631 | |
tsepez | e5cb0b1 | 2016-10-26 15:06:11 -0700 | [diff] [blame] | 632 | pPage->SetRenderContext(nullptr); |
Nico Weber | 9d8ec5a | 2015-08-04 13:00:21 -0700 | [diff] [blame] | 633 | } |
Lei Zhang | ae85f87 | 2016-02-19 14:57:07 -0800 | [diff] [blame] | 634 | #endif // defined(_WIN32) |
Nico Weber | 9d8ec5a | 2015-08-04 13:00:21 -0700 | [diff] [blame] | 635 | |
Dan Sinclair | 00d2ad1 | 2017-08-10 14:13:02 -0400 | [diff] [blame] | 636 | FPDF_EXPORT void FPDF_CALLCONV FPDF_RenderPageBitmap(FPDF_BITMAP bitmap, |
| 637 | FPDF_PAGE page, |
| 638 | int start_x, |
| 639 | int start_y, |
| 640 | int size_x, |
| 641 | int size_y, |
| 642 | int rotate, |
| 643 | int flags) { |
Tom Sepez | db0be96 | 2015-10-16 14:00:21 -0700 | [diff] [blame] | 644 | if (!bitmap) |
Nico Weber | 9d8ec5a | 2015-08-04 13:00:21 -0700 | [diff] [blame] | 645 | return; |
tsepez | 1e2c557 | 2016-05-25 14:58:09 -0700 | [diff] [blame] | 646 | |
Tom Sepez | db0be96 | 2015-10-16 14:00:21 -0700 | [diff] [blame] | 647 | CPDF_Page* pPage = CPDFPageFromFPDFPage(page); |
Nico Weber | 9d8ec5a | 2015-08-04 13:00:21 -0700 | [diff] [blame] | 648 | if (!pPage) |
| 649 | return; |
Nico Weber | 9d8ec5a | 2015-08-04 13:00:21 -0700 | [diff] [blame] | 650 | |
weili | 9f515bc | 2016-07-24 08:08:24 -0700 | [diff] [blame] | 651 | CPDF_PageRenderContext* pContext = new CPDF_PageRenderContext; |
tsepez | 36eb4bd | 2016-10-03 15:24:27 -0700 | [diff] [blame] | 652 | pPage->SetRenderContext(pdfium::WrapUnique(pContext)); |
Tom Sepez | f0799fe | 2017-03-28 09:31:32 -0700 | [diff] [blame] | 653 | |
Dan Sinclair | a5085d4 | 2017-05-11 16:26:50 -0400 | [diff] [blame] | 654 | CFX_DefaultRenderDevice* pDevice = new CFX_DefaultRenderDevice; |
weili | 9f515bc | 2016-07-24 08:08:24 -0700 | [diff] [blame] | 655 | pContext->m_pDevice.reset(pDevice); |
dsinclair | 31b08d4 | 2017-03-28 15:47:47 +0000 | [diff] [blame] | 656 | |
Tom Sepez | 525147a | 2018-05-03 17:19:53 +0000 | [diff] [blame] | 657 | RetainPtr<CFX_DIBitmap> pBitmap(CFXDIBitmapFromFPDFBitmap(bitmap)); |
Tom Sepez | f0799fe | 2017-03-28 09:31:32 -0700 | [diff] [blame] | 658 | pDevice->Attach(pBitmap, !!(flags & FPDF_REVERSE_BYTE_ORDER), nullptr, false); |
Nico Weber | 9d8ec5a | 2015-08-04 13:00:21 -0700 | [diff] [blame] | 659 | FPDF_RenderPage_Retail(pContext, page, start_x, start_y, size_x, size_y, |
tsepez | 4cf5515 | 2016-11-02 14:37:54 -0700 | [diff] [blame] | 660 | rotate, flags, true, nullptr); |
Nico Weber | 9d8ec5a | 2015-08-04 13:00:21 -0700 | [diff] [blame] | 661 | |
caryclark | 687fbde | 2016-11-22 12:44:25 -0800 | [diff] [blame] | 662 | #ifdef _SKIA_SUPPORT_PATHS_ |
Cary Clark | 364d18b | 2017-07-25 10:39:10 -0400 | [diff] [blame] | 663 | pDevice->Flush(true); |
caryclark | 687fbde | 2016-11-22 12:44:25 -0800 | [diff] [blame] | 664 | pBitmap->UnPreMultiply(); |
| 665 | #endif |
tsepez | e5cb0b1 | 2016-10-26 15:06:11 -0700 | [diff] [blame] | 666 | pPage->SetRenderContext(nullptr); |
John Abd-El-Malek | 3f3b45c | 2014-05-23 17:28:10 -0700 | [diff] [blame] | 667 | } |
| 668 | |
Dan Sinclair | 00d2ad1 | 2017-08-10 14:13:02 -0400 | [diff] [blame] | 669 | FPDF_EXPORT void FPDF_CALLCONV |
| 670 | FPDF_RenderPageBitmapWithMatrix(FPDF_BITMAP bitmap, |
| 671 | FPDF_PAGE page, |
| 672 | const FS_MATRIX* matrix, |
| 673 | const FS_RECTF* clipping, |
| 674 | int flags) { |
thestig | a78ba60 | 2016-11-23 15:25:48 -0800 | [diff] [blame] | 675 | if (!bitmap) |
| 676 | return; |
| 677 | |
| 678 | CPDF_Page* pPage = CPDFPageFromFPDFPage(page); |
| 679 | if (!pPage) |
| 680 | return; |
| 681 | |
Tom Sepez | 525147a | 2018-05-03 17:19:53 +0000 | [diff] [blame] | 682 | auto pOwnedContext = pdfium::MakeUnique<CPDF_PageRenderContext>(); |
| 683 | CPDF_PageRenderContext* pContext = pOwnedContext.get(); |
| 684 | pPage->SetRenderContext(std::move(pOwnedContext)); |
Tom Sepez | f0799fe | 2017-03-28 09:31:32 -0700 | [diff] [blame] | 685 | |
Tom Sepez | 525147a | 2018-05-03 17:19:53 +0000 | [diff] [blame] | 686 | auto pOwnedDevice = pdfium::MakeUnique<CFX_DefaultRenderDevice>(); |
| 687 | CFX_DefaultRenderDevice* pDevice = pOwnedDevice.get(); |
| 688 | pContext->m_pDevice = std::move(pOwnedDevice); |
Tom Sepez | f0799fe | 2017-03-28 09:31:32 -0700 | [diff] [blame] | 689 | |
Tom Sepez | 525147a | 2018-05-03 17:19:53 +0000 | [diff] [blame] | 690 | RetainPtr<CFX_DIBitmap> pBitmap(CFXDIBitmapFromFPDFBitmap(bitmap)); |
thestig | a78ba60 | 2016-11-23 15:25:48 -0800 | [diff] [blame] | 691 | pDevice->Attach(pBitmap, !!(flags & FPDF_REVERSE_BYTE_ORDER), nullptr, false); |
| 692 | |
thestig | a78ba60 | 2016-11-23 15:25:48 -0800 | [diff] [blame] | 693 | CFX_FloatRect clipping_rect; |
Lei Zhang | 367e7de | 2017-10-31 13:32:17 +0000 | [diff] [blame] | 694 | if (clipping) |
| 695 | clipping_rect = CFXFloatRectFromFSRECTF(*clipping); |
Nicolas Pena | 60bde10 | 2017-07-26 13:50:12 -0400 | [diff] [blame] | 696 | FX_RECT clip_rect = clipping_rect.ToFxRect(); |
Henrique Nakashima | 2914b6f | 2018-01-17 20:00:37 +0000 | [diff] [blame] | 697 | |
Lei Zhang | c4242b2 | 2018-04-12 15:50:49 +0000 | [diff] [blame] | 698 | const FX_RECT rect(0, 0, pPage->GetPageWidth(), pPage->GetPageHeight()); |
| 699 | CFX_Matrix transform_matrix = pPage->GetDisplayMatrix(rect, 0); |
Henrique Nakashima | 2914b6f | 2018-01-17 20:00:37 +0000 | [diff] [blame] | 700 | if (matrix) { |
| 701 | transform_matrix.Concat(CFX_Matrix(matrix->a, matrix->b, matrix->c, |
| 702 | matrix->d, matrix->e, matrix->f)); |
| 703 | } |
| 704 | RenderPageImpl(pContext, pPage, transform_matrix, clip_rect, flags, true, |
| 705 | nullptr); |
thestig | a78ba60 | 2016-11-23 15:25:48 -0800 | [diff] [blame] | 706 | |
| 707 | pPage->SetRenderContext(nullptr); |
| 708 | } |
| 709 | |
Cary Clark | 399be5b | 2016-03-14 16:51:29 -0400 | [diff] [blame] | 710 | #ifdef _SKIA_SUPPORT_ |
Dan Sinclair | 00d2ad1 | 2017-08-10 14:13:02 -0400 | [diff] [blame] | 711 | FPDF_EXPORT FPDF_RECORDER FPDF_CALLCONV FPDF_RenderPageSkp(FPDF_PAGE page, |
| 712 | int size_x, |
| 713 | int size_y) { |
Cary Clark | 399be5b | 2016-03-14 16:51:29 -0400 | [diff] [blame] | 714 | CPDF_Page* pPage = CPDFPageFromFPDFPage(page); |
| 715 | if (!pPage) |
| 716 | return nullptr; |
tsepez | 1e2c557 | 2016-05-25 14:58:09 -0700 | [diff] [blame] | 717 | |
weili | 9f515bc | 2016-07-24 08:08:24 -0700 | [diff] [blame] | 718 | CPDF_PageRenderContext* pContext = new CPDF_PageRenderContext; |
tsepez | 36eb4bd | 2016-10-03 15:24:27 -0700 | [diff] [blame] | 719 | pPage->SetRenderContext(pdfium::WrapUnique(pContext)); |
Dan Sinclair | a5085d4 | 2017-05-11 16:26:50 -0400 | [diff] [blame] | 720 | CFX_DefaultRenderDevice* skDevice = new CFX_DefaultRenderDevice; |
Cary Clark | 399be5b | 2016-03-14 16:51:29 -0400 | [diff] [blame] | 721 | FPDF_RECORDER recorder = skDevice->CreateRecorder(size_x, size_y); |
weili | 9f515bc | 2016-07-24 08:08:24 -0700 | [diff] [blame] | 722 | pContext->m_pDevice.reset(skDevice); |
tsepez | 4cf5515 | 2016-11-02 14:37:54 -0700 | [diff] [blame] | 723 | FPDF_RenderPage_Retail(pContext, page, 0, 0, size_x, size_y, 0, 0, true, |
tsepez | 1e2c557 | 2016-05-25 14:58:09 -0700 | [diff] [blame] | 724 | nullptr); |
tsepez | e5cb0b1 | 2016-10-26 15:06:11 -0700 | [diff] [blame] | 725 | pPage->SetRenderContext(nullptr); |
Cary Clark | 399be5b | 2016-03-14 16:51:29 -0400 | [diff] [blame] | 726 | return recorder; |
| 727 | } |
| 728 | #endif |
| 729 | |
Dan Sinclair | 00d2ad1 | 2017-08-10 14:13:02 -0400 | [diff] [blame] | 730 | FPDF_EXPORT void FPDF_CALLCONV FPDF_ClosePage(FPDF_PAGE page) { |
Nico Weber | 9d8ec5a | 2015-08-04 13:00:21 -0700 | [diff] [blame] | 731 | if (!page) |
| 732 | return; |
Tom Sepez | 2aa4b2f | 2018-05-25 22:38:49 +0000 | [diff] [blame] | 733 | |
| 734 | // Take it back across the API and hold for duration of this function. |
Tom Sepez | 101535f | 2018-06-12 13:36:05 +0000 | [diff] [blame^] | 735 | RetainPtr<IPDF_Page> pPage; |
| 736 | pPage.Unleak(IPDFPageFromFPDFPage(page)); |
Tom Sepez | 2aa4b2f | 2018-05-25 22:38:49 +0000 | [diff] [blame] | 737 | |
Tom Sepez | 2491990 | 2018-06-04 17:47:28 +0000 | [diff] [blame] | 738 | #ifndef PDF_ENABLE_XFA |
Tom Sepez | 51da093 | 2015-11-25 16:05:49 -0800 | [diff] [blame] | 739 | CPDFSDK_PageView* pPageView = |
Tom Sepez | 101535f | 2018-06-12 13:36:05 +0000 | [diff] [blame^] | 740 | static_cast<CPDFSDK_PageView*>(pPage->AsPDFPage()->GetView()); |
Tom Sepez | 2aa4b2f | 2018-05-25 22:38:49 +0000 | [diff] [blame] | 741 | if (!pPageView || pPageView->IsBeingDestroyed()) |
| 742 | return; |
dsinclair | bcf4623 | 2016-10-03 13:02:27 -0700 | [diff] [blame] | 743 | |
Tom Sepez | 2aa4b2f | 2018-05-25 22:38:49 +0000 | [diff] [blame] | 744 | if (pPageView->IsLocked()) { |
| 745 | pPageView->TakePageOwnership(); |
| 746 | return; |
Tom Sepez | 51da093 | 2015-11-25 16:05:49 -0800 | [diff] [blame] | 747 | } |
Tom Sepez | 2aa4b2f | 2018-05-25 22:38:49 +0000 | [diff] [blame] | 748 | |
| 749 | // This will delete the |pPageView| object. We must cleanup the PageView |
| 750 | // first because it will attempt to reset the View on the |pPage| during |
| 751 | // destruction. |
| 752 | pPageView->GetFormFillEnv()->RemovePageView(pPage.Get()); |
Tom Sepez | 2491990 | 2018-06-04 17:47:28 +0000 | [diff] [blame] | 753 | #endif // PDF_ENABLE_XFA |
John Abd-El-Malek | 3f3b45c | 2014-05-23 17:28:10 -0700 | [diff] [blame] | 754 | } |
| 755 | |
Dan Sinclair | 00d2ad1 | 2017-08-10 14:13:02 -0400 | [diff] [blame] | 756 | FPDF_EXPORT void FPDF_CALLCONV FPDF_CloseDocument(FPDF_DOCUMENT document) { |
Tom Sepez | 2d11d72 | 2018-05-31 23:38:32 +0000 | [diff] [blame] | 757 | // Take it back across the API and throw it away, |
| 758 | std::unique_ptr<CPDF_Document>(CPDFDocumentFromFPDFDocument(document)); |
John Abd-El-Malek | 3f3b45c | 2014-05-23 17:28:10 -0700 | [diff] [blame] | 759 | } |
| 760 | |
Dan Sinclair | 00d2ad1 | 2017-08-10 14:13:02 -0400 | [diff] [blame] | 761 | FPDF_EXPORT unsigned long FPDF_CALLCONV FPDF_GetLastError() { |
Nico Weber | 9d8ec5a | 2015-08-04 13:00:21 -0700 | [diff] [blame] | 762 | return GetLastError(); |
John Abd-El-Malek | 3f3b45c | 2014-05-23 17:28:10 -0700 | [diff] [blame] | 763 | } |
| 764 | |
Lei Zhang | 822886b | 2018-04-12 17:24:45 +0000 | [diff] [blame] | 765 | FPDF_EXPORT FPDF_BOOL FPDF_CALLCONV FPDF_DeviceToPage(FPDF_PAGE page, |
| 766 | int start_x, |
| 767 | int start_y, |
| 768 | int size_x, |
| 769 | int size_y, |
| 770 | int rotate, |
| 771 | int device_x, |
| 772 | int device_y, |
| 773 | double* page_x, |
| 774 | double* page_y) { |
Lei Zhang | 412e908 | 2015-12-14 18:34:00 -0800 | [diff] [blame] | 775 | if (!page || !page_x || !page_y) |
Lei Zhang | 822886b | 2018-04-12 17:24:45 +0000 | [diff] [blame] | 776 | return false; |
Lei Zhang | a105fa1 | 2018-04-12 16:23:01 +0000 | [diff] [blame] | 777 | |
Tom Sepez | 101535f | 2018-06-12 13:36:05 +0000 | [diff] [blame^] | 778 | IPDF_Page* pPage = IPDFPageFromFPDFPage(page); |
Lei Zhang | c4242b2 | 2018-04-12 15:50:49 +0000 | [diff] [blame] | 779 | const FX_RECT rect(start_x, start_y, start_x + size_x, start_y + size_y); |
Lei Zhang | 822886b | 2018-04-12 17:24:45 +0000 | [diff] [blame] | 780 | Optional<CFX_PointF> pos = |
| 781 | pPage->DeviceToPage(rect, rotate, CFX_PointF(device_x, device_y)); |
| 782 | if (!pos) |
| 783 | return false; |
| 784 | |
| 785 | *page_x = pos->x; |
| 786 | *page_y = pos->y; |
| 787 | return true; |
John Abd-El-Malek | 3f3b45c | 2014-05-23 17:28:10 -0700 | [diff] [blame] | 788 | } |
| 789 | |
Lei Zhang | 822886b | 2018-04-12 17:24:45 +0000 | [diff] [blame] | 790 | FPDF_EXPORT FPDF_BOOL FPDF_CALLCONV FPDF_PageToDevice(FPDF_PAGE page, |
| 791 | int start_x, |
| 792 | int start_y, |
| 793 | int size_x, |
| 794 | int size_y, |
| 795 | int rotate, |
| 796 | double page_x, |
| 797 | double page_y, |
| 798 | int* device_x, |
| 799 | int* device_y) { |
Lei Zhang | a105fa1 | 2018-04-12 16:23:01 +0000 | [diff] [blame] | 800 | if (!page || !device_x || !device_y) |
Lei Zhang | 822886b | 2018-04-12 17:24:45 +0000 | [diff] [blame] | 801 | return false; |
Lei Zhang | a105fa1 | 2018-04-12 16:23:01 +0000 | [diff] [blame] | 802 | |
Tom Sepez | 101535f | 2018-06-12 13:36:05 +0000 | [diff] [blame^] | 803 | IPDF_Page* pPage = IPDFPageFromFPDFPage(page); |
Lei Zhang | c4242b2 | 2018-04-12 15:50:49 +0000 | [diff] [blame] | 804 | const FX_RECT rect(start_x, start_y, start_x + size_x, start_y + size_y); |
Lei Zhang | a8db06a | 2018-04-12 17:53:15 +0000 | [diff] [blame] | 805 | CFX_PointF page_point(static_cast<float>(page_x), static_cast<float>(page_y)); |
| 806 | Optional<CFX_PointF> pos = pPage->PageToDevice(rect, rotate, page_point); |
Lei Zhang | 822886b | 2018-04-12 17:24:45 +0000 | [diff] [blame] | 807 | if (!pos) |
| 808 | return false; |
| 809 | |
| 810 | *device_x = FXSYS_round(pos->x); |
| 811 | *device_y = FXSYS_round(pos->y); |
| 812 | return true; |
John Abd-El-Malek | 3f3b45c | 2014-05-23 17:28:10 -0700 | [diff] [blame] | 813 | } |
| 814 | |
Dan Sinclair | 00d2ad1 | 2017-08-10 14:13:02 -0400 | [diff] [blame] | 815 | FPDF_EXPORT FPDF_BITMAP FPDF_CALLCONV FPDFBitmap_Create(int width, |
| 816 | int height, |
| 817 | int alpha) { |
Tom Sepez | f0799fe | 2017-03-28 09:31:32 -0700 | [diff] [blame] | 818 | auto pBitmap = pdfium::MakeRetain<CFX_DIBitmap>(); |
tsepez | 37b12ad | 2016-12-14 19:50:23 -0800 | [diff] [blame] | 819 | if (!pBitmap->Create(width, height, alpha ? FXDIB_Argb : FXDIB_Rgb32)) |
thestig | 1cd352e | 2016-06-07 17:53:06 -0700 | [diff] [blame] | 820 | return nullptr; |
tsepez | 37b12ad | 2016-12-14 19:50:23 -0800 | [diff] [blame] | 821 | |
Tom Sepez | 525147a | 2018-05-03 17:19:53 +0000 | [diff] [blame] | 822 | return FPDFBitmapFromCFXDIBitmap(pBitmap.Leak()); |
John Abd-El-Malek | 3f3b45c | 2014-05-23 17:28:10 -0700 | [diff] [blame] | 823 | } |
| 824 | |
Dan Sinclair | 00d2ad1 | 2017-08-10 14:13:02 -0400 | [diff] [blame] | 825 | FPDF_EXPORT FPDF_BITMAP FPDF_CALLCONV FPDFBitmap_CreateEx(int width, |
| 826 | int height, |
| 827 | int format, |
| 828 | void* first_scan, |
| 829 | int stride) { |
Nico Weber | 9d8ec5a | 2015-08-04 13:00:21 -0700 | [diff] [blame] | 830 | FXDIB_Format fx_format; |
| 831 | switch (format) { |
| 832 | case FPDFBitmap_Gray: |
| 833 | fx_format = FXDIB_8bppRgb; |
| 834 | break; |
| 835 | case FPDFBitmap_BGR: |
| 836 | fx_format = FXDIB_Rgb; |
| 837 | break; |
| 838 | case FPDFBitmap_BGRx: |
| 839 | fx_format = FXDIB_Rgb32; |
| 840 | break; |
| 841 | case FPDFBitmap_BGRA: |
| 842 | fx_format = FXDIB_Argb; |
| 843 | break; |
| 844 | default: |
thestig | 1cd352e | 2016-06-07 17:53:06 -0700 | [diff] [blame] | 845 | return nullptr; |
Nico Weber | 9d8ec5a | 2015-08-04 13:00:21 -0700 | [diff] [blame] | 846 | } |
Tom Sepez | e7f4d33 | 2018-05-03 20:27:05 +0000 | [diff] [blame] | 847 | |
| 848 | // Ensure external memory is good at least for the duration of this call. |
| 849 | UnownedPtr<uint8_t> pChecker(static_cast<uint8_t*>(first_scan)); |
Tom Sepez | f0799fe | 2017-03-28 09:31:32 -0700 | [diff] [blame] | 850 | auto pBitmap = pdfium::MakeRetain<CFX_DIBitmap>(); |
Tom Sepez | e7f4d33 | 2018-05-03 20:27:05 +0000 | [diff] [blame] | 851 | if (!pBitmap->Create(width, height, fx_format, pChecker.Get(), stride)) |
Nicolas Pena | d08667c | 2018-04-16 17:41:47 +0000 | [diff] [blame] | 852 | return nullptr; |
Tom Sepez | e7f4d33 | 2018-05-03 20:27:05 +0000 | [diff] [blame] | 853 | |
Tom Sepez | 525147a | 2018-05-03 17:19:53 +0000 | [diff] [blame] | 854 | return FPDFBitmapFromCFXDIBitmap(pBitmap.Leak()); |
John Abd-El-Malek | 3f3b45c | 2014-05-23 17:28:10 -0700 | [diff] [blame] | 855 | } |
| 856 | |
Dan Sinclair | 00d2ad1 | 2017-08-10 14:13:02 -0400 | [diff] [blame] | 857 | FPDF_EXPORT int FPDF_CALLCONV FPDFBitmap_GetFormat(FPDF_BITMAP bitmap) { |
Jane Liu | 28fb7ba | 2017-08-02 21:45:57 -0400 | [diff] [blame] | 858 | if (!bitmap) |
| 859 | return FPDFBitmap_Unknown; |
| 860 | |
Tom Sepez | 525147a | 2018-05-03 17:19:53 +0000 | [diff] [blame] | 861 | FXDIB_Format format = CFXDIBitmapFromFPDFBitmap(bitmap)->GetFormat(); |
Jane Liu | 28fb7ba | 2017-08-02 21:45:57 -0400 | [diff] [blame] | 862 | switch (format) { |
| 863 | case FXDIB_8bppRgb: |
| 864 | case FXDIB_8bppMask: |
| 865 | return FPDFBitmap_Gray; |
| 866 | case FXDIB_Rgb: |
| 867 | return FPDFBitmap_BGR; |
| 868 | case FXDIB_Rgb32: |
| 869 | return FPDFBitmap_BGRx; |
| 870 | case FXDIB_Argb: |
| 871 | return FPDFBitmap_BGRA; |
| 872 | default: |
| 873 | return FPDFBitmap_Unknown; |
| 874 | } |
| 875 | } |
| 876 | |
Dan Sinclair | 00d2ad1 | 2017-08-10 14:13:02 -0400 | [diff] [blame] | 877 | FPDF_EXPORT void FPDF_CALLCONV FPDFBitmap_FillRect(FPDF_BITMAP bitmap, |
| 878 | int left, |
| 879 | int top, |
| 880 | int width, |
| 881 | int height, |
| 882 | FPDF_DWORD color) { |
Lei Zhang | 412e908 | 2015-12-14 18:34:00 -0800 | [diff] [blame] | 883 | if (!bitmap) |
Nico Weber | 9d8ec5a | 2015-08-04 13:00:21 -0700 | [diff] [blame] | 884 | return; |
thestig | befa450 | 2016-05-26 20:15:19 -0700 | [diff] [blame] | 885 | |
Dan Sinclair | a5085d4 | 2017-05-11 16:26:50 -0400 | [diff] [blame] | 886 | CFX_DefaultRenderDevice device; |
Tom Sepez | 525147a | 2018-05-03 17:19:53 +0000 | [diff] [blame] | 887 | RetainPtr<CFX_DIBitmap> pBitmap(CFXDIBitmapFromFPDFBitmap(bitmap)); |
thestig | befa450 | 2016-05-26 20:15:19 -0700 | [diff] [blame] | 888 | device.Attach(pBitmap, false, nullptr, false); |
| 889 | if (!pBitmap->HasAlpha()) |
Nico Weber | 9d8ec5a | 2015-08-04 13:00:21 -0700 | [diff] [blame] | 890 | color |= 0xFF000000; |
Lei Zhang | e5c3ebd | 2018-04-10 19:02:15 +0000 | [diff] [blame] | 891 | device.FillRect(FX_RECT(left, top, left + width, top + height), color); |
John Abd-El-Malek | 3f3b45c | 2014-05-23 17:28:10 -0700 | [diff] [blame] | 892 | } |
| 893 | |
Dan Sinclair | 00d2ad1 | 2017-08-10 14:13:02 -0400 | [diff] [blame] | 894 | FPDF_EXPORT void* FPDF_CALLCONV FPDFBitmap_GetBuffer(FPDF_BITMAP bitmap) { |
Tom Sepez | 525147a | 2018-05-03 17:19:53 +0000 | [diff] [blame] | 895 | return bitmap ? CFXDIBitmapFromFPDFBitmap(bitmap)->GetBuffer() : nullptr; |
Bo Xu | 9114e83 | 2014-07-14 13:22:47 -0700 | [diff] [blame] | 896 | } |
| 897 | |
Dan Sinclair | 00d2ad1 | 2017-08-10 14:13:02 -0400 | [diff] [blame] | 898 | FPDF_EXPORT int FPDF_CALLCONV FPDFBitmap_GetWidth(FPDF_BITMAP bitmap) { |
Tom Sepez | 525147a | 2018-05-03 17:19:53 +0000 | [diff] [blame] | 899 | return bitmap ? CFXDIBitmapFromFPDFBitmap(bitmap)->GetWidth() : 0; |
Bo Xu | 9114e83 | 2014-07-14 13:22:47 -0700 | [diff] [blame] | 900 | } |
| 901 | |
Dan Sinclair | 00d2ad1 | 2017-08-10 14:13:02 -0400 | [diff] [blame] | 902 | FPDF_EXPORT int FPDF_CALLCONV FPDFBitmap_GetHeight(FPDF_BITMAP bitmap) { |
Tom Sepez | 525147a | 2018-05-03 17:19:53 +0000 | [diff] [blame] | 903 | return bitmap ? CFXDIBitmapFromFPDFBitmap(bitmap)->GetHeight() : 0; |
Nico Weber | 9d8ec5a | 2015-08-04 13:00:21 -0700 | [diff] [blame] | 904 | } |
| 905 | |
Dan Sinclair | 00d2ad1 | 2017-08-10 14:13:02 -0400 | [diff] [blame] | 906 | FPDF_EXPORT int FPDF_CALLCONV FPDFBitmap_GetStride(FPDF_BITMAP bitmap) { |
Tom Sepez | 525147a | 2018-05-03 17:19:53 +0000 | [diff] [blame] | 907 | return bitmap ? CFXDIBitmapFromFPDFBitmap(bitmap)->GetPitch() : 0; |
Nico Weber | 9d8ec5a | 2015-08-04 13:00:21 -0700 | [diff] [blame] | 908 | } |
| 909 | |
Dan Sinclair | 00d2ad1 | 2017-08-10 14:13:02 -0400 | [diff] [blame] | 910 | FPDF_EXPORT void FPDF_CALLCONV FPDFBitmap_Destroy(FPDF_BITMAP bitmap) { |
Dan Sinclair | 0b95042 | 2017-09-21 15:49:49 -0400 | [diff] [blame] | 911 | RetainPtr<CFX_DIBitmap> destroyer; |
Tom Sepez | 525147a | 2018-05-03 17:19:53 +0000 | [diff] [blame] | 912 | destroyer.Unleak(CFXDIBitmapFromFPDFBitmap(bitmap)); |
Nico Weber | 9d8ec5a | 2015-08-04 13:00:21 -0700 | [diff] [blame] | 913 | } |
| 914 | |
weili | 9f515bc | 2016-07-24 08:08:24 -0700 | [diff] [blame] | 915 | void FPDF_RenderPage_Retail(CPDF_PageRenderContext* pContext, |
Nico Weber | 9d8ec5a | 2015-08-04 13:00:21 -0700 | [diff] [blame] | 916 | FPDF_PAGE page, |
| 917 | int start_x, |
| 918 | int start_y, |
| 919 | int size_x, |
| 920 | int size_y, |
| 921 | int rotate, |
| 922 | int flags, |
tsepez | 4cf5515 | 2016-11-02 14:37:54 -0700 | [diff] [blame] | 923 | bool bNeedToRestore, |
Dan Sinclair | 7d12532 | 2018-03-28 18:49:34 +0000 | [diff] [blame] | 924 | IPDFSDK_PauseAdapter* pause) { |
Tom Sepez | db0be96 | 2015-10-16 14:00:21 -0700 | [diff] [blame] | 925 | CPDF_Page* pPage = CPDFPageFromFPDFPage(page); |
| 926 | if (!pPage) |
Nico Weber | 9d8ec5a | 2015-08-04 13:00:21 -0700 | [diff] [blame] | 927 | return; |
| 928 | |
Lei Zhang | c4242b2 | 2018-04-12 15:50:49 +0000 | [diff] [blame] | 929 | const FX_RECT rect(start_x, start_y, start_x + size_x, start_y + size_y); |
| 930 | RenderPageImpl(pContext, pPage, pPage->GetDisplayMatrix(rect, rotate), rect, |
| 931 | flags, bNeedToRestore, pause); |
Nico Weber | 9d8ec5a | 2015-08-04 13:00:21 -0700 | [diff] [blame] | 932 | } |
| 933 | |
Dan Sinclair | 00d2ad1 | 2017-08-10 14:13:02 -0400 | [diff] [blame] | 934 | FPDF_EXPORT int FPDF_CALLCONV FPDF_GetPageSizeByIndex(FPDF_DOCUMENT document, |
| 935 | int page_index, |
| 936 | double* width, |
| 937 | double* height) { |
Tom Sepez | fe06d51 | 2018-05-01 17:25:25 +0000 | [diff] [blame] | 938 | auto* pDoc = CPDFDocumentFromFPDFDocument(document); |
Tom Sepez | 540c436 | 2015-11-24 13:33:57 -0800 | [diff] [blame] | 939 | if (!pDoc) |
tsepez | 4cf5515 | 2016-11-02 14:37:54 -0700 | [diff] [blame] | 940 | return false; |
Nico Weber | 9d8ec5a | 2015-08-04 13:00:21 -0700 | [diff] [blame] | 941 | |
Tom Sepez | 40e9ff3 | 2015-11-30 12:39:54 -0800 | [diff] [blame] | 942 | #ifdef PDF_ENABLE_XFA |
Tom Sepez | fe06d51 | 2018-05-01 17:25:25 +0000 | [diff] [blame] | 943 | if (page_index < 0 || page_index >= FPDF_GetPageCount(document)) |
tsepez | 4cf5515 | 2016-11-02 14:37:54 -0700 | [diff] [blame] | 944 | return false; |
Tom Sepez | 3f3c39d | 2018-05-01 17:46:34 +0000 | [diff] [blame] | 945 | |
| 946 | auto* pContext = static_cast<CPDFXFA_Context*>(pDoc->GetExtension()); |
| 947 | if (pContext) { |
| 948 | RetainPtr<CPDFXFA_Page> pPage = pContext->GetXFAPage(page_index); |
| 949 | if (!pPage) |
| 950 | return false; |
| 951 | |
| 952 | *width = pPage->GetPageWidth(); |
| 953 | *height = pPage->GetPageHeight(); |
| 954 | return true; |
| 955 | } |
| 956 | #endif // PDF_ENABLE_XFA |
| 957 | |
Tom Sepez | 967aa07 | 2018-05-08 13:40:20 +0000 | [diff] [blame] | 958 | CPDF_Dictionary* pDict = pDoc->GetPageDictionary(page_index); |
Tom Sepez | 40e9ff3 | 2015-11-30 12:39:54 -0800 | [diff] [blame] | 959 | if (!pDict) |
tsepez | 4cf5515 | 2016-11-02 14:37:54 -0700 | [diff] [blame] | 960 | return false; |
thestig | 5cc2465 | 2016-04-26 11:46:02 -0700 | [diff] [blame] | 961 | |
Tom Sepez | f06ed6d | 2018-06-04 18:26:07 +0000 | [diff] [blame] | 962 | auto page = pdfium::MakeRetain<CPDF_Page>(pDoc, pDict, true); |
Tom Sepez | 2aa4b2f | 2018-05-25 22:38:49 +0000 | [diff] [blame] | 963 | *width = page->GetPageWidth(); |
| 964 | *height = page->GetPageHeight(); |
tsepez | 4cf5515 | 2016-11-02 14:37:54 -0700 | [diff] [blame] | 965 | return true; |
Nico Weber | 9d8ec5a | 2015-08-04 13:00:21 -0700 | [diff] [blame] | 966 | } |
| 967 | |
Dan Sinclair | 00d2ad1 | 2017-08-10 14:13:02 -0400 | [diff] [blame] | 968 | FPDF_EXPORT FPDF_BOOL FPDF_CALLCONV |
Nico Weber | 9d8ec5a | 2015-08-04 13:00:21 -0700 | [diff] [blame] | 969 | FPDF_VIEWERREF_GetPrintScaling(FPDF_DOCUMENT document) { |
Lei Zhang | 55bbb0a | 2018-05-08 19:26:37 +0000 | [diff] [blame] | 970 | const CPDF_Document* pDoc = CPDFDocumentFromFPDFDocument(document); |
Nico Weber | 9d8ec5a | 2015-08-04 13:00:21 -0700 | [diff] [blame] | 971 | if (!pDoc) |
tsepez | 4cf5515 | 2016-11-02 14:37:54 -0700 | [diff] [blame] | 972 | return true; |
Tom Sepez | 471a103 | 2015-10-15 16:17:18 -0700 | [diff] [blame] | 973 | CPDF_ViewerPreferences viewRef(pDoc); |
Nico Weber | 9d8ec5a | 2015-08-04 13:00:21 -0700 | [diff] [blame] | 974 | return viewRef.PrintScaling(); |
| 975 | } |
| 976 | |
Dan Sinclair | 00d2ad1 | 2017-08-10 14:13:02 -0400 | [diff] [blame] | 977 | FPDF_EXPORT int FPDF_CALLCONV |
| 978 | FPDF_VIEWERREF_GetNumCopies(FPDF_DOCUMENT document) { |
Lei Zhang | 55bbb0a | 2018-05-08 19:26:37 +0000 | [diff] [blame] | 979 | const CPDF_Document* pDoc = CPDFDocumentFromFPDFDocument(document); |
Nico Weber | 9d8ec5a | 2015-08-04 13:00:21 -0700 | [diff] [blame] | 980 | if (!pDoc) |
| 981 | return 1; |
| 982 | CPDF_ViewerPreferences viewRef(pDoc); |
| 983 | return viewRef.NumCopies(); |
| 984 | } |
| 985 | |
Dan Sinclair | 00d2ad1 | 2017-08-10 14:13:02 -0400 | [diff] [blame] | 986 | FPDF_EXPORT FPDF_PAGERANGE FPDF_CALLCONV |
Nico Weber | 9d8ec5a | 2015-08-04 13:00:21 -0700 | [diff] [blame] | 987 | FPDF_VIEWERREF_GetPrintPageRange(FPDF_DOCUMENT document) { |
Lei Zhang | 55bbb0a | 2018-05-08 19:26:37 +0000 | [diff] [blame] | 988 | const CPDF_Document* pDoc = CPDFDocumentFromFPDFDocument(document); |
Nico Weber | 9d8ec5a | 2015-08-04 13:00:21 -0700 | [diff] [blame] | 989 | if (!pDoc) |
thestig | 1cd352e | 2016-06-07 17:53:06 -0700 | [diff] [blame] | 990 | return nullptr; |
Nico Weber | 9d8ec5a | 2015-08-04 13:00:21 -0700 | [diff] [blame] | 991 | CPDF_ViewerPreferences viewRef(pDoc); |
Tom Sepez | 525147a | 2018-05-03 17:19:53 +0000 | [diff] [blame] | 992 | return FPDFPageRangeFromCPDFArray(viewRef.PrintPageRange()); |
Nico Weber | 9d8ec5a | 2015-08-04 13:00:21 -0700 | [diff] [blame] | 993 | } |
| 994 | |
Lei Zhang | 9c6204f | 2018-05-08 19:20:57 +0000 | [diff] [blame] | 995 | FPDF_EXPORT size_t FPDF_CALLCONV |
| 996 | FPDF_VIEWERREF_GetPrintPageRangeCount(FPDF_PAGERANGE pagerange) { |
| 997 | const CPDF_Array* pArray = CPDFArrayFromFPDFPageRange(pagerange); |
| 998 | return pArray ? pArray->GetCount() : 0; |
| 999 | } |
| 1000 | |
| 1001 | FPDF_EXPORT int FPDF_CALLCONV |
| 1002 | FPDF_VIEWERREF_GetPrintPageRangeElement(FPDF_PAGERANGE pagerange, |
| 1003 | size_t index) { |
| 1004 | const CPDF_Array* pArray = CPDFArrayFromFPDFPageRange(pagerange); |
| 1005 | if (!pArray || index >= pArray->GetCount()) |
| 1006 | return -1; |
| 1007 | return pArray->GetIntegerAt(index); |
| 1008 | } |
| 1009 | |
Dan Sinclair | 00d2ad1 | 2017-08-10 14:13:02 -0400 | [diff] [blame] | 1010 | FPDF_EXPORT FPDF_DUPLEXTYPE FPDF_CALLCONV |
Nico Weber | 9d8ec5a | 2015-08-04 13:00:21 -0700 | [diff] [blame] | 1011 | FPDF_VIEWERREF_GetDuplex(FPDF_DOCUMENT document) { |
Lei Zhang | 55bbb0a | 2018-05-08 19:26:37 +0000 | [diff] [blame] | 1012 | const CPDF_Document* pDoc = CPDFDocumentFromFPDFDocument(document); |
Nico Weber | 9d8ec5a | 2015-08-04 13:00:21 -0700 | [diff] [blame] | 1013 | if (!pDoc) |
Bo Xu | 9114e83 | 2014-07-14 13:22:47 -0700 | [diff] [blame] | 1014 | return DuplexUndefined; |
Nico Weber | 9d8ec5a | 2015-08-04 13:00:21 -0700 | [diff] [blame] | 1015 | CPDF_ViewerPreferences viewRef(pDoc); |
Ryan Harrison | 275e260 | 2017-09-18 14:23:18 -0400 | [diff] [blame] | 1016 | ByteString duplex = viewRef.Duplex(); |
Lei Zhang | d983b09 | 2015-12-14 16:58:33 -0800 | [diff] [blame] | 1017 | if ("Simplex" == duplex) |
Nico Weber | 9d8ec5a | 2015-08-04 13:00:21 -0700 | [diff] [blame] | 1018 | return Simplex; |
Lei Zhang | d983b09 | 2015-12-14 16:58:33 -0800 | [diff] [blame] | 1019 | if ("DuplexFlipShortEdge" == duplex) |
Nico Weber | 9d8ec5a | 2015-08-04 13:00:21 -0700 | [diff] [blame] | 1020 | return DuplexFlipShortEdge; |
Lei Zhang | d983b09 | 2015-12-14 16:58:33 -0800 | [diff] [blame] | 1021 | if ("DuplexFlipLongEdge" == duplex) |
Nico Weber | 9d8ec5a | 2015-08-04 13:00:21 -0700 | [diff] [blame] | 1022 | return DuplexFlipLongEdge; |
| 1023 | return DuplexUndefined; |
Bo Xu | 9114e83 | 2014-07-14 13:22:47 -0700 | [diff] [blame] | 1024 | } |
| 1025 | |
Dan Sinclair | 00d2ad1 | 2017-08-10 14:13:02 -0400 | [diff] [blame] | 1026 | FPDF_EXPORT unsigned long FPDF_CALLCONV |
| 1027 | FPDF_VIEWERREF_GetName(FPDF_DOCUMENT document, |
| 1028 | FPDF_BYTESTRING key, |
| 1029 | char* buffer, |
| 1030 | unsigned long length) { |
Lei Zhang | 55bbb0a | 2018-05-08 19:26:37 +0000 | [diff] [blame] | 1031 | const CPDF_Document* pDoc = CPDFDocumentFromFPDFDocument(document); |
thestig | 04bebfe | 2016-11-04 16:07:25 -0700 | [diff] [blame] | 1032 | if (!pDoc) |
| 1033 | return 0; |
| 1034 | |
| 1035 | CPDF_ViewerPreferences viewRef(pDoc); |
Lei Zhang | 55bbb0a | 2018-05-08 19:26:37 +0000 | [diff] [blame] | 1036 | Optional<ByteString> bsVal = viewRef.GenericName(key); |
| 1037 | if (!bsVal) |
thestig | 04bebfe | 2016-11-04 16:07:25 -0700 | [diff] [blame] | 1038 | return 0; |
| 1039 | |
Lei Zhang | 55bbb0a | 2018-05-08 19:26:37 +0000 | [diff] [blame] | 1040 | unsigned long dwStringLen = bsVal->GetLength() + 1; |
thestig | 04bebfe | 2016-11-04 16:07:25 -0700 | [diff] [blame] | 1041 | if (buffer && length >= dwStringLen) |
Lei Zhang | 55bbb0a | 2018-05-08 19:26:37 +0000 | [diff] [blame] | 1042 | memcpy(buffer, bsVal->c_str(), dwStringLen); |
thestig | 04bebfe | 2016-11-04 16:07:25 -0700 | [diff] [blame] | 1043 | return dwStringLen; |
| 1044 | } |
| 1045 | |
Dan Sinclair | 00d2ad1 | 2017-08-10 14:13:02 -0400 | [diff] [blame] | 1046 | FPDF_EXPORT FPDF_DWORD FPDF_CALLCONV |
| 1047 | FPDF_CountNamedDests(FPDF_DOCUMENT document) { |
Tom Sepez | 471a103 | 2015-10-15 16:17:18 -0700 | [diff] [blame] | 1048 | CPDF_Document* pDoc = CPDFDocumentFromFPDFDocument(document); |
| 1049 | if (!pDoc) |
Nico Weber | 9d8ec5a | 2015-08-04 13:00:21 -0700 | [diff] [blame] | 1050 | return 0; |
Bo Xu | 4d62b6b | 2015-01-10 22:52:59 -0800 | [diff] [blame] | 1051 | |
Lei Zhang | 0158106 | 2017-08-30 14:19:26 -0700 | [diff] [blame] | 1052 | const CPDF_Dictionary* pRoot = pDoc->GetRoot(); |
Nico Weber | 9d8ec5a | 2015-08-04 13:00:21 -0700 | [diff] [blame] | 1053 | if (!pRoot) |
| 1054 | return 0; |
Bo Xu | 4d62b6b | 2015-01-10 22:52:59 -0800 | [diff] [blame] | 1055 | |
Lei Zhang | d983b09 | 2015-12-14 16:58:33 -0800 | [diff] [blame] | 1056 | CPDF_NameTree nameTree(pDoc, "Dests"); |
Oliver Chang | 3f1c71f | 2016-01-11 08:45:31 -0800 | [diff] [blame] | 1057 | pdfium::base::CheckedNumeric<FPDF_DWORD> count = nameTree.GetCount(); |
Lei Zhang | 55bbb0a | 2018-05-08 19:26:37 +0000 | [diff] [blame] | 1058 | const CPDF_Dictionary* pDest = pRoot->GetDictFor("Dests"); |
Nico Weber | 9d8ec5a | 2015-08-04 13:00:21 -0700 | [diff] [blame] | 1059 | if (pDest) |
| 1060 | count += pDest->GetCount(); |
Oliver Chang | 3f1c71f | 2016-01-11 08:45:31 -0800 | [diff] [blame] | 1061 | |
| 1062 | if (!count.IsValid()) |
| 1063 | return 0; |
| 1064 | |
| 1065 | return count.ValueOrDie(); |
Nico Weber | 9d8ec5a | 2015-08-04 13:00:21 -0700 | [diff] [blame] | 1066 | } |
| 1067 | |
Dan Sinclair | 00d2ad1 | 2017-08-10 14:13:02 -0400 | [diff] [blame] | 1068 | FPDF_EXPORT FPDF_DEST FPDF_CALLCONV |
| 1069 | FPDF_GetNamedDestByName(FPDF_DOCUMENT document, FPDF_BYTESTRING name) { |
Nico Weber | 9d8ec5a | 2015-08-04 13:00:21 -0700 | [diff] [blame] | 1070 | if (!name || name[0] == 0) |
Tom Sepez | 471a103 | 2015-10-15 16:17:18 -0700 | [diff] [blame] | 1071 | return nullptr; |
Nico Weber | 9d8ec5a | 2015-08-04 13:00:21 -0700 | [diff] [blame] | 1072 | |
Tom Sepez | 471a103 | 2015-10-15 16:17:18 -0700 | [diff] [blame] | 1073 | CPDF_Document* pDoc = CPDFDocumentFromFPDFDocument(document); |
| 1074 | if (!pDoc) |
| 1075 | return nullptr; |
| 1076 | |
Lei Zhang | d983b09 | 2015-12-14 16:58:33 -0800 | [diff] [blame] | 1077 | CPDF_NameTree name_tree(pDoc, "Dests"); |
Tom Sepez | 525147a | 2018-05-03 17:19:53 +0000 | [diff] [blame] | 1078 | return FPDFDestFromCPDFArray( |
| 1079 | name_tree.LookupNamedDest(pDoc, PDF_DecodeText(ByteString(name)))); |
Nico Weber | 9d8ec5a | 2015-08-04 13:00:21 -0700 | [diff] [blame] | 1080 | } |
| 1081 | |
Tom Sepez | 51da093 | 2015-11-25 16:05:49 -0800 | [diff] [blame] | 1082 | #ifdef PDF_ENABLE_XFA |
Dan Sinclair | 00d2ad1 | 2017-08-10 14:13:02 -0400 | [diff] [blame] | 1083 | FPDF_EXPORT FPDF_RESULT FPDF_CALLCONV FPDF_BStr_Init(FPDF_BSTR* str) { |
Nico Weber | 9d8ec5a | 2015-08-04 13:00:21 -0700 | [diff] [blame] | 1084 | if (!str) |
| 1085 | return -1; |
| 1086 | |
Dan Sinclair | 1c5d0b4 | 2017-04-03 15:05:11 -0400 | [diff] [blame] | 1087 | memset(str, 0, sizeof(FPDF_BSTR)); |
Nico Weber | 9d8ec5a | 2015-08-04 13:00:21 -0700 | [diff] [blame] | 1088 | return 0; |
| 1089 | } |
| 1090 | |
Dan Sinclair | 00d2ad1 | 2017-08-10 14:13:02 -0400 | [diff] [blame] | 1091 | FPDF_EXPORT FPDF_RESULT FPDF_CALLCONV FPDF_BStr_Set(FPDF_BSTR* str, |
| 1092 | FPDF_LPCSTR bstr, |
| 1093 | int length) { |
Lei Zhang | a88e305 | 2017-12-15 15:51:52 -0800 | [diff] [blame] | 1094 | if (!str || !bstr || !length) |
Nico Weber | 9d8ec5a | 2015-08-04 13:00:21 -0700 | [diff] [blame] | 1095 | return -1; |
Lei Zhang | a88e305 | 2017-12-15 15:51:52 -0800 | [diff] [blame] | 1096 | |
Nico Weber | 9d8ec5a | 2015-08-04 13:00:21 -0700 | [diff] [blame] | 1097 | if (length == -1) |
Ryan Harrison | 8b1408e | 2017-09-27 11:07:51 -0400 | [diff] [blame] | 1098 | length = strlen(bstr); |
Nico Weber | 9d8ec5a | 2015-08-04 13:00:21 -0700 | [diff] [blame] | 1099 | |
| 1100 | if (length == 0) { |
Lei Zhang | a88e305 | 2017-12-15 15:51:52 -0800 | [diff] [blame] | 1101 | FPDF_BStr_Clear(str); |
Nico Weber | 9d8ec5a | 2015-08-04 13:00:21 -0700 | [diff] [blame] | 1102 | return 0; |
| 1103 | } |
| 1104 | |
| 1105 | if (str->str && str->len < length) |
| 1106 | str->str = FX_Realloc(char, str->str, length + 1); |
| 1107 | else if (!str->str) |
| 1108 | str->str = FX_Alloc(char, length + 1); |
| 1109 | |
| 1110 | str->str[length] = 0; |
Dan Sinclair | 1c5d0b4 | 2017-04-03 15:05:11 -0400 | [diff] [blame] | 1111 | memcpy(str->str, bstr, length); |
Nico Weber | 9d8ec5a | 2015-08-04 13:00:21 -0700 | [diff] [blame] | 1112 | str->len = length; |
| 1113 | |
| 1114 | return 0; |
| 1115 | } |
| 1116 | |
Dan Sinclair | 00d2ad1 | 2017-08-10 14:13:02 -0400 | [diff] [blame] | 1117 | FPDF_EXPORT FPDF_RESULT FPDF_CALLCONV FPDF_BStr_Clear(FPDF_BSTR* str) { |
Nico Weber | 9d8ec5a | 2015-08-04 13:00:21 -0700 | [diff] [blame] | 1118 | if (!str) |
| 1119 | return -1; |
| 1120 | |
| 1121 | if (str->str) { |
| 1122 | FX_Free(str->str); |
thestig | 1cd352e | 2016-06-07 17:53:06 -0700 | [diff] [blame] | 1123 | str->str = nullptr; |
Nico Weber | 9d8ec5a | 2015-08-04 13:00:21 -0700 | [diff] [blame] | 1124 | } |
| 1125 | str->len = 0; |
| 1126 | return 0; |
| 1127 | } |
Tom Sepez | 40e9ff3 | 2015-11-30 12:39:54 -0800 | [diff] [blame] | 1128 | #endif // PDF_ENABLE_XFA |
Nico Weber | 9d8ec5a | 2015-08-04 13:00:21 -0700 | [diff] [blame] | 1129 | |
Dan Sinclair | 00d2ad1 | 2017-08-10 14:13:02 -0400 | [diff] [blame] | 1130 | FPDF_EXPORT FPDF_DEST FPDF_CALLCONV FPDF_GetNamedDest(FPDF_DOCUMENT document, |
| 1131 | int index, |
| 1132 | void* buffer, |
| 1133 | long* buflen) { |
Nico Weber | 9d8ec5a | 2015-08-04 13:00:21 -0700 | [diff] [blame] | 1134 | if (!buffer) |
| 1135 | *buflen = 0; |
Tom Sepez | 540c436 | 2015-11-24 13:33:57 -0800 | [diff] [blame] | 1136 | |
| 1137 | if (index < 0) |
| 1138 | return nullptr; |
Nico Weber | 9d8ec5a | 2015-08-04 13:00:21 -0700 | [diff] [blame] | 1139 | |
Tom Sepez | bf59a07 | 2015-10-21 14:07:23 -0700 | [diff] [blame] | 1140 | CPDF_Document* pDoc = CPDFDocumentFromFPDFDocument(document); |
Tom Sepez | 540c436 | 2015-11-24 13:33:57 -0800 | [diff] [blame] | 1141 | if (!pDoc) |
| 1142 | return nullptr; |
| 1143 | |
Lei Zhang | 0158106 | 2017-08-30 14:19:26 -0700 | [diff] [blame] | 1144 | const CPDF_Dictionary* pRoot = pDoc->GetRoot(); |
Nico Weber | 9d8ec5a | 2015-08-04 13:00:21 -0700 | [diff] [blame] | 1145 | if (!pRoot) |
Tom Sepez | 540c436 | 2015-11-24 13:33:57 -0800 | [diff] [blame] | 1146 | return nullptr; |
Nico Weber | 9d8ec5a | 2015-08-04 13:00:21 -0700 | [diff] [blame] | 1147 | |
Oliver Chang | 3f1c71f | 2016-01-11 08:45:31 -0800 | [diff] [blame] | 1148 | CPDF_Object* pDestObj = nullptr; |
Ryan Harrison | 275e260 | 2017-09-18 14:23:18 -0400 | [diff] [blame] | 1149 | WideString wsName; |
Lei Zhang | d983b09 | 2015-12-14 16:58:33 -0800 | [diff] [blame] | 1150 | CPDF_NameTree nameTree(pDoc, "Dests"); |
Nico Weber | 9d8ec5a | 2015-08-04 13:00:21 -0700 | [diff] [blame] | 1151 | int count = nameTree.GetCount(); |
| 1152 | if (index >= count) { |
Lei Zhang | 55bbb0a | 2018-05-08 19:26:37 +0000 | [diff] [blame] | 1153 | const CPDF_Dictionary* pDest = pRoot->GetDictFor("Dests"); |
Nico Weber | 9d8ec5a | 2015-08-04 13:00:21 -0700 | [diff] [blame] | 1154 | if (!pDest) |
Oliver Chang | 3f1c71f | 2016-01-11 08:45:31 -0800 | [diff] [blame] | 1155 | return nullptr; |
| 1156 | |
| 1157 | pdfium::base::CheckedNumeric<int> checked_count = count; |
| 1158 | checked_count += pDest->GetCount(); |
| 1159 | if (!checked_count.IsValid() || index >= checked_count.ValueOrDie()) |
| 1160 | return nullptr; |
| 1161 | |
Nico Weber | 9d8ec5a | 2015-08-04 13:00:21 -0700 | [diff] [blame] | 1162 | index -= count; |
Nico Weber | 9d8ec5a | 2015-08-04 13:00:21 -0700 | [diff] [blame] | 1163 | int i = 0; |
Ryan Harrison | 275e260 | 2017-09-18 14:23:18 -0400 | [diff] [blame] | 1164 | ByteString bsName; |
Oliver Chang | 3f1c71f | 2016-01-11 08:45:31 -0800 | [diff] [blame] | 1165 | for (const auto& it : *pDest) { |
| 1166 | bsName = it.first; |
tsepez | 0e606b5 | 2016-11-18 16:22:41 -0800 | [diff] [blame] | 1167 | pDestObj = it.second.get(); |
Nico Weber | 9d8ec5a | 2015-08-04 13:00:21 -0700 | [diff] [blame] | 1168 | if (!pDestObj) |
| 1169 | continue; |
| 1170 | if (i == index) |
| 1171 | break; |
| 1172 | i++; |
Bo Xu | 4d62b6b | 2015-01-10 22:52:59 -0800 | [diff] [blame] | 1173 | } |
Jane Liu | 67ccef7 | 2017-07-19 13:10:50 -0400 | [diff] [blame] | 1174 | wsName = PDF_DecodeText(bsName); |
Nico Weber | 9d8ec5a | 2015-08-04 13:00:21 -0700 | [diff] [blame] | 1175 | } else { |
Jane Liu | 67ccef7 | 2017-07-19 13:10:50 -0400 | [diff] [blame] | 1176 | pDestObj = nameTree.LookupValueAndName(index, &wsName); |
Nico Weber | 9d8ec5a | 2015-08-04 13:00:21 -0700 | [diff] [blame] | 1177 | } |
| 1178 | if (!pDestObj) |
Dan Sinclair | 2b11dc1 | 2015-10-22 15:02:06 -0400 | [diff] [blame] | 1179 | return nullptr; |
Dan Sinclair | f1251c1 | 2015-10-20 16:24:45 -0400 | [diff] [blame] | 1180 | if (CPDF_Dictionary* pDict = pDestObj->AsDictionary()) { |
dsinclair | 38fd844 | 2016-09-15 10:15:32 -0700 | [diff] [blame] | 1181 | pDestObj = pDict->GetArrayFor("D"); |
Nico Weber | 9d8ec5a | 2015-08-04 13:00:21 -0700 | [diff] [blame] | 1182 | if (!pDestObj) |
Dan Sinclair | 2b11dc1 | 2015-10-22 15:02:06 -0400 | [diff] [blame] | 1183 | return nullptr; |
Nico Weber | 9d8ec5a | 2015-08-04 13:00:21 -0700 | [diff] [blame] | 1184 | } |
Dan Sinclair | 2b11dc1 | 2015-10-22 15:02:06 -0400 | [diff] [blame] | 1185 | if (!pDestObj->IsArray()) |
| 1186 | return nullptr; |
| 1187 | |
Ryan Harrison | 275e260 | 2017-09-18 14:23:18 -0400 | [diff] [blame] | 1188 | ByteString utf16Name = wsName.UTF16LE_Encode(); |
weili | 47ca692 | 2016-03-31 15:08:27 -0700 | [diff] [blame] | 1189 | int len = utf16Name.GetLength(); |
Nico Weber | 9d8ec5a | 2015-08-04 13:00:21 -0700 | [diff] [blame] | 1190 | if (!buffer) { |
| 1191 | *buflen = len; |
thestig | 9067fd6 | 2016-11-23 14:10:06 -0800 | [diff] [blame] | 1192 | } else if (len <= *buflen) { |
Nico Weber | 9d8ec5a | 2015-08-04 13:00:21 -0700 | [diff] [blame] | 1193 | memcpy(buffer, utf16Name.c_str(), len); |
| 1194 | *buflen = len; |
| 1195 | } else { |
| 1196 | *buflen = -1; |
| 1197 | } |
Tom Sepez | 525147a | 2018-05-03 17:19:53 +0000 | [diff] [blame] | 1198 | return FPDFDestFromCPDFArray(pDestObj->AsArray()); |
Bo Xu | 4d62b6b | 2015-01-10 22:52:59 -0800 | [diff] [blame] | 1199 | } |