1 // Copyright 2017 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 #ifndef PUBLIC_CPP_FPDF_DELETERS_H_
6 #define PUBLIC_CPP_FPDF_DELETERS_H_
7 
8 #include "public/fpdf_annot.h"
9 #include "public/fpdf_dataavail.h"
10 #include "public/fpdf_edit.h"
11 #include "public/fpdf_formfill.h"
12 #include "public/fpdf_javascript.h"
13 #include "public/fpdf_structtree.h"
14 #include "public/fpdf_text.h"
15 #include "public/fpdf_transformpage.h"
16 #include "public/fpdfview.h"
17 
18 // Custom deleters for using FPDF_* types with std::unique_ptr<>.
19 
20 struct FPDFAnnotationDeleter {
operatorFPDFAnnotationDeleter21   inline void operator()(FPDF_ANNOTATION annot) { FPDFPage_CloseAnnot(annot); }
22 };
23 
24 struct FPDFAvailDeleter {
operatorFPDFAvailDeleter25   inline void operator()(FPDF_AVAIL avail) { FPDFAvail_Destroy(avail); }
26 };
27 
28 struct FPDFBitmapDeleter {
operatorFPDFBitmapDeleter29   inline void operator()(FPDF_BITMAP bitmap) { FPDFBitmap_Destroy(bitmap); }
30 };
31 
32 struct FPDFClipPathDeleter {
operatorFPDFClipPathDeleter33   inline void operator()(FPDF_CLIPPATH clip_path) {
34     FPDF_DestroyClipPath(clip_path);
35   }
36 };
37 
38 struct FPDFDocumentDeleter {
operatorFPDFDocumentDeleter39   inline void operator()(FPDF_DOCUMENT doc) { FPDF_CloseDocument(doc); }
40 };
41 
42 struct FPDFFontDeleter {
operatorFPDFFontDeleter43   inline void operator()(FPDF_FONT font) { FPDFFont_Close(font); }
44 };
45 
46 struct FPDFFormHandleDeleter {
operatorFPDFFormHandleDeleter47   inline void operator()(FPDF_FORMHANDLE form) {
48     FPDFDOC_ExitFormFillEnvironment(form);
49   }
50 };
51 
52 struct FPDFJavaScriptActionDeleter {
operatorFPDFJavaScriptActionDeleter53   inline void operator()(FPDF_JAVASCRIPT_ACTION javascript) {
54     FPDFDoc_CloseJavaScriptAction(javascript);
55   }
56 };
57 
58 struct FPDFPageDeleter {
operatorFPDFPageDeleter59   inline void operator()(FPDF_PAGE page) { FPDF_ClosePage(page); }
60 };
61 
62 struct FPDFPageLinkDeleter {
operatorFPDFPageLinkDeleter63   inline void operator()(FPDF_PAGELINK pagelink) {
64     FPDFLink_CloseWebLinks(pagelink);
65   }
66 };
67 
68 struct FPDFPageObjectDeleter {
operatorFPDFPageObjectDeleter69   inline void operator()(FPDF_PAGEOBJECT object) {
70     FPDFPageObj_Destroy(object);
71   }
72 };
73 
74 struct FPDFStructTreeDeleter {
operatorFPDFStructTreeDeleter75   inline void operator()(FPDF_STRUCTTREE tree) { FPDF_StructTree_Close(tree); }
76 };
77 
78 struct FPDFTextFindDeleter {
operatorFPDFTextFindDeleter79   inline void operator()(FPDF_SCHHANDLE handle) { FPDFText_FindClose(handle); }
80 };
81 
82 struct FPDFTextPageDeleter {
operatorFPDFTextPageDeleter83   inline void operator()(FPDF_TEXTPAGE text) { FPDFText_ClosePage(text); }
84 };
85 
86 #endif  // PUBLIC_CPP_FPDF_DELETERS_H_
87