diff options
author | Jay Berkenbilt <ejb@ql.org> | 2020-12-23 12:12:49 +0100 |
---|---|---|
committer | Jay Berkenbilt <ejb@ql.org> | 2020-12-28 18:58:19 +0100 |
commit | 39bfa0130713defc9abb478a70717ca07377cdab (patch) | |
tree | 18b6370d5f2f7d10a3f1ef09a8f0dd3b9281bd3c /include | |
parent | 1fb26f08ad91d08f67ac30e2557ddcadd8b9ccac (diff) | |
download | qpdf-39bfa0130713defc9abb478a70717ca07377cdab.tar.zst |
Implement user-provided stream filters
Refactor QPDF_Stream to use stream filter classes to handle supported
stream filters as well.
Diffstat (limited to 'include')
-rw-r--r-- | include/qpdf/QPDF.hh | 17 | ||||
-rw-r--r-- | include/qpdf/QPDFStreamFilter.hh | 78 |
2 files changed, 95 insertions, 0 deletions
diff --git a/include/qpdf/QPDF.hh b/include/qpdf/QPDF.hh index 285ba1e3..b0e9b717 100644 --- a/include/qpdf/QPDF.hh +++ b/include/qpdf/QPDF.hh @@ -31,6 +31,8 @@ #include <list> #include <iostream> #include <vector> +#include <functional> +#include <memory> #include <qpdf/QIntC.hh> #include <qpdf/QPDFExc.hh> @@ -39,6 +41,7 @@ #include <qpdf/QPDFXRefEntry.hh> #include <qpdf/QPDFObjectHandle.hh> #include <qpdf/QPDFTokenizer.hh> +#include <qpdf/QPDFStreamFilter.hh> #include <qpdf/Buffer.hh> #include <qpdf/InputSource.hh> @@ -132,6 +135,20 @@ class QPDF QPDF_DLL void emptyPDF(); + // From 10.1: register a new filter implementation for a specific + // stream filter. You can add your own implementations for new + // filter types or override existing ones provided by the library. + // Registered stream filters are used for decoding only as you can + // override encoding with stream data providers. For example, you + // could use this method to support for one of the other filter + // types by using additional third-party libraries that qpdf does + // not presently use. The standard filters are implemented using + // QPDFStreamFilter classes. + QPDF_DLL + static void registerStreamFilter( + std::string const& filter_name, + std::function<std::shared_ptr<QPDFStreamFilter> ()> factory); + // Parameter settings // By default, warning messages are issued to std::cerr and output diff --git a/include/qpdf/QPDFStreamFilter.hh b/include/qpdf/QPDFStreamFilter.hh new file mode 100644 index 00000000..5fdcf5ca --- /dev/null +++ b/include/qpdf/QPDFStreamFilter.hh @@ -0,0 +1,78 @@ +// Copyright (c) 2005-2020 Jay Berkenbilt +// +// This file is part of qpdf. +// +// Licensed under the Apache License, Version 2.0 (the "License"); +// you may not use this file except in compliance with the License. +// You may obtain a copy of the License at +// +// http://www.apache.org/licenses/LICENSE-2.0 +// +// Unless required by applicable law or agreed to in writing, software +// distributed under the License is distributed on an "AS IS" BASIS, +// WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. +// See the License for the specific language governing permissions and +// limitations under the License. +// +// Versions of qpdf prior to version 7 were released under the terms +// of version 2.0 of the Artistic License. At your option, you may +// continue to consider qpdf to be licensed under those terms. Please +// see the manual for additional information. + +#ifndef QPDFSTREAMFILTER_HH +#define QPDFSTREAMFILTER_HH + +#include <qpdf/DLL.h> +#include <qpdf/QPDFObjectHandle.hh> +#include <qpdf/Pipeline.hh> + +class QPDF_DLL_CLASS QPDFStreamFilter +{ + public: + QPDF_DLL + QPDFStreamFilter() = default; + + QPDF_DLL + virtual ~QPDFStreamFilter() = default; + + // A QPDFStreamFilter class must implement, at a minimum, + // setDecodeParms() and getDecodePipeline(). QPDF will always call + // setDecodeParms() before calling getDecodePipeline(). It is + // expected that you will store any needed information from + // decode_parms (or the decode_parms object iself) in your + // instance so that it can be used to construct the decode + // pipeline. + + // Return a boolean indicating whether your filter can proceed + // with the given /DecodeParms. The default implementation accepts + // a null object and rejects everything else. + QPDF_DLL + virtual bool setDecodeParms(QPDFObjectHandle decode_parms); + + // Return a pipeline that will decode data encoded with your + // filter. Your implementation must ensure that the pipeline is + // deleted when the instance of your class is destroyed. + QPDF_DLL + virtual Pipeline* getDecodePipeline(Pipeline* next) = 0; + + // If your filter implements "specialized" compression or lossy + // compression, override one or both of these methods. The default + // implementations return false. See comments in QPDFWriter for + // details. QPDF defines specialized compression as non-lossy + // compression not intended for general-purpose data. qpdf, by + // default, doesn't mess with streams that are compressed with + // specialized compression, the idea being that the decision to + // use that compression scheme would fall outside of what + // QPDFWriter would know anything about, so any attempt to decode + // and re-encode would probably be undesirable. + QPDF_DLL + virtual bool isSpecializedCompression(); + QPDF_DLL + virtual bool isLossyCompression(); + + private: + QPDFStreamFilter(QPDFStreamFilter const&) = delete; + QPDFStreamFilter& operator=(QPDFStreamFilter const&) = delete; +}; + +#endif // QPDFSTREAMFILTER_HH |