xref: /aosp_15_r20/external/pdfium/fpdfsdk/fpdf_ext.cpp (revision 3ac0a46f773bac49fa9476ec2b1cf3f8da5ec3a4)
1 // Copyright 2014 The PDFium Authors
2 // Use of this source code is governed by a BSD-style license that can be
3 // found in the LICENSE file.
4 
5 // Original code copyright 2014 Foxit Software Inc. http://www.foxitsoftware.com
6 
7 #include "public/fpdf_ext.h"
8 
9 #include "core/fpdfapi/parser/cpdf_dictionary.h"
10 #include "core/fpdfapi/parser/cpdf_document.h"
11 #include "core/fpdfdoc/cpdf_interactiveform.h"
12 #include "core/fpdfdoc/cpdf_metadata.h"
13 #include "core/fxcrt/fx_extension.h"
14 #include "fpdfsdk/cpdfsdk_helpers.h"
15 
16 static_assert(static_cast<int>(UnsupportedFeature::kDocumentXFAForm) ==
17                   FPDF_UNSP_DOC_XFAFORM,
18               "UnsupportedFeature::kDocumentXFAForm value mismatch");
19 static_assert(
20     static_cast<int>(UnsupportedFeature::kDocumentPortableCollection) ==
21         FPDF_UNSP_DOC_PORTABLECOLLECTION,
22     "UnsupportedFeature::kDocumentPortableCollection value mismatch");
23 static_assert(static_cast<int>(UnsupportedFeature::kDocumentAttachment) ==
24                   FPDF_UNSP_DOC_ATTACHMENT,
25               "UnsupportedFeature::kDocumentAttachment value mismatch");
26 static_assert(static_cast<int>(UnsupportedFeature::kDocumentSecurity) ==
27                   FPDF_UNSP_DOC_SECURITY,
28               "UnsupportedFeature::kDocumentSecurity value mismatch");
29 static_assert(static_cast<int>(UnsupportedFeature::kDocumentSharedReview) ==
30                   FPDF_UNSP_DOC_SHAREDREVIEW,
31               "UnsupportedFeature::kDocumentSharedReview value mismatch");
32 static_assert(
33     static_cast<int>(UnsupportedFeature::kDocumentSharedFormAcrobat) ==
34         FPDF_UNSP_DOC_SHAREDFORM_ACROBAT,
35     "UnsupportedFeature::kDocumentSharedFormAcrobat value mismatch");
36 static_assert(
37     static_cast<int>(UnsupportedFeature::kDocumentSharedFormFilesystem) ==
38         FPDF_UNSP_DOC_SHAREDFORM_FILESYSTEM,
39     "UnsupportedFeature::kDocumentSharedFormFilesystem value mismatch");
40 static_assert(static_cast<int>(UnsupportedFeature::kDocumentSharedFormEmail) ==
41                   FPDF_UNSP_DOC_SHAREDFORM_EMAIL,
42               "UnsupportedFeature::kDocumentSharedFormEmail value mismatch");
43 static_assert(static_cast<int>(UnsupportedFeature::kAnnotation3d) ==
44                   FPDF_UNSP_ANNOT_3DANNOT,
45               "UnsupportedFeature::kAnnotation3d value mismatch");
46 static_assert(static_cast<int>(UnsupportedFeature::kAnnotationMovie) ==
47                   FPDF_UNSP_ANNOT_MOVIE,
48               "UnsupportedFeature::kAnnotationMovie value mismatch");
49 static_assert(static_cast<int>(UnsupportedFeature::kAnnotationSound) ==
50                   FPDF_UNSP_ANNOT_SOUND,
51               "UnsupportedFeature::kAnnotationSound value mismatch");
52 static_assert(static_cast<int>(UnsupportedFeature::kAnnotationScreenMedia) ==
53                   FPDF_UNSP_ANNOT_SCREEN_MEDIA,
54               "UnsupportedFeature::kAnnotationScreenMedia value mismatch");
55 static_assert(
56     static_cast<int>(UnsupportedFeature::kAnnotationScreenRichMedia) ==
57         FPDF_UNSP_ANNOT_SCREEN_RICHMEDIA,
58     "UnsupportedFeature::kAnnotationScreenRichMedia value mismatch");
59 static_assert(static_cast<int>(UnsupportedFeature::kAnnotationAttachment) ==
60                   FPDF_UNSP_ANNOT_ATTACHMENT,
61               "UnsupportedFeature::kAnnotationAttachment value mismatch");
62 static_assert(static_cast<int>(UnsupportedFeature::kAnnotationSignature) ==
63                   FPDF_UNSP_ANNOT_SIG,
64               "UnsupportedFeature::kAnnotationSignature value mismatch");
65 
66 FPDF_EXPORT FPDF_BOOL FPDF_CALLCONV
FSDK_SetUnSpObjProcessHandler(UNSUPPORT_INFO * unsp_info)67 FSDK_SetUnSpObjProcessHandler(UNSUPPORT_INFO* unsp_info) {
68   if (!unsp_info || unsp_info->version != 1)
69     return false;
70 
71   SetPDFUnsupportInfo(unsp_info);
72   return true;
73 }
74 
FSDK_SetTimeFunction(time_t (* func)())75 FPDF_EXPORT void FPDF_CALLCONV FSDK_SetTimeFunction(time_t (*func)()) {
76   FXSYS_SetTimeFunction(func);
77 }
78 
79 FPDF_EXPORT void FPDF_CALLCONV
FSDK_SetLocaltimeFunction(struct tm * (* func)(const time_t * tp))80 FSDK_SetLocaltimeFunction(struct tm* (*func)(const time_t* tp)) {
81   FXSYS_SetLocaltimeFunction(func);
82 }
83 
FPDFDoc_GetPageMode(FPDF_DOCUMENT document)84 FPDF_EXPORT int FPDF_CALLCONV FPDFDoc_GetPageMode(FPDF_DOCUMENT document) {
85   CPDF_Document* pDoc = CPDFDocumentFromFPDFDocument(document);
86   if (!pDoc)
87     return PAGEMODE_UNKNOWN;
88 
89   const CPDF_Dictionary* pRoot = pDoc->GetRoot();
90   if (!pRoot)
91     return PAGEMODE_UNKNOWN;
92 
93   RetainPtr<const CPDF_Object> pName = pRoot->GetObjectFor("PageMode");
94   if (!pName)
95     return PAGEMODE_USENONE;
96 
97   ByteString strPageMode = pName->GetString();
98   if (strPageMode.IsEmpty() || strPageMode.EqualNoCase("UseNone"))
99     return PAGEMODE_USENONE;
100   if (strPageMode.EqualNoCase("UseOutlines"))
101     return PAGEMODE_USEOUTLINES;
102   if (strPageMode.EqualNoCase("UseThumbs"))
103     return PAGEMODE_USETHUMBS;
104   if (strPageMode.EqualNoCase("FullScreen"))
105     return PAGEMODE_FULLSCREEN;
106   if (strPageMode.EqualNoCase("UseOC"))
107     return PAGEMODE_USEOC;
108   if (strPageMode.EqualNoCase("UseAttachments"))
109     return PAGEMODE_USEATTACHMENTS;
110 
111   return PAGEMODE_UNKNOWN;
112 }
113