diff --git a/PdfForQtLib/sources/pdfcatalog.cpp b/PdfForQtLib/sources/pdfcatalog.cpp index 97f66da..e4657ce 100644 --- a/PdfForQtLib/sources/pdfcatalog.cpp +++ b/PdfForQtLib/sources/pdfcatalog.cpp @@ -46,7 +46,7 @@ PDFCatalog PDFCatalog::parse(const PDFObject& catalog, const PDFDocument* docume { if (!catalog.isDictionary()) { - throw PDFParserException(PDFTranslationContext::tr("Catalog must be a dictionary.")); + throw PDFException(PDFTranslationContext::tr("Catalog must be a dictionary.")); } const PDFDictionary* catalogDictionary = catalog.getDictionary(); @@ -71,7 +71,7 @@ PDFViewerPreferences PDFViewerPreferences::parse(const PDFObject& catalogDiction if (!catalogDictionary.isDictionary()) { - throw PDFParserException(PDFTranslationContext::tr("Catalog must be a dictionary.")); + throw PDFException(PDFTranslationContext::tr("Catalog must be a dictionary.")); } const PDFDictionary* dictionary = catalogDictionary.getDictionary(); @@ -94,7 +94,7 @@ PDFViewerPreferences PDFViewerPreferences::parse(const PDFObject& catalogDiction } else { - throw PDFParserException(PDFTranslationContext::tr("Expected boolean value.")); + throw PDFException(PDFTranslationContext::tr("Expected boolean value.")); } } }; @@ -112,7 +112,7 @@ PDFViewerPreferences PDFViewerPreferences::parse(const PDFObject& catalogDiction { if (!nonFullscreenPageMode.isName()) { - throw PDFParserException(PDFTranslationContext::tr("Expected name.")); + throw PDFException(PDFTranslationContext::tr("Expected name.")); } QByteArray enumName = nonFullscreenPageMode.getString(); @@ -134,7 +134,7 @@ PDFViewerPreferences PDFViewerPreferences::parse(const PDFObject& catalogDiction } else { - throw PDFParserException(PDFTranslationContext::tr("Unknown viewer preferences settings.")); + throw PDFException(PDFTranslationContext::tr("Unknown viewer preferences settings.")); } } @@ -144,7 +144,7 @@ PDFViewerPreferences PDFViewerPreferences::parse(const PDFObject& catalogDiction { if (!direction.isName()) { - throw PDFParserException(PDFTranslationContext::tr("Expected name.")); + throw PDFException(PDFTranslationContext::tr("Expected name.")); } QByteArray enumName = direction.getString(); @@ -158,7 +158,7 @@ PDFViewerPreferences PDFViewerPreferences::parse(const PDFObject& catalogDiction } else { - throw PDFParserException(PDFTranslationContext::tr("Unknown viewer preferences settings.")); + throw PDFException(PDFTranslationContext::tr("Unknown viewer preferences settings.")); } } @@ -173,7 +173,7 @@ PDFViewerPreferences PDFViewerPreferences::parse(const PDFObject& catalogDiction } else { - throw PDFParserException(PDFTranslationContext::tr("Expected name.")); + throw PDFException(PDFTranslationContext::tr("Expected name.")); } } }; @@ -188,7 +188,7 @@ PDFViewerPreferences PDFViewerPreferences::parse(const PDFObject& catalogDiction { if (!printScaling.isName()) { - throw PDFParserException(PDFTranslationContext::tr("Expected name.")); + throw PDFException(PDFTranslationContext::tr("Expected name.")); } QByteArray enumName = printScaling.getString(); @@ -202,7 +202,7 @@ PDFViewerPreferences PDFViewerPreferences::parse(const PDFObject& catalogDiction } else { - throw PDFParserException(PDFTranslationContext::tr("Unknown viewer preferences settings.")); + throw PDFException(PDFTranslationContext::tr("Unknown viewer preferences settings.")); } } @@ -212,7 +212,7 @@ PDFViewerPreferences PDFViewerPreferences::parse(const PDFObject& catalogDiction { if (!duplex.isName()) { - throw PDFParserException(PDFTranslationContext::tr("Expected name.")); + throw PDFException(PDFTranslationContext::tr("Expected name.")); } QByteArray enumName = duplex.getString(); @@ -230,7 +230,7 @@ PDFViewerPreferences PDFViewerPreferences::parse(const PDFObject& catalogDiction } else { - throw PDFParserException(PDFTranslationContext::tr("Unknown viewer preferences settings.")); + throw PDFException(PDFTranslationContext::tr("Unknown viewer preferences settings.")); } } @@ -240,7 +240,7 @@ PDFViewerPreferences PDFViewerPreferences::parse(const PDFObject& catalogDiction { if (!duplex.isArray()) { - throw PDFParserException(PDFTranslationContext::tr("Expected array of integers.")); + throw PDFException(PDFTranslationContext::tr("Expected array of integers.")); } // According to PDF Reference 1.7, this entry is ignored in following cases: @@ -292,7 +292,7 @@ PDFViewerPreferences PDFViewerPreferences::parse(const PDFObject& catalogDiction } else { - throw PDFParserException(PDFTranslationContext::tr("Expected integer.")); + throw PDFException(PDFTranslationContext::tr("Expected integer.")); } } @@ -314,13 +314,13 @@ PDFViewerPreferences PDFViewerPreferences::parse(const PDFObject& catalogDiction } else { - throw PDFParserException(PDFTranslationContext::tr("Expected integer.")); + throw PDFException(PDFTranslationContext::tr("Expected integer.")); } } } else if (!viewerPreferencesObject.isNull()) { - throw PDFParserException(PDFTranslationContext::tr("Viewer preferences must be a dictionary.")); + throw PDFException(PDFTranslationContext::tr("Viewer preferences must be a dictionary.")); } } @@ -347,7 +347,7 @@ PDFPageLabel PDFPageLabel::parse(PDFInteger pageIndex, const PDFDocument* docume } else { - throw PDFParserException(PDFTranslationContext::tr("Expected page label dictionary.")); + throw PDFException(PDFTranslationContext::tr("Expected page label dictionary.")); } return PDFPageLabel(); diff --git a/PdfForQtLib/sources/pdfcolorspaces.cpp b/PdfForQtLib/sources/pdfcolorspaces.cpp index 1763c1a..57b5de7 100644 --- a/PdfForQtLib/sources/pdfcolorspaces.cpp +++ b/PdfForQtLib/sources/pdfcolorspaces.cpp @@ -101,13 +101,13 @@ QImage PDFAbstractColorSpace::getImage(const PDFImageData& imageData) const unsigned int componentCount = imageData.getComponents(); if (componentCount != getColorComponentCount()) { - throw PDFParserException(PDFTranslationContext::tr("Invalid colors for color space. Color space has %1 colors. Provided color count is %4.").arg(getColorComponentCount()).arg(componentCount)); + throw PDFException(PDFTranslationContext::tr("Invalid colors for color space. Color space has %1 colors. Provided color count is %4.").arg(getColorComponentCount()).arg(componentCount)); } const std::vector& decode = imageData.getDecode(); if (!decode.empty() && decode.size() != componentCount * 2) { - throw PDFParserException(PDFTranslationContext::tr("Invalid size of the decoded array. Expected %1, actual %2.").arg(componentCount * 2).arg(decode.size())); + throw PDFException(PDFTranslationContext::tr("Invalid size of the decoded array. Expected %1, actual %2.").arg(componentCount * 2).arg(decode.size())); } PDFBitReader reader(&imageData.getData(), imageData.getBitsPerComponent()); @@ -159,20 +159,20 @@ QImage PDFAbstractColorSpace::getImage(const PDFImageData& imageData) const unsigned int componentCount = imageData.getComponents(); if (componentCount != getColorComponentCount()) { - throw PDFParserException(PDFTranslationContext::tr("Invalid colors for color space. Color space has %1 colors. Provided color count is %4.").arg(getColorComponentCount()).arg(componentCount)); + throw PDFException(PDFTranslationContext::tr("Invalid colors for color space. Color space has %1 colors. Provided color count is %4.").arg(getColorComponentCount()).arg(componentCount)); } Q_ASSERT(componentCount > 0); const std::vector& colorKeyMask = imageData.getColorKeyMask(); if (colorKeyMask.size() / 2 != componentCount) { - throw PDFParserException(PDFTranslationContext::tr("Invalid number of color components in color key mask. Expected %1, provided %2.").arg(2 * componentCount).arg(colorKeyMask.size())); + throw PDFException(PDFTranslationContext::tr("Invalid number of color components in color key mask. Expected %1, provided %2.").arg(2 * componentCount).arg(colorKeyMask.size())); } const std::vector& decode = imageData.getDecode(); if (!decode.empty() && decode.size() != componentCount * 2) { - throw PDFParserException(PDFTranslationContext::tr("Invalid size of the decoded array. Expected %1, actual %2.").arg(componentCount * 2).arg(decode.size())); + throw PDFException(PDFTranslationContext::tr("Invalid size of the decoded array. Expected %1, actual %2.").arg(componentCount * 2).arg(decode.size())); } PDFBitReader reader(&imageData.getData(), imageData.getBitsPerComponent()); @@ -241,7 +241,7 @@ QColor PDFAbstractColorSpace::getCheckedColor(const PDFColor& color) const { if (getColorComponentCount() != color.size()) { - throw PDFParserException(PDFTranslationContext::tr("Invalid number of color components. Expected number is %1, actual number is %2.").arg(static_cast(getColorComponentCount())).arg(static_cast(color.size()))); + throw PDFException(PDFTranslationContext::tr("Invalid number of color components. Expected number is %1, actual number is %2.").arg(static_cast(getColorComponentCount())).arg(static_cast(color.size()))); } return getColor(color); @@ -314,7 +314,7 @@ PDFColorSpacePointer PDFAbstractColorSpace::createColorSpaceImpl(const PDFDictio { if (--recursion <= 0) { - throw PDFParserException(PDFTranslationContext::tr("Can't load color space, because color space structure is too complex.")); + throw PDFException(PDFTranslationContext::tr("Can't load color space, because color space structure is too complex.")); } if (colorSpace.isName()) @@ -403,7 +403,7 @@ PDFColorSpacePointer PDFAbstractColorSpace::createColorSpaceImpl(const PDFDictio } } - throw PDFParserException(PDFTranslationContext::tr("Invalid color space.")); + throw PDFException(PDFTranslationContext::tr("Invalid color space.")); return PDFColorSpacePointer(); } @@ -414,7 +414,7 @@ PDFColorSpacePointer PDFAbstractColorSpace::createDeviceColorSpaceByNameImpl(con { if (--recursion <= 0) { - throw PDFParserException(PDFTranslationContext::tr("Can't load color space, because color space structure is too complex.")); + throw PDFException(PDFTranslationContext::tr("Can't load color space, because color space structure is too complex.")); } if (name == COLOR_SPACE_NAME_PATTERN) @@ -460,7 +460,7 @@ PDFColorSpacePointer PDFAbstractColorSpace::createDeviceColorSpaceByNameImpl(con return createColorSpaceImpl(colorSpaceDictionary, document, document->getObject(colorSpaceDictionary->get(name)), recursion); } - throw PDFParserException(PDFTranslationContext::tr("Invalid color space.")); + throw PDFException(PDFTranslationContext::tr("Invalid color space.")); return PDFColorSpacePointer(); } @@ -746,7 +746,7 @@ PDFColorSpacePointer PDFICCBasedColorSpace::createICCBasedColorSpace(const PDFDi default: { - throw PDFParserException(PDFTranslationContext::tr("Can't determine alternate color space for ICC based profile. Number of components is %1.").arg(N)); + throw PDFException(PDFTranslationContext::tr("Can't determine alternate color space for ICC based profile. Number of components is %1.").arg(N)); break; } } @@ -754,7 +754,7 @@ PDFColorSpacePointer PDFICCBasedColorSpace::createICCBasedColorSpace(const PDFDi if (!alternateColorSpace) { - throw PDFParserException(PDFTranslationContext::tr("Can't determine alternate color space for ICC based profile.")); + throw PDFException(PDFTranslationContext::tr("Can't determine alternate color space for ICC based profile.")); } Ranges ranges = { 0.0f, 1.0f, 0.0f, 1.0f, 0.0f, 1.0f, 0.0f, 1.0f }; @@ -765,7 +765,7 @@ PDFColorSpacePointer PDFICCBasedColorSpace::createICCBasedColorSpace(const PDFDi if (rangeSize > ranges.size()) { - throw PDFParserException(PDFTranslationContext::tr("Too much color components for ICC based profile.")); + throw PDFException(PDFTranslationContext::tr("Too much color components for ICC based profile.")); } auto itStart = ranges.begin(); @@ -830,7 +830,7 @@ QImage PDFIndexedColorSpace::getImage(const PDFImageData& imageData) const if (componentCount != getColorComponentCount()) { - throw PDFParserException(PDFTranslationContext::tr("Invalid colors for indexed color space. Color space has %1 colors. Provided color count is %4.").arg(getColorComponentCount()).arg(componentCount)); + throw PDFException(PDFTranslationContext::tr("Invalid colors for indexed color space. Color space has %1 colors. Provided color count is %4.").arg(getColorComponentCount()).arg(componentCount)); } Q_ASSERT(componentCount == 1); @@ -875,7 +875,7 @@ PDFColorSpacePointer PDFIndexedColorSpace::createIndexedColorSpace(const PDFDict if (!baseColorSpace) { - throw PDFParserException(PDFTranslationContext::tr("Can't determine base color space for indexed color space.")); + throw PDFException(PDFTranslationContext::tr("Can't determine base color space for indexed color space.")); } // Read maximum value @@ -901,7 +901,7 @@ PDFColorSpacePointer PDFIndexedColorSpace::createIndexedColorSpace(const PDFDict const int byteCount = colorCount * componentCount; if (byteCount != colors.size()) { - throw PDFParserException(PDFTranslationContext::tr("Invalid colors for indexed color space. Color space has %1 colors, %2 color components and must have %3 size. Provided size is %4.").arg(colorCount).arg(componentCount).arg(byteCount).arg(colors.size())); + throw PDFException(PDFTranslationContext::tr("Invalid colors for indexed color space. Color space has %1 colors, %2 color components and must have %3 size. Provided size is %4.").arg(colorCount).arg(componentCount).arg(byteCount).arg(colors.size())); } return PDFColorSpacePointer(new PDFIndexedColorSpace(qMove(baseColorSpace), qMove(colors), maxValue)); @@ -962,7 +962,7 @@ PDFColorSpacePointer PDFSeparationColorSpace::createSeparationColorSpace(const P const PDFObject& colorNameObject = document->getObject(array->getItem(1)); if (!colorNameObject.isName()) { - throw PDFParserException(PDFTranslationContext::tr("Can't determine color name for separation color space.")); + throw PDFException(PDFTranslationContext::tr("Can't determine color name for separation color space.")); } QByteArray colorName = colorNameObject.getString(); @@ -970,13 +970,13 @@ PDFColorSpacePointer PDFSeparationColorSpace::createSeparationColorSpace(const P PDFColorSpacePointer alternateColorSpace = PDFAbstractColorSpace::createColorSpaceImpl(colorSpaceDictionary, document, document->getObject(array->getItem(2)), recursion); if (!alternateColorSpace) { - throw PDFParserException(PDFTranslationContext::tr("Can't determine alternate color space for separation color space.")); + throw PDFException(PDFTranslationContext::tr("Can't determine alternate color space for separation color space.")); } PDFFunctionPtr tintTransform = PDFFunction::createFunction(document, array->getItem(3)); if (!tintTransform) { - throw PDFParserException(PDFTranslationContext::tr("Can't determine tint transform for separation color space.")); + throw PDFException(PDFTranslationContext::tr("Can't determine tint transform for separation color space.")); } return PDFColorSpacePointer(new PDFSeparationColorSpace(qMove(colorName), qMove(alternateColorSpace), qMove(tintTransform))); @@ -998,7 +998,7 @@ QColor PDFPatternColorSpace::getDefaultColor() const QColor PDFPatternColorSpace::getColor(const PDFColor& color) const { Q_UNUSED(color); - throw PDFParserException(PDFTranslationContext::tr("Pattern doesn't have defined uniform color.")); + throw PDFException(PDFTranslationContext::tr("Pattern doesn't have defined uniform color.")); } size_t PDFPatternColorSpace::getColorComponentCount() const @@ -1075,7 +1075,7 @@ PDFColorSpacePointer PDFDeviceNColorSpace::createDeviceNColorSpace(const PDFDict if (colorantNames.empty()) { - throw PDFParserException(PDFTranslationContext::tr("Invalid colorants for DeviceN color space.")); + throw PDFException(PDFTranslationContext::tr("Invalid colorants for DeviceN color space.")); } std::vector colorants; @@ -1089,13 +1089,13 @@ PDFColorSpacePointer PDFDeviceNColorSpace::createDeviceNColorSpace(const PDFDict PDFColorSpacePointer alternateColorSpace = PDFAbstractColorSpace::createColorSpaceImpl(colorSpaceDictionary, document, document->getObject(array->getItem(2)), recursion); if (!alternateColorSpace) { - throw PDFParserException(PDFTranslationContext::tr("Can't determine alternate color space for DeviceN color space.")); + throw PDFException(PDFTranslationContext::tr("Can't determine alternate color space for DeviceN color space.")); } PDFFunctionPtr tintTransform = PDFFunction::createFunction(document, array->getItem(3)); if (!tintTransform) { - throw PDFParserException(PDFTranslationContext::tr("Can't determine tint transform for DeviceN color space.")); + throw PDFException(PDFTranslationContext::tr("Can't determine tint transform for DeviceN color space.")); } Type type = Type::DeviceN; diff --git a/PdfForQtLib/sources/pdfdocument.cpp b/PdfForQtLib/sources/pdfdocument.cpp index 975d8bf..6ff70cb 100644 --- a/PdfForQtLib/sources/pdfdocument.cpp +++ b/PdfForQtLib/sources/pdfdocument.cpp @@ -101,7 +101,7 @@ void PDFDocument::initInfo() } else if (!stringObject.isNull()) { - throw PDFParserException(tr("Bad format of document info entry in trailer dictionary. String expected.")); + throw PDFException(tr("Bad format of document info entry in trailer dictionary. String expected.")); } } }; @@ -124,12 +124,12 @@ void PDFDocument::initInfo() if (!fillEntry.isValid()) { - throw PDFParserException(tr("Bad format of document info entry in trailer dictionary. String with date time format expected.")); + throw PDFException(tr("Bad format of document info entry in trailer dictionary. String with date time format expected.")); } } else if (!stringObject.isNull()) { - throw PDFParserException(tr("Bad format of document info entry in trailer dictionary. String with date time format expected.")); + throw PDFException(tr("Bad format of document info entry in trailer dictionary. String with date time format expected.")); } } }; @@ -156,18 +156,18 @@ void PDFDocument::initInfo() } else { - throw PDFParserException(tr("Bad format of document info entry in trailer dictionary. Trapping information expected")); + throw PDFException(tr("Bad format of document info entry in trailer dictionary. Trapping information expected")); } } else { - throw PDFParserException(tr("Bad format of document info entry in trailer dictionary. Trapping information expected")); + throw PDFException(tr("Bad format of document info entry in trailer dictionary. Trapping information expected")); } } } else if (!info.isNull()) // Info may be invalid... { - throw PDFParserException(tr("Bad format of document info entry in trailer dictionary.")); + throw PDFException(tr("Bad format of document info entry in trailer dictionary.")); } } } diff --git a/PdfForQtLib/sources/pdfdocumentreader.cpp b/PdfForQtLib/sources/pdfdocumentreader.cpp index 3b63882..10e480a 100644 --- a/PdfForQtLib/sources/pdfdocumentreader.cpp +++ b/PdfForQtLib/sources/pdfdocumentreader.cpp @@ -110,13 +110,13 @@ PDFDocument PDFDocumentReader::readFromBuffer(const QByteArray& buffer) // 2) Find start of cross reference table if (findFromEnd(PDF_END_OF_FILE_MARK, buffer, PDF_FOOTER_SCAN_LIMIT) == FIND_NOT_FOUND_RESULT) { - throw PDFParserException(tr("End of file marking was not found.")); + throw PDFException(tr("End of file marking was not found.")); } const int startXRefPosition = findFromEnd(PDF_START_OF_XREF_MARK, buffer, PDF_FOOTER_SCAN_LIMIT); if (startXRefPosition == FIND_NOT_FOUND_RESULT) { - throw PDFParserException(tr("Start of object reference table not found.")); + throw PDFException(tr("Start of object reference table not found.")); } Q_ASSERT(startXRefPosition + std::strlen(PDF_START_OF_XREF_MARK) < buffer.size()); @@ -124,7 +124,7 @@ PDFDocument PDFDocumentReader::readFromBuffer(const QByteArray& buffer) const PDFLexicalAnalyzer::Token token = analyzer.fetch(); if (token.type != PDFLexicalAnalyzer::TokenType::Integer) { - throw PDFParserException(tr("Start of object reference table not found.")); + throw PDFException(tr("Start of object reference table not found.")); } const PDFInteger firstXrefTableOffset = token.data.toLongLong(); @@ -161,13 +161,13 @@ PDFDocument PDFDocumentReader::readFromBuffer(const QByteArray& buffer) } else { - throw PDFParserException(tr("Header of PDF file was not found.")); + throw PDFException(tr("Header of PDF file was not found.")); } // Check, if version is valid if (!m_version.isValid()) { - throw PDFParserException(tr("Version of the PDF file is not valid.")); + throw PDFException(tr("Version of the PDF file is not valid.")); } // Now, we are ready to scan xref table @@ -188,25 +188,25 @@ PDFDocument PDFDocumentReader::readFromBuffer(const QByteArray& buffer) if (!objectNumber.isInt() || !generation.isInt()) { - throw PDFParserException(tr("Can't read object at position %1.").arg(offset)); + throw PDFException(tr("Can't read object at position %1.").arg(offset)); } if (!parser.fetchCommand(PDF_OBJECT_START_MARK)) { - throw PDFParserException(tr("Can't read object at position %1.").arg(offset)); + throw PDFException(tr("Can't read object at position %1.").arg(offset)); } PDFObject object = parser.getObject(); if (!parser.fetchCommand(PDF_OBJECT_END_MARK)) { - throw PDFParserException(tr("Can't read object at position %1.").arg(offset)); + throw PDFException(tr("Can't read object at position %1.").arg(offset)); } PDFObjectReference scannedReference(objectNumber.getInteger(), generation.getInteger()); if (scannedReference != reference) { - throw PDFParserException(tr("Can't read object at position %1.").arg(offset)); + throw PDFException(tr("Can't read object at position %1.").arg(offset)); } return object; @@ -256,7 +256,7 @@ PDFDocument PDFDocumentReader::readFromBuffer(const QByteArray& buffer) QMutexLocker lock(&m_mutex); objects[entry.reference.objectNumber] = PDFObjectStorage::Entry(entry.reference.generation, object); } - catch (PDFParserException exception) + catch (PDFException exception) { QMutexLocker lock(&m_mutex); m_result = Result::Failed; @@ -291,7 +291,7 @@ PDFDocument PDFDocumentReader::readFromBuffer(const QByteArray& buffer) } else { - throw PDFParserException(tr("Invalid trailer dictionary.")); + throw PDFException(tr("Invalid trailer dictionary.")); } // Read the document ID @@ -335,7 +335,7 @@ PDFDocument PDFDocumentReader::readFromBuffer(const QByteArray& buffer) if (authorizationResult == PDFSecurityHandler::AuthorizationResult::Failed) { - throw PDFParserException(PDFTranslationContext::tr("Authorization failed. Bad password provided.")); + throw PDFException(PDFTranslationContext::tr("Authorization failed. Bad password provided.")); } // Now, decrypt the document, if we are authorized. We must also check, if we have to decrypt the object. @@ -390,13 +390,13 @@ PDFDocument PDFDocumentReader::readFromBuffer(const QByteArray& buffer) PDFParsingContext context(objectFetcher); if (objectStreamReference.objectNumber >= static_cast(objects.size())) { - throw PDFParserException(PDFTranslationContext::tr("Object stream %1 not found.").arg(objectStreamReference.objectNumber)); + throw PDFException(PDFTranslationContext::tr("Object stream %1 not found.").arg(objectStreamReference.objectNumber)); } const PDFObject& object = objects[objectStreamReference.objectNumber].object; if (!object.isStream()) { - throw PDFParserException(PDFTranslationContext::tr("Object stream %1 is invalid.").arg(objectStreamReference.objectNumber)); + throw PDFException(PDFTranslationContext::tr("Object stream %1 is invalid.").arg(objectStreamReference.objectNumber)); } const PDFStream* objectStream = object.getStream(); @@ -405,14 +405,14 @@ PDFDocument PDFDocumentReader::readFromBuffer(const QByteArray& buffer) const PDFObject& objectStreamType = objectStreamDictionary->get("Type"); if (!objectStreamType.isName() || objectStreamType.getString() != "ObjStm") { - throw PDFParserException(PDFTranslationContext::tr("Object stream %1 is invalid.").arg(objectStreamReference.objectNumber)); + throw PDFException(PDFTranslationContext::tr("Object stream %1 is invalid.").arg(objectStreamReference.objectNumber)); } const PDFObject& nObject = objectStreamDictionary->get("N"); const PDFObject& firstObject = objectStreamDictionary->get("First"); if (!nObject.isInt() || !firstObject.isInt()) { - throw PDFParserException(PDFTranslationContext::tr("Object stream %1 is invalid.").arg(objectStreamReference.objectNumber)); + throw PDFException(PDFTranslationContext::tr("Object stream %1 is invalid.").arg(objectStreamReference.objectNumber)); } // Number of objects in object stream dictionary @@ -433,7 +433,7 @@ PDFDocument PDFDocumentReader::readFromBuffer(const QByteArray& buffer) if (!currentObjectNumber.isInt() || !currentOffset.isInt()) { - throw PDFParserException(PDFTranslationContext::tr("Object stream %1 is invalid.").arg(objectStreamReference.objectNumber)); + throw PDFException(PDFTranslationContext::tr("Object stream %1 is invalid.").arg(objectStreamReference.objectNumber)); } const PDFInteger objectNumber = currentObjectNumber.getInteger(); @@ -456,11 +456,11 @@ PDFDocument PDFDocumentReader::readFromBuffer(const QByteArray& buffer) } else { - throw PDFParserException(PDFTranslationContext::tr("Object stream %1 is invalid.").arg(objectStreamReference.objectNumber)); + throw PDFException(PDFTranslationContext::tr("Object stream %1 is invalid.").arg(objectStreamReference.objectNumber)); } } } - catch (PDFParserException exception) + catch (PDFException exception) { QMutexLocker lock(&m_mutex); m_result = Result::Failed; @@ -474,7 +474,7 @@ PDFDocument PDFDocumentReader::readFromBuffer(const QByteArray& buffer) PDFObjectStorage storage(std::move(objects), PDFObject(xrefTable.getTrailerDictionary()), std::move(securityHandler)); return PDFDocument(std::move(storage)); } - catch (PDFParserException parserException) + catch (PDFException parserException) { m_result = Result::Failed; m_errorMessage = parserException.getMessage(); diff --git a/PdfForQtLib/sources/pdfexception.h b/PdfForQtLib/sources/pdfexception.h index 71fbd2a..74a8c0d 100644 --- a/PdfForQtLib/sources/pdfexception.h +++ b/PdfForQtLib/sources/pdfexception.h @@ -23,10 +23,10 @@ namespace pdf { -class PDFParserException : public std::exception +class PDFException : public std::exception { public: - PDFParserException(const QString& message) : + PDFException(const QString& message) : m_message(message) { diff --git a/PdfForQtLib/sources/pdffont.cpp b/PdfForQtLib/sources/pdffont.cpp index f8ea96e..8b31298 100644 --- a/PdfForQtLib/sources/pdffont.cpp +++ b/PdfForQtLib/sources/pdffont.cpp @@ -605,7 +605,7 @@ void PDFRealizedFontImpl::checkFreeTypeError(FT_Error error) message = QString::fromLatin1(errorString); } - throw PDFParserException(PDFTranslationContext::tr("FreeType error code %1: %2").arg(error).arg(message)); + throw PDFException(PDFTranslationContext::tr("FreeType error code %1: %2").arg(error).arg(message)); } } @@ -673,7 +673,7 @@ PDFRealizedFontPointer PDFRealizedFont::createRealizedFont(PDFFontPointer font, if (impl->m_systemFontData.isEmpty()) { - throw PDFParserException(PDFTranslationContext::tr("Can't load system font '%1'.").arg(QString::fromLatin1(descriptor->fontName))); + throw PDFException(PDFTranslationContext::tr("Can't load system font '%1'.").arg(QString::fromLatin1(descriptor->fontName))); } PDFRealizedFontImpl::checkFreeTypeError(FT_Init_FreeType(&impl->m_library)); @@ -751,7 +751,7 @@ PDFFontPointer PDFFont::createFont(const PDFObject& object, const PDFDocument* d const PDFObject& dereferencedFontDictionary = document->getObject(object); if (!dereferencedFontDictionary.isDictionary()) { - throw PDFParserException(PDFTranslationContext::tr("Font object must be a dictionary.")); + throw PDFException(PDFTranslationContext::tr("Font object must be a dictionary.")); } const PDFDictionary* fontDictionary = dereferencedFontDictionary.getDictionary(); @@ -768,7 +768,7 @@ PDFFontPointer PDFFont::createFont(const PDFObject& object, const PDFDocument* d const FontType fontType = fontLoader.readEnumByName(fontDictionary->get("Subtype"), fontTypes.cbegin(), fontTypes.cend(), FontType::Invalid); if (fontType == FontType::Invalid) { - throw PDFParserException(PDFTranslationContext::tr("Invalid font type.")); + throw PDFException(PDFTranslationContext::tr("Invalid font type.")); } QByteArray name = fontLoader.readNameFromDictionary(fontDictionary, "Name"); @@ -872,7 +872,7 @@ PDFFontPointer PDFFont::createFont(const PDFObject& object, const PDFDocument* d { if (currentOffset >= differences.size()) { - throw PDFParserException(PDFTranslationContext::tr("Invalid differences in encoding entry of the font.")); + throw PDFException(PDFTranslationContext::tr("Invalid differences in encoding entry of the font.")); } QChar character = PDFNameToUnicode::getUnicodeUsingResolvedName(item.getString()); @@ -882,19 +882,19 @@ PDFFontPointer PDFFont::createFont(const PDFObject& object, const PDFDocument* d } else { - throw PDFParserException(PDFTranslationContext::tr("Invalid differences in encoding entry of the font.")); + throw PDFException(PDFTranslationContext::tr("Invalid differences in encoding entry of the font.")); } } } else { - throw PDFParserException(PDFTranslationContext::tr("Invalid differences in encoding entry of the font.")); + throw PDFException(PDFTranslationContext::tr("Invalid differences in encoding entry of the font.")); } } } else { - throw PDFParserException(PDFTranslationContext::tr("Invalid encoding entry of the font.")); + throw PDFException(PDFTranslationContext::tr("Invalid encoding entry of the font.")); } } @@ -907,7 +907,7 @@ PDFFontPointer PDFFont::createFont(const PDFObject& object, const PDFDocument* d if (encoding == PDFEncoding::Encoding::Invalid) { - throw PDFParserException(PDFTranslationContext::tr("Invalid encoding entry of the font.")); + throw PDFException(PDFTranslationContext::tr("Invalid encoding entry of the font.")); } simpleFontEncodingTable = *PDFEncoding::getTableForEncoding(encoding); @@ -1086,25 +1086,25 @@ PDFFontPointer PDFFont::createFont(const PDFObject& object, const PDFDocument* d if (!cmap.isValid()) { - throw PDFParserException(PDFTranslationContext::tr("Invalid CMAP in CID-keyed font.")); + throw PDFException(PDFTranslationContext::tr("Invalid CMAP in CID-keyed font.")); } const PDFObject& descendantFonts = document->getObject(fontDictionary->get("DescendantFonts")); if (!descendantFonts.isArray()) { - throw PDFParserException(PDFTranslationContext::tr("Invalid descendant font in CID-keyed font.")); + throw PDFException(PDFTranslationContext::tr("Invalid descendant font in CID-keyed font.")); } const PDFArray* descendantFontsArray = descendantFonts.getArray(); if (descendantFontsArray->getCount() != 1) { - throw PDFParserException(PDFTranslationContext::tr("Invalid number (%1) of descendant fonts in CID-keyed font - exactly one is required.").arg(descendantFontsArray->getCount())); + throw PDFException(PDFTranslationContext::tr("Invalid number (%1) of descendant fonts in CID-keyed font - exactly one is required.").arg(descendantFontsArray->getCount())); } const PDFObject& descendantFont = document->getObject(descendantFontsArray->getItem(0)); if (!descendantFont.isDictionary()) { - throw PDFParserException(PDFTranslationContext::tr("Invalid descendant font in CID-keyed font.")); + throw PDFException(PDFTranslationContext::tr("Invalid descendant font in CID-keyed font.")); } const PDFDictionary* descendantFontDictionary = descendantFont.getDictionary(); @@ -1190,14 +1190,14 @@ PDFFontPointer PDFFont::createFont(const PDFObject& object, const PDFDocument* d if (fontMatrixValues.size() != 6) { - throw PDFParserException(PDFTranslationContext::tr("Invalid Type 3 font matrix.")); + throw PDFException(PDFTranslationContext::tr("Invalid Type 3 font matrix.")); } QMatrix fontMatrix(fontMatrixValues[0], fontMatrixValues[1], fontMatrixValues[2], fontMatrixValues[3], fontMatrixValues[4], fontMatrixValues[5]); PDFObject charProcs = document->getObject(fontDictionary->get("CharProcs")); if (!charProcs.isDictionary()) { - throw PDFParserException(PDFTranslationContext::tr("Invalid Type 3 font character content streams.")); + throw PDFException(PDFTranslationContext::tr("Invalid Type 3 font character content streams.")); } const PDFDictionary* charProcsDictionary = charProcs.getDictionary(); @@ -1206,20 +1206,20 @@ PDFFontPointer PDFFont::createFont(const PDFObject& object, const PDFDocument* d if (firstChar < 0 || lastChar > 255 || firstChar > lastChar) { - throw PDFParserException(PDFTranslationContext::tr("Invalid Type 3 font character range (from %1 to %2).").arg(firstChar).arg(lastChar)); + throw PDFException(PDFTranslationContext::tr("Invalid Type 3 font character range (from %1 to %2).").arg(firstChar).arg(lastChar)); } const PDFObject& encoding = document->getObject(fontDictionary->get("Encoding")); if (!encoding.isDictionary()) { - throw PDFParserException(PDFTranslationContext::tr("Invalid Type 3 font encoding.")); + throw PDFException(PDFTranslationContext::tr("Invalid Type 3 font encoding.")); } const PDFDictionary* encodingDictionary = encoding.getDictionary(); const PDFObject& differences = document->getObject(encodingDictionary->get("Differences")); if (!differences.isArray()) { - throw PDFParserException(PDFTranslationContext::tr("Invalid Type 3 font encoding.")); + throw PDFException(PDFTranslationContext::tr("Invalid Type 3 font encoding.")); } std::map characterContentStreams; @@ -1237,7 +1237,7 @@ PDFFontPointer PDFFont::createFont(const PDFObject& object, const PDFDocument* d { if (currentOffset > 255) { - throw PDFParserException(PDFTranslationContext::tr("Invalid differences in encoding entry of type 3 font.")); + throw PDFException(PDFTranslationContext::tr("Invalid differences in encoding entry of type 3 font.")); } QByteArray characterName = item.getString(); @@ -1252,7 +1252,7 @@ PDFFontPointer PDFFont::createFont(const PDFObject& object, const PDFDocument* d } else { - throw PDFParserException(PDFTranslationContext::tr("Invalid differences in encoding entry of type 3 font.")); + throw PDFException(PDFTranslationContext::tr("Invalid differences in encoding entry of type 3 font.")); } } @@ -1448,7 +1448,7 @@ PDFFontCMap PDFFontCMap::createFromName(const QByteArray& name) return createFromData(data); } - throw PDFParserException(PDFTranslationContext::tr("Can't load CID font mapping named '%1'.").arg(QString::fromLatin1(name))); + throw PDFException(PDFTranslationContext::tr("Can't load CID font mapping named '%1'.").arg(QString::fromLatin1(name))); return PDFFontCMap(); } @@ -1488,7 +1488,7 @@ PDFFontCMap PDFFontCMap::createFromData(const QByteArray& data) return std::make_pair(codeValue, byteArray.size()); } - throw PDFParserException(PDFTranslationContext::tr("Can't fetch code from CMap definition.")); + throw PDFException(PDFTranslationContext::tr("Can't fetch code from CMap definition.")); return std::pair(); }; @@ -1499,7 +1499,7 @@ PDFFontCMap PDFFontCMap::createFromData(const QByteArray& data) return currentToken.data.value(); } - throw PDFParserException(PDFTranslationContext::tr("Can't fetch CID from CMap definition.")); + throw PDFException(PDFTranslationContext::tr("Can't fetch CID from CMap definition.")); return 0; }; @@ -1533,7 +1533,7 @@ PDFFontCMap PDFFontCMap::createFromData(const QByteArray& data) } else { - throw PDFParserException(PDFTranslationContext::tr("Can't use cmap inside cmap file.")); + throw PDFException(PDFTranslationContext::tr("Can't use cmap inside cmap file.")); } } else if (command == "beginbfrange") diff --git a/PdfForQtLib/sources/pdffunction.cpp b/PdfForQtLib/sources/pdffunction.cpp index 1fae8b1..ef0a18d 100644 --- a/PdfForQtLib/sources/pdffunction.cpp +++ b/PdfForQtLib/sources/pdffunction.cpp @@ -69,7 +69,7 @@ PDFFunctionPtr PDFFunction::createFunctionImpl(const PDFDocument* document, cons if (!dictionary) { - throw PDFParserException(PDFParsingContext::tr("Function dictionary expected.")); + throw PDFException(PDFParsingContext::tr("Function dictionary expected.")); } PDFDocumentDataLoaderDecorator loader(document); @@ -80,12 +80,12 @@ PDFFunctionPtr PDFFunction::createFunctionImpl(const PDFDocument* document, cons // Domain is required for all function if (domain.empty()) { - throw PDFParserException(PDFParsingContext::tr("Fuction has invalid domain.")); + throw PDFException(PDFParsingContext::tr("Fuction has invalid domain.")); } if ((functionType == 0 || functionType == 4) && range.empty()) { - throw PDFParserException(PDFParsingContext::tr("Fuction has invalid range.")); + throw PDFException(PDFParsingContext::tr("Fuction has invalid range.")); } switch (functionType) @@ -100,12 +100,12 @@ PDFFunctionPtr PDFFunction::createFunctionImpl(const PDFDocument* document, cons if (size.empty() || !std::all_of(size.cbegin(), size.cend(), [](PDFInteger size) { return size >= 1; })) { - throw PDFParserException(PDFParsingContext::tr("Sampled function has invalid sample size.")); + throw PDFException(PDFParsingContext::tr("Sampled function has invalid sample size.")); } if (bitsPerSample < 1 || bitsPerSample > 32) { - throw PDFParserException(PDFParsingContext::tr("Sampled function has invalid count of bits per sample.")); + throw PDFException(PDFParsingContext::tr("Sampled function has invalid count of bits per sample.")); } if (encode.empty()) @@ -129,17 +129,17 @@ PDFFunctionPtr PDFFunction::createFunctionImpl(const PDFDocument* document, cons if (n == 0) { - throw PDFParserException(PDFParsingContext::tr("Sampled function hasn't any output.")); + throw PDFException(PDFParsingContext::tr("Sampled function hasn't any output.")); } if (domain.size() != encode.size()) { - throw PDFParserException(PDFParsingContext::tr("Sampled function has invalid encode array.")); + throw PDFException(PDFParsingContext::tr("Sampled function has invalid encode array.")); } if (range.size() != decode.size()) { - throw PDFParserException(PDFParsingContext::tr("Sampled function has invalid decode array.")); + throw PDFException(PDFParsingContext::tr("Sampled function has invalid decode array.")); } const uint64_t sampleMaxValueInteger = (static_cast(1) << static_cast(bitsPerSample)) - 1; @@ -169,7 +169,7 @@ PDFFunctionPtr PDFFunction::createFunctionImpl(const PDFDocument* document, cons } else { - throw PDFParserException(PDFParsingContext::tr("Not enough samples for sampled function.")); + throw PDFException(PDFParsingContext::tr("Not enough samples for sampled function.")); } } @@ -193,17 +193,17 @@ PDFFunctionPtr PDFFunction::createFunctionImpl(const PDFDocument* document, cons if (domain.size() != 2) { - throw PDFParserException(PDFParsingContext::tr("Exponential function can have only one input value.")); + throw PDFException(PDFParsingContext::tr("Exponential function can have only one input value.")); } if (exponent < 0.0 && domain[0] <= 0.0) { - throw PDFParserException(PDFParsingContext::tr("Invalid domain of exponential function.")); + throw PDFException(PDFParsingContext::tr("Invalid domain of exponential function.")); } if (!qFuzzyIsNull(std::fmod(exponent, 1.0)) && domain[0] < 0.0) { - throw PDFParserException(PDFParsingContext::tr("Invalid domain of exponential function.")); + throw PDFException(PDFParsingContext::tr("Invalid domain of exponential function.")); } constexpr uint32_t m = 1; @@ -223,11 +223,11 @@ PDFFunctionPtr PDFFunction::createFunctionImpl(const PDFDocument* document, cons if (c0.size() != n) { - throw PDFParserException(PDFParsingContext::tr("Invalid parameter of exponential function (at x = 0.0).")); + throw PDFException(PDFParsingContext::tr("Invalid parameter of exponential function (at x = 0.0).")); } if (c1.size() != n) { - throw PDFParserException(PDFParsingContext::tr("Invalid parameter of exponential function (at x = 1.0).")); + throw PDFException(PDFParsingContext::tr("Invalid parameter of exponential function (at x = 1.0).")); } return std::make_shared(m, n, std::move(domain), std::move(range), std::move(c0), std::move(c1), exponent); @@ -240,7 +240,7 @@ PDFFunctionPtr PDFFunction::createFunctionImpl(const PDFDocument* document, cons if (domain.size() != 2) { - throw PDFParserException(PDFParsingContext::tr("Stitching function can have only one input value.")); + throw PDFException(PDFParsingContext::tr("Stitching function can have only one input value.")); } if (dictionary->hasKey("Functions")) @@ -251,7 +251,7 @@ PDFFunctionPtr PDFFunction::createFunctionImpl(const PDFDocument* document, cons const PDFArray* array = functions.getArray(); if (array->getCount() != bounds.size() + 1) { - throw PDFParserException(PDFParsingContext::tr("Stitching function has different function count. Expected %1, actual %2.").arg(array->getCount()).arg(bounds.size() + 1)); + throw PDFException(PDFParsingContext::tr("Stitching function has different function count. Expected %1, actual %2.").arg(array->getCount()).arg(bounds.size() + 1)); } std::vector partialFunctions; @@ -259,7 +259,7 @@ PDFFunctionPtr PDFFunction::createFunctionImpl(const PDFDocument* document, cons if (encode.size() != partialFunctions.size() * 2) { - throw PDFParserException(PDFParsingContext::tr("Stitching function has invalid encode array. Expected %1 items, actual %2.").arg(partialFunctions.size() * 2).arg(encode.size())); + throw PDFException(PDFParsingContext::tr("Stitching function has invalid encode array. Expected %1 items, actual %2.").arg(partialFunctions.size() * 2).arg(encode.size())); } std::vector boundsAdjusted; @@ -288,7 +288,7 @@ PDFFunctionPtr PDFFunction::createFunctionImpl(const PDFDocument* document, cons } else if (n != nLocal) { - throw PDFParserException(PDFParsingContext::tr("Functions in stitching function has different number of output variables.")); + throw PDFException(PDFParsingContext::tr("Functions in stitching function has different number of output variables.")); } } @@ -296,12 +296,12 @@ PDFFunctionPtr PDFFunction::createFunctionImpl(const PDFDocument* document, cons } else { - throw PDFParserException(PDFParsingContext::tr("Stitching function has invalid functions.")); + throw PDFException(PDFParsingContext::tr("Stitching function has invalid functions.")); } } else { - throw PDFParserException(PDFParsingContext::tr("Stitching function hasn't functions array.")); + throw PDFException(PDFParsingContext::tr("Stitching function hasn't functions array.")); } } case 4: @@ -314,7 +314,7 @@ PDFFunctionPtr PDFFunction::createFunctionImpl(const PDFDocument* document, cons if (program.empty()) { - throw PDFParserException(PDFParsingContext::tr("Empty program in PostScript function.")); + throw PDFException(PDFParsingContext::tr("Empty program in PostScript function.")); } return std::make_shared(m, n, std::move(domain), std::move(range), std::move(program)); @@ -322,7 +322,7 @@ PDFFunctionPtr PDFFunction::createFunctionImpl(const PDFDocument* document, cons default: { - throw PDFParserException(PDFParsingContext::tr("Invalid function type: %1.").arg(functionType)); + throw PDFException(PDFParsingContext::tr("Invalid function type: %1.").arg(functionType)); } } @@ -1638,7 +1638,7 @@ PDFPostScriptFunction::Code PDFPostScriptFunction::getCode(const QByteArray& byt } } - throw PDFParserException(PDFTranslationContext::tr("Invalid operator (PostScript function) '%1'.").arg(QString::fromLatin1(byteArray))); + throw PDFException(PDFTranslationContext::tr("Invalid operator (PostScript function) '%1'.").arg(QString::fromLatin1(byteArray))); } PDFPostScriptFunction::PDFPostScriptFunction(uint32_t m, uint32_t n, std::vector&& domain, std::vector&& range, PDFPostScriptFunction::Program&& program) : @@ -1707,7 +1707,7 @@ PDFPostScriptFunction::Program PDFPostScriptFunction::parseProgram(const QByteAr // Closing bracket - means end of block if (blockCallStack.empty()) { - throw PDFParserException(PDFTranslationContext::tr("Invalid program - bad enclosing brackets (PostScript function).")); + throw PDFException(PDFTranslationContext::tr("Invalid program - bad enclosing brackets (PostScript function).")); } result[blockCallStack.top()].next = result.size() + 1; @@ -1725,14 +1725,14 @@ PDFPostScriptFunction::Program PDFPostScriptFunction::parseProgram(const QByteAr default: { // All other tokens treat as invalid. - throw PDFParserException(PDFTranslationContext::tr("Invalid program (PostScript function).")); + throw PDFException(PDFTranslationContext::tr("Invalid program (PostScript function).")); } } } if (result.empty()) { - throw PDFParserException(PDFTranslationContext::tr("Empty program (PostScript function).")); + throw PDFException(PDFTranslationContext::tr("Empty program (PostScript function).")); } // We must insert execute instructions, where blocks without if/ifelse occurs. diff --git a/PdfForQtLib/sources/pdfimage.cpp b/PdfForQtLib/sources/pdfimage.cpp index fbb169c..15bfe8a 100644 --- a/PdfForQtLib/sources/pdfimage.cpp +++ b/PdfForQtLib/sources/pdfimage.cpp @@ -56,7 +56,7 @@ PDFImage PDFImage::createImage(const PDFDocument* document, const PDFStream* str if (content.isEmpty()) { - throw PDFParserException(PDFTranslationContext::tr("Image has not data.")); + throw PDFException(PDFTranslationContext::tr("Image has not data.")); } // TODO: Implement SMask @@ -166,7 +166,7 @@ PDFImage PDFImage::createImage(const PDFDocument* document, const PDFStream* str (ptr->err->format_message)(ptr, buffer); jpeg_destroy(ptr); - throw PDFParserException(PDFTranslationContext::tr("Error reading JPEG (DCT) image: %1.").arg(QString::fromLatin1(buffer))); + throw PDFException(PDFTranslationContext::tr("Error reading JPEG (DCT) image: %1.").arg(QString::fromLatin1(buffer))); }; auto fillInputBufferMethod = [](j_decompress_ptr decompress) -> boolean diff --git a/PdfForQtLib/sources/pdfoptionalcontent.cpp b/PdfForQtLib/sources/pdfoptionalcontent.cpp index 8009b6c..712fea1 100644 --- a/PdfForQtLib/sources/pdfoptionalcontent.cpp +++ b/PdfForQtLib/sources/pdfoptionalcontent.cpp @@ -63,13 +63,13 @@ PDFOptionalContentProperties PDFOptionalContentProperties::create(const PDFDocum } else if (!configsObject.isNull()) { - throw PDFParserException(PDFTranslationContext::tr("Invalid optional content properties.")); + throw PDFException(PDFTranslationContext::tr("Invalid optional content properties.")); } } } else if (!dereferencedObject.isNull()) { - throw PDFParserException(PDFTranslationContext::tr("Invalid optional content properties.")); + throw PDFException(PDFTranslationContext::tr("Invalid optional content properties.")); } return properties; @@ -110,7 +110,7 @@ PDFOptionalContentConfiguration PDFOptionalContentConfiguration::create(const PD } else if (!nameOrNames.isNull()) { - throw PDFParserException(PDFTranslationContext::tr("Invalid optional content configuration.")); + throw PDFException(PDFTranslationContext::tr("Invalid optional content configuration.")); } } @@ -129,14 +129,14 @@ PDFOptionalContentConfiguration PDFOptionalContentConfiguration::create(const PD } else if (!asArrayObject.isNull()) { - throw PDFParserException(PDFTranslationContext::tr("Invalid optional content configuration.")); + throw PDFException(PDFTranslationContext::tr("Invalid optional content configuration.")); } } configuration.m_order = document->getObject(dictionary->get("Order")); if (!configuration.m_order.isArray() && !configuration.m_order.isNull()) { - throw PDFParserException(PDFTranslationContext::tr("Invalid optional content configuration.")); + throw PDFException(PDFTranslationContext::tr("Invalid optional content configuration.")); } constexpr const std::array, 3> listModeEnumValues = { @@ -160,7 +160,7 @@ PDFOptionalContentConfiguration PDFOptionalContentConfiguration::create(const PD } else if (!rbGroupsObject.isNull()) { - throw PDFParserException(PDFTranslationContext::tr("Invalid optional content configuration.")); + throw PDFException(PDFTranslationContext::tr("Invalid optional content configuration.")); } } @@ -222,7 +222,7 @@ PDFOptionalContentGroup PDFOptionalContentGroup::create(const PDFDocument* docum const PDFObject& dereferencedObject = document->getObject(object); if (!dereferencedObject.isDictionary()) { - throw PDFParserException(PDFTranslationContext::tr("Invalid optional content group.")); + throw PDFException(PDFTranslationContext::tr("Invalid optional content group.")); } PDFDocumentDataLoaderDecorator loader(document); @@ -244,7 +244,7 @@ PDFOptionalContentGroup PDFOptionalContentGroup::create(const PDFDocument* docum } else if (!nameOrNames.isNull()) { - throw PDFParserException(PDFTranslationContext::tr("Invalid optional content group.")); + throw PDFException(PDFTranslationContext::tr("Invalid optional content group.")); } } @@ -447,7 +447,7 @@ PDFOptionalContentMembershipObject PDFOptionalContentMembershipObject::create(co { if (usedReferences.count(nodeObject.getReference())) { - throw PDFParserException(PDFTranslationContext::tr("Cyclic reference error in optional content visibility expression.")); + throw PDFException(PDFTranslationContext::tr("Cyclic reference error in optional content visibility expression.")); } else { @@ -459,7 +459,7 @@ PDFOptionalContentMembershipObject PDFOptionalContentMembershipObject::create(co const PDFArray* array = dereferencedNodeObject.getArray(); if (array->getCount() < 2) { - throw PDFParserException(PDFTranslationContext::tr("Invalid optional content visibility expression.")); + throw PDFException(PDFTranslationContext::tr("Invalid optional content visibility expression.")); } // Read the operator @@ -484,7 +484,7 @@ PDFOptionalContentMembershipObject PDFOptionalContentMembershipObject::create(co } else { - throw PDFParserException(PDFTranslationContext::tr("Invalid optional content visibility expression.")); + throw PDFException(PDFTranslationContext::tr("Invalid optional content visibility expression.")); } // Read the operands @@ -505,7 +505,7 @@ PDFOptionalContentMembershipObject PDFOptionalContentMembershipObject::create(co else { // Something strange occured - either we should have an array, or we should have a reference to the OCG - throw PDFParserException(PDFTranslationContext::tr("Invalid optional content visibility expression.")); + throw PDFException(PDFTranslationContext::tr("Invalid optional content visibility expression.")); return std::unique_ptr(nullptr); } }; diff --git a/PdfForQtLib/sources/pdfpage.cpp b/PdfForQtLib/sources/pdfpage.cpp index 43b68b7..e64cc35 100644 --- a/PdfForQtLib/sources/pdfpage.cpp +++ b/PdfForQtLib/sources/pdfpage.cpp @@ -82,7 +82,7 @@ PDFPageInheritableAttributes PDFPageInheritableAttributes::parse(const PDFPageIn } default: { - throw PDFParserException(PDFTranslationContext::tr("Invalid page rotation.")); + throw PDFException(PDFTranslationContext::tr("Invalid page rotation.")); } } } @@ -176,13 +176,13 @@ void PDFPage::parseImpl(std::vector& pages, // Check reference if (!kid.isReference()) { - throw PDFParserException(PDFTranslationContext::tr("Expected valid kids in page tree.")); + throw PDFException(PDFTranslationContext::tr("Expected valid kids in page tree.")); } // Check cycles if (visitedReferences.count(kid.getReference())) { - throw PDFParserException(PDFTranslationContext::tr("Detected cycles in page tree.")); + throw PDFException(PDFTranslationContext::tr("Detected cycles in page tree.")); } visitedReferences.insert(kid.getReference()); @@ -191,7 +191,7 @@ void PDFPage::parseImpl(std::vector& pages, } else { - throw PDFParserException(PDFTranslationContext::tr("Expected valid kids in page tree.")); + throw PDFException(PDFTranslationContext::tr("Expected valid kids in page tree.")); } } else if (typeString == "Page") @@ -218,17 +218,17 @@ void PDFPage::parseImpl(std::vector& pages, } else { - throw PDFParserException(PDFTranslationContext::tr("Expected valid type item in page tree.")); + throw PDFException(PDFTranslationContext::tr("Expected valid type item in page tree.")); } } else { - throw PDFParserException(PDFTranslationContext::tr("Expected valid type item in page tree.")); + throw PDFException(PDFTranslationContext::tr("Expected valid type item in page tree.")); } } else { - throw PDFParserException(PDFTranslationContext::tr("Expected dictionary in page tree.")); + throw PDFException(PDFTranslationContext::tr("Expected dictionary in page tree.")); } } diff --git a/PdfForQtLib/sources/pdfpagecontentprocessor.cpp b/PdfForQtLib/sources/pdfpagecontentprocessor.cpp index 51e9261..7951775 100644 --- a/PdfForQtLib/sources/pdfpagecontentprocessor.cpp +++ b/PdfForQtLib/sources/pdfpagecontentprocessor.cpp @@ -198,6 +198,8 @@ PDFPageContentProcessor::PDFPageContentProcessor(const PDFPage* page, m_patternDictionary(nullptr), m_textBeginEndState(0), m_compatibilityBeginEndState(0), + m_drawingUncoloredTilingPatternState(0), + m_isWarningColorOperatorsInUncoloredTilingPatternReported(false), m_patternBaseMatrix(pagePointToDevicePointMatrix), m_pagePointToDevicePointMatrix(pagePointToDevicePointMatrix) { @@ -230,7 +232,7 @@ QList PDFPageContentProcessor::processContents() m_deviceRGBColorSpace = PDFAbstractColorSpace::createDeviceColorSpaceByName(m_colorSpaceDictionary, m_document, COLOR_SPACE_NAME_DEVICE_RGB); m_deviceCMYKColorSpace = PDFAbstractColorSpace::createDeviceColorSpaceByName(m_colorSpaceDictionary, m_document, COLOR_SPACE_NAME_DEVICE_CMYK); } - catch (PDFParserException exception) + catch (PDFException exception) { m_errorList.append(PDFRenderError(RenderErrorType::Error, exception.getMessage())); @@ -405,7 +407,7 @@ void PDFPageContentProcessor::processContent(const QByteArray& content) if (operatorIDPosition == -1 || operatorEIPosition == -1) { - throw PDFParserException(PDFTranslationContext::tr("Invalid inline image dictionary, ID operator is missing.")); + throw PDFException(PDFTranslationContext::tr("Invalid inline image dictionary, ID operator is missing.")); } Q_ASSERT(operatorBIPosition < content.size()); @@ -438,7 +440,7 @@ void PDFPageContentProcessor::processContent(const QByteArray& content) if (!nameObject.isName()) { - throw PDFParserException(PDFTranslationContext::tr("Expected name in the inline image dictionary stream.")); + throw PDFException(PDFTranslationContext::tr("Expected name in the inline image dictionary stream.")); } // Replace the name, if neccessary @@ -476,7 +478,7 @@ void PDFPageContentProcessor::processContent(const QByteArray& content) if (width <= 0 || height <= 0 || bpc <= 0) { - throw PDFParserException(PDFTranslationContext::tr("Expected name in the inline image dictionary stream.")); + throw PDFException(PDFTranslationContext::tr("Expected name in the inline image dictionary stream.")); } const PDFInteger stride = (width * bpc + 7) / 8; @@ -487,7 +489,7 @@ void PDFPageContentProcessor::processContent(const QByteArray& content) operatorEIPosition = parser.findSubstring("EI", startDataPosition + dataLength); if (operatorEIPosition == -1) { - throw PDFParserException(PDFTranslationContext::tr("Invalid inline image stream.")); + throw PDFException(PDFTranslationContext::tr("Invalid inline image stream.")); } // We must seek after EI operator. Then we will paint the image. Because painting of image can throw exception, @@ -522,7 +524,7 @@ void PDFPageContentProcessor::processContent(const QByteArray& content) } } } - catch (PDFParserException exception) + catch (PDFException exception) { m_operands.clear(); m_errorList.append(PDFRenderError(RenderErrorType::Error, exception.getMessage())); @@ -543,7 +545,7 @@ void PDFPageContentProcessor::processContentStream(const PDFStream* stream) processContent(content); } - catch (PDFParserException exception) + catch (PDFException exception) { m_operands.clear(); m_errorList.append(PDFRenderError(RenderErrorType::Error, exception.getMessage())); @@ -608,8 +610,23 @@ void PDFPageContentProcessor::processPathPainting(const QPainterPath& path, bool case PatternType::Shading: { + PDFPageContentProcessorGraphicStateSaveRestoreGuard guard(this); const PDFShadingPattern* shadingPattern = pattern->getShadingPattern(); + // Apply pattern graphic state + const PDFObject& patternGraphicState = m_document->getObject(shadingPattern->getPatternGraphicState()); + if (!patternGraphicState.isNull()) + { + if (patternGraphicState.isDictionary()) + { + processApplyGraphicState(patternGraphicState.getDictionary()); + } + else + { + throw PDFRendererException(RenderErrorType::Error, PDFTranslationContext::tr("Shading pattern graphic state is invalid.")); + } + } + // We must create a mesh and then draw pattern PDFMeshQualitySettings settings; settings.deviceSpaceMeshingArea = getPageBoundingRectDeviceSpace(); @@ -636,7 +653,7 @@ void PDFPageContentProcessor::processPathPainting(const QPainterPath& path, bool case PatternType::Invalid: { - throw PDFParserException(PDFTranslationContext::tr("Invalid pattern.")); + throw PDFException(PDFTranslationContext::tr("Invalid pattern.")); break; } @@ -682,7 +699,22 @@ void PDFPageContentProcessor::processPathPainting(const QPainterPath& path, bool case PatternType::Shading: { - const PDFShadingPattern* shadingPatern = pattern->getShadingPattern(); + PDFPageContentProcessorGraphicStateSaveRestoreGuard guard(this); + const PDFShadingPattern* shadingPattern = pattern->getShadingPattern(); + + // Apply pattern graphic state + const PDFObject& patternGraphicState = m_document->getObject(shadingPattern->getPatternGraphicState()); + if (!patternGraphicState.isNull()) + { + if (patternGraphicState.isDictionary()) + { + processApplyGraphicState(patternGraphicState.getDictionary()); + } + else + { + throw PDFRendererException(RenderErrorType::Error, PDFTranslationContext::tr("Shading pattern graphic state is invalid.")); + } + } // We must create a mesh and then draw pattern PDFMeshQualitySettings settings; @@ -690,7 +722,7 @@ void PDFPageContentProcessor::processPathPainting(const QPainterPath& path, bool settings.userSpaceToDeviceSpaceMatrix = getPatternBaseMatrix(); settings.initDefaultResolution(); - PDFMesh mesh = shadingPatern->createMesh(settings); + PDFMesh mesh = shadingPattern->createMesh(settings); // We must stroke the path. QPainterPathStroker stroker; @@ -724,7 +756,7 @@ void PDFPageContentProcessor::processPathPainting(const QPainterPath& path, bool case PatternType::Invalid: { - throw PDFParserException(PDFTranslationContext::tr("Invalid pattern.")); + throw PDFException(PDFTranslationContext::tr("Invalid pattern.")); break; } @@ -768,6 +800,8 @@ void PDFPageContentProcessor::processTillingPatternPainting(const PDFTilingPatte QMatrix pathTransformationMatrix = m_graphicState.getCurrentTransformationMatrix() * matrix.inverted(); m_graphicState.setCurrentTransformationMatrix(matrix); + int uncoloredTilingPatternFlag = 0; + // Initialize colors for uncolored color space pattern if (tilingPattern->getPaintingType() == PDFTilingPattern::PaintType::Uncolored) { @@ -776,6 +810,8 @@ void PDFPageContentProcessor::processTillingPatternPainting(const PDFTilingPatte throw PDFRendererException(RenderErrorType::Error, PDFTranslationContext::tr("Uncolored tiling pattern has not underlying color space.")); } + uncoloredTilingPatternFlag = 1; + m_graphicState.setStrokeColorSpace(uncoloredPatternColorSpace); m_graphicState.setFillColorSpace(uncoloredPatternColorSpace); @@ -796,6 +832,9 @@ void PDFPageContentProcessor::processTillingPatternPainting(const PDFTilingPatte updateGraphicState(); + // Mark uncolored flag, if we drawing uncolored color pattern + PDFTemporaryValueChange guard2(&m_drawingUncoloredTilingPatternState, m_drawingUncoloredTilingPatternState + uncoloredTilingPatternFlag); + // Tiling parameters const QRectF tilingArea = pathTransformationMatrix.map(path).boundingRect(); const QRectF boundingBox = tilingPattern->getBoundingBox(); @@ -1523,6 +1562,62 @@ void PDFPageContentProcessor::operatorSetFlatness(PDFReal flatness) updateGraphicState(); } +void PDFPageContentProcessor::processApplyGraphicState(const PDFDictionary* graphicStateDictionary) +{ + PDFDocumentDataLoaderDecorator loader(m_document); + const PDFReal lineWidth = loader.readNumberFromDictionary(graphicStateDictionary, "LW", m_graphicState.getLineWidth()); + const Qt::PenCapStyle penCapStyle = convertLineCapToPenCapStyle(loader.readNumberFromDictionary(graphicStateDictionary, "LC", convertPenCapStyleToLineCap(m_graphicState.getLineCapStyle()))); + const Qt::PenJoinStyle penJoinStyle = convertLineJoinToPenJoinStyle(loader.readNumberFromDictionary(graphicStateDictionary, "LJ", convertPenJoinStyleToLineJoin(m_graphicState.getLineJoinStyle()))); + const PDFReal mitterLimit = loader.readNumberFromDictionary(graphicStateDictionary, "MT", m_graphicState.getMitterLimit()); + + const PDFObject& lineDashPatternObject = m_document->getObject(graphicStateDictionary->get("D")); + if (lineDashPatternObject.isArray()) + { + const PDFArray* lineDashPatternDefinitionArray = lineDashPatternObject.getArray(); + if (lineDashPatternDefinitionArray->getCount() == 2) + { + PDFLineDashPattern pattern(loader.readNumberArray(lineDashPatternDefinitionArray->getItem(0)), loader.readNumber(lineDashPatternDefinitionArray->getItem(1), 0.0)); + m_graphicState.setLineDashPattern(pattern); + } + } + + const PDFObject& renderingIntentObject = m_document->getObject(graphicStateDictionary->get("RI")); + if (renderingIntentObject.isName()) + { + m_graphicState.setRenderingIntent(renderingIntentObject.getString()); + } + + const PDFReal flatness = loader.readNumberFromDictionary(graphicStateDictionary, "FL", m_graphicState.getFlatness()); + const PDFReal smoothness = loader.readNumberFromDictionary(graphicStateDictionary, "SM", m_graphicState.getSmoothness()); + const bool textKnockout = loader.readBooleanFromDictionary(graphicStateDictionary, "TK", m_graphicState.getTextKnockout()); + + // TODO: Implement alpha constant + const PDFReal strokingAlpha = loader.readNumberFromDictionary(graphicStateDictionary, "CA", 1.0); + const PDFReal fillingAlpha = loader.readNumberFromDictionary(graphicStateDictionary, "ca", 1.0); + QByteArray blendMode = loader.readNameFromDictionary(graphicStateDictionary, "BM"); + if (strokingAlpha != 1.0) + { + m_errorList.append(PDFRenderError(RenderErrorType::NotImplemented, PDFTranslationContext::tr("Alpha constant %1 for stroking not implemented!").arg(strokingAlpha))); + } + if (fillingAlpha != 1.0) + { + m_errorList.append(PDFRenderError(RenderErrorType::NotImplemented, PDFTranslationContext::tr("Alpha constant %1 for filling not implemented!").arg(fillingAlpha))); + } + if (!blendMode.isEmpty() && blendMode != "Normal") + { + m_errorList.append(PDFRenderError(RenderErrorType::NotImplemented, PDFTranslationContext::tr("Blend mode '%1' not implemented!").arg(QString::fromLatin1(blendMode)))); + } + + m_graphicState.setLineWidth(lineWidth); + m_graphicState.setLineCapStyle(penCapStyle); + m_graphicState.setLineJoinStyle(penJoinStyle); + m_graphicState.setMitterLimit(mitterLimit); + m_graphicState.setFlatness(flatness); + m_graphicState.setSmoothness(smoothness); + m_graphicState.setTextKnockout(textKnockout); + updateGraphicState(); +} + void PDFPageContentProcessor::operatorSetGraphicState(PDFOperandName dictionaryName) { if (m_extendedGraphicStateDictionary) @@ -1533,59 +1628,7 @@ void PDFPageContentProcessor::operatorSetGraphicState(PDFOperandName dictionaryN if (graphicStateObject.isDictionary()) { const PDFDictionary* graphicStateDictionary = graphicStateObject.getDictionary(); - - PDFDocumentDataLoaderDecorator loader(m_document); - const PDFReal lineWidth = loader.readNumberFromDictionary(graphicStateDictionary, "LW", m_graphicState.getLineWidth()); - const Qt::PenCapStyle penCapStyle = convertLineCapToPenCapStyle(loader.readNumberFromDictionary(graphicStateDictionary, "LC", convertPenCapStyleToLineCap(m_graphicState.getLineCapStyle()))); - const Qt::PenJoinStyle penJoinStyle = convertLineJoinToPenJoinStyle(loader.readNumberFromDictionary(graphicStateDictionary, "LJ", convertPenJoinStyleToLineJoin(m_graphicState.getLineJoinStyle()))); - const PDFReal mitterLimit = loader.readNumberFromDictionary(graphicStateDictionary, "MT", m_graphicState.getMitterLimit()); - - const PDFObject& lineDashPatternObject = m_document->getObject(graphicStateDictionary->get("D")); - if (lineDashPatternObject.isArray()) - { - const PDFArray* lineDashPatternDefinitionArray = lineDashPatternObject.getArray(); - if (lineDashPatternDefinitionArray->getCount() == 2) - { - PDFLineDashPattern pattern(loader.readNumberArray(lineDashPatternDefinitionArray->getItem(0)), loader.readNumber(lineDashPatternDefinitionArray->getItem(1), 0.0)); - m_graphicState.setLineDashPattern(pattern); - } - } - - const PDFObject& renderingIntentObject = m_document->getObject(graphicStateDictionary->get("RI")); - if (renderingIntentObject.isName()) - { - m_graphicState.setRenderingIntent(renderingIntentObject.getString()); - } - - const PDFReal flatness = loader.readNumberFromDictionary(graphicStateDictionary, "FL", m_graphicState.getFlatness()); - const PDFReal smoothness = loader.readNumberFromDictionary(graphicStateDictionary, "SM", m_graphicState.getSmoothness()); - const bool textKnockout = loader.readBooleanFromDictionary(graphicStateDictionary, "TK", m_graphicState.getTextKnockout()); - - // TODO: Implement alpha constant - const PDFReal strokingAlpha = loader.readNumberFromDictionary(graphicStateDictionary, "CA", 1.0); - const PDFReal fillingAlpha = loader.readNumberFromDictionary(graphicStateDictionary, "ca", 1.0); - QByteArray blendMode = loader.readNameFromDictionary(graphicStateDictionary, "BM"); - if (strokingAlpha != 1.0) - { - m_errorList.append(PDFRenderError(RenderErrorType::NotImplemented, PDFTranslationContext::tr("Alpha constant %1 for stroking not implemented!").arg(strokingAlpha))); - } - if (fillingAlpha != 1.0) - { - m_errorList.append(PDFRenderError(RenderErrorType::NotImplemented, PDFTranslationContext::tr("Alpha constant %1 for filling not implemented!").arg(fillingAlpha))); - } - if (!blendMode.isEmpty() && blendMode != "Normal") - { - m_errorList.append(PDFRenderError(RenderErrorType::NotImplemented, PDFTranslationContext::tr("Blend mode '%1' not implemented!").arg(QString::fromLatin1(blendMode)))); - } - - m_graphicState.setLineWidth(lineWidth); - m_graphicState.setLineCapStyle(penCapStyle); - m_graphicState.setLineJoinStyle(penJoinStyle); - m_graphicState.setMitterLimit(mitterLimit); - m_graphicState.setFlatness(flatness); - m_graphicState.setSmoothness(smoothness); - m_graphicState.setTextKnockout(textKnockout); - updateGraphicState(); + processApplyGraphicState(graphicStateDictionary); } else { @@ -1919,6 +1962,12 @@ void PDFPageContentProcessor::operatorType3FontSetOffsetAndBB(PDFReal wx, PDFRea void PDFPageContentProcessor::operatorColorSetStrokingColorSpace(PDFPageContentProcessor::PDFOperandName name) { + if (m_drawingUncoloredTilingPatternState) + { + reportWarningAboutColorOperatorsInUTP(); + return; + } + PDFColorSpacePointer colorSpace = PDFAbstractColorSpace::createColorSpace(m_colorSpaceDictionary, m_document, PDFObject::createName(std::make_shared(QByteArray(name.name)))); if (colorSpace) { @@ -1936,6 +1985,12 @@ void PDFPageContentProcessor::operatorColorSetStrokingColorSpace(PDFPageContentP void PDFPageContentProcessor::operatorColorSetFillingColorSpace(PDFOperandName name) { + if (m_drawingUncoloredTilingPatternState) + { + reportWarningAboutColorOperatorsInUTP(); + return; + } + PDFColorSpacePointer colorSpace = PDFAbstractColorSpace::createColorSpace(m_colorSpaceDictionary, m_document, PDFObject::createName(std::make_shared(QByteArray(name.name)))); if (colorSpace) { @@ -1953,6 +2008,12 @@ void PDFPageContentProcessor::operatorColorSetFillingColorSpace(PDFOperandName n void PDFPageContentProcessor::operatorColorSetStrokingColor() { + if (m_drawingUncoloredTilingPatternState) + { + reportWarningAboutColorOperatorsInUTP(); + return; + } + const PDFAbstractColorSpace* colorSpace = m_graphicState.getStrokeColorSpace(); const size_t colorSpaceComponentCount = colorSpace->getColorComponentCount(); const size_t operandCount = m_operands.size(); @@ -1976,6 +2037,12 @@ void PDFPageContentProcessor::operatorColorSetStrokingColor() void PDFPageContentProcessor::operatorColorSetStrokingColorN() { + if (m_drawingUncoloredTilingPatternState) + { + reportWarningAboutColorOperatorsInUTP(); + return; + } + // In our implementation, operator 'SC' can also set color using all color spaces // PDF reference 1.7 allows here Pattern, Separation, DeviceN and ICCBased color spaces here, // but default operator can use them (with exception of Pattern color space). For pattern color space, @@ -2019,6 +2086,12 @@ void PDFPageContentProcessor::operatorColorSetStrokingColorN() void PDFPageContentProcessor::operatorColorSetFillingColor() { + if (m_drawingUncoloredTilingPatternState) + { + reportWarningAboutColorOperatorsInUTP(); + return; + } + const PDFAbstractColorSpace* colorSpace = m_graphicState.getFillColorSpace(); const size_t colorSpaceComponentCount = colorSpace->getColorComponentCount(); const size_t operandCount = m_operands.size(); @@ -2042,6 +2115,12 @@ void PDFPageContentProcessor::operatorColorSetFillingColor() void PDFPageContentProcessor::operatorColorSetFillingColorN() { + if (m_drawingUncoloredTilingPatternState) + { + reportWarningAboutColorOperatorsInUTP(); + return; + } + // In our implementation, operator 'sc' can also set color using all color spaces // PDF reference 1.7 allows here Pattern, Separation, DeviceN and ICCBased color spaces here, // but default operator can use them (with exception of Pattern color space). For pattern color space, @@ -2085,6 +2164,12 @@ void PDFPageContentProcessor::operatorColorSetFillingColorN() void PDFPageContentProcessor::operatorColorSetDeviceGrayStroking(PDFReal gray) { + if (m_drawingUncoloredTilingPatternState) + { + reportWarningAboutColorOperatorsInUTP(); + return; + } + m_graphicState.setStrokeColorSpace(m_deviceGrayColorSpace); m_graphicState.setStrokeColor(getColorFromColorSpace(m_graphicState.getStrokeColorSpace(), gray)); updateGraphicState(); @@ -2093,6 +2178,12 @@ void PDFPageContentProcessor::operatorColorSetDeviceGrayStroking(PDFReal gray) void PDFPageContentProcessor::operatorColorSetDeviceGrayFilling(PDFReal gray) { + if (m_drawingUncoloredTilingPatternState) + { + reportWarningAboutColorOperatorsInUTP(); + return; + } + m_graphicState.setFillColorSpace(m_deviceGrayColorSpace); m_graphicState.setFillColor(getColorFromColorSpace(m_graphicState.getFillColorSpace(), gray)); updateGraphicState(); @@ -2101,6 +2192,12 @@ void PDFPageContentProcessor::operatorColorSetDeviceGrayFilling(PDFReal gray) void PDFPageContentProcessor::operatorColorSetDeviceRGBStroking(PDFReal r, PDFReal g, PDFReal b) { + if (m_drawingUncoloredTilingPatternState) + { + reportWarningAboutColorOperatorsInUTP(); + return; + } + m_graphicState.setStrokeColorSpace(m_deviceRGBColorSpace); m_graphicState.setStrokeColor(getColorFromColorSpace(m_graphicState.getStrokeColorSpace(), r, g, b)); updateGraphicState(); @@ -2109,6 +2206,12 @@ void PDFPageContentProcessor::operatorColorSetDeviceRGBStroking(PDFReal r, PDFRe void PDFPageContentProcessor::operatorColorSetDeviceRGBFilling(PDFReal r, PDFReal g, PDFReal b) { + if (m_drawingUncoloredTilingPatternState) + { + reportWarningAboutColorOperatorsInUTP(); + return; + } + m_graphicState.setFillColorSpace(m_deviceRGBColorSpace); m_graphicState.setFillColor(getColorFromColorSpace(m_graphicState.getFillColorSpace(), r, g, b)); updateGraphicState(); @@ -2117,6 +2220,12 @@ void PDFPageContentProcessor::operatorColorSetDeviceRGBFilling(PDFReal r, PDFRea void PDFPageContentProcessor::operatorColorSetDeviceCMYKStroking(PDFReal c, PDFReal m, PDFReal y, PDFReal k) { + if (m_drawingUncoloredTilingPatternState) + { + reportWarningAboutColorOperatorsInUTP(); + return; + } + m_graphicState.setStrokeColorSpace(m_deviceCMYKColorSpace); m_graphicState.setStrokeColor(getColorFromColorSpace(m_graphicState.getStrokeColorSpace(), c, m, y, k)); updateGraphicState(); @@ -2125,6 +2234,12 @@ void PDFPageContentProcessor::operatorColorSetDeviceCMYKStroking(PDFReal c, PDFR void PDFPageContentProcessor::operatorColorSetDeviceCMYKFilling(PDFReal c, PDFReal m, PDFReal y, PDFReal k) { + if (m_drawingUncoloredTilingPatternState) + { + reportWarningAboutColorOperatorsInUTP(); + return; + } + m_graphicState.setFillColorSpace(m_deviceCMYKColorSpace); m_graphicState.setFillColor(getColorFromColorSpace(m_graphicState.getFillColorSpace(), c, m, y, k)); updateGraphicState(); @@ -2201,7 +2316,7 @@ void PDFPageContentProcessor::operatorTextSetFontAndFontSize(PDFOperandName font m_graphicState.setTextFontSize(fontSize); updateGraphicState(); } - catch (PDFParserException) + catch (PDFException) { m_graphicState.setTextFont(nullptr); m_graphicState.setTextFontSize(fontSize); @@ -2458,6 +2573,15 @@ void PDFPageContentProcessor::paintXObjectImage(const PDFStream* stream) } } +void PDFPageContentProcessor::reportWarningAboutColorOperatorsInUTP() +{ + if (!m_isWarningColorOperatorsInUncoloredTilingPatternReported) + { + m_isWarningColorOperatorsInUncoloredTilingPatternReported = true; + m_errorList.push_back(PDFRenderError(RenderErrorType::Warning, PDFTranslationContext::tr("Color operators are not allowed in uncolored tilling pattern."))); + } +} + void PDFPageContentProcessor::operatorPaintXObject(PDFPageContentProcessor::PDFOperandName name) { // We want to have empty operands, when we are invoking forms @@ -2808,7 +2932,7 @@ bool PDFPageContentProcessor::isContentSuppressedByOC(PDFObjectReference ocgOrOc { ocmd = PDFOptionalContentMembershipObject::create(m_document, PDFObject::createReference(ocgOrOcmd)); } - catch (PDFParserException e) + catch (PDFException e) { m_errorList.push_back(PDFRenderError(RenderErrorType::Error, e.getMessage())); } diff --git a/PdfForQtLib/sources/pdfpagecontentprocessor.h b/PdfForQtLib/sources/pdfpagecontentprocessor.h index 6986235..1e0ac7b 100644 --- a/PdfForQtLib/sources/pdfpagecontentprocessor.h +++ b/PdfForQtLib/sources/pdfpagecontentprocessor.h @@ -475,6 +475,10 @@ private: PDFColorSpacePointer uncoloredPatternColorSpace, PDFColor uncoloredPatternColor); + /// Applies graphic state dictionary + /// \param graphicStateDictionary Dictionary to be applied to the current graphic state + void processApplyGraphicState(const PDFDictionary* graphicStateDictionary); + enum class MarkedContentKind { OptionalContent, @@ -743,6 +747,9 @@ private: /// Implementation of painting of XObject image void paintXObjectImage(const PDFStream* stream); + /// Report warning about color operators in uncolored tiling pattern + void reportWarningAboutColorOperatorsInUTP(); + const PDFPage* m_page; const PDFDocument* m_document; const PDFFontCache* m_fontCache; @@ -784,6 +791,12 @@ private: /// Compatibility level (if positive, then unrecognized operators are ignored) int m_compatibilityBeginEndState; + /// Is drawing uncolored tiling pattern? + int m_drawingUncoloredTilingPatternState; + + /// Is warning about uncolored tiling patterns reported? + bool m_isWarningColorOperatorsInUncoloredTilingPatternReported; + /// Actually realized physical font PDFCachedItem m_realizedFont; diff --git a/PdfForQtLib/sources/pdfparser.cpp b/PdfForQtLib/sources/pdfparser.cpp index 6ec0c21..034911c 100644 --- a/PdfForQtLib/sources/pdfparser.cpp +++ b/PdfForQtLib/sources/pdfparser.cpp @@ -627,7 +627,7 @@ constexpr bool PDFLexicalAnalyzer::isHexCharacter(const char character) void PDFLexicalAnalyzer::error(const QString& message) const { std::size_t distance = std::distance(m_begin, m_current); - throw PDFParserException(tr("Error near position %1. %2").arg(distance).arg(message)); + throw PDFException(tr("Error near position %1. %2").arg(distance).arg(message)); } PDFObject PDFParsingContext::getObject(const PDFObject& object) @@ -645,7 +645,7 @@ void PDFParsingContext::beginParsingObject(PDFObjectReference reference) { if (m_activeParsedObjectSet.search(reference)) { - throw PDFParserException(tr("Cyclical reference found while parsing object %1 %2.").arg(reference.objectNumber).arg(reference.generation)); + throw PDFException(tr("Cyclical reference found while parsing object %1 %2.").arg(reference.objectNumber).arg(reference.generation)); } else { @@ -927,7 +927,7 @@ PDFObject PDFParser::getObject(PDFObjectReference reference) void PDFParser::error(const QString& message) const { - throw PDFParserException(message); + throw PDFException(message); } void PDFParser::seek(PDFInteger offset) diff --git a/PdfForQtLib/sources/pdfpattern.cpp b/PdfForQtLib/sources/pdfpattern.cpp index 0cbb4de..8951ca7 100644 --- a/PdfForQtLib/sources/pdfpattern.cpp +++ b/PdfForQtLib/sources/pdfpattern.cpp @@ -80,19 +80,19 @@ PDFPatternPtr PDFPattern::createPattern(const PDFDictionary* colorSpaceDictionar // Verify the data if (paintType != PDFTilingPattern::PaintType::Colored && paintType != PDFTilingPattern::PaintType::Uncolored) { - throw PDFParserException(PDFTranslationContext::tr("Invalid tiling pattern - wrong paint type %1.").arg(static_cast(paintType))); + throw PDFException(PDFTranslationContext::tr("Invalid tiling pattern - wrong paint type %1.").arg(static_cast(paintType))); } if (tilingType != PDFTilingPattern::TilingType::ConstantSpacing && tilingType != PDFTilingPattern::TilingType::NoDistortion && tilingType != PDFTilingPattern::TilingType::ConstantSpacingAndFasterTiling) { - throw PDFParserException(PDFTranslationContext::tr("Invalid tiling pattern - wrong tiling type %1.").arg(static_cast(tilingType))); + throw PDFException(PDFTranslationContext::tr("Invalid tiling pattern - wrong tiling type %1.").arg(static_cast(tilingType))); } if (!boundingBox.isValid()) { - throw PDFParserException(PDFTranslationContext::tr("Invalid tiling pattern - bounding box is invalid.").arg(static_cast(paintType))); + throw PDFException(PDFTranslationContext::tr("Invalid tiling pattern - bounding box is invalid.").arg(static_cast(paintType))); } if (isZero(xStep) || isZero(yStep)) { - throw PDFParserException(PDFTranslationContext::tr("Invalid tiling pattern - steps are invalid.").arg(static_cast(paintType))); + throw PDFException(PDFTranslationContext::tr("Invalid tiling pattern - steps are invalid.").arg(static_cast(paintType))); } PDFTilingPattern* pattern = new PDFTilingPattern(); @@ -116,13 +116,13 @@ PDFPatternPtr PDFPattern::createPattern(const PDFDictionary* colorSpaceDictionar } default: - throw PDFParserException(PDFTranslationContext::tr("Invalid pattern.")); + throw PDFException(PDFTranslationContext::tr("Invalid pattern.")); } return PDFPatternPtr(); } - throw PDFParserException(PDFTranslationContext::tr("Invalid pattern.")); + throw PDFException(PDFTranslationContext::tr("Invalid pattern.")); return PDFPatternPtr(); } @@ -136,7 +136,7 @@ PDFPatternPtr PDFPattern::createShadingPattern(const PDFDictionary* colorSpaceDi const PDFObject& dereferencedShadingObject = document->getObject(shadingObject); if (!dereferencedShadingObject.isDictionary() && !dereferencedShadingObject.isStream()) { - throw PDFParserException(PDFTranslationContext::tr("Invalid shading.")); + throw PDFException(PDFTranslationContext::tr("Invalid shading.")); } PDFDocumentDataLoaderDecorator loader(document); @@ -158,7 +158,7 @@ PDFPatternPtr PDFPattern::createShadingPattern(const PDFDictionary* colorSpaceDi if (colorSpace->asPatternColorSpace()) { - throw PDFParserException(PDFTranslationContext::tr("Pattern color space is not valid for shading patterns.")); + throw PDFException(PDFTranslationContext::tr("Pattern color space is not valid for shading patterns.")); } QColor backgroundColor; @@ -180,7 +180,7 @@ PDFPatternPtr PDFPattern::createShadingPattern(const PDFDictionary* colorSpaceDi const PDFArray* array = extendObject.getArray(); if (array->getCount() != 2) { - throw PDFParserException(PDFTranslationContext::tr("Invalid shading pattern extends. Expected 2, but %1 provided.").arg(array->getCount())); + throw PDFException(PDFTranslationContext::tr("Invalid shading pattern extends. Expected 2, but %1 provided.").arg(array->getCount())); } extendStart = loader.readBoolean(array->getItem(0), false); @@ -213,11 +213,11 @@ PDFPatternPtr PDFPattern::createShadingPattern(const PDFDictionary* colorSpaceDi std::vector functionDomain = loader.readNumberArrayFromDictionary(shadingDictionary, "Domain", { 0.0, 1.0, 0.0, 1.0 }); if (functionDomain.size() != 4) { - throw PDFParserException(PDFTranslationContext::tr("Invalid function shading pattern domain. Expected 4 values, but %1 provided.").arg(functionDomain.size())); + throw PDFException(PDFTranslationContext::tr("Invalid function shading pattern domain. Expected 4 values, but %1 provided.").arg(functionDomain.size())); } if (functionDomain[1] < functionDomain[0] || functionDomain[3] < functionDomain[2]) { - throw PDFParserException(PDFTranslationContext::tr("Invalid function shading pattern domain. Invalid domain ranges.")); + throw PDFException(PDFTranslationContext::tr("Invalid function shading pattern domain. Invalid domain ranges.")); } QMatrix domainToTargetTransform = loader.readMatrixFromDictionary(shadingDictionary, "Matrix", QMatrix()); @@ -225,7 +225,7 @@ PDFPatternPtr PDFPattern::createShadingPattern(const PDFDictionary* colorSpaceDi size_t colorComponentCount = colorSpace->getColorComponentCount(); if (functions.size() > 1 && colorComponentCount != functions.size()) { - throw PDFParserException(PDFTranslationContext::tr("Invalid axial shading pattern color functions. Expected %1 functions, but %2 provided.").arg(int(colorComponentCount)).arg(int(functions.size()))); + throw PDFException(PDFTranslationContext::tr("Invalid axial shading pattern color functions. Expected %1 functions, but %2 provided.").arg(int(colorComponentCount)).arg(int(functions.size()))); } // Load items for function shading @@ -250,7 +250,7 @@ PDFPatternPtr PDFPattern::createShadingPattern(const PDFDictionary* colorSpaceDi std::vector coordinates = loader.readNumberArrayFromDictionary(shadingDictionary, "Coords"); if (coordinates.size() != 4) { - throw PDFParserException(PDFTranslationContext::tr("Invalid axial shading pattern coordinates. Expected 4, but %1 provided.").arg(coordinates.size())); + throw PDFException(PDFTranslationContext::tr("Invalid axial shading pattern coordinates. Expected 4, but %1 provided.").arg(coordinates.size())); } std::vector domain = loader.readNumberArrayFromDictionary(shadingDictionary, "Domain"); @@ -260,13 +260,13 @@ PDFPatternPtr PDFPattern::createShadingPattern(const PDFDictionary* colorSpaceDi } if (domain.size() != 2) { - throw PDFParserException(PDFTranslationContext::tr("Invalid axial shading pattern domain. Expected 2, but %1 provided.").arg(domain.size())); + throw PDFException(PDFTranslationContext::tr("Invalid axial shading pattern domain. Expected 2, but %1 provided.").arg(domain.size())); } size_t colorComponentCount = colorSpace->getColorComponentCount(); if (functions.size() > 1 && colorComponentCount != functions.size()) { - throw PDFParserException(PDFTranslationContext::tr("Invalid axial shading pattern color functions. Expected %1 functions, but %2 provided.").arg(int(colorComponentCount)).arg(int(functions.size()))); + throw PDFException(PDFTranslationContext::tr("Invalid axial shading pattern color functions. Expected %1 functions, but %2 provided.").arg(int(colorComponentCount)).arg(int(functions.size()))); } // Load items for axial shading @@ -295,7 +295,7 @@ PDFPatternPtr PDFPattern::createShadingPattern(const PDFDictionary* colorSpaceDi std::vector coordinates = loader.readNumberArrayFromDictionary(shadingDictionary, "Coords"); if (coordinates.size() != 6) { - throw PDFParserException(PDFTranslationContext::tr("Invalid radial shading pattern coordinates. Expected 6, but %1 provided.").arg(coordinates.size())); + throw PDFException(PDFTranslationContext::tr("Invalid radial shading pattern coordinates. Expected 6, but %1 provided.").arg(coordinates.size())); } std::vector domain = loader.readNumberArrayFromDictionary(shadingDictionary, "Domain"); @@ -305,18 +305,18 @@ PDFPatternPtr PDFPattern::createShadingPattern(const PDFDictionary* colorSpaceDi } if (domain.size() != 2) { - throw PDFParserException(PDFTranslationContext::tr("Invalid radial shading pattern domain. Expected 2, but %1 provided.").arg(domain.size())); + throw PDFException(PDFTranslationContext::tr("Invalid radial shading pattern domain. Expected 2, but %1 provided.").arg(domain.size())); } size_t colorComponentCount = colorSpace->getColorComponentCount(); if (functions.size() > 1 && colorComponentCount != functions.size()) { - throw PDFParserException(PDFTranslationContext::tr("Invalid radial shading pattern color functions. Expected %1 functions, but %2 provided.").arg(int(colorComponentCount)).arg(int(functions.size()))); + throw PDFException(PDFTranslationContext::tr("Invalid radial shading pattern color functions. Expected %1 functions, but %2 provided.").arg(int(colorComponentCount)).arg(int(functions.size()))); } if (coordinates[2] < 0.0 || coordinates[5] < 0.0) { - throw PDFParserException(PDFTranslationContext::tr("Radial shading cannot have negative circle radius.")); + throw PDFException(PDFTranslationContext::tr("Radial shading cannot have negative circle radius.")); } // Load items for axial shading @@ -386,12 +386,12 @@ PDFPatternPtr PDFPattern::createShadingPattern(const PDFDictionary* colorSpaceDi PDFInteger bitsPerCoordinate = loader.readIntegerFromDictionary(shadingDictionary, "BitsPerCoordinate", -1); if (!contains(bitsPerCoordinate, std::initializer_list{ 1, 2, 4, 8, 12, 16, 24, 32 })) { - throw PDFParserException(PDFTranslationContext::tr("Invalid bits per coordinate (%1) for shading.").arg(bitsPerCoordinate)); + throw PDFException(PDFTranslationContext::tr("Invalid bits per coordinate (%1) for shading.").arg(bitsPerCoordinate)); } PDFInteger bitsPerComponent = loader.readIntegerFromDictionary(shadingDictionary, "BitsPerComponent", -1); if (!contains(bitsPerComponent, std::initializer_list{ 1, 2, 4, 8, 12, 16 })) { - throw PDFParserException(PDFTranslationContext::tr("Invalid bits per component (%1) for shading.").arg(bitsPerComponent)); + throw PDFException(PDFTranslationContext::tr("Invalid bits per component (%1) for shading.").arg(bitsPerComponent)); } std::vector decode = loader.readNumberArrayFromDictionary(shadingDictionary, "Decode"); @@ -399,7 +399,7 @@ PDFPatternPtr PDFPattern::createShadingPattern(const PDFDictionary* colorSpaceDi { if (decode.size() != 6) { - throw PDFParserException(PDFTranslationContext::tr("Invalid domain for shading. Expected size is 6, actual size is %1.").arg(decode.size())); + throw PDFException(PDFTranslationContext::tr("Invalid domain for shading. Expected size is 6, actual size is %1.").arg(decode.size())); } } else @@ -407,7 +407,7 @@ PDFPatternPtr PDFPattern::createShadingPattern(const PDFDictionary* colorSpaceDi const size_t expectedSize = colorSpace->getColorComponentCount() * 2 + 4; if (decode.size() != expectedSize) { - throw PDFParserException(PDFTranslationContext::tr("Invalid domain for shading. Expected size is %1, actual size is %2.").arg(expectedSize).arg(decode.size())); + throw PDFException(PDFTranslationContext::tr("Invalid domain for shading. Expected size is %1, actual size is %2.").arg(expectedSize).arg(decode.size())); } } @@ -436,7 +436,7 @@ PDFPatternPtr PDFPattern::createShadingPattern(const PDFDictionary* colorSpaceDi PDFInteger bitsPerFlag = loader.readIntegerFromDictionary(shadingDictionary, "BitsPerFlag", -1); if (!contains(bitsPerFlag, std::initializer_list{ 2, 4, 8 })) { - throw PDFParserException(PDFTranslationContext::tr("Invalid bits per flag (%1) for shading.").arg(bitsPerFlag)); + throw PDFException(PDFTranslationContext::tr("Invalid bits per flag (%1) for shading.").arg(bitsPerFlag)); } type4567Shading->m_bitsPerFlag = bitsPerFlag; break; @@ -447,7 +447,7 @@ PDFPatternPtr PDFPattern::createShadingPattern(const PDFDictionary* colorSpaceDi latticeFormGouradTriangleShading->m_verticesPerRow = loader.readIntegerFromDictionary(shadingDictionary, "VerticesPerRow", -1); if (latticeFormGouradTriangleShading->m_verticesPerRow < 2) { - throw PDFParserException(PDFTranslationContext::tr("Invalid vertices per row (%1) for lattice-form gourad triangle meshing.").arg(latticeFormGouradTriangleShading->m_verticesPerRow)); + throw PDFException(PDFTranslationContext::tr("Invalid vertices per row (%1) for lattice-form gourad triangle meshing.").arg(latticeFormGouradTriangleShading->m_verticesPerRow)); } break; } @@ -461,11 +461,11 @@ PDFPatternPtr PDFPattern::createShadingPattern(const PDFDictionary* colorSpaceDi default: { - throw PDFParserException(PDFTranslationContext::tr("Invalid shading pattern type (%1).").arg(static_cast(shadingType))); + throw PDFException(PDFTranslationContext::tr("Invalid shading pattern type (%1).").arg(static_cast(shadingType))); } } - throw PDFParserException(PDFTranslationContext::tr("Invalid shading.")); + throw PDFException(PDFTranslationContext::tr("Invalid shading.")); return PDFPatternPtr(); } @@ -2018,7 +2018,7 @@ PDFMesh PDFTensorProductPatchShading::createMesh(const PDFMeshQualitySettings& s { if (patches.empty()) { - throw PDFParserException(PDFTranslationContext::tr("Nonzero flag for first patch (flags = %1).").arg(flags)); + throw PDFException(PDFTranslationContext::tr("Nonzero flag for first patch (flags = %1).").arg(flags)); } const PDFTensorPatch& previousPatch = patches.back(); @@ -2061,7 +2061,7 @@ PDFMesh PDFTensorProductPatchShading::createMesh(const PDFMeshQualitySettings& s { if (patches.empty()) { - throw PDFParserException(PDFTranslationContext::tr("Nonzero flag for first patch (flags = %1).").arg(flags)); + throw PDFException(PDFTranslationContext::tr("Nonzero flag for first patch (flags = %1).").arg(flags)); } const PDFTensorPatch& previousPatch = patches.back(); @@ -2104,7 +2104,7 @@ PDFMesh PDFTensorProductPatchShading::createMesh(const PDFMeshQualitySettings& s { if (patches.empty()) { - throw PDFParserException(PDFTranslationContext::tr("Nonzero flag for first patch (flags = %1).").arg(flags)); + throw PDFException(PDFTranslationContext::tr("Nonzero flag for first patch (flags = %1).").arg(flags)); } const PDFTensorPatch& previousPatch = patches.back(); @@ -2144,7 +2144,7 @@ PDFMesh PDFTensorProductPatchShading::createMesh(const PDFMeshQualitySettings& s } default: - throw PDFParserException(PDFTranslationContext::tr("Invalid data in tensor product patch shading (flags = %1).").arg(flags)); + throw PDFException(PDFTranslationContext::tr("Invalid data in tensor product patch shading (flags = %1).").arg(flags)); } } @@ -2602,7 +2602,7 @@ PDFMesh PDFCoonsPatchShading::createMesh(const PDFMeshQualitySettings& settings) } default: - throw PDFParserException(PDFTranslationContext::tr("Invalid data in coons patch shading (flags = %1).").arg(flags)); + throw PDFException(PDFTranslationContext::tr("Invalid data in coons patch shading (flags = %1).").arg(flags)); } } @@ -2610,8 +2610,6 @@ PDFMesh PDFCoonsPatchShading::createMesh(const PDFMeshQualitySettings& settings) return mesh; } -// TODO: Apply graphic state of the pattern // TODO: Implement settings of meshing in the settings dialog -// TODO: Zmenit PDFParserException na PDFException } // namespace pdf diff --git a/PdfForQtLib/sources/pdfsecurityhandler.cpp b/PdfForQtLib/sources/pdfsecurityhandler.cpp index a774c2a..8afe724 100644 --- a/PdfForQtLib/sources/pdfsecurityhandler.cpp +++ b/PdfForQtLib/sources/pdfsecurityhandler.cpp @@ -206,7 +206,7 @@ PDFSecurityHandlerPointer PDFSecurityHandler::createSecurityHandler(const PDFObj if (!encryptionDictionaryObject.isDictionary()) { - throw PDFParserException(PDFTranslationContext::tr("Invalid encryption dictionary.")); + throw PDFException(PDFTranslationContext::tr("Invalid encryption dictionary.")); } const PDFDictionary* dictionary = encryptionDictionaryObject.getDictionary(); @@ -224,7 +224,7 @@ PDFSecurityHandlerPointer PDFSecurityHandler::createSecurityHandler(const PDFObj { if (required) { - throw PDFParserException(PDFTranslationContext::tr("Invalid value for entry '%1' in encryption dictionary. Name expected.").arg(QString::fromLatin1(key))); + throw PDFException(PDFTranslationContext::tr("Invalid value for entry '%1' in encryption dictionary. Name expected.").arg(QString::fromLatin1(key))); } return defaultValue ? QByteArray(defaultValue) : QByteArray(); @@ -240,7 +240,7 @@ PDFSecurityHandlerPointer PDFSecurityHandler::createSecurityHandler(const PDFObj { if (required) { - throw PDFParserException(PDFTranslationContext::tr("Invalid value for entry '%1' in encryption dictionary. Integer expected.").arg(QString::fromLatin1(key))); + throw PDFException(PDFTranslationContext::tr("Invalid value for entry '%1' in encryption dictionary. Integer expected.").arg(QString::fromLatin1(key))); } return defaultValue; @@ -252,7 +252,7 @@ PDFSecurityHandlerPointer PDFSecurityHandler::createSecurityHandler(const PDFObj QByteArray filterName = getName(dictionary, "Filter", true); if (filterName != "Standard") { - throw PDFParserException(PDFTranslationContext::tr("Unknown security handler.")); + throw PDFException(PDFTranslationContext::tr("Unknown security handler.")); } const int V = getInt(dictionary, "V", true); @@ -260,7 +260,7 @@ PDFSecurityHandlerPointer PDFSecurityHandler::createSecurityHandler(const PDFObj // Check V if (V < 1 || V > 5) { - throw PDFParserException(PDFTranslationContext::tr("Unsupported version of document encryption (V = %1).").arg(V)); + throw PDFException(PDFTranslationContext::tr("Unsupported version of document encryption (V = %1).").arg(V)); } // Only valid for V == 2 or V == 3, otherwise we set file encryption key length manually @@ -309,7 +309,7 @@ PDFSecurityHandlerPointer PDFSecurityHandler::createSecurityHandler(const PDFObj { if (!object.isDictionary()) { - throw PDFParserException(PDFTranslationContext::tr("Crypt filter is not a dictionary!")); + throw PDFException(PDFTranslationContext::tr("Crypt filter is not a dictionary!")); } const PDFDictionary* cryptFilterDictionary = object.getDictionary(); @@ -334,7 +334,7 @@ PDFSecurityHandlerPointer PDFSecurityHandler::createSecurityHandler(const PDFObj } else { - throw PDFParserException(PDFTranslationContext::tr("Unsupported encryption algorithm '%1'.").arg(QString::fromLatin1(CFMName))); + throw PDFException(PDFTranslationContext::tr("Unsupported encryption algorithm '%1'.").arg(QString::fromLatin1(CFMName))); } QByteArray authEventName = getName(cryptFilterDictionary, "AuthEvent", false, "DocOpen"); @@ -348,7 +348,7 @@ PDFSecurityHandlerPointer PDFSecurityHandler::createSecurityHandler(const PDFObj } else { - throw PDFParserException(PDFTranslationContext::tr("Unsupported authorization event '%1'.").arg(QString::fromLatin1(authEventName))); + throw PDFException(PDFTranslationContext::tr("Unsupported authorization event '%1'.").arg(QString::fromLatin1(authEventName))); } filter.keyLength = getInt(cryptFilterDictionary, "Length", false, Length / 8); @@ -370,7 +370,7 @@ PDFSecurityHandlerPointer PDFSecurityHandler::createSecurityHandler(const PDFObj if (it == handler.m_cryptFilters.cend()) { - throw PDFParserException(PDFTranslationContext::tr("Uknown crypt filter '%1'.").arg(QString::fromLatin1(name))); + throw PDFException(PDFTranslationContext::tr("Uknown crypt filter '%1'.").arg(QString::fromLatin1(name))); } return it->second; @@ -394,7 +394,7 @@ PDFSecurityHandlerPointer PDFSecurityHandler::createSecurityHandler(const PDFObj int R = getInt(dictionary, "R", true); if (R < 2 || R > 6) { - throw PDFParserException(PDFTranslationContext::tr("Revision %1 of standard security handler is not supported.").arg(R)); + throw PDFException(PDFTranslationContext::tr("Revision %1 of standard security handler is not supported.").arg(R)); } handler.m_R = R; @@ -413,12 +413,12 @@ PDFSecurityHandlerPointer PDFSecurityHandler::createSecurityHandler(const PDFObj if (result.size() != size) { - throw PDFParserException(PDFTranslationContext::tr("Expected %1 characters long string in entry '%2'. Provided length is %3.").arg(size).arg(QString::fromLatin1(key)).arg(result.size())); + throw PDFException(PDFTranslationContext::tr("Expected %1 characters long string in entry '%2'. Provided length is %3.").arg(size).arg(QString::fromLatin1(key)).arg(result.size())); } } else { - throw PDFParserException(PDFTranslationContext::tr("Expected %1 characters long string in entry '%2'.").arg(size).arg(QString::fromLatin1(key))); + throw PDFException(PDFTranslationContext::tr("Expected %1 characters long string in entry '%2'.").arg(size).arg(QString::fromLatin1(key))); } return result; @@ -570,24 +570,24 @@ PDFSecurityHandler::AuthorizationResult PDFStandardSecurityHandler::authenticate // 1) Checks, if bytes 9, 10, 11 are 'a', 'd', 'b' if (decodedPerms[9] != 'a' || decodedPerms[10] != 'd' || decodedPerms[11] != 'b') { - throw PDFParserException(PDFTranslationContext::tr("Permissions entry in the Encryption dictionary is invalid.")); + throw PDFException(PDFTranslationContext::tr("Permissions entry in the Encryption dictionary is invalid.")); } // 2) Verify, that bytes 0-3 are valid permissions entry const uint32_t permissions = qFromLittleEndian(*reinterpret_cast(decodedPerms.data())); if (permissions != m_permissions) { - throw PDFParserException(PDFTranslationContext::tr("Security permissions are manipulated. Can't open the document.")); + throw PDFException(PDFTranslationContext::tr("Security permissions are manipulated. Can't open the document.")); } // 3) Verify, that byte 8 is 'T' or 'F' and is equal to EncryptMetadata entry if (decodedPerms[8] != 'T' && decodedPerms[8] != 'F') { - throw PDFParserException(PDFTranslationContext::tr("Security permissions are manipulated. Can't open the document.")); + throw PDFException(PDFTranslationContext::tr("Security permissions are manipulated. Can't open the document.")); } if ((decodedPerms[8] == 'T') != m_encryptMetadata) { - throw PDFParserException(PDFTranslationContext::tr("Security permissions are manipulated. Can't open the document.")); + throw PDFException(PDFTranslationContext::tr("Security permissions are manipulated. Can't open the document.")); } return m_authorizationData.authorizationResult; @@ -774,7 +774,7 @@ QByteArray PDFStandardSecurityHandler::decryptByFilter(const QByteArray& data, c auto it = m_cryptFilters.find(filterName); if (it == m_cryptFilters.cend()) { - throw PDFParserException(PDFTranslationContext::tr("Crypt filter '%1' not found.").arg(QString::fromLatin1(filterName))); + throw PDFException(PDFTranslationContext::tr("Crypt filter '%1' not found.").arg(QString::fromLatin1(filterName))); } return decryptUsingFilter(data, it->second, reference); @@ -812,7 +812,7 @@ QByteArray PDFStandardSecurityHandler::createFileEncryptionKey(const QByteArray& const int keyByteLength = m_keyLength / 8; if (keyByteLength > MD5_DIGEST_LENGTH) { - throw PDFParserException(PDFTranslationContext::tr("Encryption key length (%1) exceeded maximal value of.").arg(keyByteLength).arg(MD5_DIGEST_LENGTH)); + throw PDFException(PDFTranslationContext::tr("Encryption key length (%1) exceeded maximal value of.").arg(keyByteLength).arg(MD5_DIGEST_LENGTH)); } if (m_R >= 3) @@ -841,7 +841,7 @@ QByteArray PDFStandardSecurityHandler::createFileEncryptionKey(const QByteArray& default: { - throw PDFParserException(PDFTranslationContext::tr("Revision %1 of standard security handler is not supported.").arg(m_R)); + throw PDFException(PDFTranslationContext::tr("Revision %1 of standard security handler is not supported.").arg(m_R)); } } @@ -904,7 +904,7 @@ QByteArray PDFStandardSecurityHandler::createEntryValueU_r234(const QByteArray& default: { - throw PDFParserException(PDFTranslationContext::tr("Revision %1 of standard security handler is not supported.").arg(m_R)); + throw PDFException(PDFTranslationContext::tr("Revision %1 of standard security handler is not supported.").arg(m_R)); } } @@ -926,7 +926,7 @@ QByteArray PDFStandardSecurityHandler::createUserPasswordFromOwnerPassword(const const int keyByteLength = m_keyLength / 8; if (keyByteLength > MD5_DIGEST_LENGTH) { - throw PDFParserException(PDFTranslationContext::tr("Encryption key length (%1) exceeded maximal value of.").arg(keyByteLength).arg(MD5_DIGEST_LENGTH)); + throw PDFException(PDFTranslationContext::tr("Encryption key length (%1) exceeded maximal value of.").arg(keyByteLength).arg(MD5_DIGEST_LENGTH)); } if (m_R >= 3) @@ -977,7 +977,7 @@ QByteArray PDFStandardSecurityHandler::createUserPasswordFromOwnerPassword(const default: { - throw PDFParserException(PDFTranslationContext::tr("Revision %1 of standard security handler is not supported.").arg(m_R)); + throw PDFException(PDFTranslationContext::tr("Revision %1 of standard security handler is not supported.").arg(m_R)); } } diff --git a/PdfForQtLib/sources/pdfstreamfilters.cpp b/PdfForQtLib/sources/pdfstreamfilters.cpp index 529163c..214b800 100644 --- a/PdfForQtLib/sources/pdfstreamfilters.cpp +++ b/PdfForQtLib/sources/pdfstreamfilters.cpp @@ -263,7 +263,7 @@ QByteArray PDFLzwStreamDecoder::decompress() else { // Unknown code - throw PDFParserException(PDFTranslationContext::tr("Invalid code in the LZW stream.")); + throw PDFException(PDFTranslationContext::tr("Invalid code in the LZW stream.")); } m_newCharacter = m_sequence.front(); @@ -415,7 +415,7 @@ QByteArray PDFFlateDecodeFilter::uncompress(const QByteArray& data) int error = inflateInit(&stream); if (error != Z_OK) { - throw PDFParserException(PDFTranslationContext::tr("Failed to initialize flate decompression stream.")); + throw PDFException(PDFTranslationContext::tr("Failed to initialize flate decompression stream.")); } do @@ -443,7 +443,7 @@ QByteArray PDFFlateDecodeFilter::uncompress(const QByteArray& data) break; // No error, normal behaviour default: - throw PDFParserException(PDFTranslationContext::tr("Error decompressing by flate method: %1").arg(errorMessage)); + throw PDFException(PDFTranslationContext::tr("Error decompressing by flate method: %1").arg(errorMessage)); } return result; @@ -643,7 +643,7 @@ PDFStreamPredictor PDFStreamPredictor::createPredictor(const PDFObjectFetcher& o PDFInteger value = object.getInteger(); if (value < min || value > max) { - throw PDFParserException(PDFTranslationContext::tr("Property '%1' should be in range from %2 to %3.").arg(QString::fromLatin1(key)).arg(min).arg(max)); + throw PDFException(PDFTranslationContext::tr("Property '%1' should be in range from %2 to %3.").arg(QString::fromLatin1(key)).arg(min).arg(max)); } return value; @@ -653,7 +653,7 @@ PDFStreamPredictor PDFStreamPredictor::createPredictor(const PDFObjectFetcher& o return defaultValue; } - throw PDFParserException(PDFTranslationContext::tr("Invalid property '%1' of the stream predictor parameters.").arg(QString::fromLatin1(key))); + throw PDFException(PDFTranslationContext::tr("Invalid property '%1' of the stream predictor parameters.").arg(QString::fromLatin1(key))); return 0; }; @@ -688,7 +688,7 @@ QByteArray PDFStreamPredictor::apply(const QByteArray& data) const } } - throw PDFParserException(PDFTranslationContext::tr("Invalid predictor algorithm.")); + throw PDFException(PDFTranslationContext::tr("Invalid predictor algorithm.")); return QByteArray(); } @@ -801,7 +801,7 @@ QByteArray PDFStreamPredictor::applyTIFFPredictor(const QByteArray& data) const Q_UNUSED(data); // TODO: Implement TIFF algorithm filter - throw PDFParserException(PDFTranslationContext::tr("Invalid predictor algorithm.")); + throw PDFException(PDFTranslationContext::tr("Invalid predictor algorithm.")); return QByteArray(); } @@ -812,7 +812,7 @@ QByteArray PDFCryptFilter::apply(const QByteArray& data, { if (!securityHandler) { - throw PDFParserException(PDFTranslationContext::tr("Security handler required, but not provided.")); + throw PDFException(PDFTranslationContext::tr("Security handler required, but not provided.")); } PDFObjectReference objectReference; diff --git a/PdfForQtLib/sources/pdfutils.cpp b/PdfForQtLib/sources/pdfutils.cpp index e341d0e..d9257df 100644 --- a/PdfForQtLib/sources/pdfutils.cpp +++ b/PdfForQtLib/sources/pdfutils.cpp @@ -46,7 +46,7 @@ PDFBitReader::Value PDFBitReader::read(PDFBitReader::Value bits) } else { - throw PDFParserException(PDFTranslationContext::tr("Not enough data to read %1-bit value.").arg(bits)); + throw PDFException(PDFTranslationContext::tr("Not enough data to read %1-bit value.").arg(bits)); } } @@ -66,7 +66,7 @@ void PDFBitReader::seek(qint64 position) } else { - throw PDFParserException(PDFTranslationContext::tr("Can't seek to position %1.").arg(position)); + throw PDFException(PDFTranslationContext::tr("Can't seek to position %1.").arg(position)); } } diff --git a/PdfForQtLib/sources/pdfxreftable.cpp b/PdfForQtLib/sources/pdfxreftable.cpp index 365c1c9..4da9a5c 100644 --- a/PdfForQtLib/sources/pdfxreftable.cpp +++ b/PdfForQtLib/sources/pdfxreftable.cpp @@ -65,7 +65,7 @@ void PDFXRefTable::readXRefTable(PDFParsingContext* context, const QByteArray& b if (!firstObject.isInt() || !countObject.isInt()) { - throw PDFParserException(tr("Invalid format of reference table.")); + throw PDFException(tr("Invalid format of reference table.")); } PDFInteger firstObjectNumber = firstObject.getInteger(); @@ -90,17 +90,17 @@ void PDFXRefTable::readXRefTable(PDFParsingContext* context, const QByteArray& b bool occupied = parser.fetchCommand(PDF_XREF_OCCUPIED); if (!occupied && !parser.fetchCommand(PDF_XREF_FREE)) { - throw PDFParserException(tr("Bad format of reference table entry.")); + throw PDFException(tr("Bad format of reference table entry.")); } if (!offset.isInt() || !generation.isInt()) { - throw PDFParserException(tr("Bad format of reference table entry.")); + throw PDFException(tr("Bad format of reference table entry.")); } if (static_cast(objectNumber) >= m_entries.size()) { - throw PDFParserException(tr("Bad format of reference table entry.")); + throw PDFException(tr("Bad format of reference table entry.")); } Entry entry; @@ -121,7 +121,7 @@ void PDFXRefTable::readXRefTable(PDFParsingContext* context, const QByteArray& b PDFObject trailerDictionary = parser.getObject(); if (!trailerDictionary.isDictionary()) { - throw PDFParserException(tr("Trailer dictionary is invalid.")); + throw PDFException(tr("Trailer dictionary is invalid.")); } // Now, we have scanned the table. If we didn't have a trailer dictionary yet, then @@ -138,7 +138,7 @@ void PDFXRefTable::readXRefTable(PDFParsingContext* context, const QByteArray& b if (!previousOffset.isInt()) { - throw PDFParserException(tr("Offset of previous reference table is invalid.")); + throw PDFException(tr("Offset of previous reference table is invalid.")); } workSet.push(previousOffset.getInteger()); @@ -158,19 +158,19 @@ void PDFXRefTable::readXRefTable(PDFParsingContext* context, const QByteArray& b if (!crossReferenceStreamObjectNumber.isInt() || !crossReferenceStreamGeneration.isInt()) { - throw PDFParserException(tr("Invalid format of reference table.")); + throw PDFException(tr("Invalid format of reference table.")); } if (!parser.fetchCommand(PDF_OBJECT_START_MARK)) { - throw PDFParserException(tr("Invalid format of reference table.")); + throw PDFException(tr("Invalid format of reference table.")); } PDFObject crossReferenceObject = parser.getObject(); if (!parser.fetchCommand(PDF_OBJECT_END_MARK)) { - throw PDFParserException(tr("Invalid format of reference table.")); + throw PDFException(tr("Invalid format of reference table.")); } if (crossReferenceObject.isStream()) @@ -183,7 +183,7 @@ void PDFXRefTable::readXRefTable(PDFParsingContext* context, const QByteArray& b PDFObject sizeObject = crossReferenceStreamDictionary->get("Size"); if (!sizeObject.isInt() || sizeObject.getInteger() < 0) { - throw PDFParserException(tr("Invalid format of cross-reference stream.")); + throw PDFException(tr("Invalid format of cross-reference stream.")); } const PDFInteger desiredSize = sizeObject.getInteger(); @@ -223,7 +223,7 @@ void PDFXRefTable::readXRefTable(PDFParsingContext* context, const QByteArray& b } else { - throw PDFParserException(tr("Invalid format of cross-reference stream.")); + throw PDFException(tr("Invalid format of cross-reference stream.")); } } } @@ -240,7 +240,7 @@ void PDFXRefTable::readXRefTable(PDFParsingContext* context, const QByteArray& b if (wArray.size() != 3 || indexArray.empty() || (indexArray.size() % 2 != 0)) { - throw PDFParserException(tr("Invalid format of cross-reference stream.")); + throw PDFException(tr("Invalid format of cross-reference stream.")); } const int columnTypeBytes = wArray[0]; @@ -268,7 +268,7 @@ void PDFXRefTable::readXRefTable(PDFParsingContext* context, const QByteArray& b // data aren't corrupted etc.) if (dataStream.status() != QDataStream::Ok) { - throw PDFParserException(tr("Invalid format of cross-reference stream - not enough data in the stream.")); + throw PDFException(tr("Invalid format of cross-reference stream - not enough data in the stream.")); } } @@ -343,7 +343,7 @@ void PDFXRefTable::readXRefTable(PDFParsingContext* context, const QByteArray& b continue; } - throw PDFParserException(tr("Invalid format of reference table.")); + throw PDFException(tr("Invalid format of reference table.")); } } } diff --git a/UnitTests/tst_lexicalanalyzertest.cpp b/UnitTests/tst_lexicalanalyzertest.cpp index dd3408e..dc4ad5a 100644 --- a/UnitTests/tst_lexicalanalyzertest.cpp +++ b/UnitTests/tst_lexicalanalyzertest.cpp @@ -214,20 +214,20 @@ void LexicalAnalyzerTest::test_invalid_input() bigNumber.front() = '1'; bigNumber.back() = 0; - QVERIFY_EXCEPTION_THROWN(scanWholeStream("(\\9adoctalnumber)"), pdf::PDFParserException); - QVERIFY_EXCEPTION_THROWN(scanWholeStream("(\\)"), pdf::PDFParserException); - QVERIFY_EXCEPTION_THROWN(scanWholeStream("123 456 +4-5"), pdf::PDFParserException); - QVERIFY_EXCEPTION_THROWN(scanWholeStream("123 456 +"), pdf::PDFParserException); - QVERIFY_EXCEPTION_THROWN(scanWholeStream("123 456 + 45"), pdf::PDFParserException); - QVERIFY_EXCEPTION_THROWN(scanWholeStream(bigNumber.constData()), pdf::PDFParserException); - QVERIFY_EXCEPTION_THROWN(scanWholeStream("/#Q1FF"), pdf::PDFParserException); - QVERIFY_EXCEPTION_THROWN(scanWholeStream("/#1QFF"), pdf::PDFParserException); - QVERIFY_EXCEPTION_THROWN(scanWholeStream("/# "), pdf::PDFParserException); - QVERIFY_EXCEPTION_THROWN(scanWholeStream(""), pdf::PDFParserException); - QVERIFY_EXCEPTION_THROWN(scanWholeStream("<1FA3"), pdf::PDFParserException); - QVERIFY_EXCEPTION_THROWN(scanWholeStream("<1FA"), pdf::PDFParserException); - QVERIFY_EXCEPTION_THROWN(scanWholeStream("> albatros"), pdf::PDFParserException); - QVERIFY_EXCEPTION_THROWN(scanWholeStream(")"), pdf::PDFParserException); + QVERIFY_EXCEPTION_THROWN(scanWholeStream("(\\9adoctalnumber)"), pdf::PDFException); + QVERIFY_EXCEPTION_THROWN(scanWholeStream("(\\)"), pdf::PDFException); + QVERIFY_EXCEPTION_THROWN(scanWholeStream("123 456 +4-5"), pdf::PDFException); + QVERIFY_EXCEPTION_THROWN(scanWholeStream("123 456 +"), pdf::PDFException); + QVERIFY_EXCEPTION_THROWN(scanWholeStream("123 456 + 45"), pdf::PDFException); + QVERIFY_EXCEPTION_THROWN(scanWholeStream(bigNumber.constData()), pdf::PDFException); + QVERIFY_EXCEPTION_THROWN(scanWholeStream("/#Q1FF"), pdf::PDFException); + QVERIFY_EXCEPTION_THROWN(scanWholeStream("/#1QFF"), pdf::PDFException); + QVERIFY_EXCEPTION_THROWN(scanWholeStream("/# "), pdf::PDFException); + QVERIFY_EXCEPTION_THROWN(scanWholeStream(""), pdf::PDFException); + QVERIFY_EXCEPTION_THROWN(scanWholeStream("<1FA3"), pdf::PDFException); + QVERIFY_EXCEPTION_THROWN(scanWholeStream("<1FA"), pdf::PDFException); + QVERIFY_EXCEPTION_THROWN(scanWholeStream("> albatros"), pdf::PDFException); + QVERIFY_EXCEPTION_THROWN(scanWholeStream(")"), pdf::PDFException); } void LexicalAnalyzerTest::test_header_regexp() @@ -445,7 +445,7 @@ void LexicalAnalyzerTest::test_sampled_function() pdf::PDFFunctionPtr function = pdf::PDFFunction::createFunction(&document, parser.getObject()); QVERIFY(!function); - }, pdf::PDFParserException); + }, pdf::PDFException); // Test invalid inputs QVERIFY_EXCEPTION_THROWN( @@ -466,7 +466,7 @@ void LexicalAnalyzerTest::test_sampled_function() pdf::PDFFunctionPtr function = pdf::PDFFunction::createFunction(&document, parser.getObject()); QVERIFY(!function); - }, pdf::PDFParserException); + }, pdf::PDFException); // Test invalid inputs QVERIFY_EXCEPTION_THROWN( @@ -487,7 +487,7 @@ void LexicalAnalyzerTest::test_sampled_function() pdf::PDFFunctionPtr function = pdf::PDFFunction::createFunction(&document, parser.getObject()); QVERIFY(!function); - }, pdf::PDFParserException); + }, pdf::PDFException); // Test invalid inputs QVERIFY_EXCEPTION_THROWN( @@ -508,7 +508,7 @@ void LexicalAnalyzerTest::test_sampled_function() pdf::PDFFunctionPtr function = pdf::PDFFunction::createFunction(&document, parser.getObject()); QVERIFY(!function); - }, pdf::PDFParserException); + }, pdf::PDFException); // Test invalid inputs QVERIFY_EXCEPTION_THROWN( @@ -529,7 +529,7 @@ void LexicalAnalyzerTest::test_sampled_function() pdf::PDFFunctionPtr function = pdf::PDFFunction::createFunction(&document, parser.getObject()); QVERIFY(!function); - }, pdf::PDFParserException); + }, pdf::PDFException); // Test invalid inputs QVERIFY_EXCEPTION_THROWN( @@ -551,7 +551,7 @@ void LexicalAnalyzerTest::test_sampled_function() pdf::PDFFunctionPtr function = pdf::PDFFunction::createFunction(&document, parser.getObject()); QVERIFY(!function); - }, pdf::PDFParserException); + }, pdf::PDFException); // Test invalid inputs QVERIFY_EXCEPTION_THROWN( @@ -573,7 +573,7 @@ void LexicalAnalyzerTest::test_sampled_function() pdf::PDFFunctionPtr function = pdf::PDFFunction::createFunction(&document, parser.getObject()); QVERIFY(!function); - }, pdf::PDFParserException); + }, pdf::PDFException); // Test invalid inputs QVERIFY_EXCEPTION_THROWN( @@ -593,7 +593,7 @@ void LexicalAnalyzerTest::test_sampled_function() pdf::PDFFunctionPtr function = pdf::PDFFunction::createFunction(&document, parser.getObject()); QVERIFY(!function); - }, pdf::PDFParserException); + }, pdf::PDFException); // Test invalid inputs QVERIFY_EXCEPTION_THROWN( @@ -613,7 +613,7 @@ void LexicalAnalyzerTest::test_sampled_function() pdf::PDFFunctionPtr function = pdf::PDFFunction::createFunction(&document, parser.getObject()); QVERIFY(!function); - }, pdf::PDFParserException); + }, pdf::PDFException); } void LexicalAnalyzerTest::test_exponential_function() @@ -731,7 +731,7 @@ void LexicalAnalyzerTest::test_exponential_function() pdf::PDFFunctionPtr function = pdf::PDFFunction::createFunction(&document, parser.getObject()); QVERIFY(!function); - }, pdf::PDFParserException); + }, pdf::PDFException); QVERIFY_EXCEPTION_THROWN( { @@ -746,7 +746,7 @@ void LexicalAnalyzerTest::test_exponential_function() pdf::PDFFunctionPtr function = pdf::PDFFunction::createFunction(&document, parser.getObject()); QVERIFY(!function); - }, pdf::PDFParserException); + }, pdf::PDFException); QVERIFY_EXCEPTION_THROWN( { @@ -761,7 +761,7 @@ void LexicalAnalyzerTest::test_exponential_function() pdf::PDFFunctionPtr function = pdf::PDFFunction::createFunction(&document, parser.getObject()); QVERIFY(!function); - }, pdf::PDFParserException); + }, pdf::PDFException); QVERIFY_EXCEPTION_THROWN( { @@ -776,7 +776,7 @@ void LexicalAnalyzerTest::test_exponential_function() pdf::PDFFunctionPtr function = pdf::PDFFunction::createFunction(&document, parser.getObject()); QVERIFY(!function); - }, pdf::PDFParserException); + }, pdf::PDFException); QVERIFY_EXCEPTION_THROWN( { @@ -794,7 +794,7 @@ void LexicalAnalyzerTest::test_exponential_function() pdf::PDFFunctionPtr function = pdf::PDFFunction::createFunction(&document, parser.getObject()); QVERIFY(!function); - }, pdf::PDFParserException); + }, pdf::PDFException); QVERIFY_EXCEPTION_THROWN( { @@ -811,7 +811,7 @@ void LexicalAnalyzerTest::test_exponential_function() pdf::PDFFunctionPtr function = pdf::PDFFunction::createFunction(&document, parser.getObject()); QVERIFY(!function); - }, pdf::PDFParserException); + }, pdf::PDFException); QVERIFY_EXCEPTION_THROWN( { @@ -828,7 +828,7 @@ void LexicalAnalyzerTest::test_exponential_function() pdf::PDFFunctionPtr function = pdf::PDFFunction::createFunction(&document, parser.getObject()); QVERIFY(!function); - }, pdf::PDFParserException); + }, pdf::PDFException); QVERIFY_EXCEPTION_THROWN( { @@ -845,7 +845,7 @@ void LexicalAnalyzerTest::test_exponential_function() pdf::PDFFunctionPtr function = pdf::PDFFunction::createFunction(&document, parser.getObject()); QVERIFY(!function); - }, pdf::PDFParserException); + }, pdf::PDFException); } void LexicalAnalyzerTest::test_stitching_function() @@ -890,7 +890,7 @@ void LexicalAnalyzerTest::test_stitching_function() pdf::PDFFunctionPtr function = pdf::PDFFunction::createFunction(&document, parser.getObject()); QVERIFY(!function); - }, pdf::PDFParserException); + }, pdf::PDFException); QVERIFY_EXCEPTION_THROWN( { @@ -907,7 +907,7 @@ void LexicalAnalyzerTest::test_stitching_function() pdf::PDFFunctionPtr function = pdf::PDFFunction::createFunction(&document, parser.getObject()); QVERIFY(!function); - }, pdf::PDFParserException); + }, pdf::PDFException); QVERIFY_EXCEPTION_THROWN( { @@ -924,7 +924,7 @@ void LexicalAnalyzerTest::test_stitching_function() pdf::PDFFunctionPtr function = pdf::PDFFunction::createFunction(&document, parser.getObject()); QVERIFY(!function); - }, pdf::PDFParserException); + }, pdf::PDFException); QVERIFY_EXCEPTION_THROWN( { @@ -940,7 +940,7 @@ void LexicalAnalyzerTest::test_stitching_function() pdf::PDFFunctionPtr function = pdf::PDFFunction::createFunction(&document, parser.getObject()); QVERIFY(!function); - }, pdf::PDFParserException); + }, pdf::PDFException); QVERIFY_EXCEPTION_THROWN( { @@ -956,7 +956,7 @@ void LexicalAnalyzerTest::test_stitching_function() pdf::PDFFunctionPtr function = pdf::PDFFunction::createFunction(&document, parser.getObject()); QVERIFY(!function); - }, pdf::PDFParserException); + }, pdf::PDFException); } void LexicalAnalyzerTest::test_postscript_function()