Exception refactoring

This commit is contained in:
Jakub Melka 2019-04-29 17:03:19 +02:00
parent 7e953b60e7
commit 11cb52921e
17 changed files with 96 additions and 59 deletions

View File

@ -83,7 +83,8 @@ HEADERS += \
sources/pdfrenderingerrorswidget.h \
sources/pdffunction.h \
sources/pdfnametounicode.h \
sources/pdffont.h
sources/pdffont.h \
sources/pdfexception.h
FORMS += \
sources/pdfrenderingerrorswidget.ui

View File

@ -16,8 +16,8 @@
// along with PDFForQt. If not, see <https://www.gnu.org/licenses/>.
#include "pdfcatalog.h"
#include "pdfparser.h"
#include "pdfdocument.h"
#include "pdfexception.h"
#include "pdfnumbertreeloader.h"
namespace pdf

View File

@ -18,7 +18,7 @@
#include "pdfcolorspaces.h"
#include "pdfobject.h"
#include "pdfdocument.h"
#include "pdfparser.h"
#include "pdfexception.h"
namespace pdf
{

View File

@ -17,8 +17,8 @@
#include "pdfdocument.h"
#include "pdfparser.h"
#include "pdfencoding.h"
#include "pdfexception.h"
#include "pdfstreamfilters.h"
#include "pdfconstants.h"

View File

@ -17,9 +17,10 @@
#include "pdfdocumentreader.h"
#include "pdfparser.h"
#include "pdfconstants.h"
#include "pdfxreftable.h"
#include "pdfexception.h"
#include "pdfparser.h"
#include <QFile>

View File

@ -0,0 +1,79 @@
// Copyright (C) 2019 Jakub Melka
//
// This file is part of PdfForQt.
//
// PdfForQt is free software: you can redistribute it and/or modify
// it under the terms of the GNU Lesser General Public License as published by
// the Free Software Foundation, either version 3 of the License, or
// (at your option) any later version.
//
// PdfForQt is distributed in the hope that it will be useful,
// but WITHOUT ANY WARRANTY; without even the implied warranty of
// MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
// GNU Lesser General Public License for more details.
//
// You should have received a copy of the GNU Lesser General Public License
// along with PDFForQt. If not, see <https://www.gnu.org/licenses/>.
#ifndef PDFEXCEPTION_H
#define PDFEXCEPTION_H
#include <QString>
namespace pdf
{
class PDFParserException : public std::exception
{
public:
PDFParserException(const QString& message) :
m_message(message)
{
}
/// Returns error message
const QString& getMessage() const { return m_message; }
private:
QString m_message;
};
enum RenderErrorType
{
Error,
NotImplemented
};
struct PDFRenderError
{
explicit PDFRenderError() = default;
explicit PDFRenderError(RenderErrorType type, QString message) :
type(type),
message(std::move(message))
{
}
RenderErrorType type = RenderErrorType::Error;
QString message;
};
class PDFRendererException : public std::exception
{
public:
explicit PDFRendererException(RenderErrorType type, QString message) :
m_error(type, std::move(message))
{
}
const PDFRenderError& getError() const { return m_error; }
private:
PDFRenderError m_error;
};
} // namespace pdf
#endif // PDFEXCEPTION_H

View File

@ -19,6 +19,7 @@
#include "pdfdocument.h"
#include "pdfparser.h"
#include "pdfnametounicode.h"
#include "pdfexception.h"
#include <ft2build.h>
#include <freetype/freetype.h>
@ -562,7 +563,6 @@ PDFRealizedFontPointer PDFRealizedFont::createRealizedFont(PDFFontPointer font,
if (impl->m_systemFontData.isEmpty())
{
// TODO: Upravit vyjimky do separatniho souboru
throw PDFParserException(PDFTranslationContext::tr("Can't load system font '%1'.").arg(QString::fromLatin1(descriptor->fontName)));
}

View File

@ -19,6 +19,7 @@
#include "pdfflatarray.h"
#include "pdfparser.h"
#include "pdfdocument.h"
#include "pdfexception.h"
#include <stack>
#include <iterator>

View File

@ -17,7 +17,7 @@
#include "pdfpage.h"
#include "pdfdocument.h"
#include "pdfparser.h"
#include "pdfexception.h"
namespace pdf
{

View File

@ -17,6 +17,7 @@
#include "pdfpagecontentprocessor.h"
#include "pdfdocument.h"
#include "pdfexception.h"
namespace pdf
{

View File

@ -19,8 +19,8 @@
#define PDFPAGECONTENTPROCESSOR_H
#include "pdfrenderer.h"
#include "pdfparser.h"
#include "pdfcolorspaces.h"
#include "pdfparser.h"
#include "pdffont.h"
#include "pdfutils.h"
@ -36,21 +36,6 @@ namespace pdf
{
static constexpr const char* PDF_RESOURCE_EXTGSTATE = "ExtGState";
class PDFRendererException : public std::exception
{
public:
explicit PDFRendererException(RenderErrorType type, QString message) :
m_error(type, std::move(message))
{
}
const PDFRenderError& getError() const { return m_error; }
private:
PDFRenderError m_error;
};
/// Process the contents of the page.
class PDFPageContentProcessor
{

View File

@ -18,6 +18,7 @@
#include "pdfparser.h"
#include "pdfconstants.h"
#include "pdfexception.h"
#include <QFile>
#include <QThread>

View File

@ -76,22 +76,6 @@ constexpr const char* PDF_REFERENCE_COMMAND = "R";
constexpr const char* PDF_STREAM_START_COMMAND = "stream";
constexpr const char* PDF_STREAM_END_COMMAND = "endstream";
class PDFParserException : public std::exception
{
public:
PDFParserException(const QString& message) :
m_message(message)
{
}
/// Returns error message
const QString& getMessage() const { return m_message; }
private:
QString m_message;
};
class PDFFORQTLIBSHARED_EXPORT PDFLexicalAnalyzer
{
Q_GADGET

View File

@ -19,6 +19,7 @@
#define PDFRENDERER_H
#include "pdfpage.h"
#include "pdfexception.h"
class QPainter;
@ -26,26 +27,6 @@ namespace pdf
{
class PDFFontCache;
enum RenderErrorType
{
Error,
NotImplemented
};
struct PDFRenderError
{
explicit PDFRenderError() = default;
explicit PDFRenderError(RenderErrorType type, QString message) :
type(type),
message(std::move(message))
{
}
RenderErrorType type = RenderErrorType::Error;
QString message;
};
/// Renders the PDF page on the painter, or onto an image.
class PDFRenderer
{

View File

@ -17,6 +17,7 @@
#include "pdfstreamfilters.h"
#include "pdfdocument.h"
#include "pdfexception.h"
#include "pdfparser.h"
#include <QtEndian>

View File

@ -17,6 +17,7 @@
#include "pdfxreftable.h"
#include "pdfconstants.h"
#include "pdfexception.h"
#include "pdfparser.h"
#include <stack>

View File

@ -25,6 +25,7 @@
#include "pdfstreamfilters.h"
#include "pdffunction.h"
#include "pdfdocument.h"
#include "pdfexception.h"
#include <regex>