diff options
Diffstat (limited to 'include')
-rw-r--r-- | include/qpdf/Buffer.hh | 7 | ||||
-rw-r--r-- | include/qpdf/DLL.h | 6 | ||||
-rw-r--r-- | include/qpdf/Pl_Buffer.hh | 8 | ||||
-rw-r--r-- | include/qpdf/QPDF.hh | 2 | ||||
-rw-r--r-- | include/qpdf/qpdf-c.h | 33 |
5 files changed, 43 insertions, 13 deletions
diff --git a/include/qpdf/Buffer.hh b/include/qpdf/Buffer.hh index c0669c6c..d0e6eda0 100644 --- a/include/qpdf/Buffer.hh +++ b/include/qpdf/Buffer.hh @@ -24,6 +24,7 @@ #include <cstddef> #include <memory> +#include <string> class Buffer { @@ -35,11 +36,15 @@ class Buffer // object is destroyed. QPDF_DLL Buffer(size_t size); + QPDF_DLL + Buffer(std::string&& content); // Create a Buffer object whose memory is owned by the caller and will not be freed when the // Buffer is destroyed. QPDF_DLL Buffer(unsigned char* buf, size_t size); + QPDF_DLL + Buffer(std::string& content); [[deprecated("Move Buffer or use Buffer::copy instead")]] QPDF_DLL Buffer(Buffer const&); [[deprecated("Move Buffer or use Buffer::copy instead")]] QPDF_DLL Buffer& @@ -75,8 +80,10 @@ class Buffer private: Members(size_t size, unsigned char* buf, bool own_memory); + Members(std::string&& content); Members(Members const&) = delete; + std::string str; bool own_memory; size_t size; unsigned char* buf; diff --git a/include/qpdf/DLL.h b/include/qpdf/DLL.h index 74c3c62e..6dd5137e 100644 --- a/include/qpdf/DLL.h +++ b/include/qpdf/DLL.h @@ -25,9 +25,9 @@ /* The first version of qpdf to include the version constants is 10.6.0. */ #define QPDF_MAJOR_VERSION 11 -#define QPDF_MINOR_VERSION 6 -#define QPDF_PATCH_VERSION 3 -#define QPDF_VERSION "11.6.3" +#define QPDF_MINOR_VERSION 7 +#define QPDF_PATCH_VERSION 0 +#define QPDF_VERSION "11.7.0" /* * This file defines symbols that control the which functions, diff --git a/include/qpdf/Pl_Buffer.hh b/include/qpdf/Pl_Buffer.hh index 5030e10e..5def8b4f 100644 --- a/include/qpdf/Pl_Buffer.hh +++ b/include/qpdf/Pl_Buffer.hh @@ -33,7 +33,7 @@ #include <qpdf/PointerHolder.hh> // unused -- remove in qpdf 12 (see #785) #include <memory> -#include <vector> +#include <string> class QPDF_DLL_CLASS Pl_Buffer: public Pipeline { @@ -64,6 +64,10 @@ class QPDF_DLL_CLASS Pl_Buffer: public Pipeline QPDF_DLL void getMallocBuffer(unsigned char** buf, size_t* len); + // Same as getBuffer but returns the result as a string. + QPDF_DLL + std::string getString(); + private: class QPDF_DLL_PRIVATE Members { @@ -78,7 +82,7 @@ class QPDF_DLL_CLASS Pl_Buffer: public Pipeline Members(Members const&) = delete; bool ready{true}; - std::vector<unsigned char> data; + std::string data; }; std::shared_ptr<Members> m; diff --git a/include/qpdf/QPDF.hh b/include/qpdf/QPDF.hh index 2ca6005c..ffe07559 100644 --- a/include/qpdf/QPDF.hh +++ b/include/qpdf/QPDF.hh @@ -1133,7 +1133,7 @@ class QPDF Pipeline*& pipeline, QPDFObjGen const& og, QPDFObjectHandle& stream_dict, - std::vector<std::shared_ptr<Pipeline>>& heap); + std::unique_ptr<Pipeline>& heap); // Methods to support object copying void reserveObjects(QPDFObjectHandle foreign, ObjCopier& obj_copier, bool top); diff --git a/include/qpdf/qpdf-c.h b/include/qpdf/qpdf-c.h index d4305602..f989ba15 100644 --- a/include/qpdf/qpdf-c.h +++ b/include/qpdf/qpdf-c.h @@ -21,21 +21,23 @@ #define QPDF_C_H /* - * This file defines a basic "C" API for qpdf. It provides access to a subset of the QPDF library's + * This file defines a basic "C" API for qpdf. It provides access to a subset of the QPDF library's * capabilities to make them accessible to callers who can't handle calling C++ functions or working - * with C++ classes. This may be especially useful to Windows users who are accessing the qpdf DLL + * with C++ classes. This may be especially useful to Windows users who are accessing the qpdf DLL * directly or to other people programming in non-C/C++ languages that can call C code but not C++ - * code. + * code. Starting with qpdf 11.7, it is possible to write your own `extern "C"` functions that + * interoperate with the C API. * * There are several things to keep in mind when using the C API. * * Error handling is tricky because the underlying C++ API uses exception handling. See "ERROR * HANDLING" below for a detailed explanation. * - * The C API is not as rich as the C++ API. For any operations that involve actually - * manipulating PDF objects, you must use the C++ API. The C API is primarily useful for doing - * basic transformations on PDF files similar to what you might do with the qpdf command-line - * tool. + * The C API is not as rich as the C++ API. For many operations, you must use the C++ API. The C + * API is primarily useful for doing basic transformations on PDF files similar to what you + * might do with the qpdf command-line tool. You can write your own `extern "C"` functions in + * C++ that interoperate with the C API by using qpdf_c_get_qpdf and qpdf_c_wrap which were + * introduced in qpdf 11.7.0. * * These functions store their state in a qpdf_data object. Individual instances of qpdf_data * are not thread-safe: although you may access different qpdf_data objects from different @@ -990,6 +992,23 @@ extern "C" { QPDF_ERROR_CODE qpdf_remove_page(qpdf_data qpdf, qpdf_oh page); #ifdef __cplusplus } + +// These C++ functions make it easier to write C++ code that interoperates with the C API. +// See examples/extend-c-api. + +# include <functional> +# include <memory> + +# include <qpdf/QPDF.hh> + +// Retrieve the real QPDF object attached to this qpdf_data. +QPDF_DLL +std::shared_ptr<QPDF> qpdf_c_get_qpdf(qpdf_data qpdf); + +// Wrap a C++ function that may throw an exception to translate the exception for retrieval using +// the normal QPDF C API methods. +QPDF_DLL +QPDF_ERROR_CODE qpdf_c_wrap(qpdf_data qpdf, std::function<void()> fn); #endif #endif /* QPDF_C_H */ |