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.
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 #include "third_party/base/ptr_util.h"
16 
17 static_assert(static_cast<int>(UnsupportedFeature::kDocumentXFAForm) ==
18                   FPDF_UNSP_DOC_XFAFORM,
19               "UnsupportedFeature::kDocumentXFAForm value mismatch");
20 static_assert(
21     static_cast<int>(UnsupportedFeature::kDocumentPortableCollection) ==
22         FPDF_UNSP_DOC_PORTABLECOLLECTION,
23     "UnsupportedFeature::kDocumentPortableCollection value mismatch");
24 static_assert(static_cast<int>(UnsupportedFeature::kDocumentAttachment) ==
25                   FPDF_UNSP_DOC_ATTACHMENT,
26               "UnsupportedFeature::kDocumentAttachment value mismatch");
27 static_assert(static_cast<int>(UnsupportedFeature::kDocumentSecurity) ==
28                   FPDF_UNSP_DOC_SECURITY,
29               "UnsupportedFeature::kDocumentSecurity value mismatch");
30 static_assert(static_cast<int>(UnsupportedFeature::kDocumentSharedReview) ==
31                   FPDF_UNSP_DOC_SHAREDREVIEW,
32               "UnsupportedFeature::kDocumentSharedReview value mismatch");
33 static_assert(
34     static_cast<int>(UnsupportedFeature::kDocumentSharedFormAcrobat) ==
35         FPDF_UNSP_DOC_SHAREDFORM_ACROBAT,
36     "UnsupportedFeature::kDocumentSharedFormAcrobat value mismatch");
37 static_assert(
38     static_cast<int>(UnsupportedFeature::kDocumentSharedFormFilesystem) ==
39         FPDF_UNSP_DOC_SHAREDFORM_FILESYSTEM,
40     "UnsupportedFeature::kDocumentSharedFormFilesystem value mismatch");
41 static_assert(static_cast<int>(UnsupportedFeature::kDocumentSharedFormEmail) ==
42                   FPDF_UNSP_DOC_SHAREDFORM_EMAIL,
43               "UnsupportedFeature::kDocumentSharedFormEmail value mismatch");
44 static_assert(static_cast<int>(UnsupportedFeature::kAnnotation3d) ==
45                   FPDF_UNSP_ANNOT_3DANNOT,
46               "UnsupportedFeature::kAnnotation3d value mismatch");
47 static_assert(static_cast<int>(UnsupportedFeature::kAnnotationMovie) ==
48                   FPDF_UNSP_ANNOT_MOVIE,
49               "UnsupportedFeature::kAnnotationMovie value mismatch");
50 static_assert(static_cast<int>(UnsupportedFeature::kAnnotationSound) ==
51                   FPDF_UNSP_ANNOT_SOUND,
52               "UnsupportedFeature::kAnnotationSound value mismatch");
53 static_assert(static_cast<int>(UnsupportedFeature::kAnnotationScreenMedia) ==
54                   FPDF_UNSP_ANNOT_SCREEN_MEDIA,
55               "UnsupportedFeature::kAnnotationScreenMedia value mismatch");
56 static_assert(
57     static_cast<int>(UnsupportedFeature::kAnnotationScreenRichMedia) ==
58         FPDF_UNSP_ANNOT_SCREEN_RICHMEDIA,
59     "UnsupportedFeature::kAnnotationScreenRichMedia value mismatch");
60 static_assert(static_cast<int>(UnsupportedFeature::kAnnotationAttachment) ==
61                   FPDF_UNSP_ANNOT_ATTACHMENT,
62               "UnsupportedFeature::kAnnotationAttachment value mismatch");
63 static_assert(static_cast<int>(UnsupportedFeature::kAnnotationSignature) ==
64                   FPDF_UNSP_ANNOT_SIG,
65               "UnsupportedFeature::kAnnotationSignature value mismatch");
66 
67 FPDF_EXPORT FPDF_BOOL FPDF_CALLCONV
FSDK_SetUnSpObjProcessHandler(UNSUPPORT_INFO * unsp_info)68 FSDK_SetUnSpObjProcessHandler(UNSUPPORT_INFO* unsp_info) {
69   if (!unsp_info || unsp_info->version != 1)
70     return false;
71 
72   SetPDFUnsupportInfo(unsp_info);
73   return true;
74 }
75 
FSDK_SetTimeFunction(time_t (* func)())76 FPDF_EXPORT void FPDF_CALLCONV FSDK_SetTimeFunction(time_t (*func)()) {
77   FXSYS_SetTimeFunction(func);
78 }
79 
80 FPDF_EXPORT void FPDF_CALLCONV
FSDK_SetLocaltimeFunction(struct tm * (* func)(const time_t * tp))81 FSDK_SetLocaltimeFunction(struct tm* (*func)(const time_t* tp)) {
82   FXSYS_SetLocaltimeFunction(func);
83 }
84 
FPDFDoc_GetPageMode(FPDF_DOCUMENT document)85 FPDF_EXPORT int FPDF_CALLCONV FPDFDoc_GetPageMode(FPDF_DOCUMENT document) {
86   CPDF_Document* pDoc = CPDFDocumentFromFPDFDocument(document);
87   if (!pDoc)
88     return PAGEMODE_UNKNOWN;
89 
90   const CPDF_Dictionary* pRoot = pDoc->GetRoot();
91   if (!pRoot)
92     return PAGEMODE_UNKNOWN;
93 
94   const CPDF_Object* pName = pRoot->GetObjectFor("PageMode");
95   if (!pName)
96     return PAGEMODE_USENONE;
97 
98   ByteString strPageMode = pName->GetString();
99   if (strPageMode.IsEmpty() || strPageMode.EqualNoCase("UseNone"))
100     return PAGEMODE_USENONE;
101   if (strPageMode.EqualNoCase("UseOutlines"))
102     return PAGEMODE_USEOUTLINES;
103   if (strPageMode.EqualNoCase("UseThumbs"))
104     return PAGEMODE_USETHUMBS;
105   if (strPageMode.EqualNoCase("FullScreen"))
106     return PAGEMODE_FULLSCREEN;
107   if (strPageMode.EqualNoCase("UseOC"))
108     return PAGEMODE_USEOC;
109   if (strPageMode.EqualNoCase("UseAttachments"))
110     return PAGEMODE_USEATTACHMENTS;
111 
112   return PAGEMODE_UNKNOWN;
113 }
114