mirror of
https://github.com/qpdf/qpdf.git
synced 2024-09-27 12:39:06 +00:00
Enhancements to ParserCallbacks
This commit is contained in:
parent
1bb209a9bf
commit
a15ec6967d
@ -1,5 +1,9 @@
|
|||||||
2021-03-01 Jay Berkenbilt <ejb@ql.org>
|
2021-03-01 Jay Berkenbilt <ejb@ql.org>
|
||||||
|
|
||||||
|
* QPDFObjectHandle::ParserCallbacks: add virtual handleWarning
|
||||||
|
method, and provide default (empty) implementation of it and
|
||||||
|
handleEOF().
|
||||||
|
|
||||||
* Add QPDF::numWarnings() -- useful to tell whether any warnings
|
* Add QPDF::numWarnings() -- useful to tell whether any warnings
|
||||||
were issued by a specific bit of code.
|
were issued by a specific bit of code.
|
||||||
|
|
||||||
|
@ -224,7 +224,16 @@ class QPDFObjectHandle
|
|||||||
virtual void handleObject(
|
virtual void handleObject(
|
||||||
QPDFObjectHandle, size_t offset, size_t length);
|
QPDFObjectHandle, size_t offset, size_t length);
|
||||||
|
|
||||||
virtual void handleEOF() = 0;
|
// handleWarning is called if a warning was issued during the
|
||||||
|
// parsing of the most recent object. There's no good way to
|
||||||
|
// get information about the warning, but implementors can use
|
||||||
|
// this to become aware that there was some problem while
|
||||||
|
// parsing this content stream.
|
||||||
|
QPDF_DLL
|
||||||
|
virtual void handleWarning();
|
||||||
|
|
||||||
|
QPDF_DLL
|
||||||
|
virtual void handleEOF();
|
||||||
|
|
||||||
// Override this if you want to know the full size of the
|
// Override this if you want to know the full size of the
|
||||||
// contents, possibly after concatenation of multiple streams.
|
// contents, possibly after concatenation of multiple streams.
|
||||||
|
@ -151,6 +151,16 @@ QPDFObjectHandle::ParserCallbacks::handleObject(
|
|||||||
handleObject(oh);
|
handleObject(oh);
|
||||||
}
|
}
|
||||||
|
|
||||||
|
void
|
||||||
|
QPDFObjectHandle::ParserCallbacks::handleWarning()
|
||||||
|
{
|
||||||
|
}
|
||||||
|
|
||||||
|
void
|
||||||
|
QPDFObjectHandle::ParserCallbacks::handleEOF()
|
||||||
|
{
|
||||||
|
}
|
||||||
|
|
||||||
void
|
void
|
||||||
QPDFObjectHandle::ParserCallbacks::contentSize(size_t)
|
QPDFObjectHandle::ParserCallbacks::contentSize(size_t)
|
||||||
{
|
{
|
||||||
@ -1847,10 +1857,15 @@ QPDFObjectHandle::parseContentStream_internal(
|
|||||||
pipeContentStreams(&buf, description, all_description);
|
pipeContentStreams(&buf, description, all_description);
|
||||||
PointerHolder<Buffer> stream_data = buf.getBuffer();
|
PointerHolder<Buffer> stream_data = buf.getBuffer();
|
||||||
callbacks->contentSize(stream_data->getSize());
|
callbacks->contentSize(stream_data->getSize());
|
||||||
|
QPDF* context = getOwningQPDF();
|
||||||
|
if ((! context) && isArray() && (getArrayNItems() > 0))
|
||||||
|
{
|
||||||
|
context = getArrayItem(0).getOwningQPDF();
|
||||||
|
}
|
||||||
try
|
try
|
||||||
{
|
{
|
||||||
parseContentStream_data(stream_data, all_description,
|
parseContentStream_data(stream_data, all_description,
|
||||||
callbacks, getOwningQPDF());
|
callbacks, context);
|
||||||
}
|
}
|
||||||
catch (TerminateParsing&)
|
catch (TerminateParsing&)
|
||||||
{
|
{
|
||||||
@ -1881,9 +1896,15 @@ QPDFObjectHandle::parseContentStream_data(
|
|||||||
tokenizer.readToken(input, "content", true);
|
tokenizer.readToken(input, "content", true);
|
||||||
qpdf_offset_t offset = input->getLastOffset();
|
qpdf_offset_t offset = input->getLastOffset();
|
||||||
input->seek(offset, SEEK_SET);
|
input->seek(offset, SEEK_SET);
|
||||||
|
size_t before_nwarnings = (context ? context->numWarnings() : 0);
|
||||||
QPDFObjectHandle obj =
|
QPDFObjectHandle obj =
|
||||||
parseInternal(input, "content", tokenizer,
|
parseInternal(input, "content", tokenizer,
|
||||||
empty, 0, context, true);
|
empty, 0, context, true);
|
||||||
|
size_t after_nwarnings = (context ? context->numWarnings() : 0);
|
||||||
|
if (after_nwarnings > before_nwarnings)
|
||||||
|
{
|
||||||
|
callbacks->handleWarning();
|
||||||
|
}
|
||||||
if (! obj.isInitialized())
|
if (! obj.isInitialized())
|
||||||
{
|
{
|
||||||
// EOF
|
// EOF
|
||||||
@ -1910,6 +1931,7 @@ QPDFObjectHandle::parseContentStream_data(
|
|||||||
QPDFExc(qpdf_e_damaged_pdf, input->getName(),
|
QPDFExc(qpdf_e_damaged_pdf, input->getName(),
|
||||||
"stream data", input->tell(),
|
"stream data", input->tell(),
|
||||||
"EOF found while reading inline image"));
|
"EOF found while reading inline image"));
|
||||||
|
callbacks->handleWarning();
|
||||||
}
|
}
|
||||||
else
|
else
|
||||||
{
|
{
|
||||||
|
Loading…
Reference in New Issue
Block a user