7#include "public/fpdfview.h"
13#include "build/build_config.h"
14#include "core/fpdfapi/page/cpdf_docpagedata.h"
15#include "core/fpdfapi/page/cpdf_occontext.h"
16#include "core/fpdfapi/page/cpdf_page.h"
17#include "core/fpdfapi/page/cpdf_pageimagecache.h"
18#include "core/fpdfapi/page/cpdf_pagemodule.h"
19#include "core/fpdfapi/parser/cpdf_array.h"
20#include "core/fpdfapi/parser/cpdf_dictionary.h"
21#include "core/fpdfapi/parser/cpdf_document.h"
22#include "core/fpdfapi/parser/cpdf_name.h"
23#include "core/fpdfapi/parser/cpdf_parser.h"
24#include "core/fpdfapi/parser/cpdf_stream.h"
25#include "core/fpdfapi/parser/cpdf_string.h"
26#include "core/fpdfapi/parser/fpdf_parser_decode.h"
27#include "core/fpdfapi/render/cpdf_docrenderdata.h"
28#include "core/fpdfapi/render/cpdf_pagerendercontext.h"
29#include "core/fpdfapi/render/cpdf_rendercontext.h"
30#include "core/fpdfapi/render/cpdf_renderoptions.h"
31#include "core/fpdfdoc/cpdf_nametree.h"
32#include "core/fpdfdoc/cpdf_viewerpreferences.h"
33#include "core/fxcrt/cfx_read_only_span_stream.h"
34#include "core/fxcrt/cfx_timer.h"
35#include "core/fxcrt/fx_safe_types.h"
36#include "core/fxcrt/fx_stream.h"
37#include "core/fxcrt/fx_system.h"
38#include "core/fxcrt/span_util.h"
39#include "core/fxcrt/stl_util.h"
40#include "core/fxcrt/unowned_ptr.h"
41#include "core/fxge/cfx_defaultrenderdevice.h"
42#include "core/fxge/cfx_gemodule.h"
43#include "core/fxge/cfx_glyphcache.h"
44#include "core/fxge/cfx_renderdevice.h"
45#include "core/fxge/dib/cfx_dibitmap.h"
46#include "fpdfsdk/cpdfsdk_customaccess.h"
47#include "fpdfsdk/cpdfsdk_formfillenvironment.h"
48#include "fpdfsdk/cpdfsdk_helpers.h"
49#include "fpdfsdk/cpdfsdk_pageview.h"
50#include "fpdfsdk/cpdfsdk_renderpage.h"
51#include "fxjs/ijs_runtime.h"
52#include "public/fpdf_formfill.h"
53#include "third_party/base/check_op.h"
54#include "third_party/base/containers/span.h"
55#include "third_party/base/memory/ptr_util.h"
56#include "third_party/base/numerics/safe_conversions.h"
59#include "fxjs/cfx_v8_array_buffer_allocator.h"
60#include "third_party/base/no_destructor.h"
64#include "fpdfsdk/fpdfxfa/cpdfxfa_context.h"
65#include "fpdfsdk/fpdfxfa/cpdfxfa_page.h"
69#include "core/fpdfapi/render/cpdf_progressiverenderer.h"
70#include "core/fpdfapi/render/cpdf_windowsrenderdevice.h"
71#include "public/fpdf_edit.h"
73#if defined(PDF_USE_SKIA)
78static_assert(
static_cast<
int>(WindowsPrintMode::kEmf) == FPDF_PRINTMODE_EMF,
79 "WindowsPrintMode::kEmf value mismatch");
80static_assert(
static_cast<
int>(WindowsPrintMode::kTextOnly) ==
81 FPDF_PRINTMODE_TEXTONLY,
82 "WindowsPrintMode::kTextOnly value mismatch");
83static_assert(
static_cast<
int>(WindowsPrintMode::kPostScript2) ==
84 FPDF_PRINTMODE_POSTSCRIPT2,
85 "WindowsPrintMode::kPostScript2 value mismatch");
86static_assert(
static_cast<
int>(WindowsPrintMode::kPostScript3) ==
87 FPDF_PRINTMODE_POSTSCRIPT3,
88 "WindowsPrintMode::kPostScript3 value mismatch");
89static_assert(
static_cast<
int>(WindowsPrintMode::kPostScript2PassThrough) ==
90 FPDF_PRINTMODE_POSTSCRIPT2_PASSTHROUGH,
91 "WindowsPrintMode::kPostScript2PassThrough value mismatch");
92static_assert(
static_cast<
int>(WindowsPrintMode::kPostScript3PassThrough) ==
93 FPDF_PRINTMODE_POSTSCRIPT3_PASSTHROUGH,
94 "WindowsPrintMode::kPostScript3PassThrough value mismatch");
95static_assert(
static_cast<
int>(WindowsPrintMode::kEmfImageMasks) ==
96 FPDF_PRINTMODE_EMF_IMAGE_MASKS,
97 "WindowsPrintMode::kEmfImageMasks value mismatch");
98static_assert(
static_cast<
int>(WindowsPrintMode::kPostScript3Type42) ==
99 FPDF_PRINTMODE_POSTSCRIPT3_TYPE42,
100 "WindowsPrintMode::kPostScript3Type42 value mismatch");
102 static_cast<
int>(WindowsPrintMode::kPostScript3Type42PassThrough) ==
103 FPDF_PRINTMODE_POSTSCRIPT3_TYPE42_PASSTHROUGH,
104 "WindowsPrintMode::kPostScript3Type42PassThrough value mismatch");
107#if defined(PDF_USE_SKIA)
109static_assert(
static_cast<
int>(CFX_DefaultRenderDevice::RendererType::kAgg) ==
110 FPDF_RENDERERTYPE_AGG,
111 "CFX_DefaultRenderDevice::RendererType::kAGG value mismatch");
112static_assert(
static_cast<
int>(CFX_DefaultRenderDevice::RendererType::kSkia) ==
113 FPDF_RENDERERTYPE_SKIA,
114 "CFX_DefaultRenderDevice::RendererType::kSkia value mismatch");
119bool g_bLibraryInitialized =
false;
121void SetRendererType(FPDF_RENDERER_TYPE public_type) {
130#if defined(PDF_USE_SKIA)
132 if (public_type == FPDF_RENDERERTYPE_AGG ||
133 public_type == FPDF_RENDERERTYPE_SKIA) {
134 CFX_DefaultRenderDevice::SetRendererType(
135 static_cast<CFX_DefaultRenderDevice::RendererType>(public_type));
141 CHECK_EQ(public_type, FPDF_RENDERERTYPE_AGG);
145void ResetRendererType() {
146#if defined(PDF_USE_SKIA)
147 CFX_DefaultRenderDevice::SetRendererType(
148 CFX_DefaultRenderDevice::kDefaultRenderer);
157 RetainPtr<
const CPDF_Dictionary> acro_form = root->GetDictFor(
"AcroForm");
158 return acro_form ? acro_form->GetObjectFor(
"XFA") :
nullptr;
167 std::vector<XFAPacket> packets;
172 RetainPtr<
const CPDF_Stream> xfa_stream = ToStream(xfa_object->GetDirect());
174 packets.push_back({
"",
std::move(xfa_stream)});
178 RetainPtr<
const CPDF_Array> xfa_array = ToArray(xfa_object->GetDirect());
182 packets.reserve(1 + (xfa_array->size() / 2));
183 for (size_t i = 0; i < xfa_array->size(); i += 2) {
184 if (i + 1 == xfa_array->size())
187 RetainPtr<
const CPDF_String> name = xfa_array->GetStringAt(i);
191 RetainPtr<
const CPDF_Stream> data = xfa_array->GetStreamAt(i + 1);
195 packets.push_back({name->GetString(),
std::move(data)});
201 FPDF_BYTESTRING password) {
209 std::make_unique<CPDF_DocPageData>());
212 pDocument->LoadDoc(
std::move(pFileAccess), password);
218 ReportUnsupportedFeatures(pDocument.get());
219 return FPDFDocumentFromCPDFDocument(pDocument.release());
230 if (g_bLibraryInitialized)
238#if defined(PDF_USE_SKIA)
239 CFX_GlyphCache::InitializeGlobals();
243 CPDFXFA_ModuleInit();
246 if (config && config->version >= 2) {
247 void* platform = config->version >= 3 ? config->m_pPlatform :
nullptr;
251 if (config->version >= 4)
252 SetRendererType(config->m_RendererType);
254 g_bLibraryInitialized =
true;
258 if (!g_bLibraryInitialized)
267 CPDFXFA_ModuleDestroy();
270#if defined(PDF_USE_SKIA)
271 CFX_GlyphCache::DestroyGlobals();
278 g_bLibraryInitialized =
false;
287FPDF_EXPORT FPDF_BOOL FPDF_CALLCONV FPDF_SetPrintMode(
int mode) {
288 if (mode < FPDF_PRINTMODE_EMF ||
289 mode > FPDF_PRINTMODE_POSTSCRIPT3_TYPE42_PASSTHROUGH) {
293 g_pdfium_print_mode =
static_cast<WindowsPrintMode>(mode);
315 RetainPtr<
const CPDF_Dictionary> pAcroForm = pRoot->GetDictFor(
"AcroForm");
329 auto* pDoc = CPDFDocumentFromFPDFDocument(document);
333 auto* pContext =
static_cast<CPDFXFA_Context*>(pDoc->GetExtension());
335 return pContext->LoadXFADoc();
346 return LoadDocumentImpl(
347 pdfium::MakeRetain<CFX_ReadOnlySpanStream>(pdfium::make_span(
348 static_cast<
const uint8_t*>(data_buf),
static_cast<size_t>(size))),
355 FPDF_BYTESTRING password) {
356 return LoadDocumentImpl(
357 pdfium::MakeRetain<CFX_ReadOnlySpanStream>(
358 pdfium::make_span(
static_cast<
const uint8_t*>(data_buf), size)),
364 FPDF_BYTESTRING password) {
367 return LoadDocumentImpl(pdfium::MakeRetain<CPDFSDK_CustomAccess>(pFileAccess),
413 RetainPtr<
const CPDF_Dictionary> pDict = pDoc->GetParser()->GetEncryptDict();
414 return pDict ? pDict->GetIntegerFor(
"R") : -1;
436 auto* pContext =
static_cast<CPDFXFA_Context*>(pDoc->GetExtension());
438 return FPDFPageFromIPDFPage(
439 pContext->GetOrCreateXFAPage(page_index).Leak());
443 RetainPtr<CPDF_Dictionary> pDict = pDoc->GetMutablePageDictionary(page_index);
447 auto pPage = pdfium::MakeRetain<CPDF_Page>(pDoc,
std::move(pDict));
448 pPage->AddPageImageCache();
449 pPage->ParseContent();
451 return FPDFPageFromIPDFPage(pPage.Leak());
481 *rect = FSRectFFromCFXFloatRect(pPage
->GetBBox());
488constexpr float kEpsilonSize = 0.01f;
490bool IsPageTooSmall(
const CPDF_Page* page) {
491 const CFX_SizeF& page_size = page->GetPageSize();
492 return page_size.width < kEpsilonSize || page_size.height < kEpsilonSize;
495bool IsScalingTooSmall(
const CFX_Matrix& matrix) {
498 if (matrix.a == 0.0f && matrix.d == 0.0f) {
499 horizontal = matrix.b;
502 horizontal = matrix.a;
505 return fabsf(horizontal) < kEpsilonSize || fabsf(vertical) < kEpsilonSize;
510RetainPtr<CFX_DIBitmap> GetMaskBitmap(CPDF_Page* pPage,
516 RetainPtr<
const CFX_DIBitmap> source,
517 const CFX_FloatRect& mask_box,
518 FX_RECT* bitmap_area) {
519 if (IsPageTooSmall(pPage))
522 FX_RECT page_rect(start_x, start_y, start_x + size_x, start_y + size_y);
523 CFX_Matrix matrix = pPage->GetDisplayMatrix(page_rect, rotate);
524 if (IsScalingTooSmall(matrix))
527 *bitmap_area = matrix.TransformRect(mask_box).GetOuterRect();
528 if (bitmap_area->IsEmpty())
532 RetainPtr<CFX_DIBitmap> pDst = pdfium::MakeRetain<CFX_DIBitmap>();
533 if (!pDst->Create(bitmap_area->Width(), bitmap_area->Height(),
534 FXDIB_Format::kArgb)) {
537 pDst->Clear(0x00ffffff);
538 pDst->TransferBitmap(0, 0, bitmap_area->Width(), bitmap_area->Height(),
539 std::move(source), bitmap_area->left, bitmap_area->top);
543void RenderBitmap(CFX_RenderDevice* device,
544 RetainPtr<
const CFX_DIBitmap> source,
545 const FX_RECT& mask_area) {
546 int size_x_bm = mask_area.Width();
547 int size_y_bm = mask_area.Height();
548 if (size_x_bm == 0 || size_y_bm == 0)
552 RetainPtr<CFX_DIBitmap> dest = pdfium::MakeRetain<CFX_DIBitmap>();
553 if (!dest->Create(size_x_bm, size_y_bm, FXDIB_Format::kRgb32)) {
557 dest->Clear(0xffffffff);
558 dest->CompositeBitmap(0, 0, size_x_bm, size_y_bm, std::move(source), 0, 0,
559 BlendMode::kNormal,
nullptr,
false);
561 if (device->GetDeviceType() == DeviceType::kPrinter) {
562 device->StretchDIBits(std::move(dest), mask_area.left, mask_area.top,
563 size_x_bm, size_y_bm);
565 device->SetDIBits(std::move(dest), mask_area.left, mask_area.top);
571FPDF_EXPORT
void FPDF_CALLCONV FPDF_RenderPage(HDC dc,
579 CPDF_Page* pPage = CPDFPageFromFPDFPage(page);
583 auto owned_context = std::make_unique<CPDF_PageRenderContext>();
584 CPDF_PageRenderContext* context = owned_context.get();
585 CPDF_Page::RenderContextClearer clearer(pPage);
586 pPage->SetRenderContext(std::move(owned_context));
593 const bool bEnableImageMasks =
594 g_pdfium_print_mode == WindowsPrintMode::kEmfImageMasks;
595 const bool bNewBitmap = pPage->BackgroundAlphaNeeded() ||
596 (pPage->HasImageMask() && !bEnableImageMasks) ||
597 pPage->GetMaskBoundingBoxes().size() > 100;
598 const bool bHasMask = pPage->HasImageMask() && !bNewBitmap;
599 auto* render_data = CPDF_DocRenderData::FromDocument(pPage->GetDocument());
600 if (!bNewBitmap && !bHasMask) {
601 context->m_pDevice = std::make_unique<CPDF_WindowsRenderDevice>(
602 dc, render_data->GetPSFontTracker());
603 CPDFSDK_RenderPageWithContext(context, pPage, start_x, start_y, size_x,
604 size_y, rotate, flags,
610 RetainPtr<CFX_DIBitmap> pBitmap = pdfium::MakeRetain<CFX_DIBitmap>();
613 pBitmap->Create(size_x, size_y, FXDIB_Format::kArgb);
614 if (!CFX_DefaultRenderDevice::UseSkiaRenderer()) {
616 pBitmap->Clear(0x00ffffff);
619 auto device = std::make_unique<CFX_DefaultRenderDevice>();
620 device->Attach(pBitmap);
621 context->m_pDevice = std::move(device);
623 context->m_pOptions = std::make_unique<CPDF_RenderOptions>();
624 context->m_pOptions->GetOptions().bBreakForMasks =
true;
627 CPDFSDK_RenderPageWithContext(context, pPage, start_x, start_y, size_x,
628 size_y, rotate, flags,
nullptr,
632#if defined(PDF_USE_SKIA)
633 if (CFX_DefaultRenderDevice::UseSkiaRenderer()) {
634 pBitmap->UnPreMultiply();
639 CPDF_WindowsRenderDevice win_dc(dc, render_data->GetPSFontTracker());
640 bool bitsStretched =
false;
641 if (win_dc.GetDeviceType() == DeviceType::kPrinter) {
642 auto dest_bitmap = pdfium::MakeRetain<CFX_DIBitmap>();
643 if (dest_bitmap->Create(size_x, size_y, FXDIB_Format::kRgb32)) {
644 fxcrt::spanset(dest_bitmap->GetWritableBuffer().first(
645 pBitmap->GetPitch() * size_y),
647 dest_bitmap->CompositeBitmap(0, 0, size_x, size_y, pBitmap, 0, 0,
648 BlendMode::kNormal,
nullptr,
false);
649 win_dc.StretchDIBits(std::move(dest_bitmap), 0, 0, size_x, size_y);
650 bitsStretched =
true;
654 win_dc.SetDIBits(std::move(pBitmap), 0, 0);
660 const std::vector<CFX_FloatRect>& mask_boxes = pPage->GetMaskBoundingBoxes();
661 std::vector<FX_RECT> bitmap_areas(mask_boxes.size());
662 std::vector<RetainPtr<CFX_DIBitmap>> bitmaps(mask_boxes.size());
663 for (size_t i = 0; i < mask_boxes.size(); i++) {
664 bitmaps[i] = GetMaskBitmap(pPage, start_x, start_y, size_x, size_y, rotate,
665 pBitmap, mask_boxes[i], &bitmap_areas[i]);
666 context->m_pRenderer->Continue(
nullptr);
671 pPage->ClearRenderContext();
672 owned_context = std::make_unique<CPDF_PageRenderContext>();
673 context = owned_context.get();
674 pPage->SetRenderContext(std::move(owned_context));
675 context->m_pDevice = std::make_unique<CPDF_WindowsRenderDevice>(
676 dc, render_data->GetPSFontTracker());
677 context->m_pOptions = std::make_unique<CPDF_RenderOptions>();
678 context->m_pOptions->GetOptions().bBreakForMasks =
true;
680 CPDFSDK_RenderPageWithContext(context, pPage, start_x, start_y, size_x,
681 size_y, rotate, flags,
nullptr,
686 for (size_t i = 0; i < mask_boxes.size(); i++) {
689 RenderBitmap(context->m_pDevice.get(), std::move(bitmaps[i]),
693 context->m_pRenderer->Continue(
nullptr);
713 auto owned_context =
std::make_unique<CPDF_PageRenderContext>();
714 CPDF_PageRenderContext* context = owned_context.get();
716 pPage->SetRenderContext(
std::move(owned_context));
718 RetainPtr<CFX_DIBitmap> pBitmap(CFXDIBitmapFromFPDFBitmap(bitmap));
719 auto device =
std::make_unique<CFX_DefaultRenderDevice>();
721 context->m_pDevice =
std::move(device);
724 size_y
, rotate
, flags
, nullptr,
728#if defined(PDF_USE_SKIA)
729 if (CFX_DefaultRenderDevice::UseSkiaRenderer()) {
730 pBitmap->UnPreMultiply();
738 const FS_MATRIX* matrix,
739 const FS_RECTF* clipping,
748 auto owned_context =
std::make_unique<CPDF_PageRenderContext>();
749 CPDF_PageRenderContext* context = owned_context.get();
751 pPage->SetRenderContext(
std::move(owned_context));
753 RetainPtr<CFX_DIBitmap> pBitmap(CFXDIBitmapFromFPDFBitmap(bitmap));
754 auto device =
std::make_unique<CFX_DefaultRenderDevice>();
755 device->AttachWithRgbByteOrder(
std::move(pBitmap),
757 context->m_pDevice =
std::move(device);
772#if defined(PDF_USE_SKIA)
773FPDF_EXPORT
void FPDF_CALLCONV FPDF_RenderPageSkia(FPDF_SKIA_CANVAS canvas,
781 CPDF_Page* cpdf_page = CPDFPageFromFPDFPage(page);
786 auto owned_context = std::make_unique<CPDF_PageRenderContext>();
787 CPDF_PageRenderContext* context = owned_context.get();
788 CPDF_Page::RenderContextClearer clearer(cpdf_page);
789 cpdf_page->SetRenderContext(std::move(owned_context));
791 auto device = std::make_unique<CFX_DefaultRenderDevice>();
792 device->AttachCanvas(
reinterpret_cast<SkCanvas*>(canvas));
793 context->m_pDevice = std::move(device);
795 CPDFSDK_RenderPageWithContext(context, cpdf_page, 0, 0, size_x, size_y, 0, 0,
809 if (pPage->AsXFAPage())
815 pPage->AsPDFPage()->ClearView();
820 std::unique_ptr<CPDF_Document>(CPDFDocumentFromFPDFDocument(document));
837 if (!page || !page_x || !page_y)
841 const FX_RECT rect
(start_x
, start_y
, start_x + size_x
, start_y + size_y
);
842 absl::optional<CFX_PointF> pos =
843 pPage->DeviceToPage(rect, rotate, CFX_PointF(device_x, device_y));
844 if (!pos.has_value())
862 if (!page || !device_x || !device_y)
866 const FX_RECT rect
(start_x
, start_y
, start_x + size_x
, start_y + size_y
);
867 CFX_PointF page_point(
static_cast<
float>(page_x),
static_cast<
float>(page_y));
868 absl::optional<CFX_PointF> pos =
869 pPage->PageToDevice(rect, rotate, page_point);
870 if (!pos.has_value())
873 *device_x = FXSYS_roundf(pos->x);
874 *device_y = FXSYS_roundf(pos->y);
881 auto pBitmap = pdfium::MakeRetain<CFX_DIBitmap>();
882 if (!pBitmap->Create(width, height,
886 return FPDFBitmapFromCFXDIBitmap(pBitmap.Leak());
913 UnownedPtr<uint8_t> pChecker(
static_cast<uint8_t*>(first_scan));
914 auto pBitmap = pdfium::MakeRetain<CFX_DIBitmap>();
915 if (!pBitmap->Create(width, height, fx_format, pChecker, stride))
918 return FPDFBitmapFromCFXDIBitmap(pBitmap.Leak());
950 CFX_DefaultRenderDevice device;
951 RetainPtr<CFX_DIBitmap> pBitmap(CFXDIBitmapFromFPDFBitmap(bitmap));
953 if (!pBitmap->IsAlphaFormat())
956 static_cast<uint32_t>(color));
993 if (page_index < 0 || page_index >= FPDF_GetPageCount(document))
996 auto* pContext =
static_cast<CPDFXFA_Context*>(pDoc->GetExtension());
998 RetainPtr<CPDFXFA_Page> pPage = pContext->GetOrCreateXFAPage(page_index);
1002 size->width = pPage->GetPageWidth();
1003 size->height = pPage->GetPageHeight();
1008 RetainPtr<CPDF_Dictionary> pDict = pDoc->GetMutablePageDictionary(page_index);
1012 auto page = pdfium::MakeRetain<CPDF_Page>(pDoc,
std::move(pDict));
1013 page->AddPageImageCache();
1014 size->width = page->GetPageWidth();
1015 size->height = page->GetPageHeight();
1023 if (!width || !height)
1030 *width = size.width;
1031 *height = size.height;
1067 return pArray ? pArray->size() : 0;
1074 if (!pArray || index >= pArray->size())
1076 return pArray->GetIntegerAt(index);
1083 return DuplexUndefined;
1086 if (
"Simplex" == duplex)
1088 if (
"DuplexFlipShortEdge" == duplex)
1089 return DuplexFlipShortEdge;
1090 if (
"DuplexFlipLongEdge" == duplex)
1091 return DuplexFlipLongEdge;
1092 return DuplexUndefined;
1097 FPDF_BYTESTRING key,
1099 unsigned long length) {
1105 absl::optional<ByteString> bsVal = viewRef.GenericName(key);
1106 if (!bsVal.has_value())
1109 return NulTerminateMaybeCopyAndReturnLength(bsVal.value(), buffer, length);
1122 auto name_tree = CPDF_NameTree::Create(pDoc,
"Dests");
1123 FX_SAFE_UINT32 count = name_tree ? name_tree->GetCount() : 0;
1124 RetainPtr<
const CPDF_Dictionary> pOldStyleDests = pRoot->GetDictFor(
"Dests");
1126 count += pOldStyleDests->size();
1127 return count.ValueOrDefault(0);
1132 if (!name || name[0] == 0)
1139 ByteString dest_name
(name
);
1147FPDF_EXPORT
const char* FPDF_CALLCONV FPDF_GetRecommendedV8Flags() {
1154FPDF_EXPORT
void* FPDF_CALLCONV FPDF_GetArrayBufferAllocatorSharedInstance() {
1155 static pdfium::base::NoDestructor<CFX_V8ArrayBufferAllocator> allocator;
1156 return allocator.get();
1160#ifdef PDF_ENABLE_XFA
1161FPDF_EXPORT FPDF_RESULT FPDF_CALLCONV FPDF_BStr_Init(FPDF_BSTR* bstr) {
1165 bstr->str =
nullptr;
1170FPDF_EXPORT FPDF_RESULT FPDF_CALLCONV FPDF_BStr_Set(FPDF_BSTR* bstr,
1177 length = pdfium::base::checked_cast<
int>(strlen(cstr));
1180 FPDF_BStr_Clear(bstr);
1184 if (bstr->str && bstr->len < length)
1185 bstr->str = FX_Realloc(
char, bstr->str, length + 1);
1186 else if (!bstr->str)
1187 bstr->str = FX_Alloc(
char, length + 1);
1189 bstr->str[length] = 0;
1190 memcpy(bstr->str, cstr, length);
1195FPDF_EXPORT FPDF_RESULT FPDF_CALLCONV FPDF_BStr_Clear(FPDF_BSTR* bstr) {
1201 bstr->str =
nullptr;
1226 auto name_tree = CPDF_NameTree::Create(pDoc,
"Dests");
1227 size_t name_tree_count = name_tree ? name_tree->GetCount() : 0;
1230 if (
static_cast<size_t>(index) >= name_tree_count) {
1233 RetainPtr<
const CPDF_Dictionary> pDest = pRoot->GetDictFor(
"Dests");
1237 FX_SAFE_INT32 checked_count = name_tree_count;
1238 checked_count += pDest->size();
1239 if (!checked_count.IsValid() || index >= checked_count.ValueOrDie())
1242 index -= name_tree_count;
1244 ByteStringView bsName;
1246 for (
const auto& it : locker) {
1247 bsName = it.first.AsStringView();
1248 pDestObj = it.second;
1253 wsName = PDF_DecodeText(bsName.raw_span());
1255 pDestObj = name_tree->LookupValueAndName(index, &wsName);
1259 if (
const CPDF_Dictionary* pDict = pDestObj->AsDictionary()) {
1264 if (!pDestObj->IsArray())
1268 int len = pdfium::base::checked_cast<
int>(utf16Name.GetLength());
1271 }
else if (len <= *buflen) {
1272 memcpy(buffer, utf16Name
.c_str(), len);
1277 return FPDFDestFromCPDFArray(pDestObj->AsArray());
1285 return fxcrt::CollectionSize<
int>(
1286 GetXFAPackets(GetXFAEntryFromDocument(doc)));
1293 unsigned long buflen) {
1295 if (!doc || index < 0)
1298 std::vector<XFAPacket> xfa_packets =
1299 GetXFAPackets(GetXFAEntryFromDocument(doc));
1300 if (
static_cast<size_t>(index) >= xfa_packets.size())
1303 return NulTerminateMaybeCopyAndReturnLength(xfa_packets[index].name, buffer,
1311 unsigned long buflen,
1312 unsigned long* out_buflen) {
1314 if (!doc || index < 0 || !out_buflen)
1317 std::vector<XFAPacket> xfa_packets =
1318 GetXFAPackets(GetXFAEntryFromDocument(doc));
1319 if (
static_cast<size_t>(index) >= xfa_packets.size())
1322 *out_buflen = DecodeStreamMaybeCopyAndReturnLength(
1323 xfa_packets[index].data,
1324 {
static_cast<uint8_t*>(buffer),
static_cast<size_t>(buflen)});
1330 unsigned int* buffer,
1331 unsigned long length) {
1338 std::vector<
unsigned int> trailer_ends = parser->GetTrailerEnds();
1339 const unsigned long trailer_ends_len =
1340 fxcrt::CollectionSize<
unsigned long>(trailer_ends);
1341 if (buffer && length >= trailer_ends_len) {
1342 for (size_t i = 0; i < trailer_ends_len; ++i)
1343 buffer[i] = trailer_ends[i];
1346 return trailer_ends_len;
FXDIB_Format GetFormat() const
uint32_t GetPitch() const
bool Attach(RetainPtr< CFX_DIBitmap > pBitmap)
CFX_FloatRect & operator=(const CFX_FloatRect &that)=default
static void Create(const char **pUserFontPaths)
CFX_Matrix & operator*=(const CFX_Matrix &other)
bool FillRect(const FX_RECT &rect, uint32_t color)
static void DestroyGlobals()
static void InitializeGlobals()
bool GetBooleanFor(const ByteString &key, bool bDefault) const
RetainPtr< const CPDF_Array > GetArrayFor(const ByteString &key) const
virtual int GetPageCount() const =0
bool has_valid_cross_reference_table() const
CPDF_Parser * GetParser() const
Extension * GetExtension() const
uint32_t GetUserPermissions(bool get_owner_perms) const
const CPDF_Dictionary * GetRoot() const
static RetainPtr< const CPDF_Array > LookupNamedDest(CPDF_Document *doc, const ByteString &name)
const CFX_FloatRect & GetBBox() const
RenderContextClearer(CPDF_Page *pPage)
float GetPageHeight() const override
float GetPageWidth() const override
CFX_Matrix GetDisplayMatrix(const FX_RECT &rect, int iRotate) const override
int GetFileVersion() const
RetainPtr< const CPDF_Array > PrintPageRange() const
int32_t NumCopies() const
CPDF_ViewerPreferences(const CPDF_Document *pDoc)
ByteString Duplex() const
bool PrintScaling() const
static RetainPtr< IFX_SeekableReadStream > CreateFromFilename(const char *filename)
static void Initialize(unsigned int slot, void *isolate, void *platform)
virtual float GetPageWidth() const =0
virtual float GetPageHeight() const =0
ByteString(const char *ptr)
const char * c_str() const
ByteString ToUTF16LE() const
const CPDF_Array * CPDFArrayFromFPDFPageRange(FPDF_PAGERANGE range)
IPDF_Page * IPDFPageFromFPDFPage(FPDF_PAGE page)
void ProcessParseError(CPDF_Parser::Error err)
CFX_DIBitmap * CFXDIBitmapFromFPDFBitmap(FPDF_BITMAP bitmap)
void SetPDFSandboxPolicy(FPDF_DWORD policy, FPDF_BOOL enable)
CFX_FloatRect CFXFloatRectFromFSRectF(const FS_RECTF &rect)
CPDF_Page * CPDFPageFromFPDFPage(FPDF_PAGE page)
CPDF_Document * CPDFDocumentFromFPDFDocument(FPDF_DOCUMENT doc)
CFX_Matrix CFXMatrixFromFSMatrix(const FS_MATRIX &matrix)
void CPDFSDK_RenderPageWithContext(CPDF_PageRenderContext *pContext, CPDF_Page *pPage, int start_x, int start_y, int size_x, int size_y, int rotate, int flags, const FPDF_COLORSCHEME *color_scheme, bool need_to_restore, CPDFSDK_PauseAdapter *pause)
void CPDFSDK_RenderPage(CPDF_PageRenderContext *pContext, CPDF_Page *pPage, const CFX_Matrix &matrix, const FX_RECT &clipping_rect, int flags, const FPDF_COLORSCHEME *color_scheme)
FPDF_EXPORT FPDF_PAGE FPDF_CALLCONV FPDF_LoadPage(FPDF_DOCUMENT document, int page_index)
FPDF_EXPORT int FPDF_CALLCONV FPDF_GetPageCount(FPDF_DOCUMENT document)
FPDF_EXPORT unsigned long FPDF_CALLCONV FPDF_GetLastError()
FPDF_EXPORT FPDF_BITMAP FPDF_CALLCONV FPDFBitmap_CreateEx(int width, int height, int format, void *first_scan, int stride)
FPDF_EXPORT void FPDF_CALLCONV FPDF_SetSandBoxPolicy(FPDF_DWORD policy, FPDF_BOOL enable)
FPDF_EXPORT FPDF_BOOL FPDF_CALLCONV FPDF_VIEWERREF_GetPrintScaling(FPDF_DOCUMENT document)
FPDF_EXPORT FPDF_BOOL FPDF_CALLCONV FPDF_DeviceToPage(FPDF_PAGE page, int start_x, int start_y, int size_x, int size_y, int rotate, int device_x, int device_y, double *page_x, double *page_y)
FPDF_EXPORT FPDF_DOCUMENT FPDF_CALLCONV FPDF_LoadCustomDocument(FPDF_FILEACCESS *pFileAccess, FPDF_BYTESTRING password)
FPDF_EXPORT FPDF_BOOL FPDF_CALLCONV FPDF_PageToDevice(FPDF_PAGE page, int start_x, int start_y, int size_x, int size_y, int rotate, double page_x, double page_y, int *device_x, int *device_y)
FPDF_EXPORT size_t FPDF_CALLCONV FPDF_VIEWERREF_GetPrintPageRangeCount(FPDF_PAGERANGE pagerange)
FPDF_EXPORT FPDF_DOCUMENT FPDF_CALLCONV FPDF_LoadDocument(FPDF_STRING file_path, FPDF_BYTESTRING password)
FPDF_EXPORT int FPDF_CALLCONV FPDFBitmap_GetHeight(FPDF_BITMAP bitmap)
FPDF_EXPORT FPDF_BOOL FPDF_CALLCONV FPDF_DocumentHasValidCrossReferenceTable(FPDF_DOCUMENT document)
FPDF_EXPORT void FPDF_CALLCONV FPDFBitmap_Destroy(FPDF_BITMAP bitmap)
FPDF_EXPORT FPDF_DUPLEXTYPE FPDF_CALLCONV FPDF_VIEWERREF_GetDuplex(FPDF_DOCUMENT document)
FPDF_EXPORT float FPDF_CALLCONV FPDF_GetPageHeightF(FPDF_PAGE page)
FPDF_EXPORT void FPDF_CALLCONV FPDF_DestroyLibrary()
FPDF_EXPORT int FPDF_CALLCONV FPDF_GetXFAPacketCount(FPDF_DOCUMENT document)
FPDF_EXPORT FPDF_BITMAP FPDF_CALLCONV FPDFBitmap_Create(int width, int height, int alpha)
FPDF_EXPORT int FPDF_CALLCONV FPDFBitmap_GetStride(FPDF_BITMAP bitmap)
FPDF_EXPORT FPDF_PAGERANGE FPDF_CALLCONV FPDF_VIEWERREF_GetPrintPageRange(FPDF_DOCUMENT document)
FPDF_EXPORT int FPDF_CALLCONV FPDF_GetPageSizeByIndex(FPDF_DOCUMENT document, int page_index, double *width, double *height)
FPDF_EXPORT unsigned long FPDF_CALLCONV FPDF_GetDocUserPermissions(FPDF_DOCUMENT document)
FPDF_EXPORT double FPDF_CALLCONV FPDF_GetPageWidth(FPDF_PAGE page)
FPDF_EXPORT FPDF_DOCUMENT FPDF_CALLCONV FPDF_LoadMemDocument64(const void *data_buf, size_t size, FPDF_BYTESTRING password)
FPDF_EXPORT unsigned long FPDF_CALLCONV FPDF_GetDocPermissions(FPDF_DOCUMENT document)
FPDF_EXPORT void FPDF_CALLCONV FPDF_InitLibrary()
FPDF_EXPORT FPDF_DEST FPDF_CALLCONV FPDF_GetNamedDest(FPDF_DOCUMENT document, int index, void *buffer, long *buflen)
FPDF_EXPORT FPDF_DEST FPDF_CALLCONV FPDF_GetNamedDestByName(FPDF_DOCUMENT document, FPDF_BYTESTRING name)
FPDF_EXPORT void FPDF_CALLCONV FPDF_RenderPageBitmap(FPDF_BITMAP bitmap, FPDF_PAGE page, int start_x, int start_y, int size_x, int size_y, int rotate, int flags)
FPDF_EXPORT FPDF_BOOL FPDF_CALLCONV FPDF_GetFileVersion(FPDF_DOCUMENT doc, int *fileVersion)
FPDF_EXPORT void FPDF_CALLCONV FPDF_RenderPageBitmapWithMatrix(FPDF_BITMAP bitmap, FPDF_PAGE page, const FS_MATRIX *matrix, const FS_RECTF *clipping, int flags)
FPDF_EXPORT FPDF_BOOL FPDF_CALLCONV FPDF_GetPageBoundingBox(FPDF_PAGE page, FS_RECTF *rect)
FPDF_EXPORT int FPDF_CALLCONV FPDFBitmap_GetFormat(FPDF_BITMAP bitmap)
FPDF_EXPORT void FPDF_CALLCONV FPDFBitmap_FillRect(FPDF_BITMAP bitmap, int left, int top, int width, int height, FPDF_DWORD color)
FPDF_EXPORT unsigned long FPDF_CALLCONV FPDF_VIEWERREF_GetName(FPDF_DOCUMENT document, FPDF_BYTESTRING key, char *buffer, unsigned long length)
FPDF_EXPORT void FPDF_CALLCONV FPDF_InitLibraryWithConfig(const FPDF_LIBRARY_CONFIG *config)
FPDF_EXPORT void *FPDF_CALLCONV FPDFBitmap_GetBuffer(FPDF_BITMAP bitmap)
FPDF_EXPORT FPDF_DWORD FPDF_CALLCONV FPDF_CountNamedDests(FPDF_DOCUMENT document)
FPDF_EXPORT void FPDF_CALLCONV FPDF_CloseDocument(FPDF_DOCUMENT document)
FPDF_EXPORT int FPDF_CALLCONV FPDF_VIEWERREF_GetPrintPageRangeElement(FPDF_PAGERANGE pagerange, size_t index)
FPDF_EXPORT FPDF_BOOL FPDF_CALLCONV FPDF_GetPageSizeByIndexF(FPDF_DOCUMENT document, int page_index, FS_SIZEF *size)
FPDF_EXPORT FPDF_BOOL FPDF_CALLCONV FPDF_GetXFAPacketContent(FPDF_DOCUMENT document, int index, void *buffer, unsigned long buflen, unsigned long *out_buflen)
FPDF_EXPORT int FPDF_CALLCONV FPDF_VIEWERREF_GetNumCopies(FPDF_DOCUMENT document)
FPDF_EXPORT unsigned long FPDF_CALLCONV FPDF_GetXFAPacketName(FPDF_DOCUMENT document, int index, void *buffer, unsigned long buflen)
FPDF_EXPORT double FPDF_CALLCONV FPDF_GetPageHeight(FPDF_PAGE page)
FPDF_EXPORT int FPDF_CALLCONV FPDFBitmap_GetWidth(FPDF_BITMAP bitmap)
FPDF_EXPORT FPDF_DOCUMENT FPDF_CALLCONV FPDF_LoadMemDocument(const void *data_buf, int size, FPDF_BYTESTRING password)
FPDF_EXPORT unsigned long FPDF_CALLCONV FPDF_GetTrailerEnds(FPDF_DOCUMENT document, unsigned int *buffer, unsigned long length)
FPDF_EXPORT float FPDF_CALLCONV FPDF_GetPageWidthF(FPDF_PAGE page)
FPDF_EXPORT void FPDF_CALLCONV FPDF_ClosePage(FPDF_PAGE page)
FPDF_EXPORT int FPDF_CALLCONV FPDF_GetSecurityHandlerRevision(FPDF_DOCUMENT document)
#define FPDF_REVERSE_BYTE_ORDER
#define FPDFBitmap_Unknown
void FX_InitializeMemoryAllocators()
uint32_t FXSYS_GetLastError()
bool operator==(const char *lhs, const ByteString &rhs)
constexpr FX_RECT(int l, int t, int r, int b)