mirror of
https://github.com/qpdf/qpdf.git
synced 2024-06-09 21:52:26 +00:00
Add new methods QPDF::newStream
This commit is contained in:
parent
0a3c533186
commit
9ebabd1953
|
@ -382,6 +382,36 @@ class QPDF
|
||||||
QPDF_DLL
|
QPDF_DLL
|
||||||
std::map<QPDFObjGen, QPDFXRefEntry> getXRefTable();
|
std::map<QPDFObjGen, QPDFXRefEntry> getXRefTable();
|
||||||
|
|
||||||
|
// Public factory methods
|
||||||
|
|
||||||
|
// Create a new stream. A subsequent call must be made to
|
||||||
|
// replaceStreamData() to provide data for the stream. The stream's
|
||||||
|
// dictionary may be retrieved by calling getDict(), and the resulting
|
||||||
|
// dictionary may be modified. Alternatively, you can create a new
|
||||||
|
// dictionary and call replaceDict to install it.
|
||||||
|
QPDF_DLL
|
||||||
|
QPDFObjectHandle newStream();
|
||||||
|
|
||||||
|
// Create a new stream. Use the given buffer as the stream data. The
|
||||||
|
// stream dictionary's /Length key will automatically be set to the size of
|
||||||
|
// the data buffer. If additional keys are required, the stream's
|
||||||
|
// dictionary may be retrieved by calling getDict(), and the resulting
|
||||||
|
// dictionary may be modified. This method is just a convenient wrapper
|
||||||
|
// around the newStream() and replaceStreamData(). It is a convenience
|
||||||
|
// methods for streams that require no parameters beyond the stream length.
|
||||||
|
// Note that you don't have to deal with compression yourself if you use
|
||||||
|
// QPDFWriter. By default, QPDFWriter will automatically compress
|
||||||
|
// uncompressed stream data. Example programs are provided that
|
||||||
|
// illustrate this.
|
||||||
|
QPDF_DLL
|
||||||
|
QPDFObjectHandle newStream(std::shared_ptr<Buffer> data);
|
||||||
|
|
||||||
|
// Create new stream with data from string. This method will
|
||||||
|
// create a copy of the data rather than using the user-provided
|
||||||
|
// buffer as in the std::shared_ptr<Buffer> version of newStream.
|
||||||
|
QPDF_DLL
|
||||||
|
QPDFObjectHandle newStream(std::string const& data);
|
||||||
|
|
||||||
// Install this object handle as an indirect object and return an
|
// Install this object handle as an indirect object and return an
|
||||||
// indirect reference to it.
|
// indirect reference to it.
|
||||||
QPDF_DLL
|
QPDF_DLL
|
||||||
|
|
|
@ -2001,6 +2001,31 @@ QPDF::makeIndirectObject(QPDFObjectHandle oh)
|
||||||
return makeIndirectObject(QPDFObjectHandle::ObjAccessor::getObject(oh));
|
return makeIndirectObject(QPDFObjectHandle::ObjAccessor::getObject(oh));
|
||||||
}
|
}
|
||||||
|
|
||||||
|
QPDFObjectHandle
|
||||||
|
QPDF::newStream()
|
||||||
|
{
|
||||||
|
return makeIndirectObject(QPDF_Stream::create(
|
||||||
|
this, nextObjGen(), QPDFObjectHandle::newDictionary(), 0, 0));
|
||||||
|
}
|
||||||
|
|
||||||
|
QPDFObjectHandle
|
||||||
|
QPDF::newStream(std::shared_ptr<Buffer> data)
|
||||||
|
{
|
||||||
|
auto result = newStream();
|
||||||
|
result.replaceStreamData(
|
||||||
|
data, QPDFObjectHandle::newNull(), QPDFObjectHandle::newNull());
|
||||||
|
return result;
|
||||||
|
}
|
||||||
|
|
||||||
|
QPDFObjectHandle
|
||||||
|
QPDF::newStream(std::string const& data)
|
||||||
|
{
|
||||||
|
auto result = newStream();
|
||||||
|
result.replaceStreamData(
|
||||||
|
data, QPDFObjectHandle::newNull(), QPDFObjectHandle::newNull());
|
||||||
|
return result;
|
||||||
|
}
|
||||||
|
|
||||||
QPDFObjectHandle
|
QPDFObjectHandle
|
||||||
QPDF::reserveObjectIfNotExists(QPDFObjGen const& og)
|
QPDF::reserveObjectIfNotExists(QPDFObjGen const& og)
|
||||||
{
|
{
|
||||||
|
|
|
@ -2165,30 +2165,29 @@ QPDFObjectHandle::newStream(QPDF* qpdf)
|
||||||
"attempt to create stream in null qpdf object");
|
"attempt to create stream in null qpdf object");
|
||||||
}
|
}
|
||||||
QTC::TC("qpdf", "QPDFObjectHandle newStream");
|
QTC::TC("qpdf", "QPDFObjectHandle newStream");
|
||||||
QPDFObjectHandle stream_dict = newDictionary();
|
return qpdf->newStream();
|
||||||
QPDFObjectHandle result = qpdf->makeIndirectObject(QPDFObjectHandle(
|
|
||||||
QPDF_Stream::create(qpdf, QPDFObjGen(), stream_dict, 0, 0)));
|
|
||||||
auto stream = result.asStream();
|
|
||||||
stream->setObjGen(result.getObjGen());
|
|
||||||
return result;
|
|
||||||
}
|
}
|
||||||
|
|
||||||
QPDFObjectHandle
|
QPDFObjectHandle
|
||||||
QPDFObjectHandle::newStream(QPDF* qpdf, std::shared_ptr<Buffer> data)
|
QPDFObjectHandle::newStream(QPDF* qpdf, std::shared_ptr<Buffer> data)
|
||||||
{
|
{
|
||||||
|
if (qpdf == nullptr) {
|
||||||
|
throw std::runtime_error(
|
||||||
|
"attempt to create stream in null qpdf object");
|
||||||
|
}
|
||||||
QTC::TC("qpdf", "QPDFObjectHandle newStream with data");
|
QTC::TC("qpdf", "QPDFObjectHandle newStream with data");
|
||||||
QPDFObjectHandle result = newStream(qpdf);
|
return qpdf->newStream(data);
|
||||||
result.replaceStreamData(data, newNull(), newNull());
|
|
||||||
return result;
|
|
||||||
}
|
}
|
||||||
|
|
||||||
QPDFObjectHandle
|
QPDFObjectHandle
|
||||||
QPDFObjectHandle::newStream(QPDF* qpdf, std::string const& data)
|
QPDFObjectHandle::newStream(QPDF* qpdf, std::string const& data)
|
||||||
{
|
{
|
||||||
|
if (qpdf == nullptr) {
|
||||||
|
throw std::runtime_error(
|
||||||
|
"attempt to create stream in null qpdf object");
|
||||||
|
}
|
||||||
QTC::TC("qpdf", "QPDFObjectHandle newStream with string");
|
QTC::TC("qpdf", "QPDFObjectHandle newStream with string");
|
||||||
QPDFObjectHandle result = newStream(qpdf);
|
return qpdf->newStream(data);
|
||||||
result.replaceStreamData(data, newNull(), newNull());
|
|
||||||
return result;
|
|
||||||
}
|
}
|
||||||
|
|
||||||
QPDFObjectHandle
|
QPDFObjectHandle
|
||||||
|
|
Loading…
Reference in New Issue
Block a user