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/check_op.h"
36#include "core/fxcrt/compiler_specific.h"
37#include "core/fxcrt/fx_memcpy_wrappers.h"
38#include "core/fxcrt/fx_safe_types.h"
39#include "core/fxcrt/fx_stream.h"
40#include "core/fxcrt/fx_system.h"
41#include "core/fxcrt/numerics/safe_conversions.h"
42#include "core/fxcrt/ptr_util.h"
43#include "core/fxcrt/span.h"
44#include "core/fxcrt/stl_util.h"
45#include "core/fxcrt/unowned_ptr.h"
46#include "core/fxge/cfx_defaultrenderdevice.h"
47#include "core/fxge/cfx_gemodule.h"
48#include "core/fxge/cfx_glyphcache.h"
49#include "core/fxge/cfx_renderdevice.h"
50#include "core/fxge/dib/cfx_dibitmap.h"
51#include "fpdfsdk/cpdfsdk_customaccess.h"
52#include "fpdfsdk/cpdfsdk_formfillenvironment.h"
53#include "fpdfsdk/cpdfsdk_helpers.h"
54#include "fpdfsdk/cpdfsdk_pageview.h"
55#include "fpdfsdk/cpdfsdk_renderpage.h"
56#include "fxjs/ijs_runtime.h"
57#include "public/fpdf_formfill.h"
60#include "fxjs/cfx_v8_array_buffer_allocator.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);
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)});
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();
279 g_bLibraryInitialized =
false;
288FPDF_EXPORT FPDF_BOOL FPDF_CALLCONV FPDF_SetPrintMode(
int mode) {
289 if (mode < FPDF_PRINTMODE_EMF ||
290 mode > FPDF_PRINTMODE_POSTSCRIPT3_TYPE42_PASSTHROUGH) {
294 g_pdfium_print_mode =
static_cast<WindowsPrintMode>(mode);
330 auto* pDoc = CPDFDocumentFromFPDFDocument(document);
334 auto* pContext =
static_cast<CPDFXFA_Context*>(pDoc->GetExtension());
336 return pContext->LoadXFADoc();
348 static_cast<
const uint8_t*>(data_buf),
static_cast<size_t>(size)));
349 return LoadDocumentImpl(
pdfium::MakeRetain<CFX_ReadOnlySpanStream>(data_span),
356 FPDF_BYTESTRING password) {
359 pdfium::make_span(
static_cast<
const uint8_t*>(data_buf), size));
360 return LoadDocumentImpl(
pdfium::MakeRetain<CFX_ReadOnlySpanStream>(data_span),
366 FPDF_BYTESTRING password) {
369 return LoadDocumentImpl(
pdfium::MakeRetain<CPDFSDK_CustomAccess>(pFileAccess),
416 return pDict ? pDict->GetIntegerFor(
"R") : -1;
438 auto* pContext =
static_cast<CPDFXFA_Context*>(pDoc->GetExtension());
440 return FPDFPageFromIPDFPage(
441 pContext->GetOrCreateXFAPage(page_index).Leak());
449 auto pPage =
pdfium::MakeRetain<CPDF_Page>(pDoc,
std::move(pDict));
450 pPage->AddPageImageCache();
451 pPage->ParseContent();
453 return FPDFPageFromIPDFPage(pPage.Leak());
483 *rect = FSRectFFromCFXFloatRect(pPage
->GetBBox());
490constexpr float kEpsilonSize = 0.01f;
492bool IsPageTooSmall(
const CPDF_Page* page) {
493 const CFX_SizeF& page_size = page->GetPageSize();
494 return page_size.width < kEpsilonSize || page_size.height < kEpsilonSize;
497bool IsScalingTooSmall(
const CFX_Matrix& matrix) {
500 if (matrix.a == 0.0f && matrix.d == 0.0f) {
501 horizontal = matrix.b;
504 horizontal = matrix.a;
507 return fabsf(horizontal) < kEpsilonSize || fabsf(vertical) < kEpsilonSize;
512RetainPtr<CFX_DIBitmap> GetMaskBitmap(CPDF_Page* pPage,
518 RetainPtr<
const CFX_DIBitmap> source,
519 const CFX_FloatRect& mask_box,
520 FX_RECT* bitmap_area) {
521 if (IsPageTooSmall(pPage))
524 FX_RECT page_rect(start_x, start_y, start_x + size_x, start_y + size_y);
525 CFX_Matrix matrix = pPage->GetDisplayMatrix(page_rect, rotate);
526 if (IsScalingTooSmall(matrix))
529 *bitmap_area = matrix.TransformRect(mask_box).GetOuterRect();
530 if (bitmap_area->IsEmpty())
534 RetainPtr<CFX_DIBitmap> pDst = pdfium::MakeRetain<CFX_DIBitmap>();
535 if (!pDst->Create(bitmap_area->Width(), bitmap_area->Height(),
536 FXDIB_Format::kBgra)) {
539 pDst->Clear(0x00ffffff);
540 pDst->TransferBitmap(bitmap_area->Width(), bitmap_area->Height(),
541 std::move(source), bitmap_area->left, bitmap_area->top);
545void RenderBitmap(CFX_RenderDevice* device,
546 RetainPtr<
const CFX_DIBitmap> source,
547 const FX_RECT& mask_area) {
548 int size_x_bm = mask_area.Width();
549 int size_y_bm = mask_area.Height();
550 if (size_x_bm == 0 || size_y_bm == 0)
554 RetainPtr<CFX_DIBitmap> dest = pdfium::MakeRetain<CFX_DIBitmap>();
555 if (!dest->Create(size_x_bm, size_y_bm, FXDIB_Format::kBgrx)) {
559 dest->Clear(0xffffffff);
560 dest->CompositeBitmap(0, 0, size_x_bm, size_y_bm, std::move(source), 0, 0,
561 BlendMode::kNormal,
nullptr,
false);
563 if (device->GetDeviceType() == DeviceType::kPrinter) {
564 device->StretchDIBits(std::move(dest), mask_area.left, mask_area.top,
565 size_x_bm, size_y_bm);
567 device->SetDIBits(std::move(dest), mask_area.left, mask_area.top);
573FPDF_EXPORT
void FPDF_CALLCONV FPDF_RenderPage(HDC dc,
581 CPDF_Page* pPage = CPDFPageFromFPDFPage(page);
585 auto owned_context = std::make_unique<CPDF_PageRenderContext>();
586 CPDF_PageRenderContext* context = owned_context.get();
587 CPDF_Page::RenderContextClearer clearer(pPage);
588 pPage->SetRenderContext(std::move(owned_context));
595 const bool bEnableImageMasks =
596 g_pdfium_print_mode == WindowsPrintMode::kEmfImageMasks;
597 const bool bNewBitmap = pPage->BackgroundAlphaNeeded() ||
598 (pPage->HasImageMask() && !bEnableImageMasks) ||
599 pPage->GetMaskBoundingBoxes().size() > 100;
600 const bool bHasMask = pPage->HasImageMask() && !bNewBitmap;
601 auto* render_data = CPDF_DocRenderData::FromDocument(pPage->GetDocument());
602 if (!bNewBitmap && !bHasMask) {
603 context->m_pDevice = std::make_unique<CPDF_WindowsRenderDevice>(
604 dc, render_data->GetPSFontTracker());
605 CPDFSDK_RenderPageWithContext(context, pPage, start_x, start_y, size_x,
606 size_y, rotate, flags,
612 RetainPtr<CFX_DIBitmap> pBitmap = pdfium::MakeRetain<CFX_DIBitmap>();
613 CHECK(pBitmap->Create(size_x, size_y, FXDIB_Format::kBgra));
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,
633 CPDF_WindowsRenderDevice win_dc(dc, render_data->GetPSFontTracker());
634 bool bitsStretched =
false;
635 if (win_dc.GetDeviceType() == DeviceType::kPrinter) {
636 auto dest_bitmap = pdfium::MakeRetain<CFX_DIBitmap>();
637 if (dest_bitmap->Create(size_x, size_y, FXDIB_Format::kBgrx)) {
638 fxcrt::Fill(dest_bitmap->GetWritableBuffer().first(pBitmap->GetPitch() *
641 dest_bitmap->CompositeBitmap(0, 0, size_x, size_y, pBitmap, 0, 0,
642 BlendMode::kNormal,
nullptr,
false);
643 win_dc.StretchDIBits(std::move(dest_bitmap), 0, 0, size_x, size_y);
644 bitsStretched =
true;
648 win_dc.SetDIBits(std::move(pBitmap), 0, 0);
654 const std::vector<CFX_FloatRect>& mask_boxes = pPage->GetMaskBoundingBoxes();
655 std::vector<FX_RECT> bitmap_areas(mask_boxes.size());
656 std::vector<RetainPtr<CFX_DIBitmap>> bitmaps(mask_boxes.size());
657 for (size_t i = 0; i < mask_boxes.size(); i++) {
658 bitmaps[i] = GetMaskBitmap(pPage, start_x, start_y, size_x, size_y, rotate,
659 pBitmap, mask_boxes[i], &bitmap_areas[i]);
660 context->m_pRenderer->Continue(
nullptr);
665 pPage->ClearRenderContext();
666 owned_context = std::make_unique<CPDF_PageRenderContext>();
667 context = owned_context.get();
668 pPage->SetRenderContext(std::move(owned_context));
669 context->m_pDevice = std::make_unique<CPDF_WindowsRenderDevice>(
670 dc, render_data->GetPSFontTracker());
671 context->m_pOptions = std::make_unique<CPDF_RenderOptions>();
672 context->m_pOptions->GetOptions().bBreakForMasks =
true;
674 CPDFSDK_RenderPageWithContext(context, pPage, start_x, start_y, size_x,
675 size_y, rotate, flags,
nullptr,
680 for (size_t i = 0; i < mask_boxes.size(); i++) {
683 RenderBitmap(context->m_pDevice.get(), std::move(bitmaps[i]),
687 context->m_pRenderer->Continue(
nullptr);
705 RetainPtr<CFX_DIBitmap> pBitmap(CFXDIBitmapFromFPDFBitmap(bitmap));
709 CHECK(!pBitmap->IsPremultiplied());
711 auto owned_context =
std::make_unique<CPDF_PageRenderContext>();
712 CPDF_PageRenderContext* context = owned_context.get();
714 pPage->SetRenderContext(
std::move(owned_context));
716#if defined(PDF_USE_SKIA)
717 CFX_DIBitmap::ScopedPremultiplier scoped_premultiplier(
718 pBitmap, CFX_DefaultRenderDevice::UseSkiaRenderer());
720 auto device =
std::make_unique<CFX_DefaultRenderDevice>();
721 device->AttachWithRgbByteOrder(
std::move(pBitmap),
723 context->m_pDevice =
std::move(device);
726 size_y
, rotate
, flags
, nullptr,
734 const FS_MATRIX* matrix,
735 const FS_RECTF* clipping,
742 RetainPtr<CFX_DIBitmap> pBitmap(CFXDIBitmapFromFPDFBitmap(bitmap));
746 CHECK(!pBitmap->IsPremultiplied());
748 auto owned_context =
std::make_unique<CPDF_PageRenderContext>();
749 CPDF_PageRenderContext* context = owned_context.get();
751 pPage->SetRenderContext(
std::move(owned_context));
753#if defined(PDF_USE_SKIA)
754 CFX_DIBitmap::ScopedPremultiplier scoped_premultiplier(
755 pBitmap, CFX_DefaultRenderDevice::UseSkiaRenderer());
757 auto device =
std::make_unique<CFX_DefaultRenderDevice>();
758 device->AttachWithRgbByteOrder(
std::move(pBitmap),
760 context->m_pDevice =
std::move(device);
775#if defined(PDF_USE_SKIA)
776FPDF_EXPORT
void FPDF_CALLCONV FPDF_RenderPageSkia(FPDF_SKIA_CANVAS canvas,
780 SkCanvas* sk_canvas = SkCanvasFromFPDFSkiaCanvas(canvas);
785 CPDF_Page* cpdf_page = CPDFPageFromFPDFPage(page);
790 auto owned_context = std::make_unique<CPDF_PageRenderContext>();
791 CPDF_PageRenderContext* context = owned_context.get();
792 CPDF_Page::RenderContextClearer clearer(cpdf_page);
793 cpdf_page->SetRenderContext(std::move(owned_context));
795 auto device = std::make_unique<CFX_DefaultRenderDevice>();
796 if (!device->AttachCanvas(*sk_canvas)) {
799 context->m_pDevice = std::move(device);
801 CPDFSDK_RenderPageWithContext(context, cpdf_page, 0, 0, size_x, size_y, 0, 0,
815 if (pPage->AsXFAPage())
821 pPage->AsPDFPage()->ClearView();
826 std::unique_ptr<CPDF_Document>(CPDFDocumentFromFPDFDocument(document));
843 if (!page || !page_x || !page_y)
847 const FX_RECT rect
(start_x
, start_y
, start_x + size_x
, start_y + size_y
);
849 pPage->DeviceToPage(rect, rotate, CFX_PointF(device_x, device_y));
850 if (!pos.has_value())
868 if (!page || !device_x || !device_y)
872 const FX_RECT rect
(start_x
, start_y
, start_x + size_x
, start_y + size_y
);
873 CFX_PointF page_point(
static_cast<
float>(page_x),
static_cast<
float>(page_y));
874 std::optional<
CFX_PointF> pos = pPage->PageToDevice(rect, rotate, page_point);
875 if (!pos.has_value())
878 *device_x = FXSYS_roundf(pos->x);
879 *device_y = FXSYS_roundf(pos->y);
886 auto pBitmap =
pdfium::MakeRetain<CFX_DIBitmap>();
887 if (!pBitmap->Create(width, height,
892 CHECK(!pBitmap->IsPremultiplied());
895 return FPDFBitmapFromCFXDIBitmap(pBitmap.Leak());
909 UnownedPtr<uint8_t> pChecker(
static_cast<uint8_t*>(first_scan));
910 auto pBitmap =
pdfium::MakeRetain<CFX_DIBitmap>();
911 if (!pBitmap->Create(width, height, fx_format, pChecker, stride)) {
915 CHECK(!pBitmap->IsPremultiplied());
918 return FPDFBitmapFromCFXDIBitmap(pBitmap.Leak());
922 RetainPtr<CFX_DIBitmap> pBitmap(CFXDIBitmapFromFPDFBitmap(bitmap));
927 switch (pBitmap->GetFormat()) {
948 RetainPtr<CFX_DIBitmap> pBitmap(CFXDIBitmapFromFPDFBitmap(bitmap));
952 CHECK(!pBitmap->IsPremultiplied());
956 if (!right.IsValid()) {
962 if (!bottom.IsValid()) {
966 FX_RECT fill_rect(left, top, right.ValueOrDie(), bottom.ValueOrDie());
968 if (!pBitmap->IsAlphaFormat()) {
973 const int bpp = pBitmap->GetBPP();
975 CFX_DefaultRenderDevice device;
977 return device
.FillRect(fill_rect,
static_cast<uint32_t>(color));
992 for (
int row = fill_rect
.top; row < row_end; ++row) {
993 auto span32 = pBitmap->GetWritableScanlineAs<uint32_t>(row).subspan(
995 fxcrt::Fill(span32,
static_cast<uint32_t>(color));
1004 for (
int row = fill_rect
.top; row < row_end; ++row) {
1006 pBitmap->GetWritableScanlineAs<
FX_BGR_STRUCT<uint8_t>>(row).subspan(
1008 fxcrt::Fill(bgr_span, bgr);
1014 RetainPtr<CFX_DIBitmap> pBitmap(CFXDIBitmapFromFPDFBitmap(bitmap));
1015 return pBitmap ? pBitmap->GetWritableBuffer().data() :
nullptr;
1019 RetainPtr<CFX_DIBitmap> pBitmap(CFXDIBitmapFromFPDFBitmap(bitmap));
1020 return pBitmap ? pBitmap->GetWidth() : 0;
1024 RetainPtr<CFX_DIBitmap> pBitmap(CFXDIBitmapFromFPDFBitmap(bitmap));
1025 return pBitmap ? pBitmap->GetHeight() : 0;
1029 RetainPtr<CFX_DIBitmap> pBitmap(CFXDIBitmapFromFPDFBitmap(bitmap));
1030 return pBitmap ? pBitmap->GetPitch() : 0;
1049#ifdef PDF_ENABLE_XFA
1050 if (page_index < 0 || page_index >= FPDF_GetPageCount(document))
1053 auto* pContext =
static_cast<CPDFXFA_Context*>(pDoc->GetExtension());
1055 RetainPtr<CPDFXFA_Page> pPage = pContext->GetOrCreateXFAPage(page_index);
1059 size->width = pPage->GetPageWidth();
1060 size->height = pPage->GetPageHeight();
1069 auto page =
pdfium::MakeRetain<CPDF_Page>(pDoc,
std::move(pDict));
1070 page->AddPageImageCache();
1071 size->width = page->GetPageWidth();
1072 size->height = page->GetPageHeight();
1080 if (!width || !height)
1087 *width = size.width;
1088 *height = size.height;
1124 return pArray ? pArray->size() : 0;
1131 if (!pArray || index >= pArray->size())
1133 return pArray->GetIntegerAt(index);
1140 return DuplexUndefined;
1143 if (
"Simplex" == duplex)
1145 if (
"DuplexFlipShortEdge" == duplex)
1146 return DuplexFlipShortEdge;
1147 if (
"DuplexFlipLongEdge" == duplex)
1148 return DuplexFlipLongEdge;
1149 return DuplexUndefined;
1154 FPDF_BYTESTRING key,
1156 unsigned long length) {
1163 if (!bsVal.has_value()) {
1167 return NulTerminateMaybeCopyAndReturnLength(
1168 bsVal.value(),
UNSAFE_BUFFERS(SpanFromFPDFApiArgs(buffer, length)));
1181 auto name_tree = CPDF_NameTree::Create(pDoc,
"Dests");
1185 count += pOldStyleDests->size();
1186 return count.ValueOrDefault(0);
1191 if (!name || name[0] == 0)
1206FPDF_EXPORT
const char* FPDF_CALLCONV FPDF_GetRecommendedV8Flags() {
1213FPDF_EXPORT
void* FPDF_CALLCONV FPDF_GetArrayBufferAllocatorSharedInstance() {
1217 static auto* s_allocator =
new CFX_V8ArrayBufferAllocator();
1222#ifdef PDF_ENABLE_XFA
1223FPDF_EXPORT FPDF_RESULT FPDF_CALLCONV FPDF_BStr_Init(FPDF_BSTR* bstr) {
1227 bstr->str =
nullptr;
1232FPDF_EXPORT FPDF_RESULT FPDF_CALLCONV FPDF_BStr_Set(FPDF_BSTR* bstr,
1239 length = pdfium::checked_cast<
int>(strlen(cstr));
1242 FPDF_BStr_Clear(bstr);
1247 bstr->str = FX_Alloc(
char, length + 1);
1248 }
else if (bstr->len < length) {
1249 bstr->str = FX_Realloc(
char, bstr->str, length + 1);
1255 bstr->str[length] = 0;
1256 FXSYS_memcpy(bstr->str, cstr, length);
1262FPDF_EXPORT FPDF_RESULT FPDF_CALLCONV FPDF_BStr_Clear(FPDF_BSTR* bstr) {
1268 bstr->str =
nullptr;
1293 auto name_tree = CPDF_NameTree::Create(pDoc,
"Dests");
1294 size_t name_tree_count = name_tree ? name_tree->GetCount() : 0;
1297 if (
static_cast<size_t>(index) >= name_tree_count) {
1305 checked_count += pDest->size();
1306 if (!checked_count.IsValid() || index >= checked_count.ValueOrDie())
1309 index -= name_tree_count;
1313 for (
const auto& it : locker) {
1314 bsName = it.first.AsStringView();
1315 pDestObj = it.second;
1320 wsName = PDF_DecodeText(bsName.unsigned_span());
1322 pDestObj = name_tree->LookupValueAndName(index, &wsName);
1331 if (!pDestObj->IsArray())
1335 int len =
pdfium::checked_cast<
int>(utf16Name.GetLength());
1338 }
else if (len <= *buflen) {
1342 fxcrt::Copy(utf16Name.span(), buffer_span);
1347 return FPDFDestFromCPDFArray(pDestObj->AsArray());
1355 return fxcrt::CollectionSize<
int>(
1356 GetXFAPackets(GetXFAEntryFromDocument(doc)));
1363 unsigned long buflen) {
1365 if (!doc || index < 0)
1368 std::vector<XFAPacket> xfa_packets =
1369 GetXFAPackets(GetXFAEntryFromDocument(doc));
1370 if (
static_cast<size_t>(index) >= xfa_packets.size()) {
1374 return NulTerminateMaybeCopyAndReturnLength(
1375 xfa_packets[index].name,
1383 unsigned long buflen,
1384 unsigned long* out_buflen) {
1386 if (!doc || index < 0 || !out_buflen)
1389 std::vector<XFAPacket> xfa_packets =
1390 GetXFAPackets(GetXFAEntryFromDocument(doc));
1391 if (
static_cast<size_t>(index) >= xfa_packets.size())
1395 *out_buflen = DecodeStreamMaybeCopyAndReturnLength(
1396 xfa_packets[index].data,
1398 static_cast<size_t>(buflen))));
1404 unsigned int* buffer,
1405 unsigned long length) {
1412 std::vector<
unsigned int> trailer_ends = parser->GetTrailerEnds();
1413 const unsigned long trailer_ends_len =
1414 fxcrt::CollectionSize<
unsigned long>(trailer_ends);
1415 if (buffer && length >= trailer_ends_len) {
1417 fxcrt::Copy(trailer_ends,
1421 return trailer_ends_len;
fxcrt::ByteString ByteString
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()
std::vector< RetainPtr< CPDF_Object > >::const_iterator const_iterator
bool GetBooleanFor(const ByteString &key, bool bDefault) const
RetainPtr< const CPDF_Array > GetArrayFor(const ByteString &key) const
std::map< ByteString, RetainPtr< CPDF_Object >, std::less<> > DictMap
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)
ByteString ToUTF16LE() const
#define UNSAFE_BUFFERS(...)
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)
FXDIB_Format FXDIBFormatFromFPDFFormat(int format)
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 FPDF_BOOL 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_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 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
CFX_PTemplate< float > CFX_PointF
void FX_DestroyMemoryAllocators()
void FX_InitializeMemoryAllocators()
pdfium::CheckedNumeric< uint32_t > FX_SAFE_UINT32
pdfium::CheckedNumeric< int32_t > FX_SAFE_INT32
uint32_t FXSYS_GetLastError()
bool operator==(const char *lhs, const ByteString &rhs)
fxcrt::ByteStringView ByteStringView
void Intersect(const FX_RECT &src)
constexpr FX_RECT(int l, int t, int r, int b)
fxcrt::WideString WideString